Version 3.2.3

This commit is contained in:
Neo committed 2025-12-19 00:34:03 -08:00
1 parent ae5c01cc78
commit 78706903a2
2641 files changed
+228363 -201264

No files matched your search

+277 -64
View File
@@ -3,19 +3,19 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.1.4
* IP.Board v3.2.3
* Wrapper for retrieving file contents. Methods available for removing files and directories as well.
* Last Updated: $Date: 2010-06-24 05:35:43 -0400 (Thu, 24 Jun 2010) $
* Last Updated: $Date: 2011-08-23 10:24:47 -0400 (Tue, 23 Aug 2011) $
* </pre>
*
* @author $Author: matt $
* @author $Author: mark $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/community/board/license.html
* @license This is NULLED!
* @package IP.Board
* @subpackage Kernel
* @link http://www.invisionpower.com
* @link http://hatynka.in
* @since Tuesday 22nd February 2005 (16:55)
* @version $Revision: 432 $
* @version $Revision: 9404 $
*/
if ( ! defined( 'IPS_CLASSES_PATH' ) )
@@ -31,23 +31,28 @@ class classFileManagement
/**
* Use sockets flag
*
* @access public
* @var integer
* @var integer
*/
public $use_sockets = 0;
public $use_sockets = 1;
/**
* Error array
*
* @access public
* @var array
*/
public $errors = array();
/**
* Key prefix
* Prefix to identify communication strings
*
* @var string
*/
public $key_prefix = '';
/**
* HTTP Status Code/Text
*
* @access public
* @var integer HTTP Status code
*/
public $http_status_code = 0;
@@ -55,7 +60,6 @@ class classFileManagement
/**
* HTTP Status Code/Text
*
* @access public
* @var string HTTP Status text
*/
public $http_status_text = "";
@@ -63,7 +67,6 @@ class classFileManagement
/**
* Raw HTTP header output
*
* @access public
* @var string Raw HTTP header results
*/
public $raw_headers = '';
@@ -71,18 +74,17 @@ class classFileManagement
/**#@+
* Set Authentication
*
* @access public
* @var string
*/
public $auth_req = 0;
public $auth_user;
public $auth_pass;
public $auth_raw;
/**#@-*/
/**
* Timeout setting
*
* @access public
* @var int
*/
public $timeout = 15;
@@ -90,7 +92,6 @@ class classFileManagement
/**
* Get file contents (accepts URL or path)
*
* @access public
* @param string URI / File path
* @param string HTTP User
* @param string HTTP Pass
@@ -102,8 +103,8 @@ class classFileManagement
// INIT
//-------------------------------
$contents = "";
$file_location = str_replace( '&amp;', '&', $file_location );
$contents = "";
$file_location = str_replace( '&amp;', '&', $file_location );
//-----------------------------------------
// Inline user/pass?
@@ -145,7 +146,7 @@ class classFileManagement
// Is URL, try curl and then fall back
//-------------------------------
if( ($contents = $this->_getContentsWithCurl( $file_location )) === false )
if( ( $contents = $this->_getContentsWithCurl( $file_location ) ) === false )
{
if ( $this->use_sockets )
{
@@ -161,14 +162,49 @@ class classFileManagement
return $contents;
}
/**
* Sends a POST request to specified URL
*
* @param string URI to post to
* @param array Arry of post fields
* @param string HTTP User
* @param string HTTP Pass
* @return string File data
*/
public function postFileContents( $file_location='', $post_array=array(), $http_user='', $http_pass='' )
{
//-------------------------------
// INIT
//-------------------------------
$contents = "";
$file_location = str_replace( '&amp;', '&', $file_location );
if ( ! is_array( $post_array ) OR ! count( $post_array ) )
{
return false;
}
if ( ! $file_location )
{
return false;
}
if( ( $contents = $this->_getContentsWithCurl( $file_location, $post_array ) ) === false )
{
$contents = $this->_getContentsWithSocket( $file_location, $post_array );
}
return $contents;
}
/**
* Get file contents (with PHP's fopen)
*
* @access private
* @param string File location
* @return string File data
*/
private function _getContentsWithFopen( $file_location )
protected function _getContentsWithFopen( $file_location )
{
//-------------------------------
// INIT
@@ -204,18 +240,17 @@ class classFileManagement
/**
* Get file contents (with sockets)
*
* @access private
* @param string File location
* @param array Data to post (automatically converts to POST request)
* @return string File data
*/
private function _getContentsWithSocket( $file_location )
protected function _getContentsWithSocket( $file_location, $post_array=array() )
{
//-------------------------------
// INIT
//-------------------------------
$data = null;
$fsocket_timeout = $this->timeout;
//-------------------------------
// Parse URL
@@ -258,7 +293,7 @@ class classFileManagement
// Open connection
//-------------------------------
if ( ! $fp = @fsockopen( $url_parts['scheme'] == 'https' ? "ssl://" . $host : $host, $port, $errno, $errstr, $fsocket_timeout ) )
if ( ! $fp = @fsockopen( $url_parts['scheme'] == 'https' ? "ssl://" . $host : $host, $port, $errno, $errstr, $this->timeout ) )
{
$this->errors[] = "Не могу установить соединение с {$host}";
return FALSE;
@@ -266,16 +301,33 @@ class classFileManagement
}
else
{
$final_carriage = "";
$final_carriage = ( $this->auth_req or $this->auth_raw ) ? "" : "\r\n";
if ( ! $this->auth_req )
//-----------------------------------------
// Are we posting?
//-----------------------------------------
if( is_array($post_array) AND count($post_array) )
{
$final_carriage = "\r\n";
$post_back = array();
foreach ( $post_array as $key => $val )
{
$post_back[] = $this->key_prefix . $key . '=' . urlencode($val);
}
if ( ! fputs( $fp, "GET $path HTTP/1.0\r\nHost:$host\r\nConnection: Keep-Alive\r\n{$final_carriage}" ) )
$post_back_str = implode( '&', $post_back);
$header = "POST {$path} HTTP/1.0\r\nHost:{$host}\r\nContent-Type: application/x-www-form-urlencoded\r\nConnection: Keep-Alive\r\nContent-Length: " . strlen($post_back_str) . "\r\n{$final_carriage}{$post_back_str}";
}
else
{
$this->errors[] = "Невозможно отправить запрос на $host!";
$header = "GET {$path} HTTP/1.0\r\nHost:{$host}\r\nConnection: Keep-Alive\r\n{$final_carriage}";
}
if ( ! fputs( $fp, $header ) )
{
$this->errors[] = "Не удалось отправить запрос на {$host}!";
return FALSE;
}
@@ -292,16 +344,26 @@ class classFileManagement
}
}
}
elseif ( $this->auth_raw )
{
$header = $this->auth_raw."\r\n\r\n";
if ( ! fputs( $fp, $header ) )
{
$this->errors[] = "Authorization Failed!";
return FALSE;
}
}
}
@stream_set_timeout($fp, $fsocket_timeout);
@stream_set_timeout( $fp, $this->timeout );
$status = @stream_get_meta_data($fp);
while( ! feof($fp) && ! $status['timed_out'] )
{
$data .= fgets ($fp,8192);
$status = stream_get_meta_data($fp);
$data .= fgets( $fp, 8192 );
$status = stream_get_meta_data($fp);
}
fclose ($fp);
@@ -320,7 +382,7 @@ class classFileManagement
$_chunked = false;
if( preg_match( "/Transfer\-Encoding:\s*chunked/i", $data ) )
if( preg_match( '/Transfer\-Encoding:\s*chunked/i', $data ) )
{
$_chunked = true;
}
@@ -348,24 +410,27 @@ class classFileManagement
/**
* Get file contents (with cURL)
*
* @access private
* @param string File location
* @param array Data to post (automatically converts to POST request)
* @return string File data
*/
private function _getContentsWithCurl( $file_location )
protected function _getContentsWithCurl( $file_location, $post_array=array() )
{
if ( function_exists( 'curl_init' ) AND function_exists("curl_exec") )
{
//-----------------------------------------
// Are we posting?
//-----------------------------------------
$ch = curl_init( $file_location );
curl_setopt( $ch, CURLOPT_HEADER , 1);
curl_setopt( $ch, CURLOPT_TIMEOUT , $this->timeout );
curl_setopt( $ch, CURLOPT_POST , 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_FAILONERROR , 1 );
curl_setopt( $ch, CURLOPT_MAXREDIRS , 10 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER , false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST , 1 );
curl_setopt( $ch, CURLOPT_HEADER , 1 );
curl_setopt( $ch, CURLOPT_TIMEOUT , $this->timeout );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , 1 );
curl_setopt( $ch, CURLOPT_FAILONERROR , 1 );
curl_setopt( $ch, CURLOPT_MAXREDIRS , 10 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER , false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST , 1 );
/**
* Cannot set this when safe_mode or open_basedir is enabled
@@ -380,23 +445,87 @@ class classFileManagement
{
curl_setopt( $ch, CURLOPT_USERPWD , "{$this->auth_user}:{$this->auth_pass}" );
}
elseif ( $this->auth_raw )
{
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( $this->auth_raw ) );
}
//-----------------------------------------
// Are we posting?
//-----------------------------------------
if( is_array($post_array) AND count($post_array) )
{
$post_back = array();
foreach ( $post_array as $key => $val )
{
$post_back[] = $this->key_prefix . $key . '=' . urlencode($val);
}
$post_back_str = implode( '&', $post_back);
curl_setopt( $ch, CURLOPT_POST , true );
curl_setopt( $ch, CURLOPT_POSTFIELDS , $post_back_str );
}
else
{
curl_setopt( $ch, CURLOPT_POST , false );
}
$data = curl_exec($ch);
//-----------------------------------------
// Handle some errors we can handle
//-----------------------------------------
if ( curl_errno($ch) == 60 || curl_errno($ch) == 77 )
{
// CURL_SSL_CACERT
if ( defined('CA_BUNDLE_PATH') )
{
curl_setopt( $ch, CURLOPT_CAINFO, CA_BUNDLE_PATH );
}
else
{
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
}
$data = curl_exec($ch);
}
else if ( curl_errno($ch) == 6 )
{
// Name lookup failed / DNS issues
$url_parts = @parse_url( $file_location );
$ip = @gethostbyname( $url_parts['host'] );
if ( $ip and preg_match( '#^\d{1,3}\.#', $ip ) )
{
// Turn of verify SSL as the IP will not match domain of cert
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_URL, $url_parts['scheme'] . '://' . $ip . '/' . $url_parts['path'] );
$data = curl_exec($ch);
}
}
curl_close($ch);
if( $data )
{
$tmp = preg_split("/\r\n\r\n/", $data, 2);
$data = trim($tmp[1]);
$tmp = preg_split("/\r\n\r\n/", $data, 2);
$data = trim($tmp[1]);
$this->raw_headers = trim($tmp[0]);
}
if ( $data )
$this->http_status_code = substr( $this->raw_headers, 9, 3 );
$this->http_status_text = substr( $this->raw_headers, 13, ( strpos( $this->raw_headers, "\r\n" ) - 13 ) );
if ( $data AND !$this->http_status_code )
{
$this->http_status_code = 200;
}
return $data;
}
else
@@ -408,7 +537,6 @@ class classFileManagement
/**
* Tail a file
*
* @access public
* @param string Full path to file
* @param int No. lines to tail
*/
@@ -418,7 +546,7 @@ class classFileManagement
$content = '';
$t = array();
if ( file_exists( $file ) )
if ( is_file( $file ) )
{
$handle = @fopen( $file, 'r' );
@@ -471,22 +599,22 @@ class classFileManagement
/**
* Copies contents of one directory to another, creating if necessary
*
* @access public
* @param string File location [from]
* @param string File location [destination]
* @param string [Optional] CHMOD mode to set
* @return boolean Copy successful
*/
public function copyDirectory($from_path, $to_path, $mode = 0777)
public function copyDirectory($from_path, $to_path, $mode = 0 )
{
$this->errors = array();
$this->errors = array();
$mode = $mode ? $mode : IPS_FOLDER_PERMISSION;
//-----------------------------------------
// Strip off trailing slashes...
//-----------------------------------------
$from_path = rtrim( $from_path, '/' );
$to_path = rtrim( $to_path, '/' );
$from_path = rtrim( $from_path, '/' );
$to_path = rtrim( $to_path, '/' );
if ( ! is_dir( $from_path ) )
{
@@ -523,7 +651,7 @@ class classFileManagement
if ( is_file( $from_path."/".$file ) )
{
copy( $from_path."/".$file, $to_path."/".$file );
@chmod( $to_path."/".$file, 0777 );
@chmod( $to_path."/".$file, IPS_FILE_PERMISSION );
}
}
}
@@ -540,7 +668,6 @@ class classFileManagement
/**
* Removes a directory
*
* @access public
* @param string File location [from]
* @return boolean Removal successful
*/
@@ -560,7 +687,7 @@ class classFileManagement
// Attempt CHMOD
//-----------------------------------------
@chmod( $file, 0777 );
@chmod( $file, IPS_FOLDER_PERMISSION );
if ( is_dir( $file ) )
{
@@ -570,7 +697,7 @@ class classFileManagement
{
if ( ($filename != ".") && ($filename != "..") )
{
$this->removeDirectory( $file."/".$filename );
$this->removeDirectory( $file . "/" . $filename );
}
}
@@ -603,7 +730,6 @@ class classFileManagement
/**
* Empties a directory
*
* @access public
* @param string File location [from]
* @param int In a loop (not root folder)
* @return boolean Empty successful
@@ -624,7 +750,7 @@ class classFileManagement
// Attempt CHMOD
//-----------------------------------------
@chmod( $file, 0777 );
@chmod( $file, IPS_FOLDER_PERMISSION );
if ( is_dir( $file ) )
{
@@ -667,5 +793,92 @@ class classFileManagement
}
}
/**
* Receive data from the "send" function
*
* @param array Array of fields to return
* @return array Array of fields
*/
public function communicationReceiveData( $return_fields=array() )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$return_array = array();
//-----------------------------------------
// Get data...
//-----------------------------------------
foreach( $_REQUEST as $k => $v )
{
if ( strstr( $k, $this->key_prefix ) )
{
$k = str_replace( $this->key_prefix, '', $k );
$return_array[ $k ] = $v;
}
}
return $this->_filterFields( $return_array );
}
/**
* Filter out fields (optional)
*
* @param array Array of fields to return
* @return array Array of fields
*/
protected function _filterFields( $in_fields=array(), $out_fields=array() )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$return_array = array();
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! is_array( $in_fields ) or ! count( $in_fields ) )
{
return false;
}
if ( ! is_array( $out_fields ) or ! count( $out_fields ) )
{
return $in_fields;
}
//-----------------------------------------
// Get data...
//-----------------------------------------
foreach( $out_fields as $k => $type )
{
if ( $in_fields[ $k ] )
{
switch ( $type )
{
default:
case 'string':
case 'text':
$return_array[ $k ] = trim( $in_fields[ $k ] );
break;
case 'int':
case 'integar':
$return_array[ $k ] = intval( $in_fields[ $k ] );
break;
case 'float':
case 'floatval':
$return_array[ $k ] = floatval( $in_fields[ $k ] );
break;
}
}
}
return $return_array;
}
}