ezservermonitor-web/libs/Utils/Config.class.php

94 lines
2.1 KiB
PHP
Raw Normal View History

2014-06-18 04:11:11 -04:00
<?php
class Config
{
public $file = null;
public $config = null;
public function __construct()
{
$this->file = __DIR__.'/../../esm.config.json';
2014-06-18 04:11:11 -04:00
if (file_exists($this->file))
$this->_readFile();
}
private function _readFile()
{
$content = file_get_contents($this->file);
$this->config = json_decode(utf8_encode($content), true);
2014-06-18 04:11:11 -04:00
}
/**
* 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'];
}
}
}
}