예제 #1
0
                    cpmessage('successful_data_compression_and_backup_server_to', 'admincp.php?ac=backup');
                } else {
                    cpmessage('backup_file_compression_failure', 'admincp.php?ac=backup');
                }
            } else {
                fclose(fopen(S_ROOT . './data/' . $backupdir . '/index.htm', 'a'));
                cpmessage('successful_data_compression_and_backup_server_to', 'admincp.php?ac=backup');
            }
        } else {
            cpmessage('shell_backup_failure', 'admincp.php?ac=backup');
        }
    }
} elseif ($_GET['op'] == 'import') {
    if ($_GET['do'] == 'zip') {
        include_once S_ROOT . './source/class_zib.php';
        $unzip = new SimpleUnzip();
        $unzip->ReadFile(S_ROOT . './data/' . $_GET['datafile']);
        if ($unzip->Count() == 0 || $unzip->GetError(0) != 0 || !preg_match('/\\.sql$/i', $importfile = $unzip->GetName(0))) {
            cpmessage('data_file_does_not_exist');
        }
        $identify = explode(',', base64_decode(preg_replace('/^# Identify:\\s*(\\w+).*/s', '\\1', substr($unzip->GetData(0), 0, 256))));
        //Check the version number
        $_GET['confirm'] = isset($_GET['confirm']) ? 1 : 0;
        if (!$_GET['confirm'] && $identify[1] != X_VER) {
            $showform = 1;
            include template('admin/tpl/backup');
            exit;
        }
        $sqlfilecount = 0;
        foreach ($unzip->Entries as $entry) {
            if (preg_match('/\\.sql$/i', $entry->Name)) {
예제 #2
0
         $error = TRUE;
     }
     break;
 case 'application/gzip':
     if ($cfg['GZipDump'] && @function_exists('gzopen')) {
         $import_handle = @gzopen($import_file, 'r');
     } else {
         $message = sprintf($strUnsupportedCompressionDetected, $compression);
         $show_error_header = TRUE;
         $error = TRUE;
     }
     break;
 case 'application/zip':
     if ($cfg['GZipDump'] && @function_exists('gzinflate')) {
         include_once './libraries/unzip.lib.php';
         $import_handle = new SimpleUnzip();
         $import_handle->ReadFile($import_file);
         if ($import_handle->Count() == 0) {
             $message = $strNoFilesFoundInZip;
             $show_error_header = TRUE;
             $error = TRUE;
         } elseif ($import_handle->GetError(0) != 0) {
             $message = $strErrorInZipFile . ' ' . $import_handle->GetErrorMsg(0);
             $show_error_header = TRUE;
             $error = TRUE;
         } else {
             $import_text = $import_handle->GetData(0);
         }
         // We don't need to store it further
         $import_handle = '';
     } else {
예제 #3
0
					cpmsg('database_export_succeed');
				}

			} else {

				cpmsg('database_shell_fail');

			}

		}
	}

} elseif($action == 'importzip') {

	require_once DISCUZ_ROOT.'admin/zip.func.php';
	$unzip = new SimpleUnzip();
	$unzip->ReadFile($datafile_server);

	if($unzip->Count() == 0 || $unzip->GetError(0) != 0 || !preg_match("/\.sql$/i", $importfile = $unzip->GetName(0))) {
		cpmsg('database_import_file_illegal');
	}

	$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", substr($unzip->GetData(0), 0, 256))));
	$confirm = !empty($confirm) ? 1 : 0;
	if(!$confirm && $identify[1] != $version) {
		cpmsg('database_import_confirm', 'admincp.php?action=importzip&datafile_server=$datafile_server&importsubmit=yes&confirm=yes', 'form');
	}

	$sqlfilecount = 0;
	foreach($unzip->Entries as $entry) {
		if(preg_match("/\.sql$/i", $entry->Name)) {
예제 #4
0
파일: restore.php 프로젝트: AxelPanda/ibos
function restoreZip($id)
{
    $path = PATH_ROOT;
    if (strstr($path, 'data')) {
        $id = trim(str_replace('data', '', $id), '/');
    }
    if (!file_exists($id)) {
        return array('success' => 0, 'msg' => Ibos::lang('Database import file illegal', 'dashboard.default'));
    }
    $dataFileVol1 = trim(EnvUtil::getRequest('datafilevol1', 'G'));
    $multiVol = intval(EnvUtil::getRequest('multivol', 'G'));
    Ibos::import('ext.Zip', true);
    $unzip = new SimpleUnzip();
    $unzip->ReadFile($id);
    if ($unzip->Count() == 0 || $unzip->GetError(0) != 0 || !preg_match("/\\.sql\$/i", $importFile = $unzip->GetName(0))) {
        return array('success' => 0, 'msg' => Ibos::lang('Database import file illegal', 'dashboard.default'));
    }
    $identify = explode(',', base64_decode(preg_replace("/^# Identify:\\s*(\\w+).*/s", "\\1", substr($unzip->GetData(0), 0, 256))));
    $confirm = EnvUtil::getRequest('confirm', 'G');
    $confirm = !is_null($confirm) ? 1 : 0;
    if (!$confirm && $identify[1] != VERSION) {
        return array('type' => 'confirm', 'msg' => Ibos::lang('Database import confirm', 'dashboard.default'), 'url' => 'restore.php?' . http_build_query(array('op' => 'restorezip', 'confirm' => 'yes', 'id' => $id)));
    }
    $sqlFileCount = 0;
    foreach ($unzip->Entries as $entry) {
        if (preg_match("/\\.sql\$/i", $entry->Name)) {
            $fp = fopen('backup/' . $entry->Name, 'w');
            fwrite($fp, $entry->Data);
            fclose($fp);
            $sqlFileCount++;
        }
    }
    if (!$sqlFileCount) {
        return array('success' => 0, 'msg' => Ibos::lang('Database import file illegal', 'dashboard.default'));
    }
    if ($multiVol) {
        $multiVol++;
        $id = preg_replace("/-(\\d+)(\\..+)\$/", "-{$multiVol}\\2", $id);
        if (file_exists($multiVol)) {
            $param = array('op' => 'restorezip', 'multivol' => $multiVol, 'datafilevol1' => $dataFileVol1, 'delunzip' => $dataFileVol1, 'confirm' => 'yes');
            return array('type' => 'confirm', 'msg' => Ibos::lang('Database import multivol unzip redirect', 'dashboard.default', array('multivol' => $multiVol)), 'url' => 'restore.php?' . http_build_query($param));
        } else {
            $param = array('op' => 'restore', 'id' => $dataFileVol1, 'autorestore' => 'yes', 'delunzip' => 'yes');
            return array('type' => 'confirm', 'msg' => Ibos::lang('Database import multivol confirm', 'dashboard.default'), 'url' => 'restore.php?' . http_build_query($param));
        }
    }
    $info = '<b>' . basename($id) . '</b><br />' . Ibos::lang('Version') . ': ' . $identify[1] . '<br />' . Ibos::lang('Type') . ': ' . $identify[2] . '<br />' . Ibos::lang('Backup method') . ': ' . ($identify[3] == 'multivol' ? Ibos::lang('DBMultivol') : Ibos::lang('DBShell')) . '<br />';
    if ($identify[3] == 'multivol' && $identify[4] == 1 && preg_match("/-1(\\..+)\$/", $id)) {
        $dataFileVol1 = $id;
        $id = preg_replace("/-1(\\..+)\$/", "-2\\1", $id);
        if (file_exists($id)) {
            $param = array('op' => 'restorezip', 'multivol' => 1, 'datafilevol1' => 'backup/' . $importFile, 'id' => $id, 'confirm' => 'yes');
            return array('type' => 'redirect', 'msg' => Ibos::lang('Database import multivol unzip redirect', 'dashboard.default', array('multivol' => 1)), 'url' => 'restore.php?' . http_build_query($param));
        }
    }
    $param = array('op' => 'restore', 'datafilevol1' => $dataFileVol1, 'id' => 'backup/' . $importFile, 'delunzip' => 'yes', 'autorestore' => 'yes');
    return array('type' => 'confirm', 'msg' => Ibos::lang('Database import unzip', 'dashboard.default', array('info' => $info)), 'url' => 'restore.php?' . http_build_query($param));
}
예제 #5
0
 /**
  *  Contructor of the class
  *
  *  @param  string      File name
  *  @return SimpleUnzip Instanced class
  *  @access public
  *  @uses   SimpleUnzip::ReadFile() Opens file on new if specified
  *  @since  1.0
  */
 function SimpleUnzip($in_FileName = '')
 {
     if ($in_FileName !== '') {
         SimpleUnzip::ReadFile($in_FileName);
     }
 }
예제 #6
0
     } elseif (@rename($tmpname, $datadir . $datafile)) {
     }
     @unlink($tmpname);
     $_POST['datafile'] = $datafile;
 } else {
     showmessage('vars_error_return_try', CPURL . '?action=models&op=import');
 }
 $query = $_SGLOBAL['db']->query('SELECT mid FROM ' . tname('models') . ' WHERE modelname = \'' . $_POST['modelname'] . '\'');
 $num = $_SGLOBAL['db']->num_rows($query);
 if ($num > 0) {
     deltree($datadir, $implodefile);
     showmessage('model_name_existed');
 }
 //½âѹËõ
 require_once S_ROOT . './include/zip.lib.php';
 $unzip = new SimpleUnzip();
 $unzip->ReadFile($datadir . $_POST['datafile']);
 $zipfilearr = array();
 if ($unzip->Count() != 0) {
     foreach ($unzip->Entries as $entry) {
         $zipfilearr[] = $entry->Name;
         $fp = fopen($datadir . $entry->Name, 'w');
         fwrite($fp, $entry->Data);
         fclose($fp);
     }
 }
 $copyerrorarr = array();
 if (file_exists($datadir . 'model.cache.php')) {
     //¼ì²éÖ÷ÒªsqlÎļþÊÇ·ñ´æÔÚ
     //µ¼ÈëÊý¾Ý±í
     include_once $datadir . 'model.cache.php';
예제 #7
0
 /**
  * http://bugs.php.net/bug.php?id=29532
  * bzip reads a maximum of 8192 bytes on windows systems
  *
  */
 function getNextChunk($max_size = null)
 {
     if (null !== $max_size) {
         $size = min($max_size, $this->getChunkSize());
     } else {
         $size = $this->getChunkSize();
     }
     // $result = $this->handler->getNextChunk($size);
     $result = '';
     switch ($this->getCompression()) {
         case 'application/bzip2':
             $result = '';
             while (strlen($result) < $size - 8192 && !feof($this->getHandle())) {
                 $result .= bzread($this->getHandle(), $size);
             }
             break;
         case 'application/gzip':
             $result = gzread($this->getHandle(), $size);
             break;
         case 'application/zip':
             include_once './libraries/unzip.lib.php';
             $import_handle = new SimpleUnzip();
             $import_handle->ReadFile($this->getName());
             if ($import_handle->Count() == 0) {
                 $this->_error_message = $GLOBALS['strNoFilesFoundInZip'];
                 return false;
             } elseif ($import_handle->GetError(0) != 0) {
                 $this->_error_message = $GLOBALS['strErrorInZipFile'] . ' ' . $import_handle->GetErrorMsg(0);
                 return false;
             } else {
                 $result = $import_handle->GetData(0);
             }
             break;
         case 'none':
             $result = fread($this->getHandle(), $size);
             break;
         default:
             return false;
     }
     echo $size . ' - ';
     echo strlen($result) . ' - ';
     echo @($GLOBALS['__len__'] += strlen($result)) . ' - ';
     echo $this->_error_message;
     echo '<hr />';
     if ($GLOBALS['charset_conversion']) {
         $result = PMA_convert_string($this->getCharset(), $GLOBALS['charset'], $result);
     } else {
         /**
          * Skip possible byte order marks (I do not think we need more
          * charsets, but feel free to add more, you can use wikipedia for
          * reference: <http://en.wikipedia.org/wiki/Byte_Order_Mark>)
          *
          * @todo BOM could be used for charset autodetection
          */
         if ($this->getOffset() === 0) {
             // UTF-8
             if (strncmp($result, "", 3) == 0) {
                 $result = substr($result, 3);
                 // UTF-16 BE, LE
             } elseif (strncmp($result, "þÿ", 2) == 0 || strncmp($result, "ÿþ", 2) == 0) {
                 $result = substr($result, 2);
             }
         }
     }
     $this->_offset += $size;
     if (0 === $result) {
         return true;
     }
     return $result;
 }
예제 #8
0
 function SimpleUnzip($in_FileName = '') {
     if($in_FileName !== '') {
         SimpleUnzip::ReadFile($in_FileName);
     }
 } // end of the 'SimpleUnzip' constructor
예제 #9
0
파일: db.mod.php 프로젝트: pf5512/phpstudy
	function DoImportZip()
	{
		$this->CheckAdminPrivs('dbimport');
		extract($this->Post);
		extract($this->Get);
		require_once FUNCTION_PATH.'zip.func.php';
		$unzip = new SimpleUnzip();
		$unzip->ReadFile($datafile_server);

		if($unzip->Count() == 0 || $unzip->GetError(0) != 0 || !preg_match("/\.sql$/i", $importfile = $unzip->GetName(0))) {
			$this->Messager('数据文件不存在: 可能服务器不允许上传文件或尺寸超过限制。',null);
		}

		$identify = explode(',', base64_decode(preg_replace("/^# Identify:\s*(\w+).*/s", "\\1", substr($unzip->GetData(0), 0, 256))));
		$confirm = !empty($confirm) ? 1 : 0;
		if(!$confirm && $identify[1] !=SYS_VERSION) {
			$to="admin.php?mod=db&code=importzip&datafile_server=".urlencode($datafile_server)."&importsubmit=yes&confirm=yes";
			$msg=' <form method="post" action="'.$to.'">
                    <br /><br /><br />导入和当前程序版本不一致的数据极有可能产生无法解决的故障,您确定继续吗?<br /><br /><br /><br />
                    <input type="hidden" name="FORMHASH" value="'.FORMHASH.'"> &nbsp;
                    <input class="button" type="submit" name="confirmed" value=" 确 定 "> &nbsp;
                    <input class="button" type="button" value=" 取 消 " onClick="history.go(-1);">
                  </form><br />';
			$this->Messager($msg,null);
		}

		$sqlfilecount = 0;
		foreach($unzip->Entries as $entry) {
			if(preg_match("/\.sql$/i", $entry->Name)) {
				$fp = fopen('./backup/'.$backupdir.'/'.$entry->Name, 'w');
				fwrite($fp, $entry->Data);
				fclose($fp);
				$sqlfilecount++;
			}
		}

		if(!$sqlfilecount) {
			$this->Messager('database_import_file_illegal');
		}
		$type_list=array("all_tables"=>"全部数据","custom"=>"自定义备份",'zip'=>"压缩备份");
		$info = basename($datafile_server).'<br />'.'版本'.': '.$identify[1].'<br />'.'类型'.': '.$type_list[$identify[2]].'<br />'.'方式'.': '.($identify[3] == 'multivol' ? "多卷" : "SHELL").'<br />';

		if(isset($multivol)) {
			$multivol++;
			$datafile_server = preg_replace("/-(\d+)(\..+)$/", "-$multivol\\2", $datafile_server);
			if(is_file($datafile_server)) {
				$this->Messager("数据文件 #$multivol 成功解压缩,程序将自动继续。", 'admin.php?mod=db&code=importzip&multivol='.$multivol.'&datafile_vol1='.$datafile_vol1.'&datafile_server='.urlencode($datafile_server).'&importsubmit=yes&confirm=yes');
			} else {
				$to='admin.php?mod=db&code=doimport&from=server&datafile_server='.urlencode($datafile_vol1).'&importsubmit=yes&delunzip=yes';
				$msg=' <form method="post" action="'.$to.'">
		                    <br /><br /><br />所有分卷文件解压缩完毕,您需要自动导入备份吗?导入后解压缩的文件将会被删除。<br /><br /><br /><br />
		                    <input type="hidden" name="FORMHASH" value="'.FORMHASH.'"> &nbsp;
		                    <input class="button" type="submit" name="confirmed" value=" 确 定 "> &nbsp;
		                    <input class="button" type="button" value=" 取 消 " onClick="location.href=\'admin.php?mod=db&code=import\';">
		                  </form><br />';

				$this->Messager($msg,null);
			}
		}

		if($identify[3] == 'multivol' && $identify[4] == 1 && preg_match("/-1(\..+)$/", $datafile_server)) {
			$datafile_vol1 = $datafile_server;
			$datafile_server = preg_replace("/-1(\..+)$/", "-2\\1", $datafile_server);
			if(is_file($datafile_server)) {
				$to='admin.php?mod=db&code=importzip&multivol=1&datafile_vol1=./backup/'.$backupdir.'/'.$importfile.'&datafile_server='.urlencode($datafile_server).'&importsubmit=yes&confirm=yes';
				$msg=' <form method="post" action="'.$to.'">
		                    '.$info.'<br />备份文件解压缩完毕,您需要自动解压缩其它的分卷文件吗?<br /><br /><br /><br />
		                    <input type="hidden" name="FORMHASH" value="'.FORMHASH.'"> &nbsp;
		                    <input class="button" type="submit" name="confirmed" value=" 确 定 "> &nbsp;
		                    <input class="button" type="button" value=" 取 消 " onClick="history.go(-1);">
		                  </form><br />';
				$this->Messager($msg, null);
			}
		}
		$to='admin.php?mod=db&code=doimport&from=server&datafile_server=./backup/'.$backupdir.'/'.$importfile.'&importsubmit=yes&delunzip=yes';
		$msg=' <form method="post" action="'.$to.'">
                    <br /><br /><br />所有分卷文件解压缩完毕,您需要自动导入备份吗?导入后解压缩的文件将会被删除。<br /><br /><br /><br />
                    <input type="hidden" name="FORMHASH" value="'.FORMHASH.'"> &nbsp;
                    <input class="button" type="submit" name="confirmed" value=" 确 定 "> &nbsp;
                    <input class="button" type="button" value=" 取 消 " onClick="location.href=\"admin.php?mod=db&code=import\";">
                  </form><br />';

		$this->Messager($msg,null);
	}
예제 #10
0
파일: Zip.php 프로젝트: AxelPanda/ibos
 public function SimpleUnzip($in_FileName = "")
 {
     if ($in_FileName !== "") {
         SimpleUnzip::ReadFile($in_FileName);
     }
 }
예제 #11
0
파일: dump.inc.php 프로젝트: big2men/qhm
function plugin_dump_upload()
{
    global $vars, $_STORAGE, $script;
    $qm = get_qm();
    if (!PLUGIN_DUMP_ALLOW_RESTORE) {
        return array('code' => FALSE, 'msg' => $qm->m['plg_dump']['err_prohibit_restore']);
    }
    $filename = $_FILES['upload_file']['name'];
    $matches = array();
    $arc_kind = FALSE;
    if (!preg_match('/\\.zip$/', $filename, $matches)) {
        die_message($qm->m['plg_dump']['err_invalid_filetype']);
    }
    if ($_FILES['upload_file']['size'] > PLUGIN_DUMP_MAX_FILESIZE * 1024) {
        die_message($qm->replace('plg_dump.err_size_over', PLUGIN_DUMP_MAX_FILESIZE));
    }
    //require unzip
    require_once LIB_DIR . 'unzip.lib.php';
    // Create a temporary tar file
    $uploadfile = tempnam(realpath(CACHEQHM_DIR), 'zip_uploaded_');
    if (!move_uploaded_file($_FILES['upload_file']['tmp_name'], $uploadfile)) {
        @unlink($uploadfile);
        die_message($qm->m['plg_dump']['err_upload_failed']);
    }
    $unzip = new SimpleUnzip($uploadfile);
    $files = array();
    $len = $unzip->Count();
    for ($i = 0; $i < $len; $i++) {
        $name = $unzip->GetName($i);
        $path = $unzip->GetPath($i);
        //path をディレクトリにする: ./ で始まる場合、それを除去
        $dir = basename($path);
        //swfu/d
        if ($dir == 'd') {
            $dir = strpos($path, 'swfu/d') !== FALSE ? 'swfu/d' : '';
        }
        if ($dir == 'data') {
            //swfu/data
            if (strpos($path, 'swfu/data') !== FALSE) {
                $dir = 'swfu/data';
            } else {
                if (strpos($path, 'fwd3/sys/data') !== FALSE) {
                    $dir = 'fwd3/sys/data';
                }
            }
        }
        if (strpos($path, './.') !== FALSE) {
            $path = str_replace('./.', '.', $path);
        }
        switch ($dir) {
            case 'wiki':
                $stokey = 'DATA_DIR';
                break;
            case 'attach':
                $stokey = 'UPLOAD_DIR';
                break;
            case 'backup':
                $stokey = 'BACKUP_DIR';
                break;
            case 'swfu/d':
                $stokey = 'SWFU_DIR';
                break;
            case 'swfu/data':
                $stokey = 'SWFUDATA_DIR';
                break;
            case 'fwd3/sys/data':
                $stokey = 'FWD3DATA_DIR';
                break;
            case 'cache':
                $stokey = 'CACHE_DIR';
                break;
            default:
                $stokey = 'HOME_DIR';
        }
        $filter = isset($_STORAGE[$stokey]['extract_filter']) ? $_STORAGE[$stokey]['extract_filter'] : '';
        if ($filter && preg_match("/{$filter}/", $name)) {
            $uzfile = $path . '/' . $name;
            $files[] = $uzfile;
            $data = $unzip->GetData($i);
            $dlen = strlen($data);
            if ($fp = fopen($uzfile, "wb")) {
                fwrite($fp, $data, $dlen);
                fclose($fp);
                chmod($uzfile, 0666);
            } else {
                echo '<error>', $qm->replace('plg_dump.err_open_archive', $name), '</error>';
            }
        }
    }
    if (empty($files)) {
        @unlink($uploadfile);
        return array('code' => FALSE, 'msg' => $qm->m['plg_dump']['err_upload_empty']);
    }
    $msg = '<p><strong>' . $qm->m['plg_dump']['restore_header'] . '</strong><ul>';
    foreach ($files as $name) {
        $msg .= "<li>{$name}</li>\n";
    }
    $msg .= '</ul></p>';
    $msg .= '
<p>
	<a href="' . h($script) . '?cmd=qhmsetting">設定一覧へ戻る</a>
</p>
';
    @unlink($uploadfile);
    return array('code' => TRUE, 'msg' => $msg);
}
예제 #12
0
    function DoImportZip()
    {
        if (true !== JISHIGOU_FOUNDER) {
            $this->Messager("为安全起见,只有网站创始人才能执行数据恢复操作。", null);
        }
        $datafile_server = get_param('datafile_server');
        $datafile_server = dir_safe($datafile_server);
        if (false == preg_match('~^\\.\\/data\\/backup\\/db\\/([\\w\\d\\-\\_]+)\\/\\1(\\-\\d+)?\\.zip$~i', $datafile_server)) {
            $this->Messager("文件名参数传递有误,请返回重试", null);
        }
        $backupdir = 'db/' . basename(dirname($datafile_server));
        $backupdir = dir_safe($backupdir);
        $multivol = (int) get_param('multivol');
        $datafile_vol1 = get_param('datafile_vol1');
        $datafile_vol1 = dir_safe($datafile_vol1);
        if ($datafile_vol1 && false == preg_match('~^\\.\\/data\\/backup\\/db\\/([\\w\\d\\-\\_]+)\\/\\1(\\-\\d+)?\\.sql$~i', $datafile_vol1)) {
            $this->Messager("文件名参数传递有误,请返回重试", null);
        }
        require_once ROOT_PATH . 'include/func/zip.func.php';
        $unzip = new SimpleUnzip();
        $unzip->ReadFile($datafile_server);
        if ($unzip->Count() == 0 || $unzip->GetError(0) != 0 || !preg_match("/^[\\w\\d\\-\\_]+\\.sql\$/i", $importfile = $unzip->GetName(0))) {
            $this->Messager('数据文件不存在: 可能服务器不允许上传文件或尺寸超过限制。', null);
        }
        $identify = explode(',', base64_decode(preg_replace("/^# Identify:\\s*(\\w+).*/s", "\\1", substr($unzip->GetData(0), 0, 256))));
        $confirm = 'yes' == get_param('confirm', 'P') ? 1 : 0;
        if (!$confirm && $identify[1] != SYS_VERSION) {
            $to = "admin.php?mod=db&code=importzip&datafile_server=" . urlencode($datafile_server) . "&importsubmit=yes&confirm=yes";
            $msg = ' <form method="post" action="' . $to . '">
					<input type="hidden" name="FORMHASH" value="' . FORMHASH . '"  />
                    <br /><br /><br />导入和当前程序版本不一致的数据极有可能产生无法解决的故障,您确定继续吗?<br /><br /><br /><br />
                    <input class="button" type="submit" name="confirmed" value=" 确 定 "> &nbsp;
                    <input class="button" type="button" value=" 取 消 " onClick="history.go(-1);">
                  </form><br />';
            $this->Messager($msg, null);
        }
        $sqlfilecount = 0;
        foreach ($unzip->Entries as $entry) {
            if (preg_match("/^[\\w\\d\\-\\_]+\\.sql\$/i", $entry->Name)) {
                $len = jio()->WriteFile('./data/backup/' . $backupdir . '/' . $entry->Name, $entry->Data);
                $sqlfilecount++;
            }
        }
        if (!$sqlfilecount) {
            $this->Messager('database_import_file_illegal');
        }
        $type_list = array("all_tables" => "全部数据", "custom" => "自定义备份", 'zip' => "压缩备份");
        $info = basename($datafile_server) . '<br />' . '版本' . ': ' . $identify[1] . '<br />' . '类型' . ': ' . $type_list[$identify[2]] . '<br />' . '方式' . ': ' . ($identify[3] == 'multivol' ? "多卷" : "SHELL") . '<br />';
        if ($multivol) {
            $multivol++;
            $df = $datafile_server;
            $datafile_server = preg_replace("/\\-(\\d+)(\\.zip)\$/i", "-{$multivol}\\2", $datafile_server);
            if (is_file($datafile_server)) {
                $this->Messager("数据文件 #{$multivol} 成功解压缩,程序将自动继续。", 'admin.php?mod=db&code=importzip&multivol=' . $multivol . '&datafile_vol1=' . $datafile_vol1 . '&datafile_server=' . urlencode($datafile_server) . '&importsubmit=yes&confirm=yes');
            } else {
                $to = 'admin.php?mod=db&code=doimport&from=server&datafile_server=' . urlencode($datafile_vol1) . '&importsubmit=yes&delunzip=yes';
                $msg = ' <form method="post" action="' . $to . '">
							<input type="hidden" name="FORMHASH" value="' . FORMHASH . '"  />
		                    <br /><br /><br />所有分卷文件解压缩完毕,您需要自动导入备份吗?导入后解压缩的文件将会被删除。<br /><br /><br /><br />
		                    <input class="button" type="submit" name="confirmed" value=" 确 定 "> &nbsp;
		                    <input class="button" type="button" value=" 取 消 " onClick="location.href=\'admin.php?mod=db&code=import\';">
		                  </form><br />';
                $this->Messager($msg, null);
            }
        }
        if ($identify[3] == 'multivol' && $identify[4] == 1 && preg_match("/\\-1(\\.zip+)\$/i", $datafile_server)) {
            $datafile_vol1 = $datafile_server;
            $datafile_server = preg_replace("/\\-1(\\.zip+)\$/i", "-2\\1", $datafile_server);
            if (is_file($datafile_server) && $datafile_vol1 != $datafile_server) {
                $to = 'admin.php?mod=db&code=importzip&multivol=1&datafile_vol1=./data/backup/' . $backupdir . '/' . $importfile . '&datafile_server=' . urlencode($datafile_server) . '&importsubmit=yes&confirm=yes';
                $msg = ' <form method="post" action="' . $to . '">
							<input type="hidden" name="FORMHASH" value="' . FORMHASH . '"  />
		                    ' . $info . '<br />备份文件解压缩完毕,您需要自动解压缩其它的分卷文件吗?<br /><br /><br /><br />
		                    <input class="button" type="submit" name="confirmed" value=" 确 定 "> &nbsp;
		                    <input class="button" type="button" value=" 取 消 " onClick="history.go(-1);">
		                  </form><br />';
                $this->Messager($msg, null);
            }
        }
        $to = 'admin.php?mod=db&code=doimport&from=server&datafile_server=./data/backup/' . $backupdir . '/' . $importfile . '&importsubmit=yes&delunzip=yes';
        $msg = ' <form method="post" action="' . $to . '">
					<input type="hidden" name="FORMHASH" value="' . FORMHASH . '"  />
                    <br /><br /><br />所有分卷文件解压缩完毕,您需要自动导入备份吗?导入后解压缩的文件将会被删除。<br /><br /><br /><br />
                    <input class="button" type="submit" name="confirmed" value=" 确 定 "> &nbsp;
                    <input class="button" type="button" value=" 取 消 " onClick="location.href=\\"admin.php?mod=db&code=import\\";">
                  </form><br />';
        $this->Messager($msg, null);
    }
예제 #13
0
function backupTool_settings()
{
    // set upload limits if server permits //
    @ini_set('upload_max_filesize', '100M');
    @ini_set('post_max_size', '105M');
    @ini_set('memory_limit', '350M');
    @ini_set('max_execution_time', '300');
    // end of set //
    $backupList = array();
    // create backup dir if not present
    if (!file_exists(getSystemRoot(RAZOR_ADMIN_FILENAME) . RAZOR_BACKUP_DIR)) {
        mkdir(getSystemRoot(RAZOR_ADMIN_FILENAME) . RAZOR_BACKUP_DIR, 0755);
    }
    if (isset($_GET['backup']) && $_GET['backup']) {
        $fileName = str_replace(array(',', "'", '"', '?', '/', '*', '(', ')', '@', '!', '&', '=', '<', '>'), '', $_POST['backupname']);
        $errorMsg = backupTool_checkName($fileName);
        if (!$errorMsg) {
            // do backup //
            $tempfileArray = array();
            getDirectory($tempfileArray, getSystemRoot(RAZOR_ADMIN_FILENAME) . RAZOR_DATASTORE_DIR);
            $zipfilename = $fileName . '.zip';
            // form is posted, handle it
            $zipfile = new zipfile();
            // new stuff //
            foreach ($tempfileArray as $file) {
                $f_tmp = @fopen($file, 'r');
                if ($f_tmp) {
                    $dump_buffer = fread($f_tmp, filesize($file));
                    $tempFile = explode('../', $file);
                    $zipfile->addFile($dump_buffer, $tempFile[1]);
                    fclose($f_tmp);
                }
            }
            // new stuff //
            $dump_buffer = $zipfile->file();
            // write the file to disk //
            if (put2file(RAZOR_BACKUP_DIR . $zipfilename, $dump_buffer, strlen($dump_buffer))) {
                MsgBox(lt('Backup created'), 'greenbox');
            } else {
                MsgBox(lt('Error creating backup'), 'redbox');
            }
        } else {
            MsgBox($errorMsg, 'redbox');
        }
    }
    if (isset($_GET['restore']) && $_GET['restore'] && $_SESSION['adminType'] != 'user') {
        set_time_limit(60);
        // new - clean datastore first //
        $cleanfileArray = array();
        getDirectory($cleanfileArray, getSystemRoot(RAZOR_ADMIN_FILENAME) . RAZOR_DATASTORE_DIR);
        foreach ($cleanfileArray as $file) {
            if ($file != 'razor_data.txt') {
                // try using the delete function here so this works with ftp mode too //
                unlink($file);
                // try using the delete function here so this works with ftp mode too //
            }
        }
        $zip = new SimpleUnzip();
        $filename = getSystemRoot(RAZOR_ADMIN_FILENAME) . RAZOR_BACKUP_DIR . $_GET['restore'];
        $entries = $zip->ReadFile($filename);
        $restoreMess = '';
        $restoreOK = 'greenbox';
        foreach ($entries as $entry) {
            // check dir exists, if not create it //
            if ($entry->Path != '' && !file_exists('../' . $entry->Path)) {
                $splitPath = array();
                $splitPath = explode('/', $entry->Path);
                $checkPath = '..';
                foreach ($splitPath as $pathBit) {
                    $checkPath .= '/' . $pathBit;
                    if (!file_exists($checkPath)) {
                        mkdir($checkPath, 0755);
                    }
                }
            }
            // check end //
            if (put2file($entry->Path . '/' . $entry->Name, $entry->Data)) {
                $restoreMess .= lt('Restoring') . " {$entry->Name} <br />";
            } else {
                $restoreMess .= lt('error restoring') . " {$entry->Name} <br />";
                $restoreOK = 'redbox';
            }
        }
        MsgBox($restoreMess, $restoreOK);
    }
    if (isset($_GET['delete']) && $_GET['delete']) {
        deleteFile(RAZOR_BACKUP_DIR . $_GET['delete']);
    }
    if (isset($_GET['upload']) && $_GET['upload'] && isset($_POST['upload']) && $_SESSION['adminType'] != 'user') {
        $filename = basename($_FILES['file-upload']['name']);
        $stripFileName = explode('.', $filename);
        if (end($stripFileName) == 'zip') {
            $backupDir = getSystemRoot(RAZOR_ADMIN_FILENAME) . RAZOR_BACKUP_DIR;
            $backupFiles = readDirContents($backupDir);
            $counter = 0;
            while (in_array($filename, $backupFiles)) {
                $counter++;
                $filename = $stripFileName[0] . '(' . $counter . ')' . '.' . $stripFileName[1];
            }
            $result = uploadFile(RAZOR_BACKUP_DIR . $filename, $_FILES['file-upload']['tmp_name']);
        } else {
            MsgBox(lt("Wrong file type, only zip files allowed"), 'redbox');
        }
    }
    // setup output //
    if (file_exists(getSystemRoot(RAZOR_ADMIN_FILENAME) . RAZOR_BACKUP_DIR)) {
        if ($handle = opendir(getSystemRoot(RAZOR_ADMIN_FILENAME) . RAZOR_BACKUP_DIR)) {
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != "..") {
                    $fileDate = filemtime(getSystemRoot(RAZOR_ADMIN_FILENAME) . RAZOR_BACKUP_DIR . $file);
                    $backupList[$file] = $fileDate;
                }
            }
            closedir($handle);
        }
    }
    // end setup //
    asort($backupList);
    $deleteConfirmMsg = lt("Are you sure you want to delete this backup, remember once you delete you cannot retreive again, proceed") . '?';
    $restoreConfirmMsg = lt("Are you sure you want to restore this backup, remember once you restore all old data will be lost, proceed") . '?';
    echo "<h1>" . lt('Backup Tool') . "</h1>";
    echo '<div class="contentwh">';
    echo '<h3>' . lt('Archived Backups') . '</h3>';
    echo "<table class='tableViewBackup'>";
    echo "<tr class='tableFooter'><th class='twentyFive'>" . lt('Date Created') . "</th><th class='auto'>" . lt('File Name') . "</th><th class='twenty'>" . lt('Options') . "</th></tr>";
    $restoreBackup = '';
    foreach ($backupList as $bkFile => $bkFileDate) {
        if ($_SESSION['adminType'] != 'user') {
            $restoreBackup = "<a href='?action=backuptool&restore={$bkFile}' title='" . lt('Restore') . "' onclick='return confirm(\"{$restoreConfirmMsg}\");'><img class='updown' src='theme/images/restore.gif' alt=" . lt('restore') . " /></a> ";
        }
        $formatDT = date("d-m-Y H:i:s", $bkFileDate);
        echo "<tr><td>{$formatDT}</td><td>{$bkFile}</td><td>" . $restoreBackup . "<a href='../datastore/backup/{$bkFile}' title='" . lt('Download') . "'><img class='edit' src='theme/images/download.gif' alt=" . lt('download') . " /></a> <a href='?action=backuptool&delete={$bkFile}' title='" . lt('Delete') . "' onclick='return confirm(\"{$deleteConfirmMsg}\");'><img class='delete' src='theme/images/trash.gif' alt=" . lt('delete') . " /></a></td></tr>";
    }
    echo "<tr class='tableFooter'><th class='twentyFive'></th><th class='auto'></th><th class='twentyFive'></th></tr></table>";
    echo '<h3>' . lt('Create New Backup') . '</h3>';
    echo "<form action='?action=backuptool&backup=true' method='post'>";
    echo "<table class='tableViewBackup'>";
    echo "<tr class='tableFooter'><th class='auto'></th><th class='ten'></th></tr>";
    echo "<tr><td><input type='text' name='backupname' value=''>.zip</td><td><input id='button' type='submit' value='" . lt('Submit') . "' class='floatright'></td></tr>";
    echo "<tr class='tableFooter'><th class='twentyFive'></th><th class='auto'></th></tr></table></form>";
    if ($_SESSION['adminType'] != 'user') {
        echo '<h3>' . lt('Upload to Archived Backups') . '</h3>';
        echo "<p>" . lt('Upload limit per file') . ' - ' . ini_get('upload_max_filesize') . "</p>";
        echo '<p>' . lt('Please upload backups in zip format. Please note that file upload is limited by your server, razorCMS attempts to up this limit to 100mb per file but your server may restrict access. If the limit above is not set to 100mb, please visit the help forum on other ways to increase this limit.') . '</p>';
        echo '<form enctype="multipart/form-data" action="?action=backuptool&upload=true" method="POST">';
        echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . getMaxUploadSize(ini_get('upload_max_filesize')) . '" />';
        echo "<table class='tableViewBackup'>";
        echo "<tr class='tableFooter'><th class='auto'></th><th class='ten'></th></tr>";
        echo '<tr><td><input name="file-upload" type="file" /></td><td><input id="button" type="submit" value="' . lt('upload file') . '" name="upload"/></td></tr>';
        echo "<tr class='tableFooter'><th class='twentyFive'></th><th class='auto'></th></tr></table></form>";
    }
    echo "</div>";
}
예제 #14
0
<?php

$unzip = new SimpleUnzip();
$backupdir = substr($datafile_server, 8, 13);
$unzip->ReadFile($datafile_server);
예제 #15
0
 /**
  * @Title: getNextSql 
  * @Description: todo(显示) 
  * @return string|boolean  
  * @author laicaixia 
  * @date 2013-5-31 下午5:27:02 
  * @throws 
  */
 public function show()
 {
     $filename = $_GET['filename'];
     $folder = urldecode($_GET['folder']);
     $gbk_folder = @iconv('UTF-8', 'gb2312', $folder);
     $folderdir = R("Backup/getBackupDir");
     $file = $folderdir . '/' . $gbk_folder . '/' . $filename;
     if (file_exists($file)) {
         import("@.ORG.Zip");
         $unzip = new SimpleUnzip($file);
         $unzip->SimpleUnzip();
         $dbname = C('DB_NAME');
         $tables = '';
         $file_count = $unzip->Count();
         for ($i = 0; $i < $file_count; $i++) {
             if ($unzip->GetName($i) == C('BACKUP_RECORD_FILE')) {
                 $tables = $unzip->GetData($i);
                 break;
             }
         }
         $tables = explode(',', $tables);
         $html_show = '';
         foreach ($tables as $table) {
             if ($table != C('BACKUP_TABLE') && $table != C('UPGRADE_TABLE')) {
                 $html_show .= "<label style='width:300px;'><input name='table' type='checkbox' value='{$table}' />{$table}</label>";
             }
         }
         $this->assign('html_show', $html_show);
         $this->assign('file', $filename);
         $this->assign('folder', $folder);
     }
     //还原模式显示
     if (C('RESUME_MODEL') == 'Database') {
         $modelInfo = "当前还原模式为:数据库级<br/>还原失败所有数据均不会被还原!";
     } else {
         if (C('RESUME_MODEL') == 'Table') {
             $modelInfo = "当前还原模式为:数据表级<br/>还原失败只有出错表数据不还原!";
         }
     }
     $this->assign('modelInfo', $modelInfo);
     $this->display();
 }
예제 #16
0
 function extractContents($fileName)
 {
     $zip = new SimpleUnzip();
     $this->zipContents = $zip->ReadFile('../' . $fileName);
 }