array( 'Client.wsdl', 'ClientData.xsd', 'ClientMessages.xsd', 'ClientMessagesInfo.xsd', ), 'DNSZone' => array( 'DNSZone.wsdl', 'DNSZoneData.xsd', 'DNSZoneMessages.xsd', 'DNSZoneMessagesInfo.xsd', ), 'System' => array( 'System.wsdl', 'SystemData.xsd', 'SystemMessages.xsd', 'SystemMessagesInfo.xsd', ), ); private $dnsmanager_ip; private $dnsmanager_port; private $dnsmanager_version; private $dnsmanager_secure; public $error; /** * The constructor of the class * Verifies each schema file if it needs to be downloaded and it downloads it, if it needs * Creates a soap client and puts it in $this->soap_client variable * @param string $local_location - the location of the local schemes, where the schemes will be downloaded or are already downloaded * @param array $options - the options used at the creation of the soap client */ function __construct($local_location, $options,$dnsmanager_ip, $dnsmanager_port, $dnsmanager_secure, $dnsmanager_version) { $this->dnsmanager_ip = $dnsmanager_ip; $this->dnsmanager_port = $dnsmanager_port; $this->dnsmanager_version = $dnsmanager_version; $this->dnsmanager_secure = $dnsmanager_secure; $local_schema_subfolder = "tmp/wsdl/" . "{$this->dnsmanager_ip}" . "_{$this->dnsmanager_port}/soap/schema/{$this->dnsmanager_version}/"; /* the location of the schemas on the local server */ $local_schema_location = $local_location . $local_schema_subfolder; /* create the temporary folder if it does not exist */ $this->create_temp_folder($local_schema_subfolder, $local_location); foreach ($this->scheme_files as $folder => $files) { if (is_array($files)) { foreach ($files as $file) { if ($this->mustUpdate($folder, $file, $local_schema_location)) { $this->update($folder, $file, $local_schema_location); } } } else { if ($this->mustUpdate(null, $files, $local_schema_location)) { $this->update(null, $files, $local_schema_location); } } } if($this->error != '') return false; /* creates the client based on the schemes downloaded locally */ // $url = $local_schema_location.'/dnsmanagerservice.wsdl'; // $options['location'] = $url; // $this->soap_client = new SoapClient($url, $options); $this->soap_client = new SoapClient("{$local_schema_location}dnsmanagerservice.wsdl", $options); } /** * * This method will try to create the temporary folder that contains the schema, if it does not exist. Otherwise, it does nothing * * @param $schema_temp_subfolder : the subfolder that should contain the schema * @param $main_temp_folder : the base path that contains the scripts and the temporary folder we will create. */ function create_temp_folder($schema_temp_subfolder, $main_temp_folder) { $current_folder = $main_temp_folder; $tok = strtok($schema_temp_subfolder, "/\n"); while ($tok !== false) { $current_folder = $current_folder . '/' . $tok; if(!is_dir($current_folder)) { mkdir($current_folder, 0777); } $tok = strtok("/\n"); } } /** * Verifies if a local schema file must be updated or not based on mtime * @param string $folder - the parent folder of the scheme file or null if the parent folder is the version folder * @param string $file - the name of the schema file * @param string local_schema_location - the local location of the schema file * @return boolean - true if the scheme file must be downloaded, false if it doesn't */ function mustUpdate($folder, $file, $local_schema_location) { /* check if the file exists locally */ if (empty($folder)) { $local_filepath = $local_schema_location . $file; } else { $local_filepath = $local_schema_location . $folder . "/$file"; } $glob_file = glob($local_filepath, GLOB_ERR); if (!empty($glob_file)) { /* the file exists */ /* check the last time when it was modified */ if (!$this->checkModifiedDate(filemtime($local_filepath))) { /* the file was modified */ return false; } else { /* the file must be downloaded */ return true; } } else { /* the file does not exist */ return true; } } /** * Downloads a specific schema file * @param string $folder - the parent folder of the scheme file or null if the parent folder is the version folder * @param string $file - the name of the schema file * @param string local_schema_location - the local location of the schema file */ function update($folder, $file, $local_schema_location) { /* the remote location of the schema file */ if($this->dnsmanager_secure == 1) $remote_location = "https://"; else $remote_location = "http://"; $remote_location .= $this->dnsmanager_ip .':'.$this->dnsmanager_port."/soap/schema/" . $this->dnsmanager_version . "/"; if (empty($folder)) { $remote_location = $remote_location . $file; $local_location = $local_schema_location . $file; $local_directory_location = $local_schema_location; } else { $remote_location = $remote_location . $folder . "/$file"; $local_location = $local_schema_location . $folder . "/$file"; $local_directory_location = "$local_schema_location" . $folder . "/"; } /* the content of the schema file */ if(!self::urlExists($remote_location)){ $remote_location = str_replace('http://', 'https://', $remote_location); $this->dnsmanager_secure = 1; if(!self::urlExists($remote_location)){ $this->error = "Could not create wsdl file. Please check connection parameters."; return false; } } var_dump($remote_location); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $remote_location); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $content = curl_exec($ch); if ($content) { /* create the folder location */ if(!is_dir($local_directory_location)) { mkdir($local_directory_location, 0777); } /* check if the folder was created */ if (!glob($local_directory_location, GLOB_ERR)) { $this->error = "Could not create $local_directory_location folder. Please check if the parent directory has permissions or create the folder by yourself."; return false; } else { file_put_contents($local_location, $content); } } else { $this->error = $msg_arr['err_dnsmanager_hint']; return false; } } /** * Checks if the modify timeout interval specified in config.php has passed since a specific date moment * @param int $lastModified - the date moment, specified as a timestamp * @return true - if the interval has passed, false otherwise */ function checkModifiedDate($lastModified) { $modify_timeout = 9600; /* how many hours the schemes may not be modified */ $hours_interval = $modify_timeout; $seconds_interval = $hours_interval * 60 * 60; if (time() - $seconds_interval > $lastModified) { return true; } else { return false; } } /** * Gets the soap client created in the constructor * @return soapclient $this->soap_client - the soap client created in the constructor */ function getSoapClient() { return $this->soap_client; } /** * * Function that checks whether a given URL exists * * @param $url : the URL to be checked * @return : true, if it exists; false, otherwise */ private static function urlExists($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $data = curl_exec($ch); curl_close($ch); preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches); $code = end($matches[1]); if(!$data) { return false; } else { if($code == 200) { return true; } else if($code == 404) { return false; } } } }