Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Add Check for module #6119

Merged
merged 2 commits into from
Mar 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 76 additions & 17 deletions www/class/centreon-clapi/centreonAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
namespace CentreonClapi;

require_once _CENTREON_PATH_ . "www/class/centreon-clapi/centreonExported.class.php";
require_once realpath(dirname(__FILE__)."/../centreonDB.class.php");
require_once realpath(dirname(__FILE__)."/../centreonXML.class.php");
require_once realpath(dirname(__FILE__) . "/../centreonDB.class.php");
require_once realpath(dirname(__FILE__) . "/../centreonXML.class.php");
require_once _CENTREON_PATH_ . "www/include/configuration/configGenerate/DB-Func.php";
require_once _CENTREON_PATH_ . 'www/class/config-generate/generate.class.php';
require_once _CENTREON_PATH_ . "www/class/centreonAuth.LDAP.class.php";
require_once _CENTREON_PATH_ . 'www/class/centreonLog.class.php';
require_once __DIR__ . '/centreonUtils.class.php';

if (file_exists(realpath(dirname(__FILE__)."/../centreonSession.class.php"))) {
require_once realpath(dirname(__FILE__)."/../centreonSession.class.php");
if (file_exists(realpath(dirname(__FILE__) . "/../centreonSession.class.php"))) {
require_once realpath(dirname(__FILE__) . "/../centreonSession.class.php");
} else {
require_once realpath(dirname(__FILE__)."/../Session.class.php");
require_once realpath(dirname(__FILE__) . "/../Session.class.php");
}

/**
Expand Down Expand Up @@ -88,6 +88,9 @@ class CentreonAPI
public function __construct($user, $password, $action, $centreon_path, $options)
{
global $version;
global $licensedModule;

$licensedModule = array();

/**
* Set variables
Expand Down Expand Up @@ -303,10 +306,13 @@ public function __construct($user, $password, $action, $centreon_path, $options)
$objectsPath = array();
$DBRESULT = $this->DB->query("SELECT name FROM modules_informations");
while ($row = $DBRESULT->fetchRow()) {
$objectsPath = array_merge(
$objectsPath,
glob(_CENTREON_PATH_.'www/modules/' . $row['name'] . '/centreon-clapi/class/*.php')
);

if ($this->checkModuleValidity($row['name'])) {
$objectsPath = array_merge(
$objectsPath,
glob(_CENTREON_PATH_ . 'www/modules/' . $row['name'] . '/centreon-clapi/class/*.php')
);
}
}

foreach ($objectsPath as $objectPath) {
Expand Down Expand Up @@ -341,6 +347,58 @@ function ($n) {
$this->delim = ";";
}

/**
* @param $moduleName
* @return bool
*/
public function checkModuleValidity($moduleName)
{
global $licensedModule;

$isValid = true;

$checkLicenseFile = _CENTREON_PATH_ . "www/modules/$moduleName/extensions/checkLicense.php";
if (file_exists($checkLicenseFile)) {
require_once $checkLicenseFile;
}

if (in_array($moduleName, $licensedModule)) {
$isValid = false;
$licenseFile = _CENTREON_PATH_ . "www/modules/$moduleName/license/merethis_lic.zl";

if (function_exists("zend_loader_file_encoded")) {

if (file_exists($licenseFile)) {

$zend_info = $this->parseZendLicenseFile($licenseFile);

$license_expires = strtotime($zend_info['Expires']);
if ($license_expires > time()) {
$isValid = true;
}
}
}
}

return $isValid;
}

/**
* @param $file
* @return array
*/
private function parseZendLicenseFile($file)
{
$lines = preg_split('/\n/', file_get_contents($file));
$infos = array();
foreach ($lines as $line) {
if (preg_match('/^([^= ]+)\s*=\s*(.+)$/', $line, $match)) {
$infos[$match[1]] = $match[2];
}
}
return $infos;
}

/**
*
* @param void
Expand All @@ -352,7 +410,8 @@ public static function getInstance(
$action = null,
$centreon_path = null,
$options = null
) {
)
{
if (is_null(self::$_instance)) {
self::$_instance = new CentreonAPI($user, $password, $action, $centreon_path, $options);
}
Expand Down Expand Up @@ -384,7 +443,7 @@ protected function requireLibs($object)
if ($this->relationObject[$object]['module'] == 'core') {
require_once "centreon" . $this->relationObject[$object]['class'] . ".class.php";
} else {
require_once _CENTREON_PATH_."/www/modules/"
require_once _CENTREON_PATH_ . "/www/modules/"
. $this->relationObject[$object]['module']
. "/centreon-clapi/class/centreon"
. $this->relationObject[$object]['class']
Expand Down Expand Up @@ -423,8 +482,8 @@ protected function requireLibs($object)
* Default class needed
*/

require_once _CLAPI_CLASS_."/centreonTimePeriod.class.php";
require_once _CLAPI_CLASS_."/centreonACLResources.class.php";
require_once _CLAPI_CLASS_ . "/centreonTimePeriod.class.php";
require_once _CLAPI_CLASS_ . "/centreonACLResources.class.php";
}

/**
Expand Down Expand Up @@ -487,14 +546,14 @@ public function checkUser($useSha1 = false)
}
$DBRESULT = $this->DB->query("SELECT *
FROM contact
WHERE contact_alias = '".$this->login."'
WHERE contact_alias = '" . $this->login . "'
AND contact_activate = '1'
AND contact_oreon = '1'");
if ($DBRESULT->numRows()) {
$row = $DBRESULT->fetchRow();
if ($row['contact_admin'] == 1) {
$algo = $this->utilsObject->detectPassPattern($row['contact_passwd']);
if(!$algo) {
if (!$algo) {
if ($useSha1) {
$row['contact_passwd'] = 'sha1__' . $row['contact_passwd'];
} else {
Expand Down Expand Up @@ -914,8 +973,8 @@ private function fileExists($filename)
*/
public function printLegals()
{
$DBRESULT = & $this->DB->query("SELECT * FROM informations WHERE `key` = 'version'");
$data = & $DBRESULT->fetchRow();
$DBRESULT = &$this->DB->query("SELECT * FROM informations WHERE `key` = 'version'");
$data = &$DBRESULT->fetchRow();
print "Centreon version " . $data["value"] . " - ";
print "Copyright Centreon - www.centreon.com\n";
unset($data);
Expand Down