[enh] Handles version
This commit is contained in:
parent
4ecfd9c73a
commit
04e0b270fe
|
@ -15,6 +15,9 @@ class Alternc_Diagnostic_Manager{
|
||||||
*/
|
*/
|
||||||
public $directoryInstance;
|
public $directoryInstance;
|
||||||
|
|
||||||
|
/** @var string the Alternc version */
|
||||||
|
public $version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with dependancy injection
|
* Constructor with dependancy injection
|
||||||
*
|
*
|
||||||
|
@ -30,12 +33,19 @@ class Alternc_Diagnostic_Manager{
|
||||||
throw new \Exception("Missing parameter formatInstance");
|
throw new \Exception("Missing parameter formatInstance");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempts to retrieve directoryInstance
|
// Attempts to retrieve directoryInstance
|
||||||
if (isset($options["directoryInstance"]) && ! is_null($options["directoryInstance"])) {
|
if (isset($options["directoryInstance"]) && ! is_null($options["directoryInstance"])) {
|
||||||
$this->directoryInstance = $options["directoryInstance"];
|
$this->directoryInstance = $options["directoryInstance"];
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception("Missing parameter directoryInstance");
|
throw new \Exception("Missing parameter directoryInstance");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempts to retrieve version
|
||||||
|
if (isset($options["version"]) && ! is_null($options["version"])) {
|
||||||
|
$this->version = $options["version"];
|
||||||
|
} else {
|
||||||
|
throw new \Exception("Missing parameter version");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +68,7 @@ class Alternc_Diagnostic_Manager{
|
||||||
throw new \Exception("Invalid service $service");
|
throw new \Exception("Invalid service $service");
|
||||||
}
|
}
|
||||||
/** @var Alternc_Diagnostic_Service_Interface */
|
/** @var Alternc_Diagnostic_Service_Interface */
|
||||||
$serviceAgent = new $class_name;
|
$serviceAgent = new $class_name( array("service" => $this) );
|
||||||
|
|
||||||
// Runs the service agent and store the results
|
// Runs the service agent and store the results
|
||||||
$diagnosticData->addData($serviceAgent->name, $serviceAgent->run());
|
$diagnosticData->addData($serviceAgent->name, $serviceAgent->run());
|
||||||
|
|
|
@ -40,7 +40,10 @@ abstract class Alternc_Diagnostic_Service_Abstract{
|
||||||
/** @var m_quota */
|
/** @var m_quota */
|
||||||
protected $quota;
|
protected $quota;
|
||||||
|
|
||||||
public function __construct() {
|
/** @var Alternc_Diagnostic_Service */
|
||||||
|
protected $service;
|
||||||
|
|
||||||
|
public function __construct( $options ) {
|
||||||
$this->data = new Alternc_Diagnostic_Data(Alternc_Diagnostic_Data::TYPE_DOMAIN);
|
$this->data = new Alternc_Diagnostic_Data(Alternc_Diagnostic_Data::TYPE_DOMAIN);
|
||||||
|
|
||||||
global $db;
|
global $db;
|
||||||
|
@ -76,6 +79,10 @@ abstract class Alternc_Diagnostic_Service_Abstract{
|
||||||
global $admin;
|
global $admin;
|
||||||
$this->admin= $admin;
|
$this->admin= $admin;
|
||||||
|
|
||||||
|
if( array_key_exists("service",$options) && is_object($options["service"] ) ){
|
||||||
|
$this->service = $options["service"];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -209,4 +216,4 @@ abstract class Alternc_Diagnostic_Service_Abstract{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,24 +23,23 @@ class Alternc_Diagnostic_Service_Dns
|
||||||
const SECTION_ZONES = "zones";
|
const SECTION_ZONES = "zones";
|
||||||
const SECTION_ZONES_LOCKED = "zones_locked";
|
const SECTION_ZONES_LOCKED = "zones_locked";
|
||||||
const SECTION_SLAVES = "slaves";
|
const SECTION_SLAVES = "slaves";
|
||||||
public function __construct() {
|
|
||||||
parent::__construct();
|
|
||||||
$this->bind = new system_bind();
|
|
||||||
}
|
|
||||||
|
|
||||||
function run(){
|
function run(){
|
||||||
|
|
||||||
/** @var m_dom */
|
/** @var m_dom */
|
||||||
global $dom;
|
global $dom;
|
||||||
|
|
||||||
if( !is_a($dom, "system_bind")){
|
$this->bind = new system_bind();
|
||||||
|
$version = $this->service->version;
|
||||||
|
if( $version < 3 ) {
|
||||||
|
$this->domainList = $this->get_domain_all_summary();
|
||||||
|
}else{
|
||||||
|
$this->domainList = $dom->get_domain_all_summary();
|
||||||
|
|
||||||
$this->data->setMetadata("Alternc 1.x: can't read DNS");
|
|
||||||
return $this->data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes the domains list
|
// Writes the domains list
|
||||||
$this->writeSectionData (self::SECTION_LIST,$this->domainList);
|
$this->writeSectionData (self::SECTION_LIST,$this->domainList);
|
||||||
// Writes the domains hosts
|
// Writes the domains hosts
|
||||||
$this->writeSectionData (self::SECTION_HOST, $this->getHosts());
|
$this->writeSectionData (self::SECTION_HOST, $this->getHosts());
|
||||||
// Writes the domains nameservers
|
// Writes the domains nameservers
|
||||||
|
@ -54,7 +53,26 @@ class Alternc_Diagnostic_Service_Dns
|
||||||
$this->writeSectionData (self::SECTION_SLAVES,$this->getSlaves());
|
$this->writeSectionData (self::SECTION_SLAVES,$this->getSlaves());
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local override if not available (1.0)
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function get_domain_all_summary() {
|
||||||
|
global $db, $err;
|
||||||
|
$res = array();
|
||||||
|
$db->query("SELECT domaine, gesdns, gesmx, dns_action, zonettl FROM domaines ORDER BY domaine");
|
||||||
|
while ($db->next_record()) {
|
||||||
|
$res[$db->f("domaine")] = array(
|
||||||
|
"gesdns" => $db->f("gesdns"),
|
||||||
|
"gesmx" => $db->f("gesmx"),
|
||||||
|
"dns_action" => $db->f("dns_action"),
|
||||||
|
"zonettl" => $db->f("zonettl"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
function getHosts(){
|
function getHosts(){
|
||||||
$resultArray = array();
|
$resultArray = array();
|
||||||
foreach ($this->domainList as $domain => $domainInfo) {
|
foreach ($this->domainList as $domain => $domainInfo) {
|
||||||
|
|
|
@ -112,10 +112,12 @@ function __autoload($class_name)
|
||||||
// ==================================================================
|
// ==================================================================
|
||||||
// ==================================================================
|
// ==================================================================
|
||||||
|
|
||||||
|
$version = "3.0";
|
||||||
|
|
||||||
// alternc 1.0
|
// alternc 1.0
|
||||||
if(is_file("/usr/share/alternc/panel/class/config_nochk.php")){
|
if(is_file("/usr/share/alternc/panel/class/config_nochk.php")){
|
||||||
require_once("/usr/share/alternc/panel/class/config_nochk.php");
|
require_once("/usr/share/alternc/panel/class/config_nochk.php");
|
||||||
|
$version = "1.0";
|
||||||
}else{
|
}else{
|
||||||
require_once("/var/alternc/bureau/class/config_nochk.php");
|
require_once("/var/alternc/bureau/class/config_nochk.php");
|
||||||
include "../bureau/class/class_system_bind.php";
|
include "../bureau/class/class_system_bind.php";
|
||||||
|
@ -131,7 +133,8 @@ $directoryInstance = new Alternc_Diagnostic_Directory("/tmp
|
||||||
|
|
||||||
$diagnosticManager = new Alternc_Diagnostic_Manager( array(
|
$diagnosticManager = new Alternc_Diagnostic_Manager( array(
|
||||||
"directoryInstance" => $directoryInstance,
|
"directoryInstance" => $directoryInstance,
|
||||||
"formatInstance" => new Alternc_Diagnostic_Format_Json($directoryInstance)
|
"formatInstance" => new Alternc_Diagnostic_Format_Json($directoryInstance),
|
||||||
|
"version" => $version
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue