mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-17 02:41:02 +01:00
Add ability to request string return from gethttpsocketfile()
This commit is contained in:
parent
5794ca4cc1
commit
376535ad22
@ -20,7 +20,7 @@
|
||||
* along with this library; if not, write to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
||||
\**************************************************************************/
|
||||
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
class network
|
||||
@ -87,7 +87,7 @@
|
||||
{
|
||||
$this->socket = fsockopen($server,$port,$errcode,$errmsg);
|
||||
}
|
||||
if (!$this->socket)
|
||||
if(!$this->socket)
|
||||
{
|
||||
return $this->set_error('Error',$errcode.':'.$errmsg,'Connection to '.$server.':'.$port.' failed - could not open socket.');
|
||||
}
|
||||
@ -115,7 +115,7 @@
|
||||
function write_port($str)
|
||||
{
|
||||
$ok = fputs($this->socket,$this->add_crlf($str));
|
||||
if (!$ok)
|
||||
if(!$ok)
|
||||
{
|
||||
return $this->set_error('Error','Connection Lost','lost connection to server');
|
||||
}
|
||||
@ -127,7 +127,7 @@
|
||||
|
||||
function bs_write_port($str,$bytes=0)
|
||||
{
|
||||
if ($bytes)
|
||||
if($bytes)
|
||||
{
|
||||
$ok = fwrite($this->socket,$this->add_crlf($str),$bytes);
|
||||
}
|
||||
@ -135,7 +135,7 @@
|
||||
{
|
||||
$ok = fwrite($this->socket,$this->add_crlf($str));
|
||||
}
|
||||
if (!$ok)
|
||||
if(!$ok)
|
||||
{
|
||||
return $this->set_error('Error','Connection Lost','lost connection to server');
|
||||
}
|
||||
@ -152,7 +152,7 @@
|
||||
return $this->set_error('521','socket does not exist',
|
||||
'The required socked does not exist. The settings for your mail server may be wrong.');
|
||||
}
|
||||
if (!$this->write_port($str))
|
||||
if(!$this->write_port($str))
|
||||
{
|
||||
if(substr($expected_response,1,1) == '+')
|
||||
{
|
||||
@ -164,12 +164,12 @@
|
||||
}
|
||||
}
|
||||
$response = $this->read_port();
|
||||
if (!ereg(strtoupper($expected_response),strtoupper($response)))
|
||||
if(!ereg(strtoupper($expected_response),strtoupper($response)))
|
||||
{
|
||||
if(substr($expected_response,1,1) == '+')
|
||||
{
|
||||
return $this->set_error('550','','');
|
||||
}
|
||||
}
|
||||
$pos = strpos(' ',$response);
|
||||
return $this->set_error(substr($response,0,$pos),
|
||||
'invalid response('.$expected_response.')',
|
||||
@ -182,7 +182,7 @@
|
||||
}
|
||||
|
||||
// return contents of a web url as an array or false if timeout
|
||||
function gethttpsocketfile($file,$user='',$passwd='')
|
||||
function gethttpsocketfile($file,$user='',$passwd='',$string=False)
|
||||
{
|
||||
$server = str_replace('http://','',$file);
|
||||
$file = strstr($server,'/');
|
||||
@ -198,7 +198,7 @@
|
||||
$auth = '';
|
||||
}
|
||||
|
||||
if ($GLOBALS['phpgw_info']['server']['httpproxy_server'])
|
||||
if($GLOBALS['phpgw_info']['server']['httpproxy_server'])
|
||||
{
|
||||
$proxyAuth = '';
|
||||
if(!empty($GLOBALS['phpgw_info']['server']['httpproxy_server_username']))
|
||||
@ -207,16 +207,16 @@
|
||||
$proxyPassword = $GLOBALS['phpgw_info']['server']['httpproxy_server_password'];
|
||||
$proxyAuth = 'Proxy-Authorization: Basic '.base64_encode("$proxyUsername:$proxyPassword")."\n";
|
||||
}
|
||||
if ($this->open_port($server,80, 15))
|
||||
if($this->open_port($server,80, 15))
|
||||
{
|
||||
if (! $this->write_port('GET http://' . $server . $file . ' HTTP/1.0'."\n".$proxyAuth.$auth."\r\n\r\n"))
|
||||
if(!$this->write_port('GET http://' . $server . $file . ' HTTP/1.0'."\n".$proxyAuth.$auth."\r\n\r\n"))
|
||||
{
|
||||
return False;
|
||||
}
|
||||
$i = 0;
|
||||
while ($line = $this->read_port())
|
||||
while($line = $this->read_port())
|
||||
{
|
||||
if (feof($this->socket))
|
||||
if(feof($this->socket))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -224,6 +224,10 @@
|
||||
$i++;
|
||||
}
|
||||
$this->close_port();
|
||||
if($string)
|
||||
{
|
||||
return implode("\n",$lines);
|
||||
}
|
||||
return $lines;
|
||||
}
|
||||
else
|
||||
@ -233,17 +237,21 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->open_port($server, 80, 15))
|
||||
if($this->open_port($server, 80, 15))
|
||||
{
|
||||
if (!$this->write_port('GET '.$file.' HTTP/1.0'."\n".'Host: '.$server."\n".$auth."\r\n\r\n"))
|
||||
if(!$this->write_port('GET '.$file.' HTTP/1.0'."\n".'Host: '.$server."\n".$auth."\r\n\r\n"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
while ($line = $this->read_port())
|
||||
while($line = $this->read_port())
|
||||
{
|
||||
$lines[] = $line;
|
||||
}
|
||||
$this->close_port();
|
||||
if($string)
|
||||
{
|
||||
return implode("\n",$lines);
|
||||
}
|
||||
return $lines;
|
||||
}
|
||||
else
|
||||
@ -253,4 +261,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user