Commit b658fdfd authored by Franco Fichtner's avatar Franco Fichtner

firewall: merge rules, schedule, and virtual ip pages

parent a9d697f9
<?php <?php
/* /*
Copyright (C) 2014-2015 Deciso B.V. Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com) Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
...@@ -32,826 +31,510 @@ require_once("guiconfig.inc"); ...@@ -32,826 +31,510 @@ require_once("guiconfig.inc");
require_once("filter.inc"); require_once("filter.inc");
require_once("pfsense-utils.inc"); require_once("pfsense-utils.inc");
function rule_popup($src,$srcport,$dst,$dstport){
global $config,$g;
$aliases_array = array();
if (isset($config['aliases']['alias'])) {
$descriptions = array ();
foreach ($config['aliases']['alias'] as $alias_id=>$alias_name){
if ($alias_name['name'] == $src) {
//var_dump($config['aliases']['alias'][$alias_id]);
$aliases_array['src']=$config['aliases']['alias'][$alias_id];
$aliases_array['src']['aliasid']=$alias_id;
//$descriptions['src'] = $span_begin;
//$descriptions['src_end'] = $span_end;
}
if ($alias_name['name'] == $srcport) {
$aliases_array['srcport']=$config['aliases']['alias'][$alias_id];
$aliases_array['srcport']['aliasid']=$alias_id;
//$descriptions['srcport'] = $span_begin;
//$descriptions['srcport_end'] = $span_end;
}
if ($alias_name['name'] == $dst ) {
$aliases_array['dst']=$config['aliases']['alias'][$alias_id];
$aliases_array['dst']['aliasid']=$alias_id;
//$descriptions['dst'] = $span_begin;
//$descriptions['dst_end'] = $span_end;
}
if ($alias_name['name'] == $dstport) {
$aliases_array['dstport']=$config['aliases']['alias'][$alias_id];
$aliases_array['dstport']['aliasid']=$alias_id;
//$descriptions['dstport'] = $span_begin;
//$descriptions['dstport_end'] = $span_end;
}
}
return $aliases_array;//$descriptions;
}
}
$pgtitle = array(gettext("Firewall"),gettext("Rules"));
$shortcut_section = "firewall";
function delete_nat_association($id) {
global $config;
if (!$id || !isset($config['nat']['rule']))
return;
$a_nat = &$config['nat']['rule'];
foreach ($a_nat as &$natent)
if ($natent['associated-rule-id'] == $id)
$natent['associated-rule-id'] = '';
}
if (!isset($config['filter']['rule'])) { if (!isset($config['filter']['rule'])) {
$config['filter']['rule'] = array(); $config['filter']['rule'] = array();
} }
filter_rules_sort();
$a_filter = &$config['filter']['rule'];
$if = $_GET['if'];
if ($_POST['if'])
$if = $_POST['if'];
$ifdescs = get_configured_interface_with_descr();
// Drag and drop reordering
if($_REQUEST['dragdroporder']) {
// First create a new ruleset array and tmp arrays
$a_filter_before = array();
$a_filter_order = array();
$a_filter_order_tmp = array();
$a_filter_after = array();
$found = false;
$drag_order = $_REQUEST['dragtable'];
// Next traverse through rules building a new order for interface
for ($i = 0; isset($a_filter[$i]); $i++) {
if(( $_REQUEST['if'] == "FloatingRules" && isset($a_filter[$i]['floating']) ) || ( $a_filter[$i]['interface'] == $_REQUEST['if'] && !isset($a_filter[$i]['floating']) )) {
$a_filter_order_tmp[] = $a_filter[$i];
$found = true;
} else if (!$found)
$a_filter_before[] = $a_filter[$i];
else
$a_filter_after[] = $a_filter[$i];
}
// Reorder rules with the posted order
for ($i = 0; $i<count($drag_order); $i++)
$a_filter_order[] = $a_filter_order_tmp[$drag_order[$i]];
// In case $drag_order didn't account for some rules, make sure we don't lose them
if(count($a_filter_order) < count($a_filter_order_tmp)) {
for ($i = 0; $i<count($a_filter_order_tmp); $i++)
if(!in_array($i, $drag_order))
$a_filter_order[] = $a_filter_order_tmp[$i];
}
// Overwrite filter rules with newly created items
$config['filter']['rule'] = array_merge($a_filter_before, $a_filter_order, $a_filter_after);
// Write configuration
$config = write_config(gettext("Drag and drop firewall rules ordering update."));
// Redirect back to page
mark_subsystem_dirty('filter');
$undo = array();
foreach($_REQUEST['dragtable'] as $dt)
$undo[] = "";
$counter = 0;
foreach($_REQUEST['dragtable'] as $dt) {
$undo[$dt] = $counter;
$counter++;
}
foreach($undo as $dt)
$undotxt .= "&dragtable[]={$dt}";
header("Location: firewall_rules.php?if=" . $_REQUEST['if'] . "&undodrag=true" . $undotxt);
exit;
}
$icmptypes = array(
"" => gettext("any"),
"echoreq" => gettext("Echo request"),
"echorep" => gettext("Echo reply"),
"unreach" => gettext("Destination unreachable"),
"squench" => gettext("Source quench"),
"redir" => gettext("Redirect"),
"althost" => gettext("Alternate Host"),
"routeradv" => gettext("Router advertisement"),
"routersol" => gettext("Router solicitation"),
"timex" => gettext("Time exceeded"),
"paramprob" => gettext("Invalid IP header"),
"timereq" => gettext("Timestamp"),
"timerep" => gettext("Timestamp reply"),
"inforeq" => gettext("Information request"),
"inforep" => gettext("Information reply"),
"maskreq" => gettext("Address mask request"),
"maskrep" => gettext("Address mask reply")
);
/* add group interfaces */
if (isset($config['ifgroups']['ifgroupentry']))
foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
if (have_ruleint_access($ifgen['ifname']))
$iflist[$ifgen['ifname']] = $ifgen['ifname'];
foreach ($ifdescs as $ifent => $ifdesc)
if(have_ruleint_access($ifent))
$iflist[$ifent] = $ifdesc;
if (isset($config['l2tp']['mode']) && $config['l2tp']['mode'] == "server")
if(have_ruleint_access("l2tp"))
$iflist['l2tp'] = "L2TP VPN";
if (isset($config['pptpd']['mode']) && $config['pptpd']['mode'] == "server")
if(have_ruleint_access("pptp"))
$iflist['pptp'] = "PPTP VPN";
if (isset($config['pppoes']['pppoe'])) {
foreach ($config['pppoes']['pppoe'] as $pppoes) {
if (($pppoes['mode'] == 'server') && have_ruleint_access('pppoe')) {
$iflist['pppoe'] = "PPPoE Server";
}
}
}
/* add ipsec interfaces */
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) {
if (have_ruleint_access('enc0')) {
$iflist['enc0'] = 'IPsec';
}
}
/* add openvpn/tun interfaces */ $a_filter = &$config['filter']['rule'];
if (isset($config['openvpn']['openvpn-server']) || isset($config['openvpn']['openvpn-client'])) { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$iflist['openvpn'] = 'OpenVPN'; if (isset($_GET['if'])) {
} $current_if = htmlspecialchars($_GET['if']);
} else {
if (!$if || !isset($iflist[$if])) { $current_if = "FloatingRules";
if ("any" == $if)
$if = "FloatingRules";
else if ("FloatingRules" != $if) {
if (isset($iflist['wan']))
$if = "wan";
else
$if = "FloatingRules";
} }
}
if ($_POST) {
$pconfig = $_POST; $pconfig = $_POST;
if (isset($pconfig['id']) && isset($a_filter[$pconfig['id']])) {
if ($_POST['apply']) { // id found and valid
$retval = 0; $id = $pconfig['id'];
$retval = filter_configure(); }
if (isset($pconfig['apply'])) {
filter_configure();
clear_subsystem_dirty('filter'); clear_subsystem_dirty('filter');
$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br />You can also %s monitor %s the reload progress"),"<a href='status_filter_reload.php'>","</a>"); $savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br />You can also %s monitor %s the reload progress"),"<a href='status_filter_reload.php'>","</a>");
} elseif (isset($pconfig['act']) && $pconfig['act'] == 'del' && isset($id)) {
// delete single item
if (!empty($a_filter[$id]['associated-rule-id'])) {
// unlink nat entry
if (isset($config['nat']['rule'])) {
$a_nat = &$config['nat']['rule'];
foreach ($a_nat as &$natent) {
if ($natent['associated-rule-id'] == $a_filter[$id]['associated-rule-id']) {
$natent['associated-rule-id'] = '';
} }
}
if ($_GET['act'] == "del") {
if ($a_filter[$_GET['id']]) {
if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
} }
unset($a_filter[$_GET['id']]);
if (write_config())
mark_subsystem_dirty('filter');
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
exit;
} }
}
// Handle save msg if defined
if($_REQUEST['savemsg'])
$savemsg = htmlentities($_REQUEST['savemsg']);
if (isset($_POST['del_x'])) {
/* delete selected rules */
if (isset($_POST['rule']) && count($_POST['rule'])) {
foreach ($_POST['rule'] as $rulei) {
delete_nat_association($a_filter[$rulei]['associated-rule-id']);
unset($a_filter[$rulei]);
} }
if (write_config()) unset($a_filter[$id]);
if (write_config()) {
mark_subsystem_dirty('filter'); mark_subsystem_dirty('filter');
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
exit;
} }
} else if ($_GET['act'] == "toggle") { header("Location: firewall_rules.php?if=" . htmlspecialchars($current_if));
if ($a_filter[$_GET['id']]) {
if(isset($a_filter[$_GET['id']]['disabled']))
unset($a_filter[$_GET['id']]['disabled']);
else
$a_filter[$_GET['id']]['disabled'] = true;
if (write_config())
mark_subsystem_dirty('filter');
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
exit; exit;
} elseif (isset($pconfig['act']) && $pconfig['act'] == 'del_x' && isset($pconfig['rule']) && count($pconfig['rule']) > 0) {
// delete selected rules
foreach ($pconfig['rule'] as $rulei) {
// unlink nat entry
if (isset($config['nat']['rule'])) {
$a_nat = &$config['nat']['rule'];
foreach ($a_nat as &$natent) {
if ($natent['associated-rule-id'] == $a_filter[$rulei]['associated-rule-id']) {
$natent['associated-rule-id'] = '';
} }
} else {
/* yuck - IE won't send value attributes for image buttons, while Mozilla does -
so we use .x/.y to fine move button clicks instead... */
unset($movebtn);
foreach ($_POST as $pn => $pd) {
if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
$movebtn = $matches[1];
break;
} }
} }
unset($a_filter[$rulei]);
/* move selected rules before this rule */
if (isset($movebtn) && isset($_POST['rule']) && count($_POST['rule'])) {
$a_filter_new = array();
/* copy all rules < $movebtn and not selected */
for ($i = 0; $i < $movebtn; $i++) {
if (!in_array($i, $_POST['rule']))
$a_filter_new[] = $a_filter[$i];
} }
if (write_config()) {
/* copy all selected rules */ mark_subsystem_dirty('filter');
for ($i = 0; $i < count($a_filter); $i++) {
if ($i == $movebtn)
continue;
if (in_array($i, $_POST['rule']))
$a_filter_new[] = $a_filter[$i];
} }
header("Location: firewall_rules.php?if=" . htmlspecialchars($current_if));
/* copy $movebtn rule */ exit;
if ($movebtn < count($a_filter)) } elseif ( isset($pconfig['act']) && $pconfig['act'] == 'move' && isset($pconfig['rule']) && count($pconfig['rule']) > 0) {
$a_filter_new[] = $a_filter[$movebtn]; // move selected rules
if (!isset($id)) {
/* copy all rules > $movebtn and not selected */ // if rule not set/found, move to end
for ($i = $movebtn+1; $i < count($a_filter); $i++) { $id = count($a_nat);
if (!in_array($i, $_POST['rule'])) }
$a_filter_new[] = $a_filter[$i]; $a_filter = legacy_move_config_list_items($a_filter, $id, $pconfig['rule']);
if (write_config()) {
mark_subsystem_dirty('filter');
} }
header("Location: firewall_rules.php?if=" . htmlspecialchars($current_if));
exit;
$a_filter = $a_filter_new; } elseif (isset($pconfig['act']) && $pconfig['act'] == 'toggle' && isset($id)) {
if (write_config()) // toggle item
if(isset($a_filter[$id]['disabled'])) {
unset($a_filter[$id]['disabled']);
} else {
$a_filter[$id]['disabled'] = true;
}
if (write_config()) {
mark_subsystem_dirty('filter'); mark_subsystem_dirty('filter');
header("Location: firewall_rules.php?if=" . htmlspecialchars($if)); }
header("Location: firewall_rules.php?if=" . htmlspecialchars($current_if));
exit; exit;
} }
} }
$closehead = true;
if (isset($_GET['if'])) {
$selected_if = htmlspecialchars($_GET['if']);
} else {
$selected_if = "FloatingRules";
}
$closehead = true;
$pgtitle = array(gettext("Firewall"),gettext("Rules"));
$shortcut_section = "firewall";
include("head.inc"); include("head.inc");
?> ?>
<script type="text/javascript" src="/themes/<?=$g['theme'];?>/assets/javascripts/jquery-sortable.js"></script>
<style type="text/css">
body.dragging, body.dragging * {
cursor: move !important;
}
.dragged {
position: absolute;
opacity: 0.5;
z-index: 2000;
}
ol.example li.placeholder {
position: relative;
/** More li styles **/
}
ol.example li.placeholder:before {
position: absolute;
/** Define arrowhead **/
}
</style>
</head> </head>
<body> <body>
<script type="text/javascript">
<script type='text/javascript'>//<![CDATA[ $( document ).ready(function() {
jQuery(window).load( // link delete buttons
function(){ $(".act_delete").click(function(){
var originalLeave=jQuery.fn.popover.Constructor.prototype.leave; var id = $(this).attr("id").split('_').pop(-1);
jQuery.fn.popover.Constructor.prototype.leave=function(obj) if (id != 'x') {
{ // delete single
var self=obj instanceof this.constructor?obj:jQuery(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.'+this.type) BootstrapDialog.show({
var container,timeout;originalLeave.call(this,obj); type:BootstrapDialog.TYPE_INFO,
if(obj.currentTarget){container=jQuery(obj.currentTarget).siblings('.popover') title: "<?= gettext("Rules");?>",
timeout=self.timeout; message: "<?=gettext("Do you really want to delete this rule?");?>",
container.one('mouseenter',function() buttons: [{
{ label: "<?= gettext("No");?>",
clearTimeout(timeout); action: function(dialogRef) {
container.one('mouseleave',function() dialogRef.close();
{ }}, {
jQuery.fn.popover.Constructor.prototype.leave.call(self,self); label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#id").val(id);
$("#action").val("del");
$("#iform").submit()
}
}]
}); });
}) } else {
} // delete selected
}; BootstrapDialog.show({
jQuery('body').popover({selector:'[data-popover]',trigger:'click hover',placement:'auto',delay:{show:250,hide:50} type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Rules");?>",
message: "<?=gettext("Do you really want to delete the selected rules?");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#id").val("");
$("#action").val("del_x");
$("#iform").submit()
}
}]
}); });
}
}); });
//]]>
</script>
<?php include("fbegin.inc"); ?> // link move buttons
$(".act_move").click(function(){
var id = $(this).attr("id").split('_').pop(-1);
$("#id").val(id);
$("#action").val("move");
$("#iform").submit();
});
// link toggle buttons
$(".act_toggle").click(function(){
var id = $(this).attr("id").split('_').pop(-1);
$("#id").val(id);
$("#action").val("toggle");
$("#iform").submit();
});
});
</script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<?php if (isset($savemsg)) print_info_box($savemsg); ?> <?php if (isset($savemsg)) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('filter')): ?><p> <?php if (is_subsystem_dirty('filter')): ?><p>
<?php <?php print_info_box_apply(gettext("The firewall rule configuration has been changed.<br />You must apply the changes in order for them to take effect."));?>
if ($_REQUEST['undodrag']) { <?php endif; ?>
foreach ($_REQUEST['dragtable'] as $dt) { <section class="col-xs-12">
$dragtable .= "&dragtable[]={$dt}"; <?php
// create tabs per interface + floating
$iflist_tabs = array();
$iflist_tabs['FloatingRules'] = 'Floating';
if (isset($config['ifgroups']['ifgroupentry']))
foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
$iflist_tabs[$ifgen['ifname']] = $ifgen['ifname'];
foreach (get_configured_interface_with_descr() as $ifent => $ifdesc)
$iflist_tabs[$ifent] = $ifdesc;
if (isset($config['l2tp']['mode']) && $config['l2tp']['mode'] == "server")
$iflist_tabs['l2tp'] = "L2TP VPN";
if (isset($config['pptpd']['mode']) && $config['pptpd']['mode'] == "server")
$iflist_tabs['pptp'] = "PPTP VPN";
if (isset($config['pppoes']['pppoe'])) {
foreach ($config['pppoes']['pppoe'] as $pppoes) {
if (($pppoes['mode'] == 'server') && have_ruleint_access('pppoe')) {
$iflist_tabs['pppoe'] = "PPPoE Server";
}
} }
print_info_box_apply_undo(gettext("The firewall rule configuration has been changed.<br />You must apply the changes in order for them to take effect."), "firewall_rules.php?if={$_REQUEST['if']}&dragdroporder=true&{$dragtable}");
} else {
print_info_box_apply(gettext("The firewall rule configuration has been changed.<br />You must apply the changes in order for them to take effect."));
} }
?>
<?php endif; ?>
<section class="col-xs-12"> /* add ipsec interfaces */
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) {
$iflist_tabs['enc0'] = 'IPsec';
}
/* add openvpn/tun interfaces */
if (isset($config['openvpn']['openvpn-server']) || isset($config['openvpn']['openvpn-client'])) {
$iflist_tabs['openvpn'] = 'OpenVPN';
}
<?php
/* active tabs */
$tab_array = array(); $tab_array = array();
if ("FloatingRules" == $if) foreach ($iflist_tabs as $ifent => $ifname) {
$active = true;
else
$active = false; $active = false;
$tab_array[] = array(gettext("Floating"), $active, "firewall_rules.php?if=FloatingRules"); // mark active if selected or mark floating active when none is selected
$tabscounter = 0; $i = 0; foreach ($iflist as $ifent => $ifname) { if ($ifent == $selected_if) {
if ($ifent == $if)
$active = true; $active = true;
else }
$active = false;
$tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}"); $tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}");
} }
display_top_tabs($tab_array); display_top_tabs($tab_array);
?> ?>
<div class="content-box">
<form action="firewall_rules.php?if=<?=$selected_if;?>" method="post" name="iform" id="iform">
<div class="tab-content content-box col-xs-12" style="overflow: auto;"> <input type="hidden" id="id" name="id" value="" />
<input type="hidden" id="action" name="act" value="" />
<form action="firewall_rules.php<? if (!empty($if)): ?>?if=<?=$if;?><? endif; ?>" method="post" name="iform" id="iform">
<div class="table-responsive" > <div class="table-responsive" >
<table class="table table-striped table-sort dragable"> <table class="table table-striped">
<thead> <thead>
<tr id="frheader"> <tr>
<th class="list">&nbsp;</th> <th>&nbsp;</th>
<th class="list">&nbsp;</th> <th>&nbsp;</th>
<th class="listhdrr"><?=gettext("Proto");?></th> <th><?=gettext("Proto");?></th>
<th class="listhdrr"><?=gettext("Source");?></th> <th><?=gettext("Source");?></th>
<th class="listhdrr"><?=gettext("Port");?></th> <th class="hidden-xs hidden-sm"><?=gettext("Port");?></th>
<th class="listhdrr"><?=gettext("Destination");?></th> <th class="hidden-xs hidden-sm"><?=gettext("Destination");?></th>
<th class="listhdrr"><?=gettext("Port");?></th> <th class="hidden-xs hidden-sm"><?=gettext("Port");?></th>
<th class="listhdrr"><?=gettext("Gateway");?></th> <th class="hidden-xs hidden-sm"><?=gettext("Gateway");?></th>
<th class="listhdrr"><?=gettext("Queue");?></th> <th class="hidden-xs hidden-sm"><?=gettext("Schedule");?></th>
<th class="listhdrr"><?=gettext("Schedule");?></th> <th><?=gettext("Description");?></th>
<th class="listhdr"><?=gettext("Description");?></th> <th></th>
<th class="list">
<?php
$nrules = 0;
for ($i = 0; isset($a_filter[$i]); $i++) {
$filterent = $a_filter[$i];
if ($filterent['interface'] != $if && !isset($filterent['floating']))
continue;
if (isset($filterent['floating']) && "FloatingRules" != $if)
continue;
$nrules++;
}
?>
<?php if ($nrules): ?>
<button name="del" type="submit" title="<?=gettext("delete selected rules");?>" onclick="return confirm('<?=gettext('Do you really want to delete the selected rules?');?>')" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></button>
<?php endif; ?>
<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>&amp;after=-1" title="<?=gettext("add new rule");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a>
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php // Show the anti-lockout rule if it's enabled, and we are on LAN with an if count > 1, or WAN with an if count of 1. <?php
// Show the anti-lockout rule if it's enabled, and we are on LAN with an if count > 1, or WAN with an if count of 1.
if (!isset($config['system']['webgui']['noantilockout']) && if (!isset($config['system']['webgui']['noantilockout']) &&
(((count($config['interfaces']) > 1) && ($if == 'lan')) (((count($config['interfaces']) > 1) && ($selected_if == 'lan'))
|| ((count($config['interfaces']) == 1) && ($if == 'wan')))): || ((count($config['interfaces']) == 1) && ($selected_if == 'wan')))):
$alports = implode('<br />', filter_get_antilockout_ports(true)); $alports = implode('<br />', filter_get_antilockout_ports(true));
?> ?>
<tr valign="top" id="antilockout"> <tr valign="top">
<td class="list">&nbsp;</td> <td>&nbsp;</td>
<td class="listt" align="center"><span class="glyphicon glyphicon-play text-success"></span></td> <td><span class="glyphicon glyphicon-play text-success"></span></td>
<td>*</td>
<td class="listr">*</td> <td>*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm"><?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($selected_if));?> Address</td>
<td class="listr"><?=$iflist[$if];?> Address</td> <td class="hidden-xs hidden-sm"><?=$alports;?></td>
<td class="listr"><?= $alports ?></td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">&nbsp;</td>
<td class="listr">*</td> <td><?=gettext("Anti-Lockout Rule");?></td>
<td class="listr">&nbsp;</td> <td>
<td class="listbg"><?=gettext("Anti-Lockout Rule");?></td>
<td valign="middle" class="list nowrap">
<span title="<?=gettext("move selected rules before this rule");?>" alt="move" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-arrow-left"></span></span>
<a href="system_advanced_admin.php" title="<?=gettext("edit rule");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a> <a href="system_advanced_admin.php" title="<?=gettext("edit rule");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<span title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0" alt="add" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></span>
</td> </td>
</tr> </tr>
<?php endif; ?> <?php
endif; ?>
<?php if (isset($config['interfaces'][$if]['blockpriv'])): ?> <?php
<tr valign="top" id="frrfc1918"> if (isset($config['interfaces'][$selected_if]['blockpriv'])): ?>
<td class="list">&nbsp;</td> <tr>
<td class="listt" align="center"><span class="glyphicon glyphicon-remove text-danger"></span></td> <td>&nbsp;</td>
<td><span class="glyphicon glyphicon-remove text-danger"></span></td>
<td class="listr">*</td> <td>*</td>
<td class="listr"><?=gettext("RFC 1918 networks");?></td> <td><?=gettext("RFC 1918 networks");?></td>
<td class="listr">*</td> <td>*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">&nbsp;</td>
<td class="listr">&nbsp;</td> <td class="hidden-xs hidden-sm"><?=gettext("Block private networks");?></td>
<td class="listbg"><?=gettext("Block private networks");?></td>
<td valign="middle" class="list nowrap"> <td valign="middle" class="list nowrap">
<span title="<?=gettext("move selected rules before this rule");?>" alt="move" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-arrow-left"></span></span> <a href="interfaces.php?if=<?=$selected_if?>#rfc1918" title="<?=gettext("edit rule");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<a href="interfaces.php?if=<?=htmlspecialchars($if)?>#rfc1918" title="<?=gettext("edit rule");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<span title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0" alt="add" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></span>
</td> </td>
</tr> </tr>
<?php endif; ?> <?php
<?php if (isset($config['interfaces'][$if]['blockbogons'])): ?> endif;
if (isset($config['interfaces'][$selected_if]['blockbogons'])): ?>
<tr valign="top" id="frrfc1918"> <tr valign="top" id="frrfc1918">
<td class="list">&nbsp;</td> <td>&nbsp;</td>
<td class="listt" align="center"><span class="glyphicon glyphicon-remove text-danger"></span></td> <td align="center"><span class="glyphicon glyphicon-remove text-danger"></span></td>
<td>*</td>
<td class="listr">*</td> <td><?=gettext("Reserved/not assigned by IANA");?></td>
<td class="listr"><?=gettext("Reserved/not assigned by IANA");?></td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td class="hidden-xs hidden-sm">*</td>
<td class="listr">*</td> <td><?=gettext("Block bogon networks");?></td>
<td class="listr">*</td> <td>
<td class="listbg"><?=gettext("Block bogon networks");?></td>
<td valign="middle" class="list nowrap">
<span title="<?=gettext("move selected rules before this rule");?>" alt="move" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-arrow-left"></span></span>
<a href="interfaces.php?if=<?=htmlspecialchars($if)?>#rfc1918" title="<?=gettext("edit rule");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a> <a href="interfaces.php?if=<?=htmlspecialchars($if)?>#rfc1918" title="<?=gettext("edit rule");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
<span title="<?=gettext("add a new rule based on this one");?>" width="17" height="17" border="0" alt="add" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></span>
</td> </td>
</tr> </tr>
</tbody> <?php
<?php endif; ?> endif; ?>
<tbody id="dragtable"> <?php
<?php $nrules = 0; for ($i = 0; isset($a_filter[$i]); $i++): $interface_has_rules = false;
$filterent = $a_filter[$i]; foreach ($a_filter as $i => $filterent):
if ($filterent['interface'] != $if && !isset($filterent['floating'])) if ( (isset($filterent['interface']) && $filterent['interface'] == $selected_if) ||
continue; (isset($filterent['floating']) && $selected_if == "FloatingRules" )):
if (isset($filterent['floating']) && "FloatingRules" != $if) $interface_has_rules = true;
continue; // select icon
$isadvset = firewall_check_for_advanced_options($filterent); if (!isset($filterent['type']) && empty($filterent['disabled'])) {
if($isadvset) // not very nice.... associated NAT rules don't have a type...
$advanced_set = "<span class=\"glyphicon glypicon-cog\" title=\"" . gettext("advanced settings set") . ": {$isadvset}\"></span>"; $iconfn = "glyphicon-play text-success";
else } else if (!isset($filterent['type']) && !empty($filterent['disabled'])) {
$advanced_set = ""; $iconfn = "glyphicon-play text-muted";
?> } elseif ($filterent['type'] == "block" && empty($filterent['disabled'])) {
<tr valign="top" id="fr<?=$nrules;?>"> $iconfn = "glyphicon-remove text-danger";
<td class="listt"> } elseif ($filterent['type'] == "block" && !empty($filterent['disabled'])) {
<input type="checkbox" id="frc<?=$nrules;?>" name="rule[]" value="<?=$i;?>" /> $iconfn = "glyphicon-remove text-muted";
<?php echo $advanced_set; ?> } elseif ($filterent['type'] == "reject" && empty($filterent['disabled'])) {
</td> $iconfn = "glyphicon-remove text-warning";
<td class="listt" align="center"> } elseif ($filterent['type'] == "reject" && !empty($filterent['disabled'])) {
<?php $iconfn = "glyphicon-remove text-muted";
if ($filterent['type'] == "block") { } else if ($filterent['type'] == "match" && empty($filterent['disabled'])) {
$iconfn = "glyphicon-remove";
$textss = "text-danger"; }
else if ($filterent['type'] == "reject") {
$iconfn = "glyphicon-remove";
$textss = "text-warning"; }
else if ($filterent['type'] == "match") {
$iconfn = "glyphicon-ok"; $iconfn = "glyphicon-ok";
$textss = ""; } } else if ($filterent['type'] == "match" && !empty($filterent['disabled'])) {
else { $iconfn = "glyphicon-ok text-muted";
$iconfn = "glyphicon-play"; } elseif (empty($filterent['disabled'])) {
$textss = "text-success"; } $iconfn = "glyphicon-play text-success";
if (isset($filterent['disabled'])) {
$textss = $textse = "text-muted";
} else { } else {
//$textss = $textse = ""; $iconfn = "glyphicon-play text-muted";
$textse = "";
}
?>
<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$i;?>" title="<?=gettext("click to toggle enabled/disabled status");?>" ><span class="glyphicon <?=$iconfn;?> <?=$textss;?>"></span></a>
<?php
if (isset($filterent['log'])):
$iconfnlog = "glyphicon-info-sign";
if (isset($filterent['disabled']))
$iconfnlog .= " text-muted";
?>
<span class="glyphicon <?=$iconfnlog;?>"></span>
<?php endif; ?>
</td>
<?php
//build Alias popup box
$alias_src_span_begin = "";
$alias_popup = rule_popup($filterent['source']['address'],pprint_port($filterent['source']['port']),$filterent['destination']['address'],pprint_port($filterent['destination']['port']));
$alias_src_span_end = ""; //$alias_popup["src_end"];
if ( count($alias_popup) > 0 ) {
$aliases_popup['src']['addrlist']=explode(" ",$alias_popup['src']['address']);
$aliases_popup['src']['detlist']=explode("||",$alias_popup['src']['detail']);
$alias_src_span_begin="<span title=\"\" type=\"button\" data-placement=\"bottom\" data-popover=\"true\" data-html=\"true\" data-content='";
foreach ($aliases_popup['src']['addrlist'] as $addrkey => $address) {
$alias_src_span_begin=$alias_src_span_begin."<b>".$address."</b> <small>(".$aliases_popup['src']['detlist'][$addrkey].")</small>&nbsp;<br>";
} }
$alias_src_span_begin=$alias_src_span_begin."' data-original-title='<a href=\"/firewall_aliases_edit.php?id=".(string)$alias_popup['src']['aliasid']."\" target=\"_self\" >
<span class=\"text-primary\"><b>".htmlspecialchars(pprint_address($filterent['source']))."(".count($aliases_popup['src']['addrlist']).")"."</span></b></a>'>";
//<i class="glyphicon glyphicon-list">&nbsp;</i><b>Vergelijk Producten</b>&nbsp;<span class="badge">2</span>
$alias_src_span_end="</span>";
}
//build Schedule popup box
$a_schedules = &$config['schedules']['schedule'];
$schedule_span_begin = "";
$schedule_span_end = "";
$sched_caption_escaped = "";
$sched_content = "";
$schedstatus = false;
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
$monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December'));
if(isset($config['schedules']['schedule'])) {
foreach ($a_schedules as $schedule)
{
if ($schedule['name'] == $filterent['sched'] ){
$schedstatus = filter_get_time_based_rule_status($schedule);
foreach($schedule['timerange'] as $timerange) {
$tempFriendlyTime = "";
$tempID = "";
$firstprint = false;
if ($timerange){
$dayFriendly = "";
$tempFriendlyTime = "";
//get hours // construct line ipprotocol
$temptimerange = $timerange['hour'];
$temptimeseparator = strrpos($temptimerange, "-");
$starttime = substr ($temptimerange, 0, $temptimeseparator);
$stoptime = substr ($temptimerange, $temptimeseparator+1);
if ($timerange['month']){
$tempmontharray = explode(",", $timerange['month']);
$tempdayarray = explode(",",$timerange['day']);
$arraycounter = 0;
$firstDayFound = false;
$firstPrint = false;
foreach ($tempmontharray as $monthtmp){
$month = $tempmontharray[$arraycounter];
$day = $tempdayarray[$arraycounter];
if (!$firstDayFound)
{
$firstDay = $day;
$firstmonth = $month;
$firstDayFound = true;
}
$currentDay = $day;
$nextDay = $tempdayarray[$arraycounter+1];
$currentDay++;
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
if ($firstPrint)
$dayFriendly .= ", ";
$currentDay--;
if ($currentDay != $firstDay)
$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
else
$dayFriendly .= $monthArray[$month-1] . " " . $day;
$firstDayFound = false;
$firstPrint = true;
}
$arraycounter++;
}
}
else
{
$tempdayFriendly = $timerange['position'];
$firstDayFound = false;
$tempFriendlyDayArray = explode(",", $tempdayFriendly);
$currentDay = "";
$firstDay = "";
$nextDay = "";
$counter = 0;
foreach ($tempFriendlyDayArray as $day){
if ($day != ""){
if (!$firstDayFound)
{
$firstDay = $tempFriendlyDayArray[$counter];
$firstDayFound = true;
}
$currentDay =$tempFriendlyDayArray[$counter];
//get next day
$nextDay = $tempFriendlyDayArray[$counter+1];
$currentDay++;
if ($currentDay != $nextDay){
if ($firstprint)
$dayFriendly .= ", ";
$currentDay--;
if ($currentDay != $firstDay)
$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
else
$dayFriendly .= $dayArray[$firstDay-1];
$firstDayFound = false;
$firstprint = true;
}
$counter++;
}
}
}
$timeFriendly = $starttime . " - " . $stoptime;
$description = $timerange['rangedescr'];
$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
}
}
$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
$schedule_span_begin = "<span style=\"cursor: help;\" onmouseover=\"domTT_activate(this, event, 'content', '<h1>{$sched_caption_escaped}</h1><p>{$sched_content}</p>', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><u>";
$schedule_span_end = "</u></span>";
}
}
}
$printicon = false;
$alttext = "";
$image = "";
if (!isset($filterent['disabled'])) {
if ($schedstatus) {
if ($iconfn == "block" || $iconfn == "reject") {
$image = "glyphicon-remove text-danger";
$alttext = gettext("Traffic matching this rule is currently being denied");
} else {
$image = "glyphicon-play text-success";
$alttext = gettext("Traffic matching this rule is currently being allowed");
}
$printicon = true;
} else if ($filterent['sched']) {
if ($iconfn == "block" || $iconfn == "reject")
$image = "glyphicon-remove text-muted";
else
$image = "glyphicon-remove text-danger";
$alttext = gettext("This rule is not currently active because its period has expired");
$printicon = true;
}
}
?>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<span class="<?=$textse;?>">
<?php
if (isset($filterent['ipprotocol'])) { if (isset($filterent['ipprotocol'])) {
switch($filterent['ipprotocol']) { switch($filterent['ipprotocol']) {
case "inet": case "inet":
echo "IPv4 "; $record_ipprotocol = "IPv4 ";
break; break;
case "inet6": case "inet6":
echo "IPv6 "; $record_ipprotocol = "IPv6 ";
break; break;
case "inet46": case "inet46":
echo "IPv4+6 "; $record_ipprotocol = "IPv4+6 ";
break; break;
} }
} else { } else {
echo "IPv4 "; $record_ipprotocol = "IPv4 ";
} }
if (isset($filterent['protocol'])) {
echo strtoupper($filterent['protocol']);
if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) { ?>
echo ' <span style="cursor: help;" title="ICMP type: ' . $icmptypes[$filterent['icmptype']] . '"><u>'; <tr ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
echo $filterent['icmptype']; <td>
echo '</u></span>'; <input type="checkbox" name="rule[]" value="<?=$i;?>" />
} </td>
} else echo "*"; <td>
?> <a href="#" class="act_toggle" id="toggle_<?=$i;?>" data-toggle="tooltip" data-placement="left" title="<?=gettext("click to toggle enabled/disabled status");?>">
<span class="glyphicon <?=$iconfn;?>"></span>
</a>
<?php
if (isset($filterent['log'])):?>
<span class="glyphicon glyphicon-info-sign <?=!empty($filterent['disabled']) ? "text-muted" :""?>"></span>
<?php
endif; ?>
</td>
<td>
<?=$record_ipprotocol;?>
<?php
$icmptypes = array(
"" => gettext("any"),
"echoreq" => gettext("Echo request"),
"echorep" => gettext("Echo reply"),
"unreach" => gettext("Destination unreachable"),
"squench" => gettext("Source quench"),
"redir" => gettext("Redirect"),
"althost" => gettext("Alternate Host"),
"routeradv" => gettext("Router advertisement"),
"routersol" => gettext("Router solicitation"),
"timex" => gettext("Time exceeded"),
"paramprob" => gettext("Invalid IP header"),
"timereq" => gettext("Timestamp"),
"timerep" => gettext("Timestamp reply"),
"inforeq" => gettext("Information request"),
"inforep" => gettext("Information reply"),
"maskreq" => gettext("Address mask request"),
"maskrep" => gettext("Address mask reply")
);
if (isset($filterent['protocol']) && $filterent['protocol'] == "icmp" && !empty($filterent['icmptype'])):
?>
<span data-toggle="tooltip" title="ICMP type: <?=$icmptypes[$filterent['icmptype']];?> ">
<?= isset($filterent['protocol']) ? strtoupper($filterent['protocol']) : "*";?>
</span> </span>
<?php
else:?>
<?= isset($filterent['protocol']) ? strtoupper($filterent['protocol']) : "*";?>
<?php
endif;?>
</td> </td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"> <td>
<span class="<?=$textse;?>"><?php echo $alias_src_span_begin;?><?php echo htmlspecialchars(pprint_address($filterent['source']));?><?php echo $alias_src_span_end;?></span> <?=htmlspecialchars(pprint_address($filterent['source']));?>
<?php if (isset($filterent['source']['address']) && is_alias($filterent['source']['address'])): ?>
&nbsp;<a href="/firewall_aliases_edit.php?name=<?=htmlspecialchars($filterent['source']['address']);?>"><i class="fa fa-list"></i> </a>
<?php endif; ?>
</td> </td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"> <td class="hidden-xs hidden-sm">
<span class="<?=$textse;?>"><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?></span> <?=htmlspecialchars(pprint_port(isset($filterent['source']['port']) ? $filterent['source']['port'] : null)); ?>
<?php if (isset($filterent['source']['port']) && is_alias($filterent['source']['port'])): ?>
&nbsp;<a href="/firewall_aliases_edit.php?name=<?=htmlspecialchars($filterent['source']['port']);?>"><i class="fa fa-list"></i> </a>
<?php endif; ?>
</td> </td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"> <td class="hidden-xs hidden-sm">
<span class="<?=$textse;?>"><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?></span> <?=htmlspecialchars(pprint_address($filterent['destination'])); ?>
<?php if (isset($filterent['destination']['address']) && is_alias($filterent['destination']['address'])): ?>
&nbsp;<a href="/firewall_aliases_edit.php?name=<?=htmlspecialchars($filterent['destination']['address']);?>"><i class="fa fa-list"></i> </a>
<?php endif; ?>
</td> </td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"> <td class="hidden-xs hidden-sm">
<span class="<?=$textse;?>"><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?></span> <?=htmlspecialchars(pprint_port(isset($filterent['destination']['port']) ? $filterent['destination']['port'] : null)); ?>
<?php if (isset($filterent['destination']['port']) && is_alias($filterent['destination']['port'])): ?>
&nbsp;<a href="/firewall_aliases_edit.php?name=<?=htmlspecialchars($filterent['destination']['port']);?>"><i class="fa fa-list"></i> </a>
<?php endif; ?>
</td> </td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"> <td class="hidden-xs hidden-sm">
<span class="<?=$textse;?>"><?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])) echo htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']); else echo htmlspecialchars(pprint_port($filterent['gateway'])); ?></span> <?php
if (isset($filterent['gateway'])):?>
<?=isset($config['interfaces'][$filterent['gateway']]['descr']) ? htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']) : htmlspecialchars(pprint_port($filterent['gateway'])); ?>
<?php
else: ?>
*
<?php endif; ?>
</td> </td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"> <td class="hidden-xs hidden-sm">
<span class="<?=$textse;?>"><?=gettext('none');?></span> <?php
if (!empty($filterent['sched'])):?>
<?=htmlspecialchars($filterent['sched']);?>
<a href="/firewall_schedule_edit.php?name=<?=htmlspecialchars($filterent['sched']);?>"> <span class="glyphicon glyphicon-calendar"> </span> </a>
<?php
endif;?>
</td> </td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"><font color="black"> <td>
<?php if ($printicon) { ?><span class="glyphicon <?php echo $image; ?>" title="<?php echo $alttext;?>"></span><?php } ?><span class="<?=$textse;?>"><?php echo $schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?>&nbsp;<?php echo $schedule_span_end; ?></span> <?=htmlspecialchars($filterent['descr']);?>
</font></td>
<td class="listbg descr" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<span class="<?=$textse;?>"><?=htmlspecialchars($filterent['descr']);?>&nbsp;</span>
</td> </td>
<td valign="middle" class="list nowrap"> <td>
<button name="move_<?=$i;?>_x" type="submit" title="<?=gettext("move selected rules before this rule"); ?>" class="btn btn-default btn-xs" value="<?=$i;?>"><span class="glyphicon glyphicon-arrow-left"></span></button> <a id="move_<?=$i;?>" name="move_<?=$i;?>_x" data-toggle="tooltip" data-placement="left" title="<?=gettext("move selected rules before this rule");?>" class="act_move btn btn-default btn-xs">
<a href="firewall_rules_edit.php?id=<?=$i;?>" title="<?=gettext("edit rule"); ?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a> <span class="glyphicon glyphicon-arrow-left"></span>
</a>
<a href="firewall_rules.php?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" title="<?=gettext("delete rule"); ?>" onclick="return confirm('Do you really want to delete this rule?')" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a> <a href="firewall_rules_edit.php?id=<?=$i;?>" data-toggle="tooltip" data-placement="left" title="<?=gettext("edit this rule");?>" class="btn btn-default btn-xs">
<a href="firewall_rules_edit.php?dup=<?=$i;?>" title="<?=gettext("add a new rule based on this one"); ?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a> <span class="glyphicon glyphicon-pencil"></span>
</a>
<a id="del_<?=$i;?>" title="<?=gettext("delete this rule"); ?>" data-toggle="tooltip" class="act_delete btn btn-default btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</a>
<a href="firewall_rules_edit.php?dup=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="left" title="<?=gettext("add new rule based on this one");?>">
<span class="glyphicon glyphicon-plus"></span>
</a>
</td> </td>
</tr> </tr>
<?php $nrules++; endfor; ?> <?php
</tbody> endif;
<?php if ($nrules == 0): ?> endforeach;
if (!$interface_has_rules):
?>
<tr> <tr>
<td class="listt"></td> <td colspan="11" align="center" valign="middle">
<td class="listt"></td>
<td class="listlr" colspan="11" align="center" valign="middle">
<span class="gray"> <span class="gray">
<?php if ($_REQUEST['if'] == "FloatingRules"): ?> <?php if ($selected_if == "FloatingRules"): ?>
<?=gettext("No floating rules are currently defined."); ?><br /><br /> <?=gettext("No floating rules are currently defined."); ?><br /><br />
<?php else: ?> <?php else: ?>
<?=gettext("No rules are currently defined for this interface"); ?><br /> <?=gettext("No rules are currently defined for this interface"); ?><br />
<?=gettext("All incoming connections on this interface will be blocked until you add pass rules."); ?><br /><br /> <?=gettext("All incoming connections on this interface will be blocked until you add pass rules."); ?><br /><br />
<?php endif; ?> <?php endif; ?>
<?=gettext("Click the"); ?> <a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a><?=gettext(" button to add a new rule.");?></span> <?=gettext("Click the"); ?>
<a href="firewall_rules_edit.php?if=<?=$selected_if;?>" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-plus"></span>
</a>
<?=gettext(" button to add a new rule.");?></span>
</td> </td>
</tr> </tr>
<?php endif; ?> <?php else: ?>
<tr id="fr<?=$nrules;?>"> <tr>
<td class="list"></td> <td colspan="5"></td>
<td class="list"></td> <td colspan="5" class="hidden-xs hidden-sm"></td>
<td class="list">&nbsp;</td> <td>
<td class="list">&nbsp;</td> <a type="submit" id="move_<?=$i;?>" name="move_<?=$i;?>_x" data-toggle="tooltip" data-placement="left" title="<?=gettext("move selected rules to end");?>" class="act_move btn btn-default btn-xs">
<td class="list">&nbsp;</td> <span class="glyphicon glyphicon-arrow-left"></span>
<td class="list">&nbsp;</td> </a>
<td class="list">&nbsp;</td> <a id="del_x" title="<?=gettext("delete selected rules"); ?>" data-toggle="tooltip" class="act_delete btn btn-default btn-xs">
<td class="list">&nbsp;</td> <span class="glyphicon glyphicon-remove"></span>
<td class="list">&nbsp;</td> </a>
<td class="list">&nbsp;</td> <a href="firewall_rules_edit.php?if=<?=$selected_if;?>" class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="left" title="<?=gettext("add new rule");?>">
<td class="list">&nbsp;</td> <span class="glyphicon glyphicon-plus"></span>
<td class="list"> </a>
<?php if ($nrules): ?>
<button name="move_<?=$i;?>_x" type="submit" value="<?=$i;?>" title="<?=gettext("move selected rules to end");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-arrow-left"></span></button>
<button name="del_x" type="submit" title="<?=gettext("delete selected rules");?>" onclick="return confirm('<?=gettext('Do you really want to delete the selected rules?');?>')" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></button>
<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>" title="<?=gettext("add new rule");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span></a>
<?php endif; ?>
</td> </td>
</tr> </tr>
<?php endif; ?>
</tbody> </tbody>
</table> <tfoot>
<tr>
<td colspan="11">&nbsp;</td>
<div class="container-fluid"> </tr>
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="icons"> <tr class="hidden-xs hidden-sm">
<td colspan="11">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> <tr>
<td width="16"><span class="glyphicon glyphicon-play text-success"></span></td> <td width="16"><span class="glyphicon glyphicon-play text-success"></span></td>
<td width="100"><?=gettext("pass");?></td> <td width="100"><?=gettext("pass");?></td>
...@@ -884,102 +567,46 @@ include("head.inc"); ...@@ -884,102 +567,46 @@ include("head.inc");
<td width="16"><span class="glyphicon glyphicon-info-sign text-muted"></span></td> <td width="16"><span class="glyphicon glyphicon-info-sign text-muted"></span></td>
<td class="nowrap"><?=gettext("log (disabled)");?></td> <td class="nowrap"><?=gettext("log (disabled)");?></td>
</tr> </tr>
<tr> </table>
<td colspan="10"> </td>
<p>&nbsp;</p> </tr>
<tr class="hidden-xs hidden-sm">
<td><a><i class="fa fa-list"></i></a></td>
<td colspan="10"><?=gettext("Alias (click to view/edit)");?></td>
</tr>
<tr class="hidden-xs hidden-sm">
<td><a><span class="glyphicon glyphicon-calendar"> </span></a></td>
<td colspan="10"><?=gettext("Schedule (click to view/edit)");?></td>
</tr>
<tr class="hidden-xs hidden-sm">
<td colspan="11">
<strong> <strong>
<span class="red"><?=gettext("Hint:");?></span> <span class="text-danger"><?=gettext("Hint:");?></span>
</strong><br /> </strong>
<ul> <br />
<?php if ("FloatingRules" != $if): ?> <?php if ("FloatingRules" != $selected_if): ?>
<li><?=gettext("Rules are evaluated on a first-match basis (i.e. " . <?=gettext("Rules are evaluated on a first-match basis (i.e. " .
"the action of the first rule to match a packet will be executed). " . "the action of the first rule to match a packet will be executed). " .
"This means that if you use block rules, you'll have to pay attention " . "This means that if you use block rules, you'll have to pay attention " .
"to the rule order. Everything that isn't explicitly passed is blocked " . "to the rule order. Everything that isn't explicitly passed is blocked " .
"by default. ");?> "by default. ");?>
</li>
<?php else: ?> <?php else: ?>
<li><?=gettext("Floating rules are evaluated on a first-match basis (i.e. " . <?=gettext("Floating rules are evaluated on a first-match basis (i.e. " .
"the action of the first rule to match a packet will be executed) only " . "the action of the first rule to match a packet will be executed) only " .
"if the 'quick' option is checked on a rule. Otherwise they will only apply if no " . "if the 'quick' option is checked on a rule. Otherwise they will only apply if no " .
"other rules match. Pay close attention to the rule order and options " . "other rules match. Pay close attention to the rule order and options " .
"chosen. If no rule here matches, the per-interface or default rules are used. ");?> "chosen. If no rule here matches, the per-interface or default rules are used. ");?>
</li>
<?php endif; ?> <?php endif; ?>
</ul>
</td> </td>
</tr> </tr>
</tfoot>
</table> </table>
</div> </div>
</div>
</form> </form>
</div> </div>
</section> </section>
</div> </div>
</div> </div>
</section> </section>
<input type="hidden" name="if" value="<?=htmlspecialchars($if);?>" />
<!-- <script type="text/javascript">
//<![CDATA[
var number_of_rules = <?=$nrules?>;
<?php $nrules = 0; for ($i = 0; isset($a_filter[$i]); $i++): ?>
Sortable.create("dragtable", {
tag:"tr",
format:"fr([0-9999999])",
containment:["dragtable"],
onChange:function(affected) {
document.body.style.cursor = 'move';
},
onUpdate:function(container) {
document.body.style.cursor = 'move';
updateOrder(Sortable.serialize('dragtable', 'tr'));
}
});
<?php endfor; ?>
jQuery('#loading').hide();
//]]>
</script> -->
<script type="text/javascript">
$(function () {
$('table.dragable').sortable({
containerSelector: 'table',
itemPath: '> tbody#dragtable',
itemSelector: 'tr',
placeholder: '<tr class="placeholder"/>',
onDrop: function(item,container,_super, event) {
item.removeClass("dragged").removeAttr("style");
$("body").removeClass("dragging");
updateOrder(container);
}
})
});
function updateOrder(container) {
if(document.getElementById("redboxtable"))
//jQuery('#redboxtable').hide();
//jQuery('#loading').show();
document.body.style.cursor = 'wait';
var drag_url = '';
$('tbody#dragtable tr').each(function(i, obj) {
drag_url += '&dragtable[]='+$(obj).attr('id').replace('fr','');
});
document.location = 'firewall_rules.php?if=<?=htmlspecialchars($if);?>&dragdroporder=true' + drag_url;
return;
}
</script>
<?php include("foot.inc"); ?> <?php include("foot.inc"); ?>
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -30,109 +30,121 @@ ...@@ -30,109 +30,121 @@
require_once("guiconfig.inc"); require_once("guiconfig.inc");
require_once("filter.inc"); require_once("filter.inc");
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun')); $dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
$monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December')); $monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December'));
$pgtitle = array(gettext("Firewall"),gettext("Schedules")); $pgtitle = array(gettext("Firewall"),gettext("Schedules"));
if (!is_array($config['schedules']['schedule'])) if (!isset($config['schedules']['schedule'])) {
$config['schedules']['schedule'] = array(); $config['schedules']['schedule'] = array();
}
$a_schedules = &$config['schedules']['schedule']; $a_schedules = &$config['schedules']['schedule'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pconfig = $_POST;
if (isset($pconfig['id']) && isset($a_schedules[$pconfig['id']])) {
// id found and valid
$id = $pconfig['id'];
}
if ($_GET['act'] == "del") { if (isset($pconfig['act']) && $pconfig['act'] == 'del' && isset($id)) {
if ($a_schedules[$_GET['id']]) { /* make sure rule is not being referenced by filter rule */
/* make sure rule is not being referenced by any nat or filter rules */
$is_schedule_referenced = false;
$referenced_by = false; $referenced_by = false;
$schedule_name = $a_schedules[$_GET['id']]['name']; if(isset($config['filter']['rule'])) {
if(is_array($config['filter']['rule'])) {
foreach($config['filter']['rule'] as $rule) { foreach($config['filter']['rule'] as $rule) {
//check for this later once this is established //check for this later once this is established
if ($rule['sched'] == $schedule_name){ if ($rule['sched'] == $a_schedules[$id]['name']){
$referenced_by = $rule['descr']; $referenced_by = $rule['descr'];
$is_schedule_referenced = true;
break; break;
} }
} }
} }
if($is_schedule_referenced == true) { if( $referenced_by !== false) {
$savemsg = sprintf(gettext("Cannot delete Schedule. Currently in use by %s"),$referenced_by); $savemsg = sprintf(gettext("Cannot delete Schedule. Currently in use by %s"),$referenced_by);
} else { } else {
unset($a_schedules[$_GET['id']]); unset($a_schedules[$id]);
write_config(); write_config();
header("Location: firewall_schedule.php"); header("Location: firewall_schedule.php");
exit; exit;
} }
} }
} }
include("head.inc"); include("head.inc");
legacy_html_escape_form_data($a_schedules);
$main_buttons = array( $main_buttons = array(
array('label'=>'Add a new schedule', 'href'=>'firewall_schedule_edit.php'), array('label'=>'Add a new schedule', 'href'=>'firewall_schedule_edit.php'),
); );
?> ?>
<body> <body>
<?php include("fbegin.inc"); ?> <script type="text/javascript">
$( document ).ready(function() {
// link delete buttons
$(".act_delete").click(function(){
var id = $(this).attr("id").split('_').pop(-1);
// delete single
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Rules");?>",
message: "<?=gettext('Do you really want to delete this schedule?');?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#id").val(id);
$("#action").val("del");
$("#iform").submit()
}
}]
});
});
});
</script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<?php if (isset($savemsg)) print_info_box($savemsg); ?> <?php if (isset($savemsg)) print_info_box($savemsg); ?>
<section class="col-xs-12"> <section class="col-xs-12">
<div class="content-box content-box-main ">
<div class="content-box">
<div class="content-box-main ">
<form action="firewall_schedule.php" method="post" name="iform" id="iform"> <form action="firewall_schedule.php" method="post" name="iform" id="iform">
<input type="hidden" id="id" name="id" value="" />
<input type="hidden" id="action" name="act" value="" />
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-sort"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<td width="25%" class="listhdrr"><?=gettext("Name");?></td> <td><?=gettext("Name");?></td>
<td width="35%" class="listhdrr"><?=gettext("Time Range(s)");?></td> <td><?=gettext("Time Range(s)");?></td>
<td width="35%" class="listhdr"><?=gettext("Description");?></td> <td><?=gettext("Description");?></td>
<td width="5%" class="list sort_ignore"> <td></td>
</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $i = 0; foreach ($a_schedules as $schedule): ?> <?php $i = 0; foreach ($a_schedules as $schedule): ?>
<tr> <tr ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';"> <td>
<?=htmlspecialchars($schedule['name']);?> <?=$schedule['name'];?>
<?php <?php
$schedstatus = filter_get_time_based_rule_status($schedule); if (filter_get_time_based_rule_status($schedule)):?>
if ($schedstatus) { ?> <span data-toggle="tooltip" title="<?=gettext("Schedule is currently active");?>" class="fa fa-clock-o"></span>
&nbsp;<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_frmfld_time.png" title="<?=gettext("Schedule is currently active");?>" width="17" height="17" border="0" alt="schedule" /> <?php
<?php } ?> endif;?>
</td> </td>
<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';"> <td>
<table width="98%" border="0" cellpadding="0" cellspacing="0" summary="schedule"> <table class="table table-condensed table-striped">
<?php <?php
foreach($schedule['timerange'] as $timerange) { foreach($schedule['timerange'] as $timerange) {
$tempFriendlyTime = "";
$tempID = "";
$firstprint = false; $firstprint = false;
if ($timerange){ if ($timerange){
$dayFriendly = ""; $dayFriendly = "";
$tempFriendlyTime = "";
//get hours //get hours
$temptimerange = $timerange['hour']; $temptimerange = $timerange['hour'];
...@@ -174,9 +186,7 @@ $main_buttons = array( ...@@ -174,9 +186,7 @@ $main_buttons = array(
} }
$arraycounter++; $arraycounter++;
} }
} } else {
else
{
$tempdayFriendly = $timerange['position']; $tempdayFriendly = $timerange['position'];
$firstDayFound = false; $firstDayFound = false;
$tempFriendlyDayArray = explode(",", $tempdayFriendly); $tempFriendlyDayArray = explode(",", $tempdayFriendly);
...@@ -217,30 +227,35 @@ $main_buttons = array( ...@@ -217,30 +227,35 @@ $main_buttons = array(
} }
}//end for?></table> }//end for?></table>
</td> </td>
<td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';"> <td>
<?=htmlspecialchars($schedule['descr']);?>&nbsp; <?=$schedule['descr'];?>
</td> </td>
<td valign="middle" class="list nowrap"> <td>
<table border="0" cellspacing="0" cellpadding="1" summary="buttons"> <a href="firewall_schedule_edit.php?id=<?=$i;?>" data-toggle="tooltip" data-placement="left" title="<?=gettext("edit this schedule");?>" class="btn btn-default btn-xs">
<tr> <span class="glyphicon glyphicon-pencil"></span>
<td valign="middle"><a href="firewall_schedule_edit.php?id=<?=$i;?>" title="<?=gettext("edit alias");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a></td> </a>
<td><a href="firewall_schedule.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext('Do you really want to delete this schedule?');?>')" title="<?=gettext("delete alias");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></a></td> <a id="del_<?=$i;?>" title="<?=gettext("delete this schedule"); ?>" data-toggle="tooltip" class="act_delete btn btn-default btn-xs">
</tr> <span class="glyphicon glyphicon-remove"></span>
</table> </a>
<a href="firewall_schedule.php?dup=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="left" title="<?=gettext("add new schedule based on this one");?>">
<span class="glyphicon glyphicon-plus"></span>
</a>
</td> </td>
</tr> </tr>
<?php $i++; endforeach; ?> <?php
$i++;
endforeach; ?>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="container-fluid"> <div class="container-fluid">
<p><span class="vexpl"><span class="text-danger"><strong><?=gettext("Note:");?><br /></strong></span><?=gettext("Schedules act as placeholders for time ranges to be used in Firewall Rules.");?></span></p> <span class="text-danger"><strong><?=gettext("Note:");?><br /></strong></span>
<?=gettext("Schedules act as placeholders for time ranges to be used in Firewall Rules.");?>
</div> </div>
</form> </form>
</div> </div>
</div>
</section> </section>
</div> </div>
</div> </div>
</section> </section>
<?php include("foot.inc"); ?> <?php include("foot.inc"); ?>
...@@ -75,98 +75,94 @@ function schedule_sort(){ ...@@ -75,98 +75,94 @@ function schedule_sort(){
usort($config['schedules']['schedule'], "schedulecmp"); usort($config['schedules']['schedule'], "schedulecmp");
} }
$pgtitle = array(gettext("Firewall"),gettext("Schedules"),gettext("Edit"));
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_schedule.php');
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun')); $dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
$monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December')); $monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December'));
if (!is_array($config['schedules']['schedule']))
$config['schedules']['schedule'] = array();
if (!isset($config['schedules']['schedule'])) {
$config['schedules']['schedule'] = array();
}
$a_schedules = &$config['schedules']['schedule']; $a_schedules = &$config['schedules']['schedule'];
if (is_numericint($_GET['id'])) if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// input record id, if valid
if (!empty($_GET['name'])) {
foreach ($a_schedules as $i => $sched) {
if ($sched['name'] == $_GET['name']) {
$id = $i;
break;
}
}
} elseif (isset($_GET['dup']) && isset($a_schedules[$_GET['dup']])) {
$configId = $_GET['dup'];
} elseif (isset($_GET['id']) && isset($a_schedules[$_GET['id']])) {
$id = $_GET['id']; $id = $_GET['id'];
if (isset($_POST['id']) && is_numericint($_POST['id'])) $configId = $id;
}
$pconfig['name'] = $a_schedules[$configId]['name'];
$pconfig['descr'] = $a_schedules[$configId]['descr'];
$pconfig['timerange'] = isset($a_schedules[$configId]['timerange']) ? $a_schedules[$configId]['timerange'] : array();
$pconfig['schedlabel'] = isset($a_schedules[$configId]['schedlabel']) ? $a_schedules[$configId]['schedlabel'] : uniqid();
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id']) && isset($a_schedules[$_POST['id']])) {
$id = $_POST['id']; $id = $_POST['id'];
}
$pconfig = $_POST;
if (isset($id) && $a_schedules[$id]) { // validate
$pconfig['name'] = $a_schedules[$id]['name']; if(strtolower($pconfig['name']) == "lan")
$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
$pconfig['timerange'] = $a_schedules[$id]['timerange'];
$pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
$getSchedule = true;
}
if ($_POST) {
if(strtolower($_POST['name']) == "lan")
$input_errors[] = gettext("Schedule may not be named LAN."); $input_errors[] = gettext("Schedule may not be named LAN.");
if(strtolower($_POST['name']) == "wan") if(strtolower($pconfig['name']) == "wan")
$input_errors[] = gettext("Schedule may not be named WAN."); $input_errors[] = gettext("Schedule may not be named WAN.");
if(strtolower($_POST['name']) == "") if(strtolower($pconfig['name']) == "")
$input_errors[] = gettext("Schedule name cannot be blank."); $input_errors[] = gettext("Schedule name cannot be blank.");
$x = is_validaliasname($pconfig['name']);
$x = is_validaliasname($_POST['name']);
if (!isset($x)) { if (!isset($x)) {
$input_errors[] = gettext("Reserved word used for schedule name."); $input_errors[] = gettext("Reserved word used for schedule name.");
} else { } elseif ($x == false) {
if (is_validaliasname($_POST['name']) == false)
$input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9"); $input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9");
} }
/* check for name conflicts */ /* check for name conflicts */
foreach ($a_schedules as $schedule) { foreach ($a_schedules as $schedId => $schedule) {
if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule)) if ( $schedId != $id && $schedule['name'] == $pconfig['name']) {
continue;
if ($schedule['name'] == $_POST['name']) {
$input_errors[] = gettext("A Schedule with this name already exists."); $input_errors[] = gettext("A Schedule with this name already exists.");
break; break;
} }
} }
$schedule = array();
$schedule['name'] = $_POST['name']; // parse time ranges
$schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8'); $pconfig['timerange'] = array();
$timerangeFound = false; $timerangeFound = false;
for ($x=0; $x<99; $x++){ for ($x=0; $x<99; $x++){
if($_POST['schedule' . $x]) { if($pconfig['schedule' . $x]) {
if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['starttime' . $x])) { if (!preg_match('/^[0-9]+:[0-9]+$/', $pconfig['starttime' . $x])) {
$input_errors[] = sprintf(gettext("Invalid start time - '%s'"), $_POST['starttime' . $x]); $input_errors[] = sprintf(gettext("Invalid start time - '%s'"), $pconfig['starttime' . $x]);
continue; continue;
} }
if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['stoptime' . $x])) { if (!preg_match('/^[0-9]+:[0-9]+$/', $pconfig['stoptime' . $x])) {
$input_errors[] = sprintf(gettext("Invalid stop time - '%s'"), $_POST['stoptime' . $x]); $input_errors[] = sprintf(gettext("Invalid stop time - '%s'"), $pconfig['stoptime' . $x]);
continue; continue;
} }
$timerangeFound = true; $timerangeFound = true;
$timeparts = array(); $timeparts = array();
$firstprint = false; $firstprint = false;
$timestr = $_POST['schedule' . $x]; $timestr = $pconfig['schedule' . $x];
$timehourstr = $_POST['starttime' . $x]; $timehourstr = $pconfig['starttime' . $x];
$timehourstr .= "-"; $timehourstr .= "-";
$timehourstr .= $_POST['stoptime' . $x]; $timehourstr .= $pconfig['stoptime' . $x];
$timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8'); $timedescrstr = htmlentities($pconfig['timedescr' . $x], ENT_QUOTES, 'UTF-8');
$dashpos = strpos($timestr, '-'); $dashpos = strpos($timestr, '-');
if ($dashpos === false) if ($dashpos === false) {
{
$timeparts['position'] = $timestr; $timeparts['position'] = $timestr;
} } else {
else
{
$tempindarray = array(); $tempindarray = array();
$monthstr = ""; $monthstr = "";
$daystr = ""; $daystr = "";
$tempindarray = explode(",", $timestr); $tempindarray = explode(",", $timestr);
foreach ($tempindarray as $currentselection) foreach ($tempindarray as $currentselection) {
{
if ($currentselection){ if ($currentselection){
if ($firstprint) if ($firstprint) {
{
$monthstr .= ","; $monthstr .= ",";
$daystr .= ","; $daystr .= ",";
} }
...@@ -183,52 +179,42 @@ if ($_POST) { ...@@ -183,52 +179,42 @@ if ($_POST) {
} }
$timeparts['hour'] = $timehourstr; $timeparts['hour'] = $timehourstr;
$timeparts['rangedescr'] = $timedescrstr; $timeparts['rangedescr'] = $timedescrstr;
$schedule['timerange'][$x] = $timeparts; $pconfig['timerange'][$x] = $timeparts;
} }
} }
if (!$timerangeFound) if (count($pconfig['timerange']) == 0) {
$input_errors[] = gettext("The schedule must have at least one time range configured."); $input_errors[] = gettext("The schedule must have at least one time range configured.");
}
if (!$input_errors) { if (count($input_errors) == 0) {
$schedule = array();
if (!empty($pconfig['schedlabel'])) $schedule['name'] = $pconfig['name'];
$schedule['descr'] = $pconfig['descr'];
$schedule['timerange'] = $pconfig['timerange'];
$schedule['schedlabel'] = $pconfig['schedlabel']; $schedule['schedlabel'] = $pconfig['schedlabel'];
else
$schedule['schedlabel'] = uniqid();
if (isset($id) && $a_schedules[$id]){ if (isset($id)) {
$a_schedules[$id] = $schedule; $a_schedules[$id] = $schedule;
} } else {
else{
$a_schedules[] = $schedule; $a_schedules[] = $schedule;
} }
schedule_sort(); schedule_sort();
if (write_config()) if (write_config()) {
filter_configure(); filter_configure();
}
header("Location: firewall_schedule.php"); header("Location: firewall_schedule.php");
exit; exit;
}
//we received input errors, copy data to prevent retype
else
{
if (!$_POST['schedule0'])
$getSchedule = false;
else
$getSchedule = true;
$pconfig['name'] = $schedule['name'];
$pconfig['descr'] = $schedule['descr'];
$pconfig['timerange'] = $schedule['timerange'];
} }
} }
include("head.inc");
/* put your custom HTML head content here */
/* using some of the new function calls */ $pgtitle = array(gettext("Firewall"),gettext("Schedules"),gettext("Edit"));
$jscriptstr = <<<EOD legacy_html_escape_form_data($pconfig);
include("head.inc");
?>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
var daysSelected = ""; var daysSelected = "";
...@@ -366,11 +352,11 @@ function daytoggle(id) { ...@@ -366,11 +352,11 @@ function daytoggle(id) {
} }
function update_month(){ function update_month(){
var indexNum = document.forms[0].monthsel.selectedIndex; var indexNum = document.iform.monthsel.selectedIndex;
var selected = document.forms[0].monthsel.options[indexNum].text; var selected = document.iform.monthsel.options[indexNum].text;
for (i=0; i<=11; i++){ for (i=0; i<=11; i++){
option = document.forms[0].monthsel.options[i].text; option = document.iform.monthsel.options[i].text;
document.popupMonthLayer = eval('document.getElementById (option)'); document.popupMonthLayer = eval('document.getElementById (option)');
if(selected == option) { if(selected == option) {
...@@ -638,15 +624,15 @@ function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimeh ...@@ -638,15 +624,15 @@ function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimeh
tr.appendChild(td); tr.appendChild(td);
td = d.createElement("td"); td = d.createElement("td");
td.innerHTML="<input type='text' readonly class='vexpl' name='starttime" + schCounter + "' id='starttime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + starttimehour + ":" + starttimemin + "' />"; td.innerHTML="<input type='text' readonly name='starttime" + schCounter + "' id='starttime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + starttimehour + ":" + starttimemin + "' />";
tr.appendChild(td); tr.appendChild(td);
td = d.createElement("td"); td = d.createElement("td");
td.innerHTML="<input type='text' readonly class='vexpl' name='stoptime" + schCounter + "' id='stoptime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + stoptimehour + ":" + stoptimemin + "' />"; td.innerHTML="<input type='text' readonly name='stoptime" + schCounter + "' id='stoptime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + stoptimehour + ":" + stoptimemin + "' />";
tr.appendChild(td); tr.appendChild(td);
td = d.createElement("td"); td = d.createElement("td");
td.innerHTML="<input type='text' readonly class='vexpl' name='timedescr" + schCounter + "' id='timedescr" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + tempdescr + "' />"; td.innerHTML="<input type='text' readonly name='timedescr" + schCounter + "' id='timedescr" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + tempdescr + "' />";
tr.appendChild(td); tr.appendChild(td);
td = d.createElement("td"); td = d.createElement("td");
...@@ -753,6 +739,7 @@ function editRow(incTime, el) { ...@@ -753,6 +739,7 @@ function editRow(incTime, el) {
} }
removeRownoprompt(el); removeRownoprompt(el);
} }
$('.selectpicker').selectpicker('refresh');
} }
function removeRownoprompt(el) { function removeRownoprompt(el) {
...@@ -782,126 +769,113 @@ function removeRow(el) { ...@@ -782,126 +769,113 @@ function removeRow(el) {
} }
//]]> //]]>
</script> </script>
EOD;
?>
<body> <body>
<?php include("fbegin.inc"); echo $jscriptstr; ?> <?php include("fbegin.inc"); echo $jscriptstr; ?>
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?> <?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<div id="inputerrors"></div>
<section class="col-xs-12"> <section class="col-xs-12">
<div class="content-box content-box-main">
<div class="content-box">
<header class="content-box-head container-fluid">
<h3><?=gettext("Schedule information");?></h3>
</header>
<div class="content-box-main">
<form action="firewall_schedule_edit.php" method="post" name="iform" id="iform"> <form action="firewall_schedule_edit.php" method="post" name="iform" id="iform">
<input type="hidden" name="schedlabel" value="<?=$pconfig['schedlabel'];?>"/>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-sort"> <table class="table table-striped">
<tbody> <tbody>
<tr> <tr>
<td width="15%" valign="top" class="vncellreq"><?=gettext("Schedule Name");?></td> <td width="15%"><strong><?=gettext("Schedule information");?></strong></td>
<td width="85%" class="vtable"> <td width="85%" align="right">
<?php if(is_schedule_inuse($pconfig['name']) == true): ?> <small><?=gettext("full help"); ?> </small>
<input name="name" type="hidden" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" /> <i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i></a>
<?php echo $pconfig['name']; ?> </td>
</tr>
<tr>
<td><a id="help_for_name" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Schedule Name");?></td>
<td>
<?php
if(is_schedule_inuse($pconfig['name']) == true):?>
<input name="name" type="hidden" id="name" value="<?=htmlspecialchars($pconfig['name']);?>" />
<?=$pconfig['name']; ?>
<p> <p>
<span class="vexpl"><?=gettext("NOTE: This schedule is in use so the name may not be modified!");?></span> <?=gettext("NOTE: This schedule is in use so the name may not be modified!");?>
</p> </p>
<?php else: ?> <?php
<input name="name" type="text" id="name" size="40" maxlength="40" class="form-control unknown" value="<?=htmlspecialchars($pconfig['name']);?>" /><br /> else: ?>
<span class="vexpl"> <input name="name" type="text" id="name" value="<?=$pconfig['name'];?>" />
<div class="hidden" for="help_for_name">
<?=gettext("The name of the alias may only consist of the characters a-z, A-Z and 0-9");?> <?=gettext("The name of the alias may only consist of the characters a-z, A-Z and 0-9");?>
</span> </div>
<?php endif; ?> <?php
endif; ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="15%" valign="top" class="vncell"><?=gettext("Description");?></td> <td><a id="help_for_description" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description");?></td>
<td width="85%" class="vtable"><input name="descr" type="text" id="descr" size="40" maxlength="40" class="form-control unknown" value="<?=htmlspecialchars($pconfig['descr']);?>" /><br /> <td>
<span class="vexpl"> <input name="descr" type="text" id="descr" value="<?=$pconfig['descr'];?>" /><br />
<div class="hidden" for="help_for_name">
<?=gettext("You may enter a description here for your reference (not parsed).");?> <?=gettext("You may enter a description here for your reference (not parsed).");?>
</span> </div>
</td> </td>
</tr> </tr>
<!-- tr>
</tr -->
<tr> <tr>
<td width="15%" valign="top" class="vncellreq"><?=gettext("Month");?></td> <td><a id="help_for_month" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Month");?></td>
<td width="85%" class="vtable"> <td>
<select name="monthsel" class="form-control" id="monthsel" onchange="update_month();"> <select name="monthsel" class="selectpicker" data-width="auto" data-live-search="true" id="monthsel" onchange="update_month();">
<?php <?php
$monthcounter = date("n"); $monthcounter = date("n");
$monthlimit = $monthcounter + 12; $monthlimit = $monthcounter + 12;
$yearcounter = date("Y"); $yearcounter = date("Y");
for ($k=0; $k<12; $k++){?> for ($k=0; $k<12; $k++){?>
<option value="<?php echo $monthcounter;?>"><?php echo date("F_y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option> <option value="<?= $monthcounter;?>"><?=date("F_y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option>
<?php <?php
if ($monthcounter == 12) if ($monthcounter == 12) {
{
$monthcounter = 1; $monthcounter = 1;
$yearcounter++; $yearcounter++;
} } else {
else
{
$monthcounter++; $monthcounter++;
} }
} ?> } ?>
</select><br /><br /> </select>
<?php <br /><br />
<?php
$firstmonth = TRUE; $firstmonth = TRUE;
$monthcounter = date("n"); $monthcounter = date("n");
$yearcounter = date("Y"); $yearcounter = date("Y");
for ($k=0; $k<12; $k++){ for ($k=0; $k<12; $k++){
$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter))); $firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
if ($firstdayofmonth == 0) if ($firstdayofmonth == 0) {
$firstdayofmonth = 7; $firstdayofmonth = 7;
}
$daycounter = 1; $daycounter = 1;
//number of day in month //number of day in month
$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter))); $numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
$firstdayprinted = FALSE; $firstdayprinted = FALSE;
$lasttr = FALSE; $lasttr = FALSE;
$positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc $positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc
?> ?>
<div id="<?php echo date("F_y",mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?>" style=" position:relative; display:<?php if($firstmonth)echo "block";else echo "none";?>"> <div id="<?=date("F_y",mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?>" style=" position:relative; display:<?= $firstmonth ? "block" : "none";?>">
<table border="1" cellspacing="1" cellpadding="1" id="calTable<?=$monthcounter . $yearcounter;?>" class="tabcont " summary="month"> <table border="1" cellspacing="1" cellpadding="1" id="calTable<?=$monthcounter . $yearcounter;?>" class="table table-condensed" summary="month">
<thead> <thead>
<tr><td colspan="7" align="center" class="listbg"><?php echo date("F_Y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></td></tr> <tr><td colspan="7" align="center"><?= date("F_Y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></td></tr>
<tr> <tr>
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p1');"><u><?=gettext("Mon");?></u></td> <td align="center" style="cursor: pointer;" onclick="daytoggle('w1p1');"><u><?=gettext("Mon");?></u></td>
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p2');"><u><?=gettext("Tue");?></u></td> <td align="center" style="cursor: pointer;" onclick="daytoggle('w1p2');"><u><?=gettext("Tue");?></u></td>
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p3');"><u><?=gettext("Wed");?></u></td> <td align="center" style="cursor: pointer;" onclick="daytoggle('w1p3');"><u><?=gettext("Wed");?></u></td>
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p4');"><u><?=gettext("Thu");?></u></td> <td align="center" style="cursor: pointer;" onclick="daytoggle('w1p4');"><u><?=gettext("Thu");?></u></td>
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p5');"><u><?=gettext("Fri");?></u></td> <td align="center" style="cursor: pointer;" onclick="daytoggle('w1p5');"><u><?=gettext("Fri");?></u></td>
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p6');"><u><?=gettext("Sat");?></u></td> <td align="center" style="cursor: pointer;" onclick="daytoggle('w1p6');"><u><?=gettext("Sat");?></u></td>
<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p7');"><u><?=gettext("Sun");?></u></td> <td align="center" style="cursor: pointer;" onclick="daytoggle('w1p7');"><u><?=gettext("Sun");?></u></td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php <?php
$firstmonth = FALSE; $firstmonth = FALSE;
while ($daycounter<=$numberofdays){ while ($daycounter<=$numberofdays){
$weekcounter = date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter))); $weekcounter = date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
$weekcounter = ltrim($weekcounter, "0"); $weekcounter = ltrim($weekcounter, "0");
if ($positioncounter == 1) if ($positioncounter == 1) {
{
echo "<tr>"; echo "<tr>";
} }
if ($firstdayofmonth == $positioncounter){?> if ($firstdayofmonth == $positioncounter){?>
...@@ -910,122 +884,112 @@ EOD; ...@@ -910,122 +884,112 @@ EOD;
$daycounter++; $daycounter++;
$firstdayprinted = TRUE; $firstdayprinted = TRUE;
echo "</td>"; echo "</td>";
} } elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays){?>
elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays){?>
<td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');"> <td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
<?php echo $daycounter; <?php echo $daycounter;
$daycounter++; $daycounter++;
echo "</td>"; echo "</td>";
} } else {
else
{
echo "<td align=\"center\" class=\"listr\"></td>"; echo "<td align=\"center\" class=\"listr\"></td>";
} }
if ($positioncounter == 7 || $daycounter > $numberofdays){ if ($positioncounter == 7 || $daycounter > $numberofdays) {
$positioncounter = 1; $positioncounter = 1;
echo "</tr>"; echo "</tr>";
} } else {
else{
$positioncounter++; $positioncounter++;
} }
}//end while loop?> }//end while loop?>
</tbody> </tbody>
</table> </table>
</div> </div>
<?php <?php
if ($monthcounter == 12) {
if ($monthcounter == 12)
{
$monthcounter = 1; $monthcounter = 1;
$yearcounter++; $yearcounter++;
} } else {
else
{
$monthcounter++; $monthcounter++;
} }
} //end for loop } //end for loop
?> ?>
<div class="hidden" for="help_for_month">
<br /> <br />
<?=gettext("Click individual date to select that date only. Click the appropriate weekday Header to select all occurrences of that weekday.");?> <?=gettext("Click individual date to select that date only. Click the appropriate weekday Header to select all occurrences of that weekday.");?>
</div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="15%" valign="top" class="vncellreq"><?=gettext("Time");?></td> <td><a id="help_for_time" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Time");?></td>
<td width="85%" class="vtable"> <td>
<table cellspacing="2" class="tabcont" summary="time"> <table cellspacing="2" class="tabcont" summary="time">
<tr> <tr>
<td class="listhdrr" align="center"><?=gettext("Start Time");?></td><td></td><td class="listhdrr" align="center"><?=gettext("Stop Time");?></td> <td><?=gettext("Start Time");?></td>
<td><?=gettext("Stop Time");?></td>
</tr> </tr>
<tr> <tr>
<td> <td>
<select name="starttimehour" class="form-control" id="starttimehour"> <div class="input-group">
<?php <select name="starttimehour" class="selectpicker form-control" data-width="auto" data-size="5" data-live-search="true" id="starttimehour">
for ($i=0; $i<24; $i++) <?php
{ for ($i=0; $i<24; $i++):?>
echo "<option value=\"$i\">"; <option value="<?=$i;?>"><?=$i;?> </option>
echo $i; <?php
echo "</option>"; endfor; ?>
} </select>
?> <select name="starttimemin" class="selectpicker form-control" data-width="auto" data-size="5" data-live-search="true" id="starttimemin">
</select>&nbsp;<?=gettext("Hr"); ?>&nbsp;&nbsp;
<select name="starttimemin" class="form-control" id="starttimemin">
<option value="00">00</option> <option value="00">00</option>
<option value="15">15</option> <option value="15">15</option>
<option value="30">30</option> <option value="30">30</option>
<option value="45">45</option> <option value="45">45</option>
<option value="59">59</option> <option value="59">59</option>
</select>&nbsp;<?=gettext("Min"); ?> </select>
</div>
</td> </td>
<td></td>
<td> <td>
<select name="stoptimehour" class="form-control" id="stoptimehour"> <div class="input-group">
<?php <select name="stoptimehour" class="selectpicker form-control" data-width="auto" data-size="5" data-live-search="true" id="stoptimehour">
for ($i=0; $i<24; $i++) <?php
{ for ($i=0; $i<24; $i++):?>
if ($i==23) <option value="<?=$i;?>"><?=$i;?> </option>
$selected = "selected=\"selected\""; <?php
else endfor; ?>
$selected = ""; </select>
<select name="stoptimemin" class="selectpicker form-control" data-width="auto" data-size="5" data-live-search="true" id="stoptimemin">
echo "<option value=\"$i\" $selected>";
echo $i;
echo "</option>";
}
?>
</select>&nbsp;<?=gettext("Hr");?>&nbsp;&nbsp;
<select name="stoptimemin" class="form-control" id="stoptimemin">
<option value="00">00</option> <option value="00">00</option>
<option value="15">15</option> <option value="15">15</option>
<option value="30">30</option> <option value="30">30</option>
<option value="45">45</option> <option value="45">45</option>
<option value="59" selected="selected">59</option> <option value="59" selected="selected">59</option>
</select>&nbsp;<?=gettext("Min");?> </select>
</div>
</td> </td>
</tr> </tr>
</table><br /> </table>
<div class="hidden" for="help_for_time">
<br />
<?=gettext("Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.")?> <?=gettext("Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.")?>
</div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="15%" valign="top" class="vncell"><?=gettext("Time Range Description")?></td> <td><a id="help_for_timerange_desc" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Time Range Description")?></td>
<td width="85%" class="vtable"><input name="timerangedescr" type="text" class="form-control unknown" id="timerangedescr" size="40" maxlength="40" /><br /> <td>
<span class="vexpl"> <input name="timerangedescr" type="text" id="timerangedescr"/>
<div class="hidden" for="help_for_timerange_desc">
<?=gettext("You may enter a description here for your reference (not parsed).")?> <?=gettext("You may enter a description here for your reference (not parsed).")?>
</span> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top">&nbsp;</td> <td>&nbsp;</td>
<td width="78%"> <td>
<input type="button" value="<?=gettext("Add Time");?>" class="btn btn-default" onclick="javascript:processEntries();" />&nbsp;&nbsp;&nbsp; <input type="button" value="<?=gettext("Add Time");?>" class="btn btn-default" onclick="javascript:processEntries();" />&nbsp;&nbsp;&nbsp;
<input type="button" value="<?=gettext("Clear Selection");?>" class="btn btn-default" onclick="javascript:clearCalendar(); clearTime(); clearDescr();" /> <input type="button" value="<?=gettext("Clear Selection");?>" class="btn btn-default" onclick="javascript:clearCalendar(); clearTime(); clearDescr();" />
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="15%" valign="top" class="vtable"></td> <td></td>
<td width="85%" class="vtable"></td> <td></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
...@@ -1037,20 +1001,19 @@ EOD; ...@@ -1037,20 +1001,19 @@ EOD;
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td width="15%" valign="top" class="vncellreq"><?=gettext("Configured Ranges");?></td> <td><?=gettext("Configured Ranges");?></td>
<td width="85%"> <td>
<table id="scheduletable" summary="range"> <table id="scheduletable" summary="range">
<tbody> <tbody>
<tr> <tr>
<td align="center" class="listbg" width="35%"><?=gettext("Day(s)");?></td> <td align="center" width="35%"><?=gettext("Day(s)");?></td>
<td align="center" class="listbg" width="12%"><?=gettext("Start Time");?></td> <td align="center" width="12%"><?=gettext("Start Time");?></td>
<td align="center" class="listbg" width="11%"><?=gettext("Stop Time");?></td> <td align="center" width="11%"><?=gettext("Stop Time");?></td>
<td align="center" class="listbg" width="42%"><?=gettext("Description");?></td> <td align="center" width="42%"><?=gettext("Description");?></td>
</tr> </tr>
<?php <?php
if ($getSchedule){ if (isset($pconfig['timerange'])){
$counter = 0; $counter = 0;
foreach($pconfig['timerange'] as $timerange) { foreach($pconfig['timerange'] as $timerange) {
$tempFriendlyTime = ""; $tempFriendlyTime = "";
$tempID = ""; $tempID = "";
...@@ -1058,7 +1021,6 @@ EOD; ...@@ -1058,7 +1021,6 @@ EOD;
$dayFriendly = ""; $dayFriendly = "";
$tempFriendlyTime = ""; $tempFriendlyTime = "";
$timedescr = $timerange['rangedescr']; $timedescr = $timerange['rangedescr'];
//get hours //get hours
$temptimerange = $timerange['hour']; $temptimerange = $timerange['hour'];
$temptimeseparator = strrpos($temptimerange, "-"); $temptimeseparator = strrpos($temptimerange, "-");
...@@ -1073,7 +1035,7 @@ EOD; ...@@ -1073,7 +1035,7 @@ EOD;
$firstPrint = false; $firstPrint = false;
$firstprint2 = false; $firstprint2 = false;
if ($timerange['month']){ if (!empty($timerange['month'])){
$tempmontharray = explode(",", $timerange['month']); $tempmontharray = explode(",", $timerange['month']);
$tempdayarray = explode(",",$timerange['day']); $tempdayarray = explode(",",$timerange['day']);
$arraycounter = 0; $arraycounter = 0;
...@@ -1087,16 +1049,12 @@ EOD; ...@@ -1087,16 +1049,12 @@ EOD;
} }
$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y"))); $weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
$weeknumber = ltrim($weeknumber, "0"); $weeknumber = ltrim($weeknumber, "0");
if ($firstPrint) {
if ($firstPrint)
{
$tempID .= ","; $tempID .= ",";
} }
$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" . $month . "d" . $day; $tempID .= "w" . $weeknumber . "p" . $daypos . "-m" . $month . "d" . $day;
$firstPrint = true; $firstPrint = true;
if (!$firstDayFound) {
if (!$firstDayFound)
{
$firstDay = $day; $firstDay = $day;
$firstmonth = $month; $firstmonth = $month;
$firstDayFound = true; $firstDayFound = true;
...@@ -1106,26 +1064,24 @@ EOD; ...@@ -1106,26 +1064,24 @@ EOD;
$nextDay = $tempdayarray[$arraycounter+1]; $nextDay = $tempdayarray[$arraycounter+1];
$currentDay++; $currentDay++;
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){ if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
if ($firstprint2) if ($firstprint2) {
$tempFriendlyTime .= ", "; $tempFriendlyTime .= ", ";
}
$currentDay--; $currentDay--;
if ($currentDay != $firstDay) if ($currentDay != $firstDay) {
$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ; $tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
else } else {
$tempFriendlyTime .= $monthArray[$month-1] . " " . $day; $tempFriendlyTime .= $monthArray[$month-1] . " " . $day;
}
$firstDayFound = false; $firstDayFound = false;
$firstprint2 = true; $firstprint2 = true;
} }
$arraycounter++; $arraycounter++;
} }
} else {
}
else
{
$dayFriendly = $timerange['position']; $dayFriendly = $timerange['position'];
$tempID = $dayFriendly; $tempID = $dayFriendly;
} }
$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr; $tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed //following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
...@@ -1137,11 +1093,10 @@ EOD; ...@@ -1137,11 +1093,10 @@ EOD;
$firstDay = ""; $firstDay = "";
$nextDay = ""; $nextDay = "";
$i = 0; $i = 0;
if (!$timerange['month']){ if (empty($timerange['month'])) {
foreach ($tempFriendlyDayArray as $day){ foreach ($tempFriendlyDayArray as $day){
if ($day != ""){ if ($day != ""){
if (!$firstDayFound) if (!$firstDayFound) {
{
$firstDay = $tempFriendlyDayArray[$i]; $firstDay = $tempFriendlyDayArray[$i];
$firstDayFound = true; $firstDayFound = true;
} }
...@@ -1150,13 +1105,15 @@ EOD; ...@@ -1150,13 +1105,15 @@ EOD;
$nextDay = $tempFriendlyDayArray[$i+1]; $nextDay = $tempFriendlyDayArray[$i+1];
$currentDay++; $currentDay++;
if ($currentDay != $nextDay){ if ($currentDay != $nextDay){
if ($firstprint) if ($firstprint){
$tempFriendlyTime .= ", "; $tempFriendlyTime .= ", ";
}
$currentDay--; $currentDay--;
if ($currentDay != $firstDay) if ($currentDay != $firstDay) {
$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1]; $tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
else } else {
$tempFriendlyTime .= $dayArray[$firstDay-1]; $tempFriendlyTime .= $dayArray[$firstDay-1];
}
$firstDayFound = false; $firstDayFound = false;
$firstprint = true; $firstprint = true;
} }
...@@ -1164,31 +1121,28 @@ EOD; ...@@ -1164,31 +1121,28 @@ EOD;
} }
} }
} }
?>
?>
<tr> <tr>
<td> <td>
<span class="vexpl"><?php echo $tempFriendlyTime; ?></span> <span><?=$tempFriendlyTime; ?></span>
</td> </td>
<td> <td>
<input type='text' readonly='readonly' class='vexpl' name='starttime<?php echo $counter; ?>' id='starttime<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $starttime; ?>' /> <input type='text' readonly='readonly' name='starttime<?=$counter; ?>' id='starttime<?=$counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?=$starttime; ?>' />
</td> </td>
<td> <td>
<input type='text' readonly='readonly' class='vexpl' name='stoptime<?php echo $counter; ?>' id='stoptime<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $stoptime; ?>' /> <input type='text' readonly='readonly' name='stoptime<?=$counter; ?>' id='stoptime<?=$counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?=$stoptime; ?>' />
</td> </td>
<td> <td>
<input type='text' readonly='readonly' class='vexpl' name='timedescr<?php echo $counter; ?>' id='timedescr<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $timedescr; ?>' /> <input type='text' readonly='readonly' name='timedescr<?=$counter; ?>' id='timedescr<?=$counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?=$timedescr; ?>' />
</td> </td>
<td> <td>
<a onclick='editRow("<?php echo $tempTime; ?>",this); return false;' href='#' class="btn btn-default"><span class="glyphicon glyphicon-edit"></span></a> <a onclick='editRow("<?=$tempTime; ?>",this); return false;' href='#' class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
</td> </td>
<td> <td>
<a onclick='removeRow(this); return false;' href='#' class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></a> <a onclick='removeRow(this); return false;' href='#' class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></a>
</td> </td>
<td> <td>
<input type='hidden' id='schedule<?php echo $counter; ?>' name='schedule<?php echo $counter; ?>' value='<?php echo $tempID; ?>' /> <input type='hidden' id='schedule<?=$counter; ?>' name='schedule<?=$counter; ?>' value='<?=$tempID; ?>' />
</td> </td>
</tr> </tr>
<?php <?php
...@@ -1202,12 +1156,12 @@ EOD; ...@@ -1202,12 +1156,12 @@ EOD;
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="15%" valign="top">&nbsp;</td> <td>&nbsp;</td>
<td width="85%"> <td>
<input id="submit" name="submit" type="submit" onclick="return checkForRanges();" class="btn btn-primary" value="<?=gettext("Save"); ?>" /> <input id="submit" name="submit" type="submit" onclick="return checkForRanges();" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" /> <input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_schedule.php');?>'" />
<?php if (isset($id) && $a_schedules[$id]): ?> <?php if (isset($id)): ?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" /> <input name="id" type="hidden" value="<?=$id;?>" />
<?php endif; ?> <?php endif; ?>
</td> </td>
</tr> </tr>
...@@ -1216,7 +1170,6 @@ EOD; ...@@ -1216,7 +1170,6 @@ EOD;
</div> </div>
</form> </form>
</div> </div>
</div>
</section> </section>
</div> </div>
</div> </div>
......
...@@ -33,54 +33,18 @@ require_once("guiconfig.inc"); ...@@ -33,54 +33,18 @@ require_once("guiconfig.inc");
require_once("interfaces.inc"); require_once("interfaces.inc");
require_once("filter.inc"); require_once("filter.inc");
if (!isset($config['virtualip']['vip'])) { /**
$config['virtualip']['vip'] = array(); * delete virtual ip
} */
function deleteVIPEntry($id) {
$a_vip = &$config['virtualip']['vip']; global $config;
$input_errors = array();
if ($_POST) { $a_vip = &$config['virtualip']['vip'];
$pconfig = $_POST;
if ($_POST['apply']) {
if (file_exists('/tmp/.firewall_virtual_ip.apply')) {
$toapplylist = unserialize(file_get_contents('/tmp/.firewall_virtual_ip.apply'));
foreach ($toapplylist as $vid => $ovip) {
if (!empty($ovip))
interface_vip_bring_down($ovip);
if ($a_vip[$vid]) {
switch ($a_vip[$vid]['mode']) {
case "ipalias":
interface_ipalias_configure($a_vip[$vid]);
break;
case "proxyarp":
interface_proxyarp_configure($a_vip[$vid]['interface']);
break;
case "carp":
interface_carp_configure($a_vip[$vid]);
break;
default:
break;
}
}
}
@unlink('/tmp/.firewall_virtual_ip.apply');
}
$retval = 0;
$retval |= filter_configure();
$savemsg = get_std_save_message();
clear_subsystem_dirty('vip');
}
}
if ($_GET['act'] == "del") {
if ($a_vip[$_GET['id']]) {
/* make sure no inbound NAT mappings reference this entry */ /* make sure no inbound NAT mappings reference this entry */
if (is_array($config['nat']['rule'])) { if (isset($config['nat']['rule'])) {
foreach ($config['nat']['rule'] as $rule) { foreach ($config['nat']['rule'] as $rule) {
if($rule['destination']['address'] <> "") { if(!empty($rule['destination']['address'])) {
if ($rule['destination']['address'] == $a_vip[$_GET['id']]['subnet']) { if ($rule['destination']['address'] == $a_vip[$id]['subnet']) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one NAT mapping."); $input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one NAT mapping.");
break; break;
} }
...@@ -88,24 +52,24 @@ if ($_GET['act'] == "del") { ...@@ -88,24 +52,24 @@ if ($_GET['act'] == "del") {
} }
} }
if (is_ipaddrv6($a_vip[$_GET['id']]['subnet'])) { if (is_ipaddrv6($a_vip[$id]['subnet'])) {
$is_ipv6 = true; $is_ipv6 = true;
$subnet = gen_subnetv6($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']); $subnet = gen_subnetv6($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']);
$if_subnet_bits = get_interface_subnetv6($a_vip[$_GET['id']]['interface']); $if_subnet_bits = get_interface_subnetv6($a_vip[$id]['interface']);
$if_subnet = gen_subnetv6(get_interface_ipv6($a_vip[$_GET['id']]['interface']), $if_subnet_bits); $if_subnet = gen_subnetv6(get_interface_ipv6($a_vip[$id]['interface']), $if_subnet_bits);
} else { } else {
$is_ipv6 = false; $is_ipv6 = false;
$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']); $subnet = gen_subnet($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']);
$if_subnet_bits = get_interface_subnet($a_vip[$_GET['id']]['interface']); $if_subnet_bits = get_interface_subnet($a_vip[$id]['interface']);
$if_subnet = gen_subnet(get_interface_ip($a_vip[$_GET['id']]['interface']), $if_subnet_bits); $if_subnet = gen_subnet(get_interface_ip($a_vip[$id]['interface']), $if_subnet_bits);
} }
$subnet .= "/" . $a_vip[$_GET['id']]['subnet_bits']; $subnet .= "/" . $a_vip[$id]['subnet_bits'];
$if_subnet .= "/" . $if_subnet_bits; $if_subnet .= "/" . $if_subnet_bits;
if (isset($config['gateways']['gateway_item'])) { if (isset($config['gateways']['gateway_item'])) {
foreach($config['gateways']['gateway_item'] as $gateway) { foreach($config['gateways']['gateway_item'] as $gateway) {
if ($a_vip[$_GET['id']]['interface'] != $gateway['interface']) if ($a_vip[$id]['interface'] != $gateway['interface'])
continue; continue;
if ($is_ipv6 && $gateway['ipprotocol'] == 'inet') if ($is_ipv6 && $gateway['ipprotocol'] == 'inet')
continue; continue;
...@@ -121,8 +85,8 @@ if ($_GET['act'] == "del") { ...@@ -121,8 +85,8 @@ if ($_GET['act'] == "del") {
} }
} }
if ($a_vip[$_GET['id']]['mode'] == "ipalias") { if ($a_vip[$id]['mode'] == "ipalias") {
$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']) . "/" . $a_vip[$_GET['id']]['subnet_bits']; $subnet = gen_subnet($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']) . "/" . $a_vip[$id]['subnet_bits'];
$found_if = false; $found_if = false;
$found_carp = false; $found_carp = false;
$found_other_alias = false; $found_other_alias = false;
...@@ -130,23 +94,43 @@ if ($_GET['act'] == "del") { ...@@ -130,23 +94,43 @@ if ($_GET['act'] == "del") {
if ($subnet == $if_subnet) if ($subnet == $if_subnet)
$found_if = true; $found_if = true;
$vipiface = $a_vip[$_GET['id']]['interface']; $vipiface = $a_vip[$id]['interface'];
foreach ($a_vip as $vip_id => $vip) { foreach ($a_vip as $vip_id => $vip) {
if ($vip_id == $_GET['id']) if ($vip_id != $id) {
continue; if ($vip['interface'] == $vipiface && ip_in_subnet($vip['subnet'], $subnet)) {
if ($vip['mode'] == "carp") {
if ($vip['interface'] == $vipiface && ip_in_subnet($vip['subnet'], $subnet))
if ($vip['mode'] == "carp")
$found_carp = true; $found_carp = true;
else if ($vip['mode'] == "ipalias") } else if ($vip['mode'] == "ipalias") {
$found_other_alias = true; $found_other_alias = true;
} }
}
if ($found_carp === true && $found_other_alias === false && $found_if === false) }
}
if ($found_carp === true && $found_other_alias === false && $found_if === false) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by a CARP IP with the description") . " {$vip['descr']}."; $input_errors[] = gettext("This entry cannot be deleted because it is still referenced by a CARP IP with the description") . " {$vip['descr']}.";
} }
}
if (count($input_errors) == 0) {
// Special case since every proxyarp vip is handled by the same daemon.
if ($a_vip[$id]['mode'] == "proxyarp") {
$viface = $a_vip[$id]['interface'];
unset($a_vip[$id]);
interface_proxyarp_configure($viface);
} else {
interface_vip_bring_down($a_vip[$id]);
unset($a_vip[$id]);
}
if (count($config['virtualip']['vip']) == 0) {
unset($config['virtualip']['vip']);
}
}
return $input_errors;
}
if (!$input_errors) { /**
* redirect user if config may not be saved.
*/
function redirectReadOnlyUser() {
if (session_status() == PHP_SESSION_NONE) { if (session_status() == PHP_SESSION_NONE) {
session_start(); session_start();
} }
...@@ -156,41 +140,118 @@ if ($_GET['act'] == "del") { ...@@ -156,41 +140,118 @@ if ($_GET['act'] == "del") {
exit; exit;
} }
session_write_close(); session_write_close();
}
// Special case since every proxyarp vip is handled by the same daemon.
if ($a_vip[$_GET['id']]['mode'] == "proxyarp") { if (!isset($config['virtualip']['vip'])) {
$viface = $a_vip[$_GET['id']]['interface']; $config['virtualip']['vip'] = array();
unset($a_vip[$_GET['id']]); }
interface_proxyarp_configure($viface); $a_vip = &$config['virtualip']['vip'];
} else {
interface_vip_bring_down($a_vip[$_GET['id']]); if ($_SERVER['REQUEST_METHOD'] === 'POST') {
unset($a_vip[$_GET['id']]); $pconfig = $_POST;
if (isset($pconfig['id']) && isset($a_vip[$pconfig['id']])) {
// id found and valid
$id = $pconfig['id'];
} }
if (count($config['virtualip']['vip']) == 0) if (isset($pconfig['apply'])) {
unset($config['virtualip']['vip']); if (file_exists('/tmp/.firewall_virtual_ip.apply')) {
$toapplylist = unserialize(file_get_contents('/tmp/.firewall_virtual_ip.apply'));
foreach ($toapplylist as $vid => $ovip) {
if (!empty($ovip)) {
interface_vip_bring_down($ovip);
}
if (!empty($a_vip[$vid])) {
switch ($a_vip[$vid]['mode']) {
case "ipalias":
interface_ipalias_configure($a_vip[$vid]);
break;
case "proxyarp":
interface_proxyarp_configure($a_vip[$vid]['interface']);
break;
case "carp":
interface_carp_configure($a_vip[$vid]);
break;
default:
break;
}
}
}
@unlink('/tmp/.firewall_virtual_ip.apply');
}
filter_configure();
$savemsg = get_std_save_message();
clear_subsystem_dirty('vip');
} elseif (isset($pconfig['act']) && $pconfig['act'] == 'del' && isset($id)) {
redirectReadOnlyUser();
$input_errors = deleteVIPEntry($id);
if (count($input_errors) == 0) {
write_config(); write_config();
header("Location: firewall_virtual_ip.php"); header("Location: firewall_virtual_ip.php");
exit; exit;
} }
} elseif (isset($pconfig['act']) && $pconfig['act'] == 'move' && isset($pconfig['rule']) && count($pconfig['rule']) > 0) {
redirectReadOnlyUser();
// move selected rules
if (!isset($id)) {
// if rule not set/found, move to end
$id = count($a_nat);
}
$a_vip = legacy_move_config_list_items($a_vip, $id, $pconfig['rule']);
write_config();
header("Location: firewall_virtual_ip.php");
exit;
} }
} else if ($_GET['changes'] == "mods" && is_numericint($_GET['id'])) }
$id = $_GET['id'];
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses")); $pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses"));
include("head.inc"); include("head.inc");
$main_buttons = array( $main_buttons = array(
array('href'=>'firewall_virtual_ip_edit.php', 'label'=>'Add'), array('href'=>'firewall_virtual_ip_edit.php', 'label'=>gettext('Add')),
array('href'=>'system_hasync.php', 'label'=>gettext('CARP Settings'))
); );
?> ?>
<body> <body>
<?php include("fbegin.inc"); ?> <script type="text/javascript">
$( document ).ready(function() {
// link delete buttons
$(".act_delete").click(function(){
var id = $(this).attr("id").split('_').pop(-1);
// delete single
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Alias");?>",
message: "<?=gettext("Do you really want to delete this entry?");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#id").val(id);
$("#action").val("del");
$("#iform").submit()
}
}]
});
});
// link move buttons
$(".act_move").click(function(){
var id = $(this).attr("id").split('_').pop(-1);
$("#id").val(id);
$("#action").val("move");
$("#iform").submit();
});
});
</script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<?php <?php
if (isset($input_errors) && count($input_errors) > 0) if (isset($input_errors) && count($input_errors) > 0)
print_input_errors($input_errors); print_input_errors($input_errors);
...@@ -201,77 +262,83 @@ $main_buttons = array( ...@@ -201,77 +262,83 @@ $main_buttons = array(
if (is_subsystem_dirty('vip')) if (is_subsystem_dirty('vip'))
print_info_box_np(gettext("The VIP configuration has been changed.")."<br />".gettext("You must apply the changes in order for them to take effect.")); print_info_box_np(gettext("The VIP configuration has been changed.")."<br />".gettext("You must apply the changes in order for them to take effect."));
?> ?>
<section class="col-xs-12"> <section class="col-xs-12">
<div class="content-box-main content-box">
<?php
/* active tabs */
$tab_array = array();
$tab_array[] = array(gettext("Virtual IPs"), true, "firewall_virtual_ip.php");
$tab_array[] = array(gettext("CARP Settings"), false, "system_hasync.php");
display_top_tabs($tab_array);
?>
<div class="tab-content content-box col-xs-12">
<form action="firewall_virtual_ip.php" method="post" name="iform" id="iform"> <form action="firewall_virtual_ip.php" method="post" name="iform" id="iform">
<input type="hidden" id="id" name="id" value="<?php echo htmlspecialchars($id); ?>" /> <input type="hidden" id="id" name="id" value="" />
<input type="hidden" id="action" name="act" value="" />
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-sort"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<td width="30%" class="listhdrr"><?=gettext("Virtual IP address");?></td> <td></td>
<td width="10%" class="listhdrr"><?=gettext("Interface");?></td> <td><?=gettext("Virtual IP address");?></td>
<td width="10%" class="listhdrr"><?=gettext("Type");?></td> <td><?=gettext("Interface");?></td>
<td width="40%" class="listhdr"><?=gettext("Description");?></td> <td><?=gettext("Type");?></td>
<td width="10%" class="list"></td> <td><?=gettext("Description");?></td>
<td></td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php <?php
$interfaces = get_configured_interface_with_descr(false, true); $interfaces = get_configured_interface_with_descr(false, true);
$interfaces['lo0'] = "Localhost"; $interfaces['lo0'] = "Localhost";
?> $i = 0;
<?php $i = 0; foreach ($a_vip as $vipent): ?> foreach ($a_vip as $vipent):
<?php if($vipent['subnet'] <> "" or $vipent['range'] <> "" or if(!empty($vipent['subnet']) || !empty($vipent['range']) || !empty($vipent['subnet_bits']) || (isset($vipent['range']['from']) && !empty($vipent['range']['from']))): ?>
$vipent['subnet_bits'] <> "" or (isset($vipent['range']['from']) && $vipent['range']['from'] <> "")): ?> <tr ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
<tr> <td>
<td class="listlr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';"> <input type="checkbox" name="rule[]" value="<?=$i;?>" />
<?php if (($vipent['type'] == "single") || ($vipent['type'] == "network"))
if($vipent['subnet_bits'])
echo "{$vipent['subnet']}/{$vipent['subnet_bits']}";
if ($vipent['type'] == "range")
echo "{$vipent['range']['from']}-{$vipent['range']['to']}";
?>
<?php if($vipent['mode'] == "carp") echo " (vhid {$vipent['vhid']})"; ?>
</td> </td>
<td class="listr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';"> <td>
<?=htmlspecialchars($interfaces[$vipent['interface']]);?>&nbsp; <?=($vipent['type'] == "single" || $vipent['type'] == "network") && !empty($vipent['subnet_bits']) ? $vipent['subnet']."/".$vipent['subnet_bits'] : "";?>
<?=$vipent['type'] == "range" ? $vipent['range']['from'] . "-" . $vipent['range']['to'] : "";?>
<?=$vipent['mode'] == "carp" ? " (vhid {$vipent['vhid']})" : "";?>
</td> </td>
<td class="listr" align="center" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';"> <td>
<?php if($vipent['mode'] == "proxyarp") echo "Proxy ARP"; elseif($vipent['mode'] == "carp") echo "CARP"; elseif($vipent['mode'] == "other") echo "Other"; elseif($vipent['mode'] == "ipalias") echo "IP Alias";?> <?=htmlspecialchars($interfaces[$vipent['interface']]);?>
</td> </td>
<td class="listbg" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';"> <td>
<?=htmlspecialchars($vipent['descr']);?>&nbsp; <?=$vipent['mode'] == "proxyarp" ? "Proxy ARP" : "";?>
<?=$vipent['mode'] == "carp" ? "CARP" : "";?>
<?=$vipent['mode'] == "other" ? "Other" : "";?>
<?=$vipent['mode'] == "ipalias" ? "IP Alias" :"";?>
</td> </td>
<td class="list nowrap"> <td>
<table border="0" cellspacing="0" cellpadding="1" summary="icons"> <?=htmlspecialchars($vipent['descr']);?>
<tr> </td>
<td valign="middle"> <td>
<a href="firewall_virtual_ip_edit.php?id=<?=$i;?>" class="btn btn-default"><span class="glyphicon glyphicon-edit" title="<?=gettext("Edit");?>"></span></a> <a id="move_<?=$i;?>" name="move_<?=$i;?>_x" data-toggle="tooltip" data-placement="left" title="<?=gettext("move selected alias before this rule");?>" class="act_move btn btn-default btn-xs">
<span class="glyphicon glyphicon-arrow-left"></span>
<a href="firewall_virtual_ip.php?act=del&amp;tab=<?=$tab;?>&amp;id=<?=$i;?>" class="btn btn-default" onclick="return confirm('<?=gettext("Do you really want to delete this entry?");?>')"><span class="glyphicon glyphicon-remove"></span></a> </a>
<a href="firewall_virtual_ip_edit.php?id=<?=$i;?>" data-toggle="tooltip" data-placement="left" title="<?=gettext("edit this alias");?>" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<a id="del_<?=$i;?>" title="<?=gettext("delete this alias"); ?>" data-toggle="tooltip" class="act_delete btn btn-default btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</a>
<a href="firewall_virtual_ip_edit.php?dup=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="left" title="<?=gettext("add new rule based on this one");?>">
<span class="glyphicon glyphicon-plus"></span>
</a>
</td> </td>
</tr> </tr>
</table> <?php
endif;
$i++;
endforeach;
?>
<?php ?>
<tr>
<td colspan="5"></td>
<td>
<a type="submit" id="move_<?=$i;?>" name="move_<?=$i;?>_x" data-toggle="tooltip" data-placement="left" title="<?=gettext("move selected rules to end");?>" class="act_move btn btn-default btn-xs">
<span class="glyphicon glyphicon-arrow-left"></span>
</a>
<a href="firewall_virtual_ip_edit.php" class="btn btn-default btn-xs" data-toggle="tooltip" data-placement="left" title="<?=gettext("add new rule");?>">
<span class="glyphicon glyphicon-plus"></span>
</a>
</td> </td>
</tr> </tr>
<?php endif; ?>
<?php $i++; endforeach; ?>
</tbody> </tbody>
</table> </table>
</div> </div>
......
...@@ -33,195 +33,200 @@ require_once("guiconfig.inc"); ...@@ -33,195 +33,200 @@ require_once("guiconfig.inc");
require_once("interfaces.inc"); require_once("interfaces.inc");
require_once("pfsense-utils.inc"); require_once("pfsense-utils.inc");
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_virtual_ip.php'); /**
* find max vhid
if (!is_array($config['virtualip']['vip'])) { */
$config['virtualip']['vip'] = array();
}
$a_vip = &$config['virtualip']['vip'];
if (is_numericint($_GET['id']))
$id = $_GET['id'];
if (isset($_POST['id']) && is_numericint($_POST['id']))
$id = $_POST['id'];
function return_first_two_octets($ip) {
$ip_split = explode(".", $ip);
return $ip_split[0] . "." . $ip_split[1];
}
function find_last_used_vhid() { function find_last_used_vhid() {
global $config, $g; global $config;
$vhid = 0; $vhid = 0;
if (isset($config['virtualip']['vip'])) {
foreach($config['virtualip']['vip'] as $vip) { foreach($config['virtualip']['vip'] as $vip) {
if($vip['vhid'] > $vhid) if(!empty($vip['vhid']) && $vip['vhid'] > $vhid) {
$vhid = $vip['vhid']; $vhid = $vip['vhid'];
} }
}
}
return $vhid; return $vhid;
} }
if (isset($id) && $a_vip[$id]) {
$pconfig['mode'] = $a_vip[$id]['mode']; // create new vip array if none existent
$pconfig['vhid'] = $a_vip[$id]['vhid']; if (!isset($config['virtualip']) || !is_array($config['virtualip'])) {
$pconfig['advskew'] = $a_vip[$id]['advskew']; $config['virtualip'] = array();
$pconfig['advbase'] = $a_vip[$id]['advbase']; }
$pconfig['password'] = $a_vip[$id]['password']; if (!isset($config['virtualip']['vip']) || !is_array($config['virtualip']['vip'])) {
$pconfig['range'] = $a_vip[$id]['range']; $config['virtualip']['vip'] = array();
$pconfig['subnet'] = $a_vip[$id]['subnet'];
$pconfig['subnet_bits'] = $a_vip[$id]['subnet_bits'];
$pconfig['noexpand'] = $a_vip[$id]['noexpand'];
$pconfig['descr'] = $a_vip[$id]['descr'];
$pconfig['type'] = $a_vip[$id]['type'];
$pconfig['interface'] = $a_vip[$id]['interface'];
} else {
$lastvhid = find_last_used_vhid();
$lastvhid++;
$pconfig['vhid'] = $lastvhid;
} }
$a_vip = &$config['virtualip']['vip'];
if ($_POST) {
unset($input_errors); if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// input record id, if valid
if (isset($_GET['dup']) && isset($a_vip[$_GET['dup']])) {
$configId = $_GET['dup'];
$after = $configId;
} elseif (isset($_GET['id']) && isset($a_vip[$_GET['id']])) {
$id = $_GET['id'];
$configId = $id;
}
$pconfig = array();
$pconfig['vhid'] = find_last_used_vhid() + 1;
$form_fields = array('mode', 'vhid', 'advskew', 'advbase', 'password', 'subnet', 'subnet_bits'
, 'descr' ,'type', 'interface' );
if (isset($configId)) {
// 1-on-1 copy of config data
foreach ($form_fields as $fieldname) {
if (isset($a_vip[$configId][$fieldname])) {
$pconfig[$fieldname] = $a_vip[$configId][$fieldname] ;
}
}
}
// initialize empty form fields
foreach ($form_fields as $fieldname) {
if (!isset($pconfig[$fieldname])) {
$pconfig[$fieldname] = null ;
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input_errors = array();
$pconfig = $_POST; $pconfig = $_POST;
/* input validation */ // input record id, if valid
$reqdfields = explode(" ", "mode"); if (isset($pconfig['id']) && isset($a_vip[$pconfig['id']])) {
$reqdfieldsn = array(gettext("Type")); $id = $pconfig['id'];
}
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); // perform form validations
$reqdfields = array("mode");
$reqdfieldsn = array(gettext("Type"));
do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
if (isset($_POST['subnet'])) { if (isset($pconfig['subnet'])) {
$_POST['subnet'] = trim($_POST['subnet']); $pconfig['subnet'] = trim($pconfig['subnet']);
if (!is_ipaddr($_POST['subnet'])) if (!is_ipaddr($pconfig['subnet'])) {
$input_errors[] = gettext("A valid IP address must be specified."); $input_errors[] = gettext("A valid IP address must be specified.");
else {
if ($_POST['mode'] == 'carp') {
$ignore_if = $_POST['interface']."_vip{$_POST['vhid']}";
} else { } else {
$ignore_if = $_POST['interface']; if ($pconfig['mode'] == 'carp') {
$ignore_if = $pconfig['interface']."_vip{$pconfig['vhid']}";
} else {
$ignore_if = $pconfig['interface'];
} }
if (is_ipaddr_configured($pconfig['subnet'], $ignore_if)) {
if (is_ipaddr_configured($_POST['subnet'], $ignore_if)) {
$input_errors[] = gettext("This IP address is being used by another interface or VIP."); $input_errors[] = gettext("This IP address is being used by another interface or VIP.");
} }
unset($ignore_if);
} }
} }
$natiflist = get_configured_interface_with_descr(); $natiflist = get_configured_interface_with_descr();
foreach ($natiflist as $natif => $natdescr) { foreach ($natiflist as $natif => $natdescr) {
if ($_POST['interface'] == $natif && (empty($config['interfaces'][$natif]['ipaddr']) && empty($config['interfaces'][$natif]['ipaddrv6']))) if ($pconfig['interface'] == $natif && (empty($config['interfaces'][$natif]['ipaddr']) && empty($config['interfaces'][$natif]['ipaddrv6']))) {
$input_errors[] = gettext("The interface chosen for the VIP has no IPv4 or IPv6 address configured so it cannot be used as a parent for the VIP."); $input_errors[] = gettext("The interface chosen for the VIP has no IPv4 or IPv6 address configured so it cannot be used as a parent for the VIP.");
} }
}
/* ipalias and carp should not use network or broadcast address */ /* ipalias and carp should not use network or broadcast address */
if ($_POST['mode'] == "ipalias" || $_POST['mode'] == "carp") { if ($pconfig['mode'] == "ipalias" || $pconfig['mode'] == "carp") {
if (is_ipaddrv4($_POST['subnet']) && $_POST['subnet_bits'] != "32") { if (is_ipaddrv4($pconfig['subnet']) && $pconfig['subnet_bits'] != "32") {
$network_addr = gen_subnet($_POST['subnet'], $_POST['subnet_bits']); $network_addr = gen_subnet($pconfig['subnet'], $pconfig['subnet_bits']);
$broadcast_addr = gen_subnet_max($_POST['subnet'], $_POST['subnet_bits']); $broadcast_addr = gen_subnet_max($pconfig['subnet'], $pconfig['subnet_bits']);
} else if (is_ipaddrv6($_POST['subnet']) && $_POST['subnet_bits'] != "128" ) { } else if (is_ipaddrv6($pconfig['subnet']) && $_POST['subnet_bits'] != "128" ) {
$network_addr = gen_subnetv6($_POST['subnet'], $_POST['subnet_bits']); $network_addr = gen_subnetv6($pconfig['subnet'], $pconfig['subnet_bits']);
$broadcast_addr = gen_subnetv6_max($_POST['subnet'], $_POST['subnet_bits']); $broadcast_addr = gen_subnetv6_max($pconfig['subnet'], $pconfig['subnet_bits']);
} }
if (isset($network_addr) && $pconfig['subnet'] == $network_addr) {
if (isset($network_addr) && $_POST['subnet'] == $network_addr)
$input_errors[] = gettext("You cannot use the network address for this VIP"); $input_errors[] = gettext("You cannot use the network address for this VIP");
else if (isset($broadcast_addr) && $_POST['subnet'] == $broadcast_addr) } else if (isset($broadcast_addr) && $pconfig['subnet'] == $broadcast_addr) {
$input_errors[] = gettext("You cannot use the broadcast address for this VIP"); $input_errors[] = gettext("You cannot use the broadcast address for this VIP");
} }
}
/* make sure new ip is within the subnet of a valid ip /* make sure new ip is within the subnet of a valid ip
* on one of our interfaces (wan, lan optX) * on one of our interfaces (wan, lan optX)
*/ */
if ($_POST['mode'] == 'carp') { if ($pconfig['mode'] == 'carp') {
/* verify against reusage of vhids */ /* verify against reusage of vhids */
$idtracker = 0; foreach($config['virtualip']['vip'] as $vipId => $vip) {
foreach($config['virtualip']['vip'] as $vip) { if(isset($vip['vhid']) && $vip['vhid'] == $pconfig['vhid'] && $vip['interface'] == $pconfig['interface'] && $vipId <> $id) {
if($vip['vhid'] == $_POST['vhid'] && $vip['interface'] == $_POST['interface'] && $idtracker <> $id) $input_errors[] = sprintf(gettext("VHID %s is already in use on interface %s. Pick a unique number on this interface."),$pconfig['vhid'], convert_friendly_interface_to_friendly_descr($pconfig['interface']));
$input_errors[] = sprintf(gettext("VHID %s is already in use on interface %s. Pick a unique number on this interface."),$_POST['vhid'], convert_friendly_interface_to_friendly_descr($_POST['interface'])); }
$idtracker++;
} }
if (empty($_POST['password'])) if (empty($pconfig['password'])) {
$input_errors[] = gettext("You must specify a CARP password that is shared between the two VHID members."); $input_errors[] = gettext("You must specify a CARP password that is shared between the two VHID members.");
}
if (is_ipaddrv4($_POST['subnet'])) { if (is_ipaddrv4($pconfig['subnet'])) {
$parent_ip = get_interface_ip($_POST['interface']); $parent_ip = get_interface_ip($pconfig['interface']);
$parent_sn = get_interface_subnet($_POST['interface']); $parent_sn = get_interface_subnet($pconfig['interface']);
$subnet = gen_subnet($parent_ip, $parent_sn); $subnet = gen_subnet($parent_ip, $parent_sn);
} else if (is_ipaddrv6($_POST['subnet'])) { } else if (is_ipaddrv6($pconfig['subnet'])) {
$parent_ip = get_interface_ipv6($_POST['interface']); $parent_ip = get_interface_ipv6($pconfig['interface']);
$parent_sn = get_interface_subnetv6($_POST['interface']); $parent_sn = get_interface_subnetv6($pconfig['interface']);
$subnet = gen_subnetv6($parent_ip, $parent_sn); $subnet = gen_subnetv6($parent_ip, $parent_sn);
} }
if (isset($parent_ip) && !ip_in_subnet($_POST['subnet'], "{$subnet}/{$parent_sn}") && !ip_in_interface_alias_subnet($_POST['interface'], $_POST['subnet'])) { if (isset($parent_ip) && !ip_in_subnet($pconfig['subnet'], "{$subnet}/{$parent_sn}") && !ip_in_interface_alias_subnet($pconfig['interface'], $pconfig['subnet'])) {
$cannot_find = $_POST['subnet'] . "/" . $_POST['subnet_bits'] ; $cannot_find = $pconfig['subnet'] . "/" . $pconfig['subnet_bits'] ;
$input_errors[] = sprintf(gettext("Sorry, we could not locate an interface with a matching subnet for %s. Please add an IP alias in this subnet on this interface."),$cannot_find); $input_errors[] = sprintf(gettext("Sorry, we could not locate an interface with a matching subnet for %s. Please add an IP alias in this subnet on this interface."),$cannot_find);
} }
if ($_POST['interface'] == "lo0") if ($pconfig['interface'] == "lo0") {
$input_errors[] = gettext("For this type of vip localhost is not allowed.");
} else if ($_POST['mode'] != 'ipalias' && $_POST['interface'] == "lo0")
$input_errors[] = gettext("For this type of vip localhost is not allowed."); $input_errors[] = gettext("For this type of vip localhost is not allowed.");
if (!$input_errors) {
$vipent = array();
$vipent['mode'] = $_POST['mode'];
$vipent['interface'] = $_POST['interface'];
/* ProxyARP specific fields */
if ($_POST['mode'] === "proxyarp") {
if ($_POST['type'] == "range") {
$vipent['range']['from'] = $_POST['range_from'];
$vipent['range']['to'] = $_POST['range_to'];
} }
$vipent['noexpand'] = isset($_POST['noexpand']); } else if ($pconfig['mode'] != 'ipalias' && $pconfig['interface'] == "lo0") {
$input_errors[] = gettext("For this type of vip localhost is not allowed.");
} }
/* CARP specific fields */
if ($_POST['mode'] === "carp") {
$vipent['vhid'] = $_POST['vhid'];
$vipent['advskew'] = $_POST['advskew'];
$vipent['advbase'] = $_POST['advbase'];
$vipent['password'] = $_POST['password'];
}
/* Common fields */ if (count($input_errors) == 0) {
$vipent['descr'] = $_POST['descr']; $vipent = array();
if (isset($_POST['type'])) // defaults
$vipent['type'] = $_POST['type'];
else
$vipent['type'] = "single"; $vipent['type'] = "single";
if ($vipent['type'] == "single" || $vipent['type'] == "network") {
if (!isset($_POST['subnet_bits'])) {
$vipent['subnet_bits'] = "32"; $vipent['subnet_bits'] = "32";
} else { // 1-on-1 copy attributes
$vipent['subnet_bits'] = $_POST['subnet_bits']; foreach (array('mode', 'interface', 'descr', 'type', 'subnet_bits', 'subnet', 'vhid'
,'advskew','advbase','password') as $fieldname) {
if (!empty($pconfig[$fieldname])) {
$vipent[$fieldname] = $pconfig[$fieldname];
} }
$vipent['subnet'] = $_POST['subnet'];
} }
if (!isset($id)) if (!empty($pconfig['noexpand'])) {
$id = count($a_vip); // noexpand, only used for proxyarp
$vipent['noexpand'] = true;
}
// virtual ip UI keeps track of it's changes in a separate file
// (which is only use on apply in firewall_virtual_ip)
// add or change this administration here.
// Not the nicest thing to do, but we keep it for now.
if (file_exists('/tmp/.firewall_virtual_ip.apply')) { if (file_exists('/tmp/.firewall_virtual_ip.apply')) {
$toapplylist = unserialize(file_get_contents('/tmp/.firewall_virtual_ip.apply')); $toapplylist = unserialize(file_get_contents('/tmp/.firewall_virtual_ip.apply'));
} else { } else {
$toapplylist = array(); $toapplylist = array();
} }
if (isset($id)) {
if (isset($toapplylist[$id])) {
$toapplylist[$id] = $a_vip[$id]; $toapplylist[$id] = $a_vip[$id];
if (!empty($a_vip[$id])) { } else {
$toapplylist[] = $a_vip[$id];
}
}
if (isset($id)) {
/* modify all virtual IP rules with this address */ /* modify all virtual IP rules with this address */
for ($i = 0; isset($config['nat']['rule'][$i]); $i++) { for ($i = 0; isset($config['nat']['rule'][$i]); $i++) {
if ($config['nat']['rule'][$i]['destination']['address'] == $a_vip[$id]['subnet']) if (isset($config['nat']['rule'][$i]['destination']['address']) && $config['nat']['rule'][$i]['destination']['address'] == $a_vip[$id]['subnet']) {
$config['nat']['rule'][$i]['destination']['address'] = $vipent['subnet']; $config['nat']['rule'][$i]['destination']['address'] = $vipent['subnet'];
} }
} }
$a_vip[$id] = $vipent; }
// update or insert item in config
if (isset($id)) {
$a_vip[$id] = $vipent;
} else {
$a_vip[] = $vipent;
}
if (write_config()) { if (write_config()) {
mark_subsystem_dirty('vip'); mark_subsystem_dirty('vip');
file_put_contents('/tmp/.firewall_virtual_ip.apply', serialize($toapplylist)); file_put_contents('/tmp/.firewall_virtual_ip.apply', serialize($toapplylist));
...@@ -231,269 +236,257 @@ if ($_POST) { ...@@ -231,269 +236,257 @@ if ($_POST) {
} }
} }
legacy_html_escape_form_data($pconfig);
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Address"),gettext("Edit")); $pgtitle = array(gettext("Firewall"),gettext("Virtual IP Address"),gettext("Edit"));
include("head.inc"); include("head.inc");
?> ?>
<body> <body>
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script> <script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
<?php include("fbegin.inc"); ?> <?php include("fbegin.inc");?>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ $( document ).ready(function() {
function get_radio_value(obj) $("#mode").change(function(){
{ //$("#subnet").attr('disabled', true);
for (i = 0; i < obj.length; i++) { $("#type").attr('disabled', true);
if (obj[i].checked) $("#subnet_bits").attr('disabled', true);
return obj[i].value; $("#noexpand").attr('disabled', true);
} $("#password").attr('disabled', true);
return null; $("#vhid").attr('disabled', true);
} $("#advskew").attr('disabled', true);
function set_note(noteMessage){ $("#advbase").attr('disabled', true);
var note = document.getElementById("typenote"); $("#noexpand").attr('disabled', true);
if (note.firstChild != null) $("#noexpandrow").addClass("hidden");
note.removeChild(note.firstChild);
if (noteMessage) switch ($(this).val()) {
note.appendChild(noteMessage); case "ipalias":
} $("#type").prop("selectedIndex",0);
function enable_change() { $("#typenote").html("<?=gettext("Please provide a single IP address");?>");
var carpnote = document.createTextNode("<?=gettext("This must be the network's subnet mask. It does not specify a CIDR range.");?>");
var proxyarpnote = document.createTextNode("<?=gettext("This is a CIDR block of proxy ARP addresses.");?>");
var ipaliasnote = document.createTextNode("<?=gettext("This must be the network's subnet mask. It does not specify a CIDR range.");?>");
$mode = get_radio_value(document.iform.mode);
document.iform.password.disabled = $mode != "carp";
document.iform.vhid.disabled = $mode != "carp";
document.iform.advskew.disabled = $mode != "carp";
document.iform.advbase.disabled = $mode != "carp";
document.iform.type.disabled = $mode in {"carp":1,"ipalias":1};
if ($mode in {"carp":1,"ipalias":1})
document.iform.type.selectedIndex = 0;// single-adress
switch($mode)
{
case "carp" : set_note(carpnote); break;
case "ipalias" : set_note(ipaliasnote); break;
case "proxyarp": set_note(proxyarpnote); break;
default: set_note(undefined);
}
typesel_change();
}
function typesel_change() {
switch (document.iform.type.selectedIndex) {
case 0: // single
document.iform.subnet.disabled = 0;
document.iform.subnet_bits.disabled = (get_radio_value(document.iform.mode) == "proxyarp") || (get_radio_value(document.iform.mode) == "other");
document.iform.noexpand.disabled = 1;
jQuery('#noexpandrow').css('display','none');
break; break;
case 1: // network case "carp":
document.iform.subnet.disabled = 0; $("#type").prop("selectedIndex",0);
document.iform.subnet_bits.disabled = 0; $("#subnet_bits").attr('disabled', false);
document.iform.noexpand.disabled = 0; $("#password").attr('disabled', false);
jQuery('#noexpandrow').css('display',''); $("#vhid").attr('disabled', false);
//document.iform.range_from.disabled = 1; $("#advskew").attr('disabled', false);
//document.iform.range_to.disabled = 1; $("#advbase").attr('disabled', false);
$("#typenote").html("<?=gettext("This must be the network's subnet mask. It does not specify a CIDR range.");?>");
break; break;
case 2: // range case "proxyarp":
document.iform.subnet.disabled = 1; $("#type").attr('disabled', false);
document.iform.subnet_bits.disabled = 1; $("#subnet_bits").attr('disabled', false);
document.iform.noexpand.disabled = 1; $("#noexpand").attr('disabled', false);
jQuery('#noexpandrow').css('display','none'); $("#noexpandrow").removeClass("hidden");
//document.iform.range_from.disabled = 0; $("#typenote").html("<?=gettext("This is a CIDR block of proxy ARP addresses.");?>");
//document.iform.range_to.disabled = 0;
break; break;
case 3: // IP alias case "other":
document.iform.subnet.disabled = 1; $("#type").attr('disabled', false);
document.iform.subnet_bits.disabled = 0; $("#subnet_bits").attr('disabled', false);
document.iform.noexpand.disabled = 1; $("#typenote").html("<?=gettext("This must be the network's subnet mask. It does not specify a CIDR range.");?>");
jQuery('#noexpandrow').css('display','none');
//document.iform.range_from.disabled = 0;
//document.iform.range_to.disabled = 0;
break; break;
} }
} // refresh selectpickers
//]]> setTimeout(function(){
$('.selectpicker').selectpicker('refresh');
}, 100);
});
// IPv4 address, fix dstmask
$("#subnet").change(function(){
if ( $(this).val().indexOf('.') > -1 && $("#subnet_bits").val() > 32) {
$("#subnet_bits").val("32");
$('#subnet_bits').selectpicker('refresh');
}
});
// toggle initial mode change
$("#mode").change();
});
</script> </script>
</script>
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?> <?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<div id="inputerrors"></div>
<section class="col-xs-12"> <section class="col-xs-12">
<div class="content-box"> <div class="content-box">
<header class="content-box-head container-fluid">
<h3><?=gettext("Edit Virtual IP");?></h3>
</header>
<div class="content-box-main">
<form action="firewall_virtual_ip_edit.php" method="post" name="iform" id="iform"> <form action="firewall_virtual_ip_edit.php" method="post" name="iform" id="iform">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped table-sort"> <table class="table table-striped">
<thead></thead>
<tbody>
<tr>
<td width="22%"><strong><?=gettext("Edit Virtual IP");?></strong></td>
<td width="78%" align="right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i></a>
</td>
</tr>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Type");?></td> <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Type");?></td>
<td width="78%" class="vtable"> <td>
<input name="mode" type="radio" onclick="enable_change()" value="ipalias" <select id="mode" name="mode" class="selectpicker" data-width="auto" data-live-search="true">
<?php if ($pconfig['mode'] == "ipalias") echo "checked=\"checked\"";?> /> <?=gettext("IP Alias");?> <option value="ipalias" <?=$pconfig['mode'] == "ipalias" ? "selected=\"selected\"" : ""; ?>><?=gettext("IP Alias");?></option>
<input name="mode" type="radio" onclick="enable_change()" value="carp" <option value="carp" <?=$pconfig['mode'] == "carp" ? "selected=\"selected\"" : ""; ?>><?=gettext("carp");?></option>
<?php if ($pconfig['mode'] == "carp") echo "checked=\"checked\"";?> /> <?=gettext("CARP"); ?> <option value="proxyarp" <?=$pconfig['mode'] == "proxyarp" ? "selected=\"selected\"" : ""; ?>><?=gettext("Proxy ARP");?></option>
<input name="mode" type="radio" onclick="enable_change()" value="proxyarp" <option value="other" <?=$pconfig['mode'] == "other" ? "selected=\"selected\"" : ""; ?>><?=gettext("Other");?></option>
<?php if ($pconfig['mode'] == "proxyarp") echo "checked=\"checked\"";?> /> <?=gettext("Proxy ARP"); ?> </select>
<input name="mode" type="radio" onclick="enable_change()" value="other"
<?php if ($pconfig['mode'] == "other") echo "checked=\"checked\"";?> /> <?=gettext("Other");?>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td> <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Interface");?></td>
<td width="78%" class="vtable"> <td>
<select name="interface" class="form-control"> <select name="interface" class="selectpicker" data-width="auto">
<?php <?php
$interfaces = get_configured_interface_with_descr(false, true); $interfaces = get_configured_interface_with_descr(false, true);
$interfaces['lo0'] = "Localhost"; $interfaces['lo0'] = "Localhost";
foreach ($interfaces as $iface => $ifacename): ?> foreach ($interfaces as $iface => $ifacename): ?>
<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>> <option value="<?=$iface;?>" <?= $iface == $pconfig['interface'] ? "selected=\"selected\"" :""; ?>>
<?=htmlspecialchars($ifacename);?> <?=htmlspecialchars($ifacename);?>
</option> </option>
<?php endforeach; ?> <?php
endforeach; ?>
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<td valign="top" class="vncellreq"><?=gettext("IP Address(es)");?></td> <td><?=gettext("IP Address(es)");?></td>
<td class="vtable"> <td></td>
<table border="0" cellspacing="0" cellpadding="0" summary="ip addresses"> </tr>
<tr> <tr>
<td><?=gettext("Type:");?>&nbsp;&nbsp;</td> <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Type:");?></td>
<td><select name="type" class="form-control" onchange="typesel_change()"> <td>
<option value="single" <?php if ((!$pconfig['range'] && $pconfig['subnet_bits'] == 32) || (!isset($pconfig['subnet']))) echo "selected=\"selected\""; ?>> <select name="type" class="selectpicker" data-width="auto" id="type">
<?=gettext("Single address");?></option> <option value="single" <?=(!empty($pconfig['subnet_bits']) && $pconfig['subnet_bits'] == 32) || !isset($pconfig['subnet']) ? "selected=\"selected\"" : "";?>>
<option value="network" <?php if (!$pconfig['range'] && $pconfig['subnet_bits'] != 32 && isset($pconfig['subnet'])) echo "selected=\"selected\""; ?>> <?=gettext("Single address");?>
</option>
<option value="network" <?=empty($pconfig['subnet_bits']) || $pconfig['subnet_bits'] != 32 || isset($pconfig['subnet']) ? "selected=\"selected\"" : "";?>>
<?=gettext("Network");?></option> <?=gettext("Network");?></option>
<!-- XXX: Billm, don't let anyone choose this until NAT configuration screens are ready for it <option value="range" <?php if ($pconfig['range']) echo "selected=\"selected\""; ?>> </select>
Range</option> --> </td>
</select></td>
</tr> </tr>
<tr> <tr>
<td><?=gettext("Address:");?>&nbsp;&nbsp;</td> <td><a id="help_for_address" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Address:");?></td>
<td><input name="subnet" type="text" class="form-control unknown ipv4v6" id="subnet" size="28" value="<?=htmlspecialchars($pconfig['subnet']);?>" /> <td>
/<select name="subnet_bits" class="form-control ipv4v6" id="select"> <table border="0" cellspacing="0" cellpadding="0">
<?php for ($i = 128; $i >= 1; $i--): ?> <tr>
<td width="348px">
<input name="subnet" type="text" class="form-control" id="subnet" size="28" value="<?=$pconfig['subnet'];?>" />
</td>
<td >
<select name="subnet_bits" class="selectpicker" data-size="10" data-width="auto" id="subnet_bits">
<?php
for ($i = 128; $i >= 1; $i--): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['subnet_bits']) echo "selected=\"selected\""; ?>> <option value="<?=$i;?>" <?php if ($i == $pconfig['subnet_bits']) echo "selected=\"selected\""; ?>>
<?=$i;?> <?=$i;?>
</option> </option>
<?php endfor; ?> <?php
</select> <i id="typenote"></i> endfor; ?>
</td> </select>
</tr>
<tr id="noexpandrow">
<td><?=gettext("Expansion:");?>&nbsp;&nbsp;</td>
<td><input name="noexpand" type="checkbox" class="form-control unknown" id="noexpand" <?php echo (isset($pconfig['noexpand'])) ? "checked=\"checked\"" : "" ; ?> />
Disable expansion of this entry into IPs on NAT lists (e.g. 192.168.1.0/24 expands to 256 entries.)
</td>
</tr>
<?php
/*
<tr>
<td>Range:&nbsp;&nbsp;</td>
<td><input name="range_from" type="text" class="form-control unknown" id="range_from" size="28" value="<?=htmlspecialchars($pconfig['range']['from']);?>" />
-
<input name="range_to" type="text" class="form-control unknown" id="range_to" size="28" value="<?=htmlspecialchars($pconfig['range']['to']);?>" />
</td> </td>
</tr> </tr>
*/
?>
</table> </table>
<div class="hidden" for="help_for_address">
<i id="typenote"></i>
</div>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr id="noexpandrow">
<td width="22%" class="vncellreq"><?=gettext("Virtual IP Password");?></td> <td><a id="help_for_noexpand" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Expansion:");?> </td>
<td class="vtable"><input type='password' name='password' value="<?=htmlspecialchars($pconfig['password']);?>" /> <td>
<br /><?=gettext("Enter the VHID group password.");?> <input id="noexpand" name="noexpand" type="checkbox" class="form-control unknown" id="noexpand" <?= !empty($pconfig['noexpand']) ? "checked=\"checked\"" : "" ; ?> />
<div class="hidden" for="help_for_noexpand">
<?=gettext("Disable expansion of this entry into IPs on NAT lists (e.g. 192.168.1.0/24 expands to 256 entries.");?>
</div>
</tr>
<tr>
<td><a id="help_for_password" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Virtual IP Password");?></td>
<td>
<input type='password' name='password' id="password" value="<?=$pconfig['password'];?>" />
<div class="hidden" for="help_for_password">
<?=gettext("Enter the VHID group password.");?>
</div>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr>
<td width="22%" class="vncellreq"><?=gettext("VHID Group");?></td> <td><a id="help_for_vhid" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("VHID Group");?></td>
<td class="vtable"><select id='vhid' name='vhid'> <td>
<select id='vhid' name='vhid' class="selectpicker" data-size="10" data-width="auto">
<?php for ($i = 1; $i <= 255; $i++): ?> <?php for ($i = 1; $i <= 255; $i++): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['vhid']) echo "selected=\"selected\""; ?>> <option value="<?=$i;?>" <?= $i == $pconfig['vhid'] ? "selected=\"selected\"" : ""; ?>>
<?=$i;?> <?=$i;?>
</option> </option>
<?php endfor; ?> <?php endfor; ?>
</select> </select>
<br /><?=gettext("Enter the VHID group that the machines will share");?> <div class="hidden" for="help_for_vhid">
<?=gettext("Enter the VHID group that the machines will share");?>
</div>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr>
<td width="22%" class="vncellreq"><?=gettext("Advertising Frequency");?></td> <td><a id="help_for_adv" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Advertising Frequency");?></td>
<td class="vtable"> <td>
Base: <select id='advbase' name='advbase'> <?=gettext("Base");?>:
<select id='advbase' name='advbase' class="selectpicker" data-size="10" data-width="auto">
<?php for ($i = 1; $i <= 254; $i++): ?> <?php for ($i = 1; $i <= 254; $i++): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['advbase']) echo "selected=\"selected\""; ?>> <option value="<?=$i;?>" <?=$i == $pconfig['advbase'] ? "selected=\"selected\"" :""; ?>>
<?=$i;?> <?=$i;?>
</option> </option>
<?php endfor; ?> <?php endfor; ?>
</select> </select>
Skew: <select id='advskew' name='advskew'> <?=gettext("Skew");?>:
<select id='advskew' name='advskew' class="selectpicker" data-size="10" data-width="auto">
<?php for ($i = 0; $i <= 254; $i++): ?> <?php for ($i = 0; $i <= 254; $i++): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['advskew']) echo "selected=\"selected\""; ?>> <option value="<?=$i;?>" <?php if ($i == $pconfig['advskew']) echo "selected=\"selected\""; ?>>
<?=$i;?> <?=$i;?>
</option> </option>
<?php endfor; ?> <?php endfor; ?>
</select> </select>
<br /><br />
<div class="hidden" for="help_for_adv">
<br/>
<?=gettext("The frequency that this machine will advertise. 0 means usually master. Otherwise the lowest combination of both values in the cluster determines the master.");?> <?=gettext("The frequency that this machine will advertise. 0 means usually master. Otherwise the lowest combination of both values in the cluster determines the master.");?>
</div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td> <td><a id="help_for_descr" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description");?></td>
<td width="78%" class="vtable"> <td>
<input name="descr" type="text" class="form-control unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" /> <input name="descr" type="text" class="form-control unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
<br /> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed).");?></span></td> <div class="hidden" for="help_for_adv">
<?=gettext("You may enter a description here for your reference (not parsed).");?>
</div>
</td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top">&nbsp;</td> <td>&nbsp;</td>
<td width="78%"> <td>
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" /> <input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" /> <input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_virtual_ip.php');?>'" />
<?php if (isset($id) && $a_vip[$id]): ?> <?php if (isset($id) && $a_vip[$id]): ?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" /> <input name="id" type="hidden" value="<?=$id;?>" />
<?php endif; ?> <?php endif; ?>
</td> </td>
</tr> </tr>
</tbody>
</table> </table>
</div> </div>
</form>
<div class="container-fluid"> <div class="container-fluid">
<p class="vexpl">
<span class="text-danger"> <span class="text-danger">
<strong><?=gettext("Note:");?><br /></strong> <strong><?=gettext("Note:");?><br /></strong>
</span> </span>
<?=gettext("Proxy ARP and Other type Virtual IPs cannot be bound to by anything running on the firewall, such as IPsec, OpenVPN, etc. Use a CARP or IP Alias type address for these cases.");?> <?=gettext("Proxy ARP and Other type Virtual IPs cannot be bound to by anything running on the firewall, such as IPsec, OpenVPN, etc. Use a CARP or IP Alias type address for these cases.");?>
<br /><br /><?=gettext("For more information on CARP and the above values, visit the OpenBSD ");?><a href='http://www.openbsd.org/faq/pf/carp.html'> <?=gettext("CARP FAQ"); ?></a>. <br /><br />
</p> <?=gettext("For more information on CARP and the above values, visit the OpenBSD ");?><a href='http://www.openbsd.org/faq/pf/carp.html'> <?=gettext("CARP FAQ"); ?></a>.
</div>
</form>
</div> </div>
</div> </div>
</section> </section>
</div> </div>
</div> </div>
</section> </section>
<script type="text/javascript">
//<![CDATA[
enable_change();
//]]>
</script>
<?php include("foot.inc"); ?> <?php include("foot.inc"); ?>
/**
* An autosuggest textbox control.
* @class
* @scope public
*/
function AutoSuggestControl(oTextbox /*:HTMLInputElement*/,
oProvider /*:SuggestionProvider*/) {
/**
* The currently selected suggestions.
* @scope private
*/
this.cur /*:int*/ = -1;
/**
* The dropdown list layer.
* @scope private
*/
this.layer = null;
/**
* Suggestion provider for the autosuggest feature.
* @scope private.
*/
this.provider /*:SuggestionProvider*/ = oProvider;
/**
* The textbox to capture.
* @scope private
*/
this.textbox /*:HTMLInputElement*/ = oTextbox;
//initialize the control
this.init();
}
/**
* Autosuggests one or more suggestions for what the user has typed.
* If no suggestions are passed in, then no autosuggest occurs.
* @scope private
* @param aSuggestions An array of suggestion strings.
* @param bTypeAhead If the control should provide a type ahead suggestion.
*/
AutoSuggestControl.prototype.autosuggest = function (aSuggestions /*:Array*/,
bTypeAhead /*:boolean*/) {
//make sure there's at least one suggestion
if (aSuggestions.length > 0) {
if (bTypeAhead) {
this.typeAhead(aSuggestions[0]);
}
this.showSuggestions(aSuggestions);
} else {
this.hideSuggestions();
}
};
/**
* Creates the dropdown layer to display multiple suggestions.
* @scope private
*/
AutoSuggestControl.prototype.createDropDown = function () {
var oThis = this;
//create the layer and assign styles
this.layer = document.createElement("div");
this.layer.className = "suggestions";
this.layer.style.visibility = "hidden";
this.layer.style.width = this.textbox.offsetWidth;
//when the user clicks on the a suggestion, get the text (innerHTML)
//and place it into a textbox
this.layer.onmousedown =
this.layer.onmouseup =
this.layer.onmouseover = function (oEvent) {
oEvent = oEvent || window.event;
oTarget = oEvent.target || oEvent.srcElement;
if (oEvent.type == "mousedown") {
oThis.textbox.value = oTarget.firstChild.nodeValue;
oThis.hideSuggestions();
} else if (oEvent.type == "mouseover") {
oThis.highlightSuggestion(oTarget);
} else {
oThis.textbox.focus();
}
};
document.body.appendChild(this.layer);
};
/**
* Gets the left coordinate of the textbox.
* @scope private
* @return The left coordinate of the textbox in pixels.
*/
AutoSuggestControl.prototype.getLeft = function () /*:int*/ {
var oNode = this.textbox;
var iLeft = 0;
while(oNode.tagName != "BODY") {
iLeft += oNode.offsetLeft;
oNode = oNode.offsetParent;
}
return iLeft;
};
/**
* Gets the top coordinate of the textbox.
* @scope private
* @return The top coordinate of the textbox in pixels.
*/
AutoSuggestControl.prototype.getTop = function () /*:int*/ {
var oNode = this.textbox;
var iTop = 0;
while(oNode.tagName != "BODY") {
iTop += oNode.offsetTop;
oNode = oNode.offsetParent;
}
return iTop;
};
/**
* Handles three keydown events.
* @scope private
* @param oEvent The event object for the keydown event.
*/
AutoSuggestControl.prototype.handleKeyDown = function (oEvent /*:Event*/) {
switch(oEvent.keyCode) {
case 38: //up arrow
this.previousSuggestion();
break;
case 40: //down arrow
this.nextSuggestion();
break;
case 13: //enter
this.hideSuggestions();
break;
}
};
/**
* Handles keyup events.
* @scope private
* @param oEvent The event object for the keyup event.
*/
AutoSuggestControl.prototype.handleKeyUp = function (oEvent /*:Event*/) {
var iKeyCode = oEvent.keyCode;
//for backspace (8) and delete (46), shows suggestions without typeahead
if (iKeyCode == 8 || iKeyCode == 46) {
this.provider.requestSuggestions(this, false);
//make sure not to interfere with non-character keys
} else if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode < 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
//ignore
} else {
//request suggestions from the suggestion provider with typeahead
this.provider.requestSuggestions(this, true);
}
};
/**
* Hides the suggestion dropdown.
* @scope private
*/
AutoSuggestControl.prototype.hideSuggestions = function () {
this.layer.style.visibility = "hidden";
};
/**
* Highlights the given node in the suggestions dropdown.
* @scope private
* @param oSuggestionNode The node representing a suggestion in the dropdown.
*/
AutoSuggestControl.prototype.highlightSuggestion = function (oSuggestionNode) {
for (var i=0; i < this.layer.childNodes.length; i++) {
var oNode = this.layer.childNodes[i];
if (oNode == oSuggestionNode) {
oNode.className = "current";
} else if (oNode.className == "current") {
oNode.className = "";
}
}
};
/**
* Initializes the textbox with event handlers for
* auto suggest functionality.
* @scope private
*/
AutoSuggestControl.prototype.init = function () {
//save a reference to this object
var oThis = this;
//assign the onkeyup event handler
this.textbox.onkeyup = function (oEvent) {
//check for the proper location of the event object
if (!oEvent) {
oEvent = window.event;
}
//call the handleKeyUp() method with the event object
oThis.handleKeyUp(oEvent);
};
//assign onkeydown event handler
this.textbox.onkeydown = function (oEvent) {
//check for the proper location of the event object
if (!oEvent) {
oEvent = window.event;
}
//call the handleKeyDown() method with the event object
oThis.handleKeyDown(oEvent);
};
//assign onblur event handler (hides suggestions)
this.textbox.onblur = function () {
oThis.hideSuggestions();
};
//create the suggestions dropdown
this.createDropDown();
};
/**
* Highlights the next suggestion in the dropdown and
* places the suggestion into the textbox.
* @scope private
*/
AutoSuggestControl.prototype.nextSuggestion = function () {
var cSuggestionNodes = this.layer.childNodes;
if (cSuggestionNodes.length > 0 && this.cur < cSuggestionNodes.length-1) {
var oNode = cSuggestionNodes[++this.cur];
this.highlightSuggestion(oNode);
this.textbox.value = oNode.firstChild.nodeValue;
}
};
/**
* Highlights the previous suggestion in the dropdown and
* places the suggestion into the textbox.
* @scope private
*/
AutoSuggestControl.prototype.previousSuggestion = function () {
var cSuggestionNodes = this.layer.childNodes;
if (cSuggestionNodes.length > 0 && this.cur > 0) {
var oNode = cSuggestionNodes[--this.cur];
this.highlightSuggestion(oNode);
this.textbox.value = oNode.firstChild.nodeValue;
}
};
/**
* Selects a range of text in the textbox.
* @scope public
* @param iStart The start index (base 0) of the selection.
* @param iLength The number of characters to select.
*/
AutoSuggestControl.prototype.selectRange = function (iStart /*:int*/, iLength /*:int*/) {
//use text ranges for Internet Explorer
if (this.textbox.createTextRange) {
var oRange = this.textbox.createTextRange();
oRange.moveStart("character", iStart);
oRange.moveEnd("character", iLength - this.textbox.value.length);
oRange.select();
//use setSelectionRange() for Mozilla
} else if (this.textbox.setSelectionRange) {
this.textbox.setSelectionRange(iStart, iLength);
}
//set focus back to the textbox
this.textbox.focus();
};
/**
* Builds the suggestion layer contents, moves it into position,
* and displays the layer.
* @scope private
* @param aSuggestions An array of suggestions for the control.
*/
AutoSuggestControl.prototype.showSuggestions = function (aSuggestions /*:Array*/) {
var oDiv = null;
this.layer.innerHTML = ""; //clear contents of the layer
for (var i=0; i < aSuggestions.length; i++) {
oDiv = document.createElement("div");
oDiv.appendChild(document.createTextNode(aSuggestions[i]));
this.layer.appendChild(oDiv);
}
this.layer.style.left = this.getLeft() + "px";
this.layer.style.top = (this.getTop()+this.textbox.offsetHeight) + "px";
this.layer.style.visibility = "visible";
};
/**
* Inserts a suggestion into the textbox, highlighting the
* suggested part of the text.
* @scope private
* @param sSuggestion The suggestion for the textbox.
*/
AutoSuggestControl.prototype.typeAhead = function (sSuggestion /*:String*/) {
//check for support of typeahead functionality
if (this.textbox.createTextRange || this.textbox.setSelectionRange){
var iLen = this.textbox.value.length;
this.textbox.value = sSuggestion;
this.selectRange(iLen, sSuggestion.length);
}
};
function kH(e) {
var pK = document.all? window.event.keyCode:e.which;
return pK != 13;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
//<![CDATA[
var portsenabled = 1;
var editenabled = 1;
function ext_change() {
if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled && editenabled) {
document.iform.srcbeginport_cust.disabled = 0;
} else {
if (editenabled)
document.iform.srcbeginport_cust.value = "";
document.iform.srcbeginport_cust.disabled = 1;
}
if ((document.iform.srcendport.selectedIndex == 0) && portsenabled && editenabled) {
document.iform.srcendport_cust.disabled = 0;
} else {
if (editenabled)
document.iform.srcendport_cust.value = "";
document.iform.srcendport_cust.disabled = 1;
}
if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled && editenabled) {
document.iform.dstbeginport_cust.disabled = 0;
} else {
if (editenabled)
document.iform.dstbeginport_cust.value = "";
document.iform.dstbeginport_cust.disabled = 1;
}
if ((document.iform.dstendport.selectedIndex == 0) && portsenabled && editenabled) {
document.iform.dstendport_cust.disabled = 0;
} else {
if (editenabled)
document.iform.dstendport_cust.value = "";
document.iform.dstendport_cust.disabled = 1;
}
if (!portsenabled) {
document.iform.srcbeginport.disabled = 1;
document.iform.srcendport.disabled = 1;
document.iform.dstbeginport.disabled = 1;
document.iform.dstendport.disabled = 1;
} else {
if( editenabled ) {
document.iform.srcbeginport.disabled = 0;
document.iform.srcendport.disabled = 0;
document.iform.dstbeginport.disabled = 0;
document.iform.dstendport.disabled = 0;
}
}
}
function show_source_port_range() {
if (portsenabled) {
document.getElementById("sprtable").style.display = '';
document.getElementById("showadvancedboxspr").style.display = 'none';
}
}
function typesel_change() {
if( editenabled ) {
switch (document.iform.srctype.selectedIndex) {
case 1: /* single */
document.iform.src.disabled = 0;
document.iform.srcmask.value = "";
document.iform.srcmask.disabled = 1;
break;
case 2: /* network */
document.iform.src.disabled = 0;
document.iform.srcmask.disabled = 0;
break;
default:
document.iform.src.value = "";
document.iform.src.disabled = 1;
document.iform.srcmask.value = "";
document.iform.srcmask.disabled = 1;
break;
}
switch (document.iform.dsttype.selectedIndex) {
case 1: /* single */
document.iform.dst.disabled = 0;
document.iform.dstmask.value = "";
document.iform.dstmask.disabled = 1;
break;
case 2: /* network */
document.iform.dst.disabled = 0;
document.iform.dstmask.disabled = 0;
break;
default:
document.iform.dst.value = "";
document.iform.dst.disabled = 1;
document.iform.dstmask.value = "";
document.iform.dstmask.disabled = 1;
break;
}
}
}
function proto_change() {
if (document.iform.proto.selectedIndex < 3) {
portsenabled = 1;
document.getElementById("tcpflags").style.display = '';
} else {
portsenabled = 0;
document.getElementById("tcpflags").style.display = 'none';
}
if (document.iform.proto.selectedIndex == 3) {
document.iform.icmptype.disabled = 0;
} else {
document.iform.icmptype.disabled = 1;
}
ext_change();
if(document.iform.proto.selectedIndex == 3 || document.iform.proto.selectedIndex == 4) {
document.getElementById("icmpbox").style.display = '';
} else {
document.getElementById("icmpbox").style.display = 'none';
}
if(document.iform.proto.selectedIndex >= 0 && document.iform.proto.selectedIndex <= 2) {
document.getElementById("dprtr").style.display = '';
if (editenabled) {
document.getElementById("showadvancedboxspr").style.display = 'table-row';
}
} else {
document.getElementById("sprtable").style.display = 'none';
document.getElementById("dprtr").style.display = 'none';
document.getElementById("showadvancedboxspr").style.display = 'none';
}
}
function show_aodiv() {
document.getElementById("aoadv").innerHTML='';
aodiv = document.getElementById('aodivmain');
aodiv.style.display = "block";
}
function show_dsdiv() {
document.getElementById("dsadv").innerHTML='';
dsdiv = document.getElementById('dsdivmain');
dsdiv.style.display = "block";
}
function show_advanced_noxmlrpc() {
document.getElementById("showadvnoxmlrpcsyncbox").innerHTML='';
aodiv = document.getElementById('shownoxmlrpcadv');
aodiv.style.display = "block";
}
function show_advanced_schedule() {
document.getElementById("showadvschedulebox").innerHTML='';
aodiv = document.getElementById('showscheduleadv');
aodiv.style.display = "block";
}
function show_advanced_gateway() {
document.getElementById("showadvgatewaybox").innerHTML='';
aodiv = document.getElementById('showgatewayadv');
aodiv.style.display = "block";
}
function show_advanced_sourceos() {
document.getElementById("showadvsourceosbox").innerHTML='';
aodiv = document.getElementById('showsourceosadv');
aodiv.style.display = "block";
}
function show_advanced_inout() {
document.getElementById("showadvinoutbox").innerHTML='';
aodiv = document.getElementById('showinoutadv');
aodiv.style.display = "block";
}
function show_advanced_state() {
document.getElementById("showadvstatebox").innerHTML='';
aodiv = document.getElementById('showstateadv');
aodiv.style.display = "block";
}
function show_advanced_tcpflags() {
document.getElementById("showtcpflagsbox").innerHTML='';
aodiv = document.getElementById('showtcpflagsadv');
aodiv.style.display = "block";
}
function src_rep_change() {
document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
}
function dst_rep_change() {
document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
}
function tcpflags_anyclick(obj) {
if (obj.checked) {
document.getElementById('tcpheader').style.display= 'none';
} else {
document.getElementById('tcpheader').style.display= "";
}
}
//]]>
/**
* Provides suggestions for state names (USA).
* @class
* @scope public
*/
function StateSuggestions(text) {
this.states = text;
}
/**
* Request suggestions for the given autosuggest control.
* @scope protected
* @param oAutoSuggestControl The autosuggest control to provide suggestions for.
*/
StateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
bTypeAhead /*:boolean*/) {
var aSuggestions = [];
var sTextboxValue = oAutoSuggestControl.textbox.value;
if (sTextboxValue.length > 0){
//search for matching states
for (var i=0; i < this.states.length; i++) {
if (this.states[i].toLowerCase().indexOf(sTextboxValue.toLowerCase()) == 0) {
aSuggestions.push(this.states[i]);
}
}
}
//provide suggestions to the control
oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
};
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