Exemplo n.º 1
0
 public function get_backupconf($name, $ip, $port, $path_to_store, $diagnostic = false)
 {
     $serial_number = $this->serial_number;
     $url = 'http://' . $ip;
     if ($port) {
         $url .= ":" . $port;
     }
     $url .= "/get_backupconf";
     $fp = fopen($path_to_store, 'wb');
     if ($fp === false) {
         $msg = 'Could not open ' . $path_to_store . ' for writing!';
         return array('success' => false, 'error' => $msg);
     }
     $curl_req = new cURL($url);
     $curl_req->post("diagnostic={$diagnostic}");
     $curl_req->progress($serial_number);
     $curl_req->setopt(CURLOPT_FILE, $fp);
     $curl_req->exec();
     $curl_req->close();
     fclose($fp);
     $info = $curl_req->get_info();
     $content_type = $info['content_type'];
     $stored_path = $path_to_store;
     // try to add extension based on mime type received.....
     $ext = IOFile::get_mime_extension($content_type);
     if ($ext) {
         // if has extension rename file...
         $stored_path = $path_to_store . '.' . $ext;
         rename($path_to_store, $stored_path);
     }
     $status = $curl_req->get_status();
     $error = $curl_req->get_error();
     if ($status != 200 && $error) {
         $msg = 'Could not get ' . $name . ' backup conf (' . $error . ')';
         return array('success' => false, 'error' => $msg);
     }
     return array('success' => true, 'path' => $stored_path);
 }