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,56 +23,49 @@
* @param string URL to be tested
* @return bool
* @author Christian Hoffmann
* @author Froxlor team <team@froxlor.org> (2010-)
*
*/
function validateUrl($url) {
function validateUrl($url)
{
global $idna_convert, $theme;
if(strtolower(substr($url, 0, 7)) != "http://"
&& strtolower(substr($url, 0, 8)) != "https://")
{
if (strtolower(substr($url, 0, 7)) != "http://"
&& strtolower(substr($url, 0, 8)) != "https://"
) {
$url = 'http://' . $url;
}
// needs converting
$url = $idna_convert->encode($url);
$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;
}
// not an fqdn
if(strtolower(substr($url, 0, 7)) == "http://"
|| strtolower(substr($url, 0, 8)) == "https://")
{
if(strtolower(substr($url, 0, 7)) == "http://")
{
if (strtolower(substr($url, 0, 7)) == "http://"
|| strtolower(substr($url, 0, 8)) == "https://"
) {
if (strtolower(substr($url, 0, 7)) == "http://") {
$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 = 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;
}
else
{
} else {
return false;
}
}
else
{
} else {
return false;
}
}

View File

@@ -22,25 +22,19 @@
*
* @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
&& filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) === FALSE)
{
if($return_bool)
{
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === 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) {
return false;
}
else
{
} else {
standard_error($lng, $ip);
exit;
}
}
else
{
} else {
return $ip;
}
}