Ejemplo n.º 1
0
 /**
  * 
  * @return array
  */
 public static function buildTemplatesList()
 {
     $rawTemplatesFileList = array();
     $moduleList = Informations::getModuleList();
     foreach ($moduleList as $module) {
         $modulePath = Informations::getModulePath($module);
         $pollerTemplatesFilePath = $modulePath . '/pollers/*.json';
         $rawTemplatesFileList = array_merge($rawTemplatesFileList, glob($pollerTemplatesFilePath));
     }
     $templatesList = array();
     foreach ($rawTemplatesFileList as $templateFile) {
         $liteTemplate = self::liteFileParser($templateFile);
         if (!isset($templatesList[$liteTemplate['name']])) {
             $myLiteTemplate = new LiteTemplate($liteTemplate['name']);
             if ($liteTemplate['engine']) {
                 $myLiteTemplate->setEnginePath($templateFile);
             }
             if ($liteTemplate['broker']) {
                 $myLiteTemplate->setBrokerPath($templateFile);
             }
             $templatesList[$liteTemplate['name']] = $myLiteTemplate;
         } else {
             $enginePath = $templatesList[$liteTemplate['name']]->getEnginePath();
             if ($liteTemplate['engine'] && empty($enginePath)) {
                 $templatesList[$liteTemplate['name']]->setEnginePath($templateFile);
             }
             $brokerPath = $templatesList[$liteTemplate['name']]->getBrokerPath();
             if ($liteTemplate['broker']) {
                 $templatesList[$liteTemplate['name']]->setBrokerPath($templateFile);
             }
         }
         unset($liteTemplate);
     }
     return $templatesList;
 }
Ejemplo n.º 2
0
 /**
  * The page structure for display
  *
  * @method GET
  * @route /eventlogs
  */
 public function displayAction()
 {
     $di = Di::getDefault();
     $tmpl = $di->get('template');
     $tmpl->addJs('hogan-3.0.0.min.js');
     //$tmpl->addJs('moment-with-langs.min.js');
     $tmpl->addJs('daterangepicker.js');
     $tmpl->addJs('jquery.select2/select2.min.js');
     $tmpl->addJs('centreon.search.js');
     $tmpl->addJs('centreon-infinite-scroll.js');
     $tmpl->addCss('select2.css');
     $tmpl->addCss('select2-bootstrap.css');
     $tmpl->addCss('daterangepicker-bs3.css');
     //$tmpl->addCss('centreon.status.css');
     if (Module::isModuleReachable('centreon-performance')) {
         $tmpl->addJs('d3.min.js');
         $tmpl->addJs('c3.min.js');
         $tmpl->addJs('centreon.graph.js', 'bottom', 'centreon-performance');
         $tmpl->addCss('c3.css');
     }
     /* Prepare field for search */
     $searchField = array('header' => array('columnSearch' => array('host' => array('main' => true, 'title' => _("Host name"), 'type' => 'text', 'searchLabel' => 'host', 'colIndex' => 1), 'service' => array('main' => true, 'title' => _("Service"), 'type' => 'text', 'searchLabel' => 'service', 'colIndex' => 2), 'output' => array('main' => false, 'title' => _("Message"), 'type' => 'text', 'searchLabel' => 'output', 'colIndex' => 3), 'status' => array('main' => false, 'title' => _("Status"), 'type' => 'select', 'searchLabel' => 'status', 'colIndex' => 3, 'additionnalParams' => array('Ok' => 0, 'Warning' => 1, 'Critical' => 2)), 'eventtype' => array('main' => false, 'title' => _("Event Type"), 'type' => 'select', 'searchLabel' => 'eventtype', 'colIndex' => 4, 'additionnalParams' => array('Alert' => 0, 'Current State' => 6, 'Initial State' => 8, 'Notification' => 2, 'Acknowledgement' => 10)))));
     $tmpl->assign('datatableParameters', $searchField);
     $tmpl->display('file:[CentreonRealtimeModule]eventlogs.tpl');
 }
Ejemplo n.º 3
0
 /**
  * List all information about modules
  * @param string $type
  * @param int $onlyActivated
  * @param int $header
  */
 public function extendedListAction($onlyActivated = 1, $header = 1)
 {
     $moduleList = Informations::getModuleExtendedList($onlyActivated);
     if ($header) {
         echo 'name;alias;description;version;author;isactivated;isinstalled' . "\n";
     }
     foreach ($moduleList as $module) {
         echo $module['name'] . ';' . $module['alias'] . ';' . $module['description'] . ';' . $module['version'] . ';' . $module['author'] . ';' . $module['isactivated'] . ';' . $module['isinstalled'] . "\n";
     }
 }
Ejemplo n.º 4
0
 /**
  * 
  * @param string $moduleName Module slug from which the static files will be deploy
  */
 public static function deploy($moduleName)
 {
     // Building static path
     $path = rtrim(Di::getDefault()->get('config')->get('global', 'centreon_path'), '/');
     $sourceModuleStaticFilesPath = Informations::getModulePath($moduleName) . '/static/' . $moduleName;
     $targetModuleStaticFilesPath = $path . '/www/static/' . $moduleName;
     //
     if (file_exists($sourceModuleStaticFilesPath)) {
         Directory::copy($sourceModuleStaticFilesPath, $targetModuleStaticFilesPath);
     }
 }
Ejemplo n.º 5
0
 /**
  * Init event listeners of modules
  */
 public static function initEventListeners()
 {
     $moduleList = Informations::getModuleList();
     foreach ($moduleList as $module) {
         $listenersPath = Informations::getModulePath($module) . '/listeners/';
         if (file_exists($listenersPath)) {
             $ModuleListenersList = glob($listenersPath . '*');
             foreach ($ModuleListenersList as $moduleListenersPath) {
                 $mTarget = substr($moduleListenersPath, strlen($listenersPath));
                 $mSource = CamelCaseTransformation::customToCamelCase($module, '-');
                 self::attachModuleEventListeners($mSource, $mTarget, $moduleListenersPath);
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * 
  */
 public function generateAction()
 {
     $moduleCanonicalName = InputOutput::prompt(_("Type the module canonical name here (in CamelCase, it must not contains Module at the ends)"), function ($params, &$result) {
         call_user_func_array(array('\\Centreon\\Internal\\Module\\Informations', 'isCanonicalNameValid'), array($params, &$result));
     });
     // Display Name and short name
     $moduleDisplayName = CamelCaseTransformation::camelCaseToCustom($moduleCanonicalName, " ");
     $moduleShortname = strtolower(CamelCaseTransformation::camelCaseToCustom($moduleCanonicalName, "-"));
     $moduleGenerator = new Generator($moduleCanonicalName);
     $moduleGenerator->setModuleShortName($moduleShortname);
     $moduleGenerator->setModuleDisplayName($moduleDisplayName);
     // Get Module ShortName set by user
     $userAnswer = InputOutput::prompt(_("Type the module shortname here (seperate by -) [" . $moduleShortname . "]"));
     if (!empty($userAnswer)) {
         $moduleShortname = $userAnswer;
     }
     // Type User Name
     $moduleAuthor = InputOutput::prompt(_("Type your name here"));
     $moduleGenerator->setModuleAuthor($moduleAuthor);
     // Ask For generating Directory Structure
     InputOutput::display(_("Generating module full structure... "), false);
     $moduleGenerator->generateModuleStructure();
     $moduleGenerator->generateConfigFile();
     $moduleGenerator->createSampleInstaller();
     InputOutput::display(_("Done\n"), true, "bgreen");
     // Ask For sample Controller/View
     $generateController = InputOutput::prompt(_("Generate sample controller/view (yes/no)? [yes]"));
     if (empty($generateController) || $generateController == "yes" || $generateController == "y") {
         $moduleGenerator->createSampleController();
         $moduleGenerator->createSampleView();
     }
     // Ask to install the module
     $installModule = InputOutput::prompt(_("Install the module(yes/no)? [no] "));
     if (!empty($installModule) && ($installModule == "yes" || $installModule == "y")) {
         $moduleInstaller = Informations::getModuleInstaller($moduleShortname);
         $moduleInstaller->install();
     }
 }
Ejemplo n.º 7
0
 /**
  * 
  * @param string $statement
  * @param array $queries
  * @param string $module
  * @return array
  */
 private static function keepStatement($statement, $queries, $module)
 {
     $finalQueries = array();
     $moduleTables = Informations::getModuleTables($module);
     $numberOfQueries = count($queries);
     for ($i = 0; $i < $numberOfQueries; $i++) {
         if (strpos($queries[$i], $statement) !== false) {
             preg_match("/\\`\\w+\\`/", $queries[$i], $rawTargetTable);
             $targetTable = trim($rawTargetTable[0], '`');
             if (in_array($targetTable, $moduleTables)) {
                 $finalQueries[] = $queries[$i];
             }
         }
     }
     return $finalQueries;
 }
Ejemplo n.º 8
0
 private static function getFilesystemWidget(&$resultSet)
 {
     // Get current moduleName
     $widgetNameList = array();
     foreach ($resultSet as $cWidget) {
         $widgetNameList[] = $cWidget['shortname'];
     }
     $path = rtrim(Di::getDefault()->get('config')->get('global', 'centreon_path'), '/');
     $modules = Informations::getModuleList(true);
     // Add file system repo
     $possibleWidgetDir = array($path . "/widgets/*Widget/");
     foreach ($modules as $module) {
         $directoryModule = str_replace(' ', '', ucwords(str_replace('-', ' ', $module))) . "Module";
         $possibleWidgetDir[] = $path . "/modules/" . $directoryModule . "/widgets/*Widget/";
     }
     foreach ($possibleWidgetDir as $d) {
         $rawWidgetList = glob($d);
         foreach ($rawWidgetList as $widget) {
             if ($widget == "." || $widget == "..") {
                 continue;
             }
             if (file_exists(realpath($widget . '/install/config.json'))) {
                 $info = json_decode(file_get_contents($widget . '/install/config.json'), true);
                 if (!in_array($info['shortname'], $widgetNameList)) {
                     $resultSet[] = array('widget_model_id' => 0, 'name' => $info['name'], 'shortname' => $info['shortname'], 'description' => $info['description'], 'version' => $info['version'], 'author' => $info['author'], 'isactivated' => 0, 'isinstalled' => 0);
                 }
             }
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * 
  */
 private function parseManifest()
 {
     $manifestDir = realpath(Informations::getModulePath(static::$moduleShortName) . '/');
     $manifestFile = $this->objectName . 'Manifest.json';
     $manifestPath = $manifestDir . '/api/internal/' . $manifestFile;
     $objectManifest = json_decode(file_get_contents($manifestPath), true);
     $moduleList = Informations::getModuleList();
     foreach ($moduleList as $module) {
         if ($module !== static::$moduleShortName) {
             $modulePath = Informations::getModulePath($module);
             if (file_exists($modulePath . '/api/internal/' . $manifestFile)) {
                 $objectManifest = self::mergeManifest($objectManifest, json_decode(file_get_contents($modulePath . '/api/internal/' . $manifestFile), true));
             }
         }
     }
     $this->objectManifest = $objectManifest;
     foreach ($this->objectManifest as $mKey => $mValue) {
         if (property_exists($this, $mKey)) {
             $this->{$mKey} = $mValue;
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * 
  * @param type $resultSet
  */
 private static function getFilesystemModule(&$resultSet)
 {
     // Get current moduleName
     $moduleNameList = Informations::getModuleList();
     $path = rtrim(Di::getDefault()->get('config')->get('global', 'centreon_path'), '/');
     $rawModuleList = glob($path . "/modules/*Module/");
     foreach ($rawModuleList as $module) {
         if (file_exists(realpath($module . 'install/config.json'))) {
             $b = json_decode(file_get_contents($module . 'install/config.json'), true);
             if (!in_array($b['shortname'], $moduleNameList)) {
                 $resultSet[] = array('id' => 0, 'name' => $b['shortname'], 'description' => $b['name'], 'version' => $b['version'], 'author' => implode(", ", $b['author']), 'isactivated' => 0, 'isinstalled' => 0, 'action' => 0, 'alias' => $b['name']);
             }
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * 
  * @param array $modules
  */
 private function parseCommand($modules)
 {
     $this->commandList = array();
     // First get the Core one
     $this->getCommandDirectoryContent(realpath(__DIR__ . "/../commands/"));
     // Now lets see the modules
     foreach ($modules as $module) {
         $moduleName = str_replace('Module', '', $module);
         preg_match_all('/[A-Z]?[a-z]+/', $moduleName, $myMatches);
         $moduleShortName = strtolower(implode('-', $myMatches[0]));
         if (Informations::isModuleReachable($moduleShortName)) {
             $this->getCommandDirectoryContent(__DIR__ . "/../../modules/{$module}/commands/", $moduleShortName, $moduleName);
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * 
  * @param type $request
  * @throws Exception
  */
 public function __construct($request)
 {
     parent::__construct($request);
     $this->parseManifest();
     if (is_null($this->repository)) {
         throw new Exception('Repository unspecified');
     }
     $repository = $this->repository;
     $repository::setRelationMap($this->relationMap);
     $repository::setObjectName($this->objectName);
     $repository::setObjectClass($this->objectClass);
     if (!empty($this->secondaryObjectClass)) {
         $repository::setSecondaryObjectClass($this->secondaryObjectClass);
     }
     $rc = new \ReflectionClass(get_class($this));
     $moduleName = Informations::getModuleFromPath($rc->getFileName());
     static::$moduleShortName = Informations::getModuleSlugName($moduleName);
     $this->objectBaseUrl = '/' . static::$moduleShortName . '/' . $this->objectName;
 }
Ejemplo n.º 13
0
 /**
  * 
  * @param integer $moduleId
  * @param array $menus
  * @param string $parent
  */
 public static function parseMenuArray($moduleId, $menus, $parent = null)
 {
     foreach ($menus as $menu) {
         if (!is_null($parent)) {
             $menu['parent'] = $parent;
         }
         $menu['module'] = $moduleId;
         Informations::setMenu($menu);
         if (isset($menu['menus']) && count($menu['menus'])) {
             self::parseMenuArray($moduleId, $menu['menus'], $menu['short_name']);
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * 
  * @param string $module
  * @return array
  */
 private function getModulesTablesFiles($module = 'centreon')
 {
     // Get Mandatory tables files
     $fileList = File::getFiles($this->appPath . '/install/db/' . $this->dbName, 'xml');
     // Get Modules tables files
     $moduleList = Informations::getModuleList(false);
     foreach ($moduleList as $module) {
         $expModuleName = array_map(function ($n) {
             return ucfirst($n);
         }, explode('-', $module));
         $moduleFileSystemName = implode("", $expModuleName) . 'Module';
         $fileList = array_merge($fileList, File::getFiles($this->appPath . '/modules/' . $moduleFileSystemName . '/install/db/' . $this->dbName, 'xml'));
     }
     return $fileList;
 }
Ejemplo n.º 15
0
 /**
  * 
  * @param string $object
  * @cmdObject string module the host
  */
 public function deployFormsAction($object)
 {
     echo Colorize::colorizeMessage("Deployment of Forms...", "info");
     try {
         $modulePath = Informations::getModulePath($object['module']);
         $moduleId = Informations::getModuleIdByName($object['module']);
         $formsFiles = $modulePath . '/install/forms/*.xml';
         foreach (glob($formsFiles) as $xmlFile) {
             Form::installFromXml($moduleId, $xmlFile);
         }
         echo Colorize::colorizeMessage("     Done", "success");
     } catch (\Exception $ex) {
         throw new \Exception("     " . $ex->getMessage(), 1);
     }
 }
Ejemplo n.º 16
0
 /**
  * Load application constant
  *
  * Load module constant if database is loaded
  */
 private function initConstants()
 {
     require $this->di->get('config')->get('global', 'centreon_path') . '/core/internal/Constant.php';
     try {
         $this->di->get('db_centreon');
         foreach (Module::getModuleList() as $moduleName) {
             $modulePath = Module::getModulePath($moduleName);
             if (file_exists($modulePath . '/config/Constant.php')) {
                 require $modulePath . '/config/Constant.php';
             }
         }
     } catch (\Exception $e) {
     }
 }
Ejemplo n.º 17
0
 /**
  * Install
  *
  * @param string $jsonFile
  */
 public static function install($jsonFile, $moduleName)
 {
     $config = self::readConfigFile($jsonFile);
     $db = Di::getDefault()->get('db_centreon');
     $isactivated = 1;
     $isinstalled = 1;
     $module = Informations::getModuleIdByName($moduleName);
     $stmt = $db->prepare("INSERT INTO cfg_widgets_models (name, shortname, description, version,\n            author, email, website, keywords, screenshot, thumbnail, isactivated, isinstalled, module_id)\n        \tVALUES (:name, :shortname, :description, :version, \n            :author, :email, :website, :keywords, :screenshot, :thumbnail,\n            :isactivated, :isinstalled, :module)");
     $stmt->bindParam(':name', $config['name']);
     $stmt->bindParam(':shortname', $config['shortname']);
     $stmt->bindParam(':description', $config['description']);
     $stmt->bindParam(':version', $config['version']);
     $stmt->bindParam(':author', $config['author']);
     $stmt->bindParam(':email', $config['email']);
     $stmt->bindParam(':website', $config['website']);
     $stmt->bindParam(':keywords', $config['keywords']);
     $stmt->bindParam(':screenshot', $config['screenshot']);
     $stmt->bindParam(':thumbnail', $config['thumbnail']);
     $stmt->bindParam(':isactivated', $isactivated);
     $stmt->bindParam(':isinstalled', $isinstalled);
     $stmt->bindParam(':module', $module);
     $stmt->execute();
     $lastId = self::getLastInsertedWidgetModelId($config['name']);
     self::insertWidgetPreferences($lastId, $config);
     self::insertWidgetWizard($config['name'], $lastId, $module);
 }
Ejemplo n.º 18
0
 /**
  * 
  * @return string
  */
 public function buildMigrationPathForProduction()
 {
     $finalPath = Informations::getModulePath($this->moduleSlug);
     $finalPath .= '/install/db/';
     return $finalPath;
 }
Ejemplo n.º 19
0
 /**
  * 
  * @return array
  */
 private function getRoutesList()
 {
     // getting controllers list using current activate module list
     $modulesList = Informations::getModuleList(true);
     $modules = array();
     foreach ($modulesList as $currentModule) {
         $modules[$currentModule]['path'] = Informations::getModulePath($currentModule);
         $modules[$currentModule]['commonName'] = Informations::getModuleCommonName($currentModule);
     }
     $controllersFullList = $this->getControllersList($modules);
     // getting front route
     $routesFullList = array('front' => array(), 'api' => array());
     foreach ($controllersFullList as $type => $controllersList) {
         foreach ($controllersList as $moduleName => $controllers) {
             $this->getRoutesFromController($moduleName, $controllers, $routesFullList[$type]);
         }
     }
     return $routesFullList;
 }
Ejemplo n.º 20
0
 /**
  * 
  * @param string $operationType
  * @param string $targetDbName
  * @return array
  */
 private static function getAllXmlFiles($operationType = 'update', $targetDbName = 'centreon')
 {
     // Initialize configuration
     $di = Di::getDefault();
     $config = $di->get('config');
     $centreonPath = $config->get('global', 'centreon_path');
     $xmlDbFiles = glob(realpath(rtrim($centreonPath, '/') . '/install/db/' . $targetDbName) . '/*.xml');
     // Module
     if ($operationType == 'update') {
         $registeredModules = Module::getList('name');
         $registeredModules(array_merge($registeredModules, Informations::getCoreModuleList()));
         foreach ($registeredModules as $module) {
             $module['name'] = str_replace(' ', '', ucwords(str_replace('-', ' ', $module['name']))) . 'Module';
             $xmlDbFiles = array_merge($xmlDbFiles, glob(realpath(rtrim($centreonPath, '/') . '/modules') . '/' . $module['name'] . '/install/db/' . $targetDbName . '/*.xml'));
         }
     } else {
         $xmlDbFiles = array_merge($xmlDbFiles, glob(realpath(rtrim($centreonPath, '/') . '/modules') . '/*Module/install/db/' . $targetDbName . '/*.xml'));
     }
     return $xmlDbFiles;
 }