summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2004-11-21 02:16:09 +0000
committerScott Ullrich <sullrich@pfsense.org>2004-11-21 02:16:09 +0000
commitd2cfb7a4f7f11653b2372ebec416c5482b32afd4 (patch)
tree6429b859b3769bf5d9176cc24099427279f8aec3
parentc55b323d6100c3ca8ef32c7b857d12e5bca2dd80 (diff)
downloadpfsense-d2cfb7a4f7f11653b2372ebec416c5482b32afd4.zip
pfsense-d2cfb7a4f7f11653b2372ebec416c5482b32afd4.tar.gz
Add the ability to define networks, ports and or hosts as aliases. Allow the alias to point to more than ONE item ;)
-rwxr-xr-xusr/local/www/firewall_aliases.php71
-rwxr-xr-xusr/local/www/firewall_aliases_edit.php197
-rwxr-xr-xusr/local/www/row_helper.js63
3 files changed, 250 insertions, 81 deletions
diff --git a/usr/local/www/firewall_aliases.php b/usr/local/www/firewall_aliases.php
index f2ab68f..a7c728b 100755
--- a/usr/local/www/firewall_aliases.php
+++ b/usr/local/www/firewall_aliases.php
@@ -85,43 +85,40 @@ if ($_GET['act'] == "del") {
<?php print_info_box_np("The alias list has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
<?php endif; ?>
- <table width="100%" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td width="25%" class="listhdrr">Name</td>
- <td width="30%" class="listhdrr">Address</td>
- <td width="35%" class="listhdr">Description</td>
- <td width="10%" class="list"></td>
- </tr>
- <?php $i = 0; foreach ($a_aliases as $alias): ?>
- <tr>
- <td class="listlr">
- <?=htmlspecialchars($alias['name']);?>
- </td>
- <td class="listr">
- <?=htmlspecialchars($alias['address']);?>
- </td>
- <td class="listbg">
- <font color="#FFFFFF"><?=htmlspecialchars($alias['descr']);?>&nbsp;
- </td>
- <td valign="middle" nowrap class="list"> <a href="firewall_aliases_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
- &nbsp;<a href="firewall_aliases.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this alias? All elements that still use it will become invalid (e.g. filter rules)!')"><img src="x.gif" width="17" height="17" border="0"></a></td>
- </tr>
- <?php $i++; endforeach; ?>
- <tr>
- <td class="list" colspan="3"></td>
- <td class="list"> <a href="firewall_aliases_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
- </tr>
- </table>
- </form>
-<p><span class="vexpl"><span class="red"><strong>Note:<br>
- </strong></span>Aliases act as placeholders for real IP addresses
- and can be used to minimize the number of changes that have to
- be made if a host or network address changes. You can enter the
- name of an alias instead of an IP address in all address fields
- that have a blue background. The alias will be resolved to its
- current address according to the list below. If an alias cannot
- be resolved (e.g. because you deleted it), the corresponding element
- (e.g. filter/NAT/shaper rule) will be considered invalid and skipped.</span></p>
+
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+<tr>
+ <td width="25%" class="listhdrr">Name</td>
+ <td width="30%" class="listhdrr">Address</td>
+ <td width="35%" class="listhdr">Description</td>
+ <td width="10%" class="list"></td>
+</tr>
+ <?php $i = 0; foreach ($a_aliases as $alias): ?>
+<tr>
+ <td class="listlr">
+ <?=htmlspecialchars($alias['name']);?>
+ </td>
+ <td class="listr">
+ <?=htmlspecialchars($alias['address']);?>
+ </td>
+ <td class="listbg">
+ <font color="#FFFFFF"><?=htmlspecialchars($alias['descr']);?>&nbsp;
+ </td>
+ <td valign="middle" nowrap class="list"> <a href="firewall_aliases_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
+ &nbsp;<a href="firewall_aliases.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this alias? All elements that still use it will become invalid (e.g. filter rules)!')"><img src="x.gif" width="17" height="17" border="0"></a></td>
+</tr>
+ <?php $i++; endforeach; ?>
+<tr>
+ <td class="list" colspan="3"></td>
+ <td class="list"> <a href="firewall_aliases_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
+</tr>
+<tr>
+ <td class="tabcont" colspan="3">
+ <p><span class="vexpl"><span class="red"><strong>Note:<br></strong></span>Aliases act as placeholders for real IP addresses and can be used to minimize the number of changes that have to be made if a host or network address changes. You can enter the name of an alias instead of an IP address in all address fields that have a blue background. The alias will be resolved to its current address according to the list below. If an alias cannot be resolved (e.g. because you deleted it), the corresponding element (e.g. filter/NAT/shaper rule) will be considered invalid and skipped.</span></p>
+ </td>
+</tr>
+</table>
+</form>
<?php include("fend.inc"); ?>
</body>
</html>
diff --git a/usr/local/www/firewall_aliases_edit.php b/usr/local/www/firewall_aliases_edit.php
index 8955197..4219d37 100755
--- a/usr/local/www/firewall_aliases_edit.php
+++ b/usr/local/www/firewall_aliases_edit.php
@@ -1,22 +1,22 @@
#!/usr/local/bin/php
-<?php
+<?php
/*
firewall_aliases_edit.php
part of m0n0wall (http://m0n0.ch/wall)
-
+
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
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
@@ -43,7 +43,7 @@ if (isset($_POST['id']))
if (isset($id) && $a_aliases[$id]) {
$pconfig['name'] = $a_aliases[$id]['name'];
- list($pconfig['address'],$pconfig['address_subnet']) =
+ list($pconfig['address'],$pconfig['address_subnet']) =
explode('/', $a_aliases[$id]['address']);
if ($pconfig['address_subnet'])
$pconfig['type'] = "network";
@@ -60,14 +60,14 @@ if ($_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 (($_POST['name'] && !is_validaliasname($_POST['name']))) {
$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9.";
}
@@ -77,7 +77,7 @@ if ($_POST) {
if (($_POST['address_subnet'] && !is_numeric($_POST['address_subnet']))) {
$input_errors[] = "A valid subnet bit count must be specified.";
}
-
+
/* check for name conflicts */
foreach ($a_aliases as $alias) {
if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
@@ -94,19 +94,36 @@ if ($_POST) {
$alias['name'] = $_POST['name'];
if ($_POST['type'] == "network")
$alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet'];
+
else
$alias['address'] = $_POST['address'];
+
+ $address = $alias['address'];
+ $isfirst = 0;
+ for($x=0; $x<99; $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;
+ }
+ }
+
+ $alias['address'] = $address;
$alias['descr'] = $_POST['descr'];
if (isset($id) && $a_aliases[$id])
$a_aliases[$id] = $alias;
else
$a_aliases[] = $alias;
-
+
touch($d_aliasesdirty_path);
-
+
write_config();
-
+
header("Location: firewall_aliases.php");
exit;
}
@@ -123,63 +140,150 @@ if ($_POST) {
function typesel_change() {
switch (document.iform.type.selectedIndex) {
case 0: /* host */
+ var cmd;
document.iform.address_subnet.disabled = 1;
document.iform.address_subnet.value = "";
+ newrows = totalrows+1;
+ for(i=2; i<newrows; i++) {
+ comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
+ eval(comd);
+ comd = 'document.iform.address_subnet' + i + '.value = "";';
+ eval(comd);
+ }
break;
case 1: /* network */
+ var cmd;
document.iform.address_subnet.disabled = 0;
+ newrows = totalrows+1;
+ for(i=2; i<newrows; i++) {
+ comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
+ eval(comd);
+ comd = 'document.iform.address_subnet' + i + '.value = "32";';
+ eval(comd);
+ }
break;
+
}
}
-//-->
+
+function update_box_type() {
+ var indexNum = document.forms[0].type.selectedIndex;
+ var selected = document.forms[0].type.options[indexNum].text;
+ if(selected == 'Network(s)') {
+ document.getElementById ("addressnetworkport").firstChild.data = "Network(s)";
+ document.getElementById ("address_subnet").visible = true;
+ } else if(selected == 'Hosts(s)') {
+ ument.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
+ document.getElementById ("address_subnet").visible = false;
+ } else if(selected == 'Port(s)') {
+
+ document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
+ document.getElementById ("address_subnet").visible = false;
+ }
+}
+
+-->
</script>
</head>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
+
+<script type="text/javascript" language="javascript" src="row_helper.js">
+</script>
+
+<input type='hidden' name='address_type' value='textbox'></input>
+<input type='hidden' name='address_subnet_type' value='select'></input>
+
+<script type="text/javascript" language='javascript'>
+<!--
+
+rowname[0] = "address";
+rowtype[0] = "textbox";
+
+rowname[1] = "address_subnet";
+rowtype[1] = "select";
+
+rowname[2] = "address_subnet";
+rowtype[2] = "select";
+-->
+</script>
+
<p class="pgtitle">Firewall: Aliases: Edit alias</p>
<?php if ($input_errors) print_input_errors($input_errors); ?>
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
<table width="100%" border="0" cellpadding="6" cellspacing="0">
- <tr>
+ <tr>
<td valign="top" class="vncellreq">Name</td>
- <td class="vtable"> <input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>">
- <br> <span class="vexpl">The name of the alias may only consist
+ <td class="vtable"> <input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>">
+ <br> <span class="vexpl">The name of the alias may only consist
of the characters a-z, A-Z and 0-9.</span></td>
</tr>
- <tr>
+ <tr>
+ <td width="22%" valign="top" class="vncell">Description</td>
+ <td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
+ <br> <span class="vexpl">You may enter a description here
+ for your reference (not parsed).</span></td>
+ </tr>
+ <tr>
<td valign="top" class="vncellreq">Type</td>
- <td class="vtable">
- <select name="type" class="formfld" id="type" onChange="typesel_change()">
- <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host</option>
- <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network</option>
+ <td class="vtable">
+ <select name="type" class="formfld" id="type" onChange="update_box_type(); typesel_change();">
+ <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
+ <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
+ <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
</select>
</td>
</tr>
- <tr>
- <td width="22%" valign="top" class="vncellreq">Address</td>
- <td width="78%" class="vtable"> <input name="address" type="text" class="formfld" id="address" size="20" value="<?=htmlspecialchars($pconfig['address']);?>">
- /
- <select name="address_subnet" class="formfld" id="address_subnet">
- <?php for ($i = 32; $i >= 1; $i--): ?>
- <option value="<?=$i;?>" <?php if ($i == $pconfig['address_subnet']) echo "selected"; ?>>
- <?=$i;?>
- </option>
- <?php endfor; ?>
- </select> <br> <span class="vexpl">The address that this alias
- represents.</span></td>
- </tr>
- <tr>
- <td width="22%" valign="top" class="vncell">Description</td>
- <td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
- <br> <span class="vexpl">You may enter a description here
- for your reference (not parsed).</span></td>
+ <tr>
+ <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport" name="addressnetworkport">Host(s)</div></td>
+ <td width="78%" class="vtable">
+
+
+ <table name="maintable" id="maintable">
+ <tbody>
+
+ <?php
+ $counter = 0;
+ $address = $a_aliases[$id]['address'];
+ $item = explode(", ", $address);
+ foreach($item as $ww) {
+ $address = $item[$counter];
+ $address_subnet = "";
+ $item2 = explode("/", $address);
+ foreach($item2 as $current) {
+ if($item2[1] <> "") {
+ $address = $item2[0];
+ $address_subnet = $item2[1];
+ }
+ }
+ if($counter > 0) $tracker = $counter + 1;
+ ?>
+ <tr><td> <input name="address<?php echo $tracker; ?>" type="text" class="formfld" id="address<?php echo $tracker; ?>" size="20" value="<?=htmlspecialchars($address);?>"></td><td>
+ <select name="address_subnet<?php echo $tracker; ?>" class="formfld" id="address_subnet<?php echo $tracker; ?>">
+ <option></option>
+ <?php for ($i = 32; $i >= 1; $i--): ?>
+ <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
+ <?php endfor; ?>
+ </select>
+ <?php
+ if($counter > 0)
+ echo "<input type=\"button\" onclick=\"removeRow(this); typesel_change();\" value=\"Delete\">";
+ ?>
+
+ </td></tr>
+ <?php $counter++; } ?>
+
+ </tbody>
+ </table>
+ <input type="button" onclick="addRowTo('maintable'); typesel_change();" value="Add">
+ </td>
</tr>
- <tr>
+ <tr>
<td width="22%" valign="top">&nbsp;</td>
- <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
+ <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
<?php if (isset($id) && $a_aliases[$id]): ?>
- <input name="id" type="hidden" value="<?=$id;?>">
+ <input name="id" type="hidden" value="<?=$id;?>">
<?php endif; ?>
</td>
</tr>
@@ -187,7 +291,12 @@ function typesel_change() {
</form>
<script language="JavaScript">
<!--
+field_counter_js = 2;
+rows = 1;
+totalrows = <?php echo $counter; ?>;
+loaded = <?php echo $counter; ?>;
typesel_change();
+
//-->
</script>
<?php include("fend.inc"); ?>
diff --git a/usr/local/www/row_helper.js b/usr/local/www/row_helper.js
new file mode 100755
index 0000000..2379f96
--- /dev/null
+++ b/usr/local/www/row_helper.js
@@ -0,0 +1,63 @@
+// Global Variables
+var rowname = new Array(99);
+var rowtype = new Array(99);
+for (i = 0; i < 99; i++) {
+ rowname[i] = '';
+ rowtype[i] = '';
+}
+
+var field_counter_js = 0;
+var loaded = 0;
+var is_streaming_progress_bar = 0;
+var temp_streaming_text = "";
+
+var addRowTo = (function() {
+ return (function (tableId) {
+ var d, tbody, tr, td, bgc, i, ii, j;
+ d = document;
+ tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
+ tr = d.createElement("tr");
+ totalrows++;
+ for (i = 0; i < field_counter_js; i++) {
+ td = d.createElement("td");
+ if(rowtype[i] == 'textbox') {
+ td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input name='" + rowname[i] + + totalrows + "'></input> ";
+ } else if(rowtype[i] == 'select') {
+ td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><select name='" + rowname[i] + totalrows + "'><option value=\"32\" selected>32</option><option value=\"31\" >31</option><option value=\"30\" >30</option><option value=\"29\" >29</option><option value=\"28\" >28</option><option value=\"27\" >27</option><option value=\"26\" >26</option><option value=\"25\" >25</option><option value=\"24\" >24</option><option value=\"23\" >23</option><option value=\"22\" >22</option><option value=\"21\" >21</option><option value=\"20\" >20</option><option value=\"19\" >19</option><option value=\"18\" >18</option><option value=\"17\" >17</option><option value=\"16\" >16</option><option value=\"15\" >15</option><option value=\"14\" >14</option><option value=\"13\" >13</option><option value=\"12\" >12</option><option value=\"11\" >11</option><option value=\"10\" >10</option><option value=\"9\" >9</option><option value=\"8\" >8</option><option value=\"7\" >7</option><option value=\"6\" >6</option><option value=\"5\" >5</option><option value=\"4\" >4</option><option value=\"3\" >3</option><option value=\"2\" >2</option><option value=\"1\" >1</option></select> ";
+ } else {
+ td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input type='checkbox' name='" + rowname[i] + totalrows + "'></input> ";
+ }
+ tr.appendChild(td);
+ }
+ td = d.createElement("td");
+ td.rowSpan = "1";
+ td.innerHTML = '<input type="button" value="Delete" onclick="removeRow(this)">';
+ tr.appendChild(td);
+ tbody.appendChild(tr);
+ });
+})();
+
+function removeRow(el) {
+ var cel;
+ while (el && el.nodeName.toLowerCase() != "tr")
+ el = el.parentNode;
+
+ if (el && el.parentNode) {
+ cel = el.getElementsByTagName("td").item(0);
+ el.parentNode.removeChild(el);
+ }
+}
+
+function find_unique_field_name(field_name) {
+ // loop through field_name and strip off -NUMBER
+ var last_found_dash = 0;
+ for (var i = 0; i < field_name.length; i++) {
+ // is this a dash, if so, update
+ // last_found_dash
+ if (field_name.substr(i,1) == "-" )
+ last_found_dash = i;
+ }
+ if (last_found_dash < 1)
+ return field_name;
+ return(field_name.substr(0,last_found_dash));
+}
OpenPOWER on IntegriCloud