Пример #1
0
 /**
  * overwrite parents __construct() method as we do not have a lot to do here.
  *
  * @param none
  * @return void
  * @throws \Thallium\Controllers\ExceptionController
  */
 public function __construct()
 {
     if (!\Thallium\Controllers\MainController::inTestMode()) {
         static::raiseError(__METHOD__ . '(), this view is only valid in test mode!', true);
         return;
     }
     if (!$this->addMode('show')) {
         static::raiseError(__CLASS__ . '::addMode() returned false!', true);
         return;
     }
     if (!$this->addContent('testcontent')) {
         static::raiseError(__CLASS__ . '::addContent() returned false!', true);
         return;
     }
     parent::__construct();
     return;
 }
Пример #2
0
 public function __construct($mode = null)
 {
     if (!$this->setNamespacePrefix('MasterShaper')) {
         static::raiseError(__METHOD__ . '(), unable to set namespace prefix!', true);
         return;
     }
     try {
         $this->registerModel('chain', 'ChainModel');
         $this->registerModel('chains', 'ChainsModel');
         $this->registerModel('auditentry', 'AuditEntryModel');
         $this->registerModel('auditlog', 'AuditLogModel');
         $this->registerModel('filter', 'FilterModel');
         $this->registerModel('filters', 'FiltersModel');
         $this->registerModel('host_profile', 'HostProfileModel');
         $this->registerModel('host_profiles', 'HostProfilesModel');
         $this->registerModel('host_task', 'HostTaskModel');
         $this->registerModel('host_tasks', 'HostTasksModel');
         $this->registerModel('network_interface', 'NetworkInterfaceModel');
         $this->registerModel('network_interfaces', 'NetworkInterfacesModel');
         $this->registerModel('network_path', 'NetworkPathModel');
         $this->registerModel('network_paths', 'NetworkPathsModel');
         $this->registerModel('pipe', 'PipeModel');
         $this->registerModel('pipes', 'PipesModel');
         $this->registerModel('port', 'PortModel');
         $this->registerModel('ports', 'PortsModel');
         $this->registerModel('protocol', 'ProtocolModel');
         $this->registerModel('protocols', 'ProtocolsModel');
         $this->registerModel('service_level', 'ServiceLevelModel');
         $this->registerModel('service_levels', 'ServiceLevelsModel');
         $this->registerModel('target', 'TargetModel');
         $this->registerModel('targets', 'TargetsModel');
         $this->registerModel('user', 'UserModel');
         $this->registerModel('users', 'UsersModel');
         $this->registerModel('atg', 'AssignTargetToGroupModel');
         $this->registerModel('atgs', 'AssignTargetToGroupsModel');
         $this->registerModel('apf', 'AssignPortToFilterModel');
         $this->registerModel('apfs', 'AssignPortToFiltersModel');
         $this->registerModel('apc', 'AssignPipeToChainModel');
         $this->registerModel('apcs', 'AssignPipeToChainsModel');
         $this->registerModel('afp', 'AssignFilterToPipeModel');
         $this->registerModel('afps', 'AssignFilterToPipesModel');
         $this->registerModel('setting', 'SettingModel');
         $this->registerModel('settings', 'SettingsModel');
         $this->registerModel('tcid', 'TcIdModel');
         $this->registerModel('tcids', 'TcIdsModel');
     } catch (\Exception $e) {
         static::raiseError(__CLASS__ . '::__construct(), error on registering models!', true, $e);
         return;
     }
     if (extension_loaded('Zend OPcache')) {
         $this->zend_opcache_available = true;
     }
     $GLOBALS['ms'] =& $this;
     parent::__construct();
     global $config;
     if (($timeout = $config->getScriptTimeout()) !== false) {
         set_time_limit($timeout);
     }
     if (!$this->loadSettings()) {
         static::raiseError(__CLASS__ . '::loadSettings() returned false!', true);
         return false;
     }
     return;
 }
Пример #3
0
 /**
  * returns all or only the HTTP request header specified by $header.
  *
  * @param string
  * @return string|array|bool
  * @throws \Thallium\Controllers\ExceptionController
  */
 public function getHttpHeaders($header = null)
 {
     // in test mode we are going to fake a JSON content-type.
     if (\Thallium\Controllers\MainController::inTestMode() and $header === 'Content-Type') {
         return 'application/json';
     }
     if (!is_null($header) && !is_string($header)) {
         static::raiseError(__METHOD__ . '(), $header parameter is invalid!');
         return false;
     }
     if (!isset($this->httpRequestHeaders) || empty($this->httpRequestHeaders)) {
         return false;
     }
     if (is_null($header)) {
         return $this->httpRequestHeaders;
     }
     if (in_array($header, array_keys($this->httpRequestHeaders))) {
         return $this->httpRequestHeaders[$header];
     }
     return false;
 }
Пример #4
0
 /**
  * retrieves content snippets from a specific view.
  *
  * @param none
  * @return bool
  * @throws \Thallium\Controllers\ExceptionController
  */
 protected function rpcGetViewContent()
 {
     global $thallium, $router;
     if (!$router->hasQueryParams() || !$router->hasQueryParam('view') || !$router->hasQueryParam('data') || ($view = $router->getQueryParam('view')) === false || ($data = $router->getQueryParam('data')) === false || empty($view) || !is_string($view) || empty($data) || !is_array($data)) {
         static::raiseError(__METHOD__ . '(), invalid content-request data!');
         return false;
     }
     if (!array_key_exists('content', $data) || !isset($data['content']) || empty($data['content']) || !is_string($data['content'])) {
         static::raiseError(__METHOD__ . '(), $data["content"] is invalid!');
         return false;
     }
     if (!preg_match('/^[a-z]+$/', strtolower($view))) {
         static::raiseError(__METHOD__ . '(), $_POST["view"] contains invalid data!');
         return false;
     }
     if (!preg_match('/^[a-z]+$/', strtolower($data['content']))) {
         static::raiseError(__METHOD__ . '(), $data["content"] contains invalid data!');
         return false;
     }
     if (!$thallium->loadController("Templates", "tmpl")) {
         static::raiseError(__METHOD__ . '(), failed to load TemplatesController!');
         return false;
     }
     if (($prefix = $thallium->getNamespacePrefix()) === false) {
         static::raiseError(get_class($thallium) . '::getNamespacePrefix() returned false!');
         return false;
     }
     if (!isset($prefix) || empty($prefix) || !is_string($prefix)) {
         static::raiseError(get_class($thallium) . '::getNamespacePrefix() returned no valid data!');
         return false;
     }
     $view_name = ucwords(strtolower($view));
     $view_name = sprintf('\\%s\\Views\\%sView', $prefix, $view_name);
     try {
         $view = new $view_name();
     } catch (\Exception $e) {
         static::raiseError(__METHOD__ . "(), failed to load view {$view_name}!", false, $e);
         return false;
     }
     if (!$view->hasContent($data['content'])) {
         static::raiseError(get_class($view) . '::hasContent() returned false!');
         return false;
     }
     if (($content = $view->getContent($data['content'], $data)) === false) {
         static::raiseError(get_class($view) . '::getContent() returned false!');
         return false;
     }
     if (!isset($content) || empty($content)) {
         static::raiseError(get_class($view) . '::getContent() returned invalid content!');
         return false;
     }
     if (\Thallium\Controllers\MainController::inTestMode()) {
         return $content;
     }
     print $content;
     return true;
 }
Пример #5
0
 public function isBelowDirectory($dir, $topmost = self::DATA_DIRECTORY)
 {
     if (!parent::isBelowDirectory($dir, $topmost)) {
         return false;
     }
     return true;
 }