<?php
//超时设置
if($php_outtime)
{
$php_outtime=(int)$php_outtime;
@set_time_limit($php_outtime);
}
//--------------------------------------错误提示
function printerror($error="",$gotourl="",$ecms=0){
global $empire,$public_r,$editor;
if($editor==1){$a="../";}
elseif($editor==2){$a="../../";}
elseif($editor==3){$a="../../../";}
else{$a="";}
if(strstr($gotourl,"(")||empty($gotourl))
{
$gotourl_js="history.go(-1)";
$gotourl="javascript:history.go(-1)";
}
else
{$gotourl_js="self.location.href='$gotourl';";}
if(empty($error))
{$error="DbError";}
if($ecms==0)
{
@include $a.LoadLang("m.php");
$error=$message_r[$error];
@include $a.LoadAdminTemp('message.php');
}
elseif($ecms==9)//弹出对话框
{
@include $a.LoadLang("m.php");
$error=$message_r[$error];
echo"<script>alert('".$error."');".$gotourl_js."</script>";
}
exit();
}
//--------------------------------------字符截取
function sub_str($title,$lengh){
if(strlen($title)>$lengh)
{
$pp=2;
$len=strlen($title);
if($len%2<>0)
{$pp=1;}
$title=substr($title,0,$lengh-$pp);
$title=$title.' …';
}
return $title;
}
//--------------------------------------取得文件扩展名
function GetFiletype($filename){
$filer=explode(".",$filename);
$count=count($filer)-1;
return strtolower(".".$filer[$count]);
}
//--------------------------------------字符截取函数2
function sub($Modi_Str,$start,$length,$mode = false){
$n = 0;
for($i=0;$i<$start;$i++){
if(ord(substr($Modi_Str,$i,1))>0xa0){
if($mode){
$start++;
$i++;
}
$n++;
}
}
if(!$mode)$start = $start + $n%2;
$The_length = $start+$length;
for($i=$start;$i<$The_length;$i++){
if(ord(substr($Modi_Str,$i,1))>0xa0){
$The_Str.=substr($Modi_Str,$i,2);
$i++;
if($mode) $The_length++;
}else{
$The_Str.=substr($Modi_Str,$i,1);
}
}
return $The_Str;
}
//--------------------------------------取得随机数
function make_password($pw_length){
$low_ascii_bound=50;
$upper_ascii_bound=122;
$notuse=array(58,59,60,61,62,63,64,73,79,91,92,93,94,95,96,108,111);
while($i<$pw_length)
{
mt_srand((double)microtime()*1000000);
$randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
if(!in_array($randnum,$notuse))
{
$password1=$password1.chr($randnum);
$i++;
}
}
return $password1;
}
//-------------------------------字符过虑
function escape_str($str){
$str=mysql_escape_string($str);
$str=str_replace('\\\'','\'\'',$str);
$str=str_replace("\\\\","\\\\\\\\",$str);
$str=str_replace('$','\$',$str);
return $str;
}
//-------------------------------删除文件
function DelFiletext($filename){
@unlink($filename);
}
//---------------------------------取得文件内容
function ReadFiletext($filepath){
$htmlfp=@fopen($filepath,"r");
while($data=@fread($htmlfp,1000))
{
$string.=$data;
}
@fclose($htmlfp);
return $string;
}
//--------------------------------写文件
function WriteFiletext($filepath,$string){
global $filechmod;
$string=stripSlashes($string);
$fp=@fopen($filepath,"w");
@fputs($fp,$string);
@fclose($fp);
if(empty($filechmod))
{
@chmod($filepath,0777);
}
}
//--------------------------------写文件
function WriteFiletext_n($filepath,$string){
global $filechmod;
$fp=@fopen($filepath,"w");
@fputs($fp,$string);
@fclose($fp);
if(empty($filechmod))
{
@chmod($filepath,0777);
}
}
//-----------------------------建立目录函数
function DoMkdir($path){
global $public_r;
//不存在则建立
if(!file_exists($path))
{
//安全模式
if($public_r[phpmode])
{
$pr[0]=$path;
FtpMkdir($ftpid,$pr);
$mk=1;
}
else
{
$mk=@mkdir($path,0777);
}
@chmod($path,0777);
if(empty($mk))
{
printerror("NotMkdir","history.go(-1)");
}
}
return true;
}
//------------------------------是否登陆
function islogin($lusername,$rnd){
global $set_username,$set_outtime;
if(empty($lusername)||empty($rnd))
{
printerror("NotLogin","index.php");
}
if($lusername<>$set_username)
{
printerror("NotLogin","index.php");
}
$time=time();
if($time-getcvar('baklogintime')>$set_outtime*60)
{
printerror("OutLogintime","index.php");
}
$s2=esetcookie("baklogintime",$time,0);
}
//--------------------------替换目录值
function RepPathStr($path){
$path=str_replace("\\","",$path);
$path=str_replace("/","",$path);
return $path;
}
//---------------------------备份
//初使化备份
function Ebak_DoEbak($add){
global $empire,$bakpath,$fun_r,$phome_db_ver;
$dbname=RepPostVar($add['mydbname']);
if(empty($dbname))
{
printerror("NotChangeDb","history.go(-1)");
}
$tablename=$add['tablename'];
$count=count($tablename);
if(empty($count))
{
printerror("EmptyChangeTb","history.go(-1)");
}
$add['baktype']=(int)$add['baktype'];
$add['filesize']=(int)$add['filesize'];
$add['bakline']=(int)$add['bakline'];
$add['autoauf']=(int)$add['autoauf'];
if((!$add['filesize']&&!$add['baktype'])||(!$add['bakline']&&$add['baktype']))
{
printerror("EmptyBakFilesize","history.go(-1)");
}
//目录名
if(empty($add['mypath']))
{
$add['mypath']=$dbname."_".date("YmdHis");
}
DoMkdir($bakpath."/".$add['mypath']);
//生成说明文件
$readme=$add['readme'];
$rfile=$bakpath."/".$add['mypath']."/readme.txt";
$readme.="\r\n\r\nBaktime: ".date("Y-m-d H:i:s");
WriteFiletext_n($rfile,$readme);
$b_table="";
$d_table="";
for($i=0;$i<$count;$i++)
{
$b_table.=$tablename[$i].",";
$d_table.="\$tb[".$tablename[$i]."]=0;\r\n";
}
//去掉最后一个,
$b_table=substr($b_table,0,strlen($b_table)-1);
$bakstru=(int)$add['bakstru'];
$bakstrufour=(int)$add['bakstrufour'];
$beover=(int)$add['beover'];
$waitbaktime=(int)$add['waitbaktime'];
if($add['insertf']=='insert')
{
$insertf='insert';
}
else
{
$insertf='replace';
}
if($phome_db_ver=='4.0'&&$add['dbchar']=='auto')
{
$add['dbchar']='';
}
$string="<?php
\$b_table=\"".$b_table."\";
".$d_table."
\$b_baktype=".$add['baktype'].";
\$b_filesize=".$add['filesize'].";
\$b_bakline=".$add['bakline'].";
\$b_autoauf=".$add['autoauf'].";
\$b_dbname=\"".$dbname."\";
\$b_stru=".$bakstru.";
\$b_strufour=".$bakstrufour.";
\$b_dbchar=\"".addslashes($add['dbchar'])."\";
\$b_beover=".$beover.";
\$b_insertf=\"".addslashes($insertf)."\";
\$b_autofield=\",".addslashes($add['autofield']).",\";
?>";
$cfile=$bakpath."/".$add['mypath']."/config.php";
WriteFiletext_n($cfile,$string);
if($add['baktype'])
{
$phome='BakExeT';
}
else
{
$phome='BakExe';
}
echo $fun_r['StartToBak']."<script>self.location.href='phome.php?phome=$phome&t=0&s=0&p=0&mypath=$add[mypath]&waitbaktime=$waitbaktime';</script>";
exit();
}
//--------------------时间转换
function ToChangeUseTime($time){
global $fun_r;
$usetime=time()-$time;
if($usetime<60)
{
$tstr=$usetime.$fun_r['TimeSecond'];
}
else
{
$usetime=round($usetime/60);
$tstr=$usetime.$fun_r['TimeMinute'];
}
return $tstr;
}
//--------------------执行备份(按文件大小)
function Ebak_BakExe($t,$s,$p,$mypath,$alltotal,$thenof,$fnum,$stime=0){
global $empire,$bakpath,$limittype,$fun_r;
if(empty($mypath))
{
printerror("ErrorUrl","history.go(-1)");
}
$path=$bakpath."/".$mypath;
@include($path."/config.php");
if(empty($b_table))
{
printerror("ErrorUrl","history.go(-1)");
}
$waitbaktime=(int)$_GET['waitbaktime'];
if(empty($stime))
{
$stime=time();
}
$header="<?php
@include(\"../../inc/header.php\");
";
$footer="
@include(\"../../inc/footer.php\");
?>";
$btb=explode(",",$b_table);
$count=count($btb);
$t=(int)$t;
$s=(int)$s;
$p=(int)$p;
//备份完毕
if($t>=$count)
{
echo"<script>alert('".$fun_r['BakSuccess']."\\n\\n".$fun_r['TotalUseTime'].ToChangeUseTime($stime)."');self.location.href='ChangeDb.php';</script>";
exit();