Dieser Commit ist enthalten in:
Commit
35b80040c0
337 geänderte Dateien mit 31341 neuen und 0 gelöschten Zeilen
27
inc/define_icons.php
Normale Datei
27
inc/define_icons.php
Normale Datei
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
//define icons
|
||||
$icon['arrow_up']='<img src="' . $config['files']['iconpath'] . 'arrow_up.gif" alt="">';
|
||||
$icon['arrow_down']='<img src="' . $config['files']['iconpath'] . 'arrow_down.gif" alt="">';
|
||||
$icon['blank']=$config['files']['iconpath'] . 'blank.gif';
|
||||
$icon['browse']='<img src="' . $config['files']['iconpath'] . 'browse.gif" alt="' . $lang['title_show_data'] . '" title="' . $lang['title_show_data'] . '">';
|
||||
$icon['edit']='<img src="' . $config['files']['iconpath'] . 'edit.gif" alt="' . $lang['edit'] . '" title="' . $lang['edit'] . '">';
|
||||
$icon['delete']='<img src="' . $config['files']['iconpath'] . 'delete.gif" alt="' . $lang['delete'] . '" title="' . $lang['delete'] . '">';
|
||||
|
||||
$icon['index']='<img src="' . $config['files']['iconpath'] . 'index.gif" alt="' . $lang['title_index'] . '" title="' . $lang['title_index'] . '">';
|
||||
$icon['key_primary']='<img src="' . $config['files']['iconpath'] . 'key_primary.gif" alt="' . $lang['title_key_primary'] . '" title="' . $lang['title_key_primary'] . '">';
|
||||
$icon['key_fulltext']='<img src="' . $config['files']['iconpath'] . 'key_fulltext.gif" alt="' . $lang['title_key_fulltext'] . '" title="' . $lang['title_key_fulltext'] . '">';
|
||||
$icon['key_unique']='<img src="' . $config['files']['iconpath'] . 'key_unique.gif" alt="' . $lang['title_key_unique'] . '" title="' . $lang['title_key_unique'] . '">';
|
||||
$icon['key_nokey']='<img src="' . $config['files']['iconpath'] . 'key_nokey.gif" alt="' . $lang['title_nokey'] . '" title="' . $lang['title_nokey'] . '">';
|
||||
$icon['table_truncate']='<img src="' . $config['files']['iconpath'] . 'table_truncate.gif" alt="' . $lang['empty'] . '" title="' . $lang['empty'] . '">';
|
||||
$icon['table_truncate_reset']='<img src="' . $config['files']['iconpath'] . 'table_truncate_reset.gif" alt="' . $lang['emptykeys'] . '" title="' . $lang['emptykeys'] . '">';
|
||||
$icon['back2db_overview']='<img src="' . $config['files']['iconpath'] . 'arrowleft.gif" alt="' . $lang['sql_backdboverview'] . '" title="' . $lang['sql_backdboverview'] . '">';
|
||||
|
||||
$icon['search']='<img src="' . $config['files']['iconpath'] . 'search.gif" alt="' . $lang['title_search'] . '" title="' . $lang['title_search'] . '">';
|
||||
$icon['mysql_help']='<img src="' . $config['files']['iconpath'] . 'mysql_help.gif" alt="' . $lang['title_mysql_help'] . '" title="' . $lang['title_mysql_help'] . '">';
|
||||
$icon['upload']='<img src="' . $config['files']['iconpath'] . 'openfile.gif" alt="' . $lang['title_upload'] . '" title="' . $lang['title_upload'] . '">';
|
||||
|
||||
//other pics
|
||||
$icon['logo']=$config['theme'] . 'pics/h1_logo.gif';
|
||||
|
||||
?>
|
||||
6
inc/footer.php
Normale Datei
6
inc/footer.php
Normale Datei
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
echo '<p align="center" class="footer">
|
||||
' . $lang['authors'] . ': <a href="http://www.mysqldumper.de" target="_blank">Daniel Schlichtholz & Steffen Kamper</a> | Infoboard:
|
||||
<a href="' . $config['homepage'] . '" target="_blank">' . $config['homepage'] . '</a></p>';
|
||||
echo '</div></body></html>';
|
||||
692
inc/functions.php
Normale Datei
692
inc/functions.php
Normale Datei
|
|
@ -0,0 +1,692 @@
|
|||
<?php
|
||||
if (!function_exists('get_page_parameter')) include ( './inc/functions_global.php' );
|
||||
|
||||
if (!function_exists('str_ireplace')) // borrowed from http://www.dscripts.net
|
||||
{
|
||||
|
||||
function str_ireplace($find, $replace, $string)
|
||||
{
|
||||
if (!is_array($find)) $find=array(
|
||||
|
||||
$find
|
||||
);
|
||||
if (!is_array($replace))
|
||||
{
|
||||
if (!is_array($find)) $replace=array(
|
||||
|
||||
$replace
|
||||
);
|
||||
else
|
||||
{
|
||||
// this will duplicate the string into an array the size of $find
|
||||
$c=count($find);
|
||||
$rString=$replace;
|
||||
unset($replace);
|
||||
for ($i=0; $i < $c; $i++)
|
||||
{
|
||||
$replace[$i]=$rString;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($find as $fKey=>$fItem)
|
||||
{
|
||||
$between=explode(strtolower($fItem),strtolower($string));
|
||||
$pos=0;
|
||||
foreach ($between as $bKey=>$bItem)
|
||||
{
|
||||
$between[$bKey]=substr($string,$pos,strlen($bItem));
|
||||
$pos+=strlen($bItem) + strlen($fItem);
|
||||
}
|
||||
$string=implode($replace[$fKey],$between);
|
||||
}
|
||||
return ( $string );
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('stripos')) // borrowed from php.net comments
|
||||
{
|
||||
|
||||
function stripos($haystack, $needle)
|
||||
{
|
||||
return strpos($haystack,stristr($haystack,$needle));
|
||||
}
|
||||
}
|
||||
|
||||
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=array();
|
||||
$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]=true;
|
||||
else $deleted[$file]=false;
|
||||
}
|
||||
}
|
||||
closedir($d);
|
||||
return $deleted;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
function SetDefault($load_default=false)
|
||||
{
|
||||
global $config,$databases,$nl,$out,$lang,$preConfig;
|
||||
|
||||
if ($load_default == true)
|
||||
{
|
||||
if (file_exists($config['files']['parameter']) && ( is_readable($config['files']['parameter']) )) include ( $config['files']['parameter'] ); // alte Config lesen
|
||||
}
|
||||
$restore_values=array();
|
||||
$restore_values['cron_samedb']=isset($config['cron_samedb']) ? intval($config['cron_samedb']) : 0;
|
||||
$restore_values['cron_dbindex']=isset($config['cron_dbindex']) ? $config['cron_dbindex'] : -3;
|
||||
$restore_values['cron_dbpraefix_array']=isset($config['cron_dbpraefix_array']) ? $config['cron_dbpraefix_array'] : '';
|
||||
if ($restore_values['cron_dbindex'] >= 0 && isset($databases['Name'][$config['cron_dbindex']])) // eine bestimmte Db gewaehlt?
|
||||
{
|
||||
// Ja, Namen merken, um spaeter den Index wieder herzustellen
|
||||
$restore_values['db_actual_cron']=$databases['Name'][$config['cron_dbindex']];
|
||||
}
|
||||
$restore_values['db_actual']=isset($databases['db_actual']) ? $databases['db_actual']:'';
|
||||
//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];
|
||||
}
|
||||
}
|
||||
|
||||
WriteParams(1,$restore_values);
|
||||
if ($load_default === true) WriteLog("default settings loaded.");
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
function WriteParams($as=0, $restore_values=false)
|
||||
{
|
||||
// wenn $as=1 wird versucht den aktuellen Index der Datenbank nach dem Einlesen wieder zu ermitteln
|
||||
// auch wenn sich die Indexnummer durch Loeschaktionen geaendert hat
|
||||
global $config,$databases,$config_dontsave;
|
||||
$nl="\n";
|
||||
|
||||
// alte Werte retten
|
||||
if ($as)
|
||||
{
|
||||
if (is_array($restore_values))
|
||||
{
|
||||
$config['cron_samedb']=$restore_values['cron_samedb'];
|
||||
if ($restore_values['cron_dbindex'] < 0)
|
||||
{
|
||||
// Multidump oder "alle Datenbanken" war gewaehlt
|
||||
$config['cron_dbindex']=$restore_values['cron_dbindex'];
|
||||
}
|
||||
else
|
||||
{
|
||||
//den Index der konkreten Datenbank aus der alten Konfiguration ermitteln
|
||||
$db_names=array();
|
||||
$db_names=array_flip($databases['Name']);
|
||||
if (isset($db_names[$restore_values['db_actual']]))
|
||||
{
|
||||
// alte Db existiert noch -> Index uebernehmen
|
||||
$databases['db_actual']=$restore_values['db_actual'];
|
||||
}
|
||||
else
|
||||
$databases['db_actual']=$databases['Name'][0];
|
||||
|
||||
//Cron-Index wiederfinden
|
||||
if (isset($db_names[$restore_values['cron_dbindex']]))
|
||||
{
|
||||
$config['cron_dbindex']=$db_names[$restore_values['cron_dbindex']];
|
||||
}
|
||||
else
|
||||
{
|
||||
// DB wurde zwischenzeitlich geloescht - sicherheitshalber alle DBs sichern
|
||||
$databases['cron_dbindex']=-3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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("./"));
|
||||
$config['files']['parameter']=$config['paths']['config'] . $config['config_file'] . '.php';
|
||||
$config['files']['iconpath']='./css/' . $config['theme'] . '/icons/';
|
||||
|
||||
foreach ($config as $var=>$val)
|
||||
{
|
||||
if (!in_array($var,$config_dontsave))
|
||||
{
|
||||
if (is_array($val))
|
||||
{
|
||||
$pars_all.='$config[\'' . $var . '\']=array();' . $nl;
|
||||
foreach ($val as $var2=>$val2)
|
||||
{
|
||||
if ($config['magic_quotes_gpc'] == 1)
|
||||
{
|
||||
$val2=stripslashes($val2);
|
||||
}
|
||||
$pars_all.='$config[\'' . $var . '\'][' . ( ( is_int($var2) ) ? $var2 : "'" . $var2 . "'" ) . '] = \'' . myaddslashes($val2) . "';$nl";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($config['magic_quotes_gpc'] == 1)
|
||||
{
|
||||
$val=stripslashes($val);
|
||||
}
|
||||
if (!in_array($var,$config_dontsave)) $pars_all.='$config[\'' . $var . '\'] = \'' . myaddslashes($val) . "';$nl";
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($databases as $var=>$val)
|
||||
{
|
||||
if (is_array($val))
|
||||
{
|
||||
$pars_all.='$databases[\'' . $var . '\']=array();' . $nl;
|
||||
foreach ($val as $var2=>$val2)
|
||||
{
|
||||
if ($config['magic_quotes_gpc'] == 1 || $as == 1)
|
||||
{
|
||||
$pars_all.='$databases[\'' . $var . '\'][' . ( ( is_int($var2) ) ? $var2 : "'" . $var2 . "'" ) . '] = \'' . myaddslashes(stripslashes($val2)) . "';$nl";
|
||||
}
|
||||
else
|
||||
{
|
||||
$pars_all.='$databases[\'' . $var . '\'][' . ( ( is_int($var2) ) ? $var2 : "'" . $var2 . "'" ) . '] = \'' . myaddslashes($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;
|
||||
$file=$config['paths']['config'] . $config['config_file'] . '.php';
|
||||
if ($fp=fopen($file,"wb"))
|
||||
{
|
||||
if (!fwrite($fp,$pars_all)) $ret=false;
|
||||
if (!fclose($fp)) $ret=false;
|
||||
@chmod($file,0777);
|
||||
}
|
||||
else
|
||||
$ret=false;
|
||||
|
||||
$ret=WriteCronScript($restore_values);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function escape_specialchars($text)
|
||||
{
|
||||
$suchen=ARRAY(
|
||||
|
||||
'@',
|
||||
'$',
|
||||
'\\\\',
|
||||
'"'
|
||||
);
|
||||
$ersetzen=ARRAY(
|
||||
|
||||
'\@',
|
||||
'\$',
|
||||
'\\',
|
||||
'\"'
|
||||
);
|
||||
$text=str_replace($suchen,$ersetzen,$text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
// definiert einen SAtring, der ein Array nach Perlsyntax aufbaut
|
||||
function my_implode($arr, $mode=0) // 0=String, 1=intval
|
||||
{
|
||||
global $nl;
|
||||
if (!is_array($arr)) return false;
|
||||
foreach ($arr as $key=>$val)
|
||||
{
|
||||
if ($mode == 0) $arr[$key]=escape_specialchars($val);
|
||||
else $arr[$key]=intval($val);
|
||||
}
|
||||
if ($mode == 0) $ret='("' . implode('","',$arr) . '");' . $nl;
|
||||
else $ret='(' . implode(',',$arr) . ');' . $nl;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function WriteCronScript($restore_values=false)
|
||||
{
|
||||
global $nl,$config,$databases,$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 );
|
||||
$cron_dbname=$databases['db_actual'];
|
||||
|
||||
//v($databases);
|
||||
// -2 = Multidump configuration
|
||||
// -3 = all databases - nothing to do
|
||||
// get standard values for all databases
|
||||
$cron_db_array=$databases['Name'];
|
||||
$cron_dbpraefix_array=$databases['praefix'];
|
||||
$cron_command_before_dump=$databases['command_before_dump'];
|
||||
$cron_command_after_dump=$databases['command_after_dump'];
|
||||
if (!isset($config['cron_dbindex'])) $config['cron_dbindex']=-3;
|
||||
if (intval($config['cron_dbindex']) == -2)
|
||||
{
|
||||
// get values from multidump-settings
|
||||
$cron_db_array=$databases['multi'];
|
||||
$cron_dbpraefix_array=$databases['multi_praefix'];
|
||||
$cron_command_before_dump=$databases['multi_commandbeforedump'];
|
||||
$cron_command_after_dump=$databases['multi_commandafterdump'];
|
||||
}
|
||||
|
||||
$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',
|
||||
'multi_part',
|
||||
'multipart_groesse',
|
||||
'email_maxsize',
|
||||
'auto_delete',
|
||||
'max_backup_files',
|
||||
'perlspeed',
|
||||
'optimize_tables_beforedump',
|
||||
'logcompression',
|
||||
'log_maxsize',
|
||||
'cron_completelog',
|
||||
'cron_use_sendmail',
|
||||
'cron_smtp_port'
|
||||
);
|
||||
foreach ($int_array as $i)
|
||||
{
|
||||
if (is_array($i))
|
||||
{
|
||||
foreach ($i as $key=>$val)
|
||||
{
|
||||
$int_array[$key]=intval($val);
|
||||
}
|
||||
}
|
||||
else
|
||||
$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.='$dbsocket="' . escape_specialchars($config['dbsocket']) . '";' . $nl;
|
||||
$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_dbindex=' . $config['cron_dbindex'] . ';' . $nl;
|
||||
$cronscript.='$cron_printout=' . $config['cron_printout'] . ';' . $nl;
|
||||
$cronscript.='$cronmail=' . $config['send_mail'] . ';' . $nl;
|
||||
$cronscript.='$cronmail_dump=' . $config['send_mail_dump'] . ';' . $nl;
|
||||
$cronscript.='$cronmailto="' . escape_specialchars($config['email_recipient']) . '";' . $nl;
|
||||
$cronscript.='$cronmailto_cc="' . escape_specialchars($config['email_recipient_cc']) . '";' . $nl;
|
||||
$cronscript.='$cronmailfrom="' . escape_specialchars($config['email_sender']) . '";' . $nl;
|
||||
$cronscript.='$cron_use_sendmail=' . $config['cron_use_sendmail'] . ';' . $nl;
|
||||
$cronscript.='$cron_smtp="' . escape_specialchars($config['cron_smtp']) . '";' . $nl;
|
||||
|
||||
$cronscript.='$cron_smtp_port="' . $config['cron_smtp_port'] . '";' . $nl;
|
||||
$cronscript.='@cron_db_array=' . my_implode($cron_db_array);
|
||||
$cronscript.='@cron_dbpraefix_array=' . my_implode($cron_dbpraefix_array);
|
||||
$cronscript.='@cron_command_before_dump=' . my_implode($cron_command_before_dump);
|
||||
$cronscript.='@cron_command_after_dump=' . my_implode($cron_command_after_dump);
|
||||
|
||||
$cronscript.='@ftp_server=' . my_implode($config['ftp_server']);
|
||||
$cronscript.='@ftp_port=' . my_implode($config['ftp_port'],1);
|
||||
$cronscript.='@ftp_mode=' . my_implode($config['ftp_mode'],1);
|
||||
$cronscript.='@ftp_user=' . my_implode($config['ftp_user']);
|
||||
$cronscript.='@ftp_pass=' . my_implode($config['ftp_pass']);
|
||||
$cronscript.='@ftp_dir=' . my_implode($config['ftp_dir']);
|
||||
$cronscript.='@ftp_timeout=' . my_implode($config['ftp_timeout'],1);
|
||||
$cronscript.='@ftp_useSSL=' . my_implode($config['ftp_useSSL'],1);
|
||||
$cronscript.='@ftp_transfer=' . my_implode($config['ftp_transfer'],1);
|
||||
$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.='$max_backup_files=' . $config['max_backup_files'] . ';' . $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.='$complete_log=' . $config['cron_completelog'] . ';' . $nl;
|
||||
$cronscript.='$my_comment="' . escape_specialchars(stripslashes($config['cron_comment'])) . '";' . $nl;
|
||||
$cronscript.="?>";
|
||||
|
||||
// Save config
|
||||
$ret=true;
|
||||
$sfile=$config['paths']['config'] . $config['config_file'] . '.conf.php';
|
||||
if (file_exists($sfile)) @unlink($sfile);
|
||||
|
||||
if ($fp=fopen($sfile,"wb"))
|
||||
{
|
||||
if (!fwrite($fp,$cronscript)) $ret=false;
|
||||
if (!fclose($fp)) $ret=false;
|
||||
@chmod("$sfile",0777);
|
||||
}
|
||||
else
|
||||
$ret=false;
|
||||
|
||||
// if standard config was deleted -> restore it with the actual values
|
||||
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",0777);
|
||||
}
|
||||
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['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, $db='')
|
||||
{
|
||||
global $databases,$config,$lang;
|
||||
|
||||
if (!isset($config['dbconnection'])) MSD_mysql_connect();
|
||||
$db_list=array();
|
||||
if ($db == '')
|
||||
{
|
||||
// Datenbanken automatisch erkennen
|
||||
$show_dbs=mysql_query("SHOW DATABASES",$config['dbconnection']);
|
||||
if (!$show_dbs === false)
|
||||
{
|
||||
WHILE ($row=mysql_fetch_row($show_dbs))
|
||||
{
|
||||
if (trim($row[0]) > '') $db_list[]=$row[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
$db_list[]=$db; // DB wurde manuell angegeben
|
||||
|
||||
|
||||
if (sizeof($db_list) > 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]=$db_list[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)
|
||||
{
|
||||
global $dont_strip;
|
||||
if (is_array($value))
|
||||
{
|
||||
foreach ($value as $key=>$val)
|
||||
{
|
||||
if (!in_array($key,$dont_strip)) $ret[$key]=my_strip_tags($val);
|
||||
else $ret[$key]=$val;
|
||||
}
|
||||
}
|
||||
else
|
||||
$ret=trim(strip_tags($value));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function myaddslashes($t)
|
||||
{
|
||||
return str_replace("'","\'",$t);
|
||||
}
|
||||
|
||||
?>
|
||||
545
inc/functions_dump.php
Normale Datei
545
inc/functions_dump.php
Normale Datei
|
|
@ -0,0 +1,545 @@
|
|||
<?php
|
||||
include ( './inc/functions_global.php' );
|
||||
|
||||
//Buffer fuer Multipart-Filesizepruefung
|
||||
$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());
|
||||
$endung=( $config['compression'] ) ? '.sql.gz' : '.sql';
|
||||
$dump['backupdatei']=$dateiname . $endung;
|
||||
|
||||
if (file_exists($config['paths']['backup'] . $dump['backupdatei'])) unlink($config['paths']['backup'] . $dump['backupdatei']);
|
||||
$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;
|
||||
$statuszeile.='SET FOREIGN_KEY_CHECKS=0;' . $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: ' . $cur_time;
|
||||
}
|
||||
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,$lang,$dump,$mysql_commentstring;
|
||||
|
||||
$t_array=explode("|",$databases['db_actual_tableselected']);
|
||||
$t=0;
|
||||
$r=0;
|
||||
$t_zeile="$mysql_commentstring\n$mysql_commentstring TABLE-INFO\r\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);
|
||||
if ($res2 === false)
|
||||
{
|
||||
// error reading table definition
|
||||
$read_create_error=sprintf($lang['fatal_error_dump'],$databases['Name'][$dump['dbindex']],$erg['Name']) . ': ' . mysql_error($config['dbconnection']);
|
||||
Errorlog("DUMP",$databases['Name'][$dump['dbindex']],'',$read_create_error,0);
|
||||
WriteLog($read_create_error);
|
||||
if ($config['stop_with_error'] > 0)
|
||||
{
|
||||
die($read_create_error);
|
||||
}
|
||||
$dump['errors']++;
|
||||
//$i++; // skip corrupted table
|
||||
}
|
||||
else
|
||||
{
|
||||
$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'];
|
||||
if (isset($erg['Type'])) $erg['Engine']=$erg['Type'];
|
||||
$t_zeile.="$mysql_commentstring TABLE|" . $erg['Name'] . '|' . $erg['Rows'] . '|' . ( $erg['Data_length'] + $erg['Index_length'] ) . '|' . $erg['Update_time'] . '|' . $erg['Engine'] . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
//$dump['totalrecords']=$r;
|
||||
$flags=1;
|
||||
|
||||
$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";
|
||||
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,$dump;
|
||||
|
||||
$def="\n\n$mysql_commentstring\n$mysql_commentstring Create Table `$table`\n$mysql_commentstring\n\n";
|
||||
if ($dump['table_types'][getDBIndex($db,$table)] == 'VIEW')
|
||||
{
|
||||
$def.="DROP VIEW IF EXISTS `$table`;\n";
|
||||
$withdata=0;
|
||||
}
|
||||
else
|
||||
$def.="DROP TABLE IF EXISTS `$table`;\n";
|
||||
mysql_select_db($db);
|
||||
$result=mysql_query('SHOW CREATE TABLE `' . $table . '`',$config['dbconnection']);
|
||||
$row=@mysql_fetch_row($result);
|
||||
if ($row === false) return false;
|
||||
$def.=$row[1] . ';' . "\n\n";
|
||||
if ($withdata == 1)
|
||||
{
|
||||
$def.="$mysql_commentstring\n$mysql_commentstring Data for Table `$table`\n$mysql_commentstring\n\n";
|
||||
$def.="/*!40000 ALTER TABLE `$table` DISABLE KEYS */;" . $nl;
|
||||
}
|
||||
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='';
|
||||
$complete=Fieldlist($db,$table) . ' ';
|
||||
|
||||
$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);
|
||||
if ($ergebnisse !== false)
|
||||
{
|
||||
$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++;
|
||||
|
||||
$insert='INSERT INTO `' . $table . '` ' . $complete . 'VALUES (';
|
||||
|
||||
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) . ');' . $nl;
|
||||
$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 && $dump['table_types'][getDBIndex($db,$table)] != 'VIEW') $dump['data'].="/*!40000 ALTER TABLE `$table` ENABLE KEYS */;\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
// table corrupt -> skip it
|
||||
$dump['table_offset']++;
|
||||
$dump['zeilen_offset']=0;
|
||||
$dump['restzeilen']=$dump['restzeilen'] - $ergebnisse;
|
||||
$dump['data'].="/*!40000 ALTER TABLE `$table` ENABLE KEYS */;\n";
|
||||
if (strlen($dump['data']) > $config['memory_limit'] || ( $config['multi_part'] == 1 && strlen($dump['data']) + $buffer > $config['multipart_groesse'] ))
|
||||
{
|
||||
WriteToDumpFile();
|
||||
}
|
||||
}
|
||||
@mysql_free_result($result);
|
||||
}
|
||||
|
||||
function WriteToDumpFile()
|
||||
{
|
||||
global $config,$dump,$buffer;
|
||||
$dump['filesize']=0;
|
||||
|
||||
$df=$config['paths']['backup'] . $dump['backupdatei'];
|
||||
|
||||
if ($config['compression'] == 1)
|
||||
{
|
||||
if ($dump['data'] != '')
|
||||
{
|
||||
$fp=gzopen($df,'ab');
|
||||
gzwrite($fp,$dump['data']);
|
||||
gzclose($fp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($dump['data'] != '')
|
||||
{
|
||||
$fp=fopen($df,'ab');
|
||||
fwrite($fp,$dump['data']);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
$dump['data']='';
|
||||
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 (!isset($dump['dbindex'])) return;
|
||||
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";
|
||||
if (isset($config['email_recipient_cc']) && trim($config['email_recipient_cc']) > '') $header.="Cc: " . $config['email_recipient_cc'] . "\r\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\n";
|
||||
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)) . ")");
|
||||
}
|
||||
include_once ( './inc/functions.php' );
|
||||
$msg_body.='<a href="' . getServerProtocol() . $_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";
|
||||
if (isset($config['email_recipient_cc']) && trim($config['email_recipient_cc']) > '') $header.="Cc: " . $config['email_recipient_cc'] . "\r\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";
|
||||
if (isset($config['email_recipient_cc']) && trim($config['email_recipient_cc']) > '') $header.="Cc: " . $config['email_recipient_cc'] . "\r\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";
|
||||
if (isset($config['email_recipient_cc']) && trim($config['email_recipient_cc']) > '') $header.="Cc: " . $config['email_recipient_cc'] . "\r\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 . 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($i)
|
||||
{
|
||||
global $config,$dump,$out;
|
||||
|
||||
if ($config['multi_part'] == 0)
|
||||
{
|
||||
SendViaFTP($i,$dump['backupdatei'],1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$dateistamm=substr($dump['backupdatei'],0,strrpos($dump['backupdatei'],"part_")) . "part_";
|
||||
$dateiendung=( $config['compression'] == 1 ) ? ".sql.gz" : ".sql";
|
||||
for ($a=1; $a < ( $dump['part'] - $dump['part_offset'] ); $a++)
|
||||
{
|
||||
$mpdatei=$dateistamm . $a . $dateiendung;
|
||||
SendViaFTP($i,$mpdatei,$a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function SendViaFTP($i, $source_file, $conn_msg=1)
|
||||
{
|
||||
global $config,$out,$lang;
|
||||
flush();
|
||||
if ($conn_msg == 1) $out.='<span class="success">' . $lang['filesendftp'] . "(" . $config['ftp_server'][$i] . " - " . $config['ftp_user'][$i] . ")</span><br>";
|
||||
// Herstellen der Basis-Verbindung
|
||||
if ($config['ftp_useSSL'][$i] == 0) $conn_id=@ftp_connect($config['ftp_server'][$i],$config['ftp_port'][$i],$config['ftp_timeout'][$i]);
|
||||
else $conn_id=@ftp_ssl_connect($config['ftp_server'][$i],$config['ftp_port'][$i],$config['ftp_timeout'][$i]);
|
||||
// Einloggen mit Benutzername und Kennwort
|
||||
$login_result=@ftp_login($conn_id,$config['ftp_user'][$i],$config['ftp_pass'][$i]);
|
||||
if ($config['ftp_mode'][$i] == 1) ftp_pasv($conn_id,true);
|
||||
|
||||
// Verbindung überprüfen
|
||||
if (( !$conn_id ) || ( !$login_result ))
|
||||
{
|
||||
$out.='<span class="error">' . $lang['ftpconnerror'] . $config['ftp_server'][$i] . $lang['ftpconnerror1'] . $config['ftp_user'][$i] . $lang['ftpconnerror2'] . '</span><br>';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($conn_msg == 1) $out.='<span class="success">' . $lang['ftpconnected1'] . $config['ftp_server'][$i] . $lang['ftpconnerror1'] . $config['ftp_user'][$i] . '</span><br>';
|
||||
}
|
||||
|
||||
// Upload der Datei
|
||||
$dest=$config['ftp_dir'][$i] . $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'][$i] . $lang['ftpconnected3'] . '</span><br>';
|
||||
WriteLog("'$source_file' sent via FTP.");
|
||||
}
|
||||
|
||||
// Schließen des FTP-Streams
|
||||
@ftp_quit($conn_id);
|
||||
}
|
||||
?>
|
||||
484
inc/functions_files.php
Normale Datei
484
inc/functions_files.php
Normale Datei
|
|
@ -0,0 +1,484 @@
|
|||
<?php
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
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,$fpath,$lang,$databases,$href,$dbactiv,$action,$expand;
|
||||
|
||||
$files=Array();
|
||||
//Backup-Dateien
|
||||
$Theader=$lang['fm_files1'] . ' ' . $lang['of'] . ' "' . $dbactiv . '"';
|
||||
$akind=1;
|
||||
$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>' . $lang['fm_choose_file'] . ' ';
|
||||
$fl.='<span id="gd"> </span><br><br>';
|
||||
|
||||
$fl.='<table class="bdr">';
|
||||
$fl.='<tr><td colspan="8" align="left"><strong>' . $Theader . '</strong></td><td colspan="3" align="right"></td></tr>';
|
||||
|
||||
//Tableheader
|
||||
$fl.='<tr class="thead"><th colspan="2">' . $lang['db'] . '</th>
|
||||
<th>gz</th>
|
||||
<th>Script</th>
|
||||
<th colspan="2">' . $lang['comment'] . '</th>
|
||||
<th>' . $lang['fm_filedate'] . '</th>
|
||||
<th>Multipart</th>
|
||||
<th>' . $lang['fm_tables'] . ' / ' . $lang['fm_records'] . '</th>
|
||||
<th align="right" colspan="2">' . $lang['fm_filesize'] . '</th>
|
||||
<th align="right" >' . $lang['encoding'] . '</th></tr>';
|
||||
|
||||
$checkindex=$arrayindex=$gesamt=0;
|
||||
$db_summary_anzahl=Array();
|
||||
if (count($files) > 0)
|
||||
{
|
||||
for ($i=0; $i < sizeof($files); $i++)
|
||||
{
|
||||
// Dateigröß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'],-3) == '.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 (sortierdatum($but) > sortierdatum($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 (sortierdatum($but) > sortierdatum($db_summary_last[$dbn])) $db_summary_last[$dbn]=$but;
|
||||
|
||||
}
|
||||
}
|
||||
// Gesamtgroesse 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--)
|
||||
{
|
||||
if (isset($db_backups[$i]['db']) && $db_backups[$i]['db'] == $dbactiv)
|
||||
{
|
||||
$cl=( $rowclass % 2 ) ? 'dbrow' : 'dbrow1';
|
||||
$multi=( $db_summary_anzahl[$dbactiv] > 1 && $action == 'files' ) ? 1 : 0;
|
||||
|
||||
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.='>';
|
||||
$fl.='<td align="left" colspan="2" nowrap="nowrap">';
|
||||
$fl.='<input type="hidden" name="multi" value="' . $multi . '">';
|
||||
|
||||
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 ) ? ' <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>' : ' <span style="font-size:8pt;">' . $db_backups[$i]['db'] . '</span></td>';
|
||||
|
||||
$fl.='<td class="sm" nowrap="nowrap" align="center">' . ( ( substr($dbn,-3) == ".gz" ) ? '<img src="' . $config['files']['iconpath'] . 'gz.gif" alt="' . $lang['compressed'] . '" width="16" height="16" border="0">' : " " ) . '</td>';
|
||||
$fl.='<td class="sm" nowrap="nowrap" align="center">' . $db_backups[$i]['script'] . '</td>';
|
||||
$fl.='<td class="sm" nowrap="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">' : " " ) . '</td>';
|
||||
$fl.='<td class="sm" nowrap="nowrap" align="left">' . ( ( $db_backups[$i]['kommentar'] != "" ) ? nl2br(wordwrap($db_backups[$i]['kommentar'],50)) : " " ) . '</td>';
|
||||
|
||||
$fl.='<td class="sm" nowrap="nowrap">' . $db_backups[$i]['date'] . '</td>';
|
||||
$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><td style="text-align:right;padding-right:12px;" nowrap="nowrap">';
|
||||
$fl.=( $db_backups[$i]['eintraege'] != -1 ) ? $db_backups[$i]['tabellen'] . ' / ' . number_format($db_backups[$i]['eintraege'],0,",",".") : $lang['fm_oldbackup'];
|
||||
$fl.='</td>';
|
||||
$fl.='<td align="right" colspan="2" style="font-size:8pt;">' . byte_output($db_backups[$i]['size']) . '</td>';
|
||||
$fl.='<td align="right" style="font-size:8pt;">' . $db_backups[$i]['charset'] . '</td>';
|
||||
$fl.='</tr>';
|
||||
|
||||
if ($expand == $i)
|
||||
{
|
||||
$fl.='<tr ' . ( ( $dbactiv == $databases['db_actual'] ) ? 'class="dbrowsel"' : 'class="' . $cl . '"' ) . '>';
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//v($db_backups);
|
||||
$fl.='<tr><td colspan="11" align="left"><br><strong>' . $lang['fm_all_bu'] . '</strong></td></tr>';
|
||||
//Tableheader
|
||||
$fl.='<tr class="thead"><th colspan="5" align="left">' . $lang['fm_dbname'] . '</th>
|
||||
<th align="left">' . $lang['fm_anz_bu'] . '</th><th>' . $lang['fm_last_bu'] . '</th>
|
||||
<th colspan="5" style="text-align:right;">' . $lang['fm_totalsize'] . '</th></tr>';
|
||||
//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 . '"><td colspan="5" align="left"><a href="' . $href . '&dbactiv=' . $key . '">' . $keyaus . '</a></td>';
|
||||
$fl.='<td style="text-align:right">' . $val . ' </td>';
|
||||
$fl.='<td class="sm" nowrap="nowrap">' . ( ( isset($db_summary_last[$key]) ) ? $db_summary_last[$key] : "" ) . '</td>';
|
||||
$fl.='<td style="text-align:right;font-size:8pt;" colspan="5">' . byte_output($db_summary_size[$key]) . ' </td>';
|
||||
$fl.='</tr>';
|
||||
}
|
||||
}
|
||||
if (!is_array($files)) $fl.='<tr><td colspan="11">' . $lang['fm_nofilesfound'] . '</td></tr>';
|
||||
|
||||
//--------------------------------------------------------
|
||||
//*** Ausgabe der Gesamtgröße aller Backupfiles ***
|
||||
//--------------------------------------------------------
|
||||
$space=MD_FreeDiskSpace();
|
||||
$fl.='<tr>';
|
||||
$fl.='<td align="left" colspan="8"><b>' . $lang['fm_totalsize'] . ' (' . $Sum_Files . ' files): </b> </td>';
|
||||
$fl.='<td style="text-align:right" colspan="4"><b>' . byte_output($gesamt) . '</b></td>';
|
||||
$fl.='</tr>';
|
||||
|
||||
//--------------------------------------------------------
|
||||
//*** Ausgabe des freien Speicher auf dem Rechner ***
|
||||
//--------------------------------------------------------
|
||||
$fl.='<tr>';
|
||||
$fl.='<td colspan="8" align="left">' . $lang['fm_freespace'] . ': </td>';
|
||||
$fl.='<td colspan="4" style="text-align:right"><b>' . $space . '</b></td>';
|
||||
$fl.='</tr>';
|
||||
$fl.='</table></div>';
|
||||
|
||||
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> ' . byte_output(@filesize($config['paths']['backup'] . $dateistamm . $i . $dateiendung));
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
|
||||
function Converter($filesource, $filedestination, $cp)
|
||||
{
|
||||
global $config,$lang;
|
||||
|
||||
$filesize=0;
|
||||
$max_filesize=1024 * 1024 * 10; //10 MB splitsize
|
||||
$part=1;
|
||||
$cps=( substr(strtolower($filesource),-2) == "gz" ) ? 1 : 0;
|
||||
$filedestination.='_' . date("Y_m_d_H_i",time());
|
||||
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=( $cp == 1 ) ? gzopen($config['paths']['backup'] . $filedestination . '_part_1.sql.gz',"w") : fopen($config['paths']['backup'] . $filedestination . '_part_1.sql',"w");
|
||||
|
||||
$zeile=get_pseudo_statusline($part,$filedestination) . "\r\n";
|
||||
( $cp == 1 ) ? gzwrite($z,$zeile) : fwrite($z,$zeile);
|
||||
$zeile='';
|
||||
|
||||
$insert=$mode="";
|
||||
$n=0;
|
||||
$eof=( $cps == 1 ) ? gzeof($f) : feof($f);
|
||||
$splitable=false; // can the file besplitted? Try to avoid splitting before a command is completed
|
||||
WHILE (!$eof)
|
||||
{
|
||||
$eof=( $cps == 1 ) ? gzeof($f) : feof($f);
|
||||
$zeile=( $cps == 1 ) ? gzgets($f,5144000) : fgets($f,5144000);
|
||||
|
||||
$t=strtolower(substr($zeile,0,10));
|
||||
if ($t > '')
|
||||
{
|
||||
switch ($t)
|
||||
{
|
||||
case 'insert int':
|
||||
{
|
||||
// eine neue Insert Anweisung beginnt
|
||||
if (strpos($zeile,0,'(') === false)
|
||||
{
|
||||
//Feldnamen stehen in der naechsten Zeile - holen
|
||||
$zeile.="\n\r";
|
||||
$zeile.=( $cps == 1 ) ? trim(gzgets($f,8192)) : trim(fgets($f,8192));
|
||||
$zeile.=' ';
|
||||
}
|
||||
|
||||
// get INSERT-Satement
|
||||
$insert=substr($zeile,0,strpos($zeile,'('));
|
||||
if (substr(strtoupper($insert),-7) != 'VALUES ') $insert.=' VALUES ';
|
||||
$mode='insert';
|
||||
$zeile="\n\r" . $zeile;
|
||||
$splitable=false;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'create tab':
|
||||
{
|
||||
$mode='create';
|
||||
WHILE (substr(rtrim($zeile),-1) != ';')
|
||||
{
|
||||
$zeile.=fgets($f,8192);
|
||||
}
|
||||
$zeile="\n\r" . MySQL_Ticks($zeile) . "\n\r";
|
||||
$splitable=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode == 'insert')
|
||||
{
|
||||
if (substr(rtrim($zeile),strlen($zeile) - 3,2) == ');') $splitable=true;
|
||||
|
||||
// Komma loeschen
|
||||
$zeile=str_replace('),(',");\n\r" . $insert . ' (',$zeile);
|
||||
//if(substr(ltrim($zeile),0,2)==',(' && $insert !='')
|
||||
//{
|
||||
// $zeile=";\n\r".$insert.$zeile; //substr($zeile,1);
|
||||
//}
|
||||
//if(substr(rtrim($zeile),-2)=='),' && $insert !='') {
|
||||
// $zeile="\n\r".substr(rtrim($zeile),0,strlen(rtrim($zeile))-1).";\r\n".$insert;
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ($splitable == true && $filesize > $max_filesize) // start new file?
|
||||
{
|
||||
$part++;
|
||||
if ($mode == 'insert') // Insert -> first complete Insert-Statement, then begin new file
|
||||
{
|
||||
if ($cp == 1)
|
||||
{
|
||||
gzwrite($z,$zeile);
|
||||
gzclose($z);
|
||||
$z=gzopen($config['paths']['backup'] . $filedestination . '_part_' . $part . '.sql.gz',"w");
|
||||
$zeile=get_pseudo_statusline($part,$filedestination) . "\r\n";
|
||||
gzwrite($z,$zeile);
|
||||
$zeile='';
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($z,$zeile);
|
||||
echo "<br>Neue Datei.Zeile: <br>" . htmlspecialchars(substr($zeile,0,20)) . ".." . htmlspecialchars(substr($zeile,strlen($zeile) - 41,40)) . "<br>";
|
||||
fclose($z);
|
||||
$z=fopen($config['paths']['backup'] . $filedestination . '_part_' . $part . '.sql',"w");
|
||||
$zeile=get_pseudo_statusline($part,$filedestination) . "\r\n";
|
||||
gzwrite($z,$zeile);
|
||||
$zeile='';
|
||||
}
|
||||
}
|
||||
else // first close last file, then begin new one and write new beginning command
|
||||
{
|
||||
if ($cp == 1)
|
||||
{
|
||||
gzclose($z);
|
||||
$z=gzopen($config['paths']['backup'] . $filedestination . '_part_' . $part . '.sql.gz',"w");
|
||||
$zeile=get_pseudo_statusline($part,$filedestination) . "\r\n" . $zeile;
|
||||
gzwrite($z,$zeile);
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose($z);
|
||||
$z=fopen($config['paths']['backup'] . $filedestination . '_part_' . $part . '.sql',"w");
|
||||
$zeile=get_pseudo_statusline($part,$filedestination) . "\r\n" . $zeile;
|
||||
fwrite($z,$zeile);
|
||||
}
|
||||
}
|
||||
$filesize=0;
|
||||
$splitable=false;
|
||||
}
|
||||
else // no, append to actual file
|
||||
{
|
||||
$filesize+=strlen($zeile);
|
||||
if ($n > 600)
|
||||
{
|
||||
$n=0;
|
||||
echo '<br>';
|
||||
}
|
||||
echo '.';
|
||||
if ($cps == 1) gzwrite($z,$zeile);
|
||||
else fwrite($z,$zeile);
|
||||
flush();
|
||||
}
|
||||
$n++;
|
||||
//if ($part>4) break;
|
||||
}
|
||||
$zeile="\n-- EOB";
|
||||
if ($cps == 1)
|
||||
{
|
||||
gzwrite($z,$zeile);
|
||||
gzclose($z);
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($z,$zeile);
|
||||
fclose($z);
|
||||
}
|
||||
|
||||
if ($cps == 1) gzclose($f);
|
||||
else fclose($f);
|
||||
echo "</span><h5>" . sprintf($lang['convert_finished'],$filedestination) . "</h5>";
|
||||
}
|
||||
|
||||
function get_pseudo_statusline($part, $filedestination)
|
||||
{
|
||||
echo "<br>Continue with part: " . $part . '<br>';
|
||||
$ret="-- Status:-1:-1:MP_" . ( $part ) . ":" . $filedestination . ":php:converter2:converted:unknown:1:::latin1:EXTINFO\r\n" . "-- TABLE-INFO\r\n" . "-- TABLE|unknown|0|0|2009-01-24 20:39:39\r\n" . "-- EOF TABLE-INFO\r\n";
|
||||
return $ret;
|
||||
}
|
||||
|
||||
?>
|
||||
1084
inc/functions_global.php
Normale Datei
1084
inc/functions_global.php
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
356
inc/functions_restore.php
Normale Datei
356
inc/functions_restore.php
Normale Datei
|
|
@ -0,0 +1,356 @@
|
|||
<?php
|
||||
define('DEBUG',0);
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
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']);
|
||||
if (DEBUG) echo "<br><br>Zeile: " . htmlspecialchars($zeile);
|
||||
/******************* 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));
|
||||
// pre-built compare strings - so we need the CPU power only once :)
|
||||
$sub9=substr($zeile2,0,9);
|
||||
$sub7=substr($sub9,0,7);
|
||||
$sub6=substr($sub7,0,6);
|
||||
$sub4=substr($sub6,0,4);
|
||||
$sub3=substr($sub4,0,3);
|
||||
$sub2=substr($sub3,0,2);
|
||||
$sub1=substr($sub2,0,1);
|
||||
|
||||
if ($sub7 == 'INSERT ')
|
||||
{
|
||||
$sqlparser_status=3; //Datensatzaktion
|
||||
$restore['actual_table']=get_tablename($zeile);
|
||||
}
|
||||
|
||||
//Einfache Anweisung finden die mit Semikolon beendet werden
|
||||
elseif ($sub7 == 'LOCK TA') $sqlparser_status=4;
|
||||
elseif ($sub6 == 'COMMIT') $sqlparser_status=7;
|
||||
elseif ($sub6 == 'BEGIN ') $sqlparser_status=7;
|
||||
elseif ($sub9 == 'UNLOCK TA') $sqlparser_status=4;
|
||||
elseif ($sub3 == 'SET') $sqlparser_status=4;
|
||||
elseif ($sub6 == 'START ') $sqlparser_status=4;
|
||||
elseif ($sub3 == '/*!') $sqlparser_status=5; //MySQL-Condition oder Kommentar
|
||||
elseif ($sub9 == 'ALTER TAB') $sqlparser_status=4; // Alter Table
|
||||
elseif ($sub9 == 'CREATE TA') $sqlparser_status=2; //Create Table
|
||||
elseif ($sub9 == 'CREATE AL') $sqlparser_status=2; //Create View
|
||||
elseif ($sub9 == 'CREATE IN') $sqlparser_status=4; //Indexaktion
|
||||
|
||||
|
||||
//Condition?
|
||||
elseif (( $sqlparser_status != 5 ) && ( substr($zeile2,0,2) == '/*' )) $sqlparser_status=6;
|
||||
|
||||
// Delete actions
|
||||
elseif ($sub9 == 'DROP TABL') $sqlparser_status=1;
|
||||
elseif ($sub9 == 'DROP VIEW') $sqlparser_status=1;
|
||||
|
||||
// Befehle, die nicht ausgeführt werden sollen
|
||||
elseif ($sub9 == 'CREATE DA ') $sqlparser_status=7;
|
||||
elseif ($sub9 == 'DROP DATA ') $sqlparser_status=7;
|
||||
elseif ($sub3 == 'USE') $sqlparser_status=7;
|
||||
|
||||
// Am Ende eines MySQLDumper-Backups angelangt?
|
||||
elseif ($sub6 == '-- EOB' || $sub4 == '# EO')
|
||||
{
|
||||
$restore['EOB']=true;
|
||||
$restore['fileEOF']=true;
|
||||
$zeile='';
|
||||
$zeile2='';
|
||||
$sqlparser_status=100;
|
||||
}
|
||||
|
||||
// Kommentar?
|
||||
elseif ($sub2 == '--' || $sub1 == '#')
|
||||
{
|
||||
$zeile='';
|
||||
$zeile2='';
|
||||
$sqlparser_status=0;
|
||||
}
|
||||
|
||||
// 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: " . htmlspecialchars($complete_sql);
|
||||
echo "<br>Erweiterte Inserts: " . $restore['erweiterte_inserts'];
|
||||
die('<br>' . $lang['unknown_sqlcommand'] . ': ' . $zeile . '<br><br>' . $complete_sql);
|
||||
}
|
||||
/******************* 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 == 3)
|
||||
{
|
||||
//INSERT
|
||||
if (SQL_Is_Complete($complete_sql))
|
||||
{
|
||||
$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
|
||||
else 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 ')
|
||||
{
|
||||
// wenn der Syntax aufgrund eines Reloads verloren ging - neu ermitteln
|
||||
if (!isset($restore['insert_syntax'])) $restore['insert_syntax']=get_insert_syntax($restore['actual_table']);
|
||||
$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'] . '`';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if ($sqlparser_status == 1)
|
||||
{
|
||||
//Löschaktion
|
||||
if ($last_char == ';') $sqlparser_status=100; //Befehl komplett
|
||||
$restore['actual_table']=get_tablename($complete_sql);
|
||||
}
|
||||
|
||||
else if ($sqlparser_status == 2)
|
||||
{
|
||||
// Createanweisung ist beim Finden eines ; beendet
|
||||
if ($last_char == ';')
|
||||
{
|
||||
if ($config['minspeed'] > 0) $restore['anzahl_zeilen']=$config['minspeed'];
|
||||
// Soll die Tabelle hergestellt werden?
|
||||
$do_it=true;
|
||||
if (is_array($restore['tables_to_restore']))
|
||||
{
|
||||
$do_it=false;
|
||||
if (in_array($restore['actual_table'],$restore['tables_to_restore']))
|
||||
{
|
||||
$do_it=true;
|
||||
}
|
||||
}
|
||||
if ($do_it)
|
||||
{
|
||||
$tablename=submit_create_action($complete_sql);
|
||||
$restore['actual_table']=$tablename;
|
||||
$restore['table_ready']++;
|
||||
}
|
||||
// Zeile verwerfen, da CREATE jetzt bereits ausgefuehrt wurde und naechsten Befehl suchen
|
||||
$complete_sql='';
|
||||
$sqlparser_status=0;
|
||||
}
|
||||
}
|
||||
|
||||
// Index
|
||||
else 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;
|
||||
}
|
||||
}
|
||||
|
||||
// Kommentar oder Condition
|
||||
else if ($sqlparser_status == 5)
|
||||
{ //Anweisung
|
||||
$t=strrpos($zeile,'*/;');
|
||||
if (!$t === false)
|
||||
{
|
||||
$restore['anzahl_zeilen']=$config['minspeed'];
|
||||
$sqlparser_status=100;
|
||||
}
|
||||
}
|
||||
|
||||
// Mehrzeiliger oder Inline-Kommentar
|
||||
else if ($sqlparser_status == 6)
|
||||
{
|
||||
$t=strrpos($zeile,'*/');
|
||||
if (!$t === false)
|
||||
{
|
||||
$complete_sql='';
|
||||
$sqlparser_status=0;
|
||||
}
|
||||
}
|
||||
|
||||
// Befehle, die verworfen werden sollen
|
||||
else 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;
|
||||
}
|
||||
// wenn bestimmte Tabellen wiederhergestellt werden sollen -> pruefen
|
||||
if (is_array($restore['tables_to_restore']) && !( in_array($restore['actual_table'],$restore['tables_to_restore']) ))
|
||||
{
|
||||
$complete_sql='';
|
||||
}
|
||||
return trim($complete_sql);
|
||||
}
|
||||
|
||||
function submit_create_action($sql)
|
||||
{
|
||||
//Führt eine Create-Anweisung durch
|
||||
$tablename=get_tablename($sql);
|
||||
$res=@mysql_query($sql);
|
||||
if ($res === false)
|
||||
{
|
||||
// erster Versuch fehlgeschlagen -> zweiter Versuch - vielleicht versteht der Server die Inline-Kommentare nicht?
|
||||
$sql=del_inline_comments($sql);
|
||||
$res=@mysql_query(downgrade($sql));
|
||||
if ($res === false)
|
||||
{
|
||||
// wieder nichts. Ok, haben wir hier einen alten MySQL-Server 3.x oder 4.0.x?
|
||||
// versuchen wir es mal mit der alten Syntax
|
||||
$res=@mysql_query(downgrade($sql));
|
||||
}
|
||||
}
|
||||
if ($res === false)
|
||||
{
|
||||
// wenn wir hier angekommen sind hat nichts geklappt -> Fehler ausgeben und abbrechen
|
||||
SQLError($sql,mysql_error());
|
||||
die("<br>Fatal error: Couldn't create table or view `" . $tablename . "´");
|
||||
}
|
||||
return $tablename;
|
||||
}
|
||||
|
||||
function get_insert_syntax($table)
|
||||
{
|
||||
$insert='';
|
||||
$sql='SHOW COLUMNS FROM `' . $table . '`';
|
||||
$res=mysql_query($sql);
|
||||
if ($res)
|
||||
{
|
||||
$insert='INSERT INTO `' . $table . '` (';
|
||||
while ($row=mysql_fetch_object($res))
|
||||
{
|
||||
$insert.='`' . $row->Field . '`,';
|
||||
}
|
||||
$insert=substr($insert,0,strlen($insert) - 1) . ') ';
|
||||
}
|
||||
else
|
||||
{
|
||||
global $restore;
|
||||
v($restore);
|
||||
SQLError($sql,mysql_error());
|
||||
}
|
||||
return $insert;
|
||||
}
|
||||
|
||||
function del_inline_comments($sql)
|
||||
{
|
||||
$sql=str_replace("\n",'<br>',$sql);
|
||||
$array=array();
|
||||
preg_match_all("/(\/\*(.+)\*\/)/U",$sql,$array);
|
||||
if (is_array($array[0]))
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
// extrahiert auf einfache Art den Tabellennamen aus dem "Create",Drop"-Befehl
|
||||
function get_tablename($t)
|
||||
{
|
||||
// alle Schluesselbegriffe entfernen, bis der Tabellenname am Anfang steht
|
||||
$t=substr($t,0,50); // verkuerzen, um Speicher zu sparen - wir brauchenhier nur den Tabellennamen
|
||||
$t=str_ireplace('DROP TABLE','',$t);
|
||||
$t=str_ireplace('DROP VIEW','',$t);
|
||||
$t=str_ireplace('CREATE TABLE','',$t);
|
||||
$t=str_ireplace('INSERT INTO','',$t);
|
||||
$t=str_ireplace('REPLACE INTO','',$t);
|
||||
$t=str_ireplace('IF NOT EXISTS','',$t);
|
||||
$t=str_ireplace('IF EXISTS','',$t);
|
||||
if (substr(strtoupper($t),0,16) == 'CREATE ALGORITHM')
|
||||
{
|
||||
$pos=strpos($sql,'DEFINER VIEW ');
|
||||
$t=substr($t,$pos,strlen($t) - $pos);
|
||||
}
|
||||
$t=str_ireplace(';',' ;',$t); // tricky -> insert space as delimiter
|
||||
$t=trim($t);
|
||||
|
||||
// jetzt einfach nach dem ersten Leerzeichen suchen
|
||||
$delimiter=substr($t,0,1);
|
||||
if ($delimiter != '`') $delimiter=' ';
|
||||
$found=false;
|
||||
$position=1;
|
||||
WHILE (!$found)
|
||||
{
|
||||
if (substr($t,$position,1) == $delimiter) $found=true;
|
||||
if ($position >= strlen($t)) $found=true;
|
||||
$position++;
|
||||
}
|
||||
$t=substr($t,0,$position);
|
||||
$t=trim(str_replace('`','',$t));
|
||||
return $t;
|
||||
}
|
||||
|
||||
// decide if an INSERT-Command is complete - simply count quotes and look for ); at the end of line
|
||||
function SQL_Is_Complete($string)
|
||||
{
|
||||
$string=str_replace('\\\\','',trim($string)); // trim and remove escaped backslashes
|
||||
$quotes=substr_count($string,'\'');
|
||||
$escaped_quotes=substr_count($string,'\\\'');
|
||||
if (( $quotes - $escaped_quotes ) % 2 == 0)
|
||||
{
|
||||
if (substr($string,-2) == ');') return true;
|
||||
if (substr($string,-2) == '),') return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
1543
inc/functions_sql.php
Normale Datei
1543
inc/functions_sql.php
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
27
inc/header.php
Normale Datei
27
inc/header.php
Normale Datei
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
$msd_path=realpath(dirname(__FILE__));
|
||||
$msd_path=str_replace('\\','/',$msd_path);
|
||||
$msd_path=str_replace('/inc','/',$msd_path);
|
||||
if (!defined('MSD_PATH')) define('MSD_PATH',$msd_path);
|
||||
session_name('MySQLDumper');
|
||||
session_start();
|
||||
if (!isset($download))
|
||||
{
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0",false);
|
||||
header("Pragma: no-cache");
|
||||
}
|
||||
include ( MSD_PATH.'inc/functions.php' );
|
||||
include ( MSD_PATH.'inc/mysql.php' );
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
if (!file_exists($config['files']['parameter'])) $error=TestWorkDir();
|
||||
//include ( MSD_PATH . $config['files']['parameter'] );
|
||||
//v($config);
|
||||
read_config($config['config_file']);
|
||||
include ( MSD_PATH.'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/';
|
||||
if (isset($error)) echo $error;
|
||||
470
inc/mysql.php
Normale Datei
470
inc/mysql.php
Normale Datei
|
|
@ -0,0 +1,470 @@
|
|||
<?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',
|
||||
'DESCRIBE',
|
||||
'DESC'
|
||||
);
|
||||
|
||||
function MSD_mysql_connect($encoding='utf8', $keycheck_off=false, $actual_table='')
|
||||
{
|
||||
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();
|
||||
|
||||
if (!isset($config['mysql_standard_character_set']) || $config['mysql_standard_character_set'] == '') get_sql_encodings();
|
||||
|
||||
if ($config['mysql_standard_character_set'] != $encoding)
|
||||
{
|
||||
$set_encoding=@mysql_query('SET NAMES \'' . $encoding . '\'',$config['dbconnection']);
|
||||
if ($set_encoding === false) $config['mysql_can_change_encoding']=false;
|
||||
else $config['mysql_can_change_encoding']=true;
|
||||
}
|
||||
if ($keycheck_off) mysql_query('SET FOREIGN_KEY_CHECKS=0',$config['dbconnection']);
|
||||
return $config['dbconnection'];
|
||||
}
|
||||
|
||||
function GetMySQLVersion()
|
||||
{
|
||||
$res=MSD_query("select version()");
|
||||
$row=mysql_fetch_array($res);
|
||||
$version=$row[0];
|
||||
if (!defined('MSD_MYSQL_VERSION')) define('MSD_MYSQL_VERSION',$version);
|
||||
$versions=explode('.',$version);
|
||||
$new=false;
|
||||
if ($versions[0] == 4 && $versions[1] >= 1) $new=true;
|
||||
if ($versions[0] > 4) $new=true;
|
||||
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();
|
||||
//echo "<br>Query: ".htmlspecialchars($query);
|
||||
$res=mysql_query($query,$config['dbconnection']);
|
||||
if (false===$res) SQLError($query,mysql_error($config['dbconnection']));
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
function SQLError($sql, $error, $return_output=false)
|
||||
{
|
||||
// v(debug_backtrace());
|
||||
global $lang;
|
||||
|
||||
$ret='<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></td></tr>
|
||||
<tr><td style="width:80%;overflow: auto;">' . $lang['sql_error2'] . '<br><span style="color:red;">' . $error . '</span></td></tr>
|
||||
<tr><td width="600"><br>' . $lang['sql_error1'] . '<br>' . Highlight_SQL($sql) . '</td></tr>
|
||||
</table></div>';
|
||||
if ($return_output) return $ret;
|
||||
else echo $ret;
|
||||
}
|
||||
|
||||
function Highlight_SQL($sql)
|
||||
{
|
||||
global $sql_keywords;
|
||||
|
||||
$end='';
|
||||
$tickstart=false;
|
||||
if (function_exists("token_get_all")) $a=@token_get_all("<?$sql?>");
|
||||
else return $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;
|
||||
}
|
||||
|
||||
// reads all Tableinfos and place them in $dump-Array
|
||||
function getDBInfos()
|
||||
{
|
||||
global $databases,$dump,$config,$tbl_sel,$flipped;
|
||||
for ($ii=0; $ii < count($databases['multi']); $ii++)
|
||||
{
|
||||
$dump['dbindex']=$flipped[$databases['multi'][$ii]];
|
||||
$tabellen=mysql_query('SHOW TABLE STATUS FROM `' . $databases['Name'][$dump['dbindex']] . '`',$config['dbconnection']) or die('getDBInfos: ' . mysql_error());
|
||||
$num_tables=mysql_num_rows($tabellen);
|
||||
// Array mit den gewünschten Tabellen zusammenstellen... wenn Präfix angegeben, werden die anderen einfach nicht übernommen
|
||||
if ($num_tables > 0)
|
||||
{
|
||||
for ($i=0; $i < $num_tables; $i++)
|
||||
{
|
||||
$row=mysql_fetch_array($tabellen);
|
||||
if (isset($row['Type'])) $row['Engine']=$row['Type'];
|
||||
if (isset($row['Comment']) && substr(strtoupper($row['Comment']),0,4) == 'VIEW') $dump['table_types'][]='VIEW';
|
||||
else $dump['table_types'][]=strtoupper($row['Engine']);
|
||||
// check if data needs to be backed up
|
||||
if (strtoupper($row['Comment']) == 'VIEW' || ( isset($row['Engine']) && in_array(strtoupper($row['Engine']),array(
|
||||
|
||||
'MEMORY'
|
||||
)) ))
|
||||
{
|
||||
$dump['skip_data'][]=$databases['Name'][$dump['dbindex']] . '|' . $row['Name'];
|
||||
}
|
||||
if ($config['optimize_tables_beforedump'] == 1 && $dump['table_offset'] == -1) mysql_query('OPTIMIZE `' . $row['Name'] . '`');
|
||||
if (isset($tbl_sel))
|
||||
{
|
||||
if (in_array($row['Name'],$dump['tblArray']))
|
||||
{
|
||||
$dump['tables'][]=$databases['Name'][$dump['dbindex']] . '|' . $row['Name'];
|
||||
$dump['records'][]=$databases['Name'][$dump['dbindex']] . '|' . $row['Rows'];
|
||||
$dump['totalrecords']+=$row['Rows'];
|
||||
}
|
||||
}
|
||||
elseif ($databases['praefix'][$dump['dbindex']] != '' && !isset($tbl_sel))
|
||||
{
|
||||
if (substr($row['Name'],0,strlen($databases['praefix'][$dump['dbindex']])) == $databases['praefix'][$dump['dbindex']])
|
||||
{
|
||||
$dump['tables'][]=$databases['Name'][$dump['dbindex']] . '|' . $row['Name'];
|
||||
$dump['records'][]=$databases['Name'][$dump['dbindex']] . '|' . $row['Rows'];
|
||||
$dump['totalrecords']+=$row['Rows'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$dump['tables'][]=$databases['Name'][$dump['dbindex']] . '|' . $row['Name'];
|
||||
$dump['records'][]=$databases['Name'][$dump['dbindex']] . '|' . $row['Rows'];
|
||||
|
||||
// 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']] . "`.`" . $row['Name'] . "`";
|
||||
$res2=@mysql_query($sql_2);
|
||||
if ($res2 === false)
|
||||
{
|
||||
$read_error='(' . mysql_errno() . ') ' . mysql_error();
|
||||
SQLError($read_error,$sql_2);
|
||||
WriteLog($read_error);
|
||||
if ($config['stop_with_error'] > 0)
|
||||
{
|
||||
die($read_error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$row2=@mysql_fetch_array($res2);
|
||||
$row['Rows']=$row2['count_records'];
|
||||
$dump['totalrecords']+=$row['Rows'];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Correct total number of records; substract skipped data
|
||||
foreach ($dump['skip_data'] as $skip_data)
|
||||
{
|
||||
$index=false;
|
||||
$records_to_skip=0;
|
||||
//find index of table to get the nr of records
|
||||
$count=sizeof($dump['tables']);
|
||||
for ($a=0; $a < $count; $a++)
|
||||
{
|
||||
if ($dump['tables'][$a] == $skip_data)
|
||||
{
|
||||
$index=$a;
|
||||
$t=explode('|',$dump['records'][$a]);
|
||||
$rekords_to_skip=$t[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($index) $dump['totalrecords']-=$rekords_to_skip;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// gets the numeric index in dump-array and returns it
|
||||
function getDBIndex($db, $table)
|
||||
{
|
||||
global $dump;
|
||||
$index=array_keys($dump['tables'],$db . '|' . $table);
|
||||
return $index[0];
|
||||
}
|
||||
?>
|
||||
123
inc/runtime.php
Normale Datei
123
inc/runtime.php
Normale Datei
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
//Konstanten
|
||||
if (!defined('MSD_VERSION')) define('MSD_VERSION','1.23 Rev 497');
|
||||
if (!defined('MSD_OS')) define('MSD_OS',PHP_OS);
|
||||
if (!defined('MSD_OS_EXT')) define('MSD_OS_EXT',@php_uname());
|
||||
if (!defined('config') || !is_array($config)) $config=array();
|
||||
if (!defined('databases') || !is_array($databases)) $databases=array();
|
||||
|
||||
//Pfade und Files
|
||||
$config['paths']['root']=Realpfad('./');
|
||||
$config['paths']['work']='work/';
|
||||
$config['paths']['backup']=$config['paths']['work'] . 'backup/';
|
||||
$config['paths']['log']=$config['paths']['work'] . 'log/';
|
||||
$config['paths']['config']=$config['paths']['work'] . 'config/';
|
||||
$config['paths']['perlexec']='msd_cron/';
|
||||
|
||||
if (isset($_SESSION['config_file']))
|
||||
{
|
||||
$config['config_file']=$_SESSION['config_file'];
|
||||
$config['cron_configurationfile']=$_SESSION['config_file'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$config['config_file']='mysqldumper';
|
||||
$_SESSION['config_file']='mysqldumper';
|
||||
$config['cron_configurationfile']='mysqldumper.conf.php';
|
||||
}
|
||||
$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'] . $config['config_file'] . '.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']=get_cfg_var('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']=get_cfg_var('upload_max_filesize');
|
||||
$config['safe_mode']=get_cfg_var('safe_mode');
|
||||
$config['magic_quotes_gpc']=get_cfg_var('magic_quotes_gpc');
|
||||
$config['disabled']=get_cfg_var('disable_functions');
|
||||
$config['phpextensions']=implode(', ',get_loaded_extensions());
|
||||
$m=trim(str_replace('M','',ini_get('memory_limit')));
|
||||
// fallback if ini_get doesn't work
|
||||
if (intval($m) == 0) $m=trim(str_replace('M','',get_cfg_var('memory_limit')));
|
||||
$config['php_ram']=$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 Datensaetze, die in einem Rutsch gelesen werden
|
||||
|
||||
//Bausteine
|
||||
$config['homepage']='http://forum.mysqldumper.de/';
|
||||
$languagepacks_ref='http://forum.mysqldumper.de/downloads.php?cat=9';
|
||||
$stylepacks_ref='http://forum.mysqldumper.de/downloads.php?cat=3';
|
||||
$nl="\n";
|
||||
$mysql_commentstring='--';
|
||||
|
||||
//config-Variablen, die nicht gesichert werden sollen
|
||||
$config_dontsave=Array(
|
||||
|
||||
'homepage',
|
||||
'max_execution_time',
|
||||
'safe_mode',
|
||||
'magic_quotes_gpc',
|
||||
'disabled',
|
||||
'phpextensions',
|
||||
'php_ram',
|
||||
'zlib',
|
||||
'tuning_add',
|
||||
'tuning_sub',
|
||||
'time_buffer',
|
||||
'perlspeed',
|
||||
'cron_configurationfile',
|
||||
'dbconnection',
|
||||
'version',
|
||||
'mysql_possible_character_sets',
|
||||
'mysql_standard_character_set',
|
||||
'config_file',
|
||||
'upload_max_filesize',
|
||||
'mysql_can_change_encoding',
|
||||
);
|
||||
|
||||
// Automatisches entfernen von Slashes und Leerzeichen vorn und hinten abschneiden
|
||||
if (get_magic_quotes_gpc()) $_POST=stripslashes_deep($_POST);
|
||||
$_POST=trim_deep($_POST);
|
||||
if (get_magic_quotes_gpc()) $_GET=stripslashes_deep($_GET);
|
||||
$_GET=trim_deep($_GET);
|
||||
|
||||
function v($t)
|
||||
{
|
||||
echo '<br>';
|
||||
if (is_array($t) || is_object($t))
|
||||
{
|
||||
echo '<pre>';
|
||||
print_r($t);
|
||||
echo '</pre>';
|
||||
}
|
||||
else
|
||||
echo $t;
|
||||
}
|
||||
|
||||
function getServerProtocol()
|
||||
{
|
||||
return ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
|
||||
}
|
||||
|
||||
?>
|
||||
293
inc/sql_importexport.php
Normale Datei
293
inc/sql_importexport.php
Normale Datei
|
|
@ -0,0 +1,293 @@
|
|||
<?php
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
//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> ' . 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 . '&dbid=' . $dbid . '&context=4&import=1" method="post" enctype="multipart/form-data">' . $nl;
|
||||
$impaus.='';
|
||||
$impaus.='<a href="sql.php?db=' . $db . '&dbid=' . $dbid . '&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_namefirstline0" 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'] . ':
|
||||
<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> </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" type="text/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);
|
||||
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 . '&dbid=' . $dbid . '&context=4" method="post">' . $nl;
|
||||
$exaus.='<a href="sql.php?db=' . $db . '&dbid=' . $dbid . '&context=4&import=1">' . $lang['import'] . '</a>';
|
||||
$exaus.='<h6>' . sprintf($lang['sql_export'],$databases['Name'][$dbid]) . '</h6>';
|
||||
$exaus.='<table class="bdr"><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.=' <a class="ssmall" href="#" onclick="SelectTableList(true);">' . $lang['all'] . '</a> <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" . ' ' . $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" . ' ' . $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" . ' ' . $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="' . $icon['blank'] . '" 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" type="text/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> ' . sprintf($lang['exportlines'],$sql['export']['lines']) . $nl;
|
||||
}
|
||||
else
|
||||
{
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
85
inc/sql_sqlstrings.php
Normale Datei
85
inc/sql_sqlstrings.php
Normale Datei
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
//SQL-Strings
|
||||
echo $aus.='<h4>' . $lang['sql_befehle'] . ' (' . count($SQL_ARRAY) . ')</h4>';
|
||||
echo '<a href="' . $params . '&sqlconfig=1&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="bdr"><tr class="thead"><th>#</th><th>' . $lang['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>';
|
||||
?>
|
||||
176
inc/sql_tools.php
Normale Datei
176
inc/sql_tools.php
Normale Datei
|
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
get_sql_encodings();
|
||||
|
||||
//Datenbanken
|
||||
if (isset($_GET['dbrefresh'])) SetDefault();
|
||||
|
||||
echo $aus . "<h4>Tools</h4>";
|
||||
if (isset($_POST['dbdosubmit']))
|
||||
{
|
||||
$newname=$_POST['newname'];
|
||||
$db_index=$_POST['db_index'];
|
||||
echo "<br>Db-Index:" . $_GET['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" type="text/javascript">parent.MySQL_Dumper_menu.location.href="menu.php?action=dbrefresh";</script>';
|
||||
|
||||
}
|
||||
}
|
||||
if (isset($_POST['dbwantaction']))
|
||||
{
|
||||
if (isset($_POST['db_createnew']))
|
||||
{
|
||||
$newname=trim($_POST['db_create']);
|
||||
if (!empty($newname))
|
||||
{
|
||||
$sqlc="CREATE DATABASE `$newname`";
|
||||
$col=( MSD_NEW_VERSION ) ? $_POST['db_collate'] : "";
|
||||
if (isset($_POST['db_default_charset']) && intval(substr(MSD_NEW_VERSION,0,1)) > 3)
|
||||
{
|
||||
$db_default_charset_string=$config['mysql_possible_character_sets'][$_POST['db_default_charset']];
|
||||
$db_default_charset=explode(' ',$db_default_charset_string);
|
||||
if (isset($db_default_charset[0])) $sqlc.=' DEFAULT CHARACTER SET `' . $db_default_charset[0] . '`';
|
||||
}
|
||||
$db_default_collation=@explode('|',$col);
|
||||
if (isset($db_default_collation[1])) $sqlc.=' COLLATE `' . $db_default_collation[1] . '`';
|
||||
|
||||
MSD_query($sqlc);
|
||||
echo $lang['db'] . " `$newname` " . $lang['sql_wascreated'] . ".<br>";
|
||||
SetDefault();
|
||||
include ( $config['files']['parameter'] );
|
||||
echo '<script language="JavaScript" type="text/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><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="Formbutton">';
|
||||
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="Formbutton">';
|
||||
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="Formbutton">';
|
||||
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="Formbutton">';
|
||||
}
|
||||
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="Formbutton">';
|
||||
}
|
||||
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><table class="bdr">';
|
||||
echo '<tr><td colspan="2" align="center"><strong>' . $lang['create_database'] . '</strong></td></tr>';
|
||||
echo '<tr><td>Name:</td><td><input type="text" class="text" name="db_create" size="20"></td></tr>';
|
||||
|
||||
echo '<tr><td>' . $lang['default_charset'] . ':</td><td><select name="db_default_charset">';
|
||||
echo make_options($config['mysql_possible_character_sets'],get_index($config['mysql_possible_character_sets'],$config['mysql_standard_character_set']));
|
||||
echo '</select></td></tr>';
|
||||
|
||||
echo '<tr><td>' . $lang['collation'] . '</td><td><select name="db_collate">' . CollationCombo('',1) . '</select></td></tr>';
|
||||
echo '<tr><td colspan="2"><input type="submit" name="db_createnew" value="' . $lang['create'] . '" class="Formbutton"></td></tr>';
|
||||
echo '</table>';
|
||||
|
||||
echo '<br><table class="bdr">';
|
||||
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] . '&dbid=' . $i . '">' . $databases['Name'][$i] . '</a></td>';
|
||||
echo '<td nowrap="nowrap"><input type="text" class="text" name="db_rename' . $i . '" size="20">';
|
||||
echo ' <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" . ' <input type="submit" name="db_do_' . $i . '" value="' . $lang['do'] . '" disabled="disabled" class="Formbutton">';
|
||||
|
||||
echo ' <input type="Button" value="' . $lang['sql_imexport'] . '" onclick="location.href=\'sql.php?db=' . $databases['Name'][$i] . '&dbid=' . $i . '&context=4\'" class="Formbutton"></td></tr>';
|
||||
}
|
||||
|
||||
echo '</table></div></form>';
|
||||
|
||||
|
||||
53
inc/sqllib.php
Normale Datei
53
inc/sqllib.php
Normale Datei
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
//SQL-Library
|
||||
include ( './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++;
|
||||
|
||||
?>
|
||||
169
inc/tabellenabfrage.php
Normale Datei
169
inc/tabellenabfrage.php
Normale Datei
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
include ( './language/' . $config['language'] . '/lang.php' );
|
||||
include ( './language/' . $config['language'] . '/lang_dump.php' );
|
||||
include ( './inc/template.php' );
|
||||
$tblr=( $tblfrage_refer == 'dump' ) ? 'Backup' : 'Restore';
|
||||
$filename=( isset($_GET['filename']) ) ? $_GET['filename'] : '';
|
||||
if (isset($_POST['file'][0])) $filename=$_POST['file'][0];
|
||||
|
||||
ob_start();
|
||||
$tpl=new MSDTemplate();
|
||||
$sel_dump_encoding=isset($_POST['sel_dump_encoding']) ? $_POST['sel_dump_encoding'] : '';
|
||||
$tpl=new MSDtemplate();
|
||||
|
||||
//Informationen zusammenstellen
|
||||
if ($tblr == 'Backup')
|
||||
{
|
||||
$tpl->set_filenames(array(
|
||||
'show' => './tpl/dump_select_tables.tpl'
|
||||
));
|
||||
$button_name='dump_tbl';
|
||||
//Info aus der Datenbank lesen
|
||||
MSD_mysql_connect();
|
||||
$res=mysql_query('SHOW TABLE STATUS FROM `' . $databases['db_actual'] . '`');
|
||||
$numrows=mysql_num_rows($res);
|
||||
$tbl_zeile='';
|
||||
for ($i=0; $i < $numrows; $i++)
|
||||
{
|
||||
$row=mysql_fetch_array($res,MYSQL_ASSOC);
|
||||
//v($row);
|
||||
// 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);
|
||||
if ($res2 === false)
|
||||
{
|
||||
$read_error='(' . mysql_errno() . ') ' . mysql_error();
|
||||
$row['Rows']='<span class="error">' . $lang['error'] . ': ' . $read_error . '</span>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$row2=@mysql_fetch_array($res2);
|
||||
$row['Rows']=$row2['count_records'];
|
||||
}
|
||||
|
||||
$klasse=( $i % 2 ) ? 1 : '';
|
||||
$table_size=$row['Data_length'] + $row['Index_length'];
|
||||
$table_type=$row['Engine'];
|
||||
if (substr($row['Comment'],0,4) == 'VIEW')
|
||||
{
|
||||
$table_type='View';
|
||||
$table_size='-';
|
||||
}
|
||||
$tpl->assign_block_vars('ROW',array(
|
||||
|
||||
'CLASS' => 'dbrow' . $klasse,
|
||||
'ID' => $i,
|
||||
'NR' => $i + 1,
|
||||
'TABLENAME' => $row['Name'],
|
||||
'TABLETYPE' => $table_type,
|
||||
'RECORDS' => $table_type == 'View' ? '<i>' . $row['Rows'] . '</i>' : '<strong>' . $row['Rows'] . '</strong>',
|
||||
'SIZE' => is_int($table_size) ? byte_output($table_size) : $table_size,
|
||||
'LAST_UPDATE' => $row['Update_time']
|
||||
));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$tpl->set_filenames(array(
|
||||
|
||||
'show' => './tpl/restore_select_tables.tpl'
|
||||
));
|
||||
//Restore - Header aus Backupfile lesen
|
||||
$button_name='restore_tbl';
|
||||
$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['tables'];
|
||||
$anzahl_eintraege=$sline['records'];
|
||||
$tbl_zeile='';
|
||||
$part=( $sline['part'] == '' ) ? 0 : substr($sline['part'],3);
|
||||
if ($anzahl_eintraege == -1)
|
||||
{
|
||||
// not a backup of MySQLDumper
|
||||
$tpl->assign_block_vars('NO_MSD_BACKUP',array());
|
||||
}
|
||||
else
|
||||
{
|
||||
$tabledata=array();
|
||||
$i=0;
|
||||
//Tabellenfinos lesen
|
||||
gzseek($fp,$offset);
|
||||
$eof=false;
|
||||
WHILE (!$eof)
|
||||
{
|
||||
$line=$gz ? gzgets($fp,40960) : fgets($fp,40960);
|
||||
|
||||
if (substr($line,0,9) == '-- TABLE|')
|
||||
{
|
||||
$d=explode('|',$line);
|
||||
$tabledata[$i]['name']=$d[1];
|
||||
$tabledata[$i]['records']=$d[2];
|
||||
$tabledata[$i]['size']=$d[3];
|
||||
$tabledata[$i]['update']=$d[4];
|
||||
$tabledata[$i]['engine']=isset($d[5]) ? $d[5]:'';
|
||||
$i++;
|
||||
}
|
||||
if (substr($line,0,6) == '-- EOF') $eof=true;
|
||||
if (substr(strtolower($line),0,6) == 'create') $eof=true;
|
||||
}
|
||||
for ($i=0; $i < sizeof($tabledata); $i++)
|
||||
{
|
||||
$klasse=( $i % 2 ) ? 1 : '';
|
||||
$tpl->assign_block_vars('ROW',array(
|
||||
|
||||
'CLASS' => 'dbrow' . $klasse,
|
||||
'ID' => $i,
|
||||
'NR' => $i + 1,
|
||||
'TABLENAME' => $tabledata[$i]['name'],
|
||||
'RECORDS' => $tabledata[$i]['records'],
|
||||
'SIZE' => byte_output($tabledata[$i]['size']),
|
||||
'LAST_UPDATE' => $tabledata[$i]['update'],
|
||||
'TABLETYPE' => $tabledata[$i]['engine']
|
||||
));
|
||||
}
|
||||
}
|
||||
if ($gz) gzclose($fp);
|
||||
else fclose($fp);
|
||||
}
|
||||
|
||||
if (!isset($dk)) $dk='';
|
||||
|
||||
$tpl->assign_vars(array(
|
||||
|
||||
'PAGETITLE' => $tblr . ' -' . $lang['tableselection'],
|
||||
'L_NAME' => $lang['name'],
|
||||
'L_DATABASE' => $lang['db'],
|
||||
'DATABASE' => $databases['db_actual'],
|
||||
'L_LAST_UPDATE' => $lang['lastbufrom'],
|
||||
'SEL_DUMP_ENCODING' => $sel_dump_encoding,
|
||||
'FILENAME' => $filename,
|
||||
'DUMP_COMMENT' => $dk,
|
||||
'BUTTON_NAME' => $button_name,
|
||||
'L_START_BACKUP' => $lang['startdump'],
|
||||
'L_START_RESTORE' => $lang['fm_restore'],
|
||||
'L_ROWS' => $lang['info_records'],
|
||||
'L_SIZE' => $lang['info_size'],
|
||||
'L_TABLE_TYPE' => $lang['table_type'],
|
||||
'L_SELECT_ALL' => $lang['selectall'],
|
||||
'L_DESELECT_ALL' => $lang['deselectall'],
|
||||
'L_RESTORE' => $lang['restore'],
|
||||
'L_NO_MSD_BACKUP' => $lang['not_supported']
|
||||
));
|
||||
|
||||
$tpl->pparse('show');
|
||||
ob_end_flush();
|
||||
?>
|
||||
477
inc/template.php
Normale Datei
477
inc/template.php
Normale Datei
|
|
@ -0,0 +1,477 @@
|
|||
<?php
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
/***************************************************************************
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Laden …
Tabelle hinzufügen
Einen Link hinzufügen
In neuem Issue referenzieren