Commit eccfa60f authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) spaces and curly braces ipsec.auth-user.php

(cherry picked from commit 47cd7b9a)
parent e8ca3eaa
...@@ -39,9 +39,12 @@ require_once("auth.inc"); ...@@ -39,9 +39,12 @@ require_once("auth.inc");
require_once("interfaces.inc"); require_once("interfaces.inc");
require_once("util.inc"); require_once("util.inc");
function cisco_to_cidr($addr) { function cisco_to_cidr($addr)
if (!is_ipaddr($addr)) {
if (!is_ipaddr($addr)) {
return 0; return 0;
}
$mask = decbin(~ip2long($addr)); $mask = decbin(~ip2long($addr));
$mask = substr($mask, -32); $mask = substr($mask, -32);
$k = 0; $k = 0;
...@@ -51,20 +54,23 @@ function cisco_to_cidr($addr) { ...@@ -51,20 +54,23 @@ function cisco_to_cidr($addr) {
return $k; return $k;
} }
function cisco_extract_index($prule) { function cisco_extract_index($prule)
{
$index = explode("#", $prule); $index = explode("#", $prule);
if (is_numeric($index[1])) if (is_numeric($index[1])) {
return intval($index[1]); return intval($index[1]);
else } else {
syslog(LOG_WARNING, "Error parsing rule {$prule}: Could not extract index"); syslog(LOG_WARNING, "Error parsing rule {$prule}: Could not extract index");
}
return -1;; return -1;;
} }
function parse_cisco_acl($attribs) { function parse_cisco_acl($attribs)
{
global $attributes; global $attributes;
if (!is_array($attribs)) if (!is_array($attribs)) {
return ""; return "";
}
$devname = "enc0"; $devname = "enc0";
$finalrules = ""; $finalrules = "";
...@@ -76,29 +82,31 @@ function parse_cisco_acl($attribs) { ...@@ -76,29 +82,31 @@ function parse_cisco_acl($attribs) {
$dir = ""; $dir = "";
if (strstr($rule[0], "inacl")) { if (strstr($rule[0], "inacl")) {
$dir = "in"; $dir = "in";
} else if (strstr($rule[0], "outacl")) } elseif (strstr($rule[0], "outacl")) {
$dir = "out"; $dir = "out";
else if (strstr($rule[0], "dns-servers")) { } elseif (strstr($rule[0], "dns-servers")) {
$attributes['dns-servers'] = explode(" ", $rule[1]); $attributes['dns-servers'] = explode(" ", $rule[1]);
continue; continue;
} else if (strstr($rule[0], "route")) { } else if (strstr($rule[0], "route")) {
if (!is_array($attributes['routes'])) if (!is_array($attributes['routes'])) {
$attributes['routes'] = array(); $attributes['routes'] = array();
}
$attributes['routes'][] = $rule[1]; $attributes['routes'][] = $rule[1];
continue; continue;
} }
$rindex = cisco_extract_index($rule[0]); $rindex = cisco_extract_index($rule[0]);
if ($rindex < 0) if ($rindex < 0) {
continue; continue;
}
$rule = $rule[1]; $rule = $rule[1];
$rule = explode(" ", $rule); $rule = explode(" ", $rule);
$tmprule = ""; $tmprule = "";
$index = 0; $index = 0;
$isblock = false; $isblock = false;
if ($rule[$index] == "permit") if ($rule[$index] == "permit") {
$tmprule = "pass {$dir} quick on {$devname} "; $tmprule = "pass {$dir} quick on {$devname} ";
else if ($rule[$index] == "deny") { } elseif ($rule[$index] == "deny") {
//continue; //continue;
$isblock = true; $isblock = true;
$tmprule = "block {$dir} quick on {$devname} "; $tmprule = "block {$dir} quick on {$devname} ";
...@@ -113,7 +121,6 @@ function parse_cisco_acl($attribs) { ...@@ -113,7 +121,6 @@ function parse_cisco_acl($attribs) {
case "udp": case "udp":
$tmprule .= "proto {$rule[$index]} "; $tmprule .= "proto {$rule[$index]} ";
break; break;
} }
$index++; $index++;
...@@ -122,8 +129,9 @@ function parse_cisco_acl($attribs) { ...@@ -122,8 +129,9 @@ function parse_cisco_acl($attribs) {
$index++; $index++;
$tmprule .= "from {$rule[$index]} "; $tmprule .= "from {$rule[$index]} ";
$index++; $index++;
if ($isblock == true) if ($isblock == true) {
$isblock = false; $isblock = false;
}
} else if (trim($rule[$index]) == "any") { } else if (trim($rule[$index]) == "any") {
$tmprule .= "from any"; $tmprule .= "from any";
$index++; $index++;
...@@ -133,16 +141,18 @@ function parse_cisco_acl($attribs) { ...@@ -133,16 +141,18 @@ function parse_cisco_acl($attribs) {
$netmask = cisco_to_cidr($rule[$index]); $netmask = cisco_to_cidr($rule[$index]);
$tmprule .= "/{$netmask} "; $tmprule .= "/{$netmask} ";
$index++; $index++;
if ($isblock == true) if ($isblock == true) {
$isblock = false; $isblock = false;
} }
}
/* Destination */ /* Destination */
if (trim($rule[$index]) == "host") { if (trim($rule[$index]) == "host") {
$index++; $index++;
$tmprule .= "to {$rule[$index]} "; $tmprule .= "to {$rule[$index]} ";
$index++; $index++;
if ($isblock == true) if ($isblock == true) {
$isblock = false; $isblock = false;
}
} else if (trim($rule[$index]) == "any") { } else if (trim($rule[$index]) == "any") {
$index++; $index++;
$tmprule .= "to any"; $tmprule .= "to any";
...@@ -152,32 +162,37 @@ function parse_cisco_acl($attribs) { ...@@ -152,32 +162,37 @@ function parse_cisco_acl($attribs) {
$netmask = cisco_to_cidr($rule[$index]); $netmask = cisco_to_cidr($rule[$index]);
$tmprule .= "/{$netmask} "; $tmprule .= "/{$netmask} ";
$index++; $index++;
if ($isblock == true) if ($isblock == true) {
$isblock = false; $isblock = false;
} }
}
if ($isblock == true) if ($isblock == true) {
continue; continue;
}
if ($dir == "in") if ($dir == "in") {
$inrules[$rindex] = $tmprule; $inrules[$rindex] = $tmprule;
else if ($dir == "out") } elseif ($dir == "out") {
$outrules[$rindex] = $tmprule; $outrules[$rindex] = $tmprule;
} }
}
$state = ""; $state = "";
if (!empty($outrules)) if (!empty($outrules)) {
$state = "no state"; $state = "no state";
}
ksort($inrules, SORT_NUMERIC); ksort($inrules, SORT_NUMERIC);
foreach ($inrules as $inrule) foreach ($inrules as $inrule) {
$finalrules .= "{$inrule} {$state}\n"; $finalrules .= "{$inrule} {$state}\n";
}
if (!empty($outrules)) { if (!empty($outrules)) {
ksort($outrules, SORT_NUMERIC); ksort($outrules, SORT_NUMERIC);
foreach ($outrules as $outrule) foreach ($outrules as $outrule) {
$finalrules .= "{$outrule} {$state}\n"; $finalrules .= "{$outrule} {$state}\n";
} }
} }
}
return $finalrules; return $finalrules;
} }
...@@ -191,9 +206,8 @@ if (!function_exists("getNasID")) { ...@@ -191,9 +206,8 @@ if (!function_exists("getNasID")) {
function getNasID() function getNasID()
{ {
global $g; global $g;
$nasId = gethostname(); $nasId = gethostname();
if(empty($nasId)) { if (empty($nasId)) {
$nasId = $g['product_name']; $nasId = $g['product_name'];
} }
return $nasId; return $nasId;
...@@ -238,8 +252,9 @@ if (($strictusercn === true) && ($common_name != $username)) { ...@@ -238,8 +252,9 @@ if (($strictusercn === true) && ($common_name != $username)) {
$attributes = array(); $attributes = array();
foreach ($authmodes as $authmode) { foreach ($authmodes as $authmode) {
$authcfg = auth_get_authserver($authmode); $authcfg = auth_get_authserver($authmode);
if (!$authcfg && $authmode != "local") if (!$authcfg && $authmode != "local") {
continue; continue;
}
$authenticated = authenticate_user($username, $password, $authcfg); $authenticated = authenticate_user($username, $password, $authcfg);
if ($authenticated == true) { if ($authenticated == true) {
...@@ -269,8 +284,9 @@ if ($authenticated == false) { ...@@ -269,8 +284,9 @@ if ($authenticated == false) {
if (empty($common_name)) { if (empty($common_name)) {
$common_name = getenv("common_name"); $common_name = getenv("common_name");
if (empty($common_name)) if (empty($common_name)) {
$common_name = getenv("username"); $common_name = getenv("username");
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment