. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ $pgtitle = "Firewall: Aliases: Edit"; require("guiconfig.inc"); if (!is_array($config['aliases']['alias'])) $config['aliases']['alias'] = array(); aliases_sort(); $a_aliases = &$config['aliases']['alias']; $id = $_GET['id']; if (isset($_POST['id'])) $id = $_POST['id']; if (isset($id) && $a_aliases[$id]) { $pconfig['name'] = $a_aliases[$id]['name']; $pconfig['detail'] = $a_aliases[$id]['detail']; $pconfig['address'] = $a_aliases[$id]['address']; $pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']); for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) if($config['interfaces']['opt' . $i]['descr'] == $pconfig['descr']) $input_errors[] = "Sorry, an interface is already named {$pconfig['descr']}."; $addresses = explode(' ', $pconfig['address']); $address = explode("/", $addresses[0]); if ($address[1]) $addresssubnettest = true; else $addresssubnettest = false; if ($addresssubnettest) $pconfig['type'] = "network"; else if (is_ipaddr($address[0])) $pconfig['type'] = "host"; else $pconfig['type'] = "port"; if($a_aliases[$id]['aliasurl'] <> "") { $pconfig['type'] = "url"; if(is_array($a_aliases[$id]['aliasurl'])) { $isfirst = 0; $pconfig['address'] = ""; foreach($a_aliases[$id]['aliasurl'] as $aa) { if($isfirst == 1) $pconfig['address'] .= " "; $isfirst = 1; $pconfig['address'] .= $aa; } } else { $pconfig['address'] = $a_aliases[$id]['aliasurl']; } } } if ($_POST) { unset($input_errors); $pconfig = $_POST; /* input validation */ $reqdfields = explode(" ", "name address"); $reqdfieldsn = explode(",", "Name,Address"); if ($_POST['type'] == "network") { $reqdfields[] = "address_subnet"; $reqdfieldsn[] = "Subnet bit count"; } do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); if(strtolower($_POST['name']) == "lan") $input_errors[] = "Aliases may not be named LAN."; if(strtolower($_POST['name']) == "wan") $input_errors[] = "Aliases may not be named WAN."; if(strtolower($_POST['name']) == "pptp") $input_errors[] = gettext("Aliases may not be named PPTP."); $x = is_validaliasname($_POST['name']); if (!isset($x)) { $input_errors[] = "Reserved word used for alias name."; } else { if (is_validaliasname($_POST['name']) == false) $input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _."; } if ($_POST['type'] == "host") if (!is_ipaddr($_POST['address'])) { $input_errors[] = "A valid address must be specified."; } if ($_POST['type'] == "network") { if (!is_ipaddr($_POST['address'])) { $input_errors[] = "A valid address must be specified."; } if (!is_numeric($_POST['address_subnet'])) { $input_errors[] = "A valid subnet bit count must be specified."; } } if ($_POST['type'] == "url") { if(stristr($_POST['address'], "http") == false) $input_errors[] = "You must provide a valid URL to the resource."; } if ($_POST['type'] == "port") if (! is_port($_POST['address']) && ! is_portrange($_POST['address'])) $input_errors[] = "Please specify a valid port or portrange."; /* check for name conflicts */ foreach ($a_aliases as $alias) { if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias)) continue; if ($alias['name'] == $_POST['name']) { $input_errors[] = "An alias with this name already exists."; break; } } /* check for name interface description conflicts */ foreach($config['interfaces'] as $interface) { if($interface['descr'] == $_POST['name']) { $input_errors[] = "An interface description with this name already exists."; break; } } $alias = array(); $alias['name'] = $_POST['name']; if ($_POST['type'] == "network") $alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet']; else $alias['address'] = $_POST['address']; $address = $alias['address']; $final_address_detail = mb_convert_encoding($_POST['detail'],"HTML-ENTITIES","auto"); if($final_address_detail <> "") { $final_address_details .= $final_address_detail; } else { $final_address_details .= "Entry added" . " "; $final_address_details .= date('r'); } $final_address_details .= "||"; $isfirst = 0; if($_POST['type'] == "url") { $address = ""; $isfirst = 0; $address_count = 2; /* item is a url type */ if($_POST['address']) $_POST['address0'] = $_POST['address']; for($x=0; isset($_POST['address'. $x]); $x++) { if($_POST['address' . $x]) { /* fetch down and add in */ $isfirst = 0; $temp_filename = tempnam("/tmp/", "alias_import"); unlink($temp_filename); $fda = fopen("/tmp/tmpfetch","w"); fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\""); fclose($fda); mwexec("mkdir -p {$temp_filename}"); mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\""); /* if the item is tar gzipped then extract */ if(stristr($_POST['address' . $x], ".tgz")) process_alias_tgz($temp_filename); if(file_exists("{$temp_filename}/aliases")) { $file_contents = file_get_contents("{$temp_filename}/aliases"); $file_contents = str_replace("#", "\n#", $file_contents); $file_contents_split = split("\n", $file_contents); foreach($file_contents_split as $fc) { $tmp = trim($fc); if(stristr($fc, "#")) { $tmp_split = split("#", $tmp); $tmp = trim($tmp_split[0]); } if(trim($tmp) <> "") { if($isfirst == 1) $address .= " "; $address .= $tmp; $isfirst = 1; } } if($isfirst == 0) { /* nothing was found */ $input_errors[] = "You must provide a valid URL. Could not fetch usable data."; $dont_update = true; break; } $alias['aliasurl'][] = $_POST['address' . $x]; mwexec("/bin/rm -rf {$temp_filename}"); } else { $input_errors[] = "You must provide a valid URL."; $dont_update = true; break; } } } } else { /* item is a normal alias type */ for($x=0; $x<299; $x++) { $comd = "\$subnet = \$_POST['address" . $x . "'];"; eval($comd); $comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];"; eval($comd); if($subnet <> "") { $address .= " "; $address .= $subnet; if($subnet_address <> "") $address .= "/" . $subnet_address; /* Compress in details to a single key, data separated by pipes. Pulling details here lets us only pull in details for valid address entries, saving us from having to track which ones to process later. */ $comd = "\$final_address_detail = mb_convert_encoding(\$_POST['detail" . $x . "'],'HTML-ENTITIES','auto');"; eval($comd); if($final_address_detail <> "") { $final_address_details .= $final_address_detail; } else { $final_address_details .= "Entry added" . " "; $final_address_details .= date('r'); } $final_address_details .= "||"; } } } if (!$input_errors) { $alias['address'] = $address; $alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto"); $alias['type'] = $_POST['type']; $alias['detail'] = $final_address_details; if (isset($id) && $a_aliases[$id]) $a_aliases[$id] = $alias; else $a_aliases[] = $alias; touch($d_aliasesdirty_path); write_config(); filter_configure(); header("Location: firewall_aliases.php"); exit; } //we received input errors, copy data to prevent retype else { $pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto"); $pconfig['address'] = $address; $pconfig['type'] = $_POST['type']; $pconfig['detail'] = $final_address_details; } } include("head.inc"); $jscriptstr = << function typesel_change() { switch (document.iform.type.selectedIndex) { case 0: /* host */ var cmd; document.iform.address_subnet.disabled = 1; document.iform.address_subnet.value = ""; document.iform.address_subnet.selected = 0; newrows = totalrows+1; for(i=2; i EOD; ?> ">

Name

NOTE: This alias is in use so the name may not be modified!

Name
The name of the alias may only consist of the characters a-z, A-Z and 0-9.
Description
You may enter a description here for your reference (not parsed).
Type
Host(s)
"") { $address = $item2[0]; $address_subnet = $item2[1]; } } $item4 = $item3[$counter]; if($counter > 0) $tracker = $counter + 1; ?>
Item information
Network
CIDR
Description
0) echo ""; ?>