From 04e0b270fec70d7733260cb8f1b46db9b944e7aa Mon Sep 17 00:00:00 2001 From: root Date: Fri, 4 Jul 2014 16:09:08 +0200 Subject: [PATCH] [enh] Handles version --- lib/Alternc/Diagnostic/Manager.php | 14 ++++++-- lib/Alternc/Diagnostic/Service/Abstract.php | 11 ++++-- lib/Alternc/Diagnostic/Service/Dns.php | 40 +++++++++++++++------ src/diagnostic.php | 7 ++-- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/lib/Alternc/Diagnostic/Manager.php b/lib/Alternc/Diagnostic/Manager.php index 6de15e0c..e75c03d8 100644 --- a/lib/Alternc/Diagnostic/Manager.php +++ b/lib/Alternc/Diagnostic/Manager.php @@ -15,6 +15,9 @@ class Alternc_Diagnostic_Manager{ */ public $directoryInstance; + /** @var string the Alternc version */ + public $version; + /** * Constructor with dependancy injection * @@ -30,12 +33,19 @@ class Alternc_Diagnostic_Manager{ throw new \Exception("Missing parameter formatInstance"); } - // Attempts to retrieve directoryInstance + // Attempts to retrieve directoryInstance if (isset($options["directoryInstance"]) && ! is_null($options["directoryInstance"])) { $this->directoryInstance = $options["directoryInstance"]; } else { 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"); } /** @var Alternc_Diagnostic_Service_Interface */ - $serviceAgent = new $class_name; + $serviceAgent = new $class_name( array("service" => $this) ); // Runs the service agent and store the results $diagnosticData->addData($serviceAgent->name, $serviceAgent->run()); diff --git a/lib/Alternc/Diagnostic/Service/Abstract.php b/lib/Alternc/Diagnostic/Service/Abstract.php index fffbd397..8dede976 100644 --- a/lib/Alternc/Diagnostic/Service/Abstract.php +++ b/lib/Alternc/Diagnostic/Service/Abstract.php @@ -40,7 +40,10 @@ abstract class Alternc_Diagnostic_Service_Abstract{ /** @var m_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); global $db; @@ -76,6 +79,10 @@ abstract class Alternc_Diagnostic_Service_Abstract{ global $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{ } -} \ No newline at end of file +} diff --git a/lib/Alternc/Diagnostic/Service/Dns.php b/lib/Alternc/Diagnostic/Service/Dns.php index ba2bc4f1..a6cefd53 100644 --- a/lib/Alternc/Diagnostic/Service/Dns.php +++ b/lib/Alternc/Diagnostic/Service/Dns.php @@ -23,24 +23,23 @@ class Alternc_Diagnostic_Service_Dns const SECTION_ZONES = "zones"; const SECTION_ZONES_LOCKED = "zones_locked"; const SECTION_SLAVES = "slaves"; - public function __construct() { - parent::__construct(); - $this->bind = new system_bind(); - } function run(){ /** @var m_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 - $this->writeSectionData (self::SECTION_LIST,$this->domainList); + // Writes the domains list + $this->writeSectionData (self::SECTION_LIST,$this->domainList); // Writes the domains hosts $this->writeSectionData (self::SECTION_HOST, $this->getHosts()); // Writes the domains nameservers @@ -54,7 +53,26 @@ class Alternc_Diagnostic_Service_Dns $this->writeSectionData (self::SECTION_SLAVES,$this->getSlaves()); 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(){ $resultArray = array(); foreach ($this->domainList as $domain => $domainInfo) { diff --git a/src/diagnostic.php b/src/diagnostic.php index 89806d27..ef4d9f6b 100644 --- a/src/diagnostic.php +++ b/src/diagnostic.php @@ -112,10 +112,12 @@ function __autoload($class_name) // ================================================================== // ================================================================== +$version = "3.0"; + // alternc 1.0 if(is_file("/usr/share/alternc/panel/class/config_nochk.php")){ require_once("/usr/share/alternc/panel/class/config_nochk.php"); - + $version = "1.0"; }else{ require_once("/var/alternc/bureau/class/config_nochk.php"); include "../bureau/class/class_system_bind.php"; @@ -131,7 +133,8 @@ $directoryInstance = new Alternc_Diagnostic_Directory("/tmp $diagnosticManager = new Alternc_Diagnostic_Manager( array( "directoryInstance" => $directoryInstance, - "formatInstance" => new Alternc_Diagnostic_Format_Json($directoryInstance) + "formatInstance" => new Alternc_Diagnostic_Format_Json($directoryInstance), + "version" => $version ));