diff options
author | Matthijs Kuiper <info@matthijskuiper.nl> | 2018-01-15 22:53:54 +0100 |
---|---|---|
committer | Matthijs Kuiper <info@matthijskuiper.nl> | 2018-09-01 11:51:41 +0200 |
commit | a00f7e8976ad5ec1be0128fe7ccdae2d0c43b619 (patch) | |
tree | f437e4f694400657995c6064266bc9bfe445684c | |
parent | 3457a490dc8c9d92d23c540964a4e2d965c1c464 (diff) |
ereg_match to preg_matchupdate-to-mysqli
-rw-r--r-- | html/includes/ftp.php | 505 | ||||
-rw-r--r-- | html/includes/ftp_class.php | 930 | ||||
-rw-r--r-- | html/includes/ftp_class_pure.php | 340 | ||||
-rw-r--r-- | html/includes/ftp_class_sockets.php | 456 | ||||
-rwxr-xr-x | html/includes/ftptimestamp.php | 2 | ||||
-rwxr-xr-x | html/includes/functions.php | 2 | ||||
-rw-r--r-- | html/pages/admin/acelog.php | 24 |
7 files changed, 1068 insertions, 1191 deletions
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 @@ -<?php
-
+<?php
//require_once('config.php');
DeBugMessage("Execute: includes/ftp.php\nUse ftp_type: $ftp_type");
if ($ftp_type == 'php') {
- require(dirname(__FILE__) . '/ftp_class_native.php');
-
+ require(dirname(__FILE__) . '/ftp_class_native.php');
} else {
-
- require(dirname(__FILE__) . '/ftp_class.php');
-
+ require(dirname(__FILE__) . '/ftp_class.php');
}
-
-
$g_ftp_error = false;
-
-
function ftp_error($message) {
+ global $html, $g_ftp_error, $ftp;
- global $html, $g_ftp_error, $ftp;
-
-
-
- $g_ftp_error = 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)";
-
- }
+ $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 '<tr>';
-
- echo '<td class="smheading" '. $style .' align="left" width="170">'. $left .'</td>';
+ if ($ftp_debug) return;
- echo '<td class="grey" '. $style .' align="left" width="380">'. $right .'</td>';
+ $space = ($html) ? ' ' : ' ';
- echo '</tr>';
+ $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 '<tr>';
+ echo '<td class="smheading" '. $style .' align="left" width="170">'. $left .'</td>';
+ echo '<td class="grey" '. $style .' align="left" width="380">'. $right .'</td>';
+ echo '</tr>';
+ } 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'<table class="zebra box" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed"><tr><td class="smheading" align="center" height="25" width="550" colspan="2">';
-
- echo "FTP Transferring Log Files...\n";
-
- if ($html) echo '</td></tr>';
-
- }
-
-
-
- // 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 '<tr><td class="" align="center" height="25" width="550" colspan="2"></td></tr>';
-
- 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'<table class="zebra box" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed"><tr><td class="smheading" align="center" height="25" width="550" colspan="2">';
- } else {
+ echo "FTP Transferring Log Files...\n";
- tablerow("", "Setting active mode");
+ if ($html) echo '</td></tr>';
+ }
- 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 '<tr><td align="center" height="25" width="550" colspan="2"></td></tr>';
- 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 '</table><br />';
-
- 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 '</table><br />';
+
+ 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 '<p class="pages">';
+ 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 '<p class="pages">';
-
- echo "Last FTP update more than $ftp_interval minutes ago, starting update ($ftp_type): \n";
-
- if ($html) echo '</p>';
+ if ($html) echo '</p>';
+ }
- }
+ if ($ftp_debug) {
+ if ($html) echo '<table class="box" border="0"><tr><td class="smheading" width="550">';
- if ($ftp_debug) {
+ echo "FTP Debugging Output:\n";
- if ($html) echo '<table class="box" border="0"><tr><td class="smheading" width="550">';
+ if ($html) echo '</td></tr><tr><td width="550" align="left"><pre>';
+ }
- echo "FTP Debugging Output:\n";
-
- if ($html) echo '</td></tr><tr><td width="550" align="left"><pre>';
-
- }
-
- $ftp = new ftp($ftp_debug, $ftp_debug);
-
- ftpupdate();
-
- if ($ftp_debug and $html) echo '</pre></td></tr></table><br />';
+ $ftp = new ftp($ftp_debug, $ftp_debug);
+ ftpupdate();
+ if ($ftp_debug and $html) echo '</pre></td></tr></table><br />';
} else {
+ if ($html) echo '<p class="pages">';
- if ($html) echo '<p class="pages">';
-
- echo "Last FTP update was ". round(((time() - $timestamp) / 60), 0) ." minutes ago, no update necessary\n";
-
- if ($html) echo '</p>';
+ echo "Last FTP update was ". round(((time() - $timestamp) / 60), 0) ." minutes ago, no update necessary\n";
+ if ($html) echo '</p>';
}
-
-
-?>
\ No newline at end of file +?>
diff --git a/html/includes/ftp_class.php b/html/includes/ftp_class.php index 5281379..02831d7 100644 --- a/html/includes/ftp_class.php +++ b/html/includes/ftp_class.php @@ -1,5 +1,5 @@ <?php
-//
+//
// pemftp - Class by Alexey Dotsenko <alex at paneuromedia dot com>
// http://www.phpclasses.org/browse/package/1743.html
// License: Free for non-commercial use
@@ -15,478 +15,494 @@ define('FTP_OS_Windows','w'); define('FTP_OS_Mac','m');
class ftp_base {
- /* Public variables */
- var $LocalEcho=FALSE;
- var $Verbose=FALSE;
- var $OS_local;
- var $lastmsg;
-
- /* Private variables */
- var $_lastaction=NULL;
- var $_errors;
- var $_type;
- var $_umask;
- var $_timeout;
- var $_passive;
- var $_host;
- var $_fullhost;
- var $_port;
- var $_datahost;
- var $_dataport;
- var $_ftp_control_sock;
- var $_ftp_data_sock;
- var $_ftp_temp_sock;
- var $_login;
- var $_password;
- var $_connected;
- var $_ready;
- var $_code;
- var $_message;
- var $_can_restore;
- var $_port_available;
-
- var $_error_array=array();
- var $AuthorizedTransferMode=array(
- FTP_AUTOASCII,
- FTP_ASCII,
- FTP_BINARY
- );
- var $OS_FullName=array(
- FTP_OS_Unix => 'UNIX',
- FTP_OS_Windows => 'WINDOWS',
- FTP_OS_Mac => 'MACOS'
- );
- var $NewLineCode=array(
- FTP_OS_Unix => "\n",
- FTP_OS_Mac => "\r",
- FTP_OS_Windows => "\r\n"
- );
- var $AutoAsciiExt=array("ASP","BAT","C","CPP","CSV","H","HTM","HTML","SHTML","INI","LOG","PHP","PHP3","PL","PERL","SH","SQL","TXT");
-
- /* Constructor */
- function ftp_base($port_mode=FALSE) {
- $this->_port_available=($port_mode==TRUE);
- $this->SendMSG("Staring FTP client class with".($this->_port_available?"":"out")." PORT mode support");
- $this->_connected=FALSE;
- $this->_ready=FALSE;
- $this->_can_restore=FALSE;
- $this->_code=0;
- $this->_message="";
- $this->SetUmask(0022);
- $this->SetType(FTP_AUTOASCII);
- $this->SetTimeout(30);
- $this->Passive(!$this->_port_available);
- $this->_login="anonymous";
- $this->_password="anon@ftp.com";
- $this->OS_local=FTP_OS_Unix;
- if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows;
- elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
- }
+ /* Public variables */
+ var $LocalEcho=FALSE;
+ var $Verbose=FALSE;
+ var $OS_local;
+ var $lastmsg;
+
+ /* Private variables */
+ var $_lastaction=NULL;
+ var $_errors;
+ var $_type;
+ var $_umask;
+ var $_timeout;
+ var $_passive;
+ var $_host;
+ var $_fullhost;
+ var $_port;
+ var $_datahost;
+ var $_dataport;
+ var $_ftp_control_sock;
+ var $_ftp_data_sock;
+ var $_ftp_temp_sock;
+ var $_login;
+ var $_password;
+ var $_connected;
+ var $_ready;
+ var $_code;
+ var $_message;
+ var $_can_restore;
+ var $_port_available;
+
+ var $_error_array=array();
+ var $AuthorizedTransferMode=array(
+ FTP_AUTOASCII,
+ FTP_ASCII,
+ FTP_BINARY
+ );
+ var $OS_FullName=array(
+ FTP_OS_Unix => 'UNIX',
+ FTP_OS_Windows => 'WINDOWS',
+ FTP_OS_Mac => 'MACOS'
+ );
+ var $NewLineCode=array(
+ FTP_OS_Unix => "\n",
+ FTP_OS_Mac => "\r",
+ FTP_OS_Windows => "\r\n"
+ );
+ var $AutoAsciiExt=array("ASP","BAT","C","CPP","CSV","H","HTM","HTML","SHTML","INI","LOG","PHP","PHP3","PL","PERL","SH","SQL","TXT");
+
+ /* Constructor */
+ function ftp_base($port_mode=FALSE) {
+ $this->_port_available=($port_mode==TRUE);
+ $this->SendMSG("Staring FTP client class with".($this->_port_available?"":"out")." PORT mode support");
+ $this->_connected=FALSE;
+ $this->_ready=FALSE;
+ $this->_can_restore=FALSE;
+ $this->_code=0;
+ $this->_message="";
+ $this->SetUmask(0022);
+ $this->SetType(FTP_AUTOASCII);
+ $this->SetTimeout(30);
+ $this->Passive(!$this->_port_available);
+ $this->_login="anonymous";
+ $this->_password="anon@ftp.com";
+ $this->OS_local=FTP_OS_Unix;
+ if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows;
+ elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
+ }
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Public functions -->
// <!-- --------------------------------------------------------------------------------------- -->
- function parselisting($list) {
-// Parses i line like: "drwxrwx--- 2 owner group 4096 Apr 23 14:57 text"
- if(preg_match("/^([-ld])([rwxst-]+)\s+(\d+)\s+(\w+)\s+(\w+)\s+(\d+)\s+(\w{3})\s+(\d+)\s+([\:\d]+)\s+(.+)$/i", $list, $ret)) {
- $v=array(
- "type" => ($ret[1]=="-"?"f":$ret[1]),
- "perms" => 0,
- "inode" => $ret[3],
- "owner" => $ret[4],
- "group" => $ret[5],
- "size" => $ret[6],
- "date" => $ret[7]." ".$ret[8]." ".$ret[9],
- "name" => $ret[10]
- );
- $v["perms"]+=00400*(int)($ret[2]{0}=="r");
- $v["perms"]+=00200*(int)($ret[2]{1}=="w");
- $v["perms"]+=00100*(int)in_array($ret[2]{2}, array("x","s"));
- $v["perms"]+=00040*(int)($ret[2]{3}=="r");
- $v["perms"]+=00020*(int)($ret[2]{4}=="w");
- $v["perms"]+=00010*(int)in_array($ret[2]{5}, array("x","s"));
- $v["perms"]+=00004*(int)($ret[2]{6}=="r");
- $v["perms"]+=00002*(int)($ret[2]{7}=="w");
- $v["perms"]+=00001*(int)in_array($ret[2]{8}, array("x","t"));
- $v["perms"]+=04000*(int)in_array($ret[2]{2}, array("S","s"));
- $v["perms"]+=02000*(int)in_array($ret[2]{5}, array("S","s"));
- $v["perms"]+=01000*(int)in_array($ret[2]{8}, array("T","t"));
- }
- return $v;
- }
-
- function SendMSG($message = "", $crlf=true) {
- $this->lastmsg = $message;
- if ($this->Verbose) {
- echo $message.($crlf?CRLF:"");
- flush();
- }
- return TRUE;
- }
-
- function SetType($mode=FTP_AUTOASCII) {
- if(!in_array($mode, $this->AuthorizedTransferMode)) {
- $this->SendMSG("Wrong type");
- return FALSE;
- }
- $this->_type=$mode;
- $this->SendMSG("Transfer type: ".($this->_type==FTP_BINARY?"binary":($this->_type==FTP_ASCII?"ASCII":"auto ASCII") ) );
- return TRUE;
- }
-
- function Passive($pasv=NULL) {
- if(is_null($pasv)) $this->_passive=!$this->_passive;
- else $this->_passive=$pasv;
- if(!$this->_port_available and !$this->_passive) {
- $this->SendMSG("Only passive connections available!");
- $this->_passive=TRUE;
- return FALSE;
- }
- $this->SendMSG("Passive mode ".($this->_passive?"on":"off"));
- return TRUE;
- }
-
- function SetServer($host, $port=21, $reconnect=true) {
- global $ftp_debug;
- if ($ftp_debug) {
- $this->verbose=true;
- $this->SendMSG("Connect to:<br>\n- Server: $host<br>\n- Port: $port<br>\n");
- $this->verbose=false;
- }
- $port = intval($port);
- if(!is_long($port)) {
- $this->verbose=true;
- $this->SendMSG("Incorrect port syntax");
- return FALSE;
- } else {
- $ip=@gethostbyname($host);
- $dns=@gethostbyaddr($host);
- if(!$ip) $ip=$host;
- if(!$dns) $dns=$host;
- if(ip2long($ip) === -1) {
- $this->SendMSG("Wrong host name/address \"".$host."\"");
- return FALSE;
- }
- $this->_host=$ip;
- $this->_fullhost=$dns;
- $this->_port=$port;
- $this->_dataport=$port-1;
- }
- $this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\"");
- if($reconnect){
- if($this->_connected) {
- $this->SendMSG("Reconnecting");
- if(!$this->quit(FTP_FORCE)) return FALSE;
- if(!$this->connect()) return FALSE;
- }
- }
- return TRUE;
- }
-
- function SetUmask($umask=0022) {
- $this->_umask=$umask;
- umask($this->_umask);
- $this->SendMSG("UMASK 0".decoct($this->_umask));
- return TRUE;
- }
-
- function SetTimeout($timeout=30) {
- $this->_timeout=$timeout;
- $this->SendMSG("Timeout ".$this->_timeout);
- if($this->_connected)
- if(!$this->_settimeout($this->_ftp_control_sock)) return FALSE;
- return TRUE;
- }
-
- function connect() {
- $this->SendMsg('Local OS : '.$this->OS_FullName[$this->OS_local]);
- if(!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) {
- $this->SendMSG("Error : Cannot connect to remote host \"".$this->_fullhost." :".$this->_port."\"");
- return FALSE;
- }
- $this->SendMSG("Connected to remote host \"".$this->_fullhost.":".$this->_port."\". Waiting for greeting.");
- do {
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- $this->_lastaction=time();
- } while($this->_code<200);
- $this->_ready=true;
- return TRUE;
- }
-
- function quit($force=false) {
- if($this->_ready) {
- if(!$this->_exec("QUIT") and !$force) return FALSE;
- if(!$this->_checkCode() and !$force) return FALSE;
- $this->_ready=false;
- $this->SendMSG("Session finished");
- }
- $this->_quit();
- return TRUE;
- }
-
- function login($user=NULL, $pass=NULL) {
- if(!is_null($user)) $this->_login=$user;
- else $this->_login="anonymous";
- if(!is_null($pass)) $this->_password=$pass;
- else $this->_password="anon@anon.com";
- if(!$this->_exec("USER ".$this->_login, "login")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- if($this->_code!=230) {
- if(!$this->_exec((($this->_code==331)?"PASS ":"ACCT ").$this->_password, "login")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- }
- $this->SendMSG("Authentication succeeded");
- $this->_can_restore=$this->restore(100);
- $this->SendMSG("This server can".($this->_can_restore?"":"'t")." resume broken uploads/downloads");
- return TRUE;
- }
-
- function pwd() {
- if(!$this->_exec("PWD", "pwd")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return ereg_replace("^[0-9]{3} \"(.+)\" .+".CRLF, "\\1", $this->_message);
- }
-
- function cdup() {
- if(!$this->_exec("CDUP", "cdup")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return true;
- }
-
- function chdir($pathname) {
- if(!$this->_exec("CWD ".$pathname, "chdir")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function rmdir($pathname) {
- if(!$this->_exec("RMD ".$pathname, "rmdir")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function mkdir($pathname) {
- if(!$this->_exec("MKD ".$pathname, "mkdir")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function rename($from, $to) {
- if(!$this->_exec("RNFR ".$from, "rename")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- if($this->_code==350) {
- if(!$this->_exec("RNTO ".$to, "rename")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- } else return FALSE;
- return TRUE;
- }
-
- function filesize($pathname) {
- if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);
- }
-
- function mdtm($pathname) {
- if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- $mdtm = ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);
- $date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
- $timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
- return $timestamp;
- }
-
- function systype() {
- if(!$this->_exec("SYST", "systype")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- $DATA = explode(" ", $this->_message);
- return $DATA[1];
- }
-
- function delete($pathname) {
- if(!$this->_exec("DELE ".$pathname, "delete")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function site($command, $fnction="site") {
- if(!$this->_exec("SITE ".$command, $fnction)) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function chmod($pathname, $mode) {
- if(!$this->site("CHMOD ".decoct($mode)." ".$pathname, "chmod")) return FALSE;
- return TRUE;
- }
-
- function restore($from) {
- if(!$this->_exec("REST ".$from, "resore")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function features() {
- if(!$this->_exec("FEAT", "features")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return preg_split("/[".CRLF."]+/", ereg_replace("[0-9]{3}[ -][^".CRLF."]*".CRLF, "", $this->_message), -1, PREG_SPLIT_NO_EMPTY);
- }
-
- function rawlist($arg="", $pathname="") {
- return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist");
- }
-
- function nlist($arg="", $pathname="") {
- return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
- }
-
- function is_exists($pathname)
- {
- if (!($remote_list = $this->nlist("-a", dirname($pathname)))) {
- $this->SendMSG("Error : Cannot get remote file list");
- return -1;
- }
- reset($remote_list);
- while (list(,$value) = each($remote_list)) {
- if ($value == basename($pathname)) {
- $this->SendMSG("Remote file ".$pathname." exists");
- return TRUE;
- }
- }
- $this->SendMSG("Remote file ".$pathname." does not exist");
- return FALSE;
- }
-
- function get($remotefile, $localfile=NULL) {
- if(is_null($localfile)) $localfile=$remotefile;
- if (@file_exists($localfile)) $this->SendMSG("Warning : local file will be overwritten");
- $fp = @fopen($localfile, "w");
- if (!$fp) {
- $this->PushError("get","can't open local file", "Cannot create \"".$localfile."\"");
- return FALSE;
- }
- $pi=pathinfo($remotefile);
- if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
- else $mode=FTP_BINARY;
- if(!$this->_data_prepare($mode)) {
- fclose($fp);
- return FALSE;
- }
- if($this->_can_restore) $this->restore(0);
- if(!$this->_exec("RETR ".$remotefile, "get")) {
- $this->_data_close();
- fclose($fp);
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- fclose($fp);
- return FALSE;
- }
- $out=$this->_data_read($mode, $fp);
- fclose($fp);
- $this->_data_close();
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return $out;
- }
-
- function put($localfile, $remotefile=NULL) {
- if(is_null($remotefile)) $remotefile=$localfile;
- if (!@file_exists($localfile)) {
- $this->PushError("put","can't open local file", "No such file or directory \"".$localfile."\"");
- return FALSE;
- }
- $fp = @fopen($localfile, "r");
- if (!$fp) {
- $this->PushError("put","can't open local file", "Cannot read file \"".$localfile."\"");
- return FALSE;
- }
- $pi=pathinfo($localfile);
- if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
- else $mode=FTP_BINARY;
- if(!$this->_data_prepare($mode)) {
- fclose($fp);
- return FALSE;
- }
- if($this->_can_restore) $this->restore(0);
- if(!$this->_exec("STOR ".$remotefile, "put")) {
- $this->_data_close();
- fclose($fp);
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- fclose($fp);
- return FALSE;
- }
- $ret=$this->_data_write($mode, $fp);
- fclose($fp);
- $this->_data_close();
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return $ret;
- }
+ function parselisting($list) {
+// Parses i line like: "drwxrwx--- 2 owner group 4096 Apr 23 14:57 text"
+ if(preg_match("/^([-ld])([rwxst-]+)\s+(\d+)\s+(\w+)\s+(\w+)\s+(\d+)\s+(\w{3})\s+(\d+)\s+([\:\d]+)\s+(.+)$/i", $list, $ret)) {
+ $v=array(
+ "type" => ($ret[1]=="-"?"f":$ret[1]),
+ "perms" => 0,
+ "inode" => $ret[3],
+ "owner" => $ret[4],
+ "group" => $ret[5],
+ "size" => $ret[6],
+ "date" => $ret[7]." ".$ret[8]." ".$ret[9],
+ "name" => $ret[10]
+ );
+ $v["perms"]+=00400*(int)($ret[2]{0}=="r");
+ $v["perms"]+=00200*(int)($ret[2]{1}=="w");
+ $v["perms"]+=00100*(int)in_array($ret[2]{2}, array("x","s"));
+ $v["perms"]+=00040*(int)($ret[2]{3}=="r");
+ $v["perms"]+=00020*(int)($ret[2]{4}=="w");
+ $v["perms"]+=00010*(int)in_array($ret[2]{5}, array("x","s"));
+ $v["perms"]+=00004*(int)($ret[2]{6}=="r");
+ $v["perms"]+=00002*(int)($ret[2]{7}=="w");
+ $v["perms"]+=00001*(int)in_array($ret[2]{8}, array("x","t"));
+ $v["perms"]+=04000*(int)in_array($ret[2]{2}, array("S","s"));
+ $v["perms"]+=02000*(int)in_array($ret[2]{5}, array("S","s"));
+ $v["perms"]+=01000*(int)in_array($ret[2]{8}, array("T","t"));
+ }
+ return $v;
+ }
+
+ function SendMSG($message = "", $crlf=true) {
+ $this->lastmsg = $message;
+ if ($this->Verbose) {
+ echo $message.($crlf?CRLF:"");
+ flush();
+ }
+ return TRUE;
+ }
+
+ function SetType($mode=FTP_AUTOASCII) {
+ if(!in_array($mode, $this->AuthorizedTransferMode)) {
+ $this->SendMSG("Wrong type");
+ return FALSE;
+ }
+ $this->_type=$mode;
+ $this->SendMSG("Transfer type: ".($this->_type==FTP_BINARY?"binary":($this->_type==FTP_ASCII?"ASCII":"auto ASCII") ) );
+ return TRUE;
+ }
+
+ function Passive($pasv=NULL) {
+ if(is_null($pasv)) $this->_passive=!$this->_passive;
+ else $this->_passive=$pasv;
+ if(!$this->_port_available and !$this->_passive) {
+ $this->SendMSG("Only passive connections available!");
+ $this->_passive=TRUE;
+ return FALSE;
+ }
+ $this->SendMSG("Passive mode ".($this->_passive?"on":"off"));
+ return TRUE;
+ }
+
+ function SetServer($host, $port=21, $reconnect=true) {
+ global $ftp_debug;
+ if ($ftp_debug) {
+ $this->verbose=true;
+ $this->SendMSG("Connect to:<br>\n- Server: $host<br>\n- Port: $port<br>\n");
+ $this->verbose=false;
+ }
+ $port = intval($port);
+ if(!is_long($port)) {
+ $this->verbose=true;
+ $this->SendMSG("Incorrect port syntax");
+ return FALSE;
+ } else {
+ $ip=@gethostbyname($host);
+ $dns=@gethostbyaddr($host);
+ if(!$ip) $ip=$host;
+ if(!$dns) $dns=$host;
+ if(ip2long($ip) === -1) {
+ $this->SendMSG("Wrong host name/address \"".$host."\"");
+ return FALSE;
+ }
+ $this->_host=$ip;
+ $this->_fullhost=$dns;
+ $this->_port=$port;
+ $this->_dataport=$port-1;
+ }
+ $this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\"");
+ if($reconnect){
+ if($this->_connected) {
+ $this->SendMSG("Reconnecting");
+ if(!$this->quit(FTP_FORCE)) return FALSE;
+ if(!$this->connect()) return FALSE;
+ }
+ }
+ return TRUE;
+ }
+
+ function SetUmask($umask=0022) {
+ $this->_umask=$umask;
+ umask($this->_umask);
+ $this->SendMSG("UMASK 0".decoct($this->_umask));
+ return TRUE;
+ }
+
+ function SetTimeout($timeout=30) {
+ $this->_timeout=$timeout;
+ $this->SendMSG("Timeout ".$this->_timeout);
+ if($this->_connected)
+ if(!$this->_settimeout($this->_ftp_control_sock)) return FALSE;
+ return TRUE;
+ }
+
+ function connect() {
+ $this->SendMsg('Local OS : '.$this->OS_FullName[$this->OS_local]);
+
+ if(!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) {
+ $this->SendMSG("Error : Cannot connect to remote host \"".$this->_fullhost.":".$this->_port."\"");
+ return FALSE;
+ }
+
+ $this->SendMSG("Connected to remote host \"".$this->_fullhost.":".$this->_port."\". Waiting for greeting.");
+
+ do {
+ if(!$this->_readmsg()) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ $this->_lastaction=time();
+ } while($this->_code < 200);
+
+ $this->_ready=true;
+
+ return TRUE;
+ }
+
+ function quit($force=false) {
+ if($this->_ready) {
+ if(!$this->_exec("QUIT") and !$force) return FALSE;
+ if(!$this->_checkCode() and !$force) return FALSE;
+ $this->_ready=false;
+ $this->SendMSG("Session finished");
+ }
+ $this->_quit();
+ return TRUE;
+ }
+
+ function login($user=NULL, $pass=NULL) {
+ if(!is_null($user)) $this->_login=$user;
+ else $this->_login="anonymous";
+ if(!is_null($pass)) $this->_password=$pass;
+ else $this->_password="anon@anon.com";
+ if(!$this->_exec("USER ".$this->_login, "login")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ if($this->_code!=230) {
+ if(!$this->_exec((($this->_code==331)?"PASS ":"ACCT ").$this->_password, "login")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ }
+ $this->SendMSG("Authentication succeeded");
+ $this->_can_restore=$this->restore(100);
+ $this->SendMSG("This server can".($this->_can_restore?"":"'t")." resume broken uploads/downloads");
+ return TRUE;
+ }
+
+ function pwd() {
+ if(!$this->_exec("PWD", "pwd")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+
+ // return ereg_replace("^[0-9]{3} \"(.+)\" .+".CRLF, "\\1", $this->_message);
+ preg_match('/([0-9]{3} ".+")/', $this->_message, $match);
+ return $match[1];
+ }
+
+ function cdup() {
+ if(!$this->_exec("CDUP", "cdup")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ return true;
+ }
+
+ function chdir($pathname) {
+ if(!$this->_exec("CWD ".$pathname, "chdir")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ return TRUE;
+ }
+
+ function rmdir($pathname) {
+ if(!$this->_exec("RMD ".$pathname, "rmdir")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ return TRUE;
+ }
+
+ function mkdir($pathname) {
+ if(!$this->_exec("MKD ".$pathname, "mkdir")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ return TRUE;
+ }
+
+ function rename($from, $to) {
+ if(!$this->_exec("RNFR ".$from, "rename")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ if($this->_code==350) {
+ if(!$this->_exec("RNTO ".$to, "rename")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ } else return FALSE;
+ return TRUE;
+ }
+
+ function filesize($pathname) {
+ if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+
+ // return ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);
+ preg_match('/^[0-9]{3} ([0-9]+)/', $message, $match);
+ return $match[1];
+ }
+
+ function mdtm($pathname) {
+ if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+
+ // $mdtm = ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\1", $this->_message);
+ // $date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
+ preg_match('/^[0-9]{3} ([0-9]+)/', $message, $match);
+ $date = sscanf($match[1], "%4d%2d%2d%2d%2d%2d");
+
+ $timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
+ return $timestamp;
+ }
+
+ function systype() {
+ if(!$this->_exec("SYST", "systype")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ $DATA = explode(" ", $this->_message);
+ return $DATA[1];
+ }
+
+ function delete($pathname) {
+ if(!$this->_exec("DELE ".$pathname, "delete")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ return TRUE;
+ }
+
+ function site($command, $fnction="site") {
+ if(!$this->_exec("SITE ".$command, $fnction)) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ return TRUE;
+ }
+
+ function chmod($pathname, $mode) {
+ if(!$this->site("CHMOD ".decoct($mode)." ".$pathname, "chmod")) return FALSE;
+ return TRUE;
+ }
+
+ function restore($from) {
+ if(!$this->_exec("REST ".$from, "resore")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ return TRUE;
+ }
+
+ function features() {
+ if(!$this->_exec("FEAT", "features")) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ // return preg_split("/[".CRLF."]+/", ereg_replace("[0-9]{3}[ -][^".CRLF."]*".CRLF, "", $this->_message), -1, PREG_SPLIT_NO_EMPTY);
+ return preg_split("/[".CRLF."]+/", preg_replace("/[0-9]{3}[ -].*[".CRLF."]+/", "", $this->_message), -1, PREG_SPLIT_NO_EMPTY);
+ }
+
+ function rawlist($arg="", $pathname="") {
+ return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist");
+ }
+
+ function nlist($arg="", $pathname="") {
+ return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
+ }
+
+ function is_exists($pathname)
+ {
+ if (!($remote_list = $this->nlist("-a", dirname($pathname)))) {
+ $this->SendMSG("Error : Cannot get remote file list");
+ return -1;
+ }
+ reset($remote_list);
+ while (list(,$value) = each($remote_list)) {
+ if ($value == basename($pathname)) {
+ $this->SendMSG("Remote file ".$pathname." exists");
+ return TRUE;
+ }
+ }
+ $this->SendMSG("Remote file ".$pathname." does not exist");
+ return FALSE;
+ }
+
+ function get($remotefile, $localfile=NULL) {
+ if(is_null($localfile)) $localfile=$remotefile;
+ if (@file_exists($localfile)) $this->SendMSG("Warning : local file will be overwritten");
+ $fp = @fopen($localfile, "w");
+ if (!$fp) {
+ $this->PushError("get","can't open local file", "Cannot create \"".$localfile."\"");
+ return FALSE;
+ }
+ $pi=pathinfo($remotefile);
+ if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
+ else $mode=FTP_BINARY;
+ if(!$this->_data_prepare($mode)) {
+ fclose($fp);
+ return FALSE;
+ }
+ if($this->_can_restore) $this->restore(0);
+ if(!$this->_exec("RETR ".$remotefile, "get")) {
+ $this->_data_close();
+ fclose($fp);
+ return FALSE;
+ }
+ if(!$this->_checkCode()) {
+ $this->_data_close();
+ fclose($fp);
+ return FALSE;
+ }
+ $out=$this->_data_read($mode, $fp);
+ fclose($fp);
+ $this->_data_close();
+ if(!$this->_readmsg()) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ return $out;
+ }
+
+ function put($localfile, $remotefile=NULL) {
+ if(is_null($remotefile)) $remotefile=$localfile;
+ if (!@file_exists($localfile)) {
+ $this->PushError("put","can't open local file", "No such file or directory \"".$localfile."\"");
+ return FALSE;
+ }
+ $fp = @fopen($localfile, "r");
+ if (!$fp) {
+ $this->PushError("put","can't open local file", "Cannot read file \"".$localfile."\"");
+ return FALSE;
+ }
+ $pi=pathinfo($localfile);
+ if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
+ else $mode=FTP_BINARY;
+ if(!$this->_data_prepare($mode)) {
+ fclose($fp);
+ return FALSE;
+ }
+ if($this->_can_restore) $this->restore(0);
+ if(!$this->_exec("STOR ".$remotefile, "put")) {
+ $this->_data_close();
+ fclose($fp);
+ return FALSE;
+ }
+ if(!$this->_checkCode()) {
+ $this->_data_close();
+ fclose($fp);
+ return FALSE;
+ }
+ $ret=$this->_data_write($mode, $fp);
+ fclose($fp);
+ $this->_data_close();
+ if(!$this->_readmsg()) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ return $ret;
+ }
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
- function _checkCode() {
- return ($this->_code<400 and $this->_code>0);
- }
-
- function _list($arg="", $cmd="LIST", $fnction="_list") {
- if(!$this->_data_prepare()) return FALSE;
- if(!$this->_exec($cmd.$arg, $fnction)) {
- $this->_data_close();
- return FALSE;
- }
- if($this->_code == 450 and $cmd == "NLST") return(array());
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- $out=$this->_data_read();
- $this->_data_close();
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- if($out === FALSE ) return FALSE;
- $out=preg_split("/[".CRLF."]+/", $out, -1, PREG_SPLIT_NO_EMPTY);
- $this->SendMSG(implode($this->NewLineCode[$this->OS_local], $out));
- return $out;
- }
+ function _checkCode() {
+ return ($this->_code<400 and $this->_code>0);
+ }
+
+ function _list($arg="", $cmd="LIST", $fnction="_list") {
+ if(!$this->_data_prepare()) return FALSE;
+ if(!$this->_exec($cmd.$arg, $fnction)) {
+ $this->_data_close();
+ return FALSE;
+ }
+ if($this->_code == 450 and $cmd == "NLST") return(array());
+ if(!$this->_checkCode()) {
+ $this->_data_close();
+ return FALSE;
+ }
+ $out=$this->_data_read();
+ $this->_data_close();
+ if(!$this->_readmsg()) return FALSE;
+ if(!$this->_checkCode()) return FALSE;
+ if($out === FALSE ) return FALSE;
+ $out=preg_split("/[".CRLF."]+/", $out, -1, PREG_SPLIT_NO_EMPTY);
+ $this->SendMSG(implode($this->NewLineCode[$this->OS_local], $out));
+ return $out;
+ }
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Partie : gestion des erreurs -->
// <!-- --------------------------------------------------------------------------------------- -->
// G�n�re une erreur pour traitement externe � la classe
- function PushError($fctname,$msg,$desc=false){
- $error=array();
- $error['time']=time();
- $error['fctname']=$fctname;
- $error['msg']=$msg;
- $error['desc']=$desc;
- if($desc) $tmp=' ('.$desc.')'; else $tmp='';
- $this->SendMSG($fctname.': '.$msg.$tmp);
- return(array_push($this->_error_array,$error));
- }
-
+ function PushError($fctname,$msg,$desc=false){
+ $error=array();
+ $error['time']=time();
+ $error['fctname']=$fctname;
+ $error['msg']=$msg;
+ $error['desc']=$desc;
+ if($desc) $tmp=' ('.$desc.')'; else $tmp='';
+ $this->SendMSG($fctname.': '.$msg.$tmp);
+ return(array_push($this->_error_array,$error));
+ }
+
// R�cup�re une erreur externe
- function PopError(){
- if(count($this->_error_array)) return(array_pop($this->_error_array));
- else return(false);
- }
+ function PopError(){
+ if(count($this->_error_array)) return(array_pop($this->_error_array));
+ else return(false);
+ }
}
if (isset($ftp_type) and $ftp_type == 'pure') {
- require_once "ftp_class_pure.php";
+ require_once "ftp_class_pure.php";
} else {
- $mod_sockets=TRUE;
- if (!extension_loaded('sockets')) {
- $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
- if(!@dl($prefix . 'sockets.' . PHP_SHLIB_SUFFIX)) $mod_sockets=FALSE;
- }
- require_once "ftp_class_".($mod_sockets?"sockets":"pure").".php";
+ $mod_sockets=TRUE;
+ if (!extension_loaded('sockets')) {
+ $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
+ if(!@dl($prefix . 'sockets.' . PHP_SHLIB_SUFFIX)) $mod_sockets=FALSE;
+ }
+ require_once "ftp_class_".($mod_sockets?"sockets":"pure").".php";
}
-?>
\ No newline at end of file +?>
diff --git a/html/includes/ftp_class_pure.php b/html/includes/ftp_class_pure.php index 4ec345e..9858c82 100644 --- a/html/includes/ftp_class_pure.php +++ b/html/includes/ftp_class_pure.php @@ -7,186 +7,190 @@ class ftp extends ftp_base {
- function ftp($verb=FALSE, $le=FALSE) {
- $this->LocalEcho = $le;
- $this->Verbose = $verb;
- $this->ftp_base();
- }
+ function ftp($verb=FALSE, $le=FALSE) {
+ $this->LocalEcho = $le;
+ $this->Verbose = $verb;
+ $this->ftp_base();
+ }
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
- function _settimeout($sock) {
- if(!@stream_set_timeout($sock, $this->_timeout)) {
- $this->PushError('_settimeout','socket set send timeout');
- $this->_quit();
- return FALSE;
- }
- return TRUE;
- }
+ function _settimeout($sock) {
+ if(!@stream_set_timeout($sock, $this->_timeout)) {
+ $this->PushError('_settimeout', 'socket set send timeout');
+ $this->_quit();
+ return FALSE;
+ }
+ return TRUE;
+ }
- function _connect($host, $port) {
- $this->SendMSG("NOT using PHP's socket extension");
- $this->SendMSG("Creating socket");
- $sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
- if (!$sock) {
- $this->PushError('_connect','socket connect failed', $errstr." (".$errno.")");
- return FALSE;
- }
- $this->_connected=true;
- return $sock;
- }
+ function _connect($host, $port) {
+ $this->SendMSG("NOT using PHP's socket extension");
+ $this->SendMSG("Creating socket");
+ $sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
+ if (!$sock) {
+ $this->PushError('_connect', 'socket connect failed', $errstr." (".$errno.")");
+ return FALSE;
+ }
+ $this->_connected=true;
+ return $sock;
+ }
- function _readmsg($fnction="_readmsg"){
- if(!$this->_connected) {
- $this->PushError($fnction, 'Connect first');
- return FALSE;
- }
- $result=true;
- $this->_message="";
- $this->_code=0;
- $go=true;
- do {
- $tmp=@my_fgets($this->_ftp_control_sock, 512);
- if($tmp===false) {
- $go=$result=false;
- $this->PushError($fnction,'Read failed');
- } else {
- $this->_message.=$tmp;
-// for($i=0; $i<strlen($this->_message); $i++)
-// if(ord($this->_message[$i])<32) echo "#".ord($this->_message[$i]); else echo $this->_message[$i];
-// echo CRLF;
- if(preg_match("/^([0-9]{3})(-(.*".CRLF.")+\\1)? [^".CRLF."]+".CRLF."$/", $this->_message, $regs)) $go=false;
- }
- } while($go);
- if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
- $this->_code=(int)$regs[1];
- return $result;
- }
+ function _readmsg($fnction="_readmsg"){
+ if(!$this->_connected) {
+ $this->PushError($fnction, 'Connect first');
+ return FALSE;
+ }
+ $result=true;
+ $this->_message="";
+ $this->_code=0;
+ $go=true;
+ do {
+ $tmp=@my_fgets($this->_ftp_control_sock, 512);
+ if($tmp===false) {
+ $go=$result=false;
+ $this->PushError($fnction, 'Read failed');
+ } else {
+ $this->_message.=$tmp;
+// for($i=0; $i<strlen($this->_message); $i++)
+// if(ord($this->_message[$i])<32) echo "#".ord($this->_message[$i]); else echo $this->_message[$i];
+// echo CRLF;
+ if (preg_match("/^([0-9]{3})(-(.*".CRLF.")+\\1)? [^".CRLF."]+".CRLF."$/", $this->_message, $regs)) $go=false;
+ }
+ } while($go);
+ if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
+ $this->_code=(int)$regs[1];
+ return $result;
+ }
- function _exec($cmd, $fnction="_exec") {
- if(!$this->_ready) {
- $this->PushError($fnction,'Connect first');
- return FALSE;
- }
- if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
- $status=@fputs($this->_ftp_control_sock, $cmd.CRLF);
- if($status===false) {
- $this->PushError($fnction,'socket write failed');
- return FALSE;
- }
- $this->_lastaction=time();
- if(!$this->_readmsg($fnction)) return FALSE;
- return TRUE;
- }
+ function _exec($cmd, $fnction="_exec") {
+ if(!$this->_ready) {
+ $this->PushError($fnction,'Connect first');
+ return FALSE;
+ }
+ if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
+ $status=@fputs($this->_ftp_control_sock, $cmd.CRLF);
+ if($status===false) {
+ $this->PushError($fnction,'socket write failed');
+ return FALSE;
+ }
+ $this->_lastaction=time();
+ if(!$this->_readmsg($fnction)) return FALSE;
+ return TRUE;
+ }
- function _data_prepare($mode=FTP_ASCII) {
- if($mode==FTP_BINARY) {
- if(!$this->_exec("TYPE I", "_data_prepare")) return FALSE;
- } else {
- if(!$this->_exec("TYPE A", "_data_prepare")) return FALSE;
- }
- if($this->_passive) {
- if(!$this->_exec("PASV", "pasv")) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- $ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\1", $this->_message));
- $this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
- $this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
- $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
- $this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout);
- if(!$this->_ftp_data_sock) {
- $this->PushError("_data_prepare","fsockopen fails", $errstr." (".$errno.")");
- $this->_data_close();
- return FALSE;
- }
- else $this->_ftp_data_sock;
- } else {
- $this->SendMSG("Only passive connections available!");
- return FALSE;
- }
- return TRUE;
- }
+ function _data_prepare($mode=FTP_ASCII) {
+ if($mode==FTP_BINARY) {
+ if(!$this->_exec("TYPE I", "_data_prepare")) return FALSE;
+ } else {
+ if(!$this->_exec("TYPE A", "_data_prepare")) return FALSE;
+ }
+ if($this->_passive) {
+ if(!$this->_exec("PASV", "pasv")) {
+ $this->_data_close();
+ return FALSE;
+ }
+ if(!$this->_checkCode()) {
+ $this->_data_close();
+ return FALSE;
+ }
- function _data_read($mode=FTP_ASCII, $fp=NULL) {
- $NewLine=$this->NewLineCode[$this->OS_local];
- if(is_resource($fp)) $out=0;
- else $out="";
- if(!$this->_passive) {
- $this->SendMSG("Only passive connections available!");
- return FALSE;
- }
- if($mode!=FTP_BINARY) {
- while (!feof($this->_ftp_data_sock)) {
- $tmp=fread($this->_ftp_data_sock, 4096);
- $line.=$tmp;
- if(!preg_match("/".CRLF."$/", $line)) continue;
- $line=rtrim($line,CRLF).$NewLine;
- if(is_resource($fp)) $out+=fwrite($fp, $line, strlen($line));
- else $out.=$line;
- $line="";
- }
- } else {
- while (!feof($this->_ftp_data_sock)) {
- $block=fread($this->_ftp_data_sock, 4096);
- if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
- else $out.=$line;
- }
- }
- return $out;
- }
+ // $ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\1", $this->_message));
+ preg_match("/\((.*?)\)/", $this->_message, $match);
+ $ip_port = explode(",", $match[1]);
- function _data_write($mode=FTP_ASCII, $fp=NULL) {
- $NewLine=$this->NewLineCode[$this->OS_local];
- if(is_resource($fp)) $out=0;
- else $out="";
- if(!$this->_passive) {
- $this->SendMSG("Only passive connections available!");
- return FALSE;
- }
- if(is_resource($fp)) {
- while(!feof($fp)) {
- $line=my_fgets($fp, 4096);
- if($mode!=FTP_BINARY) $line=rtrim($line, CRLF).CRLF;
- do {
- if(($res=@fwrite($this->_ftp_data_sock, $line))===FALSE) {
- $this->PushError("_data_write","Can't write to socket");
- return FALSE;
- }
- $line=substr($line, $res);
- }while($line!="");
- }
- } else {
- if($mode!=FTP_BINARY) $fp=rtrim($fp, $NewLine).CRLF;
- do {
- if(($res=@fwrite($this->_ftp_data_sock, $fp))===FALSE) {
- $this->PushError("_data_write","Can't write to socket");
- return FALSE;
- }
- $fp=substr($fp, $res);
- }while($fp!="");
- }
- return TRUE;
- }
+ $this->_datahost = $ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
+ $this->_dataport = (((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
+ $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
+ $this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout);
+ if(!$this->_ftp_data_sock) {
+ $this->PushError("_data_prepare", "fsockopen fails", $errstr." (".$errno.")");
+ $this->_data_close();
+ return FALSE;
+ }
+ else $this->_ftp_data_sock;
+ } else {
+ $this->SendMSG("Only passive connections available!");
+ return FALSE;
+ }
+ return TRUE;
+ }
- function _data_close() {
- @fclose($this->_ftp_data_sock);
- $this->SendMSG("Disconnected data from remote host");
- return TRUE;
- }
+ function _data_read($mode=FTP_ASCII, $fp=NULL) {
+ $NewLine=$this->NewLineCode[$this->OS_local];
+ if(is_resource($fp)) $out=0;
+ else $out="";
+ if(!$this->_passive) {
+ $this->SendMSG("Only passive connections available!");
+ return FALSE;
+ }
+ if($mode!=FTP_BINARY) {
+ while (!feof($this->_ftp_data_sock)) {
+ $tmp=fread($this->_ftp_data_sock, 4096);
+ $line.=$tmp;
+ if(!preg_match("/".CRLF."$/", $line)) continue;
+ $line=rtrim($line,CRLF).$NewLine;
+ if(is_resource($fp)) $out+=fwrite($fp, $line, strlen($line));
+ else $out.=$line;
+ $line="";
+ }
+ } else {
+ while (!feof($this->_ftp_data_sock)) {
+ $block=fread($this->_ftp_data_sock, 4096);
+ if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
+ else $out.=$line;
+ }
+ }
+ return $out;
+ }
- function _quit($force=FALSE) {
- if($this->_connected or $force) {
- @fclose($this->_ftp_control_sock);
- $this->_connected=false;
- $this->SendMSG("Socket closed");
- }
- }
+ function _data_write($mode=FTP_ASCII, $fp=NULL) {
+ $NewLine=$this->NewLineCode[$this->OS_local];
+ if(is_resource($fp)) $out=0;
+ else $out="";
+ if(!$this->_passive) {
+ $this->SendMSG("Only passive connections available!");
+ return FALSE;
+ }
+ if(is_resource($fp)) {
+ while(!feof($fp)) {
+ $line=my_fgets($fp, 4096);
+ if($mode!=FTP_BINARY) $line=rtrim($line, CRLF).CRLF;
+ do {
+ if(($res=@fwrite($this->_ftp_data_sock, $line))===FALSE) {
+ $this->PushError("_data_write","Can't write to socket");
+ return FALSE;
+ }
+ $line=substr($line, $res);
+ }while($line!="");
+ }
+ } else {
+ if($mode!=FTP_BINARY) $fp=rtrim($fp, $NewLine).CRLF;
+ do {
+ if(($res=@fwrite($this->_ftp_data_sock, $fp))===FALSE) {
+ $this->PushError("_data_write","Can't write to socket");
+ return FALSE;
+ }
+ $fp=substr($fp, $res);
+ }while($fp!="");
+ }
+ return TRUE;
+ }
+
+ function _data_close() {
+ @fclose($this->_ftp_data_sock);
+ $this->SendMSG("Disconnected data from remote host");
+ return TRUE;
+ }
+
+ function _quit($force=FALSE) {
+ if($this->_connected or $force) {
+ @fclose($this->_ftp_control_sock);
+ $this->_connected=false;
+ $this->SendMSG("Socket closed");
+ }
+ }
}
?>
diff --git a/html/includes/ftp_class_sockets.php b/html/includes/ftp_class_sockets.php index 8cfd27f..71faab2 100644 --- a/html/includes/ftp_class_sockets.php +++ b/html/includes/ftp_class_sockets.php @@ -1,5 +1,5 @@ <?php
-//
+//
// pemftp - Class by Alexey Dotsenko <alex at paneuromedia dot com>
// http://www.phpclasses.org/browse/package/1743.html
// License: Free for non-commercial use
@@ -7,243 +7,247 @@ class ftp extends ftp_base {
- function ftp($verb=FALSE, $le=FALSE) {
- $this->LocalEcho = $le;
- $this->Verbose = $verb;
- $this->ftp_base(TRUE);
- }
+ function ftp($verb=FALSE, $le=FALSE) {
+ $this->LocalEcho = $le;
+ $this->Verbose = $verb;
+ $this->ftp_base(TRUE);
+ }
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->
- function _settimeout($sock) {
- if(!@socket_set_option($sock, 1, SO_RCVTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
- $this->PushError('_connect','socket set receive timeout',socket_strerror(socket_last_error($sock)));
- @socket_close($sock);
- return FALSE;
- }
- if(!@socket_set_option($sock, 1, SO_SNDTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
- $this->PushError('_connect','socket set send timeout',socket_strerror(socket_last_error($sock)));
- @socket_close($sock);
- return FALSE;
- }
- return true;
- }
+ function _settimeout($sock) {
+ if(!@socket_set_option($sock, 1, SO_RCVTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
+ $this->PushError('_connect','socket set receive timeout',socket_strerror(socket_last_error($sock)));
+ @socket_close($sock);
+ return FALSE;
+ }
+ if(!@socket_set_option($sock, 1, SO_SNDTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
+ $this->PushError('_connect','socket set send timeout',socket_strerror(socket_last_error($sock)));
+ @socket_close($sock);
+ return FALSE;
+ }
+ return true;
+ }
+
+ function _connect($host, $port) {
+ $this->SendMSG("Using PHP's socket extension");
+ $this->SendMSG("Creating socket");
+ $sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+ if ($sock < 0) {
+ $this->PushError('_connect','socket create failed',socket_strerror(socket_last_error($sock)));
+ return FALSE;
+ }
+ if(!$this->_settimeout($sock)) return FALSE;
+ $this->SendMSG("Connecting to \"".$host.":".$port."\"");
+ if (!($res = @socket_connect($sock, $host, $port))) {
+ $this->PushError('_connect','socket connect failed',socket_strerror(socket_last_error($sock)));
+ @socket_close($sock);
+ return FALSE;
+ }
+ $this->_connected=true;
+ return $sock;
+ }
+
+ function _readmsg($fnction="_readmsg"){
+ if(!$this->_connected) {
+ $this->PushError($fnction,'Connect first');
+ return FALSE;
+ }
+ $result=true;
+ $this->_message="";
+ $this->_code=0;
+ $go=true;
+ do {
+ $tmp=@socket_read($this->_ftp_control_sock, 4096, PHP_BINARY_READ);
+ if($tmp===false) {
+ $go=$result=false;
+ $this->PushError($fnction,'Read failed', socket_strerror(socket_last_error($this->_ftp_control_sock)));
+ } elseif($tmp=="") $go=false;
+ else {
+ $this->_message.=$tmp;
+// for($i=0; $i<strlen($this->_message); $i++)
+// if(ord($this->_message[$i])<32) echo "#".ord($this->_message[$i]); else echo $this->_message[$i];
+// echo CRLF;
+ if(preg_match("/^([0-9]{3})(-(.*".CRLF.")+\\1)? [^".CRLF."]+".CRLF."$/", $this->_message, $regs)) $go=false;
+ }
+ } while($go);
+ if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
+ $this->_code=(int)$regs[1];
+ return $result;
+ }
- function _connect($host, $port) {
- $this->SendMSG("Using PHP's socket extension");
- $this->SendMSG("Creating socket");
- $sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- if ($sock < 0) {
- $this->PushError('_connect','socket create failed',socket_strerror(socket_last_error($sock)));
- return FALSE;
- }
- if(!$this->_settimeout($sock)) return FALSE;
- $this->SendMSG("Connecting to \"".$host.":".$port."\"");
- if (!($res = @socket_connect($sock, $host, $port))) {
- $this->PushError('_connect','socket connect failed',socket_strerror(socket_last_error($sock)));
- @socket_close($sock);
- return FALSE;
- }
- $this->_connected=true;
- return $sock;
- }
+ function _exec($cmd, $fnction="_exec") {
+ if(!$this->_ready) {
+ $this->PushError($fnction,'Connect first');
+ return FALSE;
+ }
+ if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
+ $status=@socket_write($this->_ftp_control_sock, $cmd.CRLF);
+ if($status===false) {
+ $this->PushError($fnction,'socket write failed', socket_strerror(socket_last_error($this->stream)));
+ return FALSE;
+ }
+ $this->_lastaction=time();
+ if(!$this->_readmsg($fnction)) return FALSE;
+ return TRUE;
+ }
- function _readmsg($fnction="_readmsg"){
- if(!$this->_connected) {
- $this->PushError($fnction,'Connect first');
- return FALSE;
- }
- $result=true;
- $this->_message="";
- $this->_code=0;
- $go=true;
- do {
- $tmp=@socket_read($this->_ftp_control_sock, 4096, PHP_BINARY_READ);
- if($tmp===false) {
- $go=$result=false;
- $this->PushError($fnction,'Read failed', socket_strerror(socket_last_error($this->_ftp_control_sock)));
- } elseif($tmp=="") $go=false;
- else {
- $this->_message.=$tmp;
-// for($i=0; $i<strlen($this->_message); $i++)
-// if(ord($this->_message[$i])<32) echo "#".ord($this->_message[$i]); else echo $this->_message[$i];
-// echo CRLF;
- if(preg_match("/^([0-9]{3})(-(.*".CRLF.")+\\1)? [^".CRLF."]+".CRLF."$/", $this->_message, $regs)) $go=false;
- }
- } while($go);
- if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
- $this->_code=(int)$regs[1];
- return $result;
- }
+ function _data_prepare($mode=FTP_ASCII) {
+ if($mode==FTP_BINARY) {
+ if(!$this->_exec("TYPE I", "_data_prepare")) return FALSE;
+ } else {
+ if(!$this->_exec("TYPE A", "_data_prepare")) return FALSE;
+ }
+ $this->SendMSG("Creating data socket");
+ $this->_ftp_data_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+ if ($this->_ftp_data_sock < 0) {
+ $this->PushError('_data_prepare', 'socket create failed', socket_strerror(socket_last_error($this->_ftp_data_sock)));
+ return FALSE;
+ }
+ if(!$this->_settimeout($this->_ftp_data_sock)) {
+ $this->_data_close();
+ return FALSE;
+ }
+ if($this->_passive) {
+ if(!$this->_exec("PASV", "pasv")) {
+ $this->_data_close();
+ return FALSE;
+ }
+ if(!$this->_checkCode()) {
+ $this->_data_close();
+ return FALSE;
+ }
- function _exec($cmd, $fnction="_exec") {
- if(!$this->_ready) {
- $this->PushError($fnction,'Connect first');
- return FALSE;
- }
- if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
- $status=@socket_write($this->_ftp_control_sock, $cmd.CRLF);
- if($status===false) {
- $this->PushError($fnction,'socket write failed', socket_strerror(socket_last_error($this->stream)));
- return FALSE;
- }
- $this->_lastaction=time();
- if(!$this->_readmsg($fnction)) return FALSE;
- return TRUE;
- }
+ // $ip_port = explode(",", preg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\1", $this->_message));
+ preg_match("/\((.*?)\)/", $this->_message, $match);
+ $ip_port = explode(",", $match[1]);
- function _data_prepare($mode=FTP_ASCII) {
- if($mode==FTP_BINARY) {
- if(!$this->_exec("TYPE I", "_data_prepare")) return FALSE;
- } else {
- if(!$this->_exec("TYPE A", "_data_prepare")) return FALSE;
- }
- $this->SendMSG("Creating data socket");
- $this->_ftp_data_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- if ($this->_ftp_data_sock < 0) {
- $this->PushError('_data_prepare','socket create failed',socket_strerror(socket_last_error($this->_ftp_data_sock)));
- return FALSE;
- }
- if(!$this->_settimeout($this->_ftp_data_sock)) {
- $this->_data_close();
- return FALSE;
- }
- if($this->_passive) {
- if(!$this->_exec("PASV", "pasv")) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- $ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\1", $this->_message));
- $this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
+ $this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
$this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
- $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
- if(!@socket_connect($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
- $this->PushError("_data_prepare","socket_connect", socket_strerror(socket_last_error($this->_ftp_data_sock)));
- $this->_data_close();
- return FALSE;
- }
- else $this->_ftp_temp_sock=$this->_ftp_data_sock;
- } else {
- if(!@socket_getsockname($this->_ftp_control_sock, $addr, $port)) {
- $this->PushError("_data_prepare","can't get control socket information", socket_strerror(socket_last_error($this->_ftp_control_sock)));
- $this->_data_close();
- return FALSE;
- }
- if(!@socket_bind($this->_ftp_data_sock,$addr)){
- $this->PushError("_data_prepare","can't bind data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
- $this->_data_close();
- return FALSE;
- }
- if(!@socket_listen($this->_ftp_data_sock)) {
- $this->PushError("_data_prepare","can't listen data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
- $this->_data_close();
- return FALSE;
- }
- if(!@socket_getsockname($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
- $this->PushError("_data_prepare","can't get data socket information", socket_strerror(socket_last_error($this->_ftp_data_sock)));
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_exec('PORT '.str_replace('.',',',$this->_datahost.'.'.($this->_dataport>>8).'.'.($this->_dataport&0x00FF)), "_port")) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- }
- return TRUE;
- }
+ $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
+ if(!@socket_connect($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
+ $this->PushError("_data_prepare", "socket_connect", socket_strerror(socket_last_error($this->_ftp_data_sock)));
+ $this->_data_close();
+ return FALSE;
+ }
+ else $this->_ftp_temp_sock=$this->_ftp_data_sock;
+ } else {
+ if(!@socket_getsockname($this->_ftp_control_sock, $addr, $port)) {
+ $this->PushError("_data_prepare", "can't get control socket information", socket_strerror(socket_last_error($this->_ftp_control_sock)));
+ $this->_data_close();
+ return FALSE;
+ }
+ if(!@socket_bind($this->_ftp_data_sock,$addr)){
+ $this->PushError("_data_prepare", "can't bind data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
+ $this->_data_close();
+ return FALSE;
+ }
+ if(!@socket_listen($this->_ftp_data_sock)) {
+ $this->PushError("_data_prepare", "can't listen data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
+ $this->_data_close();
+ return FALSE;
+ }
+ if(!@socket_getsockname($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
+ $this->PushError("_data_prepare", "can't get data socket information", socket_strerror(socket_last_error($this->_ftp_data_sock)));
+ $this->_data_close();
+ return FALSE;
+ }
+ if(!$this->_exec('PORT '.str_replace('.',',',$this->_datahost.'.'.($this->_dataport>>8).'.'.($this->_dataport&0x00FF)), "_port")) {
+ $this->_data_close();
+ return FALSE;
+ }
+ if(!$this->_checkCode()) {
+ $this->_data_close();
+ return FALSE;
+ }
+ }
+ return TRUE;
+ }
- function _data_read($mode=FTP_ASCII, $fp=NULL) {
- $NewLine=$this->NewLineCode[$this->OS_local];
- if(is_resource($fp)) $out=0;
- else $out="";
- if(!$this->_passive) {
- $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
- $this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
- if($this->_ftp_temp_sock===FALSE) {
- $this->PushError("_data_read","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
- $this->_data_close();
- return FALSE;
- }
- }
- if($mode!=FTP_BINARY) {
- while(($tmp=@socket_read($this->_ftp_temp_sock, 8192, PHP_NORMAL_READ))!==false) {
- $line.=$tmp;
- if(!preg_match("/".CRLF."$/", $line)) continue;
- $line=rtrim($line,CRLF).$NewLine;
- if(is_resource($fp)) $out+=fwrite($fp, $line, strlen($line));
- else $out.=$line;
- $line="";
- }
- } else {
- while($block=@socket_read($this->_ftp_temp_sock, 8192, PHP_BINARY_READ)) {
- if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
- else $out.=$line;
- }
- }
- return $out;
- }
+ function _data_read($mode=FTP_ASCII, $fp=NULL) {
+ $NewLine=$this->NewLineCode[$this->OS_local];
+ if(is_resource($fp)) $out=0;
+ else $out="";
+ if(!$this->_passive) {
+ $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
+ $this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
+ if($this->_ftp_temp_sock===FALSE) {
+ $this->PushError("_data_read","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
+ $this->_data_close();
+ return FALSE;
+ }
+ }
+ if($mode!=FTP_BINARY) {
+ while(($tmp=@socket_read($this->_ftp_temp_sock, 8192, PHP_NORMAL_READ))!==false) {
+ $line.=$tmp;
+ if(!preg_match("/".CRLF."$/", $line)) continue;
+ $line=rtrim($line,CRLF).$NewLine;
+ if(is_resource($fp)) $out+=fwrite($fp, $line, strlen($line));
+ else $out.=$line;
+ $line="";
+ }
+ } else {
+ while($block=@socket_read($this->_ftp_temp_sock, 8192, PHP_BINARY_READ)) {
+ if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
+ else $out.=$line;
+ }
+ }
+ return $out;
+ }
- function _data_write($mode=FTP_ASCII, $fp=NULL) {
- $NewLine=$this->NewLineCode[$this->OS_local];
- if(is_resource($fp)) $out=0;
- else $out="";
- if(!$this->_passive) {
- $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
- $this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
- if($this->_ftp_temp_sock===FALSE) {
- $this->PushError("_data_write","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
- $this->_data_close();
- return FALSE;
- }
- }
- if(is_resource($fp)) {
- while(!feof($fp)) {
- $line=my_fgets($fp, 4096);
- if($mode!=FTP_BINARY) $line=rtrim($line, CRLF).CRLF;
- do {
- if(($res=@socket_write($this->_ftp_temp_sock, $line))===FALSE) {
- $this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
- return FALSE;
- }
- $line=substr($line, $res);
- }while($line!="");
- }
- } else {
- if($mode!=FTP_BINARY) $fp=rtrim($fp, $NewLine).CRLF;
- do {
- if(($res=@socket_write($this->_ftp_temp_sock, $fp))===FALSE) {
- $this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
- return FALSE;
- }
- $fp=substr($fp, $res);
- }while($fp!="");
- }
- return TRUE;
- }
+ function _data_write($mode=FTP_ASCII, $fp=NULL) {
+ $NewLine=$this->NewLineCode[$this->OS_local];
+ if(is_resource($fp)) $out=0;
+ else $out="";
+ if(!$this->_passive) {
+ $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
+ $this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
+ if($this->_ftp_temp_sock===FALSE) {
+ $this->PushError("_data_write","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
+ $this->_data_close();
+ return FALSE;
+ }
+ }
+ if(is_resource($fp)) {
+ while(!feof($fp)) {
+ $line=my_fgets($fp, 4096);
+ if($mode!=FTP_BINARY) $line=rtrim($line, CRLF).CRLF;
+ do {
+ if(($res=@socket_write($this->_ftp_temp_sock, $line))===FALSE) {
+ $this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
+ return FALSE;
+ }
+ $line=substr($line, $res);
+ }while($line!="");
+ }
+ } else {
+ if($mode!=FTP_BINARY) $fp=rtrim($fp, $NewLine).CRLF;
+ do {
+ if(($res=@socket_write($this->_ftp_temp_sock, $fp))===FALSE) {
+ $this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
+ return FALSE;
+ }
+ $fp=substr($fp, $res);
+ }while($fp!="");
+ }
+ return TRUE;
+ }
- function _data_close() {
- @socket_close($this->_ftp_temp_sock);
- @socket_close($this->_ftp_data_sock);
- $this->SendMSG("Disconnected data from remote host");
- return TRUE;
- }
+ function _data_close() {
+ @socket_close($this->_ftp_temp_sock);
+ @socket_close($this->_ftp_data_sock);
+ $this->SendMSG("Disconnected data from remote host");
+ return TRUE;
+ }
- function _quit() {
- if($this->_connected) {
- @socket_close($this->_ftp_control_sock);
- $this->_connected=false;
- $this->SendMSG("Socket closed");
- }
- }
+ function _quit() {
+ if($this->_connected) {
+ @socket_close($this->_ftp_control_sock);
+ $this->_connected=false;
+ $this->SendMSG("Socket closed");
+ }
+ }
}
-?>
\ No newline at end of file +?>
diff --git a/html/includes/ftptimestamp.php b/html/includes/ftptimestamp.php index c19396a..5b0132c 100755 --- a/html/includes/ftptimestamp.php +++ b/html/includes/ftptimestamp.php @@ -1 +1 @@ -1512939605
\ No newline at end of file +1516061474
\ No newline at end of file diff --git a/html/includes/functions.php b/html/includes/functions.php index cefc1cc..d0be5b7 100755 --- a/html/includes/functions.php +++ b/html/includes/functions.php @@ -28,7 +28,7 @@ srand(microtime() * 1000); $charimg = $charimages[rand(0, count($charimages)-1)];
// Two letter codes and their corresponding country names
-require_once(dirname(__FILE__) .'/countries.php');
+require_once(dirname(__FILE__) . '/countries.php');
// Addslashes if magic_quotes are off
function my_addslashes($data) {
diff --git a/html/pages/admin/acelog.php b/html/pages/admin/acelog.php index 31f98e8..e57c4d7 100644 --- a/html/pages/admin/acelog.php +++ b/html/pages/admin/acelog.php @@ -72,7 +72,6 @@ if (!empty($filename)) { if (empty($filename)) {
echo '
-
<script language = "javascript">
function timefilter() {
@@ -89,13 +88,13 @@ if (empty($filename)) { }
}
</script>
- <form name = "filter">
- <table class = "box" border="0" cellpadding="0" cellspacing="0" width="720">
+ <form name="filter">
+ <table class="box" border="0" cellpadding="0" cellspacing="0" width="720">
<tr>
<td class="heading" align="center" width="100%" colspan="5">Available ACE Logs:</td>
</tr>
<tr>
- <td class="smheading" align="center" width="100%" colspan = "5">Filter:
+ <td class="smheading" align="center" width="100%" colspan="5">Filter:
<select onchange = "javascript:timefilter()" name = "show">
<option value = "all"'.($show == "all" ? ' selected=selected' : '').'>All</option>
<option value = "day"'.($show == "day" ? ' selected=selected' : '').'>Last day</option>
@@ -118,8 +117,11 @@ if (empty($filename)) { if (!is_file('logs/ace/'. $filename)) continue;
if ($filename == '.htaccess' or $filename == 'index.htm') continue;
- preg_match('/\d{4}\.\d{2}.\d{2}.\d{2}.\d{2}.\d{2}/', $filename, &$date);
- $adate = preg_split('/\./', $date[0]);
+ // ereg_match('/\d{4}\.\d{2}.\d{2}.\d{2}.\d{2}.\d{2}/', $filename, &$date);
+ // $adate = preg_split('/\./', $date[0]);
+ preg_match('/\d{4}\.\d{2}.\d{2}.\d{2}.\d{2}.\d{2}/', $filename, $date);
+ $adate = explode(".", $date[0]);
+
// filter on days
if ($show != "all") {
// calculate days
@@ -135,6 +137,7 @@ if (empty($filename)) { $TimeStamp = "unknown";
$PlayerName = "unknown";
$KickReason = "unknown";
+
if (substr($filename, strlen($filename) - strlen($import_ace_screenshot_extension)) == $import_ace_screenshot_extension
and substr($filename, 0, strlen($import_ace_screenshot_start)) == $import_ace_screenshot_start) {
// Screenshot
@@ -144,8 +147,9 @@ if (empty($filename)) { }
else {
// logfile
+ $compression = null;
+ $fp = my_fopen("logs/ace/" . $filename, "rb", $compression);
- $fp = my_fopen('logs/ace/'.$filename, 'rb', $compression = NULL);
if (!$fp) die("Error opening file");
while (($line = my_fgets($fp, 5000, $compression)) !== FALSE) {
@@ -233,7 +237,7 @@ if (empty($filename)) { $tmp = substr($log, strlen($log) - (23 + $extra), 19);
$tmp = str_replace('.', '', $tmp);
// $ts = mtimestamp($tmp);
- echo ' <a class="'.$class.'" href="admin.php?key='.$adminkey.'&action='.$action.'&filename='.urlencode($log).'">'.$TimeStamp.'</a>';
+ echo '<a class="'.$class.'" href="admin.php?key='.$adminkey.'&action='.$action.'&filename='.urlencode($log).'">'.$TimeStamp.'</a>';
echo '</td><td class="'.$class.'">';
echo '<a class="'.$class.'" href="admin.php?key='.$adminkey.'&action='.$action.'&filename='.urlencode($log).'">'.$PlayerName.'</a>';
echo '</td><td class="'.$class.'">';
@@ -252,7 +256,7 @@ if (empty($filename)) { if (!empty($filename)) {
if (!file_exists('logs/ace/'. $filename) or !is_file('logs/ace/'. $filename)) die('File not found (2)');
- echo'<br><table class = "box" border="0" cellpadding="0" cellspacing="0" width="720">
+ echo'<br><table class="box" border="0" cellpadding="0" cellspacing="0" width="720">
<tr>
<td class="smheading" align="center" width="95%" colspan="4">'.$filename.'</td>
<td class="smheading" align="center" width="5%" align="right">';
@@ -304,7 +308,7 @@ if (!empty($filename)) { </tr>';
echo '<tr><td class="grey" colspan="5"><span style="font-family: monospace;">';
- echo '<a href = "logs/ace/'.preg_replace('/\+/', '%20', urlencode($Screenshot)).'" target = "_blank"><img src = "logs/ace/'.preg_replace('/\+/', '%20', urlencode($Screenshot)).'" width = 100% border = 0></a>';
+ echo '<a href="logs/ace/'.preg_replace('/\+/', '%20', urlencode($Screenshot)).'" target="_blank"><img src="logs/ace/'.preg_replace('/\+/', '%20', urlencode($Screenshot)).'" width=100% border=0></a>';
echo '</span></td></tr>';
}
}
|