[enh] Handles version
This commit is contained in:
		
							parent
							
								
									4ecfd9c73a
								
							
						
					
					
						commit
						04e0b270fe
					
				|  | @ -15,6 +15,9 @@ class Alternc_Diagnostic_Manager{ | |||
|      */ | ||||
|     public $directoryInstance; | ||||
| 
 | ||||
|     /** @var string the Alternc version */ | ||||
|     public $version; | ||||
| 
 | ||||
|     /** | ||||
|      * Constructor with dependancy injection | ||||
|      *  | ||||
|  | @ -37,6 +40,13 @@ class Alternc_Diagnostic_Manager{ | |||
|             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()); | ||||
|  |  | |||
|  | @ -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"]; | ||||
| 	} | ||||
| 
 | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|  |  | |||
|  | @ -23,20 +23,19 @@ 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 
 | ||||
|  | @ -55,6 +54,25 @@ class Alternc_Diagnostic_Service_Dns | |||
|         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) { | ||||
|  |  | |||
|  | @ -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  | ||||
| )); | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 root
						root