diff options
Diffstat (limited to 'libs/Utils/Config.class.php')
-rw-r--r-- | libs/Utils/Config.class.php | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/libs/Utils/Config.class.php b/libs/Utils/Config.class.php new file mode 100644 index 0000000..8111b32 --- /dev/null +++ b/libs/Utils/Config.class.php @@ -0,0 +1,94 @@ +<?php + +class Config +{ + public $file = null; + public $config = null; + + public function __construct() + { + $this->file = $_SERVER['DOCUMENT_ROOT'].'/esm.config.json'; + + if (file_exists($this->file)) + $this->_readFile(); + } + + private function _readFile() + { + $content = file_get_contents($this->file); + $this->config = json_decode($content, true); + } + + + /** + * Returns a specific config variable + * Ex : get('ping:hosts') + */ + public function get($var) + { + $tab = $this->config; + + $explode = explode(':', $var); + + foreach ($explode as $vartmp) + { + if (isset($tab[$vartmp])) + { + $tab = $tab[$vartmp]; + } + } + + return $tab == $this->config ? null : $tab; + } + + + /** + * Returns all config variables + */ + public function getAll() + { + return $this->config; + } + + + /** + * Checks if there is an eSM`Web update available + */ + public function checkUpdate() + { + $response = null; + $this_version = $this->get('esm:version'); + $update_url = $this->get('esm:website').'/esm-web/update/'.$this_version; + + if (!function_exists('curl_version')) + { + $tmp = @file_get_contents($update_url); + $response = json_decode($tmp, true); + } + else + { + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_CONNECTTIMEOUT => 10, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_TIMEOUT => 60, + CURLOPT_USERAGENT => 'eZ Server Monitor `Web', + CURLOPT_URL => $update_url, + )); + + $response = json_decode(curl_exec($curl), true); + + curl_close($curl); + } + + if (!is_null($response) && !empty($response)) + { + if (is_null($response['error'])) + { + return $response['datas']; + } + } + } +}
\ No newline at end of file |