1
0
Fork 0
Dieser Commit ist enthalten in:
DSB 2011-06-10 22:58:43 +00:00
Commit 25d3a3ee93
246 geänderte Dateien mit 25170 neuen und 0 gelöschten Zeilen

15
mysqldumper/inc/footer.php Normale Datei
Datei anzeigen

@ -0,0 +1,15 @@
<?php
$config_array=(isset($config)) ? "<strong>CONFIG</strong><pre>".@print_r($config,true)."</pre>": "";
$database_array=(isset($database)) ? "<strong>DATABASE</strong><pre>".@print_r($database,true)."</pre>": "";
$dump_array=(isset($dump)) ? "<strong>DUMP</strong><pre>".@print_r($dump,true)."</pre>": "";
$restore_array=(isset($restore)) ? "<strong>RESTORE</strong><pre>".@print_r($restore,true)."</pre>" : "";
echo '<p align="center" class="small">'.$lang['authors'].':&nbsp;
<a class="small" href="http://www.daniel-schlichtholz.de" target="_blank">
Daniel Schlichtholz &amp; Steffen Kamper</a> - Infoboard:
<a class="small" href="'.$config['homepage'].'" target="_blank">'.
$config['homepage'].'</a></p>';
echo '</div></body></html>';
?>

523
mysqldumper/inc/functions.php Normale Datei
Datei anzeigen

@ -0,0 +1,523 @@
<?php
include_once('./inc/functions_global.php');
include_once('./inc/mysql.php');
function Help($ToolTip,$Anker,$imgsize=12)
{
global $config;
if($Anker!=""){
return '<a href="language/'.$config['language'].'/help.php#'.$Anker.'" title="'.$ToolTip.'"><img src="'.$config['files']['iconpath'].'help16.gif" width="'.$imgsize.'" height="'.$imgsize.'" hspace="'.(round($imgsize/4,0)).'" vspace="0" border="0" alt="Help"></a>';
} else {
return '<img src="'.$config['files']['iconpath'].'help16.gif" width="'.$imgsize.'" height="'.$imgsize.'" alt="Help" title="'.$ToolTip.'" border="0" hspace="'.(round($imgsize/4,0)).'" vspace="0" >';
}
}
function DeleteFilesM($dir, $pattern = "*.*")
{
$deleted = false;
$pattern = str_replace(array("\*","\?"), array(".*","."), preg_quote($pattern));
if (substr($dir,-1) != "/") $dir.= "/";
if (is_dir($dir))
{ $d = opendir($dir);
while ($file = readdir($d))
{ if (is_file($dir.$file) && ereg("^".$pattern."$", $file))
{
if (unlink($dir.$file)) $deleted[] = $file;
}
}
closedir($d);
return $deleted;
}
else return 0;
}
function SetDefault($load_default=false)
{
global $config,$databases,$nl,$out,$lang,$preConfig;
//Arrays löschen
$i=0;
$databases['Name']=Array();
$old_lang=isset($config['language']) && in_array($config['language'],$lang['languages']) ? $config['language'] : '';
if($load_default==true)
{
if(file_exists($config['files']['parameter'])) @unlink($config['files']['parameter']);
include("./config.php");
if(is_array($preConfig)) {
foreach($preConfig as $key=>$val) {$config[$key]=$val;}
}
if($old_lang!='') $config['language']=$old_lang;
include("./language/".$config['language']."/lang.php");
}
//DB-Liste holen
MSD_mysql_connect();
$create_statement='CREATE TABLE `mysqldumper_test_abcxyvfgh` (`test` varchar(200) default NULL, `id` bigint(20) unsigned NOT NULL auto_increment,'
.'PRIMARY KEY (`id`)) TYPE=MyISAM;';
$res = mysql_query("SHOW DATABASES ;",$config['dbconnection']);
if (!$res===false)
{
$numrows=mysql_numrows($res);
$a=0;
for($i=0;$i<$numrows;$i++)
{
$row = mysql_fetch_row($res);
$found_db=$row[0];
// Testverbindung - Tabelle erstellen, nachschauen, ob es geklappt hat und dann wieder löschen
$use=@mysql_select_db($found_db);
if ($use)
{
$res2=mysql_query("DROP TABLE IF EXISTS `mysqldumper_test_abcxyvfgh`",$config['dbconnection']);
$res2=mysql_query($create_statement,$config['dbconnection']);
if (!$res2===false)
{
$res2=mysql_query("DROP TABLE IF EXISTS `mysqldumper_test_abcxyvfgh`",$config['dbconnection']);
if( isset($old_db) && $found_db==$old_db) $databases['db_selected_index']=$a;
$databases['Name'][$a]=$found_db;
$databases['praefix'][$a]="";
$databases['command_before_dump'][$a] = "";
$databases['command_after_dump'][$a] = "";
$out.=$lang['saving_db_form']." ".$found_db." ".$lang['added']."$nl";
$a++;
}
}
}
if(!isset($databases['db_selected_index']))
{
$databases['db_selected_index']=0;
$databases['db_actual']=$databases['Name'][0];
}
$databases['db_actual_cronpraefix']="";
$databases['db_actual_cronindex']=0;
}
WriteParams(1);
if($load_default===true) WriteLog("default settings loaded.");
return $out;
}
function WriteParams($as=0)
{
global $config,$databases,$config_dontsave;
$nl="\n";
FillMultiDBArrays();
check_manual_dbs();
//Parameter zusammensetzen
$config['multipart_groesse']=$config['multipartgroesse1']*(($config['multipartgroesse2']==1) ? 1024 : 1024*1024);
$param=$pars_all='<?php '.$nl;
if(!isset($config['email_maxsize'])) $config['email_maxsize']=$config['email_maxsize1']*(($config['email_maxsize2']==1) ? 1024 : 1024*1024);
if(!isset($config['cron_execution_path'])) $config['cron_execution_path']="msd_cron/";
if($as==0) $config['paths']['root']=addslashes(Realpfad("./"));
foreach($config as $var => $val){
if (!in_array($var,$config_dontsave))
{
if(is_array($val)) {
foreach($val as $var2 => $val2){
if ($config['magic_quotes_gpc']==0 || $as==1) {
$pars_all.='$config[\''.$var.'\']['.((is_int($var2)) ? $var2 : "'".$var2."'").'] = \''.addslashes($val2)."';$nl";
} else {
$pars_all.='$config[\''.$var.'\']['.((is_int($var2)) ? $var2 : "'".$var2."'").'] = \''.$val2."';$nl";
}
}
} else {
if ($config['magic_quotes_gpc']==0 || $as==1) {
if(!in_array($var,$config_dontsave)) $pars_all.='$config[\''.$var.'\'] = \''.addslashes($val)."';$nl";
} else {
if(!in_array($var,$config_dontsave)) $pars_all.='$config[\''.$var.'\'] = \''.$val."';$nl";
}
}
}
}
foreach($databases as $var => $val){
if(is_array($val)) {
foreach($val as $var2 => $val2){
if ($config['magic_quotes_gpc']==0 || $as==1) {
$pars_all.='$databases[\''.$var.'\']['.((is_int($var2)) ? $var2 : "'".$var2."'").'] = \''.addslashes($val2)."';$nl";
} else {
$pars_all.='$databases[\''.$var.'\']['.((is_int($var2)) ? $var2 : "'".$var2."'").'] = \''.$val2."';$nl";
}
}
} else {
if ($config['magic_quotes_gpc']==0 || $as==1) {
$pars_all.='$databases[\''.$var.'\'] = \''.addslashes($val)."';$nl";
} else {
$pars_all.='$databases[\''.$var.'\'] = \''.$val."';$nl";
}
}
}
$param.='?>'; $pars_all.='?>';
//Datei öffnen und schreiben
$ret=true;
@chmod($config['files']['parameter'], 0777);
if ($fp=fopen($config['files']['parameter'], "wb"))
{
if (!fwrite($fp,$pars_all)) $ret=false;
if (!fclose($fp)) $ret=false;
}
else $ret=false;
$ret=WriteCronScript();
return $ret;
}
function escape_specialchars($text)
{
// $tomask=Array('@'=>'\@','$'=>'\$','\\'=>'\\\\');
$suchen=ARRAY('@','$','\\\\');
$ersetzen=ARRAY('\@','\$','\\');
$text=str_replace($suchen,$ersetzen,$text);
return $text;
}
function WriteCronScript()
{
global $nl, $config, $databases, $cron_save_all_dbs,
$cron_db_array,$cron_dbpraefix_array,$cron_db_cbd_array,$cron_db_cad_array;
if (!isset($databases['db_selected_index'])) $databases['db_selected_index']=0;
if(!isset($databases['praefix'][$databases['db_selected_index']])) $databases['praefix'][$databases['db_selected_index']]="";
if(!isset($databases['db_actual_cronindex'])) $databases['db_actual_cronindex']=$databases['db_selected_index'];
if(!isset($config['email_maxsize'])) $config['email_maxsize']=$config['email_maxsize1']*(($config['email_maxsize2']==1) ? 1024 : 1024*1024);
if($config['cron_samedb']==0)
{
$cron_dbname=(isset($databases['db_actual'])) ? $databases['db_actual']:0;
$cron_dbpraefix = $databases['praefix'][$databases['db_selected_index']];
}
else
{
if($databases['db_actual_cronindex']>=0)
{
$cron_dbname=$databases['Name'][$databases['db_actual_cronindex']];
$cron_dbpraefix = $databases['db_actual_cronpraefix'];
}
else
{
$cron_dbname=$databases['db_actual'];
$cron_dbpraefix = $databases['praefix'][$databases['db_selected_index']];
}
}
if($databases['db_actual_cronindex']=="-2")
{
$cron_save_all_dbs=1;
$datenbanken=count($databases['Name']);
$cron_db_array=str_replace(";","|",$databases['multisetting']);
$cron_dbpraefix_array=str_replace(";","|",$databases['multisetting_praefix']);
$cron_db_cbd_array=str_replace(";","|",$databases['multisetting_commandbeforedump']);
$cron_db_cad_array=str_replace(";","|",$databases['multisetting_commandafterdump']);
}
if ($databases['db_actual_cronindex']=="-3")
{
$cron_save_all_dbs=1;
$cron_db_array=implode("|",$databases['Name']);
$cron_dbpraefix_array=implode("|",$databases['praefix']);
$cron_db_cbd_array=implode("|",$databases['command_before_dump']);
$cron_db_cad_array=implode("|",$databases['command_after_dump']);
}
if($databases['db_actual_cronindex']<0)
{
$csadb='$cron_save_all_dbs=1;'.$nl;
$csadb.='$cron_db_array=qw('.$cron_db_array.');'.$nl;
$csadb.='$cron_dbpraefix_array=qw('.$cron_dbpraefix_array.');'.$nl;
$csadb.='$dbpraefix="";'.$nl;
$csadb.='$command_beforedump_array="'.$cron_db_cbd_array.'";'.$nl;
$csadb.='$command_afterdump_array="'.$cron_db_cad_array.'";'.$nl;
}
else
{
$csadb='$cron_save_all_dbs=0;'.$nl;
$csadb.='$cron_db_array="";'.$nl;
$csadb.='$cron_dbpraefix_array="";'.$nl;
$csadb.='$dbpraefix="'.$cron_dbpraefix.'";'.$nl;
if (!isset($databases['command_before_dump'][$databases['db_selected_index']])) $databases['command_before_dump'][$databases['db_selected_index']]='';
$csadb.='$command_beforedump_array="'.$databases['command_before_dump'][$databases['db_selected_index']].'";'.$nl;
if (!isset($databases['command_after_dump'][$databases['db_selected_index']])) $databases['command_after_dump'][$databases['db_selected_index']]='';
$csadb.='$command_afterdump_array="'.$databases['command_after_dump'][$databases['db_selected_index']].'";'.$nl;
}
$r=str_replace("\\\\","/",$config['paths']['root']);
$r=str_replace("@","\@",$r);
$p1=$r.$config['paths']['backup'];
$p2=$r.$config['files']['perllog'].(($config['logcompression']==1) ? '.gz':'');
$p3=$r.$config['files']['perllogcomplete'].(($config['logcompression']==1) ? '.gz':'');
// auf manchen Server wird statt 0 ein leerer String gespeichert -> fuehrt zu einem Syntax-Fehler
// hier die entsprechenden Ja/Nein-Variablen sicherheitshalber in intvalues aendern
$int_array=array('dbport','cron_compression','cron_printout','cron_mail','cron_mail_dump','multi_part',
'multipart_groesse','email_maxsize','auto_delete','del_files_after_days',
'del_files_after_days','max_backup_files','perlspeed','optimize_tables_beforedump',
'logcompression','log_maxsize','backup_complete_inserts','backup_extended_inserts',
'backup_delayed_inserts','backup_ignore_inserts','backup_lock_tables','cron_completelog');
foreach ($int_array as $i)
{
$config[$i]=intval($config[$i]);
}
if ($config['dbport']==0) $config['dbport']=3306;
$cronscript="<?php\n#Vars - written at ".date("Y-m-d").$nl;
$cronscript.='$dbhost="'.$config['dbhost'].'";'.$nl;
$cronscript.='$dbname="'.$cron_dbname.'";'.$nl;
$cronscript.='$dbuser="'.escape_specialchars($config['dbuser']).'";'.$nl;
$cronscript.='$dbpass="'.escape_specialchars($config['dbpass']).'";'.$nl;
$cronscript.='$dbport='.$config['dbport'].';'.$nl;
$cronscript.=$csadb;
$cronscript.='$compression='.$config['cron_compression'].';'.$nl;
$cronscript.='$backup_path="'.$p1.'";'.$nl;
$cronscript.='$logdatei="'.$p2.'";'.$nl;
$cronscript.='$completelogdatei="'.$p3.'";'.$nl;
$cronscript.='$sendmail_call="'.escape_specialchars($config['cron_sendmail']).'";'.$nl;
$cronscript.='$nl="\n";'.$nl;
$cronscript.='$cron_printout='.$config['cron_printout'].';'.$nl;
$cronscript.='$cronmail='.$config['cron_mail'].';'.$nl;
$cronscript.='$cronmail_dump='.$config['cron_mail_dump'].';'.$nl;
$cronscript.='$cronmailto="'.escape_specialchars($config['email_recipient']).'";'.$nl;
$cronscript.='$cronmailfrom="'.escape_specialchars($config['email_sender']).'";'.$nl;
$cronscript.='$cronftp='.$config['cron_ftp'].';'.$nl;
$cronscript.='$ftp_server="'.$config['ftp_server'][$config['ftp_connectionindex']].'";'.$nl;
$cronscript.='$ftp_port='.$config['ftp_port'][$config['ftp_connectionindex']].';'.$nl;
$cronscript.='$ftp_mode='.intval($config['ftp_mode']).';'.$nl;
$cronscript.='$ftp_user="'.escape_specialchars($config['ftp_user'][$config['ftp_connectionindex']]).'";'.$nl;
$cronscript.='$ftp_pass="'.escape_specialchars($config['ftp_pass'][$config['ftp_connectionindex']]).'";'.$nl;
$cronscript.='$ftp_dir="'.$config['ftp_dir'][$config['ftp_connectionindex']].'";'.$nl;
$cronscript.='$mp='.$config['multi_part'].';'.$nl;
$cronscript.='$multipart_groesse='.$config['multipart_groesse'].';'.$nl;
$cronscript.='$email_maxsize='.$config['email_maxsize'].';'.$nl;
$cronscript.='$auto_delete='.$config['auto_delete'].';'.$nl;
$cronscript.='$cron_del_files_after_days='.$config['del_files_after_days'].';'.$nl;
$cronscript.='$max_backup_files='.$config['max_backup_files'].';'.$nl;
$cronscript.='$max_backup_files_each='.$config['max_backup_files_each'].';'.$nl;
$cronscript.='$perlspeed='.$config['perlspeed'].';'.$nl;
$cronscript.='$optimize_tables_beforedump='.$config['optimize_tables_beforedump'].';'.$nl;
$cronscript.='$logcompression='.$config['logcompression'].';'.$nl;
$cronscript.='$log_maxsize='.$config['log_maxsize'].';'.$nl;
$cronscript.='$backup_complete_inserts='.$config['backup_complete_inserts'].';'.$nl;
$cronscript.='$backup_extended_inserts='.$config['backup_extended_inserts'].';'.$nl;
$cronscript.='$backup_delayed_inserts='.$config['backup_delayed_inserts'].';'.$nl;
$cronscript.='$backup_ignore_inserts='.$config['backup_ignore_inserts'].';'.$nl;
$cronscript.='$backup_lock_tables='.$config['backup_lock_tables'].';'.$nl;
$cronscript.='$complete_log='.$config['cron_completelog'].';'.$nl;
$cronscript.='$my_comment="";'.$nl;
$cronscript.="1;\n?>";
//Datei öffnen und schreiben
$ret=true;
$ext=($config['cron_extender']==0) ? "pl" : "cgi";
$sfile=$config['paths']['config'].$config['cron_configurationfile'];
if(substr($sfile,-5)=='.conf') {
@unlink($sfile);
$sfile.='.php';
}
if(file_exists($sfile)) @chmod("$sfile",0777);
if ($fp=fopen($sfile, "wb"))
{
if (!fwrite($fp,$cronscript)) $ret=false;
if (!fclose($fp)) $ret=false;
}
else $ret=false;
if(file_exists($config['paths']['config']."mysqldumper.conf")) @unlink($config['paths']['config']."mysqldumper.conf");
if(!file_exists($config['paths']['config']."mysqldumper.conf.php")) {
$sfile=$config['paths']['config']."mysqldumper.conf.php";
if ($fp=fopen($sfile, "wb"))
{
if (!fwrite($fp,$cronscript)) $ret=false;
if (!fclose($fp)) $ret=false;
//chmod("$sfile",0755);
}
else $ret=false;
}
return $ret;
}
function LogFileInfo($logcompression) {
global $config;
$l=Array();$sum=$s=$l['log_size']=$l['perllog_size']=$l['perllogcomplete_size']=$l['errorlog_size']=$l['log_totalsize']=0;
if($logcompression==1) {
$l['log']=$config['files']['log'].".gz";
$l['perllog']=$config['files']['perllog'].".gz";
$l['perllogcomplete']=$config['files']['perllogcomplete'].".gz";
$l['errorlog']=$config['paths']['log']."error.log.gz";
} else {
$l['log']=$config['files']['log'];
$l['perllog']=$config['files']['perllog'];
$l['perllogcomplete']=$config['files']['perllogcomplete'];
$l['errorlog']=$config['paths']['log']."error.log";
}
$l['log_size']+=@filesize($l['log']);$sum+=$l['log_size'];
$l['perllog_size']+=@filesize($l['perllog']);$sum+=$l['perllog_size'];
$l['perllogcomplete_size']+=@filesize($l['perllogcomplete']);$sum+=$l['perllogcomplete_size'];
$l['errorlog_size']+=@filesize($l['errorlog']);$sum+=$l['errorlog_size'];
$l['log_totalsize']+=$sum;
return $l;
}
function DeleteLog()
{
global $config;
//Datei öffnen und schreiben
$log=date('d.m.Y H:i:s')." Log created.\n";
if($config['logcompression']==1) {
$fp = @gzopen($config['files']['log'].'.gz', "wb");
@gzwrite ($fp,$log);
@gzclose ($fp);
@chmod($config['files']['log'].'.gz',0755);
} else {
$fp = @fopen($config['files']['log'], "wb");
@fwrite ($fp,$log);
@fclose ($fp);
@chmod($config['files']['log'],0755);
}
}
function SwitchLogfileFormat()
{
global $config;
$del=DeleteFilesM($config['paths']['log'],"*");
DeleteLog();
}
function CreateDirsFTP() {
global $config,$lang,$install_ftp_server,$install_ftp_port,$install_ftp_user_name,$install_ftp_user_pass,$install_ftp_path;
// Herstellen der Basis-Verbindung
echo '<hr>'.$lang['connect_to'].' `'.$install_ftp_server.'` Port '.$install_ftp_port.' ...<br>';
$conn_id = ftp_connect($install_ftp_server);
// Einloggen mit Benutzername und Kennwort
$login_result = ftp_login($conn_id, $install_ftp_user_name, $install_ftp_user_pass);
// Verbindung überprüfen
if ((!$conn_id) || (!$login_result)) {
echo $lang['ftp_notconnected'];
echo $lang['connwith']." $tinstall_ftp_server ".$lang['asuser']." $install_ftp_user_name ".$lang['notpossible'];
return 0;
} else {
if ($config['ftp_mode']==1) ftp_pasv($conn_id,true);
//Wechsel in betroffenes Verzeichnis
echo $lang['changedir'].' `'.$install_ftp_path.'` ...<br>';
ftp_chdir($conn_id,$install_ftp_path);
// Erstellen der Verzeichnisse
echo $lang['dircr1'].' ...<br>';
ftp_mkdir($conn_id,"work");
ftp_site($conn_id, "CHMOD 0777 work");
echo $lang['changedir'].' `work` ...<br>';
ftp_chdir($conn_id,"work");
echo $lang['indir'].' `'.ftp_pwd($conn_id).'`<br>';
echo $lang['dircr5'].' ...<br>';
ftp_mkdir($conn_id,"config");
ftp_site($conn_id, "CHMOD 0777 config");
echo $lang['dircr2'].' ...<br>';
ftp_mkdir($conn_id,"backup");
ftp_site($conn_id, "CHMOD 0777 backup");
echo $lang['dircr3'].' ...<br>';
ftp_mkdir($conn_id,"structure");
ftp_site($conn_id, "CHMOD 0777 structure");
echo $lang['dircr4'].' ...<br>';
ftp_mkdir($conn_id,"log");
ftp_site($conn_id, "CHMOD 0777 log");
// Schließen des FTP-Streams
ftp_quit($conn_id);
return 1;
}
}
function ftp_mkdirs($config,$dirname)
{
$dir=split("/", $dirname);
for ($i=0;$i<count($dir)-1;$i++)
{
$path.=$dir[$i]."/";
@ftp_mkdir($config['dbconnection'],$path);
}
if (@ftp_mkdir($config['dbconnection'],$dirname))
return 1;
}
function IsWritable($dir)
{
$testfile=$dir . "/.writetest";
if ($writable = @fopen ($testfile, 'w')) {
@fclose ($writable);
@unlink ($testfile);
}
return $writable;
}
function SearchDatabases($printout)
{
global $databases,$config,$lang;
if(!isset($config['dbconnection'])) MSD_mysql_connect();
$db_list = array();
$show_dbs=mysql_query("SHOW DATABASES",$config['dbconnection']);
if (!$show_dbs===false)
{
WHILE ($row=mysql_fetch_row($show_dbs))
{
$db_list[]=$row[0];
}
}
$databases['db_selected_index'] = 0;
for ($i=0;$i<sizeof($db_list);$i++)
{
// Test-Select um zu sehen, ob Berechtigungen existieren
if(!@mysql_query("SHOW TABLES FROM `".$db_list[$i]."`",$config['dbconnection'])===false)
{
$databases['Name'][$i]=$row[0];
$databases['praefix'][$i] = '';
$databases['command_before_dump'][$i] = '';
$databases['command_after_dump'][$i] = '';
if($printout==1) echo $lang['found_db'].' `'.$db_list[$i].'`<br />';
}
}
if (isset($databases['Name'][0])) $databases['db_actual']=$databases['Name'][0];
}
// removes tags from inputs recursivly
function my_strip_tags($value)
{
$ret='';
if (is_array($value))
{
foreach ($value as $key=>$val)
{
$$key=my_strip_tags($val);
}
}
else $ret=trim(strip_tags($value));
return $ret;
}
?>

Datei anzeigen

@ -0,0 +1,483 @@
<?php
include_once('./inc/functions_global.php');
//Buffer für Multipart-Filesizeprüfung
$buffer=10*1024;
function new_file($last_groesse=0)
{
global $dump,$databases,$config,$out,$lang,$nl,$mysql_commentstring;
// Dateiname aus Datum und Uhrzeit bilden
if ($dump['part']-$dump['part_offset']==1) $dump['filename_stamp']=date("Y_m_d_H_i",time());
if ($config['multi_part']==1)
{
$dateiname=$databases['Name'][$dump['dbindex']].'_'.$dump['filename_stamp'].'_part_'.($dump['part']-$dump['part_offset']);
}
else $dateiname=$databases['Name'][$dump['dbindex']].'_'.date("Y_m_d_H_i",time());
$structurefilename=$databases['Name'][$dump['dbindex']].'_structure_file';
$endung= ($config['compression']) ? '.sql.gz' : '.sql';
$dump['backupdatei']=$dateiname.$endung;
$dump['backupdatei_structure']=$structurefilename.$endung;
if (file_exists($config['paths']['backup'].$dump['backupdatei'])) unlink($config['paths']['backup'].$dump['backupdatei']);
if($config['multi_part']==0 || ($config['multi_part']==1 && ($dump['part']-$dump['part_offset'])==1))
{
if (file_exists($config['paths']['structure'].$dump['backupdatei_structure'])) unlink($config['paths']['structure'].$dump['backupdatei_structure']);
}
$cur_time=date("Y-m-d H:i");
$statuszeile=GetStatusLine().$nl.$mysql_commentstring.' Dump by MySQLDumper '.MSD_VERSION.' ('.$config['homepage'].')'.$nl;
$statuszeile.='/*40101 SET NAMES `'.$dump['dump_encoding'].'` */;'.$nl.$nl;
if ($dump['part']-$dump['part_offset']==1)
{
if($config['multi_part']==0)
{
if($config['multi_dump']==1) WriteLog('starting Multidump with '.count($databases['multi']).' Datenbases.');
WriteLog('Start Dump \''.$dump['backupdatei'].'\'');
}
else WriteLog('Start Multipart-Dump \''.$dateiname.'\'');
$out.='<strong>'.$lang['startdump'].' `'.$databases['Name'][$dump['dbindex']].'`</strong>'.(($databases['praefix'][$dump['dbindex']]!="") ?' ('.$lang['withpraefix'].' <span style="color:blue">'.$databases['praefix'][$dump['dbindex']].'</span>)' : '').'... ';
ExecuteCommand('b');
if($dump['part']==1)
{
$dump['table_offset']=0;
$dump['countdata']=0;
}
// Seitenerstaufruf -> Backupdatei anlegen
$dump['data']=$statuszeile.$mysql_commentstring.' Dump created at '.$cur_time.$nl.$nl;
$dump['structure']=$mysql_commentstring.' Status:0:0::'.$databases['Name'][$dump['dbindex']];
$dump['structure'].=":php:".MSD_VERSION.$nl;
$dump['structure'].=$mysql_commentstring.' Dump by MySQLDumper '.MSD_VERSION.' ('.$config['homepage'].')'.$nl;
$dump['structure'].=$mysql_commentstring.' Dump created on '.$cur_time.$nl.$mysql_commentstring.' This file only contains the structure of the database without data \n\n';
}
else
{
if($config['multi_part']!=0) {
WriteLog('Continue Multipart-Dump with File '.($dump['part']-$dump['part_offset']).' (last file was '.$last_groesse.' Bytes)');
$dump['data']=$statuszeile.$mysql_commentstring.' This is part '.($dump['part']-$dump['part_offset']).' of the backup.'.$nl.$nl.$dump['data'];
}
}
WriteToDumpFile();
$dump['part']++;
}
function GetStatusLine($kind="php")
{
/*AUFBAU der Statuszeile:
-- Status:tabellenzahl:datensätze:Multipart:Datenbankname:script:scriptversion:Kommentar:MySQLVersion:Backupflags:SQLBefore:SQLAfter:Charset:CharsetEXTINFO
Aufbau Backupflags (1 Zeichen pro Flag, 0 oder 1, 2=unbekannt)
(complete inserts)(extended inserts)(ignore inserts)(delayed inserts)(downgrade)(lock tables)(optimize tables)
*/
global $databases,$config, $dump,$mysql_commentstring;
$t_array=explode("|",$databases['db_actual_tableselected']);
$t=0;
$r=0;
$t_zeile="$mysql_commentstring\n$mysql_commentstring TABLE-INFO\n";
MSD_mysql_connect();
$res=mysql_query("SHOW TABLE STATUS FROM `".$databases['Name'][$dump['dbindex']]."`");
$numrows=intval(@mysql_num_rows($res));
for($i=0;$i<$numrows;$i++) {
$erg=mysql_fetch_array($res);
// Get nr of records -> need to do it this way because of incorrect returns when using InnoDBs
$sql_2="SELECT count(*) as `count_records` FROM `".$databases['Name'][$dump['dbindex']]."`.`".$erg['Name']."`";
$res2=@mysql_query($sql_2);
$row2=mysql_fetch_array($res2);
$erg['Rows']=$row2['count_records'];
if(($databases['db_actual_tableselected']=="" || ($databases['db_actual_tableselected']!="" && (in_array($erg[0],$t_array)))) && (substr($erg[0],0,strlen($databases['praefix'][$dump['dbindex']]))==$databases['praefix'][$dump['dbindex']])) {
$t++;$r+=$erg['Rows'];
$t_zeile.="$mysql_commentstring TABLE|".$erg['Name']."|".$erg['Rows']."|".($erg['Data_length']+$erg['Index_length'])."|".$erg['Update_time']."\n";
}
}
//$dump['totalrecords']=$r;
$flags=$config['backup_complete_inserts'].$config['backup_extended_inserts'].$config['backup_ignore_inserts'].$config['backup_delayed_inserts'].$config['backup_downgrade'].$config['backup_lock_tables'].$config['optimize_tables_beforedump'];
$mp=($config['multi_part']==1) ? $mp="MP_".($dump['part']-$dump['part_offset']) : "MP_0";
$statusline="$mysql_commentstring Status:$t:$r:$mp:".$databases['Name'][$dump['dbindex']].":$kind:".MSD_VERSION.":".$dump['kommentar'].":";
$statusline.=MSD_MYSQL_VERSION.":$flags:::".$dump['dump_encoding'].":EXTINFO\n".$t_zeile."$mysql_commentstring"." EOF TABLE-INFO\n$mysql_commentstring\n\n";
return $statusline;
}
// Liest die Eigenschaften der Tabelle aus der DB und baut die CREATE-Anweisung zusammen
function get_def($db, $table,$withdata=1)
{
global $config,$nl,$mysql_commentstring;
$def = "\n\n$mysql_commentstring\n$mysql_commentstring Create Table `$table`\n$mysql_commentstring\n\nDROP TABLE IF EXISTS `$table`;\n";
mysql_select_db($db);
$result = mysql_query('SHOW CREATE TABLE `'.$table.'`',$config['dbconnection']);
$row=mysql_fetch_row($result);
$def .= (($config['backup_downgrade']==1) ? DownGrade($row[1],false) : $row[1].';')."\n\n";
if($withdata==1) {
$def.="$mysql_commentstring\n$mysql_commentstring Data for Table `$table`\n$mysql_commentstring\n\n";
if($config['backup_delayed_inserts']==0) $def.="/*!40000 ALTER TABLE `$table` DISABLE KEYS */;".$nl;
if($config['backup_lock_tables']==1 && $config['backup_delayed_inserts']==0) $def.="LOCK TABLES `$table` WRITE;\n\n";
}
return $def;
}
// Liest die Daten aus der DB aus und baut die INSERT-Anweisung zusammen
function get_content($db, $table)
{
global $config,$nl,$dump,$buffer;
$content='';
$delayed=(isset($config['backup_delayed_inserts']) && $config['backup_delayed_inserts']==1) ? 'DELAYED ' : '';
$complete=(isset($config['backup_complete_inserts']) && $config['backup_complete_inserts']==1) ? Fieldlist($db,$table).' ':'';
$ignore=(isset($config['backup_ignore_inserts']) && $config['backup_ignore_inserts']==1) ? 'IGNORE ':'';
$table_ready=0;
$query='SELECT * FROM `'.$table.'` LIMIT '.$dump['zeilen_offset'].','.($dump['restzeilen']+1);
mysql_select_db($db);
$result = mysql_query($query,$config['dbconnection']);
$ergebnisse=mysql_num_rows($result);
$num_felder=mysql_num_fields($result);
$first=1;
if ($ergebnisse>$dump['restzeilen'])
{
$dump['zeilen_offset']+=$dump['restzeilen'];
$ergebnisse--;
$dump['restzeilen']=0;
}
else
{
$dump['table_offset']++;
$dump['zeilen_offset']=0;
$dump['restzeilen']=$dump['restzeilen']-$ergebnisse;
$table_ready=1;
}
$ax=0;
for ($x=0;$x<$ergebnisse;$x++)
{
$row=mysql_fetch_row($result);
$ax++;
if($config['backup_extended_inserts']==0 || ($config['backup_extended_inserts']==1 && $first==1 && $ax==1) ) {
$insert = 'INSERT '.$delayed.$ignore.'INTO `'.$table.'` '.$complete.'VALUES (';
$first=0;
} else $insert='(';
for($j=0; $j<$num_felder;$j++)
{
if(!isset($row[$j])) $insert .= 'NULL,';
else if($row[$j] != '') $insert.= '\''.mysql_escape_string($row[$j]).'\',';
else $insert .= '\'\',';
}
$insert=substr($insert,0,-1);
if(strlen($dump['data'])>400000 || $x==($ergebnisse-1)) {
$ax=0;$first=1;
}
$insert .= ($config['backup_extended_inserts']==0 || $x==($ergebnisse-1) || $ax==0) ? ");\n" : '),';
$dump['data'] .= $insert;
$dump['countdata']++;
if(strlen($dump['data'])>$config['memory_limit'] || ($config['multi_part']==1 && strlen($dump['data'])+$buffer>$config['multipart_groesse']) ) {
WriteToDumpFile();
}
}
if($table_ready==1 && $config['backup_lock_tables']==1 && $config['backup_delayed_inserts']==0) $dump['data'].="\nUNLOCK TABLES;";
if($table_ready==1 && $config['backup_delayed_inserts']==0) $dump['data'].="\n/*!40000 ALTER TABLE `$table` ENABLE KEYS */;\n\n";
mysql_free_result($result);
}
function WriteToDumpFile()
{
global $config,$dump,$buffer;
$dump['filesize']=0;
$df=$config['paths']['backup'].$dump['backupdatei'];
$sf=$config['paths']['structure'].$dump['backupdatei_structure'];
if ($config['compression']==1)
{
if($dump['data']!='') {
$fp = gzopen ($df,'ab');
gzwrite ($fp,$dump['data']); gzclose ($fp);
}
if($dump['structure']!='') {
$fp = gzopen ($sf,'ab');
gzwrite ($fp,$dump['structure']); gzclose ($fp);
}
}
else
{
if($dump['data']!='') {
$fp = fopen ($df,'ab');
fwrite ($fp,$dump['data']);fclose ($fp);
}
if($dump['structure']!='') {
$fp = fopen ($sf,'ab');
fwrite ($fp,$dump['structure']); fclose ($fp);
}
}
$dump['data']=$dump['structure']='';
if(!isset($dump['fileoperations'])) $dump['fileoperations']=0;
$dump['fileoperations']++;
if ($config['multi_part']==1) clearstatcache();
$dump['filesize']=filesize($df);
if ($config['multi_part']==1 && $dump['filesize']+$buffer>$config['multipart_groesse'])
new_file($dump['filesize']); // Wenn maximale Dateigroesse erreicht -> neues File starten
}
function ExecuteCommand($when)
{
global $config,$databases,$dump,$out,$lang;
if($when=='b') { // before dump
$cd=$databases['command_before_dump'][$dump['dbindex']];
$cap='before Dump'; $lf='<br>';
} else {
$cd=$databases['command_after_dump'][$dump['dbindex']];
$cap='after Dump'; $lf='';
}
if($cd!='') {
//jetzt ausführen
if(substr(strtolower($cd),0,7)!='system:') {
@mysql_select_db($databases['Name'][$dump['dbindex']]);
if(strpos($cd,';')) {
$cad=explode(';',$cd);
for($i=0;$i<count($cad);$i++) {
if($cad[$i]) $result .= @mysql_query($cad[$i],$config['dbconnection']);
}
} else {
$result = @mysql_query($cd,$config['dbconnection']);
}
if(!$result) {
WriteLog("Error while executing Query $cap ($cd) : ".mysql_error());
ErrorLog("Command ".$cap,$databases['Name'][$dump['dbindex']],$cd,mysql_error());
$dump['errors']++;
$out.=$lf.'<span class="error">ERROR executing Query '.$cap.'</span><br>';
} else {
WriteLog("executing Query $cap ($cd) was successful");
$out.=$lf.'<span class="success">executing Query '.$cap.' was successful</span><br>';
}
} elseif(substr(strtolower($cd),0,7)=="system:") {
//$result=@system(substr($cd,7),$returnval);
$cap=substr($cd,7);
$result=1;
if(!$result) {
WriteLog("Error while executing System Command $cap");
$dump['errors']++;
$out.=$lf.'<span class="error">ERROR executing System Command '.$cap.'</span><br>';
} else {
WriteLog("executing System Command $cap was successful. [$returnval]");
$out.=$lf.'<span class="success">executing System Command '.$cap.' was successful</span><br>';
}
}
}
}
function DoEmail()
{
global $config,$dump,$databases,$email,$lang,$out,$REMOTE_ADDR;
$header="";
if($config['cron_use_sendmail']==1) {
//sendmail
if(ini_get("sendmail_path")!=$config['cron_sendmail']) @ini_set("SMTP",$config['cron_sendmail']);
if(ini_get("sendmail_from")!=$config['email_sender']) @ini_set("SMTP",$config['email_sender']);
} else {
//SMTP
}
if(ini_get("SMTP")!=$config['cron_smtp']) @ini_set("SMTP",$config['cron_smtp']);
if(ini_get("smtp_port")!=25) @ini_set("smtp_port",25);
if($config['multi_part']==0) {
$file = $dump['backupdatei'];
$file_name=(strpos("/",$file)) ? substr($file,strrpos("/",$file)) : $file;
$file_type = filetype($config['paths']['backup'].$file);
$file_size = filesize($config['paths']['backup'].$file);
if(($config['email_maxsize']>0 && $file_size>$config['email_maxsize']) || $config['send_mail_dump']==0) {
//anhang zu gross
$subject = "Backup '".$databases['Name'][$dump['dbindex']]."' - ".date("d\.m\.Y H:i",time());
$header.= "FROM:".$config['email_sender']."\n";
$header.= "MIME-version: 1.0\n";
$header .= "X-Mailer: PHP/" . phpversion(). "\n";
$header .= "X-Sender-IP: $REMOTE_ADDR\n";
$header .= "Content-Type: text/html";
if($config['send_mail_dump']!=0) {
$msg_body = sprintf(addslashes($lang['emailbody_toobig']),byte_output($config['email_maxsize']),$databases['Name'][$dump['dbindex']],"$file (".byte_output(filesize($config['paths']['backup'].$file)).")<br>");
} else {
$msg_body = sprintf(addslashes($lang['emailbody_noattach']),$databases['Name'][$dump['dbindex']],"$file (".byte_output(filesize($config['paths']['backup'].$file)).")");
}
$msg_body.='<a href="http://'.$_SERVER['HTTP_HOST'].substr($_SERVER["PHP_SELF"],0,strrpos($_SERVER["PHP_SELF"],"/")).'/'.$config['paths']['backup'].$file.'">'.$file.'</a>';
$email_log="Email sent to '".$config['email_recipient']."'";
$email_out=$lang['email_was_send']."`".$config['email_recipient']."`<br>";
} else {
//alles ok, anhang generieren
$msg_body = sprintf(addslashes($lang['emailbody_attach']),$databases['Name'][$dump['dbindex']],"$file (".byte_output(filesize($config['paths']['backup'].$file)).")");
$subject = "Backup '".$databases['Name'][$dump['dbindex']]."' - ".date("d\.m\.Y",time());
$fp = fopen($config['paths']['backup'].$file, "r");
$contents = fread($fp, $file_size);
$encoded_file = chunk_split(base64_encode($contents));
fclose($fp);
$header.= "FROM:".$config['email_sender']."\n";
$header.= "MIME-version: 1.0\n";
$header.= "Content-type: multipart/mixed; ";
$header.= "boundary=\"Message-Boundary\"\n";
$header.= "Content-transfer-encoding: 7BIT\n";
$header.= "X-attachments: $file_name";
$body_top = "--Message-Boundary\n";
$body_top.= "Content-type: text/html; charset=utf-8\n";
$body_top.= "Content-transfer-encoding: 7BIT\n";
$body_top.= "Content-description: Mail message body\n\n";
$msg_body = $body_top . $msg_body;
$msg_body.= "\n\n--Message-Boundary\n";
$msg_body.= "Content-type: $file_type; name=\"$file\"\n";
$msg_body.= "Content-Transfer-Encoding: BASE64\n";
$msg_body.= "Content-disposition: attachment; filename=\"$file\"\n\n";
$msg_body.= "$encoded_file\n";
$msg_body.= "--Message-Boundary--\n";
$email_log="Email was sent to '".$config['email_recipient']."' with '".$dump['backupdatei']."'.";
$email_out=$lang['email_was_send']."`".$config['email_recipient']."`".$lang['with']."`".$dump['backupdatei']."`.<br>";
}
} else {
//Multipart
$mp_sub="Backup '".$databases['Name'][$dump['dbindex']]."' - ".date("d\.m\.Y",time());
$subject = $mp_sub;
$header.= "FROM:".$config['email_sender']."\n";
$header.= "MIME-version: 1.0\n";
$header .= "X-Mailer: PHP/" . phpversion(). "\n";
$header .= "X-Sender-IP: $REMOTE_ADDR\n";
$header .= "Content-Type: text/html; charset=utf-8";
$dateistamm=substr($dump['backupdatei'],0,strrpos($dump['backupdatei'],"part_"))."part_";
$dateiendung=($config['compression']==1)?".sql.gz":".sql";
$mpdatei=Array();
$mpfiles="";
for ($i=1;$i<($dump['part']-$dump['part_offset']);$i++) {
$mpdatei[$i-1]=$dateistamm.$i.$dateiendung;
$sz=byte_output(@filesize($config['paths']['backup'].$mpdatei[$i-1]));
$mpfiles.=$mpdatei[$i-1]." (".$sz.")<br>";
}
$msg_body = ($config['send_mail_dump']==1) ? sprintf(addslashes($lang['emailbody_mp_attach']),$databases['Name'][$dump['dbindex']],$mpfiles) : sprintf(addslashes($lang['emailbody_mp_noattach']),$databases['Name'][$dump['dbindex']],$mpfiles);
$email_log="Email was sent to '".$config['email_recipient']."'";
$email_out=$lang['email_was_send']."`".$config['email_recipient']."`<br>";
}
if (@mail($config['email_recipient'], stripslashes($subject), $msg_body, $header)) {
$out.= '<span class="success">'.$email_out.'</span>';
WriteLog("$email_log");
} else {
$out.='<span class="error">'.$lang['mailerror'].'</span><br>';
WriteLog("Email to '".$config['email_recipient']."' failed !");
ErrorLog("Email ",$databases['Name'][$dump['dbindex']],'Subject: '.stripslashes($subject),$lang['mailerror']);
$dump['errors']++;
}
if(isset($mpdatei) && $config['send_mail_dump']==1) { // && ($config['email_maxsize']==0 || ($config['email_maxsize']>0 && $config['multipartgroesse2']<=$config['email_maxsize']))) {
for($i=0;$i<count($mpdatei);$i++) {
$file_name=$mpdatei[$i];
$file_type = filetype($config['paths']['backup'].$mpdatei[$i]);
$file_size = filesize($config['paths']['backup'].$mpdatei[$i]);
$fp = fopen($config['paths']['backup'].$mpdatei[$i], "r");
$contents = fread($fp, $file_size);
$encoded_file = chunk_split(base64_encode($contents));
fclose($fp);
$subject =$mp_sub. " [Part ".($i+1)." / ".count($mpdatei)."]";
$header= "FROM:".$config['email_sender']."\n";
$header.= "MIME-version: 1.0\n";
$header.= "Content-type: multipart/mixed; ";
$header.= "boundary=\"Message-Boundary\"\n";
$header.= "Content-transfer-encoding: 7BIT\n";
$header.= "X-attachments: $file_name";
$body_top = "--Message-Boundary\n";
$body_top.= "Content-type: text/html\n";
$body_top.= "Content-transfer-encoding: 7BIT\n";
$body_top.= "Content-description: Mail message body\n\n";
$msg_body = $body_top.addslashes($lang['email_only_attachment'].$lang['emailbody_footer']);
$msg_body.= "\n\n--Message-Boundary\n";
$msg_body.= "Content-type: $file_type; name=\"".$mpdatei[$i]."\"\n";
$msg_body.= "Content-Transfer-Encoding: BASE64\n";
$msg_body.= "Content-disposition: attachment; filename=\"".$mpdatei[$i]."\"\n\n";
$msg_body.= "$encoded_file\n";
$msg_body.= "--Message-Boundary--\n";
$email_log="Email with $mpdatei[$i] was sent to '".$config['email_recipient']."'";
$email_out=$lang['email_was_send']."`".$config['email_recipient']."`".$lang['with']."`".$mpdatei[$i]."`.<br>";
if (@mail($config['email_recipient'], stripslashes($subject), $msg_body, $header)) {
$out.= '<span class="success">'.$email_out.'</span>';
WriteLog("$email_log");
} else {
$out.='<span class="error">'.$lang['mailerror'].'</span><br>';
WriteLog("Email to '".$config['email_recipient']."' failed !");
ErrorLog("Email ",$databases['Name'][$dump['dbindex']],'Subject: '.stripslashes($subject),$lang['mailerror']);
$dump['errors']++;
}
}
}
}
function DoFTP()
{
global $config,$dump,$out;
if($config['multi_part']==0) {
SendViaFTP($dump['backupdatei'],1);
} else {
$dateistamm=substr($dump['backupdatei'],0,strrpos($dump['backupdatei'],"part_"))."part_";
$dateiendung=($config['compression']==1)?".sql.gz":".sql";
for ($i=1;$i<($dump['part']-$dump['part_offset']);$i++) {
$mpdatei=$dateistamm.$i.$dateiendung;
SendViaFTP($mpdatei,$i);
}
}
$out.='<span class="success">'."file sent via FTP (".$dump['backupdatei']." => ".$config['ftp_server'][$config['ftp_connectionindex']].")</span><br><br>";
}
function SendViaFTP($source_file,$conn_msg=1)
{
global $config,$out,$lang;
flush();
if($conn_msg==1) $out.='<span class="success">'.$lang['filesendftp']."(".$config['ftp_server'][$config['ftp_connectionindex']]." - ".$config['ftp_user'][$config['ftp_connectionindex']].")</span><br>";
// Herstellen der Basis-Verbindung
if($config['ftp_useSSL']==0)
$conn_id = ftp_connect($config['ftp_server'][$config['ftp_connectionindex']], $config['ftp_port'][$config['ftp_connectionindex']],$config['ftp_timeout']);
else
$conn_id = ftp_ssl_connect($config['ftp_server'][$config['ftp_connectionindex']], $config['ftp_port'][$config['ftp_connectionindex']],$config['ftp_timeout']);
// Einloggen mit Benutzername und Kennwort
$login_result = ftp_login($conn_id, $config['ftp_user'][$config['ftp_connectionindex']], $config['ftp_pass'][$config['ftp_connectionindex']]);
if ($config['ftp_mode']==1) ftp_pasv($conn_id,true);
// Verbindung überprüfen
if ((!$conn_id) || (!$login_result)) {
$out.= '<span class="error">'.$lang['ftpconnerror'].$config['ftp_server'][$config['ftp_connectionindex']].$lang['ftpconnerror1'].$config['ftp_user'][$config['ftp_connectionindex']].$lang['ftpconnerror2'].'</span><br>';
exit;
} else {
if($conn_msg==1) $out.= '<span class="success">'.$lang['ftpconnected1'].$config['ftp_server'][$config['ftp_connectionindex']].$lang['ftpconnerror1'].$config['ftp_user'][$config['ftp_connectionindex']].'</span><br>';
}
// Upload der Datei
$dest=$config['ftp_dir'][$config['ftp_connectionindex']].$source_file;
$source=$config['paths']['backup'].$source_file;
$upload = @ftp_put($conn_id, $dest,$source , FTP_BINARY);
// Upload-Status überprüfen
if (!$upload) {
$out.= '<span class="error">'.$lang['ftpconnerror3']."<br>($source -> $dest)</span><br>";
} else {
$out.= '<span class="success">'.$lang['file'].' <a href="'.$config['paths']['backup'].$source_file.'" class="smallblack">'.$source_file.'</a>'.$lang['ftpconnected2'].$config['ftp_server'][$config['ftp_connectionindex']].$lang['ftpconnected3'].'</span><br>';
WriteLog("'$source_file' sent via FTP.");
}
// Schließen des FTP-Streams
@ftp_quit($conn_id);
}
?>

Datei anzeigen

@ -0,0 +1,378 @@
<?php
function FilelisteCombo($fpath,$selected) {
$r='<select name="selectfile">';
$r.='<option value="" '.(($selected=="") ? "SELECTED" : "").'></option>';
$dh = opendir($fpath);
while (false !== ($filename = readdir($dh)))
{
if ($filename != "." && $filename != ".." && !is_dir($fpath.$filename)) {
$r.='<option value="'.$filename.'" ';
if($filename==$selected) $r.=' SELECTED';
$r.='>'.$filename.'</option>'."\n";
}
}
$r.='</select>';
return $r;
}
function sortierdatum($datum)
{
$p=explode(' ',$datum);
$uhrzeit=$p[1];
$p2=explode('.',$p[0]);
$day=$p2[0];
$month=$p2[1];
$year=$p2[2];
return $year.'.'.$month.'.'.$day.' '.$uhrzeit;
}
function FileList($multi=0)
{
global $config,$kind,$fpath,$lang,$databases,$href,$dbactiv,$action,$expand;
$files=Array();
if($kind==0){
//Backup-Dateien
$Theader=$lang['fm_files1'].' '.$lang['of'].' "'.$dbactiv.'"';
$Wheader=$lang['fm_files2'];
$akind=1;
} else {
//Struktur-Dateien
$Theader=$lang['fm_files2'];
$Wheader=$lang['fm_files1'];
$akind=0;
}
$Sum_Files=0;
$dh = opendir($fpath);
$fl="";
$i=0;
while (false !== ($filename = readdir($dh)))
{
if ($filename != "." && $filename != ".." && !is_dir($fpath.$filename))
{
$files[$i]['name'] = $filename;
$Sum_Files++;
$i++;
}
}
$fl.='<div align="center">'.br().$lang['fm_choose_file'].br();
$fl.='<span id="gd">&nbsp;</span>'.br().'<br><br>';
$fl.='<table class="border">'.br();
$fl.='<tr>'.br().'<td colspan="8" align="left"><strong>'.$Theader.'</strong></td>'.br().'<td colspan="3" align="right"><a href="filemanagement.php?action='.$action.'&amp;kind='.$akind.'" class="small">'.$Wheader.'</a></td>'.br().'</tr>'.br();
//Tableheader
$fl.='<tr class="thead">'.br().'<th colspan="2">'.$lang['db'].'</th>'.br().'
<th>gz</th>'.br().'
<th>Script</th>'.br().'
<th colspan="2">'.$lang['comment'].'</th>'.br().'
<th>'.$lang['fm_filedate'].'</th>'.br().'
<th>Multipart</th>'.br().'
<th>'.$lang['fm_tables'].' / '.$lang['fm_records'].'</th>'.br().'
<th align="right" colspan="2">'.$lang['fm_filesize'].'</th>'.br().'
<th align="right" >'.$lang['encoding'].'</th>'.br().'</tr>'.br();
$checkindex=$arrayindex=$gesamt=0;
$db_summary_anzahl=Array();
if(count($files)>0)
{
for ($i=0; $i<sizeof($files); $i++)
{
// Dateigr&ouml;&szlig;e
$size = filesize($fpath.$files[$i]['name']);
$file_datum=date("d\.m\.Y H:i", filemtime($fpath.$files[$i]['name']));
//statuszeile auslesen
$sline='';
if(substr($files[$i]['name'],-2)=="gz"){
if($config['zlib']) {
$fp = gzopen ($fpath.$files[$i]['name'], "r");
$sline=gzgets($fp,40960);
gzclose ($fp);
}
}else{
$fp = fopen ($fpath.$files[$i]['name'], "r");
$sline=fgets($fp,5000);
fclose ($fp);
}
$statusline=ReadStatusline($sline);
$but=ExtractBUT($files[$i]['name']);
if ($but=="") $but=$file_datum;
$dbn=$statusline['dbname'];
//jetzt alle in ein Array packen
if($statusline['part']=="MP_0" || $statusline['part']=="")
{
$db_backups[$arrayindex]['name']=$files[$i]['name'];
$db_backups[$arrayindex]['db']=$dbn;
$db_backups[$arrayindex]['size']=$size;
$db_backups[$arrayindex]['date']=$but;
$db_backups[$arrayindex]['sort']=sortierdatum($but);
$db_backups[$arrayindex]['tabellen']=$statusline['tables'];
$db_backups[$arrayindex]['eintraege']=$statusline['records'];
$db_backups[$arrayindex]['multipart']=0;
$db_backups[$arrayindex]['kommentar']=$statusline['comment'];
$db_backups[$arrayindex]['script']=($statusline['script']!="") ? $statusline['script']."(".$statusline['scriptversion'].")" : "";
$db_backups[$arrayindex]['charset']=$statusline['charset'];
if(!isset($db_summary_last[$dbn])) $db_summary_last[$dbn]=$but;
$db_summary_anzahl[$dbn]=(isset($db_summary_anzahl[$dbn])) ? $db_summary_anzahl[$dbn]+1 : 1;
$db_summary_size[$dbn]=(isset($db_summary_size[$dbn])) ? $db_summary_size[$dbn]+$size : $size;
if($but>$db_summary_last[$dbn])$db_summary_last[$dbn]=$but;
}
else
{
//multipart nur einmal
$done=0;
if(!isset($db_summary_size[$dbn])) $db_summary_size[$dbn]=0;
for($j=0;$j<$arrayindex;$j++)
{
if(isset($db_backups[$j]))
{
if ( ($db_backups[$j]['date']==$but) && ($db_backups[$j]['db']==$dbn) )
{
$db_backups[$j]['multipart']++;
$db_backups[$j]['size']+=$size;
$db_summary_size[$dbn]+=$size;
$done=1;
break;
}
}
}
if ($done==1) $arrayindex--;
if($done==0)
{
//Eintrag war noch nicht vorhanden
$db_backups[$arrayindex]['name']=$files[$i]['name'];
$db_backups[$arrayindex]['db']=$dbn;
$db_backups[$arrayindex]['size']=$size;
$db_backups[$arrayindex]['date']=$but;
$db_backups[$arrayindex]['sort']=sortierdatum($but);
$db_backups[$arrayindex]['tabellen']=$statusline['tables'];
$db_backups[$arrayindex]['eintraege']=$statusline['records'];
$db_backups[$arrayindex]['multipart']=1;
$db_backups[$arrayindex]['kommentar']=$statusline['comment'];
$db_backups[$arrayindex]['script']=($statusline['script']!="") ? $statusline['script']."(".$statusline['scriptversion'].")" : "";
$db_backups[$arrayindex]['charset']=$statusline['charset'];
if(!isset($db_summary_last[$dbn])) $db_summary_last[$dbn]=$but;
$db_summary_anzahl[$dbn]=(isset($db_summary_anzahl[$dbn])) ? $db_summary_anzahl[$dbn]+1 : 1;
$db_summary_size[$dbn]=(isset($db_summary_size[$dbn])) ? $db_summary_size[$dbn]+$size : $size;
if( $but>$db_summary_last[$dbn])$db_summary_last[$dbn]=$but;
}
}
// Gesamtgr&ouml;&szlig;e aller Backupfiles
$arrayindex++;
$gesamt = $gesamt + $size;
}
}
//Schleife fertig - jetzt Ausgabe
if ( (isset($db_backups)) && (is_array($db_backups)) ) $db_backups=mu_sort($db_backups,'sort,name');
// Hier werden die Dateinamen ausgegeben
$rowclass=0;
if($arrayindex>0) {
for($i=$arrayindex;$i>=0;$i--) {
//$cl= ($rowclass % 2) ? "dbrow" : "dbrow1";
if(isset($db_backups[$i]['db']) && $db_backups[$i]['db']==$dbactiv)
{
$multi=($db_summary_anzahl[$dbactiv]>1 && $action=="files") ? 1 : 0;
$fl.='<input type="hidden" name="multi" value="'.$multi.'">';
if($db_backups[$i]['multipart']>0) {$dbn=NextPart($db_backups[$i]['name'],1);}else{$dbn=$db_backups[$i]['name'];}
$fl.='<tr ';
$fl.='class="'.(($rowclass % 2) ? 'dbrow"':'dbrow1"');
$fl.='>'.br();
$fl.='<td align="left" colspan="2" nowrap>'.br();
if($multi==0)
{
$fl.='<input type="hidden" name="multipart[]" value="'.$db_backups[$i]['multipart'].'"><input name="file[]" type="radio" class="radio" value="'.$dbn.'" onClick="Check('.$checkindex++.',0);">';
}
else
{
$fl.='<input type="hidden" name="multipart[]" value="'.$db_backups[$i]['multipart'].'"><input name="file[]" type="checkbox" class="checkbox" value="'.$dbn.'" onClick="Check('.$checkindex++.',1);">';
}
$fl.=($db_backups[$i]['multipart']==0) ? '&nbsp;<a href="'.$fpath.$dbn.'" title="Backupfile: '.$dbn.'" style="font-size:8pt;" target="_blank">'.(($db_backups[$i]['db']=='unknown') ? $dbn : $db_backups[$i]['db']).'</a></td>'.br() : '&nbsp;<span style="font-size:8pt;">'.$db_backups[$i]['db'].'</span></td>'.br();
$fl.='<td class="sm" nowrap align="center">'.((substr($dbn,-3)==".gz") ? '<img src="'.$config['files']['iconpath'].'gz.gif" alt="'.$lang['compressed'].'" width="16" height="16" border="0">' : "&nbsp;").'</td>';
$fl.='<td class="sm" nowrap align="center">'.$db_backups[$i]['script'].'</td>';
$fl.='<td class="sm" nowrap align="right">'.(($db_backups[$i]['kommentar']!="") ? '<img src="'.$config['files']['iconpath'].'rename.gif" alt="'.$db_backups[$i]['kommentar'].'" title="'.$db_backups[$i]['kommentar'].'" width="16" height="16" border="0">' : "&nbsp;").'</td>';
$fl.='<td class="sm" nowrap align="left">'.(($db_backups[$i]['kommentar']!="") ? nl2br(wordwrap($db_backups[$i]['kommentar'],50)) : "&nbsp;").'</td>';
$fl.='<td class="sm" nowrap>'.$db_backups[$i]['date'].'</td>'.br();
$fl.='<td style="text-align:center">';
$fl.=($db_backups[$i]['multipart']==0) ? $lang['no'] : '<a style="font-size:11px;" href="filemanagement.php?action=files&kind=0&dbactiv='.$dbactiv.'&expand='.$i.'">'.$db_backups[$i]['multipart'].' Files</a>'; //
$fl.='</td>'.br().'<td style="text-align:right;padding-right:12px;" nowrap>';
$fl.=($db_backups[$i]['eintraege']!=-1) ? $db_backups[$i]['tabellen'].' / '.number_format($db_backups[$i]['eintraege'],0,",",".") :$lang['fm_oldbackup'];
$fl.='</td>'.br();
$fl.='<td align="right" colspan="2" style="font-size:8pt;">'.byte_output($db_backups[$i]['size']).'</td>'.br();
$fl.='<td align="right" style="font-size:8pt;">'.$db_backups[$i]['charset'].'</td>'.br();
$fl.='</tr>'.br();
if($expand==$i) {
$fl.='<tr '.(($dbactiv==$databases['db_actual']) ? 'class="dbrowsel"' : 'class="'.$cl.'"').'>'.br();
$fl.='<td class="sm" valign="top">All Parts:</td><td class="sm" colspan="11" align="left">'.PartListe($db_backups[$i]['name'],$db_backups[$i]['multipart']).'</td>';
}
$rowclass++;
}
}
}
$fl.='<tr>'.br().'<td colspan="11" align="left"><br><strong>'.$lang['fm_all_bu'].'</strong></td>'.br().'</tr>'.br();
//Tableheader
$fl.='<tr class="thead">'.br().'<th colspan="5" align="left">'.$lang['fm_dbname'].'</th>'.br().'
<th align="left">'.$lang['fm_anz_bu'].'</th>'.br().'
<th>'.$lang['fm_last_bu'].'</th>'.br().'
<th colspan="5" style="text-align:right;">'.$lang['fm_totalsize'].'</th></tr>'.br();
//die anderen Backups
if(count($db_summary_anzahl)>0)
{
$i=0;
while(list($key, $val) = each($db_summary_anzahl))
{
$cl= ($i++ % 2) ? "dbrow" : "dbrow1";
$keyaus=($key=="unknown") ? '<em>'.$lang['no_msd_backupfile'].'</em>' : $key;
$fl.='<tr class="'.$cl.'">'.br().'<td colspan="5" align="left"><a href="'.$href.'&dbactiv='.$key.'">'.$keyaus.'</a></td>'.br();
$fl.='<td style="text-align:right">'.$val.'&nbsp;&nbsp;</td>'.br();
$fl.='<td class="sm" nowrap>'.((isset($db_summary_last[$key])) ? $db_summary_last[$key] : "").'</td>'.br();
$fl.='<td style="text-align:right;font-size:8pt;" colspan="5">'.byte_output($db_summary_size[$key]).'&nbsp;</td>'.br();
$fl.='</tr>'.br(3);
}
}
if (!is_array($files)) $fl.='<tr><td colspan="11">'.$lang['fm_nofilesfound'].'</td></tr>'.br();
//--------------------------------------------------------
//*** Ausgabe der Gesamtgr&ouml;&szlig;e aller Backupfiles ***
//--------------------------------------------------------
$space = MD_FreeDiskSpace();
$fl.= '<tr>'.br();
$fl.= '<td align="left" colspan="8"><b>'.$lang['fm_totalsize'].' ('.$Sum_Files.' files): </b> </td>'.br();
$fl.= '<td style="text-align:right" colspan="4"><b>'.byte_output($gesamt).'</b></td>'.br();
$fl.= '</tr>'.br();
//--------------------------------------------------------
//*** Ausgabe des freien Speicher auf dem Rechner ***
//--------------------------------------------------------
$fl.= '<tr>'.br();
$fl.= '<td colspan="8" align="left">'.$lang['fm_freespace'].': </td>'.br();
$fl.= '<td colspan="4" style="text-align:right"><b>'.$space.'</b></td>'.br();
$fl.= '</tr>'.br();
$fl.= '</table></div>'.br();
return $fl;
}
function read_statusline_from_file($filename)
{
global $config;
if(strtolower(substr($filename,-2))=='gz')
{
$fp = gzopen ($config['paths']['backup'].$filename, "r");
if ($fp===false) die('Can\'t open file '.$filename);
$sline=gzgets($fp,40960);
gzclose ($fp);
}
else
{
$fp = fopen ($config['paths']['backup'].$filename, "r");
if ($fp===false) die('Can\'t open file '.$filename);
$sline=fgets($fp,5000);
fclose ($fp);
}
$statusline=ReadStatusline($sline);
return $statusline;
}
function PartListe($f,$nr)
{
global $config;
$dateistamm=substr($f,0,strrpos($f,"part_"))."part_";
$dateiendung=(substr(strtolower($f),-2)=="gz")?".sql.gz":".sql";
$s="";
for($i=1;$i<=$nr;$i++) {
if($i>1) $s.="<br>";
$s.='<a href="'.$config['paths']['backup'].$dateistamm.$i.$dateiendung.'">'.$dateistamm.$i.$dateiendung.'</a>&nbsp;&nbsp;&nbsp;'.byte_output(@filesize($config['paths']['backup'].$dateistamm.$i.$dateiendung));
}
return $s;
}
function Converter($filesource,$filedestination,$cp) {
global $config,$lang;
$cps=(substr(strtolower($filesource),-2)=="gz") ? 1 : 0;
echo "<h5>".sprintf($lang['convert_fileread'],$filesource).".....</h5><span style=\"font-size:10px;\">";
if(file_exists($config['paths']['backup'].$filedestination)) unlink($config['paths']['backup'].$filedestination);
$f = ($cps==1) ? gzopen($config['paths']['backup'].$filesource,"r") : fopen($config['paths']['backup'].$filesource,"r");
$z= ($cps==1) ? gzopen($config['paths']['backup'].$filedestination,"w") : fopen($config['paths']['backup'].$filedestination,"w");
$insert=$mode="";
$n=0;
$eof= ($cps==1) ? gzeof($f) : feof($f);
WHILE (!$eof)
{
$eof= ($cps==1) ? gzeof($f) : feof($f);
$zeile= ($cps==1) ? gzgets($f,8192) : fgets($f,8192);
if (substr($zeile,0,2)=="--") $zeile="";
//$zeile=rtrim($zeile);
$t=strtolower(substr($zeile,0,10));
if ($t>"")
{
switch ($t)
{
case "insert int":
{
// eine neue Insert Anweisung beginnt
$insert= substr($zeile,0,strpos($zeile,"("));
if(substr(strtoupper($insert),-7)!="VALUES ") $insert.="VALUES ";
$mode="insert";
};
break;
case "create tab":
{
$mode="create";
WHILE (substr(rtrim($zeile),-1)!=";")
{
$zeile.=fgets($f,8192);
}
$zeile="\n\r".MySQL_Ticks($zeile)."\n\r";
break;
}
case "drop table":
{
$mode="drop";
$zeile.="\n\r";
break;
}
}
if ($mode=="insert")
{
// Komma loeschen
$zeile=str_replace("),(",");\n$insert (",$zeile);
if(substr(rtrim($zeile),0,2)==",(" && $insert !="") {
$zeile=";\n".$insert.substr($zeile,1);
}
if(substr(rtrim($zeile),-2)==")," && $insert !="") {
$zeile=substr(rtrim($zeile),0,strlen(rtrim($zeile))-1).";\n$insert";
}
}
$n++;
if ($n>1000) { $n=0;echo "<br>"; }
echo ".";
if($cps==1) gzwrite($z,$zeile); else fwrite($z,$zeile);
}
flush();
$n++;
}
if($cps==1) gzclose($z); else fclose($z);
if($cps==1) gzclose($f); else fclose($f);
echo "</span><h5>".sprintf($lang['convert_finished'],$filedestination)."</h5>";
}
?>

Datei anzeigen

@ -0,0 +1,986 @@
<?php
include_once('./inc/runtime.php');
// places all Page Parameters in hidden-fields (needed fpr backup and restore in PHP)
function get_page_parameter($parameter,$ziel='dump')
{
$page_parameter='<form action="'.$ziel.'.php" method="POST" name="'.$ziel.'">'."\n";
foreach ($parameter As $key=>$val)
{
$page_parameter.='<input type="hidden" name="'.$key.'" value="'.$val.'">'."\n";
}
$page_parameter.='</form>';
return $page_parameter;
}
function mu_sort ($array, $key_sort)
{
$key_sorta = explode(",", $key_sort);
$keys = array_keys($array[0]);
$n=0;
for($m=0; $m < count($key_sorta); $m++) { $nkeys[$m] = trim($key_sorta[$m]); }
$n += count($key_sorta); // counter used inside loop
for($i=0; $i < count($keys); $i++)
{
if(!in_array($keys[$i], $key_sorta))
{
$nkeys[$n] = $keys[$i];
$n += "1";
}
}
for($u=0;$u<count($array); $u++)
{
$arr = $array[$u];
for ($s=0; $s<count($nkeys); $s++)
{
$k = $nkeys[$s];
if (isset($array[$u][$k])) $output[$u][$k] = $array[$u][$k];
}
}
// wenn die Sortierung nicht ab- sondern aufsteigend sein soll, muss sort() benutzt werden
sort($output); // Sort=Aufsteigend -> oder rsort=absteigend
return $output;
}
function FillMultiDBArrays()
{
global $config,$databases;
// Nur füllen wenn überhaupt Datenbanken gefunden wurden
if ( (isset($databases['Name'])) && (count($databases['Name'])>0) )
{
$databases['multi']=Array();
$databases['multi_praefix']=Array();
if(!isset($databases['db_selected_index'])) $databases['db_selected_index']=0;
if(!isset($databases['db_actual']) && isset($databases['Name'])) $databases['db_actual']=$databases['Name'][$databases['db_selected_index']];
if(!isset($databases['multisetting'])) $databases['multisetting']='';
if($config['multi_dump']==1)
{
if($databases['multisetting']=='')
{
$databases['multi'][0]=$databases['db_actual'];
$databases['multi_praefix'][0]=(isset($databases['praefix'][0])) ? $databases['praefix'][0] : '';
}
else
{
$databases['multi']=explode(';',$databases['multisetting']);
$flipped = array_flip($databases['Name']);
for($i=0;$i<count($databases['multi']);$i++)
{
$ind=$flipped[$databases['multi'][$i]];
$databases['multi_praefix'][$i]=(isset($databases['praefix'][$ind])) ? $databases['praefix'][$ind] : '';
}
}
}
else
{
$databases['multi'][0]=(isset($databases['db_actual'])) ? $databases['db_actual'] : '';
$databases['multi_praefix'][0]=(isset($databases['praefix'])) ? $databases['praefix'][$databases['db_selected_index']] : '';
}
}
}
function DBDetailInfo($index)
{
global $databases,$config;
$databases['Detailinfo']['tables']=$databases['Detailinfo']['records']=$databases['Detailinfo']['size']=0;
MSD_mysql_connect();
if (isset($databases['Name'][$index]))
{
mysql_select_db($databases['Name'][$index]);
$databases['Detailinfo']['Name']=$databases['Name'][$index];
$res=@mysql_query('SHOW TABLE STATUS FROM `'.$databases['Name'][$index].'`');
if($res) $databases['Detailinfo']['tables']=mysql_num_rows($res);
if($databases['Detailinfo']['tables']>0) {
$s1=$s2=0;
for ($i = 0; $i < $databases['Detailinfo']['tables']; $i++)
{
$row = mysql_fetch_array($res);
// Get nr of records -> need to do it this way because of incorrect returns when using InnoDBs
$sql_2="SELECT count(*) as `count_records` FROM `".$databases['Name'][$index]."`.`".$row['Name']."`";
$res2=@mysql_query($sql_2);
$row2=mysql_fetch_array($res2);
$row['Rows']=$row2['count_records'];
$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)
{
if($count>=strlen($s))
return str_repeat("0",$count-strlen($s)).$s;
else
return $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 '<script language="JavaScript">WP("'.addslashes($txt).','.$object.'");</script>';
}
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] : '<span class="explain" title="Bytes">B</span>';
break;
case 1:
$suffix = (isset($names[1])) ? $names[1] : '<span class="explain" title="KiloBytes">KB</span>';
break;
case 2:
$suffix = (isset($names[2])) ? $names[2] : '<span class="explain" title="MegaBytes">MB</span>';
break;
case 3:
$suffix = (isset($names[3])) ? $names[3] : '<span class="explain" title="GigaBytes">GB</span>';
break;
case 4:
$suffix = (isset($names[4])) ? $names[4] : '<span class="explain" title="TeraBytes">TB</span>';
break;
case 5:
$suffix = (isset($names[4])) ? $names[4] : '<span class="explain" title="PetaBytes">PB</span>';
break;
case 6:
$suffix = (isset($names[4])) ? $names[4] : '<span class="explain" title="ExaBytes">EB</span>';
break;
case 7:
$suffix = (isset($names[4])) ? $names[4] : '<span class="explain" title="YottaBytes">ZB</span>';
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 (strtolower($sp[$anz])=='perl') $anz--;
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,$lang;
$log=date('d.m.Y H:i:s').' '.$aktion."\n";
$logfile=($config['logcompression']==1) ? $config['files']['log'].'.gz' : $config['files']['log'];
if(@filesize($logfile)+strlen($log)>$config['log_maxsize']) @unlink($logfile);
//Datei öffnen und schreiben
if($config['logcompression']==1) {
$fp = @gzopen($logfile, 'a');
if($fp) {
@gzwrite ($fp,$log) .'<br>';
@gzclose ($fp);
} else echo '<p class="warnung">'.$lang['logfilenotwritable'].' ('.$logfile.')</p>';
} else {
$fp = @fopen($logfile, "ab");
if($fp) {
@fwrite ($fp,$log);
@fclose ($fp);
} else echo '<p class="warnung">'.$lang['logfilenotwritable'].' ('.$logfile.')</p>';
}
}
function ErrorLog($dest,$db,$sql,$error,$art=1)
{
//$art=0 -> Fehlermeldung
//$art=1 -> Hinweis
global $config;
if(strlen($sql)>100) $sql=substr($sql,0,100)." ... (snip)";
//Error-Zeile generieren
$errormsg=date('d.m.Y H:i:s').': ';
$errormsg.=($dest=='RESTORE') ? ' Restore of db `'.$db.'`|:|' : ' Dump of db `'.$db.'`|:|';
if ($art==0)
{
$errormsg.='<font color="red">Error-Message: '.$error.'</font>|:|';
}
else
{
$errormsg.='<font color="green">Notice: '.$error.'</font>|:|';
}
$errormsg.='SQL: '.$sql."\n";
//Datei öffnen und schreiben
if($config['logcompression']==1) {
$fp = @gzopen($config['paths']['log'].'error.log.gz', 'ab');
if($fp) {
@gzwrite ($fp,($errormsg));
@gzclose ($fp);
}
} else {
$fp = @fopen($config['paths']['log'].'error.log', 'ab');
if($fp) {
@fwrite ($fp,($errormsg));
@fclose ($fp);
}
}
}
function DirectoryWarnings($path="")
{
global $config,$lang;
$warn='';
if(!is_writable($config['paths']['work'])) $warn.=sprintf($lang['wrong_rights'],$config['paths']['work'],'0777');
if(!is_writable($config['paths']['config'])) $warn.=sprintf($lang['wrong_rights'],$config['paths']['config'],'0777');
if(!is_writable($config['paths']['backup'])) $warn.=sprintf($lang['wrong_rights'],$config['paths']['backup'],'0777');
if(!is_writable($config['paths']['structure'])) $warn.=sprintf($lang['wrong_rights'],$config['paths']['structure'],'0777');
if(!is_writable($config['paths']['log'])) $warn.=sprintf($lang['wrong_rights'],$config['paths']['log'],'0777');
if($warn!='') $warn='<span class="warnung"><strong>'.$warn.'</strong></span>';
return $warn;
}
function TestWorkDir()
{
global $config;
$ret=SetFileRechte($config['paths']['work']);
if($ret===true) $ret=SetFileRechte($config['paths']['backup']);
if($ret===true) $ret=SetFileRechte($config['paths']['structure']);
if($ret===true) $ret=SetFileRechte($config['paths']['log']);
if($ret===true) $ret=SetFileRechte($config['paths']['config']);
if($ret===true)
{
if(!file_exists($config['files']['parameter'])) SetDefault(true);
if(!file_exists($config['files']['log'])) DeleteLog();
}
return $ret;
}
function SetFileRechte($file,$is_dir=1,$perm=0777)
{
global $lang;
$ret=true;
if ($is_dir==1)
{
if(substr($file,-1)!="/") $file.="/";
}
clearstatcache();
// erst pruefen, ob Datei oder Verzeichnis existiert
if (!file_exists($file))
{
// Wenn es sich um ein Verzeichnis handelt -> anlegen
if ($is_dir==1)
{
$ret=@mkdir($file, $perm);
if (!$ret===true)
{
// Hat nicht geklappt -> Rueckmeldung
$ret=sprintf($lang['cant_create_dir'],$file);
}
}
}
// wenn bisher alles ok ist -> Rechte setzen - egal ob Datei oder Verzeichnis
if ($ret===true)
{
$ret=@chmod($file,$perm);
if (!$ret===true) $ret=sprintf($lang['wrong_rights'],$file,decoct($perm));
}
return $ret;
}
function SelectDB($index)
{
global $databases;
if (isset($databases['Name'][$index]))
{
$databases['db_actual'] = $databases['Name'][$index];
if (isset($databases['praefix'][$index])) $databases['praefix'][$databases['db_selected_index']] = $databases['praefix'][$index];
else $databases['praefix'][$databases['db_selected_index']]='';
if (isset($databases['db_selected_index'])) $databases['db_selected_index']=$index;
else $databases['db_selected_index']=0;
}
else
{
// keine DB vorhanden
$databases['praefix'][$databases['db_selected_index']]='';
$databases['db_selected_index']=0;
$databases['db_actual']='';
}
}
function EmptyDB($dbn)
{
global $config;
//$res=mysql_query("DROP DATABASE `$dbn`") or die(mysql_error()."");
//$res=mysql_query("CREATE DATABASE `$dbn`") or die(mysql_error()."");
$t_sql=Array();
$tabellen = mysql_list_tables($dbn,$config['dbconnection']);
$num_tables = mysql_num_rows($tabellen);
for($i=0;$i<$num_tables;$i++) {
$t=mysql_tablename($tabellen,$i);
$t_sql[]="DROP TABLE `$t`;";
}
for($i=0;$i<count($t_sql);$i++) {
$res=mysql_query($t_sql[$i]) 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");
$sline=gzgets($fp,40960);
gzclose ($fp);
}else{
$fp = fopen ($config['paths']['backup'].$filename, "r");
$sline=fgets($fp,500);
fclose ($fp);
}
$statusline=ReadStatusline($sline);
$tabellenanzahl=($statusline["tables"]==-1) ? "" : $statusline["tables"];
$eintraege=($statusline["records"]==-1) ? "" : $statusline["records"];
$part=($statusline["part"]=="MP_0") ? 0 : substr($statusline["part"],3);
$databases['db_actual']=$statusline["dbname"];
$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<sizeof($files); $i++)
{
$delfile=explode("|",$files[$i]);
$ts=substr($delfile[0],0,4)."-".substr($delfile[0],5,2)."-".substr($delfile[0],8,2);
if(strtotime($ts)<$nowtime){
$out.=DeleteFile($files[$i],"days");
unset($files[$i]);
}
}
}
@rsort($files);
if($config['max_backup_files'] > 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="<p class=\"error\">".$ll."<br>";
$r.= $delfile[3]."<br>";
WriteLog("autodeleted ($function) '$delfile[3]'.");
unlink($config['paths']['backup'].$delfile[3]);
$r.= "</p>";
return $r;
}
function ReadStatusline($line)
{
/*AUFBAU der Statuszeile:
-- Status:tabellenzahl:datensätze:Multipart:Datenbankname:script:scriptversion:Kommentar:MySQLVersion:Backupflags:SQLBefore:SQLAfter:Charset:EXTINFO
Aufbau Backupflags (1 Zeichen pro Flag, 0 oder 1, 2=unbekannt)
(complete inserts)(extended inserts)(ignore inserts)(delayed inserts)(downgrade)(lock tables)(optimize tables)
*/
global $lang;
$statusline=Array();
if(substr($line,0,8)!="# Status" && substr($line,0,9)!="-- Status")
{
//Fremdfile
$statusline["tables"]=-1;
$statusline["records"]=-1;
$statusline["part"]="MP_0";
$statusline["dbname"]="unknown";
$statusline["script"]="";
$statusline["scriptversion"]="";
$statusline["comment"]="";
$statusline["mysqlversion"]="unknown";
$statusline["flags"]="2222222";
$statusline["sqlbefore"]="";
$statusline["sqlafter"]="";
$statusline["charset"]='?';
}
else
{
// MySQLDumper-File - Informationen extrahieren
$s=explode(":",$line);
if(count($s)<12)
{
//fehlenden Elemente auffüllen
$c=count($s);
array_pop($s);
for($i=$c-1;$i<12;$i++) {$s[]="";}
}
$statusline["tables"]=$s[1];
$statusline["records"]=$s[2];
$statusline["part"]=($s[3]=="") ? "MP_0":$s[3];
$statusline["dbname"]=$s[4];
$statusline["script"]=$s[5];
$statusline["scriptversion"]=$s[6];
$statusline["comment"]=$s[7];
$statusline["mysqlversion"]=$s[8];
$statusline["flags"]=$s[9];
$statusline["sqlbefore"]=$s[10];
$statusline["sqlafter"]=$s[11];
if ( (isset($s[12])) && trim($s[12])!='EXTINFO') $statusline["charset"]=$s[12];
else $statusline["charset"]='?';
}
//flags zerlegen
if(strlen($statusline["flags"])<6) $statusline["flags"]="2222222";
$statusline["complete_inserts"]=substr($statusline["flags"],0,1);
$statusline["extended_inserts"]=substr($statusline["flags"],1,1);
$statusline["ignore_inserts"]=substr($statusline["flags"],2,1);
$statusline["delayed_inserts"]=substr($statusline["flags"],3,1);
$statusline["downgrade"]=substr($statusline["flags"],4,1);
$statusline["lock_tables"]=substr($statusline["flags"],5,1);
$statusline["optimize_tables"]=substr($statusline["flags"],6,1);
return $statusline;
}
function NextPart($s,$first=0)
{
global $restore;
$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;
}
$restore['part']=$p;
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 TesteFTP($ftp_server,$ftp_port,$ftp_user_name,$ftp_user_pass,$ftp_dir)
{
global $lang,$config;
if(!isset($config['ftp_timeout'])) $config['ftp_timeout']=60;
if($ftp_port=="" || $ftp_port==0) $ftp_port=21;
$pass=-1;
if(!extension_loaded("ftp")) {
$s='<span class="error">'.$lang['noftppossible'].'+++</span>';
} else $pass=0;
if($pass==0) {
if($ftp_server=="" || $ftp_user_name=="" || $ftp_user_pass=="") {
$s='<span class="error">'.$lang['wrongconnectionpars'].'</span>';
} else $pass=1;
}
if($pass==1) {
$s=$lang['connect_to'].' `'.$ftp_server.'` Port '.$ftp_port.'<br>';
if($config['ftp_useSSL']==0) {
$conn_id = @ftp_connect($ftp_server,$ftp_port,$config['ftp_timeout']);
} else {
$conn_id = @ftp_ssl_connect($ftp_server,$ftp_port,$config['ftp_timeout']);
}
if ($conn_id) $login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if(!$conn_id || (!$login_result)) {
$s.='<span class="error">'.$lang['conn_not_possible'].'</span>';
} else $pass=2;
}
if($pass==2) {
$s.='<br><strong>Login ok</strong><br>'.$lang['changedir'].' `'.$ftp_dir.'` ... ';
$dirc=@ftp_chdir($conn_id,$ftp_dir);
if(!$dirc) {
$s.='<br><span class="error">'.$lang['changedirerror'].'</span>';
} else $pass=3;
@ftp_close($conn_id);
}
if($pass==3) $s.='<br><br><strong>'.$lang['ftp_ok'].'</strong>';
return $s;
}
function Realpfad($p) {
global $config;
if(!isset($config['disabled'])) $config['disabled']=ini_get("disable_functions");
if(strpos($config['disabled'],"realpath"))
$s=getcwd();
else
$s=realpath($p);
$s=str_replace("\\","/",$s);
if(substr($s,-1)!="/") $s.="/";
return $s;
}
function GetPerlConfigs() {
global $config;
$default=$config['cron_configurationfile'];
$dh = opendir($config['paths']['config']);
$r="";
while (false !== ($filename = readdir($dh)))
{
if ($filename != "." && $filename != ".." && !is_dir($config['paths']['config'].$filename) && substr($filename,-9)==".conf.php") {
$f=substr($filename,0,strlen($filename)-9);
$r.='<option value="'.$f.'" ';
if($filename==$default) $r.=' SELECTED';
$r.='>&nbsp;&nbsp;'.$f.'&nbsp;&nbsp;</option>'."\n";
}
}
return $r;
}
function GetThemes() {
global $config;
$default=$config['theme'];
$dh = opendir($config['paths']['root']."css/");
$r="";
while (false !== ($filename = readdir($dh)))
{
if ($filename != "." && $filename != ".." && is_dir($config['paths']['root']."css/".$filename)) {
$r.='<option value="'.$filename.'" ';
if($filename==$default) $r.=' SELECTED';
$r.='>&nbsp;&nbsp;'.$filename.'&nbsp;&nbsp;</option>'."\n";
}
}
return $r;
}
function GetLanguageCombo($k="op",$class="",$name="",$start="",$end="") {
global $config,$lang;
$default=$config['language'];
$dh = opendir($config['paths']['root']."language/");
$r="";
while (false !== ($filename = readdir($dh)))
{
if ($filename != "." && $filename != '.svn' && $filename != ".." && $filename != "flags" && is_dir($config['paths']['root']."language/".$filename)) {
//echo $config['paths']['root']."language/".$filename."<br>";
if($k=="op") {
$r.=$start.'<option value="'.$filename.'" ';
if($filename==$default) $r.=' SELECTED';
$r.=' class="'.$class.'">&nbsp;&nbsp;'.$lang[$filename].'&nbsp;&nbsp;</option>'.$end."\n";
} elseif($k=="radio") {
$r.=$start.'<input type="radio" class="'.$class.'" name="'.$name.'" value="'.$filename.'" '.(($filename==$default) ? "checked" : "").' onclick="show_tooldivs(\''.$filename.'\');"><img src="language/flags/'.$filename.'.gif" alt="" width="25" height="15" border="0">&nbsp;&nbsp;&nbsp;'.$lang[$filename].$end."\n";
}
}
}
return $r;
}
function headline($title,$mainframe=1) {
global $config,$lang;
$s="";
if($config['interface_server_caption']==1) {
if($config['interface_server_caption_position']==$mainframe) {
$s.='<div id="server'.$mainframe.'">'.$lang['server'].': <a class="server" href="http://'.$_SERVER['SERVER_NAME'].'" target="_blank" title="'.$_SERVER['SERVER_NAME'].'">'.$_SERVER['SERVER_NAME'].'</a></div>';
}
}
if ($mainframe==1) {
$s.='<div id="pagetitle">'.$title.'</div>';
$s.='<div id="content">';
}
return $s;
}
function PicCache($rpath="./") {
global $BrowserIcon,$config;
$t='<div style="display:none">';
$dh=opendir($config['files']['iconpath']);
while (false !== ($filename = readdir($dh)))
{
if ($filename != "." && $filename != ".." && !is_dir($config['files']['iconpath'].$filename)) {
$t.='<img src="'.$config['files']['iconpath'].$filename.'" width="16" height="16" alt="">';
}
}
$t.='</div>';
return $t;
}
function MSDHeader($kind=0,$onloadFunction="")
{
global $config, $databases,$lang,$frameset_restore;
header('content-type: text/html; charset=utf-8');
//kind 0=main 1=menu 2=help
$d=($kind==2) ? "../../" : "./";
$r='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'."\n<html>\n<head>\n";
if ($kind==0) {
//Main without caching
$r.='<META HTTP-EQUIV="Pragma" CONTENT="no-cache">'."\n";
} else {
$r.='<META HTTP-EQUIV="cache-control" CONTENT="public">'."\n";
}
$r.='<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'."\n";
$r.='<META NAME="robots" CONTENT="none">'."\n";
$r.='<META NAME="robots" CONTENT="noindex">'."\n";
$r.='<title>MySqlDumper</title>'."\n";
$r.='<link rel="stylesheet" type="text/css" href="'.$d.'css/'.$config['theme'].'/style.css">'."\n";
$r.='<script language="JavaScript" src="'.$d.'js/script.js" type="text/javascript"></script>'."\n";
if($frameset_restore==1) $r.='<script language="JavaScript">
//restore the frameset
var params="";
if(document.URL.indexOf("/") != -1)
{
var stringArray = document.URL.split("/");
params = stringArray.pop();
}
if (parent.frames.length == 0) { parent.location.href="index.php?page="+params; }
</script>';
$r.="</head>\n<body ".(($kind==1) ? 'class="menu"' : '').(($onloadFunction!="") ? ' onload="'.$onloadFunction.'();"' : '').'>';
return $r;
}
function MSDFooter($rfoot="",$enddiv=1)
{
global $config, $databases,$dump,$restore,$lang;
$f= '<div id="footer">'.$lang['authors'].':&nbsp;
<a class="small" href="http://dislabs.de" target="_blank">
Daniel Schlichtholz &amp; Steffen Kamper</a> - Infoboard:
<a class="small" href="'.$config['homepage'].'" target="_blank">'.
$config['homepage'].'</a></div>';
if($enddiv==1) $f.= '</div>';
$f.=$rfoot.'</body></html>';
return $f;
}
function save_bracket($str)
{
// Wenn Klammer zu am Ende steht, diese behalten
$str=trim($str);
if (substr($str,-1)==')') $str=')';
else $str='';
return $str;
}
function DownGrade($s,$show=true)
{
// if (MSD_NEW_VERSION && strpos(strtolower($s),"collate ") && ($show) ) {
// return $s;
// } else {
$tmp=explode(",",$s);
//echo "<pre>";print_r($tmp);echo "</pre>";
for($i=0;$i<count($tmp);$i++) {
$t=strtolower($tmp[$i]);
if(strpos($t,"collate ")) {
$tmp2=explode(" ",$tmp[$i]);
for($j=0;$j<count($tmp2);$j++) {
if(strtolower($tmp2[$j])=="collate") {$tmp2[$j]="";$tmp2[$j+1]=save_bracket($tmp2[$j+1]);$j++;}
}
$tmp[$i]=implode(" ",$tmp2);
}
if(strpos($t,"engine=")) {
$tmp2=explode(" ",$tmp[$i]);
for($j=0;$j<count($tmp2);$j++) {
//echo $j.": ".$tmp2[$j]."<br>";
if(substr(strtoupper($tmp2[$j]),0,7)=="ENGINE=") $tmp2[$j]="TYPE=".substr($tmp2[$j],7);
if(substr(strtoupper($tmp2[$j]),0,8)=="CHARSET=") { $tmp2[$j]="";
$tmp2[$j-1]=save_bracket($tmp2[$j-1]);}
if(substr(strtoupper($tmp2[$j]),0,8)=="COLLATE=")
{
$tmp2[$j]=save_bracket($tmp2[$j]);
if (isset($tmp2[$j+1])) $tmp2[$j+1]=save_bracket($tmp2[$j+1]);
$tmp2[$j-1]="";
}
if(substr(strtoupper($tmp2[$j]),0,8)=="COMMENT=")
{
$tmp2[$j]=save_bracket($tmp2[$j]);
if (isset($tmp2[$j+1])) $tmp2[$j+1]=save_bracket($tmp2[$j+1]);
$tmp2[$j-1]="";
}
}
$tmp[$i]=implode(" ",$tmp2);
}
// collate entfernen
if(strpos($t,"collate"))
{
$tmp2=explode(" ",$tmp[$i]);
$end=false;
for($j=0;$j<count($tmp2);$j++) {
if(strtolower($tmp2[$j])=="collate"){
$tmp2[$j]=save_bracket($tmp2[$j]);
$tmp2[$j+1]=save_bracket($tmp2[$j+1]);
}
}
$tmp[$i]=implode(" ",$tmp2);
}
// character Set sprache entfernen
if(strpos($t,"character set"))
{
$tmp2=explode(" ",$tmp[$i]);
$end=false;
for($j=0;$j<count($tmp2);$j++) {
if(strtolower($tmp2[$j])=="character"){
$tmp2[$j]='';
$tmp2[$j+1]=save_bracket($tmp2[$j+1]);
$tmp2[$j+2]=save_bracket($tmp2[$j+2]);
}
}
$tmp[$i]=implode(" ",$tmp2);
}
if(strpos($t,"timestamp")) {
$tmp2=explode(" ",$tmp[$i]);
$end=false;
for($j=0;$j<count($tmp2);$j++) {
if($end) $tmp2[$j]="";
if(strtolower($tmp2[$j])=="timestamp"){
$tmp2[$j]="TIMESTAMP(14)";
$end=true;
}
}
$tmp[$i]=implode(" ",$tmp2);
}
}
$t=implode(",",$tmp);
if(substr(rtrim($t),-1)!=";") $t=rtrim($t).";";
return $t;
}
function MySQL_Ticks($s) {
$klammerstart=$lastklammerstart=$end=0;
$inner_s_start=strpos($s,'(');
$inner_s_end=strrpos($s,')');
$inner_s=substr($s,$inner_s_start+1,$inner_s_end-(1+$inner_s_start));
$pieces=explode(',',$inner_s);
for($i=0;$i<count($pieces);$i++)
{
$r=trim($pieces[$i]);
$klammerstart+=substr_count($r, "(")-substr_count($r, ")");
if($i==count($pieces)-1) $klammerstart+=1;
if(substr(strtoupper($r),0,4)=="KEY " ||
substr(strtoupper($r),0,7)=="UNIQUE " ||
substr(strtoupper($r),0,12)=="PRIMARY KEY " ||
substr(strtoupper($r),0,13)=="FULLTEXT KEY "
)
{
//nur ein Key
$end=1;
}
else
{
if(substr($r,0,1)!='`' && substr($r,0,1)!='\'' && $klammerstart==0 && $end==0 && $lastklammerstart==0)
{
$pos=strpos($r,' ');
$r='`'.substr($r,0,$pos).'`'.substr($r,$pos);
}
}
$pieces[$i]=$r;
$lastklammerstart=$klammerstart;
}
$back=substr($s,0,$inner_s_start+1).implode(",",$pieces).");";
return $back;
}
function check_manual_dbs()
{
global $config,$databases;
// Prüfen, ob manuell angelegte Datenbanken existieren
$dbs_manual=@file('./'.$config['files']['dbs_manual']);
if (is_array($dbs_manual))
{
foreach ($dbs_manual as $d)
{
if (!isset($databases['Name'])) $databases['Name']=array();
$index=count($databases['Name'])-1;
if ($index==-1) $index=0;
if ((trim($d)>'') && !in_array($d,$databases['Name']))
{
$databases['Name'][$index]=$d;
$databases['praefix'][$index]='';
$databases['command_before_dump'][$index]='';
$databases['command_after_dump'][$index]='';
}
// wenn Index==-1 -> keine Db gewählt -> DB 0 als aktuell setzen
if ($databases['db_selected_index']==-1)
{
$databases['db_selected_index']=0;
$databases['db_actual']=$databases['Name'][0];
}
}
}
}
function convert_to_utf8($obj)
{
global $config;
$ret=$obj;
// wenn die Verbindung zur Datenbank nicht auf utf8 steht, dann muessen die Rückgaben in utf8 gewandelt werden,
// da die Webseite utf8-kodiert ist
if (isset($config['connect_utf8']) && $config['connect_utf8']!=1)
{
if (is_array($obj))
{
foreach ($obj as $key=>$val)
{
//echo "<br> Wandle ".$val." nach ";
$obj[$key]=utf8_encode($val);
//echo $obj[$key];
}
}
if (is_string($obj)) $obj=utf8_encode($obj);
$ret=$obj;
}
return $ret;
}
// returns the index of the selected val in an optionlist
function get_index($arr,$selected)
{
$ret=false; // return false if not found
foreach ($arr as $key=>$val)
{
if (strtolower(substr($val,0,strlen($selected)))==strtolower($selected))
{
$ret=$key;
break;
}
}
return $ret;
}
?>

Datei anzeigen

@ -0,0 +1,500 @@
<?php
include_once('./inc/functions_global.php');
include_once('./inc/runtime.php');
define('DEBUG',0);
function AnzahlTabellenfelder($s,$debug=0)
{
/******* Diese Funktion wird nur in der develop.php gebraucht *******/
// ermittelt die Anzahl der Spalten einer Tabelle aus einer CREATE-Anweisung
$anz=$anz_delimter=$rit=$klammerstart=$klammerauf=$klammerzu=0;
$s=strtoupper($s);
$i=strpos($s,"(")+1;
$s=substr($s,$i);
$tb=explode(',',$s);
$defaultstart=false;
for ($i=0;$i<count($tb);$i++){
$tb[$i]=trim($tb[$i]);
$klammerstart+=substr_count($tb[$i], "(")-substr_count($tb[$i], ")");
if($i==count($tb)-1) $klammerstart+=1;
$anz_delimter+=substr_count($tb[$i], "'");
if($anz_delimter % 2 ==0) $anz_delimter=0;
//kommt ein Index???
if(substr($tb[$i],0,4)=='KEY ' ||
substr($tb[$i],0,7)=='UNIQUE ' ||
substr($tb[$i],0,12)=='PRIMARY KEY ' ||
substr($tb[$i],0,13)=='FULLTEXT KEY '
) {
$rit=1;
} else {
if($klammerstart==0 && $anz_delimter==0) {
if($rit==0) $anz++;
$rit=0;
}
}
if($debug==1) echo "$i: $tb[$i]".' <font color="#0000FF">'.$anz."</font> [offene Klammern: $klammerstart] --$rit<br>";
}
return $anz;
}
function get_sqlbefehl()
{
global $restore,$config,$databases,$lang;
//Init
$restore['fileEOF']=false;
$restore['EOB']=false;
$complete_sql='';
$sqlparser_status=0;
if(!isset($restore['eintraege_ready'])) $restore['eintraege_ready']=0;
//Parsen
WHILE ($sqlparser_status!=100 && !$restore['fileEOF'] && !$restore['EOB'] )
{
//nächste Zeile lesen
$zeile= ($restore['compressed']) ? gzgets($restore['filehandle']) : fgets($restore['filehandle']);
/******************* Setzen des Parserstatus *******************/
// herausfinden um was für einen Befehl es sich handelt
IF ($sqlparser_status==0)
{
//Vergleichszeile, um nicht bei jedem Vergleich strtoupper ausführen zu müssen
$zeile2=strtoupper(trim($zeile));
// Am Ende eines MySQLDumper-Backups angelangt?
if(substr($zeile2,0,6)=='-- EOB' || substr($zeile2,0,5)=='# EOB')
{
$restore['EOB']=true;
$zeile='--';$zeile2='--';
$sqlparser_status=100;
}
// Kommenatr?
if ( (substr($zeile2,0,2)=='--') || (substr($zeile2,0,1)=='#') )
{
$zeile='';$zeile2=''; $sqlparser_status=0;
}
//Einfache Anweisung finden die mit Semikolon beendet werden
if(substr($zeile2,0,11)=='LOCK TABLES') $sqlparser_status=5;
if(substr($zeile2,0,6)=='COMMIT') $sqlparser_status=5;
if(substr($zeile2,0,5)=='BEGIN') $sqlparser_status=5;
if(substr($zeile2,0,13)=='UNLOCK TABLES') $sqlparser_status=5;
if(substr($zeile2,0,4)=='SET ') $sqlparser_status=5;
if(substr($zeile2,0,6)=='START ') $sqlparser_status=5;
if(substr($zeile2,0,3)=='/*!') $sqlparser_status=5; //MySQL-Condition oder Kommentar
if(substr($zeile2,0,11)=='ALTER TABLE') $sqlparser_status=5;
if(substr($zeile2,0,12)=='CREATE TABLE') $sqlparser_status=2; //Createaktion
if(substr($zeile2,0,12)=='CREATE INDEX') $sqlparser_status=4; //Indexaktion
//Kommentar
if ( ($sqlparser_status!=5) && (substr($zeile2,0,2)=='/*')) $sqlparser_status=6;
// Befehle, die nicht ausgeführt werden sollen
if (substr($zeile2,0,4)=='USE ') $sqlparser_status=7;
if (substr($zeile2,0,14)=='DROP DATABASE ') $sqlparser_status=7;
if(substr($zeile2,0,10)=='DROP TABLE') $sqlparser_status=1; //Löschaktion
if (substr($zeile2,0,7)=='INSERT ')
{
$sqlparser_status=3; //Datensatzaktion
//$restore['actual_table']=strtolower(get_tablename_aus_insert($zeile));
$restore['actual_table']=get_tablename_aus_insert($zeile);
// Pruefen ob die Spaltenanzahl bekannt ist und wenn nicht setzen
if(!isset($restore['num_table_fields'][$restore['actual_table']]))
{
$restore['num_table_fields'][$restore['actual_table']]=get_num_rows($restore['actual_table']);
}
}
// Fortsetzung von erweiterten Inserts
if ($restore['flag']==1) $sqlparser_status=3;
if ( ($sqlparser_status==0) && (trim($complete_sql)>'') && ($restore['flag']==-1) )
{
// Unbekannten Befehl entdeckt
v($restore);
echo "<br>Sql: ".$complete_sql;
echo "<br>Erweiterte Inserts: ".$restore['erweiterte_inserts'];
die('<br>'.$lang['unknown_sqlcommand'].': '.$zeile);
}
/******************* Ende von Setzen des Parserstatus *******************/
}
$last_char=substr(rtrim($zeile),-1);
// Zeilenumbrüche erhalten - sonst werden Schlüsselwörter zusammengefügt
// z.B. 'null' und in der nächsten Zeile 'check' wird zu 'nullcheck'
$complete_sql.=$zeile."\n";
if($sqlparser_status==1)
{ //Löschaktion
if($last_char==';') $sqlparser_status=100; //Befehl komplett
}
if($sqlparser_status==2)
{
// Createanweisung ist beim Finden eines ; beendet
if($last_char==';' )
{
if($config['minspeed']>0) $restore['anzahl_zeilen']=$config['minspeed'];
//Spaltenanzahl fuer diese Tabelle merken
$restore['actual_table']=get_tablename($complete_sql);
$complete_sql=del_inline_comments($complete_sql); //Inline-Kommentare entfernen
//Create ausfuehren und Anzahl der Spalten speichern
$restore['actual_fieldcount']=submit_create_action($complete_sql);
$restore['num_table_fields'][$restore['actual_table']]=$restore['actual_fieldcount'];
// Zeile verwerfen und naechsten Befehl suchen
$complete_sql='';
$sqlparser_status=0;
}
}
if($sqlparser_status==3)
{
//INSERT
// Anzahl der Felder ermitteln wenn unbekannt
if(!isset($restore['num_table_fields'][$restore['actual_table']]))
{
$restore['num_table_fields'][$restore['actual_table']]=get_num_rows($restore['actual_table']);
}
$AnzahlFelder=SQL_Is_Complete($complete_sql,$restore['num_table_fields'][$restore['actual_table']],DEBUG);
// einen vollständigen Insert ermittelt
if($AnzahlFelder==$restore['num_table_fields'][$restore['actual_table']])
{
$sqlparser_status=100;
$complete_sql=trim($complete_sql);
// letzter Ausdruck des erweiterten Inserts erreicht?
if(substr($complete_sql,-2)==');')
{
$restore['flag']=-1;
}
// Wenn am Ende der Zeile ein Klammer Komma -> erweiterter Insert-Modus -> Steuerflag setzen
if(substr($complete_sql,-2)=='),')
{
// letztes Komme gegen Semikolon tauschen
$complete_sql=substr($complete_sql,0,-1).';';
$restore['erweiterte_inserts']=1;
$restore['flag']=1;
}
if (substr(strtoupper($complete_sql),0,7)!='INSERT ')
{
$complete_sql=$restore['insert_syntax'].' VALUES '.$complete_sql.';';
}
else
{
// INSERT Syntax ermitteln und merken
$ipos=strpos(strtoupper($complete_sql),'VALUES');
if (!$ipos===false) $restore['insert_syntax']=substr($complete_sql,0,$ipos);
else $restore['insert_syntax']='INSERT INTO `'.$restore['actual_table'].'`';
}
if($AnzahlFelder>$restore['num_table_fields'][$restore['actual_table']] && $restore['erweiterte_inserts']==0)
{
if(!isset($restore['table_create'][$restore['actual_table']]))
{
global $lang;
include('./inc/functions_sql.php');
$restore['table_create'][$restore['actual_table']]=GetCreateTable($databases['db_actual'],$restore['actual_table']);
}
echo '<form action="main.php?action=extinfo" method="post">';
echo '<p class="warnung">Parser-Fehler : zuviele gezählt in Tabelle '.$restore["actual_table"].' ('.$AnzahlFelder.' statt '.$restore["num_table_fields"][$restore["actual_table"]].')';
echo '<br>Aktuelle Tabelle: '.$restore['actual_table'];
echo '<h4>CREATE-Anweisung</h4><textarea name="create_sql" style="width:90%;height:200px;">'.$restore["table_create"][$restore["actual_table"]].'</textarea>';
echo '<h4>INSERT-Anweisung</h4><textarea name="insert_sql" style="width:90%;height:200px;">'.$complete_sql.'</textarea></p><br>';
echo '<br><br><input type="submit" name="tell_error" value="Fehlerbericht"></form>'.$zeile;
die;
}
}
}
// Index
if($sqlparser_status==4)
{ //Createindex
if($last_char==';' )
{
if($config['minspeed']>0) {$restore['anzahl_zeilen']=$config['minspeed'];}
$complete_sql=del_inline_comments($complete_sql);
$sqlparser_status=100; //Befehl komplett
}
}
// Kommentar oder Condition
if($sqlparser_status==5)
{ //Anweisung
if($last_char==';' )
{
if($config['minspeed']>0) {$restore['anzahl_zeilen']=$config['minspeed'];}
$complete_sql=del_inline_comments($complete_sql);
$sqlparser_status=100; //Befehl komplett
}
}
// Mehrzeiliger oder Inline-Kommentar
if($sqlparser_status==6)
{
if(!strrpos($zeile,'*/')===false)
{
$complete_sql=trim(del_inline_comments($complete_sql));
$sqlparser_status=0;
}
}
// Befehle, die verworfen werden sollen
if($sqlparser_status==7)
{ //Anweisung
if($last_char==';' )
{
if($config["minspeed"]>0) {$restore["anzahl_zeilen"]=$config["minspeed"];}
$complete_sql='';
$sqlparser_status=0;
}
}
if ( ($restore['compressed']) && (gzeof($restore['filehandle'])) ) $restore['fileEOF']=true;
if ( (!$restore['compressed']) && (feof($restore['filehandle'])) ) $restore['fileEOF']=true;
}
return trim($complete_sql);
}
function submit_create_action($sql)
{
//Führt eine Create-Anweisung durch und ermittelt danach die Anzahl der aktuellen Spalten
// und legt diese im Array ab
global $restore;
$tablename=get_tablename($sql);
if (DEBUG)
{
echo "<br>Tabellenname: ".$tablename;
echo "<br>Create: ".$sql;
}
$res=mysql_query($sql);
if (!$res===false)
{
if (DEBUG) echo "<br>Create-Anweisung erfolgreich ausgeführt.";
$restore['actual_table']=$tablename;
$restore['table_ready']++;
}
else
{
//erster Versuch die Tabelle anzulegen hat nicht geklappt
// versuchen wir es mal mit der alten Syntax
$res=mysql_query(downgrade($sql));
if (!$res===false)
{
if (DEBUG) echo "<br>Create-Anweisung nach Downgrade erfolgreich ausgeführt.";
$restore['actual_table']=$tablename;
$restore['table_ready']++;
}
else
{
SQLError($sql,'Couldn\'t create table: '.$tablename);
die();
}
}
return get_num_rows($tablename);
}
function get_num_rows($tablename)
{
//Anzahl der Tabellenspalten ermitteln
$sql='SHOW COLUMNS FROM `'.$tablename.'`';
$res=mysql_query($sql);
if ($res)
{
$num_rows=mysql_num_rows($res);
}
else
{
global $restore;
v($restore);
die('Couldn\'t read rowcount for table '.$tablename.'!<br>Restore:'.$restore['actual_table']);
}
return $num_rows;
}
function del_inline_comments($sql)
{
$sql=str_replace("\n",'<br>',$sql);
//Inline-Kommentare entfernen
preg_match_all("/(\/\*(.+)\*\/)/U",$sql,$array);
if (is_array($array[0]))
{
if (DEBUG)
{
v($array);
echo"<br><hr>vorher:<br>".$sql."<br><hr>";
}
$sql=str_replace($array[0],'',$sql);
if (DEBUG) echo"Nachher: :<br>".$sql."<br><hr>";
}
$sql=trim(str_replace('<br>',"\n",$sql));
//Wenn nach dem Entfernen nur noch ein ; übrigbleibt -> entfernen
if ($sql==';') $sql='';
return $sql;
}
function lock_table()
{
global $config,$restore;
if ($config["lock_tables"]==1 && (isset($restore["actual_table"])) && ($restore["actual_table"]<>"unbekannt") )
{
$sql="LOCK TABLES `".$restore["actual_table"]."` WRITE";
$res=MSD_query($sql) || die(SQLError("Kein Lock ausgeführt!",mysql_error()));
}
}
function stri_replace($original,$patterns)
{
$finalremove=$original;
$piece_front='';
$piece_back='';
$piece_replace='';
for ($x=0; $x < count($patterns); $x++)
{
$safety=0;
while(strstr(strtolower($finalremove),strtolower($patterns[$x])))
{
$safety=$safety+1;
if ($safety >= 100000) { break; }
$occ=strpos(strtolower($finalremove),strtolower($patterns[$x]));
$piece_front=substr($finalremove,0,$occ);
$piece_back=substr($finalremove,($occ+strlen($patterns[$x])));
$finalremove=$piece_front . $piece_replace . $piece_back;
}
}
return $finalremove;
}
// extrahiert auf einfache Art den Tabellennamen aus dem "Create"-Befehl
function get_tablename($t)
{
global $restore;
$ersetzen=array('CREATE TABLE','IF NOT EXISTS');
$t=trim(stri_replace($t,$ersetzen));
$t=trim(str_replace('(',' ',$t));
$w=explode(' ',$t);
$tn=$w[0];
if(substr($tn,0,1)=='`') $tn=substr($tn,1,strlen($tn)-2);
return $tn;
}
// extrahiert auf einfache Art den Tabellennamen aus dem "Insert"-Befehl
function get_tablename_aus_insert($t)
{
$t=substr($t,0,100);
$t=substr($t,strpos(strtolower($t), 'into ')+5);
$w=explode(' ',$t);
$tn=$w[0];
if(substr($tn,0,1)=='`') $tn=substr($tn,1,strlen($tn)-2);
return $tn;
}
function SQL_Is_Complete($s,$expected=0,$debug=0)
{
global $restore;
if ($debug) echo "<br>Zu analysieren:".$s."<br>";
$anz=$f_begin=$f_end=$restore["erw_anz"]=0;
$Backslash=chr(92);
$s=trim(strtoupper(($s)));
if(substr($s,-2)==");" || substr($s,-2)=="),") $s=substr($s,0,strlen($s)-2);
if(substr($s,-1)==")") $s=substr($s,0,strlen($s)-1);
if(strpos($s," VALUES")) {
$i=strpos($s," VALUES")+7;
$s=substr($s,$i);
}
$i=strpos($s,"(")+1;
$s=substr($s,$i);
$tb=explode(",",$s);
for ($i=0;$i<count($tb);$i++){
$first=$B_Esc=$B_Ticks=$B_Dashes=0;
$v=trim(rtrim($tb[$i]));
//erweitert ?
if($anz==0 && $restore["erweiterte_inserts"]==1 && substr($v,0,1)=="(") $v=substr($v,1);
if($expected>0 && $anz==$expected-1 && substr($v,-1)==")") {
$v=substr($v,0,strlen($v)-1); // ) entfernen
//if($i+1<count($tb)) $tb[$i+1]=substr(trim(rtrim($tb[$i+1])),1);
if($restore["erweiterte_inserts"]==0) {
$restore["erweiterte_inserts"]=1;
$restore["flag"]=1;
}
}
//Ticks + Dashes zählen
for($cpos=2;$cpos<=strlen($v);$cpos++)
{if(substr($v,(-1*$cpos),1)=="'") {$B_Ticks++;} else {break;}}
for($cpos=2;$cpos<=strlen($v);$cpos++)
{if(substr($v,(-1*$cpos),1)=='"') {$B_Dashes++;} else {break;}}
//Backslashes zählen
for($cpos=2+$B_Ticks;$cpos<=strlen($v);$cpos++)
{if(substr($v,(-1*$cpos),1)=="\\") {$B_Esc++;} else {break;}}
if($v=="NULL" && $f_begin==0){$f_begin=1;$f_end=1;}
if($f_begin==0 && is_numeric($v)){$f_begin=1;$f_end=1;}
//blob fix von PHPMyAdmin Dump
if($f_begin==0 && substr($v,0,2)=="0X" && strpos($v," ")==false){$f_begin=1;$f_end=1;}
if($f_begin==0 && is_object($v)){$f_begin=1;$f_end=1;}
if(substr($v,0,1)=="'" && $f_begin==0) {$f_begin=1;if(strlen($v)==1)$first=1;$DELIMITER="'";}
if(substr($v,0,1)=='"' && $f_begin==0) {$f_begin=1;if(strlen($v)==1)$first=1;$DELIMITER='"';}
if($f_begin==1 && $f_end!=1 && $first==0){
if (substr($v,-1)==$DELIMITER){
$B_Delimiter=($DELIMITER=="'") ? $B_Ticks : $B_Dashes;
//ist Delimiter maskiert?
if (($B_Esc % 2)==1 && ($B_Delimiter % 2)==1 && strlen($v)>2) {
$f_end=1;
} elseif (($B_Delimiter % 2)==1 && strlen($v)>2) {
//ist mit `'` maskiert
$f_end=0;
} elseif(($B_Esc % 2)==1) {
//ist mit Backslash maskiert
$f_end=0;
} else {
$f_end=1;
}
}
}
if($debug==1) echo "<font color='#0000FF'>$f_begin/$f_end</font> Feld $i: ".htmlspecialchars($tb[$i])."<font color=#008000>- $anz ($B_Ticks / $B_Esc)</font><br>";
if($f_begin==1 && $f_end==1) {
$anz++;
$f_begin=$f_end=0;
if($anz==$expected) {
$restore["erw_anz"]++;
if($debug==1) echo "<h5>".$restore["erw_anz"].".Insert - (".$anz." Felder)</h5>";
$anz=0;
}
}
}
if($anz==0 && $expected>0 && $restore["erw_anz"]>0) $anz=$expected;
return $anz;
}
?>

Datei-Diff unterdrückt, da er zu groß ist Diff laden

21
mysqldumper/inc/header.php Normale Datei
Datei anzeigen

@ -0,0 +1,21 @@
<?php
include_once('./inc/functions.php');
include_once('./inc/mysql.php');
if (!defined('MSD_VERSION')) die('No direct access.');
if(!file_exists($config['files']['parameter'])) $error=TestWorkDir();
include('./'.$config['files']['parameter']);
include('./language/lang_list.php');
if (!isset($databases['db_selected_index'])) $databases['db_selected_index']=0;
SelectDB($databases['db_selected_index']);
$config['files']['iconpath']='css/'.$config['theme'].'/icons/';
session_name('MySQLDumper');
session_start();
$session_id=session_id();
//header('content-type: text/html; charset=utf-8');
if (isset($error)) echo $error;
?>

127
mysqldumper/inc/mysql.php Normale Datei
Datei anzeigen

@ -0,0 +1,127 @@
<?php
if (!defined('MSD_VERSION')) die('No direct access.');
//Feldspezifikationen
$feldtypen=Array("VARCHAR","TINYINT","TEXT","DATE","SMALLINT","MEDIUMINT","INT","BIGINT","FLOAT","DOUBLE","DECIMAL","DATETIME","TIMESTAMP","TIME","YEAR","CHAR","TINYBLOB","TINYTEXT","BLOB","MEDIUMBLOB","MEDIUMTEXT","LONGBLOB","LONGTEXT","ENUM","SET");
$feldattribute=ARRAY("","BINARY","UNSIGNED","UNSIGNED ZEROFILL");
$feldnulls=Array("NOT NULL","NULL");
$feldextras=Array("","AUTO_INCREMENT");
$feldkeys=Array("","PRIMARY KEY","UNIQUE KEY", "FULLTEXT");
$feldrowformat=Array("","FIXED","DYNAMIC","COMPRESSED");
$rechte_daten=Array("SELECT","INSERT","UPDATE","DELETE","FILE");
$rechte_struktur=Array("CREATE","ALTER","INDEX","DROP","CREATE TEMPORARY TABLES");
$rechte_admin=Array("GRANT","SUPER","PROCESS","RELOAD","SHUTDOWN","SHOW DATABASES","LOCK TABLES","REFERENCES","EXECUTE","REPLICATION CLIENT","REPLICATION SLAVE");
$rechte_resourcen=Array("MAX QUERIES PER HOUR","MAX UPDATES PER HOUR","MAX CONNECTIONS PER HOUR");
$sql_keywords=array( 'ALTER', 'AND', 'ADD', 'AUTO_INCREMENT','BETWEEN', 'BINARY', 'BOTH', 'BY', 'BOOLEAN','CHANGE', 'CHARSET','CHECK','COLLATE', 'COLUMNS', 'COLUMN', 'CROSS','CREATE', 'DATABASES', 'DATABASE', 'DATA', 'DELAYED', 'DESCRIBE', 'DESC', 'DISTINCT', 'DELETE', 'DROP', 'DEFAULT','ENCLOSED', 'ENGINE','ESCAPED', 'EXISTS', 'EXPLAIN','FIELDS', 'FIELD', 'FLUSH', 'FOR', 'FOREIGN', 'FUNCTION', 'FROM','GROUP', 'GRANT','HAVING','IGNORE', 'INDEX', 'INFILE', 'INSERT', 'INNER', 'INTO', 'IDENTIFIED','JOIN','KEYS', 'KILL','KEY','LEADING', 'LIKE', 'LIMIT', 'LINES', 'LOAD', 'LOCAL', 'LOCK', 'LOW_PRIORITY', 'LEFT', 'LANGUAGE', 'MEDIUMINT', 'MODIFY','MyISAM','NATURAL', 'NOT', 'NULL', 'NEXTVAL','OPTIMIZE', 'OPTION', 'OPTIONALLY', 'ORDER', 'OUTFILE', 'OR', 'OUTER', 'ON','PROCEEDURE','PROCEDURAL', 'PRIMARY','READ', 'REFERENCES', 'REGEXP', 'RENAME', 'REPLACE', 'RETURN', 'REVOKE', 'RLIKE', 'RIGHT','SHOW', 'SONAME', 'STATUS', 'STRAIGHT_JOIN', 'SELECT', 'SETVAL', 'TABLES', 'TEMINATED', 'TO', 'TRAILING','TRUNCATE', 'TABLE', 'TEMPORARY', 'TRIGGER', 'TRUSTED','UNIQUE', 'UNLOCK', 'USE', 'USING', 'UPDATE', 'UNSIGNED','VALUES', 'VARIABLES', 'VIEW','WITH', 'WRITE', 'WHERE','ZEROFILL','XOR','ALL', 'ASC', 'AS','SET','IN', 'IS', 'IF');
$mysql_doc=Array("Feldtypen" => "http://dev.mysql.com/doc/mysql/de/Column_types.html");
$mysql_SQLhasRecords=array('SELECT','SHOW','EXPLAIN');
function MSD_mysql_connect($encoding='utf8')
{
global $config,$databases;
$port=(isset($config['dbport']) && !empty($config['dbport'])) ? ':'.$config['dbport'] : '';
$socket=(isset($config['dbsocket']) && !empty($config['dbsocket'])) ? ':'.$config['dbsocket'] : '';
$config['dbconnection'] = mysql_connect($config['dbhost'].$port.$socket,$config['dbuser'],$config['dbpass']) or die(SQLError("Database connection error: ",mysql_error()));
if(!defined('MSD_MYSQL_VERSION')) GetMySQLVersion();
mysql_query('SET NAMES '.$encoding,$config['dbconnection']);
return $config['dbconnection'];
}
function GetMySQLVersion()
{
$res=MSD_query("select version()");
$row = mysql_fetch_array($res);
$version=$row[0];
$new=(substr($version,0,3)>=4.1);
if(!defined('MSD_MYSQL_VERSION')) define('MSD_MYSQL_VERSION', $version);
if(!defined('MSD_NEW_VERSION')) define('MSD_NEW_VERSION',$new);
return $version;
}
function MSD_query($query)
{
global $config;
if(!isset($config['dbconnection'])) MSD_mysql_connect();
return @mysql_query($query, $config['dbconnection']);
}
function MSD_mysql_error()
{
global $config,$databases;
}
function SQLError($sql,$error)
{
global $lang,$mysql_errorhelp_ref,$config;
echo '<div align="center"><table style="border:1px solid #ff0000" cellspacing="0">
<tr bgcolor="#ff0000"><td style="color:white;font-size:16px;"><strong>MySQL-ERROR</strong>&nbsp;&nbsp;<a href="'.$mysql_errorhelp_ref.'" target="_blank">
<img src="'.$config['files']['iconpath'].'help16.gif" alt="'.$lang['MySQLErrorDoc'].'" title="'.$lang['MySQLErrorDoc'].'" width="16" height="16" border="0"></a></td></tr>
<tr><td style="width:80%;overflow: auto;">'.$lang['sql_error1'].'<br><br>'.Highlight_SQL($sql).'</td></tr>
<tr><td width="600">'.$lang['sql_error2'].'<br><br><span style="color:red;">'.$error.'</span></td></tr>
</table>
</div>';
}
function Highlight_SQL($sql)
{
global $sql_keywords;
$end="";
$tickstart=false;
$a=@token_get_all("<?$sql?>");
foreach($a as $token) {
if(!is_array($token)) {
if($token=="`") $tickstart=!$tickstart;
$end.=$token;
} else {
if($tickstart) $end.=$token[1]; else {
switch(token_name($token[0])) {
case "T_STRING":
case "T_AS":
case "T_FOR":
$end.=(in_array(strtoupper($token[1]),$sql_keywords)) ? "<span style=\"color:#990099;font-weight:bold;\">".$token[1]."</span>": $token[1];
break;
case "T_IF":
case "T_LOGICAL_AND":
case "T_LOGICAL_OR":
case "T_LOGICAL_XOR":
$end.=(in_array(strtoupper($token[1]),$sql_keywords)) ? "<span style=\"color:#0000ff;font-weight:bold;\">".$token[1]."</span>": $token[1];
break;
case "T_CLOSE_TAG":
case "T_OPEN_TAG":
break;
default:
$end.=$token[1];
}
}
}
}
$end=preg_replace("/`(.*?)`/si", "<span style=\"color:red;\">`$1`</span>", $end);
return $end;
}
function Fieldlist($db,$tbl)
{
$fl='';
$res=MSD_query("SHOW FIELDS FROM `$db`.`$tbl`;");
if($res) {
$fl='(';
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_row($res);
$fl.='`'.$row[0].'`,';
}
$fl=substr($fl,0,strlen($fl)-1).')';
}
return $fl;
}
?>

119
mysqldumper/inc/runtime.php Normale Datei
Datei anzeigen

@ -0,0 +1,119 @@
<?php
if(file_exists('../extModInclude.php')) require_once('../extModInclude.php');
error_reporting(E_ALL);
//Konstanten
if (!defined('MSD_VERSION')) define('MSD_VERSION', '1.22');
if (!defined('MSD_VERSION_ADD')) define('MSD_VERSION_ADD', '');
if (!defined('MSD_OS')) define('MSD_OS', PHP_OS);
if (!defined('MSD_OS_EXT')) define('MSD_OS_EXT',@php_uname());
if (!defined('MSD_IS_WINDOWS')) {
if (stristr(PHP_OS, 'win')) {
define('MSD_IS_WINDOWS', 1);
} else {
define('MSD_IS_WINDOWS', 0);
}
}
if (!defined('MSD_USER_OS')) {
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
} else if (!isset($HTTP_USER_AGENT)) {
$HTTP_USER_AGENT = '';
}
// 1. Platform
if (strstr($HTTP_USER_AGENT, 'Win')) {
define('MSD_USER_OS', 'Win');
} else if (strstr($HTTP_USER_AGENT, 'Mac')) {
define('MSD_USER_OS', 'Mac');
} else if (strstr($HTTP_USER_AGENT, 'Linux')) {
define('MSD_USER_OS', 'Linux');
} else if (strstr($HTTP_USER_AGENT, 'Unix')) {
define('MSD_USER_OS', 'Unix');
} else if (strstr($HTTP_USER_AGENT, 'OS/2')) {
define('MSD_USER_OS', 'OS/2');
} else {
define('MSD_USER_OS', 'Other');
}
}
//feste Variabeln
$config['lock_tables']=0;
//Pfade und Files
$config['paths']['root']=Realpfad('./');
$config['paths']['work']='work/';
$config['paths']['backup']=$config['paths']['work'].'backup/';
$config['paths']['structure']=$config['paths']['work'].'structure/';
$config['paths']['log']=$config['paths']['work'].'log/';
$config['paths']['config']=$config['paths']['work'].'config/';
$config['paths']['perlexec']='msd_cron/';
$config['cron_configurationfile']='mysqldumper.conf';
$config['files']['log']=$config['paths']['log'].'mysqldump.log';
$config['files']['perllog']=$config['paths']['log'].'mysqldump_perl.log';
$config['files']['perllogcomplete']=$config['paths']['log'].'mysqldump_perl.complete.log';
$config['files']['parameter']=$config['paths']['config'].'parameter.php';
$config['files']['dbs_manual']=$config['paths']['config'].'dbs_manual.php';
// inti MySQL-Setting-Vars
$config['mysql_standard_character_set']='';
$config['mysql_possible_character_sets']=array();
//Ini-Parameter
$config['max_execution_time']=ini_get('max_execution_time');
$config['max_execution_time']=($config['max_execution_time']<=0) ? 30:$config['max_execution_time'];
if ($config['max_execution_time']>30) $config['max_execution_time']=30;;
$config['upload_max_filesize']=ini_get('upload_max_filesize');
$config['safe_mode']=ini_get('safe_mode');
$config['magic_quotes_gpc']=ini_get('magic_quotes_gpc');
$config['disabled']=ini_get('disable_functions');
$config['phpextensions']=implode(', ',get_loaded_extensions());
$m=str_replace('M','',get_cfg_var('memory_limit'));
$config['ram']=(empty($m)) ? 0 : $m;
//Ist zlib moeglich?
$p1=explode(', ',$config['phpextensions']);
$p2=explode(',',str_replace(' ','',$config['disabled']));
//Buggy PHP-Version ?
$p3=explode('.',PHP_VERSION);
$buggy=($p3[0]==4 && $p3[1]==3 && $p3[2]<3);
$config['zlib']=(!$buggy) && (in_array('zlib',$p1) && (!in_array('gzopen',$p2) || !in_array('gzwrite',$p2) || !in_array('gzgets',$p2) || !in_array('gzseek',$p2) || !in_array('gztell',$p2)));
//Tuning-Ecke
$config['tuning_add']=1.1;
$config['tuning_sub']=0.9;
$config['time_buffer']=0.75; //max_zeit=$config['max_execution_time']*$config['time_buffer']
$config['perlspeed']=10000; //Anzahl der Datensätze, die in einem Rutsch gelesen werden
//Bausteine
$meta=br().br().'<meta http-equiv="expires" content="3600"> '.br().'<META HTTP-EQUIV="Pragma" CONTENT="no-cache">'.br(2);
$config['homepage']='http://www.mysqldumper.de/board/';
$languagepacks_ref='http://www.mysqldumper.de/board/downloads.php?cat=9';
$stylepacks_ref='http://www.mysqldumper.de/board/downloads.php?cat=3';
$nl="\n";
$mysql_commentstring='--';
//config-Variablen, die nicht gesichert werden sollen
$config_dontsave=Array('max_execution_time','safe_mode','magic_quotes_gpc','disabled',
'phpextensions','ram','zlib','tuning_add','tuning_sub','time_buffer','perlspeed',
'dbconnection','version','mysql_possible_character_sets','mysql_standard_character_set');
//Initialisierungen
//0 schaltet frameset-restore aus
$frameset_restore=0;
function v($t)
{
echo '<br>';
if (is_array($t))
{
echo '<pre>';
print_r($t);
echo '</pre>';
}
else echo $t;
}
?>

Datei anzeigen

@ -0,0 +1,301 @@
<?php
if (!defined('MSD_VERSION')) die('No direct access.');
error_reporting(E_ALL);
$lang['browse']='Ansehen';
//define icons
$icon['browse']='<img src="'.$config['files']['iconpath'].'browse.gif" alt="'.$lang['edit'].'" title="'.$lang['browse'].'" border="0">';
$icon['edit']='<img src="'.$config['files']['iconpath'].'edit.gif" alt="'.$lang['edit'].'" title="'.$lang['edit'].'" border="0">';
$icon['empty']='<img src="'.$config['files']['iconpath'].'empty.gif" alt="'.$lang['empty'].'" title="'.$lang['empty'].'" border="0">';
$icon['empty_keys']='<img src="'.$config['files']['iconpath'].'emptykeys.gif" alt="'.$lang['emptykeys'].'" title="'.$lang['emptykeys'].'" border="0">';
$icon['delete']='<img src="'.$config['files']['iconpath'].'delete.gif" alt="'.$lang['delete'].'" title="'.$lang['delete'].'" border="0">';
$icon['key_primary']='<img src="'.$config['files']['iconpath'].'key_primary.gif" alt="primary key" border="0">';
// fuegt eine Sortierungsnummer hinzu, um die Ausgabereihenfolge der Daten steuern zu koennen
// (das Feld ENGINE interessiert mich nicht so sehr und muss nicht vorne stehen)
$keysort=array(
'Name' => 0,
'Rows' => 1,
'Data_length' => 2,
'Auto_increment' => 3,
'Avg_row_length' => 4,
'Max_data_length' => 5,
'Comment' => 6,
'Row_format' => 7,
'Index_length' => 8,
'Data_free' => 9,
'Collation' => 10,
'Create_time' => 11,
'Update_time' => 12,
'Check_time' => 13,
'Create_options' => 14,
'Version' => 15,
'Engine' => 16,
'Checksum' => 17
);
$byte_output=array('Data_length','Avg_row_length','Max_data_length','Index_length','Data_free');
function add_sortkey($name)
{
global $keysort;
//echo "<br>Uebergeben: ".$name;
if (array_key_exists($name,$keysort)) $ret=$keysort[$name];
else $ret=0;
return $ret;
}
//Data-View
echo $aus.'<h4>'.(($showtables==1)?$lang['sql_tableview']:$lang['sql_dataview']).'</h4><p>';
if($showtables==0){
$p='sql.php?sql_statement='.urlencode($sql['sql_statement']).'&amp;db='.$db.'&amp;tablename='.$tablename.'&amp;dbid='.$dbid.'&amp;limitstart='.$limitstart.'&amp;order='.$order.'&amp;orderdir='.$orderdir.'&amp;tdc='.$tdcompact;
echo '<a href="'.$p.'&amp;mode=new">'.$lang['sql_recordnew'].'</a>&nbsp;&nbsp;&nbsp;&nbsp;';
echo '<a href="sql.php?db='.$db.'&amp;dbid='.$dbid.'&amp;tablename='.$tablename.'&amp;context=2">'.$lang['sql_edit_tablestructure'].'</a>';
}
else
{
$p='sql.php?db='.$db.'&amp;dbid='.$dbid.'&amp;context=2';
echo '<a href="'.$p.'">'.$lang['sql_tablenew'].'</a>';
}
//Statuszeile
$tn=ExtractTablenameFromSQL($sql['sql_statement']);
echo '</p><p class="tablename">&nbsp;'.($tn!='' ? $lang['table'].' '.$tn : '').'</p><p align="left">';
if(isset($msg))echo $msg;
//SQL ausführen
if($sql_to_display_data==0)
{
//mehrere SQL-Statements
$numrowsabs=$numrows=0;
MSD_DoSQL($sql['sql_statement']);
echo SQLOutput($out);
}
else
{
$numrowsabs=$numrows=0;
$res=MSD_query($sql['sql_statement']) or die(SQLError($sql['sql_statement'],mysql_error()));
$numrowsabs=mysql_num_rows($res);
$sqltmp=$sql['sql_statement'].$sql['order_statement'].(strpos(strtolower($sql['sql_statement'].$sql['order_statement']),' limit ') ? '' : $limit);
$res=MSD_query($sqltmp) or die(SQLError($sqltmp,mysql_error()));
$numrows=mysql_num_rows($res);
if($limitende>$numrowsabs)$limitende=$numrowsabs;
}
if($numrowsabs>0 && $Anzahl_SQLs<=1)
{
if($showtables==0)
{
$command_line=$lang['info_records']." ".($limitstart+1)." - $limitende ".$lang['sql_vonins']." $numrowsabs &nbsp;&nbsp;&nbsp;";
$command_line.=($limitstart>0) ? '<a href="'.$params.'&amp;limitstart=0">&lt;&lt;</a>&nbsp;&nbsp;&nbsp;&nbsp;' : '&lt;&lt;&nbsp;&nbsp;&nbsp;&nbsp;';
$command_line.=($limitstart>0) ? '<a href="'.$params.'&amp;limitstart='.(($limitstart-$config['sql_limit']<0) ? 0 : $limitstart-$config['sql_limit']).'">&lt;</a>&nbsp;&nbsp;&nbsp;&nbsp;' : '&lt;&nbsp;&nbsp;&nbsp;&nbsp;';
$command_line.=($limitende<$numrowsabs) ? '<a href="'.$params.'&amp;limitstart='.($limitstart+$config['sql_limit']).'">&gt;</a>&nbsp;&nbsp;&nbsp;&nbsp;' : '&gt;&nbsp;&nbsp;&nbsp;&nbsp;';
$command_line.=($limitende<($numrowsabs-$config['sql_limit'])) ? '<a href="'.$params.'&amp;limitstart='.($numrowsabs-$config['sql_limit']).'">&gt;&gt;</a>' : '&gt;&gt;';
echo $command_line;
}
else
{
echo $numrowsabs." ".$lang['tables'];
}
echo '</p>';
//Datentabelle
echo '<table class="bordersmall" id="dataTable">';
$t=$d="";
$fdesc=Array();
$key=-1;
if ($numrows>0)
{
//Infos und Header holen
//1.Datensatz für Feldinfos
$row= mysql_fetch_row($res);
//Kompaktmodus-Switcher
$t='<td colspan="'.(count($row)+1).'" align="left"><a href="sql.php?db='.$db.'&amp;tablename='.$tablename.'&amp;dbid='.$dbid.'&amp;order='.$order.'&amp;orderdir='.$orderdir.'&amp;limitstart='.$limitstart.'&amp;sql_statement='.urlencode($sql['sql_statement']).'&amp;tdc='.(($tdcompact==0) ? '1' : '0').'">'.(($tdcompact==0) ? 'Ansicht: normal' : 'Ansicht: kompakt').'</a>';
$t.='&nbsp;&nbsp;&nbsp;'.$lang['sql_queryentry'].' '.count($row).' '.$lang['sql_columns'];
$t.='</td></tr><tr class="thead">';
$t.='<th>&nbsp;</th>';
$temp=array();
for($x=0; $x<count($row); $x++)
{
$temp[$x]['data'] = mysql_fetch_field($res,$x);
$temp[$x]['sort']=add_sortkey($temp[$x]['data']->name);
}
//v($temp);
if ($showtables==1) $temp=mu_sort($temp,'sort');
for($x=0; $x<count($temp); $x++)
{
$str=$temp[$x]['data'];
$t.='<th align="left">';
$pic="";
$fdesc[$temp[$x]['data']->name]['name']=isset($str->name) ? $str->name:'';
$fdesc[$temp[$x]['data']->name]['table']=isset($str->table) ? $str->table:'';
$fdesc[$temp[$x]['data']->name]['max_length']=isset($str->max_length) ? $str->max_length:'';
$fdesc[$temp[$x]['data']->name]['not_null']=isset($str->not_null) ? $str->not_null:'';
$fdesc[$temp[$x]['data']->name]['primary_key']=isset($str->primary_key) ? $str->primary_key:'';
$fdesc[$temp[$x]['data']->name]['unique_key']=isset($str->unique_key) ? $str->unique_key:'';
$fdesc[$temp[$x]['data']->name]['multiple_key']=isset($str->multiple_key) ? $str->multiple_key:'';
$fdesc[$temp[$x]['data']->name]['numeric']=isset($str->numeric) ? $str->numeric:'';
$fdesc[$temp[$x]['data']->name]['blob']=isset($str->blob) ? $str->blob:'';
$fdesc[$temp[$x]['data']->name]['type']=isset($str->type) ? $str->type:'';
$fdesc[$temp[$x]['data']->name]['unsigned']=$str->unsigned;
$fdesc[$temp[$x]['data']->name]['zerofill']=$str->zerofill;
$fdesc[$temp[$x]['data']->name]['Check_time']=isset($str->Check_time) ? $str->Check_time:'';
$fdesc[$temp[$x]['data']->name]['Checksum']=isset($str->Checksum) ? $str->Checksum:'';
$fdesc[$temp[$x]['data']->name]['Engine']=isset($str->Engine) ? $str->Engine:'';
$fdesc[$temp[$x]['data']->name]['Version']=isset($str->Version) ? $str->Version:'';
$tt="Name: ".$fdesc[$temp[$x]['data']->name]['name']
."\nType: ".$fdesc[$temp[$x]['data']->name]['type']
."\nMax Length: ".$fdesc[$temp[$x]['data']->name]['max_length']
."\nUnsigned: ".$fdesc[$temp[$x]['data']->name]['unsigned']
."\nzerofill: ".$fdesc[$temp[$x]['data']->name]['zerofill'];
$pic='<img src="images/blank.gif" alt="" width="1" height="1" border="0">';
if($str->primary_key==1 || $str->unique_key==1)
{
if($key==-1) $key=$temp[$x]['data']->name;
if($str->primary_key==1) $pic=$icon['key_primary'];
elseif($str->unique_key==1) $pic='<img src="'.$config['files']['iconpath'].'key.gif" alt="unique key" border="0">';
}
if($bb==-1)
$bb_link=($str->type=="blob") ? '&nbsp;&nbsp;&nbsp;<a style="font-size:10px;color:blue;" title="use BB-Code for this field" href="sql.php?db='.$db.'&amp;bb='.$x.'&amp;tablename='.$tablename.'&amp;dbid='.$dbid.'&amp;order='.$order.'&amp;orderdir='.$orderdir.'&amp;limitstart='.$limitstart.'&amp;sql_statement='.urlencode($sql['sql_statement']).'&amp;tdc='.$tdcompact.'">[BB]</a>' : '';
else
$bb_link=($str->type=="blob") ? '&nbsp;&nbsp;&nbsp;<a title="use BB-Code for this field" href="sql.php?db='.$db.'&amp;bb=-1&amp;tablename='.$tablename.'&amp;dbid='.$dbid.'&amp;order='.$order.'&amp;orderdir='.$orderdir.'&amp;limitstart='.$limitstart.'&amp;sql_statement='.urlencode($sql['sql_statement']).'&amp;tdc='.$tdcompact.'">[no BB]</a>' : '';
if($no_order==false && $showtables==0)
$t.=$pic.'&nbsp;<a title="'.$tt.'" href="sql.php?db='.$db.'&amp;tablename='.$tablename.'&amp;dbid='.$dbid.'&amp;order='.$str->name.'&amp;orderdir='.$norder.'&amp;sql_statement='.urlencode($sql['sql_statement']).'&amp;tdc='.$tdcompact.'">'.$str->name.'</a>'.$bb_link;
else
$t.=$pic.'&nbsp;<span title="'.$tt.'" >'.$str->name.'</span>'.$bb_link;
$arname=($orderdir==" ASC") ? "arup.gif" : "ardown.gif";
if($str->name==$order)$t.='&nbsp;&nbsp;<img src="'.$config['files']['iconpath'].$arname.'" alt="" border="0">';
$t.='</th>';
}
unset($temp);
$temp=array();
//und jetzt Daten holen
mysql_data_seek ($res, 0);
$s=$keysort;
$s=array_flip($keysort);
ksort($s);
for ($i=0;$i<$numrows;$i++)
{
$data[0]=mysql_fetch_array($res,MYSQL_ASSOC);
if ($showtables==1)
{
// Spalten sortieren, wenn wir uns in einer Tabellenuebersicht befinden
$xx=mu_sort($data,"$s[0],$s[1],$s[2],$s[3],$s[4],$s[5],$s[6],$s[7],$s[8],$s[9],$s[10],$s[11],$s[12],$s[13],$s[14],$s[15],$s[16]");
$temp[$i]=$xx[0];
}
else $temp[$i]=$data[0];
}
for ($i=0;$i<$numrows;$i++)
{
$row= $temp[$i]; // mysql_fetch_row($res);
$cl= ($i % 2) ? 'dbrow' : 'dbrow1';
$erste_spalte=1;
// bei Tabellenuebersicht soll nach vorgefertigter Reihenfolge sortiert werden, ansonsten einfach Daten anzeigen
if ($showtables==1) $sortkey=$keysort; else $sortkey=$row;
$spalte=0;
foreach ($sortkey as $rowkey=>$rowval)
{
if ($rowkey=='Name') $tablename=$row['Name'];
if($erste_spalte==1)
{
//edit-pics
$d.=$nl.'<td valign="top" nowrap class="small">&nbsp;'.$nl;
$p='sql.php?sql_statement='.urlencode($sql['sql_statement']).'&amp;db='.$db.'&amp;tablename='.$tablename.'&amp;dbid='.$dbid.'&amp;limitstart='.$limitstart.'&amp;order='.$order.'&amp;orderdir='.$orderdir.'&amp;editkey='.$rowkey.'&amp;tdc='.$tdcompact;
if($key==-1)
{
$rk='';
foreach ($row as $rowkey2=>$rowval2)
{
if (isset($fdesc[$rowkey2])) $rk.="`".$fdesc[$rowkey2]."`='".$rowval2."' AND ";
}
// AND abschneiden
$p.='&amp;recordkey='.urlencode(substr($rk,0,strlen($rk)-5));
}
else
{
//Key vorhanden
$p.='&amp;recordkey='.urlencode("`".$fdesc[$key]['name']."`='".$rowval."'");
}
if($showtables==1) $p.='&amp;recordkey='.$tablename;
if(!$no_edit)
{
if($showtables==0)
{
$d.='<a href="'.$p.'&amp;mode=edit">'.$icon['edit'].'</a>&nbsp;';
}
}
if($showtables==0)
{
$d.='<a href="'.$p.'&amp;mode=kill" onclick="if(!confirm(\''.$lang['askdeleterecord'].'\')) return false;">'.$icon['delete'].'</a>';
}
else
{
if($tabellenansicht==1)
{
$d.='<a href="sql.php?db='.$db.'&amp;dbid='.$dbid.'&amp;tablename='.$row['Name'].'&amp;context=2">'.$icon['edit'].'</a>&nbsp;'.$nl.$nl;
$d.='<a href="'.$p.'&amp;mode=empty" onclick="if(!confirm(\''.sprintf($lang['asktableempty'],$row['Name']).'\')) return false;">'.$icon['empty'].'</a>&nbsp;'.$nl.$nl;
$d.='<a href="'.$p.'&amp;mode=emptyk" onclick="if(!confirm(\''.sprintf($lang['asktableemptykeys'],$row['Name']).'\')) return false;">'.$icon['empty_keys'].'</a>&nbsp;'.$nl.$nl;
$d.='<a href="'.$p.'&amp;mode=kill" onclick="if(!confirm(\''.sprintf($lang['askdeletetable'],$row['Name']).'\')) return false;">'.$icon['delete'].'</a>&nbsp;'.$nl.$nl;
}
}
$d.='</td>';
$erste_spalte=0;
}
$d.='<td valign="top" class="small" nowrap>';
$divstart='<div'.(($tdcompact==1) ? ' class="tdcompact" ' : ' class="tdnormal"').'>';
$divend='</div>';
if($bb==$spalte)
{
$data=simple_bbcode_conversion($rowval);
}
else
{
if ($showtables==0)
{
if (isset($fdesc[$rowkey]['type']))
$data=($fdesc[$rowkey]['type']=='string' || $fdesc[$rowkey]['type']=='blob') ? strip_tags($rowval) : $rowval;
}
else
{
if (isset($temp[$i][$rowkey]))
$data=($fdesc[$rowkey]['type']=='string' || $fdesc[$rowkey]['type']=='blob') ? strip_tags($temp[$i][$rowkey]) : $temp[$i][$rowkey];
else $data='';
if (in_array($rowkey,$byte_output)) $data=byte_output($data);
}
}
$spalte++;
$browse_link='<a href="sql.php?db='.$db.'&amp;tablename='.$tablename.'&amp;dbid='.$dbid.'" title="'.$data.'">';
$d.=($tabellenansicht==1 && $rowkey=='Name') ? $divstart.$browse_link.$icon['browse']."</a>&nbsp;".$browse_link.$data."</a>$divend" : $divstart.$data.$divend;
$d.='</td>';
}
// Tabellenueberschrift en ausgeben
if($i==0) echo '<tr>'.$t.'</tr>';
// Daten anzeigen
echo "\n\n".'<tr class="'.$cl.'">'.$d.'</tr>'."\n\n";
$d="";
}
}
echo '</table>';
if($showtables==0) echo '<br>'.$command_line;
}
else echo '<p class="success">'.$lang['sql_nodata'].'</p>';
?>

Datei anzeigen

@ -0,0 +1,254 @@
<?php
//Im-/Export
$import=(isset($_GET['import'])) ? 1 : 0;
if($import==1) {
//IMPORT
CheckcsvOptions();
if(isset($_POST['f_import_csvtrenn'])) $sql['import']['trenn']=($config['magic_quotes_gpc']) ? stripslashes($_POST['f_import_csvtrenn']) : $_POST['f_import_csvtrenn'];
if(isset($_POST['f_import_csvenc'])) $sql['import']['enc']=($config['magic_quotes_gpc']) ? stripslashes($_POST['f_import_csvenc']) : $_POST['f_import_csvenc'];
if(isset($_POST['f_import_csvesc'])) $sql['import']['esc']=($config['magic_quotes_gpc']) ? stripslashes($_POST['f_import_csvesc']) : $_POST['f_import_csvesc'];
if (empty($sql['import']['endline'])) {
$sql['import']['endline']=$nl;
} else {
$sql['import']['endline']= str_replace('\\r', "\015",$sql['import']['endline']);
$sql['import']['endline'] = str_replace('\\n', "\012",$sql['import']['endline']);
$sql['import']['endline']= str_replace('\\t', "\011",$sql['import']['endline']);
}
$sql['import']['endline']= str_replace('\\t', "\011",$sql['import']['endline']);
if(isset($_POST['f_import_csvnull'])) $sql['import']['null']=($config['magic_quotes_gpc']) ? stripslashes($_POST['f_import_csvnull']) : $_POST['f_import_csvnull'];
$sql['import']['namefirstline']=(isset($_POST['f_import_namefirstline'])) ? $_POST['f_import_namefirstline'] : 0;
$sql['import']['emptydb']=(isset($_POST['import_emptydb'])) ? 1:0;
$sql['import']['createindex']=(isset($_POST['import_createindex'])) ? 1:0;
$sql['import']['table']=(isset($_POST['import_table'])) ? $_POST['import_table'] : "";
$sql['import']['import_source']=isset($_POST['import_source']) ? $_POST['import_source'] : 0;
$sql['import']['text']=isset($_POST['import_text']) ? (($config['magic_quotes_gpc']) ? stripslashes($_POST['import_text']) : $_POST['import_text']) : "";
$sql['import']['csv']="";
if(isset($_POST['do_import'])) {
$sql['import']['tablecreate']=0;
if($sql['import']['table']=="new") {
$sql['import']['table']="import_";
$sql['import']['tablecreate']=1;
}
if($sql['import']['table']=="") {
$aus.='<span class="error">'.$lang['import_notable'].'</span>';
} else {
if($_POST['import_source']==0) {
//Import aus textbox
$sql['import']['csv']=explode($sql['import']['endline'],$sql['import']['text']);
} else {
if (!isset($_FILES['upfile']['name']) || empty($_FILES['upfile']['name'])) {
$aus.='<span class="error">'.$lang['fm_uploadfilerequest'].'</span>';
} else {
$fn=$_FILES['upfile']['tmp_name'];
$sql['import']['csv']=(substr($_FILES['upfile']['name'],-3)==".gz") ? gzfile($fn) : file($fn);
$sql['import']['text']=implode("",$sql['import']['csv']);
$aus.='<span>'.$lang['sql_uploadedfile'].'<strong>'.$_FILES['upfile']['name'].'</strong>&nbsp;&nbsp;&nbsp;'.byte_output(filesize($_FILES['upfile']['tmp_name'])).'</span>';
}
}
if(is_array($sql['import']['csv']))
$aus.=DoImport();
else
$aus.='<br><span class="error">'.$lang['csv_nodata'].'</span>';
}
}
$impaus=$aus;
$impaus.='<form action="sql.php?db='.$db.'&amp;dbid='.$dbid.'&amp;context=4&amp;import=1" method="post" enctype="multipart/form-data">'.$nl;
$impaus.= '';
$impaus.= '<a href="sql.php?db='.$db.'&amp;dbid='.$dbid.'&amp;context=4">'.$lang['export'].'</a>';
$impaus.= '<h6>'.sprintf($lang['sql_import'],$databases['Name'][$dbid]).'</h6>';
$impaus.= '<table class="bordersmall"><tr class="thead"><th>'.$nl;
$impaus.= $lang['importoptions'].'</th><th>'.$lang['csvoptions'].'</th></tr>'.$nl;
$impaus.= '<tr><td valign="top">'.$nl;
$impaus.= '<table cellpadding="0" cellspacing="0">'.$nl;
$impaus.= '<tr><td>'.$lang['importtable'].'</td><td><select name="import_table">'.TableComboBox($sql['import']['table']).'<option value="new" '.(($sql['import']['table']=="import_") ? 'selected' : '').'>== '.$lang['newtable'].' ==</option></select></td></tr>'.$nl;
$impaus.= '<tr><td>'.$lang['importsource'].'</td>'.$nl;
$impaus.= '<td><input type="radio" class="radio" name="import_source" value="0" '.(($sql['import']['import_source']==0) ? 'checked' : '').' onclick="check_csvdivs(1); return true">'.$lang['fromtextbox'].'<br>'.$nl;
$impaus.= '<input type="radio" class="radio" id="radio_csv0" name="import_source" value="1" '.(($sql['import']['import_source']==1) ? 'checked' : '').' onclick="check_csvdivs(1); return true">'.$lang['fromfile'].'</td></tr>'.$nl;
$impaus.= '<tr><td colspan="2"><input type="checkbox" class="checkbox" name="import_emptydb" value="1" '.(($sql['import']['emptydb']==1) ? 'checked' : '').'>'.$lang['emptytablebefore'].'</td></tr>'.$nl;
$impaus.= '<tr><td colspan="2"><input type="checkbox" class="checkbox" name="import_createindex" value="1" '.(($sql['import']['createindex']==1) ? 'checked' : '').'>'.$lang['createautoindex'].'</td></tr>'.$nl;
$impaus.= '</table>'.$nl;
$impaus.= '</td><td valign="top">'.$nl;
$impaus.= '<table cellpadding="0" cellspacing="0">'.$nl;
$impaus.= '<tr><td colspan="2"><input type="checkbox" class="checkbox" name="f_import_namefirstline" value="1" '.(($sql['import']['namefirstline']==1) ? "checked" : "").'>'.$lang['csv_namefirstline'].'</td></tr>'.$nl;
$impaus.= '<tr><td>'.$lang['csv_fieldseperate'].'</td><td><input type="text" class="text" name="f_import_csvtrenn" size="4" maxlength="12" value="'.$sql['import']['trenn'].'"></td></tr>'.$nl;
$impaus.= '<tr><td>'.$lang['csv_fieldsenclosed'].'</td><td><input type="text" class="text" name="f_import_csvenc" size="4" maxlength="12" value="'.htmlspecialchars($sql['import']['enc']).'"></td></tr>'.$nl;
$impaus.= '<tr><td>'.$lang['csv_fieldsescape'].'</td><td><input type="text" class="text" name="f_import_csvesc" size="4" maxlength="12" value="'.$sql['import']['esc'].'"></td></tr>'.$nl;
$impaus.= '<tr><td>'.$lang['csv_eol'].'</td><td><input type="text" class="text" name="f_import_csvztrenn" size="4" maxlength="12" value="'.$sql['import']['ztrenn'].'"></td></tr>'.$nl;
$impaus.= '<tr><td>'.$lang['csv_null'].'</td><td><input type="text" class="text" name="f_import_csvnull" size="4" maxlength="12" value="'.$sql['import']['null'].'"></td></tr>'.$nl;
$impaus.= '</table>'.$nl;
$impaus.= '</td></tr>';
$impaus.='<tr><td colspan="2"><div id="csv0">'.$lang['csv_fileopen'].':&nbsp;&nbsp;
<input type="file" name="upfile" accept="application/gzip">';
$impaus.='<input type="hidden" name="MAX_FILE_SIZE" VALUE="2500000"></div></td></tr>';
$impaus.='<tr><td colspan="2" align="right"><input class="Formbutton" type="submit" name="do_import" value=" '.$lang['importieren'].' "></td></tr>';
$impaus.= '</table>'.$nl;
$impaus.= '<p>&nbsp;</p>'.$lang['import'].':<br><textarea name="import_text" wrap="OFF" style="width:760px;height:400px;font-size=11px;">';
//$impaus.=$sql['import']['text'];
$impaus.= '</textarea></form>'.$nl;
$impaus.= '<script language="JavaScript">check_csvdivs(1);</script>'.$nl;
echo $impaus.$nl;
} else {
//EXPORT
$tables=0;$tblstr="";
$sql['export']['db']=$db;
if(isset($_POST['f_export_submit'])) {
//echo '<pre>'.print_r($_POST,true).'</pre><hr>';
$sql['export']['header_sent']="";
$sql['export']['lines']=0;
$sql['export']['format']=$_POST['f_export_format'];
$sql['export']['ztrenn']=($config['magic_quotes_gpc']) ? stripslashes($_POST['f_export_csvztrenn']) : $_POST['f_export_csvztrenn'];
$sql['endline']['ztrenn']=$sql['export']['ztrenn'];
if($sql['export']['format']==0) {
//CSV
$format=0;
$sql['export']['trenn']=($config['magic_quotes_gpc']) ? stripslashes($_POST['f_export_csvtrenn']) : $_POST['f_export_csvtrenn'];
$sql['export']['enc']=($config['magic_quotes_gpc']) ? stripslashes($_POST['f_export_csvenc']) : $_POST['f_export_csvenc'];
$sql['export']['esc']=($config['magic_quotes_gpc']) ? stripslashes($_POST['f_export_csvesc']) : $_POST['f_export_csvesc'];
if (empty($sql['export']['endline'])) {
$sql['export']['endline']=$nl;
} else {
$sql['export']['endline']= str_replace('\\r', "\015",$sql['export']['endline']);
$sql['export']['endline'] = str_replace('\\n', "\012",$sql['export']['endline']);
$sql['export']['endline']= str_replace('\\t', "\011",$sql['export']['endline']);
}
$sql['export']['endline']= str_replace('\\t', "\011",$sql['export']['endline']);
} elseif($sql['export']['format']==1) {
//EXCEL
$format=1;
$sql['export']['trenn']=",";
$sql['export']['enc']='"';
$sql['export']['esc']='"';
$sql['export']['endline']="\015\012";
} elseif($sql['export']['format']==3) {
//EXCEL 2003
$format=1;
$sql['export']['trenn']=";";
$sql['export']['enc']='"';
$sql['export']['esc']='"';
$sql['export']['endline']="\015\012";
} elseif($sql['export']['format']==4) {
//XML
$format=4;
CheckcsvOptions();
} elseif($sql['export']['format']==5) {
//HTML
$format=5;
CheckcsvOptions();
}
if($format<3) $sql['export']['null']=($config['magic_quotes_gpc']) ? stripslashes($_POST['f_export_csvnull'.$format]) : $_POST['f_export_csvnull'.$format];
$sql['export']['namefirstline']=(isset($_POST['f_export_namefirstline'.$format])) ? $_POST['f_export_namefirstline'.$format] : 0;
$sql['export']['sendfile']=$_POST['f_export_sendresult'];
$sql['export']['compressed']=(isset($_POST['f_export_compressed'])) ? $_POST['f_export_compressed'] : 0;
$sql['export']['exportfile']="";
$sql['export']['xmlstructure']=(isset($_POST['f_export_xmlstructure'])) ? $_POST['f_export_xmlstructure'] : 0;
$sql['export']['htmlstructure']=(isset($_POST['f_export_htmlstructure'])) ? $_POST['f_export_htmlstructure'] : 0;
//ausgewählte Tabellen
if(isset($_POST['f_export_tables']))
$sql['export']['tables']=$_POST['f_export_tables'];
} else CheckcsvOptions();
//Tabellenliste
$sqlt="SHOW TABLE STATUS FROM `$db`";
$res=MSD_query($sqlt) or die(SQLError($sqlt,mysql_error()));
if($res) {
$sql['export']['tablecount']=mysql_numrows($res);
$sql['export']['recordcount']=0;
for($i=0;$i<$sql['export']['tablecount'];$i++) {
$row = mysql_fetch_array($res);
$tblstr.='<option value="'.$row['Name'].'" '.((isset($sql['export']['tables']) && in_array($row['Name'],$sql['export']['tables'])) ? "selected" : "").'>'.$row['Name'].' ('.$row['Rows'].')</option>'."\n";
$sql['export']['recordcount']+=$row['Rows'];
}
}
$exaus=$aus.'<h4>'.sprintf($lang['sql_export'],$databases['Name'][$dbid]).'</h4>';
$exaus.='<form action="sql.php?db='.$db.'&amp;dbid='.$dbid.'&amp;context=4" method="post">'.$nl;
$exaus.= '<a href="sql.php?db='.$db.'&amp;dbid='.$dbid.'&amp;context=4&amp;import=1">'.$lang['import'].'</a>';
$exaus.= '<h6>'.sprintf($lang['sql_export'],$databases['Name'][$dbid]).'</h6>';
$exaus.= '<table class="bordersmall"><tr class="thead"><th>'.$lang['tables'].'</th>'.$nl;
$exaus.= '<th>'.$lang['exportoptions'].'</th>';
$exaus.= '<th>'.$lang['export'].'</th></tr><tr>';
$exaus.= '';
$exaus.= '<td><span class="ssmall"><strong>'.$sql['export']['tablecount'].'</strong> '.$lang['tables'].', <strong>'.$sql['export']['recordcount'].'</strong> '.$lang['records'].'</span>';
$exaus.= '&nbsp;&nbsp;&nbsp;<a class="ssmall" href="#" onclick="SelectTableList(true);">'.$lang['all'].'</a>&nbsp;&nbsp;<a class="ssmall" href="#" onclick="SelectTableList(false);">'.$lang['none'].'</a>'.$nl;
$exaus.= '<br><select name="f_export_tables[]" size="12" multiple>'.$tblstr.'</select><br>'.$nl;
$exaus.= '</td><td>'.$nl;
$exaus.= ''.$nl;
$exaus.= '<input type="radio" class="radio" name="f_export_format" id="radio_csv0" value="0" '.(($sql['export']['format']==0) ? "checked" : "").' onclick="check_csvdivs(0); return true">'."CSV".'&nbsp;&nbsp;&nbsp;'.$nl;
$exaus.= '<input type="radio" class="radio" name="f_export_format" id="radio_csv1" value="1" '.(($sql['export']['format']==1) ? "checked" : "").' onclick="check_csvdivs(0); return true">'."Excel".'&nbsp;&nbsp;&nbsp;'.$nl;
$exaus.= '<input type="radio" class="radio" name="f_export_format" id="radio_csv2" value="3" '.(($sql['export']['format']==3) ? "checked" : "").' onclick="check_csvdivs(0); return true">'.$lang['excel2003'].'<br>'.$nl;
$exaus.= '<input type="radio" class="radio" name="f_export_format" id="radio_csv4" value="4" '.(($sql['export']['format']==4) ? "checked" : "").' onclick="check_csvdivs(0); return true">'."XML".'&nbsp;&nbsp;&nbsp;'.$nl;
$exaus.= '<input type="radio" class="radio" name="f_export_format" id="radio_csv5" value="5" '.(($sql['export']['format']==5) ? "checked" : "").' onclick="check_csvdivs(0); return true">'."HTML".'<br><br>'.$nl;
$exaus.= '<div id="csv0"><fieldset><legend>CSV-Optionen</legend><table cellpadding="0" cellspacing="0"><tr><td colspan="2">'.$nl;
$exaus.= '<input type="checkbox" class="checkbox" name="f_export_namefirstline0" value="1" '.(($sql['export']['namefirstline']==1) ? "checked" : "").'>'.$lang['csv_namefirstline'].'</td></tr>'.$nl;
$exaus.= '<tr><td>'.$lang['csv_fieldseperate'].'</td><td><input type="text" class="text" name="f_export_csvtrenn" size="4" maxlength="12" value="'.$sql['export']['trenn'].'"></td></tr>'.$nl;
$exaus.= '<tr><td>'.$lang['csv_fieldsenclosed'].'</td><td><input type="text" class="text" name="f_export_csvenc" size="4" maxlength="12" value="'.htmlspecialchars($sql['export']['enc']).'"></td></tr>'.$nl;
$exaus.= '<tr><td>'.$lang['csv_fieldsescape'].'</td><td><input type="text" class="text" name="f_export_csvesc" size="4" maxlength="12" value="'.$sql['export']['esc'].'"></td></tr>'.$nl;
$exaus.= '<tr><td>'.$lang['csv_eol'].'</td><td><input type="text" class="text" name="f_export_csvztrenn" size="4" maxlength="12" value="'.$sql['export']['ztrenn'].'"></td></tr>'.$nl;
$exaus.= '<tr><td>'.$lang['csv_null'].'</td><td><input type="text" class="text" name="f_export_csvnull0" size="4" maxlength="12" value="'.$sql['export']['null'].'"></td></tr>'.$nl;
$exaus.= '</table></fieldset></div>'.$nl;
$exaus.= '<div id="csv1"><fieldset><legend>Excel-Optionen</legend><table cellpadding="0" cellspacing="0"><tr><td colspan="2">';
$exaus.= '<input type="checkbox" class="checkbox" name="f_export_namefirstline1" value="1"'.(($sql['export']['namefirstline']==1) ? "checked" : "").'>'.$lang['csv_namefirstline'].'</td></tr>'.$nl;
$exaus.= '<tr><td>'.$lang['csv_null'].'</td><td><input type="text" class="text" name="f_export_csvnull1" size="4" maxlength="12" value="'.$sql['export']['null'].'"></td></tr>'.$nl;
$exaus.= '</table></fieldset></div>'.$nl;
$exaus.= '<div id="csv4"><fieldset><legend>XML-Optionen</legend><table>';
$exaus.= '<tr><td><input type="checkbox" name="f_export_xmlstructure" value="1" class="checkbox" '.(($sql['export']['xmlstructure']==1) ? 'checked' : '').'> mit Struktur</td></tr>';
$exaus.= '</table></fieldset></div>'.$nl;
$exaus.= '<div id="csv5"><fieldset><legend>HTML-Optionen</legend><table>';
$exaus.= '<tr><td><input type="checkbox" name="f_export_htmlstructure" value="1" class="checkbox" '.(($sql['export']['htmlstructure']==1) ? 'checked' : '').'> mit Struktur</td></tr>';
$exaus.= '</table></fieldset></div>'.$nl;
$exaus.= '</td><td>'.$nl;
$exaus.= '<input type="radio" class="radio" name="f_export_sendresult" value="0" '.(($sql['export']['sendfile']==0) ? "checked" : "").' onclick="check_csvdivs(0); return true">'.$lang['showresult'].'<br>'.$nl;
$exaus.= '<input type="radio" class="radio" name="f_export_sendresult" id="radio_csv3" value="1" '.(($sql['export']['sendfile']==1) ? "checked" : "").' onclick="check_csvdivs(0); return true">'.$lang['sendresultasfile'].'<br>'.$nl;
$exaus.= '<div id="csv3"><input type="checkbox" class="checkbox" name="f_export_compressed" value="1" '.(($sql['export']['compressed']==1) ? "checked" : "").'>'.$lang['compressed'].'</div><br>'.$nl;
$exaus.= '<img src="images/blank.gif" width="60" height="130" border="0"><br><input class="Formbutton" type="submit" name="f_export_submit" value="'.$lang['export'].'" onclick="if(SelectedTableCount()==0) {alert(msg1);return false;}">'.$nl;
$exaus.= '</td></tr></table></form>'.$nl;
$exaus.= '<script language="JavaScript">check_csvdivs(0);</script>'.$nl;
if(!$download) echo $exaus.$nl;
if(isset($_POST['f_export_submit']) && isset($sql['export']['tables'])) {
if(!$download) echo '<br><br><table width="90%"><tr><td>'.$lang['export'].':</td><td align="right"><a href="javascript:BrowseInput(\'imexta\');">zeige in neuem Fenster</a></td></tr></table><textarea id="imexta" wrap="OFF" style="width:760px;height:400px;font-size=11px;">'.$nl;
if($format<3) ExportCSV();
elseif($format==4) ExportXML();
elseif($format==5) ExportHTML();
if(!$download) {
echo '</textarea><br>'.$nl;
echo '<span style="color:blue;">'.$lang['exportfinished'].'</span>&nbsp;&nbsp;'.sprintf($lang['exportlines'],$sql['export']['lines']).$nl;
} else exit();
}
}
?>

Datei anzeigen

@ -0,0 +1,137 @@
<?php
//Start SQL-Box
if(isset($_GET['readfile']) && $_GET['readfile']==1) {
$aus.='<form action="'.$params.'" method="post" enctype="multipart/form-data"><table class="bordersmall" width="100%"><tr><td>';
$aus.='SQL-File öffnen (auch gz möglich):</td><td><input type="file" name="upfile"></td>';
$aus.='<td><input type="submit" class="SQLbutton" name="submit_openfile" value=" öffnen "></td><td>(max 2 MB)</td>';
$aus.='<td><input type="hidden" name="MAX_FILE_SIZE" value="2500000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table></form>';
}
if(isset($_POST['submit_openfile'])) {
//open file
if (!isset($_FILES['upfile']['name']) || empty($_FILES['upfile']['name'])) $aus.='<span class="error">'.$lang['fm_uploadfilerequest'].'</span>';
else {
$fn=$_FILES['upfile']['tmp_name'];
if(strtolower(substr($_FILES['upfile']['name'],-3))==".gz")
$read__user_sqlfile=gzfile($fn);
else
$read__user_sqlfile=file($fn);
$aus.='<span>geladenes File: <strong>'.$_FILES['upfile']['name'].'</strong>&nbsp;&nbsp;&nbsp;'.byte_output(filesize($_FILES['upfile']['tmp_name'])).'</span>';
$sql_loaded=implode("",$read__user_sqlfile);
}
}
$aus.='<div id="mysqlbox"><form action="sql.php" method="post">';
//Titelzeile
$aus.='<div id="sqlheaderbox">';
$aus.='<a href="#" onclick="resizeSQL(0);"><img src="'.$config['files']['iconpath'].'close.gif" width="16" height="16" alt="" border="0" vspace="0" hspace="0" align="bottom"></a>&nbsp;&nbsp;';
$aus.='<a href="#" onclick="resizeSQL(1);"><img src="'.$config['files']['iconpath'].'arrowup.gif" width="16" height="16" alt="show less" border="0" vspace="0" hspace="0" align="bottom"></a>';
$aus.='&nbsp;<a href="#" onclick="resizeSQL(2);"><img src="'.$config['files']['iconpath'].'arrowdown.gif" width="16" height="16" alt="show more" border="0" vspace="0" hspace="0" align="bottom"></a>&nbsp;&nbsp;&nbsp;';
$aus.='<input class="SQLbutton" type="button" onclick="document.location.href=\''.$params.'&amp;context=1\'" value="'.$lang['sql_befehle'].'">'.SQL_ComboBox().'&nbsp;&nbsp;'.Table_ComboBox();
$aus.='&nbsp;<input class="SQLbutton" type="reset" name="reset" value="reset">&nbsp;<input class="SQLbutton" type="submit" name="execsql" value="'.$lang['sql_exec'].'">&nbsp;';
if(!isset($_GET['readfile'])) $aus.= '&nbsp;&nbsp;<a href="'.$params.'&amp;readfile=1" title="read file"><img src="'.$config['files']['iconpath'].'openfile.gif" width="16" height="16" alt="read file" border="0"></a>&nbsp;';
$aus.='<a href="'.$mysql_help_ref.'" target="_blanc" title="Mysql-Hilfe"><img src="'.$config['files']['iconpath'].'help16.gif" width="16" height="16" alt="" border="0"></a>';
$aus.='</div>';
//Eingabebox
$aus.='<div id="sbox2"><textarea rows="4" cols="10" style="height:'.$config['interface_sqlboxsize'].'px;" name="sqltextarea" id="sqltextarea">'.((isset($sql_loaded)) ? $sql_loaded : $sql['sql_statement'].$sql['order_statement']).'</textarea>';
$aus.='<br><div class="ssmall" align="center">'.$lang['sql_warning'].'</div></div>';
$aus.='<input type="hidden" name="db" value="'.$db.'"><input type="hidden" name="tablename" value="'.$tablename.'">';
$aus.='<input type="hidden" name="dbid" value="'.$dbid.'"></form></div><br>';
if(isset($_GET['mode']) && $context==0) {
if(isset($_GET['recordkey'])) $rk=stripslashes(urldecode($_GET['recordkey']));
if(isset($_GET['tablename'])) $tablename=$_GET['tablename'];
if($_GET['mode']=="kill") {
if($showtables==0) {
$sqlk= "DELETE FROM `$tablename` WHERE ".$rk;
$res=MSD_query($sqlk) or die(SQLError($sqlk,mysql_error()));
$aus.='<p class="success">'.$lang['sql_recorddeleted'].'</p>';
} else {
$sqlk= "Drop Table `$rk`";
$res=MSD_query($sqlk) or die(SQLError($sqlk,mysql_error()));
$aus.='<p class="success">'.sprintf($lang['sql_recorddeleted'],$rk).'</p>';
}
}
if($_GET['mode']=="empty") {
if($showtables==0) {
} else {
$sqlk= "TRUNCATE `$rk`";
$res=MSD_query($sqlk) or die(SQLError($sqlk,mysql_error()));
$aus.='<p class="success">'.sprintf($lang['sql_tableemptied'],$rk).'</p>';
}
}
if($_GET['mode']=="emptyk") {
if($showtables==0) {
} else {
$sqlk= "TRUNCATE `$rk`;";
$res=MSD_query($sqlk) or die(SQLError($sqlk,mysql_error()));
$sqlk= "ALTER TABLE `$rk` AUTO_INCREMENT=1;";
$res=MSD_query($sqlk) or die(SQLError($sqlk,mysql_error()));
$aus.='<p class="success">'.sprintf($lang['sql_tableemptiedkeys'],$rk).'</p>';
}
}
if($_GET['mode']=="edit") {
$aus.='<div id="sqleditbox"><p>'.$lang['sql_recordedit'].' '.$rk.'</p>';
$sqledit="Select * from `$tablename` where $rk";
$res=MSD_query($sqledit) or die(SQLError($sqledit,mysql_error()));
$aus.='<form action="sql.php" method="post">';
$aus.='<input type="hidden" name="recordkey" value="'.$rk.'">';
$row=mysql_fetch_row($res);
$aus.='<table>';
$feldnamen="";
for($x=0; $x<count($row); $x++) {
$str = mysql_fetch_field($res,$x);
$feldnamen.=$str->name.'|';
$aus.='<tr><td>'.$str->name.'</td><td>';
if($str->type=='blob')
$aus.='<textarea cols="60" rows="4" name="'.$str->name.'">'.$row[$x].'</textarea>';
else
$aus.='<input type="text" class="text" size="60" name="'.$str->name.'" value="'.$row[$x].'">';
$aus.='</td>';
$aus.= '<td>&nbsp;</td></tr>'; //'.$str->type.'
}
$aus.='<tr><td colspan="3" align="right"><input type="hidden" name="feldnamen" value="'.substr($feldnamen,0,strlen($feldnamen)-1).'"><input class="SQLbutton" type="submit" name="update" value="update">&nbsp;&nbsp;&nbsp;<input class="SQLbutton" type="reset" name="reset" value="reset">&nbsp;&nbsp;&nbsp;<input class="SQLbutton" type="Button" value="cancel edit" onclick="location.href=\'sql.php?db='.$db.'&amp;dbid='.$dbid.'&amp;tablename='.$tablename.'\';"></td></tr>';
$aus.='</table>'.FormHiddenParams().'<input type="hidden" name="sql_statement" value="'.urlencode($sql['sql_statement']).'"></form></div>';
}
if($_GET['mode']=="new") {
$aus.='<div id="sqlnewbox"><p>'.$lang['sql_recordnew'].'</p>';
$sqledit="SHOW FIELDS FROM `$tablename`";
$res=MSD_query($sqledit) or die(SQLError($sqledit,mysql_error()));
$num=mysql_numrows($res);
$aus.='<form action="sql.php" method="post">';
$aus.='<input type="hidden" name="recordkey" value="">';
$aus.='<table>';
$feldnamen="";
for($x=0; $x<$num; $x++) {
$row=mysql_fetch_row($res);
$feldnamen.=$row[0].'|';
$aus.='<tr><td>'.$row[0].'</td><td>';
$type=strtoupper($row[1]);
if($type=='BLOB' || $type=='TEXT')
$aus.='<textarea cols="60" rows="4" name="'.$row[0].'">'.$row[4].'</textarea>';
else
$aus.='<input type="text" class="text" size="60" name="'.$row[0].'" value="'.$row[4].'">';
$aus.='</td>';
$aus.='<td>&nbsp;</td></tr>'; //'.$str->type.'
}
$aus.='<tr><td colspan="3" align="right"><input type="hidden" name="feldnamen" value="'.substr($feldnamen,0,strlen($feldnamen)-1).'"><input class="SQLbutton" type="submit" name="insert" value="insert">&nbsp;&nbsp;&nbsp;<input class="SQLbutton" type="reset" name="reset" value="reset">&nbsp;&nbsp;&nbsp;<input class="SQLbutton" type="submit" name="cancel" value="cancel insert"></td></tr>';
$aus.='</table>'.FormHiddenParams().'<input type="hidden" name="sql_statement" value="'.urlencode($sql['sql_statement']).'"></form></div>';
}
}
?>

Datei anzeigen

@ -0,0 +1,73 @@
<?php
//SQL-Strings
echo $aus.='<h4>'.$lang['sql_befehle'].' ('.count($SQL_ARRAY).')</h4>';
echo '<a href="'.$params.'&amp;sqlconfig=1&amp;new=1">'.$lang['sql_befehlneu'].'</a><br><br>';
if(isset($_POST['sqlnewupdate'])) {
$ind=count($SQL_ARRAY);
if(count($SQL_ARRAY)>0)
array_push($SQL_ARRAY,$_POST['sqlname'.$ind]."|".$_POST['sqlstring'.$ind]);
else $SQL_ARRAY[0]=$_POST['sqlname0']."|".$_POST['sqlstring0'];
WriteSQL();
echo '<p>'.$lang['sql_befehlsaved1'].' \''.$_POST['sqlname'.$ind].'\' '.$lang['sql_befehlsaved2'].'</p>';
}
echo '<form name="sqlform" action="sql.php" method="post">
<input type="hidden" name="context" value="1">
<input type="hidden" name="sqlconfig" value="1">
<input type="hidden" name="tablename" value="'.$tablename.'">
<input type="hidden" name="dbid" value="'.$dbid.'">';
echo '<table class="border"><tr class="thead"><th>Position</th><th>Name</th><th>SQL</th><th>'.$lang['command'].'</th></tr>';
$i=0;
if(count($SQL_ARRAY)>0) {
for($i=0;$i<count($SQL_ARRAY);$i++) {
if(isset($_POST['sqlupdate'.$i])) {
echo '<p class="success">'.$lang['sql_befehlsaved1'].' \''.$_POST['sqlname'.$i].'\' '.$lang['sql_befehlsaved3'].'</p>';
$SQL_ARRAY[$i]=$_POST['sqlname'.$i]."|".$_POST['sqlstring'.$i];
WriteSQL();
}
if(isset($_POST['sqlmove'.$i])) {
echo '<p class="success">'.$lang['sql_befehlsaved1'].' \''.$_POST['sqlname'.$i].'\' '.$lang['sql_befehlsaved4'].'</p>';
$a[]=$SQL_ARRAY[$i];
array_splice($SQL_ARRAY,$i,1);
$SQL_ARRAY=array_merge($a,$SQL_ARRAY);
WriteSQL();
}
if(isset($_POST['sqldelete'.$i])) {
echo '<p class="success">'.$lang['sql_befehlsaved1'].' \''.$_POST['sqlname'.$i].'\' '.$lang['sql_befehlsaved5'].'</p>';
array_splice($SQL_ARRAY,$i,1);
WriteSQL();
}
}
for($i=0;$i<count($SQL_ARRAY);$i++) {
$cl= ($i % 2) ? "dbrow" : "dbrow1";
echo '<tr class="'.$cl.'"><td>'.($i+1).'</td><td>';
echo '<input type="text" class="text" name="sqlname'.$i.'" value="'.SQL_Name($i).'"></td>';
echo '<td><textarea rows="3" cols="40" name="sqlstring'.$i.'">'.stripslashes(SQL_String($i)).'</textarea></td>';
echo '<td><input class="SQLbutton" style="width:80px;" type="submit" name="sqlupdate'.$i.'" value="save"><br>
<input class="SQLbutton" style="width:80px;" type="submit" name="sqlmove'.$i.'" value="move up"><br>
<input class="SQLbutton" style="width:80px;" type="submit" name="sqldelete'.$i.'" value="delete"></td></tr>';
}
}
if(isset($_GET['new'])) {
$cl= ($i % 2) ? "dbrow" : "dbrow1";
echo '<tr class="'.$cl.'"><td>'.($i+1).'</td><td>';
echo '<input type="text" class="text" name="sqlname'.$i.'" id="sqlname'.$i.'" value="SQL '.($i+1).'"><br><div class="small" align="center">'.$lang['sql_library'].'<br>';
echo '<select id="sqllib" name="sqllib" onChange="InsertLib('.$i.');" class="small">';
echo '<option value=""></option>';
$og=false;
for($j=0;$j<count($sqllib);$j++) {
if($sqllib[$j]['sql']=="trenn") {
if($og) echo '</optgroup>';
echo '<optgroup label="'.$sqllib[$j]['name'].'">';
$og=true;
} else {
echo '<option value="'.$sqllib[$j]['sql'].'">'.$sqllib[$j]['name'].'</option>';
}
}
if($og) echo '</optgroup>';
echo '</select></div></td>
<td><textarea rows="3" cols="40" name="sqlstring'.$i.'" id="sqlstring'.$i.'">SELECT * FROM</textarea></td>
<td><input class="SQLbutton" style="width:80px;" type="submit" name="sqlnewupdate" value="save"></td></tr>';
}
echo '</table></form>';
?>

324
mysqldumper/inc/sql_tables.php Normale Datei
Datei anzeigen

@ -0,0 +1,324 @@
<?php
//Tabellen
echo $aus.'<h6>'.$lang['sql_tablesofdb'].' `'.$databases['Name'][$dbid].'` '.$lang['sql_edit'].'</h6>';
if(isset($_GET['kill'])) {
if($_GET['anz']==1)
echo '<p class="error">'.$lang['sql_nofielddelete'].'</p>';
else {
$sql_alter="ALTER TABLE `".$databases['Name'][$dbid]."`.`".$_GET['tablename']."` DROP COLUMN `".$_GET['kill']."`";
MSD_DoSQL($sql_alter);
echo '<div align="left" id="sqleditbox" style="font-size: 11px;width:90%;padding=6px;">';
echo '<p class="success">'.$lang['sql_fielddelete1'].' `'.$_GET['kill'].'` '.$lang['sql_deleted'].'.</p>'.highlight_sql($out).'</div>';
}
}
if(isset($_POST['tablecopysubmit'])) {
$table_edit_name=$_GET['tablename'];
if($_POST['tablecopyname']=="") {
echo '<p class="error">'.$lang['sql_nodest_copy'].'</p>';
} elseif(Table_Exists($databases['Name'][$dbid],$_POST['tablecopyname'])) {
echo '<p class="error">'.$lang['sql_desttable_exists'].'</p>';
} else {
Table_Copy("`".$databases['Name'][$dbid]."`.`".$table_edit_name."`",$_POST['tablecopyname'],$_POST['copyatt']);
echo '<div align="left" id="sqleditbox">';
echo ($_POST['copyatt']==0) ? '<p class="success">'.sprintf($lang['sql_scopy'],$table_edit_name,$_POST['tablecopyname']).'.</p>' : '<p class="success">'.sprintf($lang['sql_tcopy'],$table_edit_name,$_POST['tablecopyname']).'</p>';
echo highlight_sql($out).'</div>';
$tablename=$_POST['tablecopyname'];
}
}
if(isset($_POST['newtablesubmit'])) {
if($_POST['newtablename']=="") {
echo '<p class="error">'.$lang['sql_tablenoname'].'</p>';
} else {
$sql_alter="CREATE TABLE `".$databases['Name'][$dbid]."`.`".$_POST['newtablename']."` (`id` int(11) unsigned not null AUTO_INCREMENT PRIMARY KEY ) ".((MSD_NEW_VERSION) ? "ENGINE" : "TYPE")."=MyISAM;";
MSD_DoSQL($sql_alter);
echo SQLOutput($out,$lang['table'].' `'.$_POST['newtablename'].'` '.$lang['sql_created']);
}
}
if(isset($_POST['t_edit_submit'])) {
$sql_alter="ALTER TABLE `".$databases['Name'][$dbid]."`.`".$_POST['table_edit_name']."` ";
if($_POST['t_edit_name']=="")
echo '<p class="error">'.$lang['sql_tblnameempty'].'</p>';
elseif(MSD_NEW_VERSION && $_POST['t_edit_collate']!="" && substr($_POST['t_edit_collate'],0,strlen($_POST['t_edit_charset']))!=$_POST['t_edit_charset'])
echo '<p class="error">'.$lang['sql_collatenotmatch'].'</p>';
else {
if($_POST['table_edit_name']!=$_POST['t_edit_name']) {
$sql_alter.="RENAME TO `".$_POST['t_edit_name']."`, ";
$table_edit_name=$_POST['t_edit_name'];
} else $table_edit_name=$_POST['table_edit_name'];
if($_POST['t_edit_engine']!="") $sql_alter.=((MSD_NEW_VERSION) ? "ENGINE=" : "TYPE=").$_POST['t_edit_engine'].", ";
if($_POST['t_edit_rowformat']!="") $sql_alter.="ROW_FORMAT=".$_POST['t_edit_rowformat'].", ";
if(MSD_NEW_VERSION && $_POST['t_edit_charset']!="") $sql_alter.="DEFAULT CHARSET=".$_POST['t_edit_charset'].", ";
if(MSD_NEW_VERSION && $_POST['t_edit_collate']!="") $sql_alter.="COLLATE ".$_POST['t_edit_collate'].", ";
$sql_alter.="COMMENT='".$_POST['t_edit_comment']."' ";
MSD_DoSQL($sql_alter);
echo SQLOutput($out,$lang['table'].' `'.$_POST['table_edit_name'].'` '.$lang['sql_changed']);
}
} else {
if(!isset($table_edit_name) || $table_edit_name=="") {
$table_edit_name=(isset($_GET['tablename'])) ? $_GET['tablename'] : "";
if(isset($_POST['tableselect'])) $table_edit_name=$_POST['tableselect'];
if(isset($_POST['newtablesubmit'])) $table_edit_name=$_POST['newtablename'];
}
}
if(isset($_POST['newfield_posted'])) {
//build sql for alter
if($_POST['f_name']=="") {
echo '<p class="error">'.$lang['sql_fieldnamenotvalid'].' ('.$_POST['f_name'].')</p>';
$field_fehler=1;
} else {
//alter Key
$oldkeys[0]=$_POST['f_primary'];
$oldkeys[1]=$_POST['f_unique'];
$oldkeys[2]=$_POST['f_index'];
$oldkeys[3]=$_POST['f_fulltext'];
//neuer Key
$newkeys[0]=($_POST['f_index_new']=="primary")? 1 : 0;
$newkeys[1]=($_POST['f_index_new']=="unique")? 1 : 0;
$newkeys[2]=($_POST['f_index_new']=="index")? 1 : 0;
$newkeys[3]=(isset($_POST['f_indexfull'])) ? 1 : 0;
$add_sql.=ChangeKeys($oldkeys,$newkeys,$_POST['f_name'],$_POST['f_size'],"drop_only");
$sql_stamm="ALTER TABLE `".$databases['Name'][$dbid]."`.`$table_edit_name` ";
$sql_alter=$sql_stamm.((isset($_POST['editfield'])) ? "CHANGE COLUMN `".$_POST['fieldname']."` `".$_POST['f_name']."` " : "ADD COLUMN `".$_POST['f_name']."` ");
$sql_alter.=$_POST['f_type'];
$wl=stripslashes($_POST['f_size']);
if($wl!="" && !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$@i', $_POST['f_type'])) {
$sql_alter.="($wl) ";
} elseif ($_POST['f_size']=="" && preg_match('@^(VARCHAR)$@i', $_POST['f_type'])) {
$sql_alter.="("."255".") ";
} else $sql_alter.=" ";
$sql_alter.=$_POST['f_attribut']." ";
$sql_alter.=$_POST['f_null']." ";
$sql_alter.=($_POST['f_default']!="") ? "DEFAULT '".$_POST['f_default']."' " :"";
if(MSD_NEW_VERSION && $_POST['f_collate']!="") $sql_alter.="COLLATE ".$_POST['f_collate']." ";
if($_POST['f_extra']=="AUTO_INCREMENT") {
$sql_alter.=" AUTO_INCREMENT ";
}
if($newkeys[0]==1) $sql_alter.=" PRIMARY KEY ";
if($newkeys[1]==1) $sql_alter.=" UNIQUE INDEX ";
if($newkeys[2]==1) $sql_alter.=" INDEX ";
if($newkeys[3]==1) $sql_alter.=" FULLTEXT INDEX ";
$sql_alter.=$_POST['f_position']." ;";
if($add_sql!="") {
$add_sql=$sql_stamm.$add_sql;
$sql_alter="$sql_alter;\n$add_sql;\n";
}
MSD_DoSQL($sql_alter);
echo '<div align="left" id="sqleditbox" style="font-size: 11px;width:90%;padding=6px;">';
echo '<p class="success"> `'.$_POST['f_name'].'` '.((isset($_POST['editfield'])) ? $lang['sql_changed'] : $lang['sql_created']).'.</p>';
echo highlight_sql($out).'</div>';
$fields_infos=FillFieldinfos($databases['Name'][$dbid],$table_edit_name);
}
}
mysql_select_db($databases['Name'][$dbid]);
$sqlt="SHOW TABLE STATUS FROM `".$databases['Name'][$dbid]."` ;";
$res=MSD_query($sqlt) or die(SQLError($sqlt,mysql_error()));
$anz_tabellen=mysql_numrows($res);
$p="sql.php?db=".$databases['Name'][$dbid]."&amp;dbid=$dbid&amp;tablename=$table_edit_name&amp;context=2";
echo '<form action="sql.php?db='.$databases['Name'][$dbid].'&amp;dbid='.$dbid.'&amp;tablename='.$table_edit_name.'&amp;context=2" method="post">';
echo '<table class="border"><tr class="dbrow"><td>'.$lang['new'].' '.$lang['sql_createtable'].': </td><td colspan="2"><input type="text" class="text" name="newtablename" size="30" maxlength="150"></td><td><input type="submit" name="newtablesubmit" value="'.$lang['sql_createtable'].'" class="SQLbutton"></td></tr>';
echo '<tr class="dbrow1"><td>'.$lang['sql_copytable'].': </td><td><input type="text" class="text" name="tablecopyname" size="20" maxlength="150"></td><td><select name="copyatt"><option value="0">'.$lang['sql_structureonly'].'</option>'.((MSD_NEW_VERSION) ? '<option value="1">'.$lang['sql_structuredata'].'</option>' : '').'</select></td><td><input type="submit" class="SQLbutton" name="tablecopysubmit" value="'.$lang['sql_copytable'].'" '.(($table_edit_name=="") ? "disabled=\"disabled\"":"").'></td></tr></table>';
echo '<table>';
if($anz_tabellen==0) {
echo '<tr><td>'.$lang['sql_notablesindb'].' `'.$databases['Name'][$dbid].'`</td></tr>';
} else {
echo '<tr><td>'.$lang['sql_selecttable'].':&nbsp;&nbsp;&nbsp;</td>';
echo '<td><select name="tableselect" onchange="this.form.submit()"><option value="1" SELECTED></option>';
for($i=0;$i<$anz_tabellen;$i++) {
$row=mysql_fetch_array($res);
echo '<option value="'.$row['Name'].'">'.$row['Name'].'</option>';
}
echo '</select>&nbsp;&nbsp;</td>';
echo '<td><input type="button" class="SQLbutton" value="'.$lang['sql_showdatatable'].'" onclick="location.href=\'sql.php?db='.$databases['Name'][$dbid].'&amp;dbid='.$dbid.'&amp;tablename='.$tablename.'\'"></td></tr>';
}
echo '</table></form><p>&nbsp;</p>';
if($table_edit_name!="") {
$sqlf="SHOW FULL FIELDS FROM `".$databases['Name'][$dbid]."`.`$table_edit_name` ;";
$res=MSD_query($sqlf) or die(SQLError($sqlf,mysql_error()));
$anz_fields=mysql_num_rows($res);
//Array füllen
$fields_infos=FillFieldinfos($databases['Name'][$dbid],$table_edit_name);
if(MSD_NEW_VERSION)
$t_engine=(isset($fields_infos['_tableinfo_']['ENGINE'])) ? $fields_infos['_tableinfo_']['ENGINE'] : "MyISAM";
else
$t_engine=(isset($fields_infos['_tableinfo_']['TYPE'])) ? $fields_infos['_tableinfo_']['TYPE'] : "MyISAM";
$t_charset=(isset($fields_infos['_tableinfo_']['DEFAULT CHARSET'])) ? $fields_infos['_tableinfo_']['DEFAULT CHARSET'] : "";
$t_collation=isset($row['Collation']) ? $row['Collation'] : ""; //(isset($fields_infos['_tableinfo_']['COLLATE'])) ? $fields_infos['_tableinfo_']['COLLATE'] : "";
$t_comment=(isset($fields_infos['_tableinfo_']['COMMENT'])) ? substr($fields_infos['_tableinfo_']['COMMENT'],1,strlen($fields_infos['_tableinfo_']['COMMENT'])-2) : "";
$t_rowformat=(isset($fields_infos['_tableinfo_']['ROW_FORMAT'])) ? $fields_infos['_tableinfo_']['ROW_FORMAT'] : "";
echo "<h6>Tabelle `$table_edit_name`</h6>";
$td='<td valign="top" nowrap class="small">';
//Tabelleneigenschaften
echo '<form action="'.$p.'" method="post"><input type="hidden" name="table_edit_name" value="'.$table_edit_name.'"><table class="border">';
echo '<tr class="sqlNew"><td colspan="4" style="font-size:10pt;font-weight:bold;">'.$lang['sql_tblpropsof'].' `'.$table_edit_name.'` ('.$anz_fields.' '.$lang['fields'].')</td>';
echo '<td class="small" colspan="2" align="center">Name<br><input type="text" class="text" name="t_edit_name" value="'.$table_edit_name.'" size="30" maxlength="150" style="font-size:11px;"></td></tr>';
echo '<tr class="sqlNew">';
echo '<td class="small" align="center">Engine<br><select name="t_edit_engine" style="font-size:11px;">'.EngineCombo($t_engine).'</select></td>';
echo '<td class="small" align="center">Row Format<br><select name="t_edit_rowformat" style="font-size:11px;">'.GetOptionsCombo($feldrowformat,$t_rowformat).'</select></td>';
echo '<td class="small" align="center">'.$lang['charset'].'<br><select name="t_edit_charset" style="font-size:11px;">'.CharsetCombo($t_charset).'</select></td>';
echo '<td class="small" align="center">'.$lang['collation'].'<br><select name="t_edit_collate" style="font-size:11px;">'.CollationCombo($t_collation).'</select></td>';
echo '<td class="small" align="center">'.$lang['comment'].'<br><input type="text" class="text" name="t_edit_comment" value="'.$t_comment.'" size="30" maxlength="100" style="font-size:11px;"></td>';
echo '<td class="small" align="center">&nbsp;<br><input type="submit" name="t_edit_submit" value="'.$lang['change'].'" class="SQLbutton"></td></tr>';
echo '</table></form><p>&nbsp;</p>';
$field_fehler=0;
echo '<h6>Felder der Tabelle `'.$table_edit_name.'`</h6>';
if(isset($_GET['newfield']) || isset($_GET['editfield']) || $field_fehler>0 || isset($_POST['newfield_posted'])) {
if(isset($_GET['editfield'])) $id=$_GET['editfield'];
$d_name=(isset($_GET['editfield'])) ? $fields_infos[$id]['name'] : "";
$d_type=(isset($_GET['editfield'])) ? $fields_infos[$id]['type'] : "";
$d_size=(isset($_GET['editfield'])) ? $fields_infos[$id]['size'] : "";
$d_null=(isset($_GET['editfield'])) ? $fields_infos[$id]['null'] : "";
$d_attribute=(isset($_GET['editfield'])) ? $fields_infos[$id]['attribut'] : "";
$d_default=(isset($_GET['editfield'])) ? substr($fields_infos[$id]['default'],1,strlen($fields_infos[$id]['default'])-2) : "";
$d_extra=(isset($_GET['editfield'])) ? $fields_infos[$id]['extra'] : "";
$d_primary=$d_unique=$d_index=$d_fulltext=0;
$d_collate=(isset($_GET['editfield'])) ? $fields_infos[$id]['collate'] : "";
$d_comment=(isset($_GET['editfield'])) ? $fields_infos[$id]['comment'] : "";
$d_privileges=(isset($_GET['editfield'])) ? $fields_infos[$id]['privileges'] : "";
if(isset($_GET['editfield'])) {
$d_primary=(isset($fields_infos['_primarykey_']) && $fields_infos['_primarykey_']==$fields_infos[$id]['name']) ? 1 : 0;
if(isset($fields_infos['_key_'])) {
for($i=0;$i<count($fields_infos['_key_']);$i++) {
if($fields_infos['_key_'][$i]['name']==$fields_infos[$id]['name']) {
$d_index=1;
break;
}
}
}
if(isset($fields_infos['_fulltextkey_'])) {
for($i=0;$i<count($fields_infos['_fulltextkey_']);$i++) {
if($fields_infos['_fulltextkey_'][$i]['name']==$fields_infos[$id]['name']) {
$d_fulltext=1;
break;
}
}
}
if(isset($fields_infos['_uniquekey_'])) {
for($i=0;$i<count($fields_infos['_uniquekey_']);$i++) {
if($fields_infos['_uniquekey_'][$i]['name']==$fields_infos[$id]['name']) {
$d_unique=1;
break;
}
}
}
}
echo '<form action="'.$p.'" method="post" id="smallform"><input type="hidden" name="newfield_posted" value="1">';
if (isset($_GET['editfield'])) echo '<input type="hidden" name="editfield" value="'.$id.'"><input type="hidden" name="fieldname" value="'.$d_name.'">';
if(isset($_POST['newtablesubmit'])) echo '<input type="hidden" name="newtablename" value="'.$_POST['newtablename'].'">';
echo '<input type="hidden" name="f_primary" value="'.$d_primary.'"><input type="hidden" name="f_unique" value="'.$d_unique.'">';
echo '<input type="hidden" name="f_index" value="'.$d_index.'"><input type="hidden" name="f_fulltext" value="'.$d_fulltext.'">';
echo '<table class="bordersmall"><tr class="thead"><th colspan="6" align="center">'.((isset($_GET['editfield'])) ? $lang['sql_editfield']." `".$d_name."`" : $lang['sql_newfield']).'</th></tr>';
echo '<tr><td class="small">Name<br><input type="text" class="text" value="'.$d_name.'" name="f_name" size="30"></td>';
echo '<td>Type<br><select name="f_type">'.GetOptionsCombo($feldtypen,$d_type).'</select></td>';
echo '<td>Size&nbsp;<img src="'.$config['files']['iconpath'].'help16.gif" alt="'.$lang['sql_enumsethelp'].'" title="'.$lang['sql_enumsethelp'].'" width="12" height="12" border="0"><br><input type="text" class="text" value="'.$d_size.'" name="f_size" size="3" maxlength="80"></td>';
echo '<td>NULL<br><select name="f_null">'.GetOptionsCombo($feldnulls,$d_null).'</select></td>';
echo '<td align="center">Default<br><input type="text" class="text" name="f_default" value="'.$d_default.'" size="10"></td>';
echo '<td align="center">Extra<br><select name="f_extra">'.GetOptionsCombo($feldextras,$d_extra).'</select></td>';
echo '</tr><tr><td align="center">'.$lang['sql_indexes'].'<br>';
echo '<img src="'.$config['files']['iconpath'].'nokey.gif" width="12" height="13" border="0" alt="No Index"><input type="radio" class="radio" name="f_index_new" value="no" '.(($d_primary+$d_unique+$d_index+$d_fulltext==0) ? "checked" : "").'>&nbsp;';
echo '<img src="'.$config['files']['iconpath'].'primary.gif" width="12" height="13" border="0" alt="Primary Key"><input type="radio" class="radio" name="f_index_new" value="primary" '.(($d_primary==1) ? "checked" : "" ).'>&nbsp;';
echo '<img src="'.$config['files']['iconpath'].'unique.gif" width="13" height="12" border="0" alt="Unique Index"><input type="radio" class="radio" name="f_index_new" value="unique" '.(($d_unique==1) ? "checked" : "" ).'>&nbsp;';
echo '<img src="'.$config['files']['iconpath'].'key.gif" width="13" height="12" border="0" alt="Index"><input type="radio" class="radio" name="f_index_new" value="index" '.(($d_index==1) ? "checked" : "" ).'>&nbsp;';
echo '<img src="'.$config['files']['iconpath'].'fulltext.gif" width="13" height="12" border="0" alt="Fulltext Index"><input type="checkbox" class="checkbox" name="f_indexfull" value="1" '.(($d_fulltext==1) ? "checked" : "" ).'>&nbsp;</td>';
echo '<td align="center" colspan="2" >'.$lang['collation'].'<br><select name="f_collate">'.CollationCombo($d_collate).'</select></td>';
echo '<td align="center">'.$lang['sql_attributes'].'<br><select name="f_attribut">'.AttributeCombo($d_attribute).'</select></td>';
echo '<td align="center">'.$lang['sql_atposition'].':<br><select name="f_position"><option value=""></option><option value="FIRST">'.$lang['sql_first'].'</option>';
if($anz_fields>0) {
for($i=0;$i<$anz_fields;$i++) {
echo '<option value="AFTER `'.$fields_infos[$i]['name'].'`">'.$lang['sql_after'].' `'.$fields_infos[$i]['name'].'`</option>';
}
}
echo '</select></td><td align="center"><input type="submit" name="newfieldsubmit" value="'.((isset($_GET['editfield'])) ? $lang['sql_changefield'] : $lang['sql_insertfield']).'" class="SQLbutton"></td></tr></table></form><p>&nbsp;</p>';
} else
echo '<a style="font-size:8pt;padding-bottom:8px;" href="'.$p.'&amp;newfield=1">'.$lang['sql_insertnewfield'].'</a><br><br>';
//Felder ausgeben
echo '<table class="bordersmall">';
for($i=0;$i<$anz_fields;$i++) {
$cl= ($i % 2) ? "dbrow" : "dbrow1";
if($i==0) echo '<tr class="thead"><th>&nbsp;</th><th>Field</th><th>Type</th><th>Size</th><th>NULL</th><th>Key</th><th>Attribute</th><th>Default</th><th>Extra</th><th>Sortierung</th></tr>';
echo '<tr class="'.$cl.'"><td>';
echo '<a href="'.$p.'&amp;editfield='.$i.'"><img src="'.$config['files']['iconpath'].'edit.gif" alt="edit field" width="12" height="13" border="0"></a>&nbsp;&nbsp;';
echo '<a href="'.$p.'&amp;kill='.$fields_infos[$i]['name'].'&amp;anz='.$anz_fields.'" onclick="if(!confirm(\''.$lang['askdeletefield'].'\')) return false;"><img src="'.$config['files']['iconpath'].'delete.gif" alt="delete field" width="11" height="13" border="0"></a>&nbsp;&nbsp;';
echo '</td><td><strong>'.$fields_infos[$i]['name'].'</strong></td><td>'.$fields_infos[$i]['type'].'</td><td>'.$fields_infos[$i]['size'].'</td>';
echo '<td>'.$fields_infos[$i]['null'].'</td><td>';
//key
if($fields_infos['_primarykey_']==$fields_infos[$i]['name']) echo '<img src="'.$config['files']['iconpath'].'primary.gif" width="12" height="13" alt="Primary Key" border="0">';
if(isset($fields_infos['_fulltextkey_'])) {
for($ii=0;$ii<count($fields_infos['_fulltextkey_']);$ii++) {
if($fields_infos['_fulltextkey_'][$ii]['name']==$fields_infos[$i]['name']) {
echo '<img src="'.$config['files']['iconpath'].'fulltext.gif" width="13" height="12" alt="Fulltext Index" border="0">'; break;
}
}
}
if(isset($fields_infos['_uniquekey_'])) {
for($ii=0;$ii<count($fields_infos['_uniquekey_']);$ii++) {
if($fields_infos['_uniquekey_'][$ii]['name']==$fields_infos[$i]['name']) {
echo '<img src="'.$config['files']['iconpath'].'unique.gif" width="13" height="12" alt="Unique Index" border="0">'; break;
}
}
}
if(isset($fields_infos['_key_'])) {
for($ii=0;$ii<count($fields_infos['_key_']);$ii++) {
//echo "<h5>".$fields_infos['_key_'][$ii]['columns']."</h5>";
if($fields_infos['_key_'][$ii]['name']==$fields_infos[$i]['name']) {
echo '<img src="'.$config['files']['iconpath'].'key.gif" width="13" height="12" alt="Index" border="0">'; break;
}
}
}
echo '</td><td>'.$fields_infos[$i]['attribut'].'</td>';
echo '<td>'.$fields_infos[$i]['default'].'</td>'.$td.$fields_infos[$i]['extra'].'</td>';
echo '<td>'.((MSD_NEW_VERSION) ? $fields_infos[$i]['collate'] : "&nbsp;").'</td></tr>';
}
echo '</table><br>';
echo '<h6>'.$lang['sql_tableindexes'].' `'.$table_edit_name.'`</h6>';
echo '<table class="border"><tr><th>&nbsp;</th><th>Index-Name</th>'.((MSD_NEW_VERSION) ? '<th>Typ</th>' : '').'<th>'.$lang['sql_allowdups'].'</th><th>'.$lang['sql_cardinality'].'</th><th>Spalten</th></tr>';
$sqlk="SHOW KEYS FROM `".$databases['Name'][$dbid]."`.`$table_edit_name`;";
$res=MSD_query($sqlk) or die(SQLError($sqlk,mysql_error()));
$num=mysql_numrows($res);
if($num==0) {
echo '<tr><td colspan="6">'.$lang['sql_tablenoindexes'].'</td></tr>';
} else {
for($i=0;$i<$num;$i++) {
$row=mysql_fetch_array($res);
$cl= ($i % 2) ? "dbrow" : "dbrow1";
//Images
echo '<tr class="'.$cl.'"><td><img src="'.$config['files']['iconpath'].'edit.gif" width="12" height="13" alt="" border="0">&nbsp;&nbsp;<img src="'.$config['files']['iconpath'].'delete.gif" width="12" height="13" alt="" border="0"></td>';
echo '<td>'.$row['Key_name'].'</td>';
if(MSD_NEW_VERSION) echo '<td>'.$row['Index_type'].'</td>';
echo '<td align="center">'.(($row['Non_unique']==1) ? $lang['yes']: $lang['no']).'</td>';
echo '<td>'.(($row['Cardinality']>=0) ? $row['Cardinality'] : "keine").'</td>';
echo '<td>'.$row['Column_name'].'</td>';
echo '</tr>';
}
}
echo '</table><br><input type="Button" value="'.$lang['sql_createindex'].'" onclick="location.href=\''.$p.'\'" disabled="disabled" class="SQLbutton">';
echo '<br><pre>';print_r($fields_infos);echo '</pre>';*/
}
?>

144
mysqldumper/inc/sql_tools.php Normale Datei
Datei anzeigen

@ -0,0 +1,144 @@
<?php
//Datenbanken
if(isset($_GET['dbrefresh'])) SetDefault();
echo $aus."<h4>Tools</h4>";
if(isset($_POST['dbdosubmit'])) {
$newname=$_POST['newname'];
$db_index=$_POST['db_index'];
$db_action=$_POST['db_action'];
$changed=false;$ausgabe=$out="";
switch($db_action) {
case "drop":
MSD_DoSQL("DROP DATABASE `".$databases['Name'][$db_index]."`");
echo SQLOutput($out,'<p class="success">'.$lang['db'].' `'.$databases['Name'][$db_index].'` wurde gelöscht.</p>');
$changed=true;
break;
case "empty":
EmptyDB($databases['Name'][$db_index]);
echo SQLOutput($out,'<p class="success">'.$lang['db'].' `'.$databases['Name'][$db_index].'` '.$lang['sql_wasemptied'].'.</p>');
break;
case "rename":
$dbold=$databases['Name'][$db_index];
DB_Copy($dbold,$newname,1);
echo SQLOutput($out,'<p class="success">'.$lang['db'].' `'.$dbold.'` '.$lang['sql_renamedto'].' `'.$newname.'`.</p>');
$changed=true;
break;
case "copy":
$dbold=$databases['Name'][$db_index];
DB_Copy($dbold,$newname);
$changed=true;
echo SQLOutput($out,'<p class="success">'.sprintf($lang['sql_dbcopy'],$dbold,$newname).'</p>');
break;
case "structure":
DB_Copy($databases['Name'][$db_index],$newname,0,0);
$changed=true;
echo SQLOutput($out,'<p class="success">'.sprintf($lang['sql_dbscopy'],$databases['Name'][$db_index],$newname).'</p>');
break;
case "rights":
break;
}
if($changed=true) {
SetDefault();
include ($config['files']['parameter']);
echo '<script language="JavaScript">parent.MySQL_Dumper_menu.location.href="menu.php?action=dbrefresh";</script>';
}
}
if(isset($_POST['dbwantaction'])) {
if(isset($_POST['db_createnew'])) {
$newname=$_POST['db_create'];
if(!empty($newname)) {
$col=(MSD_NEW_VERSION) ? $_POST['db_collate'] : "";
if($col!="") {
$r=explode("|",$col);
$sqlc="CREATE DATABASE `$newname` DEFAULT CHARACTER SET $r[0] COLLATE $r[1]";
} else $sqlc="CREATE DATABASE `$newname`";
MSD_query($sqlc) or die(SQLError($sqlc,mysql_error()));
echo $lang['db']." `$newname` ".$lang['sql_wascreated'].".<br>";
SetDefault();
include ($config['files']['parameter']);
echo '<script language="JavaScript">parent.MySQL_Dumper_menu.location.href="menu.php?action=dbrefresh";</script>';
}
}
$db_action=$newname="";$db_index=-1;
for($i=0;$i<count($databases['Name']);$i++) {
if(isset($_POST['db_do_'.$i])) {
$newname=$_POST['db_rename'.$i];
$db_index=$i;
$db_action=$_POST['db_do_action_'.$i];
break;
}
}
if($db_action!="") {
echo '<div align="center"><div align="left" id="sqleditbox">';
echo '<form action="sql.php?context=3" method="post"><input type="hidden" name="db_action" value="'.$db_action.'"><input type="hidden" name="newname" value="'.$newname.'"><input type="hidden" name="db_index" value="'.$db_index.'">';
switch($db_action) {
case "drop":
echo '<strong>'.sprintf($lang['askdbdelete'],$databases['Name'][$i]).'</strong><br><br>';
echo '<input type="submit" name="dbdosubmit" value="'.$lang['do_now'].'" class="SQLbutton">';
break;
case "empty":
echo '<strong>'.sprintf($lang['askdbempty'],$databases['Name'][$i]).'</strong><br><br>';
echo '<input type="submit" name="dbdosubmit" value="'.$lang['do_now'].'" class="SQLbutton">';
break;
case "rename":
echo '<strong>'.$lang['sql_renamedb'].' `'.$databases['Name'][$db_index].'` '.$lang['in'].' `'.$newname.'`</strong><br><br>';
echo '<input type="submit" name="dbdosubmit" value="'.$lang['do_now'].'" class="SQLbutton">';
break;
case "copy":
echo '<strong>'.sprintf($lang['askdbcopy'],$databases['Name'][$db_index],$newname).'</strong><br><br>';
if($newname=="") echo '<p class="error">'.$lang['sql_namedest_missing'].'</p>'; else {
echo '<input type="submit" name="dbdosubmit" value="'.$lang['do_now'].'" class="SQLbutton">';
}
break;
case "structure":
echo '<strong>'.$lang['fm_askdbcopy1'].'`'.$databases['Name'][$db_index].'`'.$lang['fm_askdbcopy2'].'`'.$newname.'`'.$lang['fm_askdbcopy3'].'</strong><br><br>';
if($newname=="") echo '<p class="error">'.$lang['sql_namedest_missing'].'</p>'; else {
echo '<input type="submit" name="dbdosubmit" value="'.$lang['do_now'].'" class="SQLbutton">';
}
break;
case "rights":
break;
}
echo "</form></div></div><br>";
}
}
echo '<br><form action="sql.php?context=3" method="post"><input type="hidden" name="dbwantaction" value="1">';
echo '<div align="center"><table class="border">';
echo '<tr><td colspan="3" align="center"><strong>'.$lang['create_database'].'</strong></td></tr>';
echo '<tr><td colspan="3">Name:&nbsp;<input type="text" class="text" name="db_create" size="20">';
echo '&nbsp;&nbsp;'.$lang['collation'].':&nbsp;<select name="db_collate">'.CollationCombo('',1).'</select>&nbsp;&nbsp;';
echo '<input type="submit" name="db_createnew" value="'.$lang['create'].'" class="SQLbutton"></td></tr></table>';
echo '<p>&nbsp;</p><table class="border">';
echo '<tr class="thead"><th>'.$lang['dbs'].'</th><th>'.$lang['sql_actions'].'</th></tr>';
for($i=0;$i<count($databases['Name']);$i++) {
$cl= ($i % 2) ? "dbrow" : "dbrow1";
echo ($i==$databases['db_selected_index']) ? '<tr class="dbrowsel">' : '<tr class="'.$cl.'">';
echo '<td><a href="sql.php?db='.$databases['Name'][$i].'&amp;dbid='.$i.'">'.$databases['Name'][$i].'</a></td>';
echo '<td nowrap><input type="text" class="text" name="db_rename'.$i.'" size="20">';
echo '&nbsp;&nbsp;<select name="db_do_action_'.$i.'" onchange="db_do_'.$i.'.disabled=false;">';
echo '<option value="">-- '.$lang['sql_chooseaction'].' --</option>';
echo '<option value="drop">'.$lang['sql_deletedb'].'</option>';
echo '<option value="empty">'.$lang['sql_emptydb'].'</option>';
if(MSD_NEW_VERSION) echo '<option value="rename">'.$lang['sql_renamedb'].'</option>';
if(MSD_NEW_VERSION) echo '<option value="copy">'.$lang['sql_copydatadb'].'</option>';
echo '<option value="structure">'.$lang['sql_copysdb'].'</option>';
echo '</select>';
echo "\n\n".'&nbsp;&nbsp;<input type="submit" name="db_do_'.$i.'" value="'.$lang['do'].'" disabled="disabled" class="SQLbutton">';
echo '&nbsp;&nbsp;<input type="Button" value="'.$lang['sql_imexport'].'" onclick="location.href=\'sql.php?db='.$databases['Name'][$i].'&amp;dbid='.$i.'&amp;context=4\'" class="SQLbutton"></td></tr>';
}
echo '</table></div></form>';
?>

55
mysqldumper/inc/sqllib.php Normale Datei
Datei anzeigen

@ -0,0 +1,55 @@
<?php
//SQL-Library
include_once('./language/'.$config['language'].'/lang_sql.php');
/*
Template
if $sqllib[$i]['sql']=trenn, Then it is a Heading
$sqllib[$i]['name']="";
$sqllib[$i]['sql']="";
$i++;
*/
$i=0;
$sqllib=ARRAY();
$sqllib[$i]['name']=$lang['sqllib_generalfunctions'];
$sqllib[$i]['sql']="trenn";
$i++;
$sqllib[$i]['name']=$lang['sqllib_resetauto'];
$sqllib[$i]['sql']="ALTER TABLE `table` AUTO_INCREMENT=1;";
$i++;
/********* phpBB-Boards *********************************/
$sqllib[$i]['name']="phpBB-".$lang['sqllib_boards'];
$sqllib[$i]['sql']="trenn";
$i++;
// Bord de-/aktivieren
$sqllib[$i]['name']=$lang['sqllib_deactivateboard'].' [phpBB]';
$sqllib[$i]['sql']="UPDATE `phpbb_config` set config_value=1 where config_name='board_disable'";
$i++;
$sqllib[$i]['name']=$lang['sqllib_activateboard'].' [phpBB]';
$sqllib[$i]['sql']="UPDATE `phpbb_config` set config_value=0 where config_name='board_disable'";
$i++;
// Bord de-/aktivieren
$sqllib[$i]['name']="vBulletin-".$lang['sqllib_boards'];
$sqllib[$i]['sql']="trenn";
$i++;
// Bord de-/aktivieren
$sqllib[$i]['name']=$lang['sqllib_deactivateboard'].' [vBulletin]';
$sqllib[$i]['sql']="UPDATE forum SET options = options - 1 WHERE options & 1";
$i++;
$sqllib[$i]['name']=$lang['sqllib_activateboard'].' [vBulletin]';
$sqllib[$i]['sql']="UPDATE forum SET options = options + 1 WHERE NOT (options & 1)";
$i++;
?>

Datei anzeigen

@ -0,0 +1,98 @@
<?php
include_once('./language/'.$config['language'].'/lang.php');
include_once('./language/'.$config['language'].'/lang_dump.php');
$tblr=($tblfrage_refer=='dump') ? 'Backup' : $tblr='Restore';
$filename=(isset($_GET['filename'])) ? $_GET['filename'] : '';
$select_dump_encoding=$_POST['select_dump_encoding'];
//Informationen zusammenstellen
if($tblr=='Backup')
{
//Info aus der Datenbank lesen
MSD_mysql_connect();
$res=mysql_query('SHOW TABLE STATUS FROM `'.$databases['db_actual'].'`');
$numrows=mysql_num_rows($res);
$button_name='dump_tbl';
$button_caption=$lang['startdump'];
$tbl_zeile='';
for($i=0;$i<$numrows;$i++) {
$row=mysql_fetch_array($res);
// Get nr of records -> need to do it this way because of incorrect returns when using InnoDBs
$sql_2="SELECT count(*) as `count_records` FROM `".$databases['db_actual']."`.`".$row['Name']."`";
$res2=@mysql_query($sql_2);
$row2=mysql_fetch_array($res2);
$row['Rows']=$row2['count_records'];
$klasse=($i % 2) ? 1:'';
$tbl_zeile.='<tr class="dbrow'.$klasse.'"><td class="sm" align="left"><input type="checkbox" class="checkbox" name="chk_tbl" value="'.$row['Name'].'">'.$row['Name'].'</td>';
$tbl_zeile.='<td class="sm" align="left"><strong>'.$row['Rows'].'</strong> '.$lang['datawith'].' <strong>'.byte_output($row['Data_length']+$row['Index_length']).'</strong>, '.$lang['lastbufrom'].' '.$row['Update_time'].'</td></tr>';
}
} else {
//Restore - Header aus Backupfile lesen
$button_name='restore_tbl';
$button_caption="";
$gz = (substr($filename,-3))=='.gz' ? 1 : 0;
if ($gz)
{
$fp = gzopen ($fpath.$filename, "r");
$statusline=gzgets($fp,40960);
$offset= gztell($fp);
} else {
$fp = fopen ($fpath.$filename, "r");
$statusline=fgets($fp,5000);
$offset= ftell($fp);
}
//Header auslesen
$sline=ReadStatusline($statusline);
$anzahl_tabellen=$sline[0];
$anzahl_eintraege=$sline[1];
$part=($sline[2]=="") ? 0 : substr($sline[2],3);
$EXTINFO= $sline[6];
if($EXTINFO=="") {
$tbl_zeile.='<tr calss="dbrow"><td class="sm" colspan="2">'.$lang['not_supported'].'</td>';
} else {
for($i=0;$i<$anzahl_tabellen;$i++) {
if ($gz)
{
gzseek($fp,$offset);
$statusline=gzgets($fp,40960);
$offset= gztell($fp);
} else {
fseek($fp,$offset);
$statusline=fgets($fp,5000);
$offset= ftell($fp);
}
$s=explode("|",$statusline);
$tbl_zeile.='<tr class="dbrow"><td align="left"><input type="checkbox" class="checkbox" name="chk_tbl" value="'.$s[1].'">'.$s[1].'</td>';
$tbl_zeile.='<td align="left"><strong>'.$s[2].'</strong> '.$lang['datawith'].' <strong>'.byte_output($s[3]).'</strong>, '.$lang['lastbufrom'].' '.$s[4].'</td></tr>';
}
if($gz) gzclose ($fp); else fclose ($fp);
}
}
$buttons='<tr><td colspan="2"><table width="100%" border="0"><tr>'
.'<td><input type="button" class="Formbutton" onclick="Sel(true);" value="'.$lang['selectall'].'"></td>'
.'<td><input type="button" onclick="Sel(false);" value="'.$lang['deselectall'].'" class="Formbutton"></td>'
.'<td><input type="submit" class="Formbutton" style="width:180px;" name="'.$button_name.'" value="'.$button_caption.'"></td>'
.'</tr></table></td></tr>';
echo '<div id="pagetitle">'.$tblr.' - '.$lang['tableselection'].'</div><h6>'.$lang['db'].': '.$databases['db_actual'].'</h6>';
echo '<div id="content">';
echo '<form name="frm_tbl" action="filemanagement.php" method="post" onSubmit="return chkFormular()">';
echo '<table class="bordersmall">';
echo $buttons;
echo $tbl_zeile;
echo $buttons;
echo '</table>
<input type="hidden" name="dumpKommentar" value="'.$dk.'">
<input type="hidden" name="tbl_array" value="">
<input type="hidden" name="filename" value="'.$filename.'">
<input type="hidden" name="select_dump_encoding" value="'.$select_dump_encoding.'">
</form>';
//echo '</div><br><br><br><br>';
echo '</div><br><br><br>';
?>

478
mysqldumper/inc/template.php Normale Datei
Datei anzeigen

@ -0,0 +1,478 @@
<?php
/***************************************************************************
* template.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id$
*
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
/**
* Template class. By Nathan Codding of the phpBB group.
* The interface was originally inspired by PHPLib templates,
* and the template file formats are quite similar.
*
*/
class MSDTemplate {
var $classname = "MSDTemplate";
// variable that holds all the data we'll be substituting into
// the compiled templates.
// ...
// This will end up being a multi-dimensional array like this:
// $this->_tpldata[block.][iteration#][child.][iteration#][child2.][iteration#][variablename] == value
// if it's a root-level variable, it'll be like this:
// $this->_tpldata[.][0][varname] == value
var $_tpldata = array();
// Hash of filenames for each template handle.
var $files = array();
// Root template directory.
var $root = "";
// this will hash handle names to the compiled code for that handle.
var $compiled_code = array();
// This will hold the uncompiled code for that handle.
var $uncompiled_code = array();
/**
* Constructor. Simply sets the root dir.
*
*/
function MSDTemplate($root = ".")
{
$this->set_rootdir($root);
}
/**
* Destroys this template object. Should be called when you're done with it, in order
* to clear out the template data so you can load/parse a new template set.
*/
function destroy()
{
$this->_tpldata = array();
}
/**
* Sets the template root directory for this Template object.
*/
function set_rootdir($dir)
{
if (!is_dir($dir))
{
return false;
}
$this->root = $dir;
return true;
}
/**
* Sets the template filenames for handles. $filename_array
* should be a hash of handle => filename pairs.
*/
function set_filenames($filename_array)
{
if (!is_array($filename_array))
{
return false;
}
reset($filename_array);
while(list($handle, $filename) = each($filename_array))
{
$this->files[$handle] = $this->make_filename($filename);
}
return true;
}
/**
* Load the file for the handle, compile the file,
* and run the compiled code. This will print out
* the results of executing the template.
*/
function pparse($handle)
{
if (!$this->loadfile($handle))
{
die("Template->pparse(): Couldn't load template file for handle $handle");
}
// actually compile the template now.
if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle]))
{
// Actually compile the code now.
$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
}
// Run the compiled code.
eval($this->compiled_code[$handle]);
return true;
}
/**
* Inserts the uncompiled code for $handle as the
* value of $varname in the root-level. This can be used
* to effectively include a template in the middle of another
* template.
* Note that all desired assignments to the variables in $handle should be done
* BEFORE calling this function.
*/
function assign_var_from_handle($varname, $handle)
{
if (!$this->loadfile($handle))
{
die("Template->assign_var_from_handle(): Couldn't load template file for handle $handle");
}
// Compile it, with the "no echo statements" option on.
$_str = "";
$code = $this->compile($this->uncompiled_code[$handle], true, '_str');
// evaluate the variable assignment.
eval($code);
// assign the value of the generated variable to the given varname.
$this->assign_var($varname, $_str);
return true;
}
/**
* Block-level variable assignment. Adds a new block iteration with the given
* variable assignments. Note that this should only be called once per block
* iteration.
*/
function assign_block_vars($blockname, $vararray)
{
if (strstr($blockname, '.'))
{
// Nested block.
$blocks = explode('.', $blockname);
$blockcount = sizeof($blocks) - 1;
$str = '$this->_tpldata';
for ($i = 0; $i < $blockcount; $i++)
{
$str .= '[\'' . $blocks[$i] . '.\']';
eval('$lastiteration = sizeof(' . $str . ') - 1;');
$str .= '[' . $lastiteration . ']';
}
// Now we add the block that we're actually assigning to.
// We're adding a new iteration to this block with the given
// variable assignments.
$str .= '[\'' . $blocks[$blockcount] . '.\'][] = $vararray;';
// Now we evaluate this assignment we've built up.
eval($str);
}
else
{
// Top-level block.
// Add a new iteration to this block with the variable assignments
// we were given.
$this->_tpldata[$blockname . '.'][] = $vararray;
}
return true;
}
/**
* Root-level variable assignment. Adds to current assignments, overriding
* any existing variable assignment with the same name.
*/
function assign_vars($vararray)
{
reset ($vararray);
while (list($key, $val) = each($vararray))
{
$this->_tpldata['.'][0][$key] = $val;
}
return true;
}
/**
* Root-level variable assignment. Adds to current assignments, overriding
* any existing variable assignment with the same name.
*/
function assign_var($varname, $varval)
{
$this->_tpldata['.'][0][$varname] = $varval;
return true;
}
/**
* Generates a full path+filename for the given filename, which can either
* be an absolute name, or a name relative to the rootdir for this Template
* object.
*/
function make_filename($filename)
{
// Check if it's an absolute or relative path.
if (substr($filename, 0, 1) != '/')
{
$filename = $this->root . '/' . $filename;
}
if (!file_exists($filename))
{
die("Template->make_filename(): Error - file $filename does not exist");
}
return $filename;
}
/**
* If not already done, load the file for the given handle and populate
* the uncompiled_code[] hash with its code. Do not compile.
*/
function loadfile($handle)
{
// If the file for this handle is already loaded and compiled, do nothing.
if (isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle]))
{
return true;
}
// If we don't have a file assigned to this handle, die.
if (!isset($this->files[$handle]))
{
die("Template->loadfile(): No file specified for handle $handle");
}
$filename = $this->files[$handle];
$str = implode("", @file($filename));
if (empty($str))
{
die("Template->loadfile(): File $filename for handle $handle is empty");
}
$this->uncompiled_code[$handle] = $str;
return true;
}
/**
* Compiles the given string of code, and returns
* the result in a string.
* If "do_not_echo" is true, the returned code will not be directly
* executable, but can be used as part of a variable assignment
* for use in assign_code_from_handle().
*/
function compile($code, $do_not_echo = false, $retvar = '')
{
// replace \ with \\ and then ' with \'.
$code = str_replace('\\', '\\\\', $code);
$code = str_replace('\'', '\\\'', $code);
// change template varrefs into PHP varrefs
// This one will handle varrefs WITH namespaces
$varrefs = array();
preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs);
$varcount = sizeof($varrefs[1]);
for ($i = 0; $i < $varcount; $i++)
{
$namespace = $varrefs[1][$i];
$varname = $varrefs[3][$i];
$new = $this->generate_block_varref($namespace, $varname);
$code = str_replace($varrefs[0][$i], $new, $code);
}
// This will handle the remaining root-level varrefs
$code = preg_replace('#\{([a-z0-9\-_]*?)\}#is', '\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \'', $code);
// Break it up into lines.
$code_lines = explode("\n", $code);
$block_nesting_level = 0;
$block_names = array();
$block_names[0] = ".";
// Second: prepend echo ', append ' . "\n"; to each line.
$line_count = sizeof($code_lines);
for ($i = 0; $i < $line_count; $i++)
{
$code_lines[$i] = chop($code_lines[$i]);
if (preg_match('#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m))
{
$n[0] = $m[0];
$n[1] = $m[1];
// Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think. :)
if ( preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $n) )
{
$block_nesting_level++;
$block_names[$block_nesting_level] = $m[1];
if ($block_nesting_level < 2)
{
// Block is not nested.
$code_lines[$i] = '$_' . $n[1] . '_count = ( isset($this->_tpldata[\'' . $n[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $n[1] . '.\']) : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)';
$code_lines[$i] .= "\n" . '{';
}
else
{
// This block is nested.
// Generate a namespace string for this block.
$namespace = implode('.', $block_names);
// strip leading period from root level..
$namespace = substr($namespace, 2);
// Get a reference to the data array for this block that depends on the
// current indices of all parent blocks.
$varref = $this->generate_block_data_ref($namespace, false);
// Create the for loop code to iterate over this block.
$code_lines[$i] = '$_' . $n[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)';
$code_lines[$i] .= "\n" . '{';
}
// We have the end of a block.
unset($block_names[$block_nesting_level]);
$block_nesting_level--;
$code_lines[$i] .= '} // END ' . $n[1];
$m[0] = $n[0];
$m[1] = $n[1];
}
else
{
// We have the start of a block.
$block_nesting_level++;
$block_names[$block_nesting_level] = $m[1];
if ($block_nesting_level < 2)
{
// Block is not nested.
$code_lines[$i] = '$_' . $m[1] . '_count = ( isset($this->_tpldata[\'' . $m[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $m[1] . '.\']) : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)';
$code_lines[$i] .= "\n" . '{';
}
else
{
// This block is nested.
// Generate a namespace string for this block.
$namespace = implode('.', $block_names);
// strip leading period from root level..
$namespace = substr($namespace, 2);
// Get a reference to the data array for this block that depends on the
// current indices of all parent blocks.
$varref = $this->generate_block_data_ref($namespace, false);
// Create the for loop code to iterate over this block.
$code_lines[$i] = '$_' . $m[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;';
$code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)';
$code_lines[$i] .= "\n" . '{';
}
}
}
else if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $m))
{
// We have the end of a block.
unset($block_names[$block_nesting_level]);
$block_nesting_level--;
$code_lines[$i] = '} // END ' . $m[1];
}
else
{
// We have an ordinary line of code.
if (!$do_not_echo)
{
$code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";';
}
else
{
$code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";';
}
}
}
// Bring it back into a single string of lines of code.
$code = implode("\n", $code_lines);
return $code ;
}
/**
* Generates a reference to the given variable inside the given (possibly nested)
* block namespace. This is a string of the form:
* ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . '
* It's ready to be inserted into an "echo" line in one of the templates.
* NOTE: expects a trailing "." on the namespace.
*/
function generate_block_varref($namespace, $varname)
{
// Strip the trailing period.
$namespace = substr($namespace, 0, strlen($namespace) - 1);
// Get a reference to the data block for this namespace.
$varref = $this->generate_block_data_ref($namespace, true);
// Prepend the necessary code to stick this in an echo line.
// Append the variable reference.
$varref .= '[\'' . $varname . '\']';
$varref = '\' . ( ( isset(' . $varref . ') ) ? ' . $varref . ' : \'\' ) . \'';
return $varref;
}
/**
* Generates a reference to the array of data values for the given
* (possibly nested) block namespace. This is a string of the form:
* $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN']
*
* If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.
* NOTE: does not expect a trailing "." on the blockname.
*/
function generate_block_data_ref($blockname, $include_last_iterator)
{
// Get an array of the blocks involved.
$blocks = explode(".", $blockname);
$blockcount = sizeof($blocks) - 1;
$varref = '$this->_tpldata';
// Build up the string with everything but the last child.
for ($i = 0; $i < $blockcount; $i++)
{
$varref .= '[\'' . $blocks[$i] . '.\'][$_' . $blocks[$i] . '_i]';
}
// Add the block reference for the last child.
$varref .= '[\'' . $blocks[$blockcount] . '.\']';
// Add the iterator for the last child if requried.
if ($include_last_iterator)
{
$varref .= '[$_' . $blocks[$blockcount] . '_i]';
}
return $varref;
}
}
?>