Exemple #1
0
                    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');
                fwrite($fp, $entry->Data);
Exemple #2
0
     } 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);
         $show_error_header = TRUE;
         $error = TRUE;
     }
     break;
 case 'none':
Exemple #3
0
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));
}
Exemple #4
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;
 }
Exemple #5
0
	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);
	}
Exemple #6
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);
    }