Remove duplicate code

This commit is contained in:
Bill Marquette 2005-05-15 22:35:06 +00:00
parent e2cb6b5097
commit 23a8ad0447
4 changed files with 65 additions and 138 deletions

View File

@ -63,68 +63,6 @@ function is_specialnet($net) {
return false;
}
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
if (isset($adr['any']))
$padr = "any";
else if ($adr['network'])
$padr = $adr['network'];
else if ($adr['address']) {
list($padr, $pmask) = explode("/", $adr['address']);
if (!$pmask)
$pmask = 32;
}
if (isset($adr['not']))
$pnot = 1;
else
$pnot = 0;
if ($adr['port']) {
list($pbeginport, $pendport) = explode("-", $adr['port']);
if (!$pendport)
$pendport = $pbeginport;
} else {
if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
/* Item is a port alias */
} else {
$pbeginport = "any";
$pendport = "any";
}
}
}
function pconfig_to_address(&$adr, $padr, $pmask, $pnot, $pbeginport, $pendport) {
$adr = array();
if ($padr == "any")
$adr['any'] = true;
else if (is_specialnet($padr))
$adr['network'] = $padr;
else {
$adr['address'] = $padr;
if ($pmask != 32)
$adr['address'] .= "/" . $pmask;
}
if ($pnot)
$adr['not'] = true;
else
unset($addr['not']);
if (($pbeginport != 0) && ($pbeginport != "any")) {
if ($pbeginport != $pendport)
$adr['port'] = $pbeginport . "-" . $pendport;
else
$adr['port'] = $pbeginport;
}
if(alias_expand($pbeginport)) {
$adr['port'] = $pbeginport;
}
}
if (isset($id) && $a_filter[$id]) {
$pconfig['interface'] = $a_filter[$id]['interface'];

View File

@ -61,57 +61,6 @@ function is_specialnet($net) {
return false;
}
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
if (isset($adr['any']))
$padr = "any";
else if ($adr['network'])
$padr = $adr['network'];
else if ($adr['address']) {
list($padr, $pmask) = explode("/", $adr['address']);
if (!$pmask)
$pmask = 32;
}
if (isset($adr['not']))
$pnot = 1;
else
$pnot = 0;
if ($adr['port']) {
list($pbeginport, $pendport) = explode("-", $adr['port']);
if (!$pendport)
$pendport = $pbeginport;
} else {
$pbeginport = "any";
$pendport = "any";
}
}
function pconfig_to_address(&$adr, $padr, $pmask, $pnot, $pbeginport, $pendport) {
$adr = array();
if ($padr == "any")
$adr['any'] = true;
else if (is_specialnet($padr))
$adr['network'] = $padr;
else {
$adr['address'] = $padr;
if ($pmask != 32)
$adr['address'] .= "/" . $pmask;
}
$adr['not'] = $pnot ? true : false;
if (($pbeginport != 0) && ($pbeginport != "any")) {
if ($pbeginport != $pendport)
$adr['port'] = $pbeginport . "-" . $pendport;
else
$adr['port'] = $pbeginport;
}
}
if (isset($id) && $a_shaper[$id]) {
$pconfig['interface'] = $a_shaper[$id]['interface'];

View File

@ -611,4 +611,68 @@ function pkg_fetch_recursive($pkgname, $filename, $dependlevel = 0, $base_url =
fwrite($fd_log, $pkgname . " " . print_r($pkgaddout, true) . "\n");
return true;
}
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
if (isset($adr['any']))
$padr = "any";
else if ($adr['network'])
$padr = $adr['network'];
else if ($adr['address']) {
list($padr, $pmask) = explode("/", $adr['address']);
if (!$pmask)
$pmask = 32;
}
if (isset($adr['not']))
$pnot = 1;
else
$pnot = 0;
if ($adr['port']) {
list($pbeginport, $pendport) = explode("-", $adr['port']);
if (!$pendport)
$pendport = $pbeginport;
} else {
if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
/* Item is a port alias */
} else {
$pbeginport = "any";
$pendport = "any";
}
}
}
function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) {
$adr = array();
if ($padr == "any")
$adr['any'] = true;
else if (is_specialnet($padr))
$adr['network'] = $padr;
else {
$adr['address'] = $padr;
if ($pmask != 32)
$adr['address'] .= "/" . $pmask;
}
if ($pnot)
$adr['not'] = true;
else
unset($addr['not']);
if (($pbeginport != 0) && ($pbeginport != "any")) {
if ($pbeginport != $pendport)
$adr['port'] = $pbeginport . "-" . $pendport;
else
$adr['port'] = $pbeginport;
}
if(alias_expand($pbeginport)) {
$adr['port'] = $pbeginport;
}
}
?>

View File

@ -54,30 +54,6 @@ function is_specialnet($net) {
return false;
}
function address_to_pconfig($adr, &$padr, &$pmask) {
if ($adr['network'])
$padr = $adr['network'];
else if ($adr['address']) {
list($padr, $pmask) = explode("/", $adr['address']);
if (is_null($pmask))
$pmask = 32;
}
}
function pconfig_to_address(&$adr, $padr, $pmask) {
$adr = array();
if (is_specialnet($padr))
$adr['network'] = $padr;
else {
$adr['address'] = $padr;
if ($pmask != 32)
$adr['address'] .= "/" . $pmask;
}
}
if (isset($id) && $a_ipsec[$id]) {
$pconfig['disabled'] = isset($a_ipsec[$id]['disabled']);
$pconfig['auto'] = isset($a_ipsec[$id]['auto']);
@ -86,7 +62,7 @@ if (isset($id) && $a_ipsec[$id]) {
if (!isset($a_ipsec[$id]['local-subnet']))
$pconfig['localnet'] = "lan";
else
address_to_pconfig($a_ipsec[$id]['local-subnet'], $pconfig['localnet'], $pconfig['localnetmask']);
address_to_pconfig($a_ipsec[$id]['local-subnet'], $pconfig['localnet'], $pconfig['localnetmask'], null, null, null);
if ($a_ipsec[$id]['interface'])
$pconfig['interface'] = $a_ipsec[$id]['interface'];