function frame3() { global $islinux, $cmd_arg, $chmod_arg, $zip_dir, $fm_current_root, $cookie_cache_time; global $dir_dest, $current_dir, $dir_before; global $selected_file_list, $selected_dir_list, $old_name, $new_name; global $action, $or_by, $order_dir_list_by; if (!isset($order_dir_list_by)) { $order_dir_list_by = "1A"; setcookie("order_dir_list_by", $order_dir_list_by, time() + $cookie_cache_time, "/"); } elseif (strlen($or_by)) { $order_dir_list_by = $or_by; setcookie("order_dir_list_by", $or_by, time() + $cookie_cache_time, "/"); } html_header(); echo "<body>\n"; if ($action) { switch ($action) { case 1: // create dir if (strlen($cmd_arg)) { $cmd_arg = format_path($current_dir . $cmd_arg); if (!file_exists($cmd_arg)) { @mkdir($cmd_arg, 0755); @chmod($cmd_arg, 0755); reloadframe("parent", 2, "&ec_dir=" . $cmd_arg); } else { alert(et('FileDirExists') . "."); } } break; case 2: // create arq if (strlen($cmd_arg)) { $cmd_arg = $current_dir . $cmd_arg; if (!file_exists($cmd_arg)) { if ($fh = @fopen($cmd_arg, "w")) { @fclose($fh); } @chmod($cmd_arg, 0644); } else { alert(et('FileDirExists') . "."); } } break; case 3: // rename arq ou dir if (strlen($old_name) && strlen($new_name)) { rename($current_dir . $old_name, $current_dir . $new_name); if (is_dir($current_dir . $new_name)) { reloadframe("parent", 2); } } break; case 4: // delete sel if (strstr($current_dir, $fm_current_root)) { if (strlen($selected_file_list)) { $selected_file_list = explode("<|*|>", $selected_file_list); if (count($selected_file_list)) { for ($x = 0; $x < count($selected_file_list); $x++) { $selected_file_list[$x] = trim($selected_file_list[$x]); if (strlen($selected_file_list[$x])) { total_delete($current_dir . $selected_file_list[$x], $dir_dest . $selected_file_list[$x]); } } } } if (strlen($selected_dir_list)) { $selected_dir_list = explode("<|*|>", $selected_dir_list); if (count($selected_dir_list)) { for ($x = 0; $x < count($selected_dir_list); $x++) { $selected_dir_list[$x] = trim($selected_dir_list[$x]); if (strlen($selected_dir_list[$x])) { total_delete($current_dir . $selected_dir_list[$x], $dir_dest . $selected_dir_list[$x]); } } reloadframe("parent", 2); } } } break; case 5: // copy sel if (strlen($dir_dest)) { if (uppercase($dir_dest) != uppercase($current_dir)) { if (strlen($selected_file_list)) { $selected_file_list = explode("<|*|>", $selected_file_list); if (count($selected_file_list)) { for ($x = 0; $x < count($selected_file_list); $x++) { $selected_file_list[$x] = trim($selected_file_list[$x]); if (strlen($selected_file_list[$x])) { total_copy($current_dir . $selected_file_list[$x], $dir_dest . $selected_file_list[$x]); } } } } if (strlen($selected_dir_list)) { $selected_dir_list = explode("<|*|>", $selected_dir_list); if (count($selected_dir_list)) { for ($x = 0; $x < count($selected_dir_list); $x++) { $selected_dir_list[$x] = trim($selected_dir_list[$x]); if (strlen($selected_dir_list[$x])) { total_copy($current_dir . $selected_dir_list[$x], $dir_dest . $selected_dir_list[$x]); } } reloadframe("parent", 2); } } $current_dir = $dir_dest; } } break; case 6: // move sel if (strlen($dir_dest)) { if (uppercase($dir_dest) != uppercase($current_dir)) { if (strlen($selected_file_list)) { $selected_file_list = explode("<|*|>", $selected_file_list); if (count($selected_file_list)) { for ($x = 0; $x < count($selected_file_list); $x++) { $selected_file_list[$x] = trim($selected_file_list[$x]); if (strlen($selected_file_list[$x])) { total_move($current_dir . $selected_file_list[$x], $dir_dest . $selected_file_list[$x]); } } } } if (strlen($selected_dir_list)) { $selected_dir_list = explode("<|*|>", $selected_dir_list); if (count($selected_dir_list)) { for ($x = 0; $x < count($selected_dir_list); $x++) { $selected_dir_list[$x] = trim($selected_dir_list[$x]); if (strlen($selected_dir_list[$x])) { total_move($current_dir . $selected_dir_list[$x], $dir_dest . $selected_dir_list[$x]); } } reloadframe("parent", 2); } } $current_dir = $dir_dest; } } break; case 71: // compress sel if (strlen($cmd_arg)) { ignore_user_abort(true); ini_set("display_errors", 0); ini_set("max_execution_time", 0); $zipfile = false; if (strstr($cmd_arg, ".tar")) { $zipfile = new tar_file($cmd_arg); } elseif (strstr($cmd_arg, ".zip")) { $zipfile = new zip_file($cmd_arg); } elseif (strstr($cmd_arg, ".bzip")) { $zipfile = new bzip_file($cmd_arg); } elseif (strstr($cmd_arg, ".gzip")) { $zipfile = new gzip_file($cmd_arg); } if ($zipfile) { $zipfile->set_options(array('basedir' => $current_dir, 'overwrite' => 1, 'level' => 3)); if (strlen($selected_file_list)) { $selected_file_list = explode("<|*|>", $selected_file_list); if (count($selected_file_list)) { for ($x = 0; $x < count($selected_file_list); $x++) { $selected_file_list[$x] = trim($selected_file_list[$x]); if (strlen($selected_file_list[$x])) { $zipfile->add_files($selected_file_list[$x]); } } } } if (strlen($selected_dir_list)) { $selected_dir_list = explode("<|*|>", $selected_dir_list); if (count($selected_dir_list)) { for ($x = 0; $x < count($selected_dir_list); $x++) { $selected_dir_list[$x] = trim($selected_dir_list[$x]); if (strlen($selected_dir_list[$x])) { $zipfile->add_files($selected_dir_list[$x]); } } } } $zipfile->create_archive(); } unset($zipfile); } break; case 72: // decompress arq if (strlen($cmd_arg)) { if (file_exists($current_dir . $cmd_arg)) { $zipfile = false; if (strstr($cmd_arg, ".zip")) { zip_extract(); } elseif (strstr($cmd_arg, ".bzip") || strstr($cmd_arg, ".bz2") || strstr($cmd_arg, ".tbz2") || strstr($cmd_arg, ".bz") || strstr($cmd_arg, ".tbz")) { $zipfile = new bzip_file($cmd_arg); } elseif (strstr($cmd_arg, ".gzip") || strstr($cmd_arg, ".gz") || strstr($cmd_arg, ".tgz")) { $zipfile = new gzip_file($cmd_arg); } elseif (strstr($cmd_arg, ".tar")) { $zipfile = new tar_file($cmd_arg); } if ($zipfile) { $zipfile->set_options(array('basedir' => $current_dir, 'overwrite' => 1)); $zipfile->extract_files(); } unset($zipfile); reloadframe("parent", 2); } } break; case 8: // delete arq/dir if (strlen($cmd_arg)) { if (file_exists($current_dir . $cmd_arg)) { total_delete($current_dir . $cmd_arg); } if (is_dir($current_dir . $cmd_arg)) { reloadframe("parent", 2); } } break; case 9: // CHMOD if (strlen($chmod_arg) == 4 && strlen($current_dir)) { if ($chmod_arg[0] == "1") { $chmod_arg = "0" . $chmod_arg; } else { $chmod_arg = "0" . substr($chmod_arg, strlen($chmod_arg) - 3); } $new_mod = octdec($chmod_arg); if (strlen($selected_file_list)) { $selected_file_list = explode("<|*|>", $selected_file_list); if (count($selected_file_list)) { for ($x = 0; $x < count($selected_file_list); $x++) { $selected_file_list[$x] = trim($selected_file_list[$x]); if (strlen($selected_file_list[$x])) { @chmod($current_dir . $selected_file_list[$x], $new_mod); } } } } if (strlen($selected_dir_list)) { $selected_dir_list = explode("<|*|>", $selected_dir_list); if (count($selected_dir_list)) { for ($x = 0; $x < count($selected_dir_list); $x++) { $selected_dir_list[$x] = trim($selected_dir_list[$x]); if (strlen($selected_dir_list[$x])) { @chmod($current_dir . $selected_dir_list[$x], $new_mod); } } } } } break; } if ($action != 10) { dir_list_form(); } } else { dir_list_form(); } echo "</body>\n</html>"; }
// This product released under GNU General Public License v2 // //////////////////////////////////////////////////////////////////////////////// if (isset($_POST['deletebackupility'])) { $d = opendir(BACKUP_PATH); while ($f = readdir($d)) { if (is_file(BACKUP_PATH . $f)) { rcms_delete_files(BACKUP_PATH . $f); } } closedir($d); } if (!empty($_POST['backupit'])) { $bkupfilename = './backups/backup_' . date('H-i-s_d.m.Y') . '.tar.gz'; $bkp = new gzip_file($bkupfilename); $bkp->set_options(array('basedir' => RCMS_ROOT_PATH, 'overwrite' => 1, 'level' => 9)); $bkp->add_files('config'); $bkp->add_files('content'); $bkp->create_archive(); $frm = new InputForm("", "post", $lang['admincp']['general']['backup']['getit']); $frm->addbreak($lang['admincp']['general']['backup']['done']); $frm->hidden('getit', basename($bkupfilename)); $frm->show(); } if (!empty($_POST['getit'])) { ob_end_clean(); header('Content-Type: x-gzip'); header("Content-disposition: attachment; filename={$_POST['getit']}"); readfile(BACKUP_PATH . $_POST['getit']); exit; } // Interface generation
function ExportExtInc($filename) { include_once 'ext_scripts/archive.php'; $zip = new gzip_file($filename); $zip->set_options(array('basedir' => '.', 'overwrite' => 1, 'level' => 1, 'inmemory' => 1)); $zip->add_files(array('ext_inc')); #$zip->exclude_files("ext_inc/.svn/*"); $zip->create_archive(); header('Content-Type: application/octetstream; charset=utf-8'); header("Content-Disposition: attachment; filename=\"{$filename}\""); $zip->download_file(); if (count($zip->errors) > 0) { return false; } return true; }
public function uploadApplianceBackup($archive_files) { // parse the given URL $url_aux = $this->site_url . "/upload"; // mastersite url to upload file $url = parse_url($url_aux); if ($url['scheme'] != 'http') { die('Error: Only HTTP request are supported !'); } // extract host and path: $host = $url['host']; $port = isset($url['port']) ? $url['port'] : 80; $path = $url['path']; $data = ""; $boundary = "---------------------" . substr(md5(rand(0, 32000)), 0, 10); //Collect post data (login info) $this->loadSettings(); $postdata = array('username' => $this->username, 'password' => $this->password, 'serial_number' => $this->serial_number); //Collect Postdata foreach ($postdata as $key => $val) { $data .= "--{$boundary}\r\n"; $data .= "Content-Disposition: form-data; name=\"" . $key . "\"\r\n\r\n" . $val . "\r\n"; } $data .= "--{$boundary}\r\n"; $files = array('file' => array('name' => self::ARCHIVE_FILE)); $gz_options = array('basedir' => $this->archive_base_dir, 'overwrite' => 1, 'storepaths' => 0, 'level' => 3); /* * simulate compress and check for file size archive */ $this->setStage(self::BACKUP_STAGE, self::ARCHIVE_BACKUP); $create_gz = new gzip_file(Appliance::ARCHIVE_FILE); $create_gz->set_options(array_merge(array('count' => 1), $gz_options)); $create_gz->add_files($archive_files); $create_gz->create_archive(); $archive_size = $create_gz->get_count(); $this->upload_archive_size = $archive_size; $file_post_data = array(); foreach ($files as $key => $file) { $file_post_data[0] = "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file['name']}\"\r\n"; $file_post_data[1] = "Content-Type: application/octect-stream\r\n"; $file_post_data[2] = "Content-Transfer-Encoding: binary\r\n\r\n"; $file_post_data[3] = "\r\n"; $file_post_data[4] = "--{$boundary}--\r\n"; } $content_size = $archive_size + strlen($data) + strlen(implode($file_post_data)); $this->setStage(self::BACKUP_STAGE, self::UPLOAD_BACKUP); // open a socket connection $fp = fsockopen($host, $port, $errno, $errstr); if (!$fp) { $error_msg = "Could not connect to host. {$errstr} ({$errno})"; return array('success' => false, 'info' => $error_msg, 'error' => $error_msg); } fputs($fp, "POST {$path} HTTP/1.1\r\n"); fputs($fp, "Host: {$host}\r\n"); fputs($fp, "Content-Type: multipart/form-data; boundary={$boundary}\r\n"); fputs($fp, "Content-length: " . $content_size . "\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); foreach ($files as $key => $file) { $create_gz = new gzip_file(Appliance::ARCHIVE_BACKUP); $create_gz->set_options(array_merge(array('stream' => 1, 'cbk' => array($this, 'uploadApplianceProgress'), 'socket' => $fp), $gz_options)); $create_gz->add_files($archive_files); fputs($fp, $file_post_data[0]); fputs($fp, $file_post_data[1]); fputs($fp, $file_post_data[2]); $create_gz->create_archive(); fputs($fp, $file_post_data[3]); fputs($fp, $file_post_data[4]); } $result = ''; while (!feof($fp)) { // receive the results of the request $result .= fgets($fp, 128); } // close the socket connection: fclose($fp); // split the result header from the content $result = explode("\r\n\r\n", $result, 2); $header = isset($result[0]) ? $result[0] : ''; $content = isset($result[1]) ? $result[1] : ''; $response_status = explode(" ", $header); $response_status_code = $response_status[1]; $decoded = json_decode($content, true); if ($decoded) { if ($decoded['success']) { $decoded['serial_number'] = $this->serial_number; $decoded['success'] = true; return $decoded; } else { $error = $decoded['response']['errorMessage']; return array('success' => false, 'agent' => 'MASTERSITE', 'info' => 'An error occurred! ' . $error, 'error' => $error); } } if ($response_status_code != 200) { return array('success' => false, 'agent' => 'MASTERSITE', 'info' => 'An error occurred! ' . $error, 'error' => $error); } return array('success' => true, 'agent' => 'MASTERSITE'); // status 200 send ok }
function makeArchive($fD) { $my_time = time(); $my_key = CUtils::genKey(8); $objResponse = new xajaxResponse(); $objResponse->assign("archive_info", 'innerHTML', ''); $filename = 'admin/backup/' . date('YmdHi', $my_time) . '_' . $my_key . '.tar.gz'; $filename_sql = 'admin/backup/' . date('YmdHi', $my_time) . '_' . $my_key . '.sql'; $filename_sql2 = 'admin/backup/' . date('YmdHi', $my_time) . '_' . $my_key . '_after_connect.sql'; $f = fopen($GLOBALS['PRJ_DIR'] . '/' . $filename_sql2, "a"); fwrite($f, "/*!41000 SET NAMES 'cp1251' */;"); fclose($f); set_time_limit(0); $GLOBALS['db']->backupDB($filename_sql); inc_lib('tools/CArchive.php'); $test = new gzip_file($filename); $test->set_options(array('basedir' => $GLOBALS['PRJ_DIR'] . '/', 'overwrite' => 1, 'level' => 5)); $test->add_files(array("*.*")); //$test->exclude_files(array("admin/lib/templates_c/*.php", "*.gz")); $cfiles = 0; $sfiles = 0; foreach ($test->files as $key => $current) { if (stristr($current['name'], '.tar.gz')) { unset($test->files[$key]); } else { $sfiles += $current['stat'][7]; $cfiles++; } } $test->create_archive(); $text = ''; $text .= 'Количество файлов: ' . $cfiles; $text .= '<br>'; $text .= 'Размер неупакованых файлов: ' . CUtils::getSize($sfiles, 2); $text .= '<br>'; $text .= 'Размер архива: ' . CUtils::getFileSize('/' . $filename, 2); //$text = 'test'; @unlink($GLOBALS['PRJ_DIR'] . '/' . $filename_sql); @unlink($GLOBALS['PRJ_DIR'] . '/' . $filename_sql2); $objResponse->assign("archive_info", 'innerHTML', $text); $objResponse->script("hideDiv('waiting');window.location.reload()"); return $objResponse; }