From a00f7e8976ad5ec1be0128fe7ccdae2d0c43b619 Mon Sep 17 00:00:00 2001 From: Matthijs Kuiper Date: Mon, 15 Jan 2018 22:53:54 +0100 Subject: ereg_match to preg_match --- html/includes/ftp.php | 505 ++++++++++++++++++-------------------------------- 1 file changed, 177 insertions(+), 328 deletions(-) (limited to 'html/includes/ftp.php') diff --git a/html/includes/ftp.php b/html/includes/ftp.php index 1a6e7ee..552232e 100644 --- a/html/includes/ftp.php +++ b/html/includes/ftp.php @@ -1,411 +1,260 @@ -PopError()) !== false) { - - $fctname = $err['fctname']; - - $msg = $err['msg']; - - $desc = $err['desc']; - - if($desc) $tmp=' ('.$desc.')'; else $tmp=''; - - if (strpos($msg, 'socket set') === 0) { - - $tmp .= "\nTry disabling the usage of sockets (set \$ftp_type = 'pure'; in config.php)"; - - } + $g_ftp_error = true; - tablerow('Error details:', $fctname.': '.$msg.$tmp, true); + tablerow('ERROR:', $message, true); - } + while(($err = $ftp->PopError()) !== false) { + $fctname = $err['fctname']; + $msg = $err['msg']; + $desc = $err['desc']; + if ($desc) $tmp=' ('.$desc.')'; else $tmp=''; + if (strpos($msg, 'socket set') === 0) { + $tmp .= "\nTry disabling the usage of sockets (set \$ftp_type = 'pure'; in config.php)"; + } + tablerow('Error details:', $fctname.': '.$msg.$tmp, true); + } } - - function tablerow($left, $right, $error=false) { + global $html, $ftp_debug; - global $html, $ftp_debug; - - if ($ftp_debug) return; - - $space = ($html) ? ' ' : ' '; - - $left = (empty($left)) ? $space : (($html) ? htmlentities($left) : $left); - - $right = (empty($right)) ? $space : (($html) ? nl2br(htmlentities($right)) : $right); - - $style = ($error) ? 'style="background-color: red;"' : ''; - - if ($html) { - - echo ''; - - echo ''. $left .''; + if ($ftp_debug) return; - echo ''. $right .''; + $space = ($html) ? ' ' : ' '; - echo ''; + $left = (empty($left)) ? $space : (($html) ? htmlentities($left) : $left); + $right = (empty($right)) ? $space : (($html) ? nl2br(htmlentities($right)) : $right); - } else { + $style = ($error) ? 'style="background-color: red;"' : ''; - if (strlen($left) < 30) $left .= str_repeat(" ", 30 - strlen($left)); + if ($html) { + echo ''; + echo ''. $left .''; + echo ''. $right .''; + echo ''; + } else { + if (strlen($left) < 30) $left .= str_repeat(" ", 30 - strlen($left)); - echo "$left $right\n"; - - } - - flush(); + echo "$left $right\n"; + } + flush(); } +function ftpupdate() { + global $html, $ftp, $ftp_uname, $ftp_upass, $ftp_hostname, $ftp_port, $g_ftp_error, $ftp_debug, + $ftp_delete, $ftp_movedir, $ftp_dir, $ftp_passive, $import_log_start, $import_log_extension, -function ftpupdate() - -{ - - global $html, $ftp, $ftp_uname, $ftp_upass, $ftp_hostname, $ftp_port, $g_ftp_error, $ftp_debug, - - $ftp_delete, $ftp_movedir, $ftp_dir, $ftp_passive, $import_log_start, $import_log_extension, - - $import_utdc_download_enable, $import_utdc_log_start, $import_utdc_log_extension, $import_utdc_screenshot_start, $import_utdc_screenshot_extension, - $import_ac_download_enable, $import_ac_log_start, $import_ac_log_extension, - $import_ace_download_enable, $import_ace_log_start, $import_ace_log_extension, $import_ace_screenshot_start, $import_ace_screenshot_extension; - - - - if (!$ftp_debug) { - - if ($html) echo''; - - } - - - - // Update, from here on were going to be doing multiple FTP sessions. - - for ($i = 0; $i < count($ftp_hostname); $i++) { - - if ($i != 0) { - - if ($html and !$ftp_debug) echo ''; - - echo "\n"; - - } - - - - tablerow('Connecting to server:', $ftp_hostname[$i] .':'. $ftp_port[$i]); - - if (!$ftp->SetServer($ftp_hostname[$i], $ftp_port[$i])) { - - ftp_error("Unable to set server: ". $ftp->lastmsg); $ftp->quit(true); continue; - - } - - if (!$ftp->connect()) { - - ftp_error("Unable to connect to server: ". $ftp->lastmsg); $ftp->quit(true); continue; - - } - - - - tablerow('', "Connected, now logging in..."); - - if (!$ftp->login($ftp_uname[$i], $ftp_upass[$i])) { - - ftp_error("Login failed!\nBad username/password?"); $ftp->quit(true); continue; - - } - - tablerow('', "Logged in!"); - - - - if (!$ftp->SetType(FTP_BINARY)) { - - ftp_error("Could not set type: ". $ftp->lastmsg); $ftp->quit(true); continue; - - } - - if (!isset($ftp_passive[$i]) or $ftp_passive[$i]) { - - tablerow("", "Setting passive mode"); - - if(!$ftp->Passive(true)) { - - ftp_error("Could not set passive mode: ". $ftp->lastmsg); $ftp->quit(true); continue; + $import_utdc_download_enable, $import_utdc_log_start, $import_utdc_log_extension, $import_utdc_screenshot_start, $import_utdc_screenshot_extension, + $import_ac_download_enable, $import_ac_log_start, $import_ac_log_extension, + $import_ace_download_enable, $import_ace_log_start, $import_ace_log_extension, $import_ace_screenshot_start, $import_ace_screenshot_extension; - } + if (!$ftp_debug) { + if ($html) echo'
'; - - echo "FTP Transferring Log Files...\n"; - - if ($html) echo '
'; + } - if(!$ftp->Passive(false)) { + // Update, from here on were going to be doing multiple FTP sessions. + for ($i = 0; $i < count($ftp_hostname); $i++) { + if ($i != 0) { + if ($html and !$ftp_debug) echo ''; - ftp_error("Could not set active mode: ". $ftp->lastmsg); $ftp->quit(true); continue; + echo "\n"; + } - } + tablerow('Connecting to server:', $ftp_hostname[$i] .':'. $ftp_port[$i]); - } + if (!$ftp->SetServer($ftp_hostname[$i], $ftp_port[$i])) { + ftp_error("Unable to set server: ". $ftp->lastmsg); $ftp->quit(true); continue; + } - if (($pwd = $ftp->pwd()) === false) { + if (!$ftp->connect()) { + ftp_error("Unable to connect to server: ". $ftp->lastmsg); $ftp->quit(true); continue; + } - ftp_error("Unable to retrieve current working directory"); $ftp->quit(true); continue; + tablerow('', "Connected, now logging in..."); - } + if (!$ftp->login($ftp_uname[$i], $ftp_upass[$i])) { + ftp_error("Login failed!\nBad username/password?"); $ftp->quit(true); continue; + } - tablerow("Current directory is:", $pwd); + tablerow('', "Logged in!"); + if (!$ftp->SetType(FTP_BINARY)) { + ftp_error("Could not set type: ". $ftp->lastmsg); $ftp->quit(true); continue; + } + if (!isset($ftp_passive[$i]) or $ftp_passive[$i]) { + tablerow("", "Setting passive mode"); - $dl_start = time(); + if (!$ftp->Passive(true)) { + ftp_error("Could not set passive mode: ". $ftp->lastmsg); $ftp->quit(true); continue; + } + } else { + tablerow("", "Setting active mode"); - $dl_files = 0; + if (!$ftp->Passive(false)) { + ftp_error("Could not set active mode: ". $ftp->lastmsg); $ftp->quit(true); continue; + } + } - $dl_bytes = 0; + if (($pwd = $ftp->pwd()) === false) { + ftp_error("Unable to retrieve current working directory"); $ftp->quit(true); continue; + } - $error = false; + tablerow("Current directory is:", $pwd); - foreach($ftp_dir[$i] as $dir) { + $dl_start = time(); + $dl_files = 0; + $dl_bytes = 0; + $error = false; - if (!empty($dir)) { + foreach($ftp_dir[$i] as $dir) { + if (!empty($dir)) { + if (!$ftp->chdir($dir)) { + ftp_error("Unable to change directory to: $dir"); $ftp->quit(true); continue; + } - if (!$ftp->chdir($dir)) { + tablerow('', "Changing directory to: $dir"); - ftp_error("Unable to change directory to: $dir"); $ftp->quit(true); continue; + if (($pwd = $ftp->pwd()) === false) { + ftp_error("Unable to retrieve current working directory"); $ftp->quit(true); continue; + } - } + tablerow("New directory is:", $pwd); + } - tablerow('', "Changing directory to: $dir"); + if (($filelist = $ftp->nlist()) === false) { + ftp_error("Unable to retrieve file list"); continue; + } - if (($pwd = $ftp->pwd()) === false) { + tablerow("Directory contains:", count($filelist) ." ". ((count($filelist) == 1) ? 'file' : 'files')); - ftp_error("Unable to retrieve current working directory"); $ftp->quit(true); continue; + if (count($filelist) == 0) { + continue; + } - } + foreach ($filelist as $filename) { + if (((substr($filename, 0, strlen($import_log_start)) == $import_log_start) and (substr($filename, strlen($filename) - strlen($import_log_extension)) == $import_log_extension)) + or ($import_utdc_download_enable and (substr($filename, 0, strlen($import_utdc_log_start)) == $import_utdc_log_start) and (substr($filename, strlen($filename) - strlen($import_utdc_log_extension)) == $import_utdc_log_extension)) + or ($import_utdc_download_enable and (substr($filename, 0, strlen($import_utdc_screenshot_start)) == $import_utdc_screenshot_start) and (substr($filename, strlen($filename) - strlen($import_utdc_screenshot_extension)) == $import_utdc_screenshot_extension)) + or ($import_ac_download_enable and (substr($filename, 0, strlen($import_ac_log_start)) == $import_ac_log_start) and (substr($filename, strlen($filename) - strlen($import_ac_log_extension)) == $import_ac_log_extension)) + or ($import_ace_download_enable and (substr($filename, 0, strlen($import_ace_log_start)) == $import_ace_log_start) and (substr($filename, strlen($filename) - strlen($import_ace_log_extension)) == $import_ace_log_extension)) + or ($import_ace_download_enable and (substr($filename, 0, strlen($import_ace_screenshot_start)) == $import_ace_screenshot_start) and (substr($filename, strlen($filename) - strlen($import_ace_screenshot_extension)) == $import_ace_screenshot_extension))) { + } else { + continue; + } - tablerow("New directory is:", $pwd); + $size = $ftp->get($filename, 'logs/' . $filename); - } + if ($size === FALSE) { + $result = 'ERROR!'; + $error = true; - + if (file_exists('logs/' . $filename)) { + unlink('logs/' . $filename); + } + } else { + $result = "OK (". number_format(round(($size / 1024), 0)) ." KB)"; + $dl_files++; + $dl_bytes += $size; + } - if (($filelist = $ftp->nlist()) === false) { + tablerow(($dl_files == 1) ? 'Downloading...' : '', "$filename -> $result"); - ftp_error("Unable to retrieve file list"); continue; + if ((!isset($ftp_delete[$i]) or $ftp_delete[$i]) and !$error) { + $ftp->delete($filename); + } else { + // rename the file to prevent reimporting + $ftp->rename($filename, "~" . $filename); + } + } + } - } - - - - tablerow("Directory contains:", count($filelist) ." ". ((count($filelist) == 1) ? 'file' : 'files')); - - if (count($filelist) == 0) { - - continue; - - } - - foreach ($filelist as $filename) { - - if (((substr($filename, 0, strlen($import_log_start)) == $import_log_start) and (substr($filename, strlen($filename) - strlen($import_log_extension)) == $import_log_extension)) - - or ($import_utdc_download_enable and (substr($filename, 0, strlen($import_utdc_log_start)) == $import_utdc_log_start) and (substr($filename, strlen($filename) - strlen($import_utdc_log_extension)) == $import_utdc_log_extension)) - - or ($import_utdc_download_enable and (substr($filename, 0, strlen($import_utdc_screenshot_start)) == $import_utdc_screenshot_start) and (substr($filename, strlen($filename) - strlen($import_utdc_screenshot_extension)) == $import_utdc_screenshot_extension)) - - or ($import_ac_download_enable and (substr($filename, 0, strlen($import_ac_log_start)) == $import_ac_log_start) and (substr($filename, strlen($filename) - strlen($import_ac_log_extension)) == $import_ac_log_extension)) - - or ($import_ace_download_enable and (substr($filename, 0, strlen($import_ace_log_start)) == $import_ace_log_start) and (substr($filename, strlen($filename) - strlen($import_ace_log_extension)) == $import_ace_log_extension)) - - or ($import_ace_download_enable and (substr($filename, 0, strlen($import_ace_screenshot_start)) == $import_ace_screenshot_start) and (substr($filename, strlen($filename) - strlen($import_ace_screenshot_extension)) == $import_ace_screenshot_extension))) { - } else { - continue; - } - - $size = $ftp->get($filename, 'logs/' . $filename); - - if ($size === FALSE) { - - $result = 'ERROR!'; - - $error = true; - - if (file_exists('logs/' . $filename)) { - unlink('logs/' . $filename); - } - - } else { - - $result = "OK (". number_format(round(($size / 1024), 0)) ." KB)"; - - $dl_files++; - - $dl_bytes += $size; - - } - - tablerow(($dl_files == 1) ? 'Downloading...' : '', "$filename -> $result"); - - if ((!isset($ftp_delete[$i]) or $ftp_delete[$i]) and !$error) { - $ftp->delete($filename); - } - else { - // rename the file to prevent reimporting - $ftp->rename($filename, "~" . $filename); - } - - } - - } - - $dl_kb = number_format(round(($dl_bytes / 1024), 0)); - - $dl_time = time() - $dl_start; - - tablerow("Downloaded:", "$dl_files ". ((count($filelist) == 1) ? 'file' : 'files') ." ($dl_kb KB) in $dl_time seconds"); - - - - if ($error) { - - ftp_error('There were errors when downoading (some) files!'); - - } - - - - tablerow("Disconnecting...", "done!"); - - $ftp->quit(true); - - } - - if (!$ftp_debug and $html) echo '
'; - } else { + echo "FTP Transferring Log Files...\n"; - tablerow("", "Setting active mode"); + if ($html) echo '

'; - - echo "\n\n"; - - - - //update timestamp - - - - if (!$g_ftp_error) { - - $file = fopen('includes/ftptimestamp.php', 'wb+', 1); - - fwrite($file, time()); - - fclose($file); - - } + $dl_kb = number_format(round(($dl_bytes / 1024), 0)); + $dl_time = time() - $dl_start; + tablerow("Downloaded:", "$dl_files ". ((count($filelist) == 1) ? 'file' : 'files') ." ($dl_kb KB) in $dl_time seconds"); + + if ($error) { + ftp_error('There were errors when downoading (some) files!'); + } + + tablerow("Disconnecting...", "done!"); + + $ftp->quit(true); + } + + if (!$ftp_debug and $html) echo '
'; + + echo "\n\n"; + + //update timestamp + if (!$g_ftp_error) { + $file = fopen('includes/ftptimestamp.php', 'wb+', 1); + fwrite($file, time()); + fclose($file); + } } - - - - $fname = 'includes/ftptimestamp.php'; - $timestamp = 0; - - -if(file_exists($fname)) - -{ - - $file = fopen($fname, 'rb'); - - $timestamp = trim(my_fgets($file)); - - fclose($file); - +if (file_exists($fname)) { + $file = fopen($fname, 'rb'); + $timestamp = trim(my_fgets($file)); + fclose($file); } +if (!$timestamp || (time() - $timestamp) > $ftp_interval*60) { + if ($timestamp) { + if ($html) echo '

'; + echo "Last FTP update more than $ftp_interval minutes ago, starting update ($ftp_type): \n"; -if(!$timestamp || (time() - $timestamp) > $ftp_interval*60) { - - if ($timestamp) { - - if ($html) echo '

'; - - echo "Last FTP update more than $ftp_interval minutes ago, starting update ($ftp_type): \n"; - - if ($html) echo '

'; + if ($html) echo '

'; + } - } + if ($ftp_debug) { + if ($html) echo '
'; - if ($ftp_debug) { + echo "FTP Debugging Output:\n"; - if ($html) echo '
'; + if ($html) echo '
';
+  }
 
-		echo "FTP Debugging Output:\n";
-
-		if ($html) echo '
';
-
-	}
-
-	$ftp = new ftp($ftp_debug, $ftp_debug);
-
-	ftpupdate();
-
-	if ($ftp_debug and $html) echo '

'; + $ftp = new ftp($ftp_debug, $ftp_debug); + ftpupdate(); + if ($ftp_debug and $html) echo '

'; } else { + if ($html) echo '

'; - if ($html) echo '

'; - - echo "Last FTP update was ". round(((time() - $timestamp) / 60), 0) ." minutes ago, no update necessary\n"; - - if ($html) echo '

'; + echo "Last FTP update was ". round(((time() - $timestamp) / 60), 0) ." minutes ago, no update necessary\n"; + if ($html) echo '

'; } - - -?> \ No newline at end of file +?> -- cgit