0) {
$s1=$s2=0;
for ($i = 0; $i < $databases["Detailinfo"]["tables"]; $i++)
{
$row = mysql_fetch_array($res);
$s1+=$row["Rows"];
$s2+=$row["Data_length"]+$row["Index_length"];
}
$databases["Detailinfo"]["records"]=$s1;
$databases["Detailinfo"]["size"]=$s2;
}
}
//Globale Funktionen
function br($m=1)
{
//gibt m Zeilenumbrüche zurück
return str_repeat("\n",$m);
}
function Stringformat($s,$count)
{
return str_repeat("0",$count-strlen($s)).$s;
}
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function MD_FreeDiskSpace()
{
global $lang;
$dfs=@diskfreespace("../");
return ($dfs) ? byte_output($dfs) : $lang['notavail'];
}
function WriteDynamicText($txt,$object)
{
return '';
}
function byte_output($bytes, $precision = 2, $names = Array())
{
if (!is_numeric($bytes) || $bytes < 0) {
return false;
}
for ($level = 0; $bytes >= 1024; $level++) {
$bytes /= 1024;
}
switch ($level)
{
case 0:
$suffix = (isset($names[0])) ? $names[0] : 'Bytes';
break;
case 1:
$suffix = (isset($names[1])) ? $names[1] : 'KB';
break;
case 2:
$suffix = (isset($names[2])) ? $names[2] : 'MB';
break;
case 3:
$suffix = (isset($names[3])) ? $names[3] : 'GB';
break;
case 4:
$suffix = (isset($names[4])) ? $names[4] : 'TB';
break;
default:
$suffix = (isset($names[$level])) ? $names[$level] : '';
break;
}
return round($bytes, $precision) . ' ' . $suffix;
}
function ExtractDBname($s)
{
if(strpos(strtolower($s),"_structure_file")>0){
return substr($s,0,strpos(strtolower($s),"_structure_file"));
break;
}
$sp=explode("_",$s);
$anz=count($sp)-1;
$r=0;
if($anz>4) {
$df=5; //Datumsfelder
if($sp[$anz-1]=="part") $df+=2;
if($sp[$anz-3]=="crondump" || $sp[$anz-1]=="crondump") $df+=2;
$anz=$anz-$df; //Datum weg
for($i=0;$i<=$anz;$i++){ $r+=strlen($sp[$i])+1;}
return substr($s,0,$r-1);
} else {
//Fremdformat
return substr($s,0,strpos($s,"."));
}
}
function ExtractBUT($s)
{
$i=strpos(strtolower($s),"part");
if($i>0) $s=substr($s,0,$i-1);
$i=strpos(strtolower($s),"crondump");
if($i>0) $s=substr($s,0,$i-1);
$i=strpos(strtolower($s),".sql");
if($i>0) $s=substr($s,0,$i);
$sp=explode("_",$s);
$anz=count($sp)-1;
if($anz>4) {
return $sp[$anz-2].".".$sp[$anz-3].".".$sp[$anz-4]." ".$sp[$anz-1].":".$sp[$anz];
} else {
//Fremdformat
return "";
}
}
function WriteLog($aktion)
{
global $config;
//Zeile zusammensetzen
$log=date("d.m.Y h:i:s").': '.$aktion."\n";
//Datei öffnen und schreiben
$fp = @fopen($config["files"]["log"], "a+");
if($fp) {
@fwrite ($fp,($log));
@fclose ($fp);
} else echo '
Log-File kann nicht geschrieben werden!
';
}
function WriteTempOut($aktion)
{
global $config;
$fp = @fopen($config["paths"]["log"]."out.tmp", "w");
if($fp) {
@fwrite ($fp,$aktion);
@fclose ($fp);
}
}
function WritePageParams($aktion)
{
global $config,$restore,$dump,$nl;
$pars="$nl";
if($aktion=="dump") {
$datei="dump.tmp";
foreach($dump as $var => $val){
if(is_array($val)) {
foreach($val as $var2 => $val2){
if ($config["magic_quotes_gpc"]==0) {
$pars.='$dump["'."$var\"][".((is_int($var2)) ? $var2 : '"'.$var2.'"')."] = \"".addslashes($val2)."\";$nl";
} else {
$pars.='$dump["'."$var\"][".((is_int($var2)) ? $var2 : '"'.$var2.'"')."] = \"$val2\";$nl";
}
}
} else {
if ($config["magic_quotes_gpc"]==0) {
$pars.='$dump["'."$var\"] = \"".addslashes($val)."\";$nl";
} else {
$pars.='$dump["'."$var\"] = \"$val\";$nl";
}
}
}
} elseif($aktion=="restore") {
$datei="restore.tmp";
foreach($restore as $var => $val){
if(is_array($val)) {
foreach($val as $var2 => $val2){
if ($config["magic_quotes_gpc"]==0) {
$pars.='$restore["'."$var\"][".((is_int($var2)) ? $var2 : '"'.$var2.'"')."] = \"".addslashes($val2)."\";$nl";
} else {
$pars.='$restore["'."$var\"][".((is_int($var2)) ? $var2 : '"'.$var2.'"')."] = \"$val2\";$nl";
}
}
} else {
if ($config["magic_quotes_gpc"]==0) {
$pars.='$restore["'."$var\"] = \"".addslashes($val)."\";$nl";
} else {
$pars.='$restore["'."$var\"] = \"$val\";$nl";
}
}
}
}
$pars.="$nl?>";
$fp = @fopen($config["paths"]["log"].$datei, "w");
if($fp) {
@fwrite ($fp,$pars."\n");
@fclose ($fp);
}
}
function ErrorLog($dest,$db,$sql,$error)
{
global $config;
//Error-Zeile generieren
$errormsg=date("d.m.Y h:i:s").': ';
$errormsg.=($dest=="RESTORE") ? " Restore of db `$db`\n" : " Dump of db `$db`\n";
$errormsg.="Error-Message: $error\n";
$errormsg.="SQL : ".$sql."\n\n";
//Datei öffnen und schreiben
$fp = @fopen($config["paths"]["log"]."error.log", "a+");
if($fp) {
@fwrite ($fp,($errormsg));
@fclose ($fp);
}
}
function DirectoryWarnings($path="")
{
global $config;
$warn="";
if($path=="" || $path=="config") if(!is_writable($config["paths"]["config"])) $warn.='Configpath is not writable!
';
if($path=="" || $path=="backup") if(!is_writable($config["paths"]["backup"])) $warn.='Backuppath is not writable!
';
if($path=="" || $path=="structure") if(!is_writable($config["paths"]["structure"])) $warn.='Structurepath is not writable!
';
if($path=="" || $path=="log") if(!is_writable($config["paths"]["log"])) $warn.='Logpath is not writable!
';
if($warn!="") $warn='ERROR !
'.$warn.'';
return $warn;
}
function TestWorkDir()
{
global $config;
//echo "work_chmod: $config["paths"]["work"]_chmod
";
SetFileRechte($config["paths"]["work"]);
SetFileRechte($config["paths"]["backup"]);
SetFileRechte($config["paths"]["structure"]);
SetFileRechte($config["paths"]["log"]);
SetFileRechte($config["paths"]["config"]);
if(!file_exists($config["files"]["parameter"])) SetDefault();
if(!file_exists($config["files"]["log"])) DeleteLog();
}
function SetFileRechte($file,$perm="0777")
{
global $lang;
if(substr($file,-1)!="/") $file.="/";
if(strlen($perm)!=4 || intval($perm)==0 || intval($perm)>777) $perm="0777";
if( (ini_get('safe_mode')==1) && (!(is_dir($file))) )
{
echo $lang['critical_safemode'];
return 0;
} else {
clearstatcache();
if (!@is_dir($file)) @mkdir($file, $perm);
clearstatcache();
$a=@substr(decoct(fileperms($file)),-4);
$ret=1;
if($a!=$perm && (ini_get('safe_mode')!=1)) {
$ret=@chmod($file,$perm);
}
return $ret;
}
}
function SelectDB($index)
{
global $databases;
$databases["db_actual"] = $databases["Name"][$index];
$databases["praefix"][$databases["db_selected_index"]] = $databases["praefix"][$index];
$databases["db_selected_index"]=$index;
}
function EmptyDB($dbn)
{
$res=mysql_query("DROP DATABASE `$dbn`") or die(mysql_error()."");
$res=mysql_query("CREATE DATABASE `$dbn`") or die(mysql_error()."");
}
function AutoDelete()
{
global $del_files, $config, $lang,$out;
//Files einlesen
$dh = opendir($config["paths"]["backup"]);
$dbbackups=Array();
while (false !== ($filename = readdir($dh)))
{
if ($filename != "." && $filename != ".." && !is_dir($config["paths"]["backup"].$filename)) {
//statuszeile auslesen
if(substr($filename,-2)=="gz"){
$fp = gzopen ($config["paths"]["backup"].$filename, "r");
$statusline=gzgets($fp,40960);
gzclose ($fp);
}else{
$fp = fopen ($config["paths"]["backup"].$filename, "r");
$statusline=fgets($fp,500);
fclose ($fp);
}
$sline=ReadStatusline($statusline);
if($sline[0]=="9999") {
$tabellenanzahl="";
$eintraege="";
} else {
$tabellenanzahl=$sline[0];
$eintraege=$sline[1];
}
$part=($sline[2]=="") ? 0 : substr($sline[2],3);
$databases["db_actual"]=$sline[3];
$datum=substr($filename,strlen($databases["db_actual"])+1);
$datum=substr($datum,0,16);
if(isset($dbbackups[$databases["db_actual"]])) $dbbackups[$databases["db_actual"]]++; else $dbbackups[$databases["db_actual"]]=1;
$files[] = "$datum|".$databases["db_actual"]."|$part|$filename";
}
}
@rsort($files);
// Mehr Dateien vorhanden, als es laut config.php sein dürften? Dann weg damit :-)
if($config["del_files_after_days"]>0) {
$nowtime=strtotime("-".($config["del_files_after_days"]+1)." day");
for($i=0; $i 0)
{
if (sizeof($files) > $config["max_backup_files"])
{
if($config["max_backup_files_each"]==1) {
//gilt es nur für jede Datenbank
for($i=sizeof($files)-1; $i>=0; $i--)
{
$delfile=explode("|",$files[$i]);
if($dbbackups[$delfile[1]] > $config["max_backup_files"])
{
$out.=DeleteFile($files[$i],"max");
unset($files[$i]);
$dbbackups[$delfile[1]]--;
}
}
} else {
//oder gilt es für alle Backups
for($i=sizeof($files)-1; $i>=$config["max_backup_files"]; $i--)
{
$delfile=implode("|",$files);
$out.=DeleteFile($files[$i],"max");
unset($files[$i]);
}
}
}
}
return $out;
}
function DeleteFile($files,$function)
{
global $config,$lang;
$delfile=explode("|",$files);
$ll=($function=="max") ? $lang["fm_autodel1"]:$lang["fm_autodel2"];
$r="".$ll."
";
$r.= $delfile[3]."
";
WriteLog("autodeleted ($function) '$delfile[3]'.");
unlink($config["paths"]["backup"].$delfile[3]);
$r.= "";
return $r;
}
function ReadStatusline($line)
{
//Format # Status:Tabellen:Datensätze:Multipart:DBname
if(substr($line,0,8)!="# Status") {
$s=Array("-1","-1","","","","","","");
} else {
$s=explode(":",$line);
array_shift($s);
if(count($s)<7) {
for($i=count($s);$i<8;$i++) {$s[]="";}
}
}
return $s;
}
function NextPart($s,$first=0) {
$nf=explode("_",$s);
$i=array_search("part",$nf)+1;
$p=substr($nf[$i],0,strpos($nf[$i],"."));
$ext=substr($nf[$i],strlen($p));
if($first==1) {
$nf[$i]="1".$ext;
} else {
$nf[$i]=++$p.$ext;
}
return implode("_",$nf);
}
function zeit_format($t)
{
$tt_m=floor($t/60);
$tt_s=$t-($tt_m*60);
return $tt_m.' min. '.floor($tt_s).' sec';
}
function ErrorReport()
{
global $config,$PHP_SELF,$PATH,$PATH_TRANSLATED,$SCRIPT_FILENAME,$SCRIPT_NAME,$email,$_SERVER;
$error_kind=$error_aus="";
if(isset($_POST["p"]) && $_POST["p"]==1) {
//von Programmfehler geposted
$error_kind=$_POST["error_kind"];
$error_aus=$_POST["error_aus"];
}
if(isset($_POST["create_sql"])) {
//vom Parser
$error_kind="Parser-Fehler";
$error_aus=stripslashes(trim($_POST["create_sql"]))."\n\n\n".stripslashes(trim($_POST["insert_sql"]));
}
$subject = "Fehlerbericht vom ".date("d.m.Y H:s");
$r= '