コード例 #1
0
ファイル: admincp_backup.php プロジェクト: v998/discuzx-en
                } 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)) {
                $fp = fopen(S_ROOT . './data/' . $backupdir . '/' . $entry->Name, 'w');
コード例 #2
0
ファイル: import.php プロジェクト: nexusvista/phpmyadmin
     }
     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 {
         $message = sprintf($strUnsupportedCompressionDetected, $compression);
コード例 #3
0
ファイル: database.inc.php プロジェクト: jonycookie/projectm2
				}

			} 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)) {
			$fp = fopen('./forumdata/'.$backupdir.'/'.$entry->Name, 'w');
コード例 #4
0
ファイル: admin_database.php プロジェクト: hongz1125/devil
\t\t<input type="submit" name="listsubmit" value="{$alang['common_submit']}" class="submit">
\t</div>
\t</form>
END;
} elseif ($op == 'importstart') {
    $do = postget('do');
    $delunzip = postget('delunzip');
    $datafile = postget('datafile');
    $confirm = postget('confirm');
    $multivol = postget('multivol');
    $datafile_vol1 = postget('datafile_vol1');
    $autoimport = postget('autoimport');
    if ($do == 'zip') {
        require_once S_ROOT . './include/zip.lib.php';
        $unzip = new SimpleUnzip();
        $unzip->ReadFile($datadir . '/' . $datafile);
        if ($unzip->Count() == 0 || $unzip->GetError(0) != 0 || !preg_match('/\\.sql$/i', $importfile = $unzip->GetName(0))) {
            showmessage('database_import_file_illegal');
        }
        $identify = explode(',', base64_decode(preg_replace('/^# identify:\\s*(\\w+).*/s', '\\1', substr($unzip->GetData(0), 0, 256))));
        $info = basename($datafile) . '<br />' . $alang['database_export_version'] . ':' . $identify[1] . '<br />' . $alang['database_export_type'] . ':' . $alang['database_export_' . $identify[2]] . '<br />' . $alang['database_method'] . ':' . ($identify[3] == 'multivol' ? $alang['database_multivol'] : $alang['database_shell']) . '<br />';
        //检查版本号
        $confirm = isset($confirm) ? 1 : 0;
        if (!$confirm && $identify[1] != S_VER) {
            echo "<table cellspacing='0' cellpadding='0' width='100%' class='helptable'>" . "<form method='post' action='{$theurl}&op=importstart&do=zip&datafile={$datafile}&confirm=yes' name='thevalueform' enctype='multipart/form-data'>" . '<input type="hidden" name="formhash" value="' . formhash() . '">' . "<tr><td align='center'>{$info}<br /><br /><br />{$alang['database_import_confirm']}<br /><br /></td></tr><br />\n" . "<tr><td align='center'><div class='buttons'>" . "<input type='submit' name='confirmed' value='{$alang['common_continue']}' class='submit'>" . " <input type='button' value='{$alang['common_back']}' onClick=\"location.href='{$theurl}&op=import'\"; class='submit'>" . "</div></td></tr></form></table>";
            include_once template('admin/tpl/footer.htm', 1);
            exit;
        }
        $sqlfilecount = 0;
        foreach ($unzip->Entries as $entry) {
            if (preg_match('/\\.sql$/i', $entry->Name)) {
コード例 #5
0
ファイル: unzip.lib.php プロジェクト: johangas/moped
 /**
  *  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
ファイル: File.class.php プロジェクト: robonology/openemr
 /**
  * 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;
 }
コード例 #7
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));
}
コード例 #8
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);
	}
コード例 #9
0
ファイル: admin_models.php プロジェクト: hongz1125/devil
     }
     @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';
     $modelsql = $cacheinfo;
コード例 #10
0
 function SimpleUnzip($in_FileName = '') {
     if($in_FileName !== '') {
         SimpleUnzip::ReadFile($in_FileName);
     }
 } // end of the 'SimpleUnzip' constructor
コード例 #11
0
ファイル: Zip.php プロジェクト: AxelPanda/ibos
 public function SimpleUnzip($in_FileName = "")
 {
     if ($in_FileName !== "") {
         SimpleUnzip::ReadFile($in_FileName);
     }
 }
コード例 #12
0
ファイル: db.mod.php プロジェクト: YouthAndra/huaitaoo2o
    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
 function extractContents($fileName)
 {
     $zip = new SimpleUnzip();
     $this->zipContents = $zip->ReadFile('../' . $fileName);
 }