diff --git a/filemanagement.php b/filemanagement.php index 4de2348..33f0f3d 100644 --- a/filemanagement.php +++ b/filemanagement.php @@ -307,8 +307,8 @@ switch ($action) $scriptdir=$config['cron_execution_path'].'crondump.'.$cext; $sfile=$config['cron_execution_path']."perltest.$cext"; $simplefile=$config['cron_execution_path']."simpletest.$cext"; - $scriptentry=Realpfad("./").$config['paths']['config']; - $cronabsolute=(substr($config['cron_execution_path'],0,1)=="/") ? $_SERVER['DOCUMENT_ROOT'].$scriptdir : Realpfad("./").$scriptdir; + $scriptentry=basePath(). $config['paths']['config']; + $cronabsolute=(substr($config['cron_execution_path'],0,1)=="/") ? $_SERVER['DOCUMENT_ROOT'].$scriptdir : basePath().$scriptdir; $confabsolute=$config['config_file']; $scriptref=getServerProtocol().$_SERVER['SERVER_NAME'].$refdir.$config['cron_execution_path'].'crondump.'.$cext."?config=".$confabsolute; $cronref="perl ".$cronabsolute." -config=".$confabsolute." -html_output=0"; diff --git a/inc/functions.php b/inc/functions.php index ab34125..099ccef 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -249,7 +249,7 @@ function WriteParams($as = 0, $restore_values = false) $config['cron_execution_path'] = "msd_cron/"; } if ($as == 0) { - $config['paths']['root'] = addslashes(Realpfad("./")); + $config['paths']['root'] = addslashes(basePath()); } $config['files']['parameter'] = $config['paths']['config'] . $config['config_file'] . '.php'; $config['files']['iconpath'] = './css/' . $config['theme'] . '/icons/'; diff --git a/inc/functions_global.php b/inc/functions_global.php index f35ae3e..136da46 100644 --- a/inc/functions_global.php +++ b/inc/functions_global.php @@ -1,884 +1,939 @@ '."\n"; - foreach ($parameter as $key=>$val) - { - if (is_array($val)) - { - foreach ($val as $key2=>$val2) - { - $page_parameter.=''."\n"; - } - } - else - $page_parameter.=''."\n"; - } - $page_parameter.=''; - return $page_parameter; + $page_parameter = '
' . "\n"; + foreach ($parameter as $key => $val) { + if (is_array($val)) { + foreach ($val as $key2 => $val2) { + $page_parameter .= '' + . "\n"; + } + } else { + $page_parameter .= '' . "\n"; + } + } + $page_parameter .= '
'; + + return $page_parameter; } function mu_sort($array, $key_sort) { - $key_sorta=explode(',',$key_sort); - $keys=array_keys($array[0]); - $n=0; + $key_sorta = explode(',', $key_sort); + $keys = array_keys($array[0]); + $n = 0; - for ($m=0; $m oder rsort=absteigend - return $output; + for ($i = 0; $i < count($keys); $i++) { + if (!in_array($keys[$i], $key_sorta)) { + $nkeys[$n] = $keys[$i]; + $n += "1"; + } + } + for ($u = 0; $u < count($array); $u++) { + $arr = $array[$u]; + for ($s = 0; $s < count($nkeys); $s++) { + $k = $nkeys[$s]; + if (isset($array[$u][$k])) { + $output[$u][$k] = $array[$u][$k]; + } + } + } + // wenn die Sortierung nicht ab- sondern aufsteigend sein soll, muss sort() benutzt werden + sort($output); // Sort=Aufsteigend -> oder rsort=absteigend + return $output; } function FillMultiDBArrays() { - global $config,$databases; + global $config, $databases; - // Nur füllen wenn überhaupt Datenbanken gefunden wurden - if ((isset($databases['Name']))&&(count($databases['Name'])>0)) - { - $databases['multi']=Array(); - $databases['multi_praefix']=Array(); - if (!isset($databases['db_selected_index'])) $databases['db_selected_index']=0; - if (!isset($databases['db_actual'])&&isset($databases['Name'])) $databases['db_actual']=$databases['Name'][$databases['db_selected_index']]; - if (!isset($databases['multisetting'])) $databases['multisetting']=''; + // Nur füllen wenn überhaupt Datenbanken gefunden wurden + if ((isset($databases['Name'])) && (count($databases['Name']) > 0)) { + $databases['multi'] = Array(); + $databases['multi_praefix'] = Array(); + if (!isset($databases['db_selected_index'])) { + $databases['db_selected_index'] = 0; + } + if (!isset($databases['db_actual']) && isset($databases['Name'])) { + $databases['db_actual'] = $databases['Name'][$databases['db_selected_index']]; + } + if (!isset($databases['multisetting'])) { + $databases['multisetting'] = ''; + } - // if($config['multi_dump']==1) - // { - if ($databases['multisetting']=='') - { - //$databases['multi'][0]=$databases['db_actual']; - //$databases['multi_praefix'][0]=(isset($databases['praefix'][0])) ? $databases['praefix'][0] : ''; - } - else - { - $databases['multi']=explode(';',$databases['multisetting']); - $flipped=array_flip($databases['Name']); - for ($i=0; $i0) - { - $s1=$s2=0; - while ($row= mysqli_fetch_array($res, MYSQLI_ASSOC)) - { - $s1+=$row['Rows']; - $s2+=$row['Data_length']+$row['Index_length']; - } - $databases['Detailinfo']['records']=$s1; - $databases['Detailinfo']['size']=$s2; - } - } + $databases['Detailinfo']['tables'] = $databases['Detailinfo']['records'] = $databases['Detailinfo']['size'] = 0; + MSD_mysql_connect(); + if (isset($databases['Name'][$index])) { + ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $databases['Name'][$index])); + $databases['Detailinfo']['Name'] = $databases['Name'][$index]; + $res = @mysqli_query( + $GLOBALS["___mysqli_ston"], + 'SHOW TABLE STATUS FROM `' . $databases['Name'][$index] . '`' + ); + if ($res) { + $databases['Detailinfo']['tables'] = mysqli_num_rows($res); + } + if ($databases['Detailinfo']['tables'] > 0) { + $s1 = $s2 = 0; + while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) { + $s1 += $row['Rows']; + $s2 += $row['Data_length'] + $row['Index_length']; + } + $databases['Detailinfo']['records'] = $s1; + $databases['Detailinfo']['size'] = $s2; + } + } } function Stringformat($s, $count) { - if ($count>=strlen($s)) return str_repeat("0",$count-strlen($s)).$s; - else - return $s; + if ($count >= strlen($s)) { + return str_repeat("0", $count - strlen($s)) . $s; + } else { + return $s; + } } function getmicrotime() { - list ($usec, $sec)=explode(" ",microtime()); - return ((float) $usec+(float) $sec); + list ($usec, $sec) = explode(" ", microtime()); + + return ((float)$usec + (float)$sec); } function MD_FreeDiskSpace() { - global $lang; - $dfs=@diskfreespace("../"); - return ($dfs) ? byte_output($dfs) : $lang['L_NOTAVAIL']; + global $lang; + $dfs = @diskfreespace("../"); + + return ($dfs) ? byte_output($dfs) : $lang['L_NOTAVAIL']; } function WriteDynamicText($txt, $object) { - return ''; + return ''; } -function byte_output($bytes, $precision=2, $names=Array()) +function byte_output($bytes, $precision = 2, $names = Array()) { - if (!is_numeric($bytes)||$bytes<0) - { - return false; - } - for ($level=0; $bytes>=1024; $level++) - { - $bytes/=1024; - } - switch ($level) - { - case 0: - $suffix=(isset($names[0])) ? $names[0] : 'B'; - break; - case 1: - $suffix=(isset($names[1])) ? $names[1] : 'KB'; - break; - case 2: - $suffix=(isset($names[2])) ? $names[2] : 'MB'; - break; - case 3: - $suffix=(isset($names[3])) ? $names[3] : 'GB'; - break; - case 4: - $suffix=(isset($names[4])) ? $names[4] : 'TB'; - break; - case 5: - $suffix=(isset($names[4])) ? $names[4] : 'PB'; - break; - case 6: - $suffix=(isset($names[4])) ? $names[4] : 'EB'; - break; - case 7: - $suffix=(isset($names[4])) ? $names[4] : 'ZB'; - break; + if (!is_numeric($bytes) || $bytes < 0) { + return false; + } + for ($level = 0; $bytes >= 1024; $level++) { + $bytes /= 1024; + } + switch ($level) { + case 0: + $suffix = (isset($names[0])) ? $names[0] : 'B'; + break; + case 1: + $suffix = (isset($names[1])) ? $names[1] : 'KB'; + break; + case 2: + $suffix = (isset($names[2])) ? $names[2] : 'MB'; + break; + case 3: + $suffix = (isset($names[3])) ? $names[3] : 'GB'; + break; + case 4: + $suffix = (isset($names[4])) ? $names[4] : 'TB'; + break; + case 5: + $suffix = (isset($names[4])) ? $names[4] : 'PB'; + break; + case 6: + $suffix = (isset($names[4])) ? $names[4] : 'EB'; + break; + case 7: + $suffix = (isset($names[4])) ? $names[4] : 'ZB'; + break; - default: - $suffix=(isset($names[$level])) ? $names[$level] : ''; - break; - } - return sprintf("%01.".$precision."f",round($bytes,$precision)).' '.$suffix; + default: + $suffix = (isset($names[$level])) ? $names[$level] : ''; + break; + } + + return sprintf("%01." . $precision . "f", round($bytes, $precision)) . ' ' . $suffix; } function ExtractDBname($s) { - $sp=explode('_',$s); - $anz=count($sp)-1; - $r=0; - if ($anz>4) - { - $df=5; //Datumsfelder - if ($sp[$anz-1]=='part') $df+=2; - if ($sp[$anz-3]=='crondump'||$sp[$anz-1]=='crondump') $df+=2; - $anz=$anz-$df; //Datum weg - for ($i=0; $i<=$anz; $i++) - { - $r+=strlen($sp[$i])+1; - } - return substr($s,0,$r-1); - } - else - { - //Fremdformat - return substr($s,0,strpos($s,'.')); - } + $sp = explode('_', $s); + $anz = count($sp) - 1; + $r = 0; + if ($anz > 4) { + $df = 5; //Datumsfelder + if ($sp[$anz - 1] == 'part') { + $df += 2; + } + if ($sp[$anz - 3] == 'crondump' || $sp[$anz - 1] == 'crondump') { + $df += 2; + } + $anz = $anz - $df; //Datum weg + for ($i = 0; $i <= $anz; $i++) { + $r += strlen($sp[$i]) + 1; + } + + return substr($s, 0, $r - 1); + } else { + //Fremdformat + return substr($s, 0, strpos($s, '.')); + } } function ExtractBUT($s) { - $i=strpos(strtolower($s),"part"); - if ($i>0) $s=substr($s,0,$i-1); - $i=strpos(strtolower($s),"crondump"); - if ($i>0) $s=substr($s,0,$i-1); - $i=strpos(strtolower($s),".sql"); - if ($i>0) $s=substr($s,0,$i); - $sp=explode("_",$s); + $i = strpos(strtolower($s), "part"); + if ($i > 0) { + $s = substr($s, 0, $i - 1); + } + $i = strpos(strtolower($s), "crondump"); + if ($i > 0) { + $s = substr($s, 0, $i - 1); + } + $i = strpos(strtolower($s), ".sql"); + if ($i > 0) { + $s = substr($s, 0, $i); + } + $sp = explode("_", $s); - $anz=count($sp)-1; - if (strtolower($sp[$anz])=='perl') $anz--; - if ($anz>4) - { - return $sp[$anz-2].".".$sp[$anz-3].".".$sp[$anz-4]." ".$sp[$anz-1].":".$sp[$anz]; - } - else - { - //Fremdformat - return ""; - } + $anz = count($sp) - 1; + if (strtolower($sp[$anz]) == 'perl') { + $anz--; + } + if ($anz > 4) { + return $sp[$anz - 2] . "." . $sp[$anz - 3] . "." . $sp[$anz - 4] . " " . $sp[$anz - 1] . ":" . $sp[$anz]; + } else { + //Fremdformat + return ""; + } } function WriteLog($aktion) { - global $config,$lang; - $log=date('d.m.Y H:i:s').' '.htmlspecialchars($aktion)."\n"; + global $config, $lang; + $log = date('d.m.Y H:i:s') . ' ' . htmlspecialchars($aktion) . "\n"; - $logfile=($config['logcompression']==1) ? $config['files']['log'].'.gz' : $config['files']['log']; - if (@filesize($logfile)+strlen($log)>$config['log_maxsize']) @unlink($logfile); + $logfile = ($config['logcompression'] == 1) ? $config['files']['log'] . '.gz' : $config['files']['log']; + if (@filesize($logfile) + strlen($log) > $config['log_maxsize']) { + @unlink($logfile); + } - //Datei öffnen und schreiben - if ($config['logcompression']==1) - { + //Datei öffnen und schreiben + if ($config['logcompression'] == 1) { - $fp=@gzopen($logfile,'a'); - if ($fp) - { - @gzwrite($fp,$log).'
'; - @gzclose($fp); - } - else - echo '

'.$lang['L_LOGFILENOTWRITABLE'].' ('.$logfile.')

'; - } - else - { - $fp=@fopen($logfile,"ab"); - if ($fp) - { - @fwrite($fp,$log); - @fclose($fp); - } - else - echo '

'.$lang['L_LOGFILENOTWRITABLE'].' ('.$logfile.')

'; - } + $fp = @gzopen($logfile, 'a'); + if ($fp) { + @gzwrite($fp, $log) . '
'; + @gzclose($fp); + } else { + echo '

' . $lang['L_LOGFILENOTWRITABLE'] . ' (' . $logfile . ')

'; + } + } else { + $fp = @fopen($logfile, "ab"); + if ($fp) { + @fwrite($fp, $log); + @fclose($fp); + } else { + echo '

' . $lang['L_LOGFILENOTWRITABLE'] . ' (' . $logfile . ')

'; + } + } } -function ErrorLog($dest, $db, $sql, $error, $art=1) +function ErrorLog($dest, $db, $sql, $error, $art = 1) { - //$art=0 -> Fehlermeldung - //$art=1 -> Hinweis + //$art=0 -> Fehlermeldung + //$art=1 -> Hinweis - global $config; - if (strlen($sql)>100) $sql=substr($sql,0,100)." ... (snip)"; - //Error-Zeile generieren - $errormsg=date('d.m.Y H:i:s').': '; - $errormsg.=($dest=='RESTORE') ? ' Restore of db `'.$db.'`|:|' : ' Dump of db `'.$db.'`|:|'; + global $config; + if (strlen($sql) > 100) { + $sql = substr($sql, 0, 100) . " ... (snip)"; + } + //Error-Zeile generieren + $errormsg = date('d.m.Y H:i:s') . ': '; + $errormsg .= ($dest == 'RESTORE') ? ' Restore of db `' . $db . '`|:|' : ' Dump of db `' . $db . '`|:|'; - if ($art==0) - { - $errormsg.='Error-Message: '.$error.'|:|'; - } - else - { - $errormsg.='Notice: '.$error.'|:|'; - } + if ($art == 0) { + $errormsg .= 'Error-Message: ' . $error . '|:|'; + } else { + $errormsg .= 'Notice: ' . $error . '|:|'; + } - if ($sql>'') $errormsg.='SQL: '.$sql."\n"; + if ($sql > '') { + $errormsg .= 'SQL: ' . $sql . "\n"; + } - //Datei öffnen und schreiben - if ($config['logcompression']==1) - { - $fp=@gzopen($config['paths']['log'].'error.log.gz','ab'); - if ($fp) - { - @gzwrite($fp,($errormsg)); - @gzclose($fp); - } - } - else - { - $fp=@fopen($config['paths']['log'].'error.log','ab'); - if ($fp) - { - @fwrite($fp,($errormsg)); - @fclose($fp); - } - } + //Datei öffnen und schreiben + if ($config['logcompression'] == 1) { + $fp = @gzopen($config['paths']['log'] . 'error.log.gz', 'ab'); + if ($fp) { + @gzwrite($fp, ($errormsg)); + @gzclose($fp); + } + } else { + $fp = @fopen($config['paths']['log'] . 'error.log', 'ab'); + if ($fp) { + @fwrite($fp, ($errormsg)); + @fclose($fp); + } + } } -function DirectoryWarnings($path="") +function DirectoryWarnings($path = "") { - global $config,$lang; - $warn=''; - if (!is_writable($config['paths']['work'])) $warn.=sprintf($lang['L_WRONG_RIGHTS'],$config['paths']['work'],'0777'); - if (!is_writable($config['paths']['config'])) $warn.=sprintf($lang['L_WRONG_RIGHTS'],$config['paths']['config'],'0777'); - if (!is_writable($config['paths']['backup'])) $warn.=sprintf($lang['L_WRONG_RIGHTS'],$config['paths']['backup'],'0777'); - if (!is_writable($config['paths']['log'])) $warn.=sprintf($lang['L_WRONG_RIGHTS'],$config['paths']['log'],'0777'); + global $config, $lang; + $warn = ''; + if (!is_writable($config['paths']['work'])) { + $warn .= sprintf($lang['L_WRONG_RIGHTS'], $config['paths']['work'], '0777'); + } + if (!is_writable($config['paths']['config'])) { + $warn .= sprintf($lang['L_WRONG_RIGHTS'], $config['paths']['config'], '0777'); + } + if (!is_writable($config['paths']['backup'])) { + $warn .= sprintf($lang['L_WRONG_RIGHTS'], $config['paths']['backup'], '0777'); + } + if (!is_writable($config['paths']['log'])) { + $warn .= sprintf($lang['L_WRONG_RIGHTS'], $config['paths']['log'], '0777'); + } - if ($warn!='') $warn=''.$warn.''; - return $warn; + if ($warn != '') { + $warn = '' . $warn . ''; + } + + return $warn; } function TestWorkDir() { - global $config; + global $config; - $ret=SetFileRechte($config['paths']['work']); - if ($ret===true) $ret=SetFileRechte($config['paths']['backup']); - if ($ret===true) $ret=SetFileRechte($config['paths']['log']); - if ($ret===true) $ret=SetFileRechte($config['paths']['config']); + $ret = SetFileRechte($config['paths']['work']); + if ($ret === true) { + $ret = SetFileRechte($config['paths']['backup']); + } + if ($ret === true) { + $ret = SetFileRechte($config['paths']['log']); + } + if ($ret === true) { + $ret = SetFileRechte($config['paths']['config']); + } - if ($ret===true) - { - if (!file_exists($config['files']['parameter'])) SetDefault(true); - if (!file_exists($config['files']['log'])) DeleteLog(); - } - return $ret; + if ($ret === true) { + if (!file_exists($config['files']['parameter'])) { + SetDefault(true); + } + if (!file_exists($config['files']['log'])) { + DeleteLog(); + } + } + + return $ret; } -function SetFileRechte($file, $is_dir=1, $perm=0777) +function SetFileRechte($file, $is_dir = 1, $perm = 0777) { - global $lang; - $ret=true; - if ($is_dir==1) - { - if (substr($file,-1)!="/") $file.="/"; - } - clearstatcache(); + global $lang; + $ret = true; + if ($is_dir == 1) { + if (substr($file, -1) != "/") { + $file .= "/"; + } + } + clearstatcache(); - // erst pruefen, ob Datei oder Verzeichnis existiert - if (!file_exists($file)) - { - // Wenn es sich um ein Verzeichnis handelt -> anlegen - if ($is_dir==1) - { - $ret=@mkdir($file,$perm); - if (!$ret===true) - { - // Hat nicht geklappt -> Rueckmeldung - $ret=sprintf($lang['L_CANT_CREATE_DIR'],$file); - } - } - } + // erst pruefen, ob Datei oder Verzeichnis existiert + if (!file_exists($file)) { + // Wenn es sich um ein Verzeichnis handelt -> anlegen + if ($is_dir == 1) { + $ret = @mkdir($file, $perm); + if (!$ret === true) { + // Hat nicht geklappt -> Rueckmeldung + $ret = sprintf($lang['L_CANT_CREATE_DIR'], $file); + } + } + } - // wenn bisher alles ok ist -> Rechte setzen - egal ob Datei oder Verzeichnis - if ($ret===true) - { - $ret=@chmod($file,$perm); - if (!$ret===true) $ret=sprintf($lang['L_WRONG_RIGHTS'],$file,decoct($perm)); - } - return $ret; + // wenn bisher alles ok ist -> Rechte setzen - egal ob Datei oder Verzeichnis + if ($ret === true) { + $ret = @chmod($file, $perm); + if (!$ret === true) { + $ret = sprintf($lang['L_WRONG_RIGHTS'], $file, decoct($perm)); + } + } + + return $ret; } function SelectDB($index) { - global $databases; - if (is_string($index)) { - // name given - $dbNames = array_flip($databases['Name']); - if (array_key_exists($index, $dbNames)) { - $index = $dbNames[$index]; - } - } - if (isset($databases['Name'][$index])) - { - $databases['db_actual']=$databases['Name'][$index]; - if (isset($databases['praefix'][$index])) $databases['praefix'][$databases['db_selected_index']]=$databases['praefix'][$index]; - else - $databases['praefix'][$databases['db_selected_index']]=''; - if (isset($databases['db_selected_index'])) $databases['db_selected_index']=$index; - else - $databases['db_selected_index']=0; - } - else - { - // keine DB vorhanden - $databases['praefix'][$databases['db_selected_index']]=''; - $databases['db_selected_index']=0; - $databases['db_actual']=''; - } + global $databases; + if (is_string($index)) { + // name given + $dbNames = array_flip($databases['Name']); + if (array_key_exists($index, $dbNames)) { + $index = $dbNames[$index]; + } + } + if (isset($databases['Name'][$index])) { + $databases['db_actual'] = $databases['Name'][$index]; + if (isset($databases['praefix'][$index])) { + $databases['praefix'][$databases['db_selected_index']] = $databases['praefix'][$index]; + } else { + $databases['praefix'][$databases['db_selected_index']] = ''; + } + if (isset($databases['db_selected_index'])) { + $databases['db_selected_index'] = $index; + } else { + $databases['db_selected_index'] = 0; + } + } else { + // keine DB vorhanden + $databases['praefix'][$databases['db_selected_index']] = ''; + $databases['db_selected_index'] = 0; + $databases['db_actual'] = ''; + } } function EmptyDB($dbn) { - global $config; - $t_sql=array(); - @mysqli_query($GLOBALS["___mysqli_ston"], 'SET FOREIGN_KEY_CHECKS=0'); - $res=mysqli_query($config['dbconnection'], 'SHOW TABLE STATUS FROM `'.$dbn.'`') or die('EmptyDB: '.((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))); - WHILE ($row=mysqli_fetch_array($res, MYSQLI_ASSOC)) - { - if (substr(strtoupper($row['Comment']),0,4)=='VIEW') - { - $t_sql[]='DROP VIEW `'.$dbn.'`.`'.$row['Name'].'`'; - } - else - { - $t_sql[]='DROP TABLE `'.$dbn.'`.`'.$row['Name'].'`'; - } - } - if (sizeof($t_sql)>0) - { - for ($i=0; $i 0) { + for ($i = 0; $i < count($t_sql); $i++) { + $res = mysqli_query($GLOBALS["___mysqli_ston"], $t_sql[$i]) or die('EmptyDB-Error: ' . ((is_object( + $GLOBALS["___mysqli_ston"] + )) ? mysqli_error($GLOBALS["___mysqli_ston"]) + : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))); + } + } + @mysqli_query($GLOBALS["___mysqli_ston"], 'SET FOREIGN_KEY_CHECKS=1'); } function AutoDelete() { - global $del_files,$config,$lang,$out; - $out=''; - if ($config['max_backup_files']>0) - { - //Files einlesen - $dh=opendir($config['paths']['backup']); - $dbbackups=array(); - $files=array(); + global $del_files, $config, $lang, $out; + $out = ''; + if ($config['max_backup_files'] > 0) { + //Files einlesen + $dh = opendir($config['paths']['backup']); + $dbbackups = array(); + $files = array(); - // Build assoc Array $db=>$timestamp=>$filenames - while (false!==($filename=readdir($dh))) - { - if ($filename!='.'&&$filename!='..'&&!is_dir($config['paths']['backup'].$filename)) - { - //statuszeile auslesen - if (substr($filename,-2)=='gz') - { - $fp=gzopen($config['paths']['backup'].$filename,'r'); - $sline=gzgets($fp,40960); - gzclose($fp); - } - else - { - $fp=fopen($config['paths']['backup'].$filename,'r'); - $sline=fgets($fp,500); - fclose($fp); - } - $statusline=ReadStatusline($sline); - if ($statusline['dbname']!='unknown') - { - $tabellenanzahl=($statusline['tables']==-1) ? '' : $statusline['tables']; - $eintraege=($statusline['records']==-1) ? '' : $statusline['records']; - $part=($statusline['part']=='MP_0'||$statusline['part']='') ? 0 : substr($statusline['part'],3); - $db_name=$statusline['dbname']; - $datum=substr($filename,strlen($db_name)+1); - $timestamp=substr($datum,0,16); - if (!isset($files[$db_name])) $files[$db_name]=array(); - if (!isset($files[$db_name][$timestamp])) $files[$db_name][$timestamp]=array(); - $files[$db_name][$timestamp][]=$filename; - } - } - } - $out=''; // stores output messages - // Backups pro DB und Timestamp ermitteln - foreach ($files as $db=>$val) - { - //echo "
DB ".$db." hat ".sizeof($val)." Backups."; - if (sizeof($val)>$config['max_backup_files']) - { - $db_files=$val; - krsort($db_files,SORT_STRING); - //now latest backupfiles are on top -> delete all files with greater index - $i=0; - foreach ($db_files as $timestamp=>$filenames) - { - if ($i>=$config['max_backup_files']) - { - // Backup too old -> delete files - foreach ($filenames as $f) - { - if ($out=='') $out.=$lang['L_FM_AUTODEL1'].'
'; - if (@unlink('./'.$config['paths']['backup'].$f)) - { - $out.=''.sprintf($lang['L_DELETE_FILE_SUCCESS'],$f).'
'; - } - else - { - $out.=$lang['L_ERROR'].': '.sprintf($lang['L_DELETE_FILE_ERROR'],$f).'
'; - } - } - } - $i++; - } - } - } - } - return $out; + // Build assoc Array $db=>$timestamp=>$filenames + while (false !== ($filename = readdir($dh))) { + if ($filename != '.' && $filename != '..' && !is_dir($config['paths']['backup'] . $filename)) { + //statuszeile auslesen + if (substr($filename, -2) == 'gz') { + $fp = gzopen($config['paths']['backup'] . $filename, 'r'); + $sline = gzgets($fp, 40960); + gzclose($fp); + } else { + $fp = fopen($config['paths']['backup'] . $filename, 'r'); + $sline = fgets($fp, 500); + fclose($fp); + } + $statusline = ReadStatusline($sline); + if ($statusline['dbname'] != 'unknown') { + $tabellenanzahl = ($statusline['tables'] == -1) ? '' : $statusline['tables']; + $eintraege = ($statusline['records'] == -1) ? '' : $statusline['records']; + $part = ($statusline['part'] == 'MP_0' || $statusline['part'] = '') + ? 0 + : substr( + $statusline['part'], + 3 + ); + $db_name = $statusline['dbname']; + $datum = substr($filename, strlen($db_name) + 1); + $timestamp = substr($datum, 0, 16); + if (!isset($files[$db_name])) { + $files[$db_name] = array(); + } + if (!isset($files[$db_name][$timestamp])) { + $files[$db_name][$timestamp] = array(); + } + $files[$db_name][$timestamp][] = $filename; + } + } + } + $out = ''; // stores output messages + // Backups pro DB und Timestamp ermitteln + foreach ($files as $db => $val) { + //echo "
DB ".$db." hat ".sizeof($val)." Backups."; + if (sizeof($val) > $config['max_backup_files']) { + $db_files = $val; + krsort($db_files, SORT_STRING); + //now latest backupfiles are on top -> delete all files with greater index + $i = 0; + foreach ($db_files as $timestamp => $filenames) { + if ($i >= $config['max_backup_files']) { + // Backup too old -> delete files + foreach ($filenames as $f) { + if ($out == '') { + $out .= $lang['L_FM_AUTODEL1'] . '
'; + } + if (@unlink('./' . $config['paths']['backup'] . $f)) { + $out .= '' . sprintf($lang['L_DELETE_FILE_SUCCESS'], $f) + . '
'; + } else { + $out .= $lang['L_ERROR'] . ': ' . sprintf( + $lang['L_DELETE_FILE_ERROR'], + $f + ) . '
'; + } + } + } + $i++; + } + } + } + } + + return $out; } -function DeleteFile($files, $function='max') +function DeleteFile($files, $function = 'max') { - global $config,$lang; - $delfile=explode("|",$files); - $r='

'.$lang['L_FM_AUTODEL1'].'
'; - $r.=$delfile[3]."
"; - $part=$delfile[2]; - if ($part>0) - { - for ($i=$part; $i>0; $i--) - { - $delete=@unlink($config['paths']['backup'].$delfile[3]); - if ($delete) WriteLog("autodeleted ($function) '$delfile[3]'."); - } - } - else - { - WriteLog("autodeleted ($function) '$delfile[3]'."); - unlink($config['paths']['backup'].$delfile[3]); - } - $r.='

'; - return $r; + global $config, $lang; + $delfile = explode("|", $files); + $r = '

' . $lang['L_FM_AUTODEL1'] . '
'; + $r .= $delfile[3] . "
"; + $part = $delfile[2]; + if ($part > 0) { + for ($i = $part; $i > 0; $i--) { + $delete = @unlink($config['paths']['backup'] . $delfile[3]); + if ($delete) { + WriteLog("autodeleted ($function) '$delfile[3]'."); + } + } + } else { + WriteLog("autodeleted ($function) '$delfile[3]'."); + unlink($config['paths']['backup'] . $delfile[3]); + } + $r .= '

'; + + return $r; } function ReadStatusline($line) { - /*AUFBAU der Statuszeile: + /*AUFBAU der Statuszeile: -- Status:tabellenzahl:datensätze:Multipart:Datenbankname:script:scriptversion:Kommentar:MySQLVersion:Backupflags:SQLBefore:SQLAfter:Charset:EXTINFO Aufbau Backupflags (1 Zeichen pro Flag, 0 oder 1, 2=unbekannt) (complete inserts)(extended inserts)(ignore inserts)(delayed inserts)(downgrade)(lock tables)(optimize tables) */ - global $lang; - $statusline=Array(); - if ((substr($line,0,8)!="# Status"&&substr($line,0,9)!="-- Status")||substr($line,0,10)=='-- StatusC') - { - //Fremdfile - $statusline['tables']=-1; - $statusline['records']=-1; - $statusline['part']='MP_0'; - $statusline['dbname']='unknown'; - $statusline['script']=''; - $statusline['scriptversion']=''; - $statusline['comment']=''; - $statusline['mysqlversion']='unknown'; - $statusline['flags']='2222222'; - $statusline['sqlbefore']=''; - $statusline['sqlafter']=''; - $statusline['charset']='?'; - } - else - { - // MySQLDumper-File - Informationen extrahieren - $s=explode(':',$line); - if (count($s)<12) - { - //fehlenden Elemente auffüllen - $c=count($s); - array_pop($s); - for ($i=$c-1; $i<12; $i++) - { - $s[]=''; - } - } - $statusline['tables']=$s[1]; - $statusline['records']=$s[2]; - $statusline['part']=($s[3]==''||$s[3]=='MP_0') ? 'MP_0' : $s[3]; - $statusline['dbname']=$s[4]; - $statusline['script']=$s[5]; - $statusline['scriptversion']=$s[6]; - $statusline['comment']=$s[7]; - $statusline['mysqlversion']=$s[8]; - $statusline['flags']=$s[9]; - $statusline['sqlbefore']=$s[10]; - $statusline['sqlafter']=$s[11]; - if ((isset($s[12]))&&trim($s[12])!='EXTINFO') $statusline['charset']=$s[12]; - else - $statusline['charset']='?'; - } + global $lang; + $statusline = Array(); + if ((substr($line, 0, 8) != "# Status" && substr($line, 0, 9) != "-- Status") + || substr($line, 0, 10) == '-- StatusC' + ) { + //Fremdfile + $statusline['tables'] = -1; + $statusline['records'] = -1; + $statusline['part'] = 'MP_0'; + $statusline['dbname'] = 'unknown'; + $statusline['script'] = ''; + $statusline['scriptversion'] = ''; + $statusline['comment'] = ''; + $statusline['mysqlversion'] = 'unknown'; + $statusline['flags'] = '2222222'; + $statusline['sqlbefore'] = ''; + $statusline['sqlafter'] = ''; + $statusline['charset'] = '?'; + } else { + // MySQLDumper-File - Informationen extrahieren + $s = explode(':', $line); + if (count($s) < 12) { + //fehlenden Elemente auffüllen + $c = count($s); + array_pop($s); + for ($i = $c - 1; $i < 12; $i++) { + $s[] = ''; + } + } + $statusline['tables'] = $s[1]; + $statusline['records'] = $s[2]; + $statusline['part'] = ($s[3] == '' || $s[3] == 'MP_0') ? 'MP_0' : $s[3]; + $statusline['dbname'] = $s[4]; + $statusline['script'] = $s[5]; + $statusline['scriptversion'] = $s[6]; + $statusline['comment'] = $s[7]; + $statusline['mysqlversion'] = $s[8]; + $statusline['flags'] = $s[9]; + $statusline['sqlbefore'] = $s[10]; + $statusline['sqlafter'] = $s[11]; + if ((isset($s[12])) && trim($s[12]) != 'EXTINFO') { + $statusline['charset'] = $s[12]; + } else { + $statusline['charset'] = '?'; + } + } - //flags zerlegen - if (strlen($statusline['flags'])<6) $statusline['flags']="2222222"; - $statusline['complete_inserts']=substr($statusline['flags'],0,1); - $statusline['extended_inserts']=substr($statusline['flags'],1,1); - $statusline['ignore_inserts']=substr($statusline['flags'],2,1); - $statusline['delayed_inserts']=substr($statusline['flags'],3,1); - $statusline['downgrade']=substr($statusline['flags'],4,1); - $statusline['lock_tables']=substr($statusline['flags'],5,1); - $statusline['optimize_tables']=substr($statusline['flags'],6,1); - return $statusline; + //flags zerlegen + if (strlen($statusline['flags']) < 6) { + $statusline['flags'] = "2222222"; + } + $statusline['complete_inserts'] = substr($statusline['flags'], 0, 1); + $statusline['extended_inserts'] = substr($statusline['flags'], 1, 1); + $statusline['ignore_inserts'] = substr($statusline['flags'], 2, 1); + $statusline['delayed_inserts'] = substr($statusline['flags'], 3, 1); + $statusline['downgrade'] = substr($statusline['flags'], 4, 1); + $statusline['lock_tables'] = substr($statusline['flags'], 5, 1); + $statusline['optimize_tables'] = substr($statusline['flags'], 6, 1); + + return $statusline; } -function NextPart($s, $first=0, $keep_suffix=false) +function NextPart($s, $first = 0, $keep_suffix = false) { - $nf=explode('_',$s); - $i=array_search('part',$nf)+1; - $p=substr($nf[$i],0,strpos($nf[$i],'.')); - $ext=substr($nf[$i],strlen($p)); - if ($first==1) - { - $nf[$i]='1'.$ext; - } - else - { - $nf[$i]=++$p.$ext; - } - $filename=implode('_',$nf); - return $filename; + $nf = explode('_', $s); + $i = array_search('part', $nf) + 1; + $p = substr($nf[$i], 0, strpos($nf[$i], '.')); + $ext = substr($nf[$i], strlen($p)); + if ($first == 1) { + $nf[$i] = '1' . $ext; + } else { + $nf[$i] = ++$p . $ext; + } + $filename = implode('_', $nf); + + return $filename; } function zeit_format($t) { - global $lang; - $tt_m=floor($t/60); - $tt_s=$t-($tt_m*60); - if ($tt_m<1) return floor($tt_s).' '.$lang['L_SECONDS']; - else if ($tt_m==1) return '1 '.$lang['L_MINUTE'].' '.floor($tt_s).' '.$lang['L_SECONDS']; - else return $tt_m.' '.$lang['L_MINUTES'].' '.floor($tt_s).' '.$lang['L_SECONDS']; + global $lang; + $tt_m = floor($t / 60); + $tt_s = $t - ($tt_m * 60); + if ($tt_m < 1) { + return floor($tt_s) . ' ' . $lang['L_SECONDS']; + } else { + if ($tt_m == 1) { + return '1 ' . $lang['L_MINUTE'] . ' ' . floor($tt_s) . ' ' . $lang['L_SECONDS']; + } else { + return $tt_m . ' ' . $lang['L_MINUTES'] . ' ' . floor($tt_s) . ' ' . $lang['L_SECONDS']; + } + } } function TesteFTP($i) { - global $lang,$config; - if (!isset($config['ftp_timeout'][$i])) $config['ftp_timeout'][$i]=30; - $s=''; - if ($config['ftp_port'][$i]==''||$config['ftp_port'][$i]==0) $config['ftp_port'][$i]=21; - $pass=-1; - if (!extension_loaded("ftp")) - { - $s='
'.$lang['L_NOFTPPOSSIBLE'].''; - } - else - $pass=0; + global $lang, $config; + if (!isset($config['ftp_timeout'][$i])) { + $config['ftp_timeout'][$i] = 30; + } + $s = ''; + if ($config['ftp_port'][$i] == '' || $config['ftp_port'][$i] == 0) { + $config['ftp_port'][$i] = 21; + } + $pass = -1; + if (!extension_loaded("ftp")) { + $s = '
' . $lang['L_NOFTPPOSSIBLE'] . ''; + } else { + $pass = 0; + } - if ($pass==0) - { - if ($config['ftp_server'][$i]==''||$config['ftp_user'][$i]=='') - { - $s='
'.$lang['L_WRONGCONNECTIONPARS'].''; - } - else - $pass=1; - } + if ($pass == 0) { + if ($config['ftp_server'][$i] == '' || $config['ftp_user'][$i] == '') { + $s = '
' . $lang['L_WRONGCONNECTIONPARS'] . ''; + } else { + $pass = 1; + } + } - if ($pass==1) - { - $s=$lang['L_CONNECT_TO'].' `'.$config['ftp_server'][$i].'` Port '.$config['ftp_port'][$i]; + if ($pass == 1) { + $s = $lang['L_CONNECT_TO'] . ' `' . $config['ftp_server'][$i] . '` Port ' . $config['ftp_port'][$i]; - 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]); - } - if ($conn_id) $login_result=@ftp_login($conn_id,$config['ftp_user'][$i],$config['ftp_pass'][$i]); - if (!$conn_id||(!$login_result)) - { - $s.='
'.$lang['L_CONN_NOT_POSSIBLE'].''; - } - else - { - $pass=2; - if ($config['ftp_mode'][$i]==1) ftp_pasv($conn_id,true); - } - } + 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]); + } + if ($conn_id) { + $login_result = @ftp_login($conn_id, $config['ftp_user'][$i], $config['ftp_pass'][$i]); + } + if (!$conn_id || (!$login_result)) { + $s .= '
' . $lang['L_CONN_NOT_POSSIBLE'] . ''; + } else { + $pass = 2; + if ($config['ftp_mode'][$i] == 1) { + ftp_pasv($conn_id, true); + } + } + } - if ($pass==2) - { - $s.='
Login ok
'.$lang['L_CHANGEDIR'].' `'.$config['ftp_dir'][$i].'` '; - $dirc=@ftp_chdir($conn_id,$config['ftp_dir'][$i]); - if (!$dirc) - { - $s.='
'.$lang['L_CHANGEDIRERROR'].''; - } - else - { - $pass=3; - $s.=''.$lang['L_OK'].''; - } - @ftp_close($conn_id); - } + if ($pass == 2) { + $s .= '
Login ok
' . $lang['L_CHANGEDIR'] . ' `' . $config['ftp_dir'][$i] . '` '; + $dirc = @ftp_chdir($conn_id, $config['ftp_dir'][$i]); + if (!$dirc) { + $s .= '
' . $lang['L_CHANGEDIRERROR'] . ''; + } else { + $pass = 3; + $s .= '' . $lang['L_OK'] . ''; + } + @ftp_close($conn_id); + } - if ($pass==3) $s.='
'.$lang['L_FTP_OK'].''; - return $s; + if ($pass == 3) { + $s .= '
' . $lang['L_FTP_OK'] . ''; + } + + return $s; } -function Realpfad($p) +/** + * Get current MSD home path + * + * @return string + */ +function basePath() { - global $config; - $dir=dirname(__FILE__); - $dir=str_replace('inc','',$dir); - $dir=str_replace('\\','/',$dir); - $dir=str_replace('//','/',$dir); - if (substr($dir,-1)!='/') $dir.='/'; - return $dir; + $path= dirname(__FILE__) . '/../'; + if (function_exists('realpath')) { + $path = realpath($path) . '/'; + } + + return $path; } // liest die Dateiliste aller vorhanden Konfigurationsfiles function get_config_filelist() { - global $config; - $default=$config['config_file']; - clearstatcache(); - $dh=opendir($config['paths']['config']); - $r=""; - while (false!==($filename=readdir($dh))) - { - if ($filename!="."&&$filename!=".."&&!is_dir($config['paths']['config'].$filename)&&substr($filename,-9)==".conf.php") - { - $f=substr($filename,0,strlen($filename)-9); - $r.=''.$end."\n"; - } - elseif ($k=="radio") - { - $r.=$start.''; - $r.=''.$end."\n"; - } - $i++; - } - return $r; + global $config, $lang; + $default = $config['language']; + $dh = opendir($config['paths']['root'] . "language/"); + $r = ""; + $lang_files = array(); + while (false !== ($filename = readdir($dh))) { + if ($filename != "." && $filename != '.svn' && $filename != ".." && $filename != "flags" + && is_dir( + $config['paths']['root'] . "language/" . $filename + ) + ) { + $lang_files[$lang[$filename]] = $filename; + } + } + ksort($lang_files); + $i = 1; + foreach ($lang_files as $filename) { + if ($k == "op") { + $r .= $start . '' . $end . "\n"; + } elseif ($k == "radio") { + $r .= $start . ''; + $r .= '' . $end . "\n"; + } + $i++; + } + + return $r; } // detect language subdirs and add them to the global definition of $lang function GetLanguageArray() { - global $config,$lang; - $dh=opendir($config['paths']['root']."language/"); - unset($lang['languages']); - $lang['languages']=array(); - while (false!==($filename=readdir($dh))) - { - if ($filename!="."&&$filename!='.svn'&&$filename!=".."&&$filename!="flags"&&is_dir($config['paths']['root']."language/".$filename)) - { - $lang['languages'][]=$filename; - } - } + global $config, $lang; + $dh = opendir($config['paths']['root'] . "language/"); + unset($lang['languages']); + $lang['languages'] = array(); + while (false !== ($filename = readdir($dh))) { + if ($filename != "." && $filename != '.svn' && $filename != ".." && $filename != "flags" + && is_dir( + $config['paths']['root'] . "language/" . $filename + ) + ) { + $lang['languages'][] = $filename; + } + } } -function headline($title, $mainframe=1) +function headline($title, $mainframe = 1) { - global $config,$lang; - $s=''; - if ($config['interface_server_caption']==1) - { - if ($config['interface_server_caption_position']==$mainframe) - { - $s.='
'.$lang['L_SERVER'].': '.$_SERVER['SERVER_NAME'].'
'; - } - } - if ($mainframe==1) - { - $s.='
'.$title.'
'; - $s.='
'; - } - return $s; + global $config, $lang; + $s = ''; + if ($config['interface_server_caption'] == 1) { + if ($config['interface_server_caption_position'] == $mainframe) { + $s .= '
' . $lang['L_SERVER'] . ': ' . $_SERVER['SERVER_NAME'] . '
'; + } + } + if ($mainframe == 1) { + $s .= '
' . $title . '
'; + $s .= '
'; + } + + return $s; } -function PicCache($rpath='./') +function PicCache($rpath = './') { - global $BrowserIcon,$config; + global $BrowserIcon, $config; - $t='
'; + $t = '
'; - $dh=opendir($config['files']['iconpath']); - while (false!==($filename=readdir($dh))) - { - if ($filename!="."&&$filename!=".."&&!is_dir($config['files']['iconpath'].$filename)) - { - $t.=''."\n"; - } - } - $t.='
'; - return $t; + $dh = opendir($config['files']['iconpath']); + while (false !== ($filename = readdir($dh))) { + if ($filename != "." && $filename != ".." && !is_dir($config['files']['iconpath'] . $filename)) { + $t .= '' . "\n"; + } + } + $t .= '
'; + + return $t; } -function MSDHeader($kind=0) +function MSDHeader($kind = 0) { - global $config; - header('Pragma: no-cache'); - header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 - header("Expires: -1"); // Datum in der Vergangenheit - header('Content-Type: text/html; charset=UTF-8'); + global $config; + header('Pragma: no-cache'); + header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 + header("Expires: -1"); // Datum in der Vergangenheit + header('Content-Type: text/html; charset=UTF-8'); - //kind 0=main 1=menu - $r=''."\n\n\n"; - $r.=''."\n"; - $r.=''."\n"; + //kind 0=main 1=menu + $r = '' + . "\n\n\n"; + $r .= '' . "\n"; + $r .= '' . "\n"; - $r.='MySqlDumper'."\n"; - $r.=''."\n"; - $r.=''."\n"; - $r.="\n'; - return $r; + $r .= 'MySqlDumper' . "\n"; + $r .= '' . "\n"; + $r .= '' . "\n"; + $r .= "\n'; + + return $r; } -function MSDFooter($rfoot='', $enddiv=1) +function MSDFooter($rfoot = '', $enddiv = 1) { - /* + /* global $config,$databases,$dump,$restore,$lang; if (isset($config['homepage'])) { @@ -888,243 +943,254 @@ function MSDFooter($rfoot='', $enddiv=1) } else */ - $f=''; - if ($enddiv==1) $f.='
'; + $f = ''; + if ($enddiv == 1) { + $f .= '
'; + } - $f.=$rfoot.''; + $f .= $rfoot . ''; - return $f; + return $f; } function save_bracket($str) { - // Wenn Klammer zu am Ende steht, diese behalten - $str=trim($str); - if (substr($str,-1)==')') $str=')'; - else - $str=''; - return $str; + // Wenn Klammer zu am Ende steht, diese behalten + $str = trim($str); + if (substr($str, -1) == ')') { + $str = ')'; + } else { + $str = ''; + } + + return $str; } -function DownGrade($s, $show=true) +function DownGrade($s, $show = true) { - $tmp=explode(",",$s); - //echo "
";print_r($tmp);echo "
"; + $tmp = explode(",", $s); + //echo "
";print_r($tmp);echo "
"; - for ($i=0; $i$val) - { - //echo "
Wandle " . $val . " nach "; - $obj[$key]=utf8_encode($val); - //echo $obj[$key]; - } - } - if (is_string($obj)) $obj=utf8_encode($obj); - $ret=$obj; - } - return $ret; + if ($config['mysql_can_change_encoding'] == false && $config['mysql_standard_character_set'] != 'utf8') { + if (is_array($obj)) { + foreach ($obj as $key => $val) { + //echo "
Wandle " . $val . " nach "; + $obj[$key] = utf8_encode($val); + //echo $obj[$key]; + } + } + if (is_string($obj)) { + $obj = utf8_encode($obj); + } + $ret = $obj; + } + + return $ret; } /** * Convert all array elements to Latin1 * * @param $array + * * @return array */ function convert_to_latin1($obj) { - global $config; - $ret=$obj; - // wenn die Verbindung zur Datenbank nicht auf utf8 steht, dann muessen die Rückgaben in utf8 gewandelt werden, - // da die Webseite utf8-kodiert ist - if ($config['mysql_can_change_encoding']==false&&$config['mysql_standard_character_set']!='utf8') - { - if (is_array($obj)) - { - foreach ($obj as $key=>$val) - { - $obj[$key]=utf8_decode($val); - } - } - if (is_string($obj)) $obj=utf8_decode($obj); - $ret=$obj; - } - return $ret; + global $config; + $ret = $obj; + // wenn die Verbindung zur Datenbank nicht auf utf8 steht, dann muessen die Rückgaben in utf8 gewandelt werden, + // da die Webseite utf8-kodiert ist + if ($config['mysql_can_change_encoding'] == false && $config['mysql_standard_character_set'] != 'utf8') { + if (is_array($obj)) { + foreach ($obj as $key => $val) { + $obj[$key] = utf8_decode($val); + } + } + if (is_string($obj)) { + $obj = utf8_decode($obj); + } + $ret = $obj; + } + + return $ret; } // returns the index of the selected val in an optionlist function get_index($arr, $selected) { - $ret=false; // return false if not found - foreach ($arr as $key=>$val) - { - if (strtolower(substr($val,0,strlen($selected)))==strtolower($selected)) - { - $ret=$key; - break; - } - } - return $ret; + $ret = false; // return false if not found + foreach ($arr as $key => $val) { + if (strtolower(substr($val, 0, strlen($selected))) == strtolower($selected)) { + $ret = $key; + break; + } + } + + return $ret; } /** * Check if config is readable * * @param $file + * * @return boolean */ -function read_config($file=false) +function read_config($file = false) { - global $config,$databases; - $ret=false; - if (!$file) $file=$config['config_file']; - // protect from including external files - $search=array(':', 'http', 'ftp', ' '); - $replace=array('', '', '', ''); - $file=str_replace($search,$replace,$file); + global $config, $databases; + $ret = false; + if (!$file) { + $file = $config['config_file']; + } + // protect from including external files + $search = array(':', 'http', 'ftp', ' '); + $replace = array('', '', '', ''); + $file = str_replace($search, $replace, $file); - if (is_readable($config['paths']['config'].$file.'.php')) - { - // to prevent modern server from caching the new configuration we need to evaluate it this way - clearstatcache(); - $f=implode('',file($config['paths']['config'].$file.'.php')); - $f=str_replace('','',$f); - eval($f); - $config['config_file']=$file; - $_SESSION['config_file']=$config['config_file']; - $ret=true; - } - return $ret; + if (is_readable($config['paths']['config'] . $file . '.php')) { + // to prevent modern server from caching the new configuration we need to evaluate it this way + clearstatcache(); + $f = implode('', file($config['paths']['config'] . $file . '.php')); + $f = str_replace('', '', $f); + eval($f); + $config['config_file'] = $file; + $_SESSION['config_file'] = $config['config_file']; + $ret = true; + } + + return $ret; } /** @@ -1134,33 +1200,41 @@ function read_config($file=false) */ function get_config_filenames() { - global $config; - $configs=array(); - $dh=opendir($config['paths']['config']."/"); - while (false!==($filename=readdir($dh))) - { - if (substr($filename,-4)=='.php'&&substr($filename,-9)!='.conf.php'&&$filename!='dbs_manual.php') - { - $configs[]=substr($filename,0,-4); - } - } - return $configs; + global $config; + $configs = array(); + $dh = opendir($config['paths']['config'] . "/"); + while (false !== ($filename = readdir($dh))) { + if (substr($filename, -4) == '.php' && substr($filename, -9) != '.conf.php' && $filename != 'dbs_manual.php') { + $configs[] = substr($filename, 0, -4); + } + } + + return $configs; } -function table_output($text, $val, $small=false, $colspan=1) +function table_output($text, $val, $small = false, $colspan = 1) { - $ret=''; - $ret.='1) $ret.=' colspan="'.$colspan.'"'; - $ret.='>'.$text; - if ($colspan==1) $ret.=': '; - else - $ret.=' '; - if ($colspan==1) $ret.=''; - if ($small) $ret.=''.$val.''; - else - $ret.=''.$val.''; - return $ret; + $ret = ''; + $ret .= ' 1) { + $ret .= ' colspan="' . $colspan . '"'; + } + $ret .= '>' . $text; + if ($colspan == 1) { + $ret .= ': '; + } else { + $ret .= ' '; + } + if ($colspan == 1) { + $ret .= ''; + } + if ($small) { + $ret .= '' . $val . ''; + } else { + $ret .= '' . $val . ''; + } + + return $ret; } /** @@ -1168,91 +1242,108 @@ function table_output($text, $val, $small=false, $colspan=1) */ function get_sql_encodings() { - global $config; - unset($config['mysql_possible_character_sets']); - if (!isset($config['dbconnection'])) MSD_mysql_connect(); - $erg=false; - $config['mysql_standard_character_set']=''; - $config['mysql_possible_character_sets']=array(); + global $config; + unset($config['mysql_possible_character_sets']); + if (!isset($config['dbconnection'])) { + MSD_mysql_connect(); + } + $erg = false; + $config['mysql_standard_character_set'] = ''; + $config['mysql_possible_character_sets'] = array(); - if (!defined('MSD_MYSQL_VERSION')) GetMySQLVersion(); - $v=explode('.',MSD_MYSQL_VERSION); - $config['mysql_can_change_encoding']=false; - if (($v[0]<=4&&$v[1]<1)||$v[0]<=3) - { - // MySQL < 4.1 - $config['mysql_can_change_encoding']=false; - $sqlt='SHOW VARIABLES LIKE \'character_set%\''; - $res=MSD_query($sqlt) or die(SQLError($sqlt,((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)))); - if ($res) - { - WHILE ($row=mysqli_fetch_row($res)) - { - if ($row[0]=='character_set') - { - $config['mysql_standard_character_set']=$row[1]; - if ($v[0]==3) $config['mysql_possible_character_sets'][0]=$row[1]; - } + if (!defined('MSD_MYSQL_VERSION')) { + GetMySQLVersion(); + } + $v = explode('.', MSD_MYSQL_VERSION); + $config['mysql_can_change_encoding'] = false; + if (($v[0] <= 4 && $v[1] < 1) || $v[0] <= 3) { + // MySQL < 4.1 + $config['mysql_can_change_encoding'] = false; + $sqlt = 'SHOW VARIABLES LIKE \'character_set%\''; + $res = MSD_query($sqlt) or die(SQLError( + $sqlt, + ((is_object($GLOBALS["___mysqli_ston"])) + ? mysqli_error($GLOBALS["___mysqli_ston"]) + : (($___mysqli_res + = mysqli_connect_error()) ? $___mysqli_res : false)) + )); + if ($res) { + WHILE ($row = mysqli_fetch_row($res)) { + if ($row[0] == 'character_set') { + $config['mysql_standard_character_set'] = $row[1]; + if ($v[0] == 3) { + $config['mysql_possible_character_sets'][0] = $row[1]; + } + } - if ($row[0]=='character_sets'&&$v[0]>3) - { - $config['mysql_possible_character_sets']=explode(' ',$row[1]); - sort($config['mysql_possible_character_sets']); - } - } - } - } - else - { - // MySQL-Version >= 4.1 - $config['mysql_can_change_encoding']=true; - $sqlt='SHOW CHARACTER SET'; - $res=MSD_query($sqlt) or die(SQLError($sqlt,((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)))); + if ($row[0] == 'character_sets' && $v[0] > 3) { + $config['mysql_possible_character_sets'] = explode(' ', $row[1]); + sort($config['mysql_possible_character_sets']); + } + } + } + } else { + // MySQL-Version >= 4.1 + $config['mysql_can_change_encoding'] = true; + $sqlt = 'SHOW CHARACTER SET'; + $res = MSD_query($sqlt) or die(SQLError( + $sqlt, + ((is_object($GLOBALS["___mysqli_ston"])) + ? mysqli_error($GLOBALS["___mysqli_ston"]) + : (($___mysqli_res + = mysqli_connect_error()) ? $___mysqli_res : false)) + )); - if ($res) - { - WHILE ($row=mysqli_fetch_row($res)) - { - $config['mysql_possible_character_sets'][]=$row[0].' - '.$row[1]; - } - sort($config['mysql_possible_character_sets']); - } + if ($res) { + WHILE ($row = mysqli_fetch_row($res)) { + $config['mysql_possible_character_sets'][] = $row[0] . ' - ' . $row[1]; + } + sort($config['mysql_possible_character_sets']); + } - $sqlt='SHOW VARIABLES LIKE \'character_set_connection\''; - $res=MSD_query($sqlt) or die(SQLError($sqlt,((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)))); + $sqlt = 'SHOW VARIABLES LIKE \'character_set_connection\''; + $res = MSD_query($sqlt) or die(SQLError( + $sqlt, + ((is_object($GLOBALS["___mysqli_ston"])) + ? mysqli_error($GLOBALS["___mysqli_ston"]) + : (($___mysqli_res + = mysqli_connect_error()) ? $___mysqli_res : false)) + )); - if ($res) - { - WHILE ($row=mysqli_fetch_row($res)) - { - $config['mysql_standard_character_set']=$row[1]; - } - } - } + if ($res) { + WHILE ($row = mysqli_fetch_row($res)) { + $config['mysql_standard_character_set'] = $row[1]; + } + } + } } /** * Un-quotes a quoted string/array * * @param $value + * * @return string/array */ function stripslashes_deep($value) { - $value=is_array($value) ? array_map('stripslashes_deep',$value) : stripslashes($value); - return $value; + $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); + + return $value; } /** * Remove whitespaces before and after an string or array * * @param $value + * * @return string/array */ function trim_deep($value) { - $value=is_array($value) ? array_map('trim_deep',$value) : trim($value); - return $value; + $value = is_array($value) ? array_map('trim_deep', $value) : trim($value); + + return $value; } /** @@ -1265,19 +1356,21 @@ function trim_deep($value) * @param $file * @param local_file * @param $path + * * @return boolean */ -function fetchFileFromURL($url, $file, $local_path='./data/',$local_file) +function fetchFileFromURL($url, $file, $local_path = './data/', $local_file) { - $data=fetchFileDataFromURL($url.$file); - if ($data) - { - $d=fopen($local_path.$local_file,"wb"); - $ret=fwrite($d,$data); - fclose($d); - return $ret; - } - return false; + $data = fetchFileDataFromURL($url . $file); + if ($data) { + $d = fopen($local_path . $local_file, "wb"); + $ret = fwrite($d, $data); + fclose($d); + + return $ret; + } + + return false; } /** @@ -1287,36 +1380,44 @@ function fetchFileFromURL($url, $file, $local_path='./data/',$local_file) * and returns the content as a binary string or an empty string on failure * * @param $url + * * @return string file data */ function fetchFileDataFromURL($url) { - $url_parsed=parse_url($url); - $in=''; + $url_parsed = parse_url($url); + $in = ''; - $host=$url_parsed['host']; - $port=isset($url_parsed['port']) ? intval($url_parsed['port']) : 80; - if ($port==0) $port=80; - $path=$url_parsed['path']; - if (isset($url_parsed['query'])&&$url_parsed['query']!='') $path.='?'.$url_parsed['query']; + $host = $url_parsed['host']; + $port = isset($url_parsed['port']) ? intval($url_parsed['port']) : 80; + if ($port == 0) { + $port = 80; + } + $path = $url_parsed['path']; + if (isset($url_parsed['query']) && $url_parsed['query'] != '') { + $path .= '?' . $url_parsed['query']; + } - $fp=fsockopen($host,$port,$errno,$errstr,3); - if ($fp) - { - $out="GET $path HTTP/1.1\r\nHost: $host\r\n"; - $out.="Connection: close\r\n\r\n"; - fwrite($fp,$out); - $body=false; - while (!feof($fp)) - { - $s=fgets($fp,1024); - if ($body) $in.=$s; - if ($s=="\r\n") $body=true; - } + $fp = fsockopen($host, $port, $errno, $errstr, 3); + if ($fp) { + $out = "GET $path HTTP/1.1\r\nHost: $host\r\n"; + $out .= "Connection: close\r\n\r\n"; + fwrite($fp, $out); + $body = false; + while (!feof($fp)) { + $s = fgets($fp, 1024); + if ($body) { + $in .= $s; + } + if ($s == "\r\n") { + $body = true; + } + } - fclose($fp); - } - return $in; + fclose($fp); + } + + return $in; } ?> \ No newline at end of file diff --git a/inc/runtime.php b/inc/runtime.php index 5be7c70..eb27459 100644 --- a/inc/runtime.php +++ b/inc/runtime.php @@ -13,7 +13,7 @@ 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']['root']=basePath(); $config['paths']['work']='work/'; $config['paths']['backup']=$config['paths']['work'] . 'backup/'; $config['paths']['log']=$config['paths']['work'] . 'log/'; diff --git a/install.php b/install.php index bff48ec..2af78ae 100644 --- a/install.php +++ b/install.php @@ -432,7 +432,7 @@ switch ($phase) echo '
'; echo ''; - echo ''; + echo ''; echo ''; echo ''; echo ''; @@ -463,7 +463,7 @@ switch ($phase) echo '
' . $lang['L_IDOMANUAL'] . '
' . $lang['L_DOFROM'] . '
' . Realpfad('./') . '
' . $lang['L_DOFROM'] . '
' . basePath() . '
work' . ( ( $iw[0] ) ? $img_ok : $img_failed ) . '
work/config' . ( ( $iw[1] ) ? $img_ok : $img_failed ) . '
work/log' . ( ( $iw[2] ) ? $img_ok : $img_failed ) . '
'; echo ''; - echo ''; + echo ''; echo ''; echo ''; echo ''; @@ -532,7 +532,7 @@ switch ($phase) { // das Verzeichnis wurde korrekt gelöscht echo '

' . $lang['L_UI6'] . '

'; - echo $lang['L_UI7'] . "
\"" . Realpfad("./") . "\"
" . $lang['L_MANUELL'] . ".

"; + echo $lang['L_UI7'] . "
\"" . basePath() . "\"
" . $lang['L_MANUELL'] . ".

"; echo '' . $lang['L_UI8'] . ''; }
' . $lang['L_IDOMANUAL'] . '
' . $lang['L_DOFROM'] . '
' . Realpfad('./') . '
' . $lang['L_DOFROM'] . '
' . basePath() . '
work' . ( ( $iw[0] ) ? $img_ok : $img_failed ) . '
work/config' . ( ( $iw[1] ) ? $img_ok : $img_failed ) . '
work/log' . ( ( $iw[2] ) ? $img_ok : $img_failed ) . '