Initialer Commit
This commit is contained in:
commit
bf79541fc1
53
proxy/README.md
Normal file
53
proxy/README.md
Normal file
@ -0,0 +1,53 @@
|
||||
Contao 3 Module: Proxy
|
||||
======================
|
||||
|
||||
Offline Fork from the old TYPOlight Module „Proxy“.
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
No official transfer! I have changed the Module for using with Contao 3.0.
|
||||
|
||||
### Installation
|
||||
|
||||
- Download the ZIP file
|
||||
- unpack on your hard drive
|
||||
- on the server in the directory `system/modules` , create a new directory `proxy`
|
||||
- copy into the directory `system/modules/proxy` then the files and directories
|
||||
|
||||
So then there must exist:
|
||||
|
||||
- `system/modules/proxy/classes/Proxy.php`
|
||||
- `system/modules/proxy/config/autoload.php`
|
||||
etc.
|
||||
|
||||
### Using
|
||||
|
||||
In the backend, in System - Settings, there is now the new section "Proxy Settings". When the extension catalog and installation works, the
|
||||
module should be installed again over the extension catalog. So updates are displayed in the extension manager, if there is one.
|
||||
|
||||
|
||||
Beschreibung
|
||||
------------
|
||||
|
||||
Keine offizielle Übernahme! Ich habe das Modul für Contao 3.0 angepasst, um weiter damit arbeiten zu können.
|
||||
|
||||
### Installation
|
||||
|
||||
- Download ZIP Datei, oben auf dieser Seite ist dazu der Link zu finden
|
||||
- auf lokaler Festplatte auspacken
|
||||
- auf dem Server im Verzeichnis `system/modules` ein neues Verzeichnis `proxy` anlegen
|
||||
- in das Verzeichnis `system/modules/proxy` nun die Dateien und Verzeichnisse übertragen
|
||||
|
||||
Es muss also damit existieren:
|
||||
|
||||
- `system/modules/proxy/classes/Proxy.php`
|
||||
- `system/modules/proxy/config/autoload.php`
|
||||
usw.
|
||||
|
||||
### Nutzung
|
||||
|
||||
Im Backend unter System - Einstellungen ist der Abschnitt "Proxy-Einstellungen" zu finden.
|
||||
|
||||
Sobald damit der Erweiterungskatalog und die Installation funktioniert, sollte das Modul Proxy nochmal über den Erweiterungskatalog installiert
|
||||
werden. Damit werden Updates in der Verwaltung angezeigt, sofern welche vorhanden sind.
|
342
proxy/classes/Proxy.php
Normal file
342
proxy/classes/Proxy.php
Normal file
@ -0,0 +1,342 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2012 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* Proxy Module
|
||||
*
|
||||
* PHP version 5
|
||||
* @copyright Jörg Kleuver 2008, TYPOlight Version
|
||||
* @author Jörg Kleuver <joerg@kleuver.de>
|
||||
*
|
||||
* @copyright Glen Langer 2012
|
||||
* @author Glen Langer (BugBuster); for Contao 3
|
||||
* @package Proxy
|
||||
* @license LGPL
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Proxy
|
||||
*
|
||||
* Provide methods to handle HTTP Proxy informations.
|
||||
* @copyright Jörg Kleuver 2008, TYPOlight Version
|
||||
* @author Jörg Kleuver <joerg@kleuver.de>
|
||||
*
|
||||
* @copyright Glen Langer 2012
|
||||
* @author Glen Langer (BugBuster); for Contao 3
|
||||
* @version 3.0.0
|
||||
* @package Proxy
|
||||
* @license LGPL
|
||||
*/
|
||||
class Proxy
|
||||
{
|
||||
|
||||
/**
|
||||
* Proxy settings
|
||||
* @var array
|
||||
*/
|
||||
protected $arrProxy = array(
|
||||
'proxy_host' => '',
|
||||
'proxy_port' => 8080,
|
||||
'proxy_user' => '',
|
||||
'proxy_pass' => ''
|
||||
);
|
||||
|
||||
/**
|
||||
* Local settings
|
||||
* @var array
|
||||
*/
|
||||
protected $arrLocal = array();
|
||||
|
||||
/**
|
||||
* Set default values
|
||||
* @param string $strUrl
|
||||
* @param string $strLocal
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($strUrl = '', $strLocal = '')
|
||||
{
|
||||
$this->setProxy($strUrl);
|
||||
$this->setLocal($strLocal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an object property
|
||||
* @param string
|
||||
* @param mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __set($strKey, $varValue)
|
||||
{
|
||||
switch ($strKey)
|
||||
{
|
||||
case 'proxy':
|
||||
$this->setProxy($varValue);
|
||||
break;
|
||||
|
||||
case 'local':
|
||||
$this->setLocal($varValue);
|
||||
break;
|
||||
|
||||
case 'host':
|
||||
case 'port':
|
||||
case 'user':
|
||||
case 'pass':
|
||||
$this->arrProxy['proxy_'.$strKey] = $varValue;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception(sprintf('Invalid argument "%s"', $strKey));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an object property
|
||||
* @param string
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __get($strKey)
|
||||
{
|
||||
switch ($strKey)
|
||||
{
|
||||
case 'host':
|
||||
case 'port':
|
||||
case 'user':
|
||||
case 'pass':
|
||||
return $this->arrProxy['proxy_'.$strKey];
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception(sprintf('Unknown or protected property "%s"', $strKey));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if strHost is Local
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
public function isLocal($strHost)
|
||||
{
|
||||
if ($this->arrLocal)
|
||||
{
|
||||
// check if $strHost matches $local
|
||||
foreach ($this->arrLocal as $local)
|
||||
{
|
||||
// check if strings match
|
||||
if ($strHost == $local) return true;
|
||||
|
||||
switch ($this->hostType($strHost))
|
||||
{
|
||||
case 'host-name':
|
||||
switch ($this->hostType($local))
|
||||
{
|
||||
case 'host-name':
|
||||
// should never reach this, already checked
|
||||
if ($strHost == $local) return true;
|
||||
break;
|
||||
|
||||
case 'domain-name':
|
||||
if ($this->inDomain($strHost, $local)) return true;
|
||||
break;
|
||||
|
||||
// // Question: Do we rally want to check a host name against ip-adress or ip-range ?
|
||||
// case 'ip-address':
|
||||
// // do reverse lookup of $strHost and then check if ip-addresses match $local
|
||||
// // Don't do a reverse lookup of an ip-address !
|
||||
// foreach (gethostbynamel($strHost) as $ip)
|
||||
// {
|
||||
// if ($ip == $local) return true;
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// case 'ip-range':
|
||||
// // do reverse lookup of $strHost and then check if addresses is in ip-range of $local
|
||||
// foreach (gethostbynamel($strHost) as $ip)
|
||||
// {
|
||||
// if ($this->inRange($ip, $local)) return true;
|
||||
// }
|
||||
// break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'ip-address':
|
||||
switch ($this->hostType($local))
|
||||
{
|
||||
// // Question: Do we rally want to check an ip-address against a host name ?
|
||||
// case 'host-name':
|
||||
// // do reverse lookup of $local and then check if addresses match $strHost
|
||||
// // Don't do a reverse lookup of an ip-address !
|
||||
// foreach (gethostbynamel($local) as $ip)
|
||||
// {
|
||||
// if ($ip == $strHost) return true;
|
||||
// }
|
||||
// break;
|
||||
|
||||
case 'ip-address':
|
||||
// should never reach this, already checked
|
||||
if ($strHost == $local) return true;
|
||||
break;
|
||||
|
||||
case 'ip-range':
|
||||
if ($this->inRange($strHost, $local)) return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Proxy and return true if set
|
||||
* @param string
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
private function setProxy($strUrl = '')
|
||||
{
|
||||
// set arrProxy
|
||||
if ($strUrl)
|
||||
{
|
||||
$proxy_uri = parse_url($strUrl);
|
||||
if (! $proxy_uri)
|
||||
{
|
||||
throw new Exception(sprintf($GLOBALS['TL_LANG']['tl_proxy']['error_url'], $strUrl));
|
||||
}
|
||||
|
||||
if ($proxy_uri['scheme'] != 'http')
|
||||
{
|
||||
throw new Exception(sprintf($GLOBALS['TL_LANG']['tl_proxy']['error_scheme'], $proxy_uri['scheme']));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->arrProxy = array(
|
||||
'proxy_host' => $proxy_uri['host'],
|
||||
'proxy_port' => $proxy_uri['port'],
|
||||
'proxy_user' => $proxy_uri['user'],
|
||||
'proxy_pass' => $proxy_uri['pass']
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Local and return true if set
|
||||
* @param string
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
private function setLocal($strLocal = '')
|
||||
{
|
||||
// set arrLocal
|
||||
if ($strLocal)
|
||||
{
|
||||
$arrLocal = explode(",", $strLocal);
|
||||
foreach ($arrLocal as $key => $value)
|
||||
{
|
||||
$arrLocal[$key] = strtolower(trim($value));
|
||||
if (! $this->hostType($arrLocal[$key]))
|
||||
{
|
||||
throw new Exception(sprintf($GLOBALS['TL_LANG']['tl_proxy']['error_local'], $arrLocal[$key]));
|
||||
}
|
||||
}
|
||||
|
||||
$this->arrLocal = $arrLocal;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return type of Host
|
||||
* @param string
|
||||
* @return mixed
|
||||
*/
|
||||
private function hostType($strHost)
|
||||
{
|
||||
// sanity check of $strHost
|
||||
if(preg_match("/[^a-z0-9\.\-]/i", $strHost)) return false;
|
||||
|
||||
$strSlices = explode('.', $strHost);
|
||||
|
||||
// check for domain or ip range
|
||||
if ($strHost[0] == '.')
|
||||
{
|
||||
if(count($strSlices) < 2) return false;
|
||||
|
||||
$TLD = array_pop($strSlices); // TLD is last
|
||||
$ccTLD = array_pop($strSlices); // ccTLD is 2nd last
|
||||
if((strlen($TLD) < 2) || (strlen($ccTLD) < 2)) return false;
|
||||
|
||||
return 'domain-name';
|
||||
}
|
||||
else if (substr($strHost, -1) == '.')
|
||||
{
|
||||
if(count($strSlices) < 1) return false;
|
||||
if(preg_match("/[^0-9\.]/i", $strHost)) return false;
|
||||
return 'ip-range';
|
||||
}
|
||||
|
||||
// check for missing '.' at beginning of domains
|
||||
if(count($strSlices) == 2) return false;
|
||||
|
||||
// check for missing '.' at end of ip range
|
||||
if(count($strSlices) < 4 && ! preg_match("/[^0-9\.]/i", $strHost)) return false;
|
||||
|
||||
// if it's not an ip address, it's an host name
|
||||
if ((ip2long($strHost)) === false)
|
||||
{
|
||||
return 'host-name';
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'ip-address';
|
||||
}
|
||||
|
||||
// we should never reach this
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* Check if IP Address is in IP Range
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
private function inRange($strIp, $strRange)
|
||||
{
|
||||
if (preg_match("/^{$strRange}/", $strIp)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Host is in Domain
|
||||
* @param string
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
private function inDomain($strHost, $strDomain)
|
||||
{
|
||||
if (preg_match("/{$strDomain}$/", $strHost)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
512
proxy/classes/ProxyRequest.php
Normal file
512
proxy/classes/ProxyRequest.php
Normal file
@ -0,0 +1,512 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2012 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* Proxy Module
|
||||
*
|
||||
* PHP version 5
|
||||
* @copyright Jörg Kleuver 2008, TYPOlight Version
|
||||
* @author Jörg Kleuver <joerg@kleuver.de>
|
||||
*
|
||||
* @copyright Glen Langer 2012
|
||||
* @author Glen Langer (BugBuster); for Contao 3
|
||||
* @package Proxy
|
||||
* @license LGPL
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class ProxyRequest
|
||||
*
|
||||
* Provide methods to handle HTTP request over Proxy.
|
||||
* Enhance Request class from Leo Feyer with proxy functionality.
|
||||
* @author Jörg Kleuver
|
||||
*
|
||||
* @copyright Glen Langer 2012
|
||||
* @author Glen Langer (BugBuster); for Contao 3
|
||||
* @version 3.0.0
|
||||
* @package Proxy
|
||||
* @license LGPL
|
||||
*/
|
||||
class ProxyRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* Data to be added to the request
|
||||
* @var string
|
||||
*/
|
||||
protected $strData;
|
||||
|
||||
/**
|
||||
* Request method (defaults to GET)
|
||||
* @var string
|
||||
*/
|
||||
protected $strMethod;
|
||||
|
||||
/**
|
||||
* Error string
|
||||
* @var string
|
||||
*/
|
||||
protected $strError;
|
||||
|
||||
/**
|
||||
* Response code
|
||||
* @var integer
|
||||
*/
|
||||
protected $intCode;
|
||||
|
||||
/**
|
||||
* Response string
|
||||
* @var string
|
||||
*/
|
||||
protected $strResponse;
|
||||
|
||||
/**
|
||||
* Request string
|
||||
* @var string
|
||||
*/
|
||||
protected $strRequest;
|
||||
|
||||
/**
|
||||
* Headers array (these headers will be sent)
|
||||
* @var array
|
||||
*/
|
||||
protected $arrHeaders = array();
|
||||
|
||||
/**
|
||||
* Response headers array (these headers are returned)
|
||||
* @var array
|
||||
*/
|
||||
protected $arrResponseHeaders = array();
|
||||
|
||||
/**
|
||||
* Proxy handle
|
||||
* @var resource
|
||||
*/
|
||||
protected $resProxy;
|
||||
|
||||
/**
|
||||
* The socket for server connection
|
||||
* @var resource | null
|
||||
*/
|
||||
protected $socket = null;
|
||||
|
||||
/**
|
||||
* Set default values
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->strData = '';
|
||||
$this->strMethod = 'GET';
|
||||
|
||||
// check proxy settings
|
||||
if ($GLOBALS['TL_CONFIG']['useProxy'])
|
||||
{
|
||||
$this->resProxy = new Proxy($GLOBALS['TL_CONFIG']['proxy_url'], $GLOBALS['TL_CONFIG']['proxy_local']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set an object property
|
||||
* @param string
|
||||
* @param mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __set($strKey, $varValue)
|
||||
{
|
||||
switch ($strKey)
|
||||
{
|
||||
case 'data':
|
||||
$this->strData = $varValue;
|
||||
break;
|
||||
|
||||
case 'method':
|
||||
$this->strMethod = $varValue;
|
||||
break;
|
||||
|
||||
case 'proxy':
|
||||
if (is_resource($varValue))
|
||||
{
|
||||
$this->resProxy = $varValue;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception(sprintf('Invalid argument "%s"', $strKey));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an object property
|
||||
* @param string
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __get($strKey)
|
||||
{
|
||||
switch ($strKey)
|
||||
{
|
||||
case 'error':
|
||||
return $this->strError;
|
||||
break;
|
||||
|
||||
case 'code':
|
||||
return $this->intCode;
|
||||
break;
|
||||
|
||||
case 'request':
|
||||
return $this->strRequest;
|
||||
break;
|
||||
|
||||
case 'response':
|
||||
return $this->strResponse;
|
||||
break;
|
||||
|
||||
case 'headers':
|
||||
return $this->arrResponseHeaders;
|
||||
break;
|
||||
|
||||
case 'proxy':
|
||||
return $this->resProxy;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception(sprintf('Unknown or protected property "%s"', $strKey));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set additional request headers
|
||||
* @param string
|
||||
* @param mixed
|
||||
*/
|
||||
public function setHeader($strKey, $varValue)
|
||||
{
|
||||
$this->arrHeaders[$strKey] = $varValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if there has been an error
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasError()
|
||||
{
|
||||
return strlen($this->strError) ? true : false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform an HTTP request (handle GET, POST, PUT and any other HTTP request)
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
*/
|
||||
public function send($strUrl, $strData=false, $strMethod=false)
|
||||
{
|
||||
$default = array
|
||||
(
|
||||
);
|
||||
|
||||
if ($strData)
|
||||
{
|
||||
$this->strData = $strData;
|
||||
$default['Content-Length'] = 'Content-Length: '. strlen($this->strData);
|
||||
}
|
||||
|
||||
if ($strMethod)
|
||||
{
|
||||
$this->strMethod = strtoupper($strMethod);
|
||||
}
|
||||
|
||||
$uri = parse_url($strUrl);
|
||||
switch ($uri['scheme'])
|
||||
{
|
||||
case 'http':
|
||||
$port = isset($uri['port']) ? $uri['port'] : 80;
|
||||
$host = $uri['host'] . (($port != 80) ? ':' . $port : '');
|
||||
$secure = false;
|
||||
break;
|
||||
|
||||
case 'https':
|
||||
$port = isset($uri['port']) ? $uri['port'] : 443;
|
||||
$host = $uri['host'] . (($port != 443) ? ':' . $port : '');
|
||||
$secure = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->strError = 'Invalid schema ' . $uri['scheme'];
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
// Add the user-agent header
|
||||
if (! isset($this->arrHeaders['User-Agent']))
|
||||
{
|
||||
$this->arrHeaders['User-Agent'] = 'Contao (+http://contao.org/)';
|
||||
}
|
||||
|
||||
// Connect to host through proxy or direct
|
||||
if ($this->resProxy && ! $this->resProxy->isLocal($uri['host']))
|
||||
{
|
||||
$this->connect($this->resProxy->host, $this->resProxy->port, false);
|
||||
if (! is_resource($this->socket))
|
||||
{
|
||||
// unable to connect to proxy server
|
||||
return;
|
||||
}
|
||||
|
||||
// Add Proxy-Authorization header
|
||||
if ($this->resProxy->user && ! isset($this->arrHeaders['Proxy-Authorization']))
|
||||
{
|
||||
$this->arrHeaders['Proxy-Authorization'] = 'Basic '.base64_encode ($this->resProxy->user . ':' . $this->resProxy->pass);
|
||||
}
|
||||
|
||||
// if we are proxying HTTPS, preform CONNECT handshake with the proxy
|
||||
if ($uri['scheme'] == 'https') {
|
||||
try
|
||||
{
|
||||
@$this->connectHandshake($host, $port);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// Close socket
|
||||
@fclose($this->socket);
|
||||
$this->strError = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->connect($host, $port, $secure);
|
||||
}
|
||||
|
||||
if (! is_resource($this->socket))
|
||||
{
|
||||
// unable to connect to host
|
||||
return;
|
||||
}
|
||||
|
||||
// Build request headers
|
||||
if ($this->resProxy && $uri['scheme'] != 'https')
|
||||
{
|
||||
$request = "{$this->strMethod} {$strUrl} HTTP/1.0\r\n";
|
||||
} else
|
||||
{
|
||||
$path = isset($uri['path']) ? $uri['path'] : '/';
|
||||
if (isset($uri['query']))
|
||||
{
|
||||
$path .= '?' . $uri['query'];
|
||||
}
|
||||
|
||||
$request = "{$this->strMethod} {$path} HTTP/1.0\r\n";
|
||||
$request .= "Host: {$host} \r\n";
|
||||
}
|
||||
|
||||
// Add all headers to the request string
|
||||
foreach ($this->arrHeaders as $header=>$value)
|
||||
{
|
||||
$default[$header] = $header . ': ' . $value;
|
||||
}
|
||||
$request .= implode("\r\n", $default);
|
||||
|
||||
// Add the request body
|
||||
$request .= "\r\n\r\n";
|
||||
if (strlen($this->strData))
|
||||
{
|
||||
$request .= $this->strData . "\r\n";
|
||||
}
|
||||
|
||||
$this->strRequest = $request;
|
||||
fwrite($this->socket, $request);
|
||||
|
||||
$response = '';
|
||||
while (!feof($this->socket) && ($chunk = fread($this->socket, 1024)) != false)
|
||||
{
|
||||
$response .= $chunk;
|
||||
}
|
||||
|
||||
@fclose($this->socket);
|
||||
|
||||
list($split, $this->strResponse) = explode("\r\n\r\n", $response, 2);
|
||||
$split = preg_split("/\r\n|\n|\r/", $split);
|
||||
|
||||
$this->arrResponseHeaders = array();
|
||||
list($protocol, $code, $text) = explode(' ', trim(array_shift($split)), 3);
|
||||
|
||||
while (($line = trim(array_shift($split))) != false)
|
||||
{
|
||||
list($header, $value) = explode(':', $line, 2);
|
||||
|
||||
if (isset($this->arrResponseHeaders[$header]) && $header == 'Set-Cookie')
|
||||
{
|
||||
$this->arrResponseHeaders[$header] .= ',' . trim($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->arrResponseHeaders[$header] = trim($value);
|
||||
}
|
||||
}
|
||||
|
||||
$responses = array
|
||||
(
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
200 => 'OK',
|
||||
201 => 'Created',
|
||||
202 => 'Accepted',
|
||||
203 => 'Non-Authoritative Information',
|
||||
204 => 'No Content',
|
||||
205 => 'Reset Content',
|
||||
206 => 'Partial Content',
|
||||
300 => 'Multiple Choices',
|
||||
301 => 'Moved Permanently',
|
||||
302 => 'Found',
|
||||
303 => 'See Other',
|
||||
304 => 'Not Modified',
|
||||
305 => 'Use Proxy',
|
||||
307 => 'Temporary Redirect',
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'Payment Required',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not Found',
|
||||
405 => 'Method Not Allowed',
|
||||
406 => 'Not Acceptable',
|
||||
407 => 'Proxy Authentication Required',
|
||||
408 => 'Request Time-out',
|
||||
409 => 'Conflict',
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Large',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested range not satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
500 => 'Internal Server Error',
|
||||
501 => 'Not Implemented',
|
||||
502 => 'Bad Gateway',
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Time-out',
|
||||
505 => 'HTTP Version not supported'
|
||||
);
|
||||
|
||||
if (!isset($responses[$code]))
|
||||
{
|
||||
$code = floor($code / 100) * 100;
|
||||
}
|
||||
|
||||
$this->intCode = $code;
|
||||
|
||||
if (!in_array(intval($code), array(200, 304)))
|
||||
{
|
||||
$this->strError = strlen($text) ? $text : $responses[$code];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the remote server or proxy
|
||||
* @param string
|
||||
* @param int
|
||||
* @param boolean
|
||||
*/
|
||||
private function connect($host, $port = 80, $secure = false)
|
||||
{
|
||||
if ($secure)
|
||||
{
|
||||
$this->socket = @fsockopen('ssl://'.$host, $port, $errno, $errstr, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->socket = @fsockopen($host, $port, $errno, $errstr, 15);
|
||||
}
|
||||
|
||||
if (! is_resource($this->socket))
|
||||
{
|
||||
$this->strError = trim($errno .' '. $errstr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Preform HTTPS handshaking with proxy using CONNECT method
|
||||
* @param string $host
|
||||
* @param integer $port
|
||||
* @throws Exception
|
||||
*/
|
||||
private function connectHandshake($host, $port = 443)
|
||||
{
|
||||
$request = "CONNECT $host:$port HTTP/1.0\r\n" . "Host: " . $this->resProxy->host . "\r\n";
|
||||
|
||||
// Add the user-agent header
|
||||
if (isset($this->arrHeaders['User-Agent']))
|
||||
{
|
||||
$request .= "User-Agent: " . $this->arrHeaders['User-Agent'] . "\r\n";
|
||||
}
|
||||
|
||||
// If the proxy-authorization header is set, send it to proxy but remove it from headers sent to target host
|
||||
if (isset($this->arrHeaders['Proxy-Authorization']))
|
||||
{
|
||||
$request .= "Proxy-Authorization: " . $this->arrHeaders['Proxy-Authorization'] . "\r\n";
|
||||
unset($this->arrHeaders['Proxy-Authorization']);
|
||||
}
|
||||
$request .= "\r\n";
|
||||
|
||||
// Send the request
|
||||
if (! @fwrite($this->socket, $request))
|
||||
{
|
||||
throw new Exception("Error writing request to proxy server");
|
||||
}
|
||||
|
||||
// Read response headers only
|
||||
$response = '';
|
||||
$gotStatus = false;
|
||||
while ($line = @fgets($this->socket))
|
||||
{
|
||||
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
|
||||
if ($gotStatus)
|
||||
{
|
||||
$response .= $line;
|
||||
if (!chop($line)) break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the response from the proxy is 200
|
||||
if (substr($response, 9, 3) != 200)
|
||||
{
|
||||
throw new Exception("Unable to connect to HTTPS proxy. Server response: " . $response);
|
||||
}
|
||||
|
||||
// If all is good, switch socket to secure mode. We have to fall back
|
||||
// through the different modes
|
||||
$modes = array(
|
||||
STREAM_CRYPTO_METHOD_TLS_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
|
||||
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
|
||||
);
|
||||
|
||||
$success = false;
|
||||
foreach($modes as $mode)
|
||||
{
|
||||
$success = stream_socket_enable_crypto($this->socket, true, $mode);
|
||||
if ($success) break;
|
||||
}
|
||||
|
||||
if (! $success)
|
||||
{
|
||||
throw new Exception("Unable to connect to HTTPS server through proxy: could not negotiate secure connection.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
7
proxy/config/autoload.ini
Normal file
7
proxy/config/autoload.ini
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
;;
|
||||
; Configure what you want the autoload creator to register
|
||||
;;
|
||||
register_namespaces = true
|
||||
register_classes = true
|
||||
register_templates = true
|
22
proxy/config/autoload.php
Normal file
22
proxy/config/autoload.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
*
|
||||
* Copyright (C) 2005-2012 Leo Feyer
|
||||
*
|
||||
* @package Proxy
|
||||
* @link http://contao.org
|
||||
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Register the classes
|
||||
*/
|
||||
ClassLoader::addClasses(array
|
||||
(
|
||||
// Classes
|
||||
'Proxy' => 'system/modules/proxy/classes/Proxy.php',
|
||||
'ProxyRequest' => 'system/modules/proxy/classes/ProxyRequest.php',
|
||||
));
|
124
proxy/dca/tl_settings.php
Normal file
124
proxy/dca/tl_settings.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2012 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* Proxy Module
|
||||
*
|
||||
* PHP version 5
|
||||
* @copyright Jörg Kleuver 2008, TYPOlight Version
|
||||
* @author Jörg Kleuver <joerg@kleuver.de>
|
||||
*
|
||||
* @copyright Glen Langer 2012
|
||||
* @author Glen Langer (BugBuster); for Contao 3
|
||||
* @package Proxy
|
||||
* @license LGPL
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Add to palette
|
||||
*/
|
||||
$GLOBALS['TL_DCA']['tl_settings']['palettes']['__selector__'][] = 'useProxy';
|
||||
$GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] .= ';{custom_proxy_legend},useProxy';
|
||||
|
||||
/**
|
||||
* Add to subpalette
|
||||
*/
|
||||
$GLOBALS['TL_DCA']['tl_settings']['subpalettes']['useProxy'] = 'proxy_url,proxy_local';
|
||||
|
||||
|
||||
/**
|
||||
* Add fields
|
||||
*/
|
||||
$GLOBALS['TL_DCA']['tl_settings']['fields']['useProxy'] = array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['useProxy'],
|
||||
'inputType' => 'checkbox',
|
||||
'eval' => array('submitOnChange'=>true)
|
||||
);
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_settings']['fields']['proxy_url'] = array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['proxy_url'],
|
||||
'default' => '',
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'save_callback' => array( array('tl_proxy', 'checkProxyUrl') ),
|
||||
'eval' => array('mandatory'=>true, 'maxlength'=>255, 'nospace'=>true, 'rgxp'=>'url')
|
||||
);
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_settings']['fields']['proxy_local'] = array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['proxy_local'],
|
||||
'default' => '',
|
||||
'exclude' => true,
|
||||
'inputType' => 'text',
|
||||
'save_callback' => array( array('tl_proxy', 'checkProxyLocal') ),
|
||||
'eval' => array('maxlength'=>255)
|
||||
);
|
||||
|
||||
/**
|
||||
* Class tl_proxy
|
||||
*
|
||||
* Provide miscellaneous methods that are used by the data configuration array.
|
||||
* @copyright Jörg Kleuver 2008
|
||||
* @author Jörg Kleuver <joerg@kleuver.de>
|
||||
*/
|
||||
class tl_proxy extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Proxy handle
|
||||
* @var resource
|
||||
*/
|
||||
protected $resProxy;
|
||||
|
||||
/**
|
||||
* checkProxyUrl
|
||||
* @param mixed
|
||||
* @return string
|
||||
*/
|
||||
public function checkProxyUrl($varValue)
|
||||
{
|
||||
if (strlen($varValue))
|
||||
{
|
||||
try
|
||||
{
|
||||
@$this->resProxy = new Proxy($varValue);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
return $varValue;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* checkProxyLocal
|
||||
* @param mixed
|
||||
* @return string
|
||||
*/
|
||||
public function checkProxyLocal($varValue)
|
||||
{
|
||||
if (strlen($varValue))
|
||||
{
|
||||
try
|
||||
{
|
||||
@$this->resProxy = new Proxy('', $varValue);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
return $varValue;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
35
proxy/languages/de/tl_settings.php
Normal file
35
proxy/languages/de/tl_settings.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2012 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* Proxy Module
|
||||
*
|
||||
* PHP version 5
|
||||
* @copyright Jörg Kleuver 2008, TYPOlight Version
|
||||
* @author Jörg Kleuver <joerg@kleuver.de>
|
||||
*
|
||||
* @copyright Glen Langer 2012
|
||||
* @author Glen Langer (BugBuster); for Contao 3
|
||||
* @package Proxy
|
||||
* @license LGPL
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fields
|
||||
*/
|
||||
$GLOBALS['TL_LANG']['tl_settings']['custom_proxy_legend'] = "Proxy-Einstellungen";
|
||||
$GLOBALS['TL_LANG']['tl_settings']['useProxy'] = array('Proxy für Webzugriffe verwenden', 'Wenn kein direkter Zugriff auf das Internet vorhanden ist, können Sie einen Proxy angeben.');
|
||||
$GLOBALS['TL_LANG']['tl_settings']['proxy_url'] = array('URL des Proxy Servers', 'Beispiel: "http://[user:passwort@]host[:port]" ...');
|
||||
$GLOBALS['TL_LANG']['tl_settings']['proxy_local'] = array('kein Proxy für', 'Beispiel: "localhost, 127.0.0.1, .example.com, 192.168." ...');
|
||||
|
||||
/**
|
||||
* Error messages
|
||||
*/
|
||||
$GLOBALS['TL_LANG']['tl_proxy']['error_url'] = 'Ungültiger Eintrag in URL "%s".';
|
||||
$GLOBALS['TL_LANG']['tl_proxy']['error_scheme'] = 'Schema "%s" wird nicht unterstützt.';
|
||||
$GLOBALS['TL_LANG']['tl_proxy']['error_local'] = 'Ungültiger Eintrag "%s" in den Proxy Ausnahmen.';
|
||||
|
35
proxy/languages/en/tl_settings.php
Normal file
35
proxy/languages/en/tl_settings.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2012 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* Proxy Module
|
||||
*
|
||||
* PHP version 5
|
||||
* @copyright Jörg Kleuver 2008, TYPOlight Version
|
||||
* @author Jörg Kleuver <joerg@kleuver.de>
|
||||
*
|
||||
* @copyright Glen Langer 2012
|
||||
* @author Glen Langer (BugBuster); for Contao 3
|
||||
* @package Proxy
|
||||
* @license LGPL
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fields
|
||||
*/
|
||||
$GLOBALS['TL_LANG']['tl_settings']['custom_proxy_legend'] = "Proxy configuration";
|
||||
$GLOBALS['TL_LANG']['tl_settings']['useProxy'] = array('Use Proxy to access the Internet', 'If no direct connetion to the internet is possible, you can define a proxy.');
|
||||
$GLOBALS['TL_LANG']['tl_settings']['proxy_url'] = array('URL of Proxy Server', 'Example: "http://[user:passwort@]host[:port]" ...');
|
||||
$GLOBALS['TL_LANG']['tl_settings']['proxy_local'] = array('No Proxy for', 'Example: "localhost, 127.0.0.1, .example.com, 192.168." ...');
|
||||
|
||||
/**
|
||||
* Error messages
|
||||
*/
|
||||
$GLOBALS['TL_LANG']['tl_proxy']['error_url'] = 'Invalid argument in URL "%s".';
|
||||
$GLOBALS['TL_LANG']['tl_proxy']['error_scheme'] = 'Scheme "%s" not supported.';
|
||||
$GLOBALS['TL_LANG']['tl_proxy']['error_local'] = 'Invalid argument "%s" in Proxy exceptions.';
|
||||
|
29
proxy/languages/ja/tl_settings.php
Normal file
29
proxy/languages/ja/tl_settings.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Contao Open Source CMS
|
||||
* Copyright (C) 2005-2012 Leo Feyer
|
||||
*
|
||||
* Formerly known as TYPOlight Open Source CMS.
|
||||
*
|
||||
* PHP version 5
|
||||
* @copyright Takahiro Kambe 2008
|
||||
* @author Takahiro Kambe <taca@back-street.net>
|
||||
* @package Proxy
|
||||
* @license LGPL
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fields
|
||||
*/
|
||||
$GLOBALS['TL_LANG']['tl_settings']['custom_proxy_legend'] = array('インターネットのアクセスにプロキシーを使用', 'インターネットに直接接続していない場合に、プロキシーを指定できます。');
|
||||
$GLOBALS['TL_LANG']['tl_settings']['proxy_url'] = array('プロキシー・サーバのURL', '例: "http://[user:passwort@]host[:port]" ...');
|
||||
$GLOBALS['TL_LANG']['tl_settings']['proxy_local'] = array('プロキシーの例外', '例: "localhost, 127.0.0.1, .example.com, 192.168." ...');
|
||||
|
||||
/**
|
||||
* Error messages
|
||||
*/
|
||||
$GLOBALS['TL_LANG']['tl_proxy']['error_url'] = '"%s" は不正なURLです。';
|
||||
$GLOBALS['TL_LANG']['tl_proxy']['error_scheme'] = '"%s" というスキーマはサポートしていません。';
|
||||
$GLOBALS['TL_LANG']['tl_proxy']['error_local'] = 'プロキシーの例外にある "%s" は不正なパラメータです。';
|
||||
|
Loading…
Reference in New Issue
Block a user