Commit 9766a61a authored by Ad Schellevis's avatar Ad Schellevis

(legacy) code style ipsec.inc

parent 4b4e32b7
......@@ -33,7 +33,8 @@ $ipsec_loglevels = array("dmn" => "Daemon", "mgr" => "SA Manager", "ike" => "IKE
"job" => "Job Processing", "cfg" => "Configuration backend", "knl" => "Kernel Interface",
"net" => "Networking", "asn" => "ASN encoding", "enc" => "Message encoding",
"imc" => "Integrity checker", "imv" => "Integrity Verifier", "pts" => "Platform Trust Service",
"tls" => "TLS handler", "esp" => "IPsec traffic", "lib" => "StrongSWAN Lib");
"tls" => "TLS handler", "esp" => "IPsec traffic", "lib" => "StrongSWAN Lib"
);
$p1_ealgos = array(
'aes' => array( 'name' => 'AES', 'keysel' => array( 'lo' => 128, 'hi' => 256, 'step' => 64 ) ),
......@@ -43,7 +44,8 @@ $p1_ealgos = array(
'blowfish' => array( 'name' => 'Blowfish', 'keysel' => array( 'lo' => 128, 'hi' => 256, 'step' => 64 ) ),
'3des' => array( 'name' => '3DES' ),
'cast128' => array( 'name' => 'CAST128' ),
'des' => array( 'name' => 'DES' ));
'des' => array( 'name' => 'DES' )
);
$p2_ealgos = array(
'aes' => array( 'name' => 'AES', 'keysel' => array( 'lo' => 128, 'hi' => 256, 'step' => 64 ) ),
......@@ -53,7 +55,8 @@ $p2_ealgos = array(
'blowfish' => array( 'name' => 'Blowfish', 'keysel' => array( 'lo' => 128, 'hi' => 256, 'step' => 64 ) ),
'3des' => array( 'name' => '3DES' ),
'cast128' => array( 'name' => 'CAST128' ),
'des' => array( 'name' => 'DES' ));
'des' => array( 'name' => 'DES' )
);
$p2_halgos = array(
'hmac_md5' => 'MD5',
......@@ -67,7 +70,8 @@ $p2_halgos = array(
$p2_protos = array(
'esp' => 'ESP',
'ah' => 'AH');
'ah' => 'AH'
);
$p2_pfskeygroups = array(
0 => 'off',
......@@ -122,12 +126,14 @@ function ipsec_idinfo_to_cidr(& $idinfo, $addrbits = false, $mode = "") {
switch ($idinfo['type']) {
case "address":
if ($addrbits) {
if ($mode == "tunnel6")
if ($mode == "tunnel6") {
return $idinfo['address']."/128";
else
} else {
return $idinfo['address']."/32";
} else
}
} else {
return $idinfo['address'];
}
break; /* NOTREACHED */
case "network":
return "{$idinfo['address']}/{$idinfo['netbits']}";
......@@ -137,8 +143,9 @@ function ipsec_idinfo_to_cidr(& $idinfo, $addrbits = false, $mode = "") {
return "0.0.0.0/0";
break; /* NOTREACHED */
default:
if (empty($mode) && !empty($idinfo['mode']))
if (empty($mode) && !empty($idinfo['mode'])) {
$mode = $idinfo['mode'];
}
if ($mode == "tunnel6") {
$address = get_interface_ipv6($idinfo['type']);
......@@ -187,12 +194,13 @@ function ipsec_lookup_phase1(&$ph2ent, &$ph1ent)
* Check phase1 communications status
*/
function ipsec_phase1_status($ipsec_status, $ikeid) {
foreach ($ipsec_status as $ike) {
if ($ike['id'] != $ikeid)
if ($ike['id'] != $ikeid) {
continue;
if ($ike['status'] == 'established')
}
if ($ike['status'] == 'established') {
return true;
}
break;
}
......@@ -209,27 +217,30 @@ function ipsec_dump_spd()
if ($fd) {
while (!feof($fd)) {
$line = chop(fgets($fd));
if (!$line)
if (!$line) {
continue;
if ($line == "No SPD entries.")
}
if ($line == "No SPD entries.") {
break;
}
if ($line[0] != "\t") {
if (isset($cursp))
if (isset($cursp)) {
$spd[] = $cursp;
}
$cursp = array();
$linea = explode(" ", $line);
$cursp['srcid'] = substr($linea[0], 0, strpos($linea[0], "["));
$cursp['dstid'] = substr($linea[1], 0, strpos($linea[1], "["));
$i = 0;
} else if (isset($cursp)) {
} elseif (isset($cursp)) {
$linea = explode(" ", trim($line));
switch($i)
{
switch($i) {
case 1:
if ($linea[1] == "none") /* don't show default anti-lockout rule */
if ($linea[1] == "none") { /* don't show default anti-lockout rule */
unset($cursp);
else
} else {
$cursp['dir'] = $linea[0];
}
break;
case 2:
$upperspec = explode("/", $linea[0]);
......@@ -241,8 +252,9 @@ function ipsec_dump_spd()
}
$i++;
}
if (isset($cursp) && count($cursp))
if (isset($cursp) && count($cursp)) {
$spd[] = $cursp;
}
pclose($fd);
}
......@@ -259,20 +271,20 @@ function ipsec_dump_sad()
if ($fd) {
while (!feof($fd)) {
$line = chop(fgets($fd));
if (!$line || $line[0] == " ")
if (!$line || $line[0] == " ") {
continue;
if ($line == "No SAD entries.")
}
if ($line == "No SAD entries.") {
break;
if ($line[0] != "\t")
{
if (is_array($cursa))
}
if ($line[0] != "\t") {
if (is_array($cursa)) {
$sad[] = $cursa;
}
$cursa = array();
list($cursa['src'],$cursa['dst']) = explode(" ", $line);
$i = 0;
}
else
{
} else {
$linea = explode(" ", trim($line));
switch ($i) {
case 1:
......@@ -295,8 +307,9 @@ function ipsec_dump_sad()
}
$i++;
}
if (is_array($cursa) && count($cursa))
if (is_array($cursa) && count($cursa)) {
$sad[] = $cursa;
}
pclose($fd);
}
......@@ -316,9 +329,7 @@ function ipsec_mobilekey_sort() {
function ipsec_get_number_of_phase2($ikeid) {
global $config;
$a_phase2 = $config['ipsec']['phase2'];
$nbph2=0;
if (is_array($a_phase2) && count($a_phase2)) {
foreach ($a_phase2 as $ph2tmp) {
if ($ph2tmp['ikeid'] == $ikeid) {
......@@ -326,7 +337,6 @@ function ipsec_get_number_of_phase2($ikeid) {
}
}
}
return $nbph2;
}
......@@ -340,55 +350,51 @@ function ipsec_find_id(& $ph1ent, $side = "local", $rgmap = array()) {
}
$addr = ipsec_get_phase1_src($ph1ent);
if (!$addr)
if (!$addr) {
return array();
}
} elseif ($side == "peer") {
$id_type = $ph1ent['peerid_type'];
if (isset($ph1ent['peerid_data'])) {
$id_data = $ph1ent['peerid_data'];
}
if (isset($ph1ent['mobile']))
if (isset($ph1ent['mobile'])) {
$addr = "%any";
else
} else {
$addr = $ph1ent['remote-gateway'];
}
} else {
return array();
}
$thisid_type = $id_type;
switch ($thisid_type) {
case "myaddress":
$thisid_type = "address";
$thisid_data = $addr;
break;
case "dyn_dns":
$thisid_type = "address";
$thisid_data = resolve_retry($id_data);
break;
case "peeraddress":
$thisid_type = "address";
$thisid_data = $rgmap[$ph1ent['remote-gateway']];
break;
case "address";
$thisid_data = $id_data;
break;
case "fqdn";
case "keyid tag";
case "user_fqdn";
case "asn1dn";
$thisid_data = $id_data;
if( $thisid_data )
if( $thisid_data ) {
$thisid_data = "{$thisid_data}";
}
break;
}
return array($thisid_type, $thisid_data);
}
?>
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