- only log the last 1MB of an ssh transaction (this way logs can be obtained even when you're uploading terabytes and terabytes of data)

git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@165 21d32557-59b3-4da0-833f-c5933fad653e
This commit is contained in:
Jim Wigginton 2011-06-04 17:06:53 +00:00
parent 96471cf1dd
commit 497df88951

View File

@ -157,6 +157,10 @@ define('NET_SSH2_READ_SIMPLE', 1);
* Returns when a string matching the regular expression $expect is found
*/
define('NET_SSH2_READ_REGEX', 2);
/**
* Make sure that the log never gets larger than this
*/
define('NET_SSH2_LOG_MAX_SIZE', 1024 * 1024);
/**#@-*/
/**
@ -603,6 +607,18 @@ class Net_SSH2 {
*/
var $interactiveBuffer = '';
/**
* Current log size
*
* Should never exceed NET_SSH2_LOG_MAX_SIZE
*
* @see Net_SSH2::_send_binary_packet()
* @see Net_SSH2::_get_binary_packet()
* @var Integer
* @access private
*/
var $log_size;
/**
* Default Constructor.
*
@ -1902,7 +1918,7 @@ class Net_SSH2 {
$this->message_number_log[] = '<- ' . $temp .
' (' . round($stop - $start, 4) . 's)';
if (NET_SSH2_LOGGING == NET_SSH2_LOG_COMPLEX) {
$this->message_log[] = substr($payload, 1);
$this->_append_log($payload);
}
}
@ -2180,13 +2196,32 @@ class Net_SSH2 {
$this->message_number_log[] = '-> ' . $temp .
' (' . round($stop - $start, 4) . 's)';
if (NET_SSH2_LOGGING == NET_SSH2_LOG_COMPLEX) {
$this->message_log[] = substr($data, 1);
$this->_append_log($data);
}
}
return $result;
}
/**
* Logs data packets
*
* Makes sure that only the last 1MB worth of packets will be logged
*
* @param String $data
* @access private
*/
function _append_log($data)
{
$this->_string_shift($data);
$this->log_size+= strlen($data);
$this->message_log[] = $data;
while ($this->log_size > NET_SSH2_LOG_MAX_SIZE) {
$this->log_size-= strlen(array_shift($this->message_log));
array_shift($this->message_number_log);
}
}
/**
* Sends channel data
*