allow ip:port in redirections, fixes #1173

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-03-12 19:26:21 +01:00
parent b5fb0da98f
commit 4d0dfb1c88
2 changed files with 25 additions and 38 deletions

View File

@@ -23,16 +23,16 @@
* @param string URL to be tested * @param string URL to be tested
* @return bool * @return bool
* @author Christian Hoffmann * @author Christian Hoffmann
* @author Froxlor team <team@froxlor.org> (2010-)
* *
*/ */
function validateUrl($url) {
function validateUrl($url)
{
global $idna_convert, $theme; global $idna_convert, $theme;
if(strtolower(substr($url, 0, 7)) != "http://" if (strtolower(substr($url, 0, 7)) != "http://"
&& strtolower(substr($url, 0, 8)) != "https://") && strtolower(substr($url, 0, 8)) != "https://"
{ ) {
$url = 'http://' . $url; $url = 'http://' . $url;
} }
@@ -40,39 +40,32 @@ function validateUrl($url)
$url = $idna_convert->encode($url); $url = $idna_convert->encode($url);
$pattern = "/^https?:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(\:[0-9]+)?\/?(.+)?$/i"; $pattern = "/^https?:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(\:[0-9]+)?\/?(.+)?$/i";
if(preg_match($pattern, $url)) if (preg_match($pattern, $url)) {
{
return true; return true;
} }
// not an fqdn // not an fqdn
if(strtolower(substr($url, 0, 7)) == "http://" if (strtolower(substr($url, 0, 7)) == "http://"
|| strtolower(substr($url, 0, 8)) == "https://") || strtolower(substr($url, 0, 8)) == "https://"
{ ) {
if(strtolower(substr($url, 0, 7)) == "http://") if (strtolower(substr($url, 0, 7)) == "http://") {
{
$ip = strtolower(substr($url, 7)); $ip = strtolower(substr($url, 7));
} }
if(strtolower(substr($url, 0, 8)) == "https://") if (strtolower(substr($url, 0, 8)) == "https://") {
{
$ip = strtolower(substr($url, 8)); $ip = strtolower(substr($url, 8));
} }
$ip = substr($ip, 0, strpos($ip, '/')); $ip = substr($ip, 0, strpos($ip, '/'));
// possible : in IP (when a port is given), #1173
$ip = substr($ip, 0, strpos($ip, ':'));
if(validate_ip($ip, true) !== false) if (validate_ip($ip, true) !== false) {
{
return true; return true;
} } else {
else
{
return false; return false;
} }
} } else {
else
{
return false; return false;
} }
} }

View File

@@ -22,25 +22,19 @@
* *
* @return mixed ip address on success, standard_error on failure * @return mixed ip address on success, standard_error on failure
*/ */
function validate_ip($ip, $return_bool = false, $lng = 'invalidip') {
function validate_ip($ip, $return_bool = false, $lng = 'invalidip') if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false
{ && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) === false
&& filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE ) {
&& filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) === FALSE) if ($return_bool) {
{
if($return_bool)
{
return false; return false;
} } else {
else
{
standard_error($lng, $ip); standard_error($lng, $ip);
exit; exit;
} }
} } else {
else
{
return $ip; return $ip;
} }
} }