Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • SIWECOS
  • SIWECOSCollection
  • SIWECOSLeftBottomPage
  • SIWECOSRightBottomPage

Exceptions

  • SIWECOSException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * @package    Plugin
  6:  * @subpackage SIWECOS
  7:  * @author     Fulai Zhang <fulai.zhang@4fb.de>
  8:  * @copyright  four for business AG
  9:  * @link       http://www.4fb.de
 10:  */
 11: 
 12: // assert CONTENIDO framework
 13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 14: 
 15: /**
 16:  * Page to be displayed in the left bottom frame.
 17:  * It provides a navigation for all connections defined for the current client and the
 18:  * current language.
 19:  *
 20:  * @author Fulai Zhang <fulai.zhang@4fb.de>
 21:  */
 22: class SIWECOSLeftBottomPage extends cGuiPage
 23: {
 24:     /**
 25:      * id of the SIWECOS
 26:      *
 27:      * @var int
 28:      */
 29:     protected $idsiwecos;
 30: 
 31:     /**
 32:      * SIWECOSLeftBottomPage constructor.
 33:      *
 34:      * @throws SIWECOSException
 35:      * @throws cDbException
 36:      * @throws cException
 37:      * @throws cInvalidArgumentException
 38:      */
 39:     public function __construct()
 40:     {
 41:         parent::__construct('left_bottom', 'siwecos');
 42:         $this->_getMenu();
 43:     }
 44: 
 45:     /**
 46:      * Get menu with all forms of current client in current language.
 47:      *
 48:      * @return string
 49:      * @throws SIWECOSException
 50:      * @throws cDbException
 51:      * @throws cException
 52:      * @throws cInvalidArgumentException
 53:      */
 54:     private function _getMenu()
 55:     {
 56:         global $area;
 57: 
 58:         $cfg    = cRegistry::getConfig();
 59:         $client = cRegistry::getClientId();
 60:         $lang   = cRegistry::getLanguageId();
 61: 
 62:         // get all forms of current client in current language
 63:         $forms = SIWECOSCollection::getByClientAndLang($client, $lang);
 64:         if (false === $forms) {
 65:             return '<!-- no forms for current client/language -->';
 66:         }
 67: 
 68:         // create menu
 69:         $oPage = new cGuiPage("siwecos_menu", "siwecos");
 70:         $menu  = new cGuiMenu();
 71:         foreach ($forms as $form) {
 72:             $idsiwecos = $form['idsiwecos'];
 73:             $domain    = $form['domain'];
 74: 
 75:             $menu->setTitle($idsiwecos, $domain);
 76: 
 77:             // create link to show/edit the form
 78:             $link = new cHTMLLink();
 79:             $link->setMultiLink($area, '', $area, SIWECOSRightBottomPage::SHOW_FORM);
 80:             $link->setCustom('idsiwecos', $idsiwecos);
 81:             $link->setAttribute('title', 'idsiwecos: ' . $idsiwecos);
 82:             $menu->setLink($idsiwecos, $link);
 83: 
 84:             $deleteForm = 'DELETE_FORM';
 85:             // create link to delete the form
 86:             if (cRegistry::getPerm()->have_perm_area_action('form', SIWECOSRightBottomPage::DELETE_FORM)) {
 87:                 $link = new cHTMLLink();
 88:                 $link->setMultiLink(
 89:                     $area,
 90:                     SIWECOSRightBottomPage::DELETE_FORM,
 91:                     $area,
 92:                     SIWECOSRightBottomPage::DELETE_FORM
 93:                 );
 94:                 $link->setCustom('idsiwecos', $idsiwecos);
 95:                 $link->setClass('SIWECOS-icon-delete-form');
 96:                 $link->setAlt($deleteForm);
 97:                 $link->setContent(
 98:                     '<img src="' . $cfg['path']['images'] . 'delete.gif" title="' . $deleteForm . '" alt="'
 99:                     . $deleteForm . '">'
100:                 );
101:                 // $menu->setLink($idform, $link);
102:                 $menu->setActions($idsiwecos, 'delete', $link);
103:             } else {
104:                 $menu->setActions(
105:                     $idsiwecos,
106:                     'delete',
107:                     '<img src="' . $cfg['path']['images'] . 'delete_inact.gif" title="' . $deleteForm . '" alt="'
108:                     . $deleteForm . '">'
109:                 );
110:             }
111:         }
112: 
113:         $oPage->setContent($menu);
114: 
115:         return $oPage->render();
116:     }
117: }
118: 
119: /**
120:  * Page for area "form" to be displayed in the right bottom frame.
121:  *
122:  * @author Fulai Zhang <fulai.zhang@4fb.de>
123:  */
124: class SIWECOSRightBottomPage extends cGuiPage
125: {
126:     /**
127:      * Action constant.
128:      *
129:      * @var string
130:      */
131:     const METHODE_GET       = 'GET';
132:     const METHODE_POST      = 'POST';
133:     const SHOW_FORM         = 'siwecos_show';
134:     const VERIFICATION_FORM = 'siwecos_verification';
135:     const ADD_FORM          = 'siwecos_add';
136:     const SCAN_FORM         = 'siwecos_scan';
137:     const STORE_FORM        = 'siwecos_store';
138:     const DELETE_FORM       = 'siwecos_delete';
139: 
140:     private $_SIWECOSForm;
141: 
142:     /**
143:      * Creates and aggregates a model for a collection of SIWECOS forms
144:      * and another for a single SIWECOS form.
145:      *
146:      * If an ID for an item is given this is loaded from database
147:      * and its values are stored in the appropriate model.
148:      *
149:      * @throws SIWECOSException if form could not be loaded
150:      * @throws cDbException
151:      * @throws cException
152:      */
153:     public function __construct()
154:     {
155:         /**
156:          *
157:          * @param string $action to be performed
158:          */
159:         global $action;
160: 
161:         /**
162:          * id of the SIWECOS
163:          *
164:          * @param int $idsiwecos id of form to be edited
165:          */
166:         global $idsiwecos;
167: 
168:         parent::__construct('right_bottom', 'siwecos');
169:         $this->addStyle('siwecos.css');
170:         $this->addStyle('template.css');
171:         $this->addScript('jquery.AshAlom.gaugeMeter-2.0.0.min.js');
172: 
173:         $this->_SIWECOSForm = new SIWECOS();
174: 
175:         // load models
176:         $idsiwecos = cSecurity::toInteger($idsiwecos);
177:         if (0 < $idsiwecos) {
178:             if (false === $this->_SIWECOSForm->loadByPrimaryKey($idsiwecos)) {
179:                 $msg = i18n('ERR_LOAD_ENTITY', 'siwecos');
180:                 throw new SIWECOSException($msg);
181:             }
182:         }
183: 
184:         // dispatch action
185:         try {
186:             $this->_dispatch($action);
187:         } catch (SIWECOSException $e) {
188:             $cGuiNotification = new cGuiNotification();
189:             $notification     = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
190:             $this->set('s', 'notification', $notification);
191:             $this->set('s', 'content', '');
192:         }
193:     }
194: 
195:     /**
196:      * Dispatches the given action.
197:      *
198:      * @param string $action to be executed
199:      *
200:      * @throws CurlException
201:      * @throws SIWECOSException if the given action is unknown
202:      * @throws cDbException
203:      * @throws cException
204:      */
205:     private function _dispatch($action)
206:     {
207:         global $area;
208: 
209:         $cGuiNotification = new cGuiNotification();
210: 
211:         // check for permission
212:         if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
213:             throw new SIWECOSException(i18n('ERR_PERMISSION_DENIED', 'siwecos'));
214:         }
215: 
216:         $notification = $content = '';
217:         if (null === $action) {
218:             $notification = $cGuiNotification->returnNotification(
219:                 cGuiNotification::LEVEL_OK,
220:                 i18n('MSG_SELECT_DOMAIN', 'siwecos')
221:             );
222:         } else {
223:             // dispatch actions
224:             switch ($action) {
225:                 case self::SHOW_FORM:
226:                     try {
227:                         $content = $this->_showForm();
228:                     } catch (Exception $e) {
229:                         $notification = SIWECOS::notifyException($e);
230:                     }
231:                     break;
232: 
233:                 case self::VERIFICATION_FORM:
234:                     try {
235:                         $this->_startVerification();
236:                     } catch (Exception $e) {
237:                         $notification = SIWECOS::notifyException($e);
238:                     };
239:                     $content = $this->_showForm();
240:                     break;
241: 
242:                 case self::SCAN_FORM:
243:                     try {
244:                         $this->_scanForm();
245:                         $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_OK, $notification);
246:                     } catch (Exception $e) {
247:                         $notification = SIWECOS::notifyException($e);
248:                     }
249:                     $content = $this->_showForm();
250:                     break;
251: 
252:                 case self::STORE_FORM:
253:                     try {
254:                         $this->_validation();
255:                         $this->_storeForm();
256:                     } catch (Exception $e) {
257:                         $notification = SIWECOS::notifyException($e);
258:                     }
259:                     $this->setReload();
260:                     // reload right_top after saving of form
261:                     $idsiwecos  = $this->_SIWECOSForm->get('idsiwecos');
262:                     $formAction = new cHTMLLink();
263:                     $formAction->setCLink($area, 3, self::SHOW_FORM);
264:                     $formAction->setCustom('idsiwecos', $idsiwecos);
265:                     $url = $formAction->getHref();
266:                     $this->addScript(
267:                         "<script type=\"text/javascript\">
268:                             Con.getFrame('right_top').location.href = '$url';
269:                         </script>"
270:                     );
271:                     $content = $this->_showForm();
272:                     break;
273: 
274:                 case self::DELETE_FORM:
275:                     try {
276:                         $this->_deleteForm();
277:                         $notification = $cGuiNotification->returnNotification(
278:                             cGuiNotification::LEVEL_OK,
279:                             i18n('MSG_DELETED_ENTITY', 'siwecos')
280:                         );
281:                         $content      = '';
282:                         $this->setReload();
283:                     } catch (Exception $e) {
284:                         $notification = SIWECOS::notifyException($e);
285:                     }
286:                     break;
287: 
288:                 default:
289:                     $msg = i18n('ERR_UNKNOWN_ACTION', 'siwecos');
290:                     throw new SIWECOSException($msg);
291:             }
292:         }
293: 
294:         $this->set('s', 'notification', $notification);
295:         $this->set('s', 'content', $content);
296:     }
297: 
298:     /**
299:      * Build and return form for SIWECOS forms.
300:      *
301:      * @return string
302:      * @throws CurlException
303:      * @throws SIWECOSException
304:      * @throws cDbException
305:      * @throws cException
306:      */
307:     private function _showForm()
308:     {
309:         global $area, $auth, $belang;
310:         $cfg       = cRegistry::getConfig();
311:         $idsiwecos = $this->_SIWECOSForm->get('idsiwecos');
312: 
313:         // get form action
314:         $formAction = '';
315:         if (cRegistry::getPerm()->have_perm_area_action('form', self::STORE_FORM)) {
316:             $formAction = new cHTMLLink();
317:             $formAction->setCLink($area, 4, self::STORE_FORM);
318:             $formAction->setCustom('idsiwecos', $idsiwecos);
319:             $formAction = $formAction->getHref();
320:         }
321: 
322:         if (empty($idsiwecos)) {
323:             $idsiwecos   = null;
324:             $domain      = empty($_POST['domain']) ? '' : $_POST['domain'];
325:             $domain      = parse_url($domain);
326:             $domain      = $domain['scheme'] . '://' . $domain['host'];
327:             $email       = empty($_POST['email']) ? '' : $_POST['email'];
328:             $password    = empty($_POST['password']) ? '' : $_POST['password'];
329:             $userToken   = '';
330:             $domainToken = '';
331:             $dangerLevel = 10;
332:             $author      = $auth->getUsername();
333:             $created     = '';
334:         } else {
335:             $domain      = $this->_SIWECOSForm->get('domain');
336:             $email       = $this->_SIWECOSForm->get('email');
337:             $password    = '';
338:             $userToken   = $this->_SIWECOSForm->get('userToken');
339:             $domainToken = $this->_SIWECOSForm->get('domainToken');
340:             $dangerLevel = $this->_SIWECOSForm->get('dangerLevel');
341:             $author      = $this->_SIWECOSForm->get('author');
342:             $created     = $this->_SIWECOSForm->get('created');
343:         }
344: 
345:         $page = cSmartyBackend::getInstance(true);
346:         $page->assign('formAction', $formAction);
347:         $page->assign('domain', $domain);
348:         $page->assign('email', $email);
349:         $page->assign('password', $password);
350:         $page->assign('dangerLevel', $dangerLevel);
351:         $page->assign('userToken', $userToken);
352:         $page->assign('domainToken', $domainToken);
353:         $page->assign('author', $author);
354:         $page->assign('created', $created);
355: 
356:         $cGuiNotification = new cGuiNotification();
357: 
358:         if (empty($idsiwecos)) {
359:             // NOOP
360:         } elseif (empty($userToken)) {
361:             $notification = $cGuiNotification->returnNotification(
362:                 cGuiNotification::LEVEL_WARNING,
363:                 i18n('ERR_MISSING_USER_TOKEN', 'siwecos')
364:             );
365:             $this->set('s', 'notification', $notification);
366:         } else {
367:             $domainList = $this->_getDomainList($userToken);
368:             // error_log(print_r($domainList, true));
369:             if (!$this->_in_multiarray($domain, $domainList)) {
370:                 $notification = $cGuiNotification->returnNotification(
371:                     cGuiNotification::LEVEL_WARNING,
372:                     i18n('ERR_DOMAIN_NOT_FOUND', 'siwecos')
373:                 );
374:                 $this->set('s', 'notification', $notification);
375:             } else {
376:                 foreach ($domainList->domains as $ele) {
377:                     if ($ele->domain !== $domain) {
378:                         continue;
379:                     }
380: 
381:                     if (1 !== (int)$ele->verificationStatus) {
382:                         $reportHtml = $this->_showVerificationInfo();
383:                         break;
384:                     }
385: 
386:                     $domainResult = $this->_getDomainResult();
387:                     // error_log(print_r(json_decode($domainResult), true));
388: 
389:                     // href for scan start
390:                     $link = new cHTMLLink();
391:                     $link->setCLink($area, 4, self::SCAN_FORM);
392:                     $link->setCustom('idsiwecos', $idsiwecos);
393:                     $href = $link->getHref();
394: 
395:                     $reportPage = cSmartyBackend::getInstance(true);
396:                     $reportPage->assign('result', $domainResult);
397:                     $reportPage->assign('resultjson', json_decode($domainResult));
398:                     $reportPage->assign('scanHref', $href);
399:                     $reportPage->assign('howBtn', sprintf(i18n("BTN_HOWTO", 'siwecos'), $domain));
400:                     $reportPage->assign('language', $belang === 'de_DE' ? 'DE' : 'EN');
401:                     $reportHtml = $reportPage->fetch($cfg['templates']['siwecos_report_form']);
402:                 }
403:             }
404:         }
405: 
406:         $page->assign('report', $reportHtml);
407: 
408:         $out = $page->fetch($cfg['templates']['siwecos_right_bottom_form']);
409: 
410:         return $out;
411:     }
412: 
413:     /**
414:      * Build and return form for SIWECOS verifacation forms.
415:      *
416:      * @return string
417:      * @throws cException
418:      */
419:     private function _showVerificationInfo()
420:     {
421:         $cfg = cRegistry::getConfig();
422: 
423:         $formAction = new cHTMLLink();
424:         $formAction->setCLink(cRegistry::getArea(), 4, self::VERIFICATION_FORM);
425:         $formAction->setCustom('idsiwecos', $this->_SIWECOSForm->get('idsiwecos'));
426: 
427:         $page = cSmartyBackend::getInstance(true);
428:         $page->assign('domain', $this->_SIWECOSForm->get('domain'));
429:         $page->assign('domainToken', $this->_SIWECOSForm->get('domainToken'));
430:         $page->assign('verificationHref', $formAction->getHref());
431:         $out = $page->fetch($cfg['templates']['siwecos_verification_form']);
432: 
433:         return $out;
434:     }
435: 
436:     /**
437:      * Request the info for current SIWECOS user.
438:      *
439:      * @return stdClass
440:      * @throws CurlException
441:      * @throws SIWECOSException
442:      */
443:     private function _login()
444:     {
445:         $email          = $this->_SIWECOSForm->get('email');
446:         $password       = empty($_POST['password']) ? '' : $_POST['password'];
447:         $data           = [
448:             'email'    => $email,
449:             'password' => $password,
450:         ];
451:         $header         = [
452:             'Accept: application/json',
453:             'Content-Type: application/json;charset=utf-8',
454:         ];
455:         $CurlConnection = new CurlService();
456:         $result         = $CurlConnection->post(SIWECOS_API_URL . '/users/login', $data, $header);
457:         if (200 !== (int)$CurlConnection->error['info']['http_code']) {
458:             throw new SIWECOSException($CurlConnection->error['resp']);
459:         } else {
460:             return $result;
461:         }
462:     }
463: 
464:     /**
465:      * Request the list of all domains of given user.
466:      *
467:      * @param string $userToken
468:      *
469:      * @return stdClass
470:      * @throws CurlException
471:      * @throws SIWECOSException
472:      */
473:     private function _getDomainList(string $userToken)
474:     {
475:         $header  = [
476:             'Accept: application/json',
477:             'Content-Type: application/json;charset=utf-8',
478:             'userToken: ' . $userToken,
479:         ];
480:         $service = new CurlService();
481:         $result  = $service->post(SIWECOS_API_URL . '/domains/listDomains', [], $header);
482: 
483:         if (200 !== (int)$service->error['info']['http_code']) {
484:             throw new SIWECOSException($service->error['resp']);
485:         }
486: 
487:         return $result;
488:     }
489: 
490:     /**
491:      * Request the report for the domain.
492:      *
493:      * @return stdClass
494:      * @throws CurlException
495:      * @throws SIWECOSException
496:      * @throws cException
497:      */
498:     private function _getDomainResult()
499:     {
500:         global $belang;
501: 
502:         $userToken      = $this->_SIWECOSForm->get('userToken');
503:         $domain         = $this->_SIWECOSForm->get('domain');
504:         $CurlConnection = new CurlService();
505:         $header         = [
506:             'Accept: application/json',
507:             'Content-Type: application/json;charset=utf-8',
508:             'userToken: ' . $userToken,
509:         ];
510:         if ($belang === 'de_DE') {
511:             $url = SIWECOS_API_URL . '/scan/result/de?domain=';
512:         } else {
513:             $url = SIWECOS_API_URL . '/scan/result/en?domain=';
514:         }
515: 
516:         $result = $CurlConnection->get($url . $domain, $header);
517:         if (200 !== (int)$CurlConnection->error['info']['http_code']) {
518:             error_log($CurlConnection->error);
519:             $msg = i18n('MISSING_REPORT', 'siwecos');
520:             throw new SIWECOSException($msg);
521:         } else {
522:             return $result;
523:         }
524:     }
525: 
526:     /**
527:      * Starts the scan for the current domain.
528:      *
529:      * @throws CurlException
530:      */
531:     private function _scanForm()
532:     {
533:         $idsiwecos   = $this->_SIWECOSForm->get('idsiwecos');
534:         $domain      = $this->_SIWECOSForm->get('domain');
535:         $userToken   = $this->_SIWECOSForm->get('userToken');
536:         $dangerLevel = $this->_SIWECOSForm->get('dangerLevel');
537: 
538:         if ($idsiwecos && $userToken) {
539:             $CurlConnection = new CurlService();
540:             // Submit new Domain
541:             $data   = [
542:                 'dangerLevel' => $dangerLevel,
543:                 'domain'      => $domain,
544:             ];
545:             $header = [
546:                 'Accept: application/json',
547:                 'Content-Type: application/json;charset=utf-8',
548:                 'userToken: ' . $userToken,
549:             ];
550:             $CurlConnection->post(SIWECOS_API_URL . '/scan/start', $data, $header);
551:         }
552:     }
553: 
554:     /**
555:      * Validate form.
556:      *
557:      * @throws SIWECOSException
558:      * @throws cDbException
559:      * @throws cException
560:      */
561:     private function _validation()
562:     {
563:         global $client, $lang;
564:         $forms  = SIWECOSCollection::getByClientAndLang($client, $lang);
565:         $domain = trim(cSecurity::toString(cSecurity::unescapeDB($_POST['domain'])));
566:         if (!filter_var($domain, FILTER_VALIDATE_URL)) {
567:             throw new SIWECOSException(i18n('ERR_MALFORMED_URL', 'siwecos'));
568:         }
569:         $domain    = parse_url($domain);
570:         $domain    = $domain['scheme'] . '://' . $domain['host'];
571:         $email     = trim(cSecurity::toString(cSecurity::unescapeDB($_POST['email'])));
572:         $password  = trim(cSecurity::toString(cSecurity::unescapeDB($_POST['password'])));
573:         $idsiwecos = $this->_SIWECOSForm->get('idsiwecos');
574:         if (!$idsiwecos) {
575:             if ($this->_in_multiarray($domain, $forms)) {
576:                 throw new SIWECOSException(i18n('ERR_DOMAIN_EXISTS', 'siwecos'));
577:             } elseif (!$domain || !$email || !$password) {
578:                 throw new SIWECOSException(i18n('ERR_FORM_VALIDATION', 'siwecos'));
579:             }
580:         }
581:     }
582: 
583:     /**
584:      * @param $elem
585:      * @param $array
586:      *
587:      * @return bool
588:      */
589:     private function _in_multiarray($elem, $array)
590:     {
591:         foreach ($array as $key => $item) {
592:             if (is_array($item) || is_object($item)) {
593:                 if ($this->_in_multiarray($elem, (array)$item)) {
594:                     return true;
595:                 }
596:             } else {
597:                 if ($elem === $item) {
598:                     return true;
599:                 }
600:             }
601:         }
602: 
603:         return false;
604:     }
605: 
606:     /**
607:      * store connection for form
608:      *
609:      * @throws CurlException
610:      * @throws SIWECOSException
611:      * @throws cDbException
612:      * @throws cException
613:      * @throws cInvalidArgumentException
614:      */
615:     private function _storeForm()
616:     {
617:         global $auth;
618:         $CurlConnection = new CurlService();
619:         $idsiwecos      = $this->_SIWECOSForm->get('idsiwecos');
620: 
621:         // read item data from form
622:         $domain = trim(cSecurity::toString(cSecurity::unescapeDB($_POST['domain'])));
623:         $domain = parse_url($domain);
624:         $domain = $domain['scheme'] . '://' . $domain['host'];
625:         $email  = trim(cSecurity::toString(cSecurity::unescapeDB($_POST['email'])));
626:         // $password    = trim(cSecurity::toString(cSecurity::unescapeDB($_POST['password'])));
627:         $dangerLevel = trim(cSecurity::toString(cSecurity::unescapeDB($_POST['dangerLevel'])));
628:         $author      = $auth->getUsername();
629:         $created     = date('Y-m-d H:i:s');
630: 
631:         // create new item for given client & language
632:         if (!$idsiwecos) {
633:             // create new item for given client & language
634:             $SIWECOSCollection  = new SIWECOSCollection();
635:             $this->_SIWECOSForm = $SIWECOSCollection->createNewItem(
636:                 [
637:                     'idclient'    => cRegistry::getClientId(),
638:                     'idlang'      => cRegistry::getLanguageId(),
639:                     'domain'      => $domain,
640:                     'email'       => $email,
641:                     'dangerLevel' => $dangerLevel,
642:                     'author'      => $author,
643:                     'created'     => $created,
644:                 ]
645:             );
646:             $idsiwecos          = $this->_SIWECOSForm->get('idsiwecos');
647:         }
648:         if ($domain !== $this->_SIWECOSForm->get('domain')) {
649:             $this->_SIWECOSForm->set('domain', $domain);
650:         }
651:         if ($email !== $this->_SIWECOSForm->get('email')) {
652:             $this->_SIWECOSForm->set('email', $email);
653:         }
654:         if ($dangerLevel !== $this->_SIWECOSForm->get('dangerLevel')) {
655:             $this->_SIWECOSForm->set('dangerLevel', $dangerLevel);
656:         }
657:         if ($author !== $this->_SIWECOSForm->get('author')) {
658:             $this->_SIWECOSForm->set('author', $author);
659:             $this->_SIWECOSForm->set('created', $created);
660:         }
661: 
662:         // store item
663:         if (false === $this->_SIWECOSForm->store()) {
664:             $msg = i18n('FORM_STORE_ERROR', 'siwecos');
665:             throw new SIWECOSException($msg);
666:         }
667: 
668:         $userToken = $this->_SIWECOSForm->get('userToken');
669:         if (!$userToken && $idsiwecos) {
670:             $result    = $this->_login();
671:             $userToken = $result->token;
672:             if ($userToken !== $this->_SIWECOSForm->get('userToken')) {
673:                 $this->_SIWECOSForm->set('userToken', $userToken);
674:                 // store item
675:                 if (false === $this->_SIWECOSForm->store()) {
676:                     $msg = i18n('FORM_STORE_ERROR', 'siwecos');
677:                     throw new SIWECOSException($msg);
678:                 }
679:             }
680:         }
681:         $domainToken = $this->_SIWECOSForm->get('domainToken');
682:         $addDomain   = true;
683:         if ($userToken) {
684:             $result = $this->_getDomainList($userToken);
685:             foreach ($result->domains as $ele) {
686:                 if ($ele->domain === $domain) {
687:                     $domainToken = $ele->domainToken;
688:                     $addDomain   = false;
689:                 }
690:             }
691:         }
692:         if ($addDomain) {
693:             $data        = [
694:                 'danger_level' => $dangerLevel,
695:                 'domain'       => $domain,
696:             ];
697:             $header      = [
698:                 'Accept: application/json',
699:                 'Content-Type: application/json;charset=utf-8',
700:                 'userToken: ' . $userToken,
701:             ];
702:             $result      = $CurlConnection->post(SIWECOS_API_URL . '/domains/addNewDomain', $data, $header);
703:             $domainToken = $result->domainToken;
704:         }
705:         if ($domainToken !== $this->_SIWECOSForm->get('domainToken')) {
706:             $this->_SIWECOSForm->set('domainToken', $domainToken);
707:             // store item
708:             if (false === $this->_SIWECOSForm->store()) {
709:                 $msg = i18n('FORM_STORE_ERROR', 'siwecos');
710:                 throw new SIWECOSException($msg);
711:             }
712:         }
713:     }
714: 
715:     /**
716:      * Starts the scan for the current Domain.
717:      *
718:      * @throws CurlException
719:      */
720:     private function _startVerification()
721:     {
722:         $CurlConnection = new CurlService();
723:         $domain         = $this->_SIWECOSForm->get('domain');
724:         $userToken      = $this->_SIWECOSForm->get('userToken');
725:         $dangerLevel    = $this->_SIWECOSForm->get('dangerLevel');
726: 
727:         $data   = [
728:             'danger_level' => $dangerLevel,
729:             'domain'       => $domain,
730:         ];
731:         $header = [
732:             'Accept: application/json',
733:             'Content-Type: application/json;charset=utf-8',
734:             'userToken: ' . $userToken,
735:         ];
736:         $CurlConnection->post(SIWECOS_API_URL . '/domains/verifyDomain', $data, $header);
737:         // if (200 !== (int)$CurlConnection->error['info']['http_code']) {
738:         //     $msg = SIWECOS::i18n('no verification');
739:         //     throw new SIWECOSException($msg);
740:         // }
741:     }
742: 
743:     /**
744:      * Delete form.
745:      *
746:      * @throws SIWECOSException
747:      * @throws cDbException
748:      * @throws cException
749:      */
750:     private function _deleteForm()
751:     {
752:         $this->_SIWECOSForm->delete();
753:         $this->_SIWECOSForm = null;
754:     }
755: }
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0