Commit b658fdfd authored by Franco Fichtner's avatar Franco Fichtner

firewall: merge rules, schedule, and virtual ip pages

parent a9d697f9
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("filter.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'])) {
$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 */
if (isset($config['openvpn']['openvpn-server']) || isset($config['openvpn']['openvpn-client'])) {
$iflist['openvpn'] = 'OpenVPN';
$config['filter']['rule'] = array();
}
if (!$if || !isset($iflist[$if])) {
if ("any" == $if)
$if = "FloatingRules";
else if ("FloatingRules" != $if) {
if (isset($iflist['wan']))
$if = "wan";
else
$if = "FloatingRules";
}
}
if ($_POST) {
$pconfig = $_POST;
if ($_POST['apply']) {
$retval = 0;
$retval = filter_configure();
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>");
}
}
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;
}
$a_filter = &$config['filter']['rule'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_GET['if'])) {
$current_if = htmlspecialchars($_GET['if']);
} else {
$current_if = "FloatingRules";
}
$pconfig = $_POST;
if (isset($pconfig['id']) && isset($a_filter[$pconfig['id']])) {
// id found and valid
$id = $pconfig['id'];
}
if (isset($pconfig['apply'])) {
filter_configure();
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>");
} 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'] = '';
}
}
}
}
unset($a_filter[$id]);
if (write_config()) {
mark_subsystem_dirty('filter');
}
header("Location: firewall_rules.php?if=" . htmlspecialchars($current_if));
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'] = '';
}
}
}
unset($a_filter[$rulei]);
}
if (write_config()) {
mark_subsystem_dirty('filter');
}
header("Location: firewall_rules.php?if=" . htmlspecialchars($current_if));
exit;
} elseif ( isset($pconfig['act']) && $pconfig['act'] == 'move' && isset($pconfig['rule']) && count($pconfig['rule']) > 0) {
// move selected rules
if (!isset($id)) {
// if rule not set/found, move to end
$id = count($a_nat);
}
$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;
} elseif (isset($pconfig['act']) && $pconfig['act'] == 'toggle' && isset($id)) {
// 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');
}
header("Location: firewall_rules.php?if=" . htmlspecialchars($current_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())
mark_subsystem_dirty('filter');
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
exit;
}
} else if ($_GET['act'] == "toggle") {
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;
}
if (isset($_GET['if'])) {
$selected_if = htmlspecialchars($_GET['if']);
} 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;
}
}
/* 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];
}
/* copy all selected rules */
for ($i = 0; $i < count($a_filter); $i++) {
if ($i == $movebtn)
continue;
if (in_array($i, $_POST['rule']))
$a_filter_new[] = $a_filter[$i];
}
/* copy $movebtn rule */
if ($movebtn < count($a_filter))
$a_filter_new[] = $a_filter[$movebtn];
/* copy all rules > $movebtn and not selected */
for ($i = $movebtn+1; $i < count($a_filter); $i++) {
if (!in_array($i, $_POST['rule']))
$a_filter_new[] = $a_filter[$i];
}
$a_filter = $a_filter_new;
if (write_config())
mark_subsystem_dirty('filter');
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
exit;
}
$selected_if = "FloatingRules";
}
$closehead = true;
$pgtitle = array(gettext("Firewall"),gettext("Rules"));
$shortcut_section = "firewall";
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>
<body>
<script type='text/javascript'>//<![CDATA[
jQuery(window).load(
function(){
var originalLeave=jQuery.fn.popover.Constructor.prototype.leave;
jQuery.fn.popover.Constructor.prototype.leave=function(obj)
{
var self=obj instanceof this.constructor?obj:jQuery(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.'+this.type)
var container,timeout;originalLeave.call(this,obj);
if(obj.currentTarget){container=jQuery(obj.currentTarget).siblings('.popover')
timeout=self.timeout;
container.one('mouseenter',function()
{
clearTimeout(timeout);
container.one('mouseleave',function()
{
jQuery.fn.popover.Constructor.prototype.leave.call(self,self);
});
})
}
};
jQuery('body').popover({selector:'[data-popover]',trigger:'click hover',placement:'auto',delay:{show:250,hide:50}
});
});
//]]>
<script type="text/javascript">
$( document ).ready(function() {
// link delete buttons
$(".act_delete").click(function(){
var id = $(this).attr("id").split('_').pop(-1);
if (id != 'x') {
// delete single
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Rules");?>",
message: "<?=gettext("Do you really want to delete this rule?");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$("#id").val(id);
$("#action").val("del");
$("#iform").submit()
}
}]
});
} else {
// delete selected
BootstrapDialog.show({
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()
}
}]
});
}
});
// 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">
<div class="container-fluid">
<div class="row">
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('filter')): ?><p>
<?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."));?>
<?php endif; ?>
<section class="col-xs-12">
<?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";
}
}
}
/* 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';
}
$tab_array = array();
foreach ($iflist_tabs as $ifent => $ifname) {
$active = false;
// mark active if selected or mark floating active when none is selected
if ($ifent == $selected_if) {
$active = true;
}
$tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}");
}
display_top_tabs($tab_array);
?>
<div class="content-box">
<form action="firewall_rules.php?if=<?=$selected_if;?>" 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" >
<table class="table table-striped">
<thead>
<tr>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th><?=gettext("Proto");?></th>
<th><?=gettext("Source");?></th>
<th class="hidden-xs hidden-sm"><?=gettext("Port");?></th>
<th class="hidden-xs hidden-sm"><?=gettext("Destination");?></th>
<th class="hidden-xs hidden-sm"><?=gettext("Port");?></th>
<th class="hidden-xs hidden-sm"><?=gettext("Gateway");?></th>
<th class="hidden-xs hidden-sm"><?=gettext("Schedule");?></th>
<th><?=gettext("Description");?></th>
<th></th>
</tr>
</thead>
<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.
if (!isset($config['system']['webgui']['noantilockout']) &&
(((count($config['interfaces']) > 1) && ($selected_if == 'lan'))
|| ((count($config['interfaces']) == 1) && ($selected_if == 'wan')))):
$alports = implode('<br />', filter_get_antilockout_ports(true));
?>
<tr valign="top">
<td>&nbsp;</td>
<td><span class="glyphicon glyphicon-play text-success"></span></td>
<td>*</td>
<td>*</td>
<td class="hidden-xs hidden-sm">*</td>
<td class="hidden-xs hidden-sm"><?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($selected_if));?> Address</td>
<td class="hidden-xs hidden-sm"><?=$alports;?></td>
<td class="hidden-xs hidden-sm">*</td>
<td class="hidden-xs hidden-sm">&nbsp;</td>
<td><?=gettext("Anti-Lockout Rule");?></td>
<td>
<a href="system_advanced_admin.php" title="<?=gettext("edit rule");?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
</td>
</tr>
<?php
endif; ?>
<?php
if (isset($config['interfaces'][$selected_if]['blockpriv'])): ?>
<tr>
<td>&nbsp;</td>
<td><span class="glyphicon glyphicon-remove text-danger"></span></td>
<td>*</td>
<td><?=gettext("RFC 1918 networks");?></td>
<td>*</td>
<td class="hidden-xs hidden-sm">*</td>
<td class="hidden-xs hidden-sm">*</td>
<td class="hidden-xs hidden-sm">*</td>
<td class="hidden-xs hidden-sm">&nbsp;</td>
<td class="hidden-xs hidden-sm"><?=gettext("Block private networks");?></td>
<td valign="middle" class="list nowrap">
<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>
</td>
</tr>
<?php
endif;
if (isset($config['interfaces'][$selected_if]['blockbogons'])): ?>
<tr valign="top" id="frrfc1918">
<td>&nbsp;</td>
<td align="center"><span class="glyphicon glyphicon-remove text-danger"></span></td>
<td>*</td>
<td><?=gettext("Reserved/not assigned by IANA");?></td>
<td class="hidden-xs hidden-sm">*</td>
<td class="hidden-xs hidden-sm">*</td>
<td class="hidden-xs hidden-sm">*</td>
<td class="hidden-xs hidden-sm">*</td>
<td class="hidden-xs hidden-sm">*</td>
<td><?=gettext("Block bogon networks");?></td>
<td>
<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>
</td>
</tr>
<?php
endif; ?>
<?php
$interface_has_rules = false;
foreach ($a_filter as $i => $filterent):
if ( (isset($filterent['interface']) && $filterent['interface'] == $selected_if) ||
(isset($filterent['floating']) && $selected_if == "FloatingRules" )):
$interface_has_rules = true;
// select icon
if (!isset($filterent['type']) && empty($filterent['disabled'])) {
// not very nice.... associated NAT rules don't have a type...
$iconfn = "glyphicon-play text-success";
} else if (!isset($filterent['type']) && !empty($filterent['disabled'])) {
$iconfn = "glyphicon-play text-muted";
} elseif ($filterent['type'] == "block" && empty($filterent['disabled'])) {
$iconfn = "glyphicon-remove text-danger";
} elseif ($filterent['type'] == "block" && !empty($filterent['disabled'])) {
$iconfn = "glyphicon-remove text-muted";
} elseif ($filterent['type'] == "reject" && empty($filterent['disabled'])) {
$iconfn = "glyphicon-remove text-warning";
} elseif ($filterent['type'] == "reject" && !empty($filterent['disabled'])) {
$iconfn = "glyphicon-remove text-muted";
} else if ($filterent['type'] == "match" && empty($filterent['disabled'])) {
$iconfn = "glyphicon-ok";
} else if ($filterent['type'] == "match" && !empty($filterent['disabled'])) {
$iconfn = "glyphicon-ok text-muted";
} elseif (empty($filterent['disabled'])) {
$iconfn = "glyphicon-play text-success";
} else {
$iconfn = "glyphicon-play text-muted";
}
// construct line ipprotocol
if (isset($filterent['ipprotocol'])) {
switch($filterent['ipprotocol']) {
case "inet":
$record_ipprotocol = "IPv4 ";
break;
case "inet6":
$record_ipprotocol = "IPv6 ";
break;
case "inet46":
$record_ipprotocol = "IPv4+6 ";
break;
}
} else {
$record_ipprotocol = "IPv4 ";
}
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('filter')): ?><p>
<?php
if ($_REQUEST['undodrag']) {
foreach ($_REQUEST['dragtable'] as $dt) {
$dragtable .= "&dragtable[]={$dt}";
}
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">
<?php
/* active tabs */
$tab_array = array();
if ("FloatingRules" == $if)
$active = true;
else
$active = false;
$tab_array[] = array(gettext("Floating"), $active, "firewall_rules.php?if=FloatingRules");
$tabscounter = 0; $i = 0; foreach ($iflist as $ifent => $ifname) {
if ($ifent == $if)
$active = true;
else
$active = false;
$tab_array[] = array($ifname, $active, "firewall_rules.php?if={$ifent}");
}
display_top_tabs($tab_array);
?>
<div class="tab-content content-box col-xs-12" style="overflow: auto;">
<form action="firewall_rules.php<? if (!empty($if)): ?>?if=<?=$if;?><? endif; ?>" method="post" name="iform" id="iform">
<div class="table-responsive" >
<table class="table table-striped table-sort dragable">
<thead>
<tr id="frheader">
<th class="list">&nbsp;</th>
<th class="list">&nbsp;</th>
<th class="listhdrr"><?=gettext("Proto");?></th>
<th class="listhdrr"><?=gettext("Source");?></th>
<th class="listhdrr"><?=gettext("Port");?></th>
<th class="listhdrr"><?=gettext("Destination");?></th>
<th class="listhdrr"><?=gettext("Port");?></th>
<th class="listhdrr"><?=gettext("Gateway");?></th>
<th class="listhdrr"><?=gettext("Queue");?></th>
<th class="listhdrr"><?=gettext("Schedule");?></th>
<th class="listhdr"><?=gettext("Description");?></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>
</thead>
<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.
if (!isset($config['system']['webgui']['noantilockout']) &&
(((count($config['interfaces']) > 1) && ($if == 'lan'))
|| ((count($config['interfaces']) == 1) && ($if == 'wan')))):
$alports = implode('<br />', filter_get_antilockout_ports(true));
?>
<tr valign="top" id="antilockout">
<td class="list">&nbsp;</td>
<td class="listt" align="center"><span class="glyphicon glyphicon-play text-success"></span></td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr"><?=$iflist[$if];?> Address</td>
<td class="listr"><?= $alports ?></td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">&nbsp;</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>
<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>
</tr>
<?php endif; ?>
<?php if (isset($config['interfaces'][$if]['blockpriv'])): ?>
<tr valign="top" id="frrfc1918">
<td class="list">&nbsp;</td>
<td class="listt" align="center"><span class="glyphicon glyphicon-remove text-danger"></span></td>
<td class="listr">*</td>
<td class="listr"><?=gettext("RFC 1918 networks");?></td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">&nbsp;</td>
<td class="listbg"><?=gettext("Block private 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>
<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>
</tr>
<?php endif; ?>
<?php if (isset($config['interfaces'][$if]['blockbogons'])): ?>
<tr valign="top" id="frrfc1918">
<td class="list">&nbsp;</td>
<td class="listt" align="center"><span class="glyphicon glyphicon-remove text-danger"></span></td>
<td class="listr">*</td>
<td class="listr"><?=gettext("Reserved/not assigned by IANA");?></td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">*</td>
<td class="listr">*</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>
<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>
</tr>
</tbody>
<?php endif; ?>
<tbody id="dragtable">
<?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;
$isadvset = firewall_check_for_advanced_options($filterent);
if($isadvset)
$advanced_set = "<span class=\"glyphicon glypicon-cog\" title=\"" . gettext("advanced settings set") . ": {$isadvset}\"></span>";
else
$advanced_set = "";
?>
<tr valign="top" id="fr<?=$nrules;?>">
<td class="listt">
<input type="checkbox" id="frc<?=$nrules;?>" name="rule[]" value="<?=$i;?>" />
<?php echo $advanced_set; ?>
</td>
<td class="listt" align="center">
<?php
if ($filterent['type'] == "block") {
$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";
$textss = ""; }
else {
$iconfn = "glyphicon-play";
$textss = "text-success"; }
if (isset($filterent['disabled'])) {
$textss = $textse = "text-muted";
} else {
//$textss = $textse = "";
$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
$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'])) {
switch($filterent['ipprotocol']) {
case "inet":
echo "IPv4 ";
break;
case "inet6":
echo "IPv6 ";
break;
case "inet46":
echo "IPv4+6 ";
break;
}
} else {
echo "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>';
echo $filterent['icmptype'];
echo '</u></span>';
}
} else echo "*";
?>
</span>
</td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<span class="<?=$textse;?>"><?php echo $alias_src_span_begin;?><?php echo htmlspecialchars(pprint_address($filterent['source']));?><?php echo $alias_src_span_end;?></span>
</td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<span class="<?=$textse;?>"><?php echo htmlspecialchars(pprint_port($filterent['source']['port'])); ?></span>
</td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<span class="<?=$textse;?>"><?php echo htmlspecialchars(pprint_address($filterent['destination'])); ?></span>
</td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<span class="<?=$textse;?>"><?php echo htmlspecialchars(pprint_port($filterent['destination']['port'])); ?></span>
</td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<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>
</td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<span class="<?=$textse;?>"><?=gettext('none');?></span>
</td>
<td class="listr" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';"><font color="black">
<?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>
</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 valign="middle" class="list nowrap">
<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 href="firewall_rules_edit.php?id=<?=$i;?>" title="<?=gettext("edit rule"); ?>" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></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?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>
</td>
</tr>
<?php $nrules++; endfor; ?>
</tbody>
<?php if ($nrules == 0): ?>
<tr>
<td class="listt"></td>
<td class="listt"></td>
<td class="listlr" colspan="11" align="center" valign="middle">
<span class="gray">
<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
<?=gettext("No floating rules are currently defined."); ?><br /><br />
<?php else: ?>
<?=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 />
<?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>
</td>
</tr>
<?php endif; ?>
<tr id="fr<?=$nrules;?>">
<td class="list"></td>
<td class="list"></td>
<td class="list">&nbsp;</td>
<td class="list">&nbsp;</td>
<td class="list">&nbsp;</td>
<td class="list">&nbsp;</td>
<td class="list">&nbsp;</td>
<td class="list">&nbsp;</td>
<td class="list">&nbsp;</td>
<td class="list">&nbsp;</td>
<td class="list">&nbsp;</td>
<td class="list">
<?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>
</tr>
</tbody>
</table>
<div class="container-fluid">
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="icons">
<tr>
<td width="16"><span class="glyphicon glyphicon-play text-success"></span></td>
<td width="100"><?=gettext("pass");?></td>
<td width="14"></td>
<td width="16"><span class="glyphicon glyphicon-ok"></span></td>
<td width="100"><?=gettext("match");?></td>
<td width="14"></td>
<td width="16"><span class="glyphicon glyphicon-remove text-danger"></span></td>
<td width="100"><?=gettext("block");?></td>
<td width="14"></td>
<td width="16"><span class="glyphicon glyphicon-remove text-warning"></span></td>
<td width="100"><?=gettext("reject");?></td>
<td width="14"></td>
<td width="16"><span class="glyphicon glyphicon-info-sign"></span></td>
<td width="100"><?=gettext("log");?></td>
</tr>
<tr>
<td><span class="glyphicon glyphicon-play text-muted"></span></td>
<td class="nowrap"><?=gettext("pass (disabled)");?></td>
<td>&nbsp;</td>
<td><span class="glyphicon glyphicon-ok text-muted"></span></td>
<td class="nowrap"><?=gettext("match (disabled)");?></td>
<td>&nbsp;</td>
<td><span class="glyphicon glyphicon-remove text-muted"></span></td>
<td class="nowrap"><?=gettext("block (disabled)");?></td>
<td>&nbsp;</td>
<td><span class="glyphicon glyphicon-remove text-muted"></span></td>
<td class="nowrap"><?=gettext("reject (disabled)");?></td>
<td>&nbsp;</td>
<td width="16"><span class="glyphicon glyphicon-info-sign text-muted"></span></td>
<td class="nowrap"><?=gettext("log (disabled)");?></td>
</tr>
<tr>
<td colspan="10">
<p>&nbsp;</p>
<strong>
<span class="red"><?=gettext("Hint:");?></span>
</strong><br />
<ul>
<?php if ("FloatingRules" != $if): ?>
<li><?=gettext("Rules are evaluated on a first-match basis (i.e. " .
"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 " .
"to the rule order. Everything that isn't explicitly passed is blocked " .
"by default. ");?>
</li>
<?php else: ?>
<li><?=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 " .
"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 " .
"chosen. If no rule here matches, the per-interface or default rules are used. ");?>
</li>
<?php endif; ?>
</ul>
</td>
</tr>
</table>
</div>
</div>
</form>
</div>
</section>
</div>
</div>
</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>
?>
<tr ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
<td>
<input type="checkbox" name="rule[]" value="<?=$i;?>" />
</td>
<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>
<?php
else:?>
<?= isset($filterent['protocol']) ? strtoupper($filterent['protocol']) : "*";?>
<?php
endif;?>
</td>
<td>
<?=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 class="hidden-xs hidden-sm">
<?=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 class="hidden-xs hidden-sm">
<?=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 class="hidden-xs hidden-sm">
<?=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 class="hidden-xs hidden-sm">
<?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 class="hidden-xs hidden-sm">
<?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>
<?=htmlspecialchars($filterent['descr']);?>
</td>
<td>
<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">
<span class="glyphicon glyphicon-arrow-left"></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">
<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>
</tr>
<?php
endif;
endforeach;
if (!$interface_has_rules):
?>
<tr>
<td colspan="11" align="center" valign="middle">
<span class="gray">
<?php if ($selected_if == "FloatingRules"): ?>
<?=gettext("No floating rules are currently defined."); ?><br /><br />
<?php else: ?>
<?=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 />
<?php endif; ?>
<?=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>
</tr>
<?php else: ?>
<tr>
<td colspan="5"></td>
<td colspan="5" class="hidden-xs hidden-sm"></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 id="del_x" title="<?=gettext("delete selected rules"); ?>" data-toggle="tooltip" class="act_delete btn btn-default btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</a>
<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");?>">
<span class="glyphicon glyphicon-plus"></span>
</a>
</td>
</tr>
<?php endif; ?>
</tbody>
<tfoot>
<tr>
<td colspan="11">&nbsp;</td>
</tr>
<tr class="hidden-xs hidden-sm">
<td colspan="11">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16"><span class="glyphicon glyphicon-play text-success"></span></td>
<td width="100"><?=gettext("pass");?></td>
<td width="14"></td>
<td width="16"><span class="glyphicon glyphicon-ok"></span></td>
<td width="100"><?=gettext("match");?></td>
<td width="14"></td>
<td width="16"><span class="glyphicon glyphicon-remove text-danger"></span></td>
<td width="100"><?=gettext("block");?></td>
<td width="14"></td>
<td width="16"><span class="glyphicon glyphicon-remove text-warning"></span></td>
<td width="100"><?=gettext("reject");?></td>
<td width="14"></td>
<td width="16"><span class="glyphicon glyphicon-info-sign"></span></td>
<td width="100"><?=gettext("log");?></td>
</tr>
<tr>
<td><span class="glyphicon glyphicon-play text-muted"></span></td>
<td class="nowrap"><?=gettext("pass (disabled)");?></td>
<td>&nbsp;</td>
<td><span class="glyphicon glyphicon-ok text-muted"></span></td>
<td class="nowrap"><?=gettext("match (disabled)");?></td>
<td>&nbsp;</td>
<td><span class="glyphicon glyphicon-remove text-muted"></span></td>
<td class="nowrap"><?=gettext("block (disabled)");?></td>
<td>&nbsp;</td>
<td><span class="glyphicon glyphicon-remove text-muted"></span></td>
<td class="nowrap"><?=gettext("reject (disabled)");?></td>
<td>&nbsp;</td>
<td width="16"><span class="glyphicon glyphicon-info-sign text-muted"></span></td>
<td class="nowrap"><?=gettext("log (disabled)");?></td>
</tr>
</table>
</td>
</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>
<span class="text-danger"><?=gettext("Hint:");?></span>
</strong>
<br />
<?php if ("FloatingRules" != $selected_if): ?>
<?=gettext("Rules are evaluated on a first-match basis (i.e. " .
"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 " .
"to the rule order. Everything that isn't explicitly passed is blocked " .
"by default. ");?>
<?php else: ?>
<?=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 " .
"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 " .
"chosen. If no rule here matches, the per-interface or default rules are used. ");?>
<?php endif; ?>
</td>
</tr>
</tfoot>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2004 Scott Ullrich
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2004 Scott Ullrich
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("filter.inc");
$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'));
$pgtitle = array(gettext("Firewall"),gettext("Schedules"));
if (!is_array($config['schedules']['schedule']))
$config['schedules']['schedule'] = array();
if (!isset($config['schedules']['schedule'])) {
$config['schedules']['schedule'] = array();
}
$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 (isset($pconfig['act']) && $pconfig['act'] == 'del' && isset($id)) {
/* make sure rule is not being referenced by filter rule */
$referenced_by = false;
if(isset($config['filter']['rule'])) {
foreach($config['filter']['rule'] as $rule) {
//check for this later once this is established
if ($rule['sched'] == $a_schedules[$id]['name']){
$referenced_by = $rule['descr'];
break;
}
}
}
if( $referenced_by !== false) {
$savemsg = sprintf(gettext("Cannot delete Schedule. Currently in use by %s"),$referenced_by);
} else {
unset($a_schedules[$id]);
write_config();
header("Location: firewall_schedule.php");
exit;
}
}
if ($_GET['act'] == "del") {
if ($a_schedules[$_GET['id']]) {
/* make sure rule is not being referenced by any nat or filter rules */
$is_schedule_referenced = false;
$referenced_by = false;
$schedule_name = $a_schedules[$_GET['id']]['name'];
if(is_array($config['filter']['rule'])) {
foreach($config['filter']['rule'] as $rule) {
//check for this later once this is established
if ($rule['sched'] == $schedule_name){
$referenced_by = $rule['descr'];
$is_schedule_referenced = true;
break;
}
}
}
if($is_schedule_referenced == true) {
$savemsg = sprintf(gettext("Cannot delete Schedule. Currently in use by %s"),$referenced_by);
} else {
unset($a_schedules[$_GET['id']]);
write_config();
header("Location: firewall_schedule.php");
exit;
}
}
}
include("head.inc");
legacy_html_escape_form_data($a_schedules);
$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>
<?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>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<section class="col-xs-12">
<div class="content-box">
<div class="content-box-main ">
<form action="firewall_schedule.php" method="post" name="iform" id="iform">
<div class="table-responsive">
<table class="table table-striped table-sort">
<thead>
<tr>
<td width="25%" class="listhdrr"><?=gettext("Name");?></td>
<td width="35%" class="listhdrr"><?=gettext("Time Range(s)");?></td>
<td width="35%" class="listhdr"><?=gettext("Description");?></td>
<td width="5%" class="list sort_ignore">
</td>
</tr>
</thead>
<tbody>
<?php $i = 0; foreach ($a_schedules as $schedule): ?>
<tr>
<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
<?=htmlspecialchars($schedule['name']);?>
<?php
$schedstatus = filter_get_time_based_rule_status($schedule);
if ($schedstatus) { ?>
&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 } ?>
</td>
<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
<table width="98%" border="0" cellpadding="0" cellspacing="0" summary="schedule">
<?php
foreach($schedule['timerange'] as $timerange) {
$tempFriendlyTime = "";
$tempID = "";
$firstprint = false;
if ($timerange){
$dayFriendly = "";
$tempFriendlyTime = "";
//get hours
$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 .= "<br />";
$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 .= "<br />";
$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'];
?><tr><td><?=$dayFriendly;?></td><td><?=$timeFriendly;?></td><td><?=$description;?></td></tr><?php
}
}//end for?></table>
</td>
<td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
<?=htmlspecialchars($schedule['descr']);?>&nbsp;
</td>
<td valign="middle" class="list nowrap">
<table border="0" cellspacing="0" cellpadding="1" summary="buttons">
<tr>
<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>
<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>
</tr>
</table>
</td>
</tr>
<?php $i++; endforeach; ?>
</tbody>
</table>
</div>
<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>
</div>
</form>
</div>
</div>
</section>
</div>
</div>
</section>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<section class="col-xs-12">
<div class="content-box content-box-main ">
<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">
<table class="table table-striped">
<thead>
<tr>
<td><?=gettext("Name");?></td>
<td><?=gettext("Time Range(s)");?></td>
<td><?=gettext("Description");?></td>
<td></td>
</tr>
</thead>
<tbody>
<?php $i = 0; foreach ($a_schedules as $schedule): ?>
<tr ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
<td>
<?=$schedule['name'];?>
<?php
if (filter_get_time_based_rule_status($schedule)):?>
<span data-toggle="tooltip" title="<?=gettext("Schedule is currently active");?>" class="fa fa-clock-o"></span>
<?php
endif;?>
</td>
<td>
<table class="table table-condensed table-striped">
<?php
foreach($schedule['timerange'] as $timerange) {
$firstprint = false;
if ($timerange){
$dayFriendly = "";
//get hours
$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 .= "<br />";
$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 .= "<br />";
$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'];
?><tr><td><?=$dayFriendly;?></td><td><?=$timeFriendly;?></td><td><?=$description;?></td></tr><?php
}
}//end for?></table>
</td>
<td>
<?=$schedule['descr'];?>
</td>
<td>
<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">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<a id="del_<?=$i;?>" title="<?=gettext("delete this schedule"); ?>" data-toggle="tooltip" class="act_delete btn btn-default btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</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>
</tr>
<?php
$i++;
endforeach; ?>
</tbody>
</table>
</div>
<div class="container-fluid">
<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>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2004 Scott Ullrich
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2004 Scott Ullrich
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
......@@ -63,172 +63,158 @@ function is_schedule_inuse($schedule)
function schedulecmp($a, $b) {
return strcmp($a['name'], $b['name']);
return strcmp($a['name'], $b['name']);
}
function schedule_sort(){
global $g, $config;
global $g, $config;
if (!is_array($config['schedules']['schedule']))
return;
if (!is_array($config['schedules']['schedule']))
return;
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'));
$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'];
if (is_numericint($_GET['id']))
$id = $_GET['id'];
if (isset($_POST['id']) && is_numericint($_POST['id']))
$id = $_POST['id'];
if (isset($id) && $a_schedules[$id]) {
$pconfig['name'] = $a_schedules[$id]['name'];
$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
$pconfig['timerange'] = $a_schedules[$id]['timerange'];
$pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
$getSchedule = true;
}
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'];
$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'];
}
$pconfig = $_POST;
// validate
if(strtolower($pconfig['name']) == "lan")
$input_errors[] = gettext("Schedule may not be named LAN.");
if(strtolower($pconfig['name']) == "wan")
$input_errors[] = gettext("Schedule may not be named WAN.");
if(strtolower($pconfig['name']) == "")
$input_errors[] = gettext("Schedule name cannot be blank.");
$x = is_validaliasname($pconfig['name']);
if (!isset($x)) {
$input_errors[] = gettext("Reserved word used for schedule name.");
} elseif ($x == false) {
$input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9");
}
/* check for name conflicts */
foreach ($a_schedules as $schedId => $schedule) {
if ( $schedId != $id && $schedule['name'] == $pconfig['name']) {
$input_errors[] = gettext("A Schedule with this name already exists.");
break;
}
}
// parse time ranges
$pconfig['timerange'] = array();
if ($_POST) {
if(strtolower($_POST['name']) == "lan")
$input_errors[] = gettext("Schedule may not be named LAN.");
if(strtolower($_POST['name']) == "wan")
$input_errors[] = gettext("Schedule may not be named WAN.");
if(strtolower($_POST['name']) == "")
$input_errors[] = gettext("Schedule name cannot be blank.");
$x = is_validaliasname($_POST['name']);
if (!isset($x)) {
$input_errors[] = gettext("Reserved word used for schedule name.");
} else {
if (is_validaliasname($_POST['name']) == false)
$input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9");
}
/* check for name conflicts */
foreach ($a_schedules as $schedule) {
if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule))
continue;
if ($schedule['name'] == $_POST['name']) {
$input_errors[] = gettext("A Schedule with this name already exists.");
break;
}
}
$schedule = array();
$schedule['name'] = $_POST['name'];
$schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');
$timerangeFound = false;
for ($x=0; $x<99; $x++){
if($_POST['schedule' . $x]) {
if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['starttime' . $x])) {
$input_errors[] = sprintf(gettext("Invalid start time - '%s'"), $_POST['starttime' . $x]);
continue;
}
if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['stoptime' . $x])) {
$input_errors[] = sprintf(gettext("Invalid stop time - '%s'"), $_POST['stoptime' . $x]);
continue;
}
$timerangeFound = true;
$timeparts = array();
$firstprint = false;
$timestr = $_POST['schedule' . $x];
$timehourstr = $_POST['starttime' . $x];
$timehourstr .= "-";
$timehourstr .= $_POST['stoptime' . $x];
$timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8');
$dashpos = strpos($timestr, '-');
if ($dashpos === false)
{
$timeparts['position'] = $timestr;
}
else
{
$tempindarray = array();
$monthstr = "";
$daystr = "";
$tempindarray = explode(",", $timestr);
foreach ($tempindarray as $currentselection)
{
if ($currentselection){
if ($firstprint)
{
$monthstr .= ",";
$daystr .= ",";
}
$tempstr = "";
$monthpos = strpos($currentselection, "m");
$daypos = strpos($currentselection, "d");
$monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1);
$daystr .= substr($currentselection, $daypos+1);
$firstprint = true;
}
}
$timeparts['month'] = $monthstr;
$timeparts['day'] = $daystr;
}
$timeparts['hour'] = $timehourstr;
$timeparts['rangedescr'] = $timedescrstr;
$schedule['timerange'][$x] = $timeparts;
}
}
if (!$timerangeFound)
$input_errors[] = gettext("The schedule must have at least one time range configured.");
if (!$input_errors) {
if (!empty($pconfig['schedlabel']))
$schedule['schedlabel'] = $pconfig['schedlabel'];
else
$schedule['schedlabel'] = uniqid();
if (isset($id) && $a_schedules[$id]){
$a_schedules[$id] = $schedule;
}
else{
$a_schedules[] = $schedule;
}
schedule_sort();
if (write_config())
filter_configure();
header("Location: firewall_schedule.php");
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'];
}
$timerangeFound = false;
for ($x=0; $x<99; $x++){
if($pconfig['schedule' . $x]) {
if (!preg_match('/^[0-9]+:[0-9]+$/', $pconfig['starttime' . $x])) {
$input_errors[] = sprintf(gettext("Invalid start time - '%s'"), $pconfig['starttime' . $x]);
continue;
}
if (!preg_match('/^[0-9]+:[0-9]+$/', $pconfig['stoptime' . $x])) {
$input_errors[] = sprintf(gettext("Invalid stop time - '%s'"), $pconfig['stoptime' . $x]);
continue;
}
$timerangeFound = true;
$timeparts = array();
$firstprint = false;
$timestr = $pconfig['schedule' . $x];
$timehourstr = $pconfig['starttime' . $x];
$timehourstr .= "-";
$timehourstr .= $pconfig['stoptime' . $x];
$timedescrstr = htmlentities($pconfig['timedescr' . $x], ENT_QUOTES, 'UTF-8');
$dashpos = strpos($timestr, '-');
if ($dashpos === false) {
$timeparts['position'] = $timestr;
} else {
$tempindarray = array();
$monthstr = "";
$daystr = "";
$tempindarray = explode(",", $timestr);
foreach ($tempindarray as $currentselection) {
if ($currentselection){
if ($firstprint) {
$monthstr .= ",";
$daystr .= ",";
}
$tempstr = "";
$monthpos = strpos($currentselection, "m");
$daypos = strpos($currentselection, "d");
$monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1);
$daystr .= substr($currentselection, $daypos+1);
$firstprint = true;
}
}
$timeparts['month'] = $monthstr;
$timeparts['day'] = $daystr;
}
$timeparts['hour'] = $timehourstr;
$timeparts['rangedescr'] = $timedescrstr;
$pconfig['timerange'][$x] = $timeparts;
}
}
if (count($pconfig['timerange']) == 0) {
$input_errors[] = gettext("The schedule must have at least one time range configured.");
}
if (count($input_errors) == 0) {
$schedule = array();
$schedule['name'] = $pconfig['name'];
$schedule['descr'] = $pconfig['descr'];
$schedule['timerange'] = $pconfig['timerange'];
$schedule['schedlabel'] = $pconfig['schedlabel'];
if (isset($id)) {
$a_schedules[$id] = $schedule;
} else {
$a_schedules[] = $schedule;
}
schedule_sort();
if (write_config()) {
filter_configure();
}
header("Location: firewall_schedule.php");
exit;
}
}
include("head.inc");
/* put your custom HTML head content here */
/* using some of the new function calls */
$jscriptstr = <<<EOD
$pgtitle = array(gettext("Firewall"),gettext("Schedules"),gettext("Edit"));
legacy_html_escape_form_data($pconfig);
include("head.inc");
?>
<script type="text/javascript">
//<![CDATA[
var daysSelected = "";
......@@ -237,988 +223,955 @@ var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
var schCounter = 0;
function rgb2hex(rgb) {
var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
if (parts == null)
return;
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return ("#" + hex(parts[1]) + hex(parts[2]) + hex(parts[3])).toUpperCase();
var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
if (parts == null)
return;
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return ("#" + hex(parts[1]) + hex(parts[2]) + hex(parts[3])).toUpperCase();
}
function repeatExistingDays(){
var tempstr, tempstrdaypos, week, daypos, dayposdone = "";
var dayarray = daysSelected.split(",");
for (i=0; i<=dayarray.length; i++){
tempstr = dayarray[i];
tempstrdaypos = tempstr.search("p");
week = tempstr.substring(1,tempstrdaypos);
week = parseInt(week);
dashpos = tempstr.search("-");
daypos = tempstr.substring(tempstrdaypos+1, dashpos);
daypos = parseInt(daypos);
daydone = dayposdone.search(daypos);
tempstr = 'w' + week + 'p' + daypos;
daycell = eval('document.getElementById(tempstr)');
if (daydone == "-1"){
if (rgb2hex(daycell.style.backgroundColor) == "#F08080") // lightcoral
daytogglerepeating(week,daypos,true);
else
daytogglerepeating(week,daypos,false);
dayposdone += daypos + ",";
}
}
var tempstr, tempstrdaypos, week, daypos, dayposdone = "";
var dayarray = daysSelected.split(",");
for (i=0; i<=dayarray.length; i++){
tempstr = dayarray[i];
tempstrdaypos = tempstr.search("p");
week = tempstr.substring(1,tempstrdaypos);
week = parseInt(week);
dashpos = tempstr.search("-");
daypos = tempstr.substring(tempstrdaypos+1, dashpos);
daypos = parseInt(daypos);
daydone = dayposdone.search(daypos);
tempstr = 'w' + week + 'p' + daypos;
daycell = eval('document.getElementById(tempstr)');
if (daydone == "-1"){
if (rgb2hex(daycell.style.backgroundColor) == "#F08080") // lightcoral
daytogglerepeating(week,daypos,true);
else
daytogglerepeating(week,daypos,false);
dayposdone += daypos + ",";
}
}
}
function daytogglerepeating(week,daypos,bExists){
var tempstr, daycell, dayoriginal = "";
for (j=1; j<=53; j++)
{
tempstr = 'w' + j + 'p' + daypos;
daycell = eval('document.getElementById(tempstr)');
dayoriginalpos = daysSelected.indexOf(tempstr);
//if bExists set to true, means cell is already select it
//unselect it and remove original day from daysSelected string
if (daycell != null)
{
if (bExists){
daycell.style.backgroundColor = "#FFFFFF"; // white
}
else
{
daycell.style.backgroundColor = "#F08080"; // lightcoral
}
if (dayoriginalpos != "-1")
{
dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
daysSelected = daysSelected.replace(tempstr, "");
}
}
}
var tempstr, daycell, dayoriginal = "";
for (j=1; j<=53; j++)
{
tempstr = 'w' + j + 'p' + daypos;
daycell = eval('document.getElementById(tempstr)');
dayoriginalpos = daysSelected.indexOf(tempstr);
//if bExists set to true, means cell is already select it
//unselect it and remove original day from daysSelected string
if (daycell != null)
{
if (bExists){
daycell.style.backgroundColor = "#FFFFFF"; // white
}
else
{
daycell.style.backgroundColor = "#F08080"; // lightcoral
}
if (dayoriginalpos != "-1")
{
dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
daysSelected = daysSelected.replace(tempstr, "");
}
}
}
}
function daytoggle(id) {
var runrepeat, tempstr = "";
var bFoundValid = false;
iddashpos = id.search("-");
var tempstrdaypos = id.search("p");
var week = id.substring(1,tempstrdaypos);
week = parseInt(week);
if (iddashpos == "-1")
{
idmod = id;
runrepeat = true;
var daypos = id.substr(tempstrdaypos+1);
}
else
{
idmod = id.substring(0,iddashpos);
var daypos = id.substring(tempstrdaypos+1,iddashpos);
}
daypos = parseInt(daypos);
while (!bFoundValid){
var daycell = document.getElementById(idmod);
if (daycell != null){
if (rgb2hex(daycell.style.backgroundColor) == "#FF0000"){ // red
daycell.style.backgroundColor = "#FFFFFF"; // white
str = id + ",";
daysSelected = daysSelected.replace(str, "");
}
else if (rgb2hex(daycell.style.backgroundColor) == "#F08080") // lightcoral
{
daytogglerepeating(week,daypos,true);
}
else //color is white cell
{
if (!runrepeat)
{
daycell.style.backgroundColor = "#FF0000"; // red
}
else
{
daycell.style.backgroundColor = "#F08080"; // lightcoral
daytogglerepeating(week,daypos,false);
}
daysSelected += id + ",";
}
bFoundValid = true;
}
else
{
//we found an invalid cell when column was clicked, move up to the next week
week++;
tempstr = "w" + week + "p" + daypos;
idmod = tempstr;
}
}
var runrepeat, tempstr = "";
var bFoundValid = false;
iddashpos = id.search("-");
var tempstrdaypos = id.search("p");
var week = id.substring(1,tempstrdaypos);
week = parseInt(week);
if (iddashpos == "-1")
{
idmod = id;
runrepeat = true;
var daypos = id.substr(tempstrdaypos+1);
}
else
{
idmod = id.substring(0,iddashpos);
var daypos = id.substring(tempstrdaypos+1,iddashpos);
}
daypos = parseInt(daypos);
while (!bFoundValid){
var daycell = document.getElementById(idmod);
if (daycell != null){
if (rgb2hex(daycell.style.backgroundColor) == "#FF0000"){ // red
daycell.style.backgroundColor = "#FFFFFF"; // white
str = id + ",";
daysSelected = daysSelected.replace(str, "");
}
else if (rgb2hex(daycell.style.backgroundColor) == "#F08080") // lightcoral
{
daytogglerepeating(week,daypos,true);
}
else //color is white cell
{
if (!runrepeat)
{
daycell.style.backgroundColor = "#FF0000"; // red
}
else
{
daycell.style.backgroundColor = "#F08080"; // lightcoral
daytogglerepeating(week,daypos,false);
}
daysSelected += id + ",";
}
bFoundValid = true;
}
else
{
//we found an invalid cell when column was clicked, move up to the next week
week++;
tempstr = "w" + week + "p" + daypos;
idmod = tempstr;
}
}
}
function update_month(){
var indexNum = document.forms[0].monthsel.selectedIndex;
var selected = document.forms[0].monthsel.options[indexNum].text;
for (i=0; i<=11; i++){
option = document.forms[0].monthsel.options[i].text;
document.popupMonthLayer = eval('document.getElementById (option)');
if(selected == option) {
document.popupMonthLayer.style.display="block";
}
else
document.popupMonthLayer.style.display="none";
}
var indexNum = document.iform.monthsel.selectedIndex;
var selected = document.iform.monthsel.options[indexNum].text;
for (i=0; i<=11; i++){
option = document.iform.monthsel.options[i].text;
document.popupMonthLayer = eval('document.getElementById (option)');
if(selected == option) {
document.popupMonthLayer.style.display="block";
}
else
document.popupMonthLayer.style.display="none";
}
}
function checkForRanges(){
if (daysSelected != "")
{
alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
return false;
}
else
{
return true;
}
if (daysSelected != "")
{
alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
return false;
}
else
{
return true;
}
}
function processEntries(){
var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
var passedValidiation = true;
//get time specified
starttimehour = parseInt(document.getElementById("starttimehour").value);
starttimemin = parseInt(document.getElementById("starttimemin").value);
stoptimehour = parseInt(document.getElementById("stoptimehour").value);
stoptimemin = parseInt(document.getElementById("stoptimemin").value);
//do time checks
if (starttimehour > stoptimehour)
{
errors = "Error: Start Hour cannot be greater than Stop Hour.";
passedValidiation = false;
}
else if (starttimehour == stoptimehour)
{
if (starttimemin > stoptimemin){
errors = "Error: Start Minute cannot be greater than Stop Minute.";
passedValidiation = false;
}
}
if (passedValidiation){
addTimeRange();
}
else {
if (errors != "")
alert(errors);
}
var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
var passedValidiation = true;
//get time specified
starttimehour = parseInt(document.getElementById("starttimehour").value);
starttimemin = parseInt(document.getElementById("starttimemin").value);
stoptimehour = parseInt(document.getElementById("stoptimehour").value);
stoptimemin = parseInt(document.getElementById("stoptimemin").value);
//do time checks
if (starttimehour > stoptimehour)
{
errors = "Error: Start Hour cannot be greater than Stop Hour.";
passedValidiation = false;
}
else if (starttimehour == stoptimehour)
{
if (starttimemin > stoptimemin){
errors = "Error: Start Minute cannot be greater than Stop Minute.";
passedValidiation = false;
}
}
if (passedValidiation){
addTimeRange();
}
else {
if (errors != "")
alert(errors);
}
}
function addTimeRange(){
var tempdayarray = daysSelected.split(",");
var tempstr, tempFriendlyDay, starttimehour, starttimemin, stoptimehour, nrtempFriendlyTime, rtempFriendlyTime, nrtempID, rtempID = "";
var stoptimemin, timeRange, tempstrdaypos, week, daypos, day, month, dashpos, nrtempTime, rtempTime, monthstr, daystr = "";
rtempFriendlyTime = "";
nrtempFriendlyTime = "";
nrtempID = "";
rtempID = "";
nrtempTime = "";
rtempTime = "";
tempdayarray.sort();
rtempFriendlyDay = "";
monthstr = "";
daystr = "";
//check for existing entries
var findCurrentCounter;
for (u=0; u<99; u++){
findCurrentCounter = document.getElementById("schedule" + u);
if (!findCurrentCounter)
{
schCounter = u;
break;
}
}
if (daysSelected != ""){
//get days selected
for (i=0; i<tempdayarray.length; i++)
{
tempstr = tempdayarray[i];
if (tempstr != "")
{
tempstrdaypos = tempstr.search("p");
week = tempstr.substring(1,tempstrdaypos);
week = parseInt(week);
dashpos = tempstr.search("-");
if (dashpos != "-1")
{
var nonrepeatingfound = true;
daypos = tempstr.substring(tempstrdaypos+1, dashpos);
daypos = parseInt(daypos);
monthpos = tempstr.search("m");
tempstrdaypos = tempstr.search("d");
month = tempstr.substring(monthpos+1, tempstrdaypos);
month = parseInt(month);
day = tempstr.substring(tempstrdaypos+1);
day = parseInt(day);
monthstr += month + ",";
daystr += day + ",";
nrtempID += tempstr + ",";
}
else
{
var repeatingfound = true;
daypos = tempstr.substr(tempstrdaypos+1);
daypos = parseInt(daypos);
rtempFriendlyDay += daypos + ",";
rtempID += daypos + ",";
}
}
}
//code below spits out friendly look format for nonrepeating schedules
var foundEnd = false;
var firstDayFound = false;
var firstprint = false;
var tempFriendlyMonthArray = monthstr.split(",");
var tempFriendlyDayArray = daystr.split(",");
var currentDay, firstDay, nextDay, currentMonth, nextMonth, firstDay, firstMonth = "";
for (k=0; k<tempFriendlyMonthArray.length; k++){
tempstr = tempFriendlyMonthArray[k];
if (tempstr != ""){
if (!firstDayFound)
{
firstDay = tempFriendlyDayArray[k];
firstDay = parseInt(firstDay);
firstMonth = tempFriendlyMonthArray[k];
firstMonth = parseInt(firstMonth);
firstDayFound = true;
}
currentDay = tempFriendlyDayArray[k];
currentDay = parseInt(currentDay);
//get next day
nextDay = tempFriendlyDayArray[k+1];
nextDay = parseInt(nextDay);
//get next month
currentDay++;
if ((currentDay != nextDay) || (tempFriendlyMonthArray[k] != tempFriendlyMonthArray[k+1])){
if (firstprint)
nrtempFriendlyTime += ", ";
currentDay--;
if (currentDay != firstDay)
nrtempFriendlyTime += month_array[firstMonth-1] + " " + firstDay + "-" + currentDay;
else
nrtempFriendlyTime += month_array[firstMonth-1] + " " + currentDay;
firstDayFound = false;
firstprint = true;
}
}
}
//code below spits out friendly look format for repeating schedules
foundEnd = false;
firstDayFound = false;
firstprint = false;
tempFriendlyDayArray = rtempFriendlyDay.split(",");
tempFriendlyDayArray.sort();
currentDay, firstDay, nextDay = "";
for (k=0; k<tempFriendlyDayArray.length; k++){
tempstr = tempFriendlyDayArray[k];
if (tempstr != ""){
if (!firstDayFound)
{
firstDay = tempFriendlyDayArray[k];
firstDay = parseInt(firstDay);
firstDayFound = true;
}
currentDay = tempFriendlyDayArray[k];
currentDay = parseInt(currentDay);
//get next day
nextDay = tempFriendlyDayArray[k+1];
nextDay = parseInt(nextDay);
currentDay++;
if (currentDay != nextDay){
if (firstprint)
rtempFriendlyTime += ", ";
currentDay--;
if (currentDay != firstDay)
rtempFriendlyTime += day_array[firstDay-1] + " - " + day_array[currentDay-1];
else
rtempFriendlyTime += day_array[firstDay-1];
firstDayFound = false;
firstprint = true;
}
}
}
//sort the tempID
var tempsortArray = rtempID.split(",");
var isFirstdone = false;
tempsortArray.sort();
//clear tempID
rtempID = "";
for (t=0; t<tempsortArray.length; t++)
{
if (tempsortArray[t] != ""){
if (!isFirstdone){
rtempID += tempsortArray[t];
isFirstdone = true;
}
else
rtempID += "," + tempsortArray[t];
}
}
//get time specified
starttimehour = document.getElementById("starttimehour").value
starttimemin = document.getElementById("starttimemin").value;
stoptimehour = document.getElementById("stoptimehour").value;
stoptimemin = document.getElementById("stoptimemin").value;
timeRange = "||" + starttimehour + ":";
timeRange += starttimemin + "-";
timeRange += stoptimehour + ":";
timeRange += stoptimemin;
//get description for time range
var tempdescr = document.getElementById("timerangedescr").value
if (nonrepeatingfound){
nrtempTime += nrtempID;
//add time ranges
nrtempTime += timeRange;
//add description
nrtempTime += "||" + tempdescr;
insertElements(nrtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, nrtempTime, nrtempID);
}
if (repeatingfound){
rtempTime += rtempID;
//add time ranges
rtempTime += timeRange;
//add description
rtempTime += "||" + tempdescr;
insertElements(rtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, rtempTime, rtempID);
}
}
else
{
//no days were selected, alert user
alert ("You must select at least 1 day before adding time");
}
var tempdayarray = daysSelected.split(",");
var tempstr, tempFriendlyDay, starttimehour, starttimemin, stoptimehour, nrtempFriendlyTime, rtempFriendlyTime, nrtempID, rtempID = "";
var stoptimemin, timeRange, tempstrdaypos, week, daypos, day, month, dashpos, nrtempTime, rtempTime, monthstr, daystr = "";
rtempFriendlyTime = "";
nrtempFriendlyTime = "";
nrtempID = "";
rtempID = "";
nrtempTime = "";
rtempTime = "";
tempdayarray.sort();
rtempFriendlyDay = "";
monthstr = "";
daystr = "";
//check for existing entries
var findCurrentCounter;
for (u=0; u<99; u++){
findCurrentCounter = document.getElementById("schedule" + u);
if (!findCurrentCounter)
{
schCounter = u;
break;
}
}
if (daysSelected != ""){
//get days selected
for (i=0; i<tempdayarray.length; i++)
{
tempstr = tempdayarray[i];
if (tempstr != "")
{
tempstrdaypos = tempstr.search("p");
week = tempstr.substring(1,tempstrdaypos);
week = parseInt(week);
dashpos = tempstr.search("-");
if (dashpos != "-1")
{
var nonrepeatingfound = true;
daypos = tempstr.substring(tempstrdaypos+1, dashpos);
daypos = parseInt(daypos);
monthpos = tempstr.search("m");
tempstrdaypos = tempstr.search("d");
month = tempstr.substring(monthpos+1, tempstrdaypos);
month = parseInt(month);
day = tempstr.substring(tempstrdaypos+1);
day = parseInt(day);
monthstr += month + ",";
daystr += day + ",";
nrtempID += tempstr + ",";
}
else
{
var repeatingfound = true;
daypos = tempstr.substr(tempstrdaypos+1);
daypos = parseInt(daypos);
rtempFriendlyDay += daypos + ",";
rtempID += daypos + ",";
}
}
}
//code below spits out friendly look format for nonrepeating schedules
var foundEnd = false;
var firstDayFound = false;
var firstprint = false;
var tempFriendlyMonthArray = monthstr.split(",");
var tempFriendlyDayArray = daystr.split(",");
var currentDay, firstDay, nextDay, currentMonth, nextMonth, firstDay, firstMonth = "";
for (k=0; k<tempFriendlyMonthArray.length; k++){
tempstr = tempFriendlyMonthArray[k];
if (tempstr != ""){
if (!firstDayFound)
{
firstDay = tempFriendlyDayArray[k];
firstDay = parseInt(firstDay);
firstMonth = tempFriendlyMonthArray[k];
firstMonth = parseInt(firstMonth);
firstDayFound = true;
}
currentDay = tempFriendlyDayArray[k];
currentDay = parseInt(currentDay);
//get next day
nextDay = tempFriendlyDayArray[k+1];
nextDay = parseInt(nextDay);
//get next month
currentDay++;
if ((currentDay != nextDay) || (tempFriendlyMonthArray[k] != tempFriendlyMonthArray[k+1])){
if (firstprint)
nrtempFriendlyTime += ", ";
currentDay--;
if (currentDay != firstDay)
nrtempFriendlyTime += month_array[firstMonth-1] + " " + firstDay + "-" + currentDay;
else
nrtempFriendlyTime += month_array[firstMonth-1] + " " + currentDay;
firstDayFound = false;
firstprint = true;
}
}
}
//code below spits out friendly look format for repeating schedules
foundEnd = false;
firstDayFound = false;
firstprint = false;
tempFriendlyDayArray = rtempFriendlyDay.split(",");
tempFriendlyDayArray.sort();
currentDay, firstDay, nextDay = "";
for (k=0; k<tempFriendlyDayArray.length; k++){
tempstr = tempFriendlyDayArray[k];
if (tempstr != ""){
if (!firstDayFound)
{
firstDay = tempFriendlyDayArray[k];
firstDay = parseInt(firstDay);
firstDayFound = true;
}
currentDay = tempFriendlyDayArray[k];
currentDay = parseInt(currentDay);
//get next day
nextDay = tempFriendlyDayArray[k+1];
nextDay = parseInt(nextDay);
currentDay++;
if (currentDay != nextDay){
if (firstprint)
rtempFriendlyTime += ", ";
currentDay--;
if (currentDay != firstDay)
rtempFriendlyTime += day_array[firstDay-1] + " - " + day_array[currentDay-1];
else
rtempFriendlyTime += day_array[firstDay-1];
firstDayFound = false;
firstprint = true;
}
}
}
//sort the tempID
var tempsortArray = rtempID.split(",");
var isFirstdone = false;
tempsortArray.sort();
//clear tempID
rtempID = "";
for (t=0; t<tempsortArray.length; t++)
{
if (tempsortArray[t] != ""){
if (!isFirstdone){
rtempID += tempsortArray[t];
isFirstdone = true;
}
else
rtempID += "," + tempsortArray[t];
}
}
//get time specified
starttimehour = document.getElementById("starttimehour").value
starttimemin = document.getElementById("starttimemin").value;
stoptimehour = document.getElementById("stoptimehour").value;
stoptimemin = document.getElementById("stoptimemin").value;
timeRange = "||" + starttimehour + ":";
timeRange += starttimemin + "-";
timeRange += stoptimehour + ":";
timeRange += stoptimemin;
//get description for time range
var tempdescr = document.getElementById("timerangedescr").value
if (nonrepeatingfound){
nrtempTime += nrtempID;
//add time ranges
nrtempTime += timeRange;
//add description
nrtempTime += "||" + tempdescr;
insertElements(nrtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, nrtempTime, nrtempID);
}
if (repeatingfound){
rtempTime += rtempID;
//add time ranges
rtempTime += timeRange;
//add description
rtempTime += "||" + tempdescr;
insertElements(rtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, rtempTime, rtempID);
}
}
else
{
//no days were selected, alert user
alert ("You must select at least 1 day before adding time");
}
}
function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, tempTime, tempID){
//add it to the schedule list
d = document;
tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0);
tr = d.createElement("tr");
td = d.createElement("td");
td.innerHTML= "<span class='vexpl'>" + tempFriendlyTime + "<\/span>";
tr.appendChild(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 + "' />";
tr.appendChild(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 + "' />";
tr.appendChild(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 + "' />";
tr.appendChild(td);
td = d.createElement("td");
td.innerHTML = "<a onclick='editRow(\"" + tempTime + "\",this); return false;' href='#' class=\"btn btn-default btn-xs\"><span class=\"glyphicon glyphicon-pencil\"></span></\a>";
tr.appendChild(td);
td = d.createElement("td");
td.innerHTML = "<a onclick='removeRow(this); return false;' href='#' class=\"btn btn-default btn-xs\"><span class=\"glyphicon glyphicon-remove\"></span></\a>";
tr.appendChild(td);
td = d.createElement("td");
td.innerHTML="<input type='hidden' id='schedule" + schCounter + "' name='schedule" + schCounter + "' value='" + tempID + "' />";
tr.appendChild(td);
tbody.appendChild(tr);
schCounter++;
//reset calendar and time and descr
clearCalendar();
clearTime();
clearDescr();
//add it to the schedule list
d = document;
tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0);
tr = d.createElement("tr");
td = d.createElement("td");
td.innerHTML= "<span class='vexpl'>" + tempFriendlyTime + "<\/span>";
tr.appendChild(td);
td = d.createElement("td");
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);
td = d.createElement("td");
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);
td = d.createElement("td");
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);
td = d.createElement("td");
td.innerHTML = "<a onclick='editRow(\"" + tempTime + "\",this); return false;' href='#' class=\"btn btn-default btn-xs\"><span class=\"glyphicon glyphicon-pencil\"></span></\a>";
tr.appendChild(td);
td = d.createElement("td");
td.innerHTML = "<a onclick='removeRow(this); return false;' href='#' class=\"btn btn-default btn-xs\"><span class=\"glyphicon glyphicon-remove\"></span></\a>";
tr.appendChild(td);
td = d.createElement("td");
td.innerHTML="<input type='hidden' id='schedule" + schCounter + "' name='schedule" + schCounter + "' value='" + tempID + "' />";
tr.appendChild(td);
tbody.appendChild(tr);
schCounter++;
//reset calendar and time and descr
clearCalendar();
clearTime();
clearDescr();
}
function clearCalendar(){
var tempstr, daycell = "";
//clear days selected
daysSelected = "";
//loop through all 52 weeks
for (j=1; j<=53; j++)
{
//loop through all 7 days
for (k=1; k<8; k++){
tempstr = 'w' + j + 'p' + k;
daycell = eval('document.getElementById(tempstr)');
if (daycell != null){
daycell.style.backgroundColor = "#FFFFFF"; // white
}
}
}
var tempstr, daycell = "";
//clear days selected
daysSelected = "";
//loop through all 52 weeks
for (j=1; j<=53; j++)
{
//loop through all 7 days
for (k=1; k<8; k++){
tempstr = 'w' + j + 'p' + k;
daycell = eval('document.getElementById(tempstr)');
if (daycell != null){
daycell.style.backgroundColor = "#FFFFFF"; // white
}
}
}
}
function clearTime(){
document.getElementById("starttimehour").value = "0";
document.getElementById("starttimemin").value = "00";
document.getElementById("stoptimehour").value = "23";
document.getElementById("stoptimemin").value = "59";
document.getElementById("starttimehour").value = "0";
document.getElementById("starttimemin").value = "00";
document.getElementById("stoptimehour").value = "23";
document.getElementById("stoptimemin").value = "59";
}
function clearDescr(){
document.getElementById("timerangedescr").value = "";
document.getElementById("timerangedescr").value = "";
}
function editRow(incTime, el) {
var check = checkForRanges();
if (check){
//reset calendar and time
clearCalendar();
clearTime();
var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = "";
tempArray = incTime.split ("||");
days = tempArray[0];
hours = tempArray[1];
descr = tempArray[2];
var tempdayArray = days.split(",");
var temphourArray = hours.split("-");
tempstr = temphourArray[0];
var temphourArray2 = tempstr.split(":");
document.getElementById("starttimehour").value = temphourArray2[0];
document.getElementById("starttimemin").value = temphourArray2[1];
tempstr = temphourArray[1];
temphourArray2 = tempstr.split(":");
document.getElementById("stoptimehour").value = temphourArray2[0];
document.getElementById("stoptimemin").value = temphourArray2[1];
document.getElementById("timerangedescr").value = descr;
//toggle the appropriate days
for (i=0; i<tempdayArray.length; i++)
{
if (tempdayArray[i]){
var tempweekstr = tempdayArray[i];
dashpos = tempweekstr.search("-");
if (dashpos == "-1")
{
tempstr = "w2p" + tempdayArray[i];
}
else
{
tempstr = tempdayArray[i];
}
daytoggle(tempstr);
}
}
removeRownoprompt(el);
}
var check = checkForRanges();
if (check){
//reset calendar and time
clearCalendar();
clearTime();
var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = "";
tempArray = incTime.split ("||");
days = tempArray[0];
hours = tempArray[1];
descr = tempArray[2];
var tempdayArray = days.split(",");
var temphourArray = hours.split("-");
tempstr = temphourArray[0];
var temphourArray2 = tempstr.split(":");
document.getElementById("starttimehour").value = temphourArray2[0];
document.getElementById("starttimemin").value = temphourArray2[1];
tempstr = temphourArray[1];
temphourArray2 = tempstr.split(":");
document.getElementById("stoptimehour").value = temphourArray2[0];
document.getElementById("stoptimemin").value = temphourArray2[1];
document.getElementById("timerangedescr").value = descr;
//toggle the appropriate days
for (i=0; i<tempdayArray.length; i++)
{
if (tempdayArray[i]){
var tempweekstr = tempdayArray[i];
dashpos = tempweekstr.search("-");
if (dashpos == "-1")
{
tempstr = "w2p" + tempdayArray[i];
}
else
{
tempstr = tempdayArray[i];
}
daytoggle(tempstr);
}
}
removeRownoprompt(el);
}
$('.selectpicker').selectpicker('refresh');
}
function removeRownoprompt(el) {
var cel;
while (el && el.nodeName.toLowerCase() != "tr")
el = el.parentNode;
el = el.parentNode;
if (el && el.parentNode) {
cel = el.getElementsByTagName("td").item(0);
el.parentNode.removeChild(el);
cel = el.getElementsByTagName("td").item(0);
el.parentNode.removeChild(el);
}
}
function removeRow(el) {
var check = confirm ("Do you really want to delete this time range?");
if (check){
var cel;
while (el && el.nodeName.toLowerCase() != "tr")
el = el.parentNode;
if (el && el.parentNode) {
cel = el.getElementsByTagName("td").item(0);
el.parentNode.removeChild(el);
}
}
var check = confirm ("Do you really want to delete this time range?");
if (check){
var cel;
while (el && el.nodeName.toLowerCase() != "tr")
el = el.parentNode;
if (el && el.parentNode) {
cel = el.getElementsByTagName("td").item(0);
el.parentNode.removeChild(el);
}
}
}
//]]>
</script>
EOD;
?>
<body>
<?php include("fbegin.inc"); echo $jscriptstr; ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<div id="inputerrors"></div>
<section class="col-xs-12">
<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">
<div class="table-responsive">
<table class="table table-striped table-sort">
<tbody>
<tr>
<td width="15%" valign="top" class="vncellreq"><?=gettext("Schedule Name");?></td>
<td width="85%" class="vtable">
<?php if(is_schedule_inuse($pconfig['name']) == true): ?>
<input name="name" type="hidden" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
<?php echo $pconfig['name']; ?>
<p>
<span class="vexpl"><?=gettext("NOTE: This schedule is in use so the name may not be modified!");?></span>
</p>
<?php else: ?>
<input name="name" type="text" id="name" size="40" maxlength="40" class="form-control unknown" value="<?=htmlspecialchars($pconfig['name']);?>" /><br />
<span class="vexpl">
<?=gettext("The name of the alias may only consist of the characters a-z, A-Z and 0-9");?>
</span>
<?php endif; ?>
</td>
</tr>
<tr>
<td width="15%" valign="top" class="vncell"><?=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 />
<span class="vexpl">
<?=gettext("You may enter a description here for your reference (not parsed).");?>
</span>
</td>
</tr>
<!-- tr>
</tr -->
<tr>
<td width="15%" valign="top" class="vncellreq"><?=gettext("Month");?></td>
<td width="85%" class="vtable">
<select name="monthsel" class="form-control" id="monthsel" onchange="update_month();">
<?php
$monthcounter = date("n");
$monthlimit = $monthcounter + 12;
$yearcounter = date("Y");
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>
<?php
if ($monthcounter == 12)
{
$monthcounter = 1;
$yearcounter++;
}
else
{
$monthcounter++;
}
} ?>
</select><br /><br />
<?php
$firstmonth = TRUE;
$monthcounter = date("n");
$yearcounter = date("Y");
for ($k=0; $k<12; $k++){
$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
if ($firstdayofmonth == 0)
$firstdayofmonth = 7;
$daycounter = 1;
//number of day in month
$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
$firstdayprinted = FALSE;
$lasttr = FALSE;
$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";?>">
<table border="1" cellspacing="1" cellpadding="1" id="calTable<?=$monthcounter . $yearcounter;?>" class="tabcont " summary="month">
<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 align="center" class="listhdrr" 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" class="listhdrr" 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" class="listhdrr" 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" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p7');"><u><?=gettext("Sun");?></u></td>
</tr>
</thead>
<tbody>
<?php
$firstmonth = FALSE;
while ($daycounter<=$numberofdays){
$weekcounter = date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
$weekcounter = ltrim($weekcounter, "0");
if ($positioncounter == 1)
{
echo "<tr>";
}
if ($firstdayofmonth == $positioncounter){?>
<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;
$daycounter++;
$firstdayprinted = TRUE;
echo "</td>";
}
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;?>');">
<?php echo $daycounter;
$daycounter++;
echo "</td>";
}
else
{
echo "<td align=\"center\" class=\"listr\"></td>";
}
if ($positioncounter == 7 || $daycounter > $numberofdays){
$positioncounter = 1;
echo "</tr>";
}
else{
$positioncounter++;
}
}//end while loop?>
</tbody>
</table>
</div>
<?php
if ($monthcounter == 12)
{
$monthcounter = 1;
$yearcounter++;
}
else
{
$monthcounter++;
}
} //end for loop
?>
<br />
<?=gettext("Click individual date to select that date only. Click the appropriate weekday Header to select all occurrences of that weekday.");?>
</td>
</tr>
<tr>
<td width="15%" valign="top" class="vncellreq"><?=gettext("Time");?></td>
<td width="85%" class="vtable">
<table cellspacing="2" class="tabcont" summary="time">
<tr>
<td class="listhdrr" align="center"><?=gettext("Start Time");?></td><td></td><td class="listhdrr" align="center"><?=gettext("Stop Time");?></td>
</tr>
<tr>
<td>
<select name="starttimehour" class="form-control" id="starttimehour">
<?php
for ($i=0; $i<24; $i++)
{
echo "<option value=\"$i\">";
echo $i;
echo "</option>";
}
?>
</select>&nbsp;<?=gettext("Hr"); ?>&nbsp;&nbsp;
<select name="starttimemin" class="form-control" id="starttimemin">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
<option value="59">59</option>
</select>&nbsp;<?=gettext("Min"); ?>
</td>
<td></td>
<td>
<select name="stoptimehour" class="form-control" id="stoptimehour">
<?php
for ($i=0; $i<24; $i++)
{
if ($i==23)
$selected = "selected=\"selected\"";
else
$selected = "";
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="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
<option value="59" selected="selected">59</option>
</select>&nbsp;<?=gettext("Min");?>
</td>
</tr>
</table><br />
<?=gettext("Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.")?>
</td>
</tr>
<tr>
<td width="15%" valign="top" class="vncell"><?=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 />
<span class="vexpl">
<?=gettext("You may enter a description here for your reference (not parsed).")?>
</span>
</td>
</tr>
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<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();" />
</td>
</tr>
<tr>
<td width="15%" valign="top" class="vtable"></td>
<td width="85%" class="vtable"></td>
</tr>
</tbody>
</table>
<table class="table table-striped">
<thead>
<tr>
<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule repeat");?></td>
</tr>
</thead>
<tbody>
<tr>
<td width="15%" valign="top" class="vncellreq"><?=gettext("Configured Ranges");?></td>
<td width="85%">
<table id="scheduletable" summary="range">
<tbody>
<tr>
<td align="center" class="listbg" width="35%"><?=gettext("Day(s)");?></td>
<td align="center" class="listbg" width="12%"><?=gettext("Start Time");?></td>
<td align="center" class="listbg" width="11%"><?=gettext("Stop Time");?></td>
<td align="center" class="listbg" width="42%"><?=gettext("Description");?></td>
</tr>
<?php
if ($getSchedule){
$counter = 0;
foreach($pconfig['timerange'] as $timerange) {
$tempFriendlyTime = "";
$tempID = "";
if ($timerange){
$dayFriendly = "";
$tempFriendlyTime = "";
$timedescr = $timerange['rangedescr'];
//get hours
$temptimerange = $timerange['hour'];
$temptimeseparator = strrpos($temptimerange, "-");
$starttime = substr ($temptimerange, 0, $temptimeseparator);
$stoptime = substr ($temptimerange, $temptimeseparator+1);
$currentDay = "";
$firstDay = "";
$nextDay = "";
$foundEnd = false;
$firstDayFound = false;
$firstPrint = false;
$firstprint2 = false;
if ($timerange['month']){
$tempmontharray = explode(",", $timerange['month']);
$tempdayarray = explode(",",$timerange['day']);
$arraycounter = 0;
foreach ($tempmontharray as $monthtmp){
$month = $tempmontharray[$arraycounter];
$day = $tempdayarray[$arraycounter];
$daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y")));
//if sunday, set position to 7 to get correct week number. This is due to php limitations on ISO-8601. When we move to php5.1 we can change this.
if ($daypos == 0){
$daypos = 7;
}
$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
$weeknumber = ltrim($weeknumber, "0");
if ($firstPrint)
{
$tempID .= ",";
}
$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" . $month . "d" . $day;
$firstPrint = true;
if (!$firstDayFound)
{
$firstDay = $day;
$firstmonth = $month;
$firstDayFound = true;
}
$currentDay = $day;
$nextDay = $tempdayarray[$arraycounter+1];
$currentDay++;
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
if ($firstprint2)
$tempFriendlyTime .= ", ";
$currentDay--;
if ($currentDay != $firstDay)
$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
else
$tempFriendlyTime .= $monthArray[$month-1] . " " . $day;
$firstDayFound = false;
$firstprint2 = true;
}
$arraycounter++;
}
}
else
{
$dayFriendly = $timerange['position'];
$tempID = $dayFriendly;
}
$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
$foundEnd = false;
$firstDayFound = false;
$firstprint = false;
$tempFriendlyDayArray = explode(",", $dayFriendly);
$currentDay = "";
$firstDay = "";
$nextDay = "";
$i = 0;
if (!$timerange['month']){
foreach ($tempFriendlyDayArray as $day){
if ($day != ""){
if (!$firstDayFound)
{
$firstDay = $tempFriendlyDayArray[$i];
$firstDayFound = true;
}
$currentDay =$tempFriendlyDayArray[$i];
//get next day
$nextDay = $tempFriendlyDayArray[$i+1];
$currentDay++;
if ($currentDay != $nextDay){
if ($firstprint)
$tempFriendlyTime .= ", ";
$currentDay--;
if ($currentDay != $firstDay)
$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
else
$tempFriendlyTime .= $dayArray[$firstDay-1];
$firstDayFound = false;
$firstprint = true;
}
$i++;
}
}
}
?>
<tr>
<td>
<span class="vexpl"><?php echo $tempFriendlyTime; ?></span>
</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; ?>' />
</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; ?>' />
</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; ?>' />
</td>
<td>
<a onclick='editRow("<?php echo $tempTime; ?>",this); return false;' href='#' class="btn btn-default"><span class="glyphicon glyphicon-edit"></span></a>
</td>
<td>
<a onclick='removeRow(this); return false;' href='#' class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></a>
</td>
<td>
<input type='hidden' id='schedule<?php echo $counter; ?>' name='schedule<?php echo $counter; ?>' value='<?php echo $tempID; ?>' />
</td>
</tr>
<?php
$counter++;
}//end if
} // end foreach
}//end if
?>
</tbody>
</table>
</td>
</tr>
<tr>
<td width="15%" valign="top">&nbsp;</td>
<td width="85%">
<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;?>'" />
<?php if (isset($id) && $a_schedules[$id]): ?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php endif; ?>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
</div>
</section>
<?php include("fbegin.inc"); echo $jscriptstr; ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<section class="col-xs-12">
<div class="content-box content-box-main">
<form action="firewall_schedule_edit.php" method="post" name="iform" id="iform">
<input type="hidden" name="schedlabel" value="<?=$pconfig['schedlabel'];?>"/>
<div class="table-responsive">
<table class="table table-striped">
<tbody>
<tr>
<td width="15%"><strong><?=gettext("Schedule information");?></strong></td>
<td width="85%" 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>
<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>
<?=gettext("NOTE: This schedule is in use so the name may not be modified!");?>
</p>
<?php
else: ?>
<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");?>
</div>
<?php
endif; ?>
</td>
</tr>
<tr>
<td><a id="help_for_description" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description");?></td>
<td>
<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).");?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_month" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Month");?></td>
<td>
<select name="monthsel" class="selectpicker" data-width="auto" data-live-search="true" id="monthsel" onchange="update_month();">
<?php
$monthcounter = date("n");
$monthlimit = $monthcounter + 12;
$yearcounter = date("Y");
for ($k=0; $k<12; $k++){?>
<option value="<?= $monthcounter;?>"><?=date("F_y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option>
<?php
if ($monthcounter == 12) {
$monthcounter = 1;
$yearcounter++;
} else {
$monthcounter++;
}
} ?>
</select>
<br /><br />
<?php
$firstmonth = TRUE;
$monthcounter = date("n");
$yearcounter = date("Y");
for ($k=0; $k<12; $k++){
$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
if ($firstdayofmonth == 0) {
$firstdayofmonth = 7;
}
$daycounter = 1;
//number of day in month
$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
$firstdayprinted = FALSE;
$lasttr = FALSE;
$positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc
?>
<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="table table-condensed" summary="month">
<thead>
<tr><td colspan="7" align="center"><?= date("F_Y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></td></tr>
<tr>
<td align="center" style="cursor: pointer;" onclick="daytoggle('w1p1');"><u><?=gettext("Mon");?></u></td>
<td align="center" style="cursor: pointer;" onclick="daytoggle('w1p2');"><u><?=gettext("Tue");?></u></td>
<td align="center" style="cursor: pointer;" onclick="daytoggle('w1p3');"><u><?=gettext("Wed");?></u></td>
<td align="center" style="cursor: pointer;" onclick="daytoggle('w1p4');"><u><?=gettext("Thu");?></u></td>
<td align="center" style="cursor: pointer;" onclick="daytoggle('w1p5');"><u><?=gettext("Fri");?></u></td>
<td align="center" style="cursor: pointer;" onclick="daytoggle('w1p6');"><u><?=gettext("Sat");?></u></td>
<td align="center" style="cursor: pointer;" onclick="daytoggle('w1p7');"><u><?=gettext("Sun");?></u></td>
</tr>
</thead>
<tbody>
<?php
$firstmonth = FALSE;
while ($daycounter<=$numberofdays){
$weekcounter = date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
$weekcounter = ltrim($weekcounter, "0");
if ($positioncounter == 1) {
echo "<tr>";
}
if ($firstdayofmonth == $positioncounter){?>
<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;
$daycounter++;
$firstdayprinted = TRUE;
echo "</td>";
} 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;?>');">
<?php echo $daycounter;
$daycounter++;
echo "</td>";
} else {
echo "<td align=\"center\" class=\"listr\"></td>";
}
if ($positioncounter == 7 || $daycounter > $numberofdays) {
$positioncounter = 1;
echo "</tr>";
} else {
$positioncounter++;
}
}//end while loop?>
</tbody>
</table>
</div>
<?php
if ($monthcounter == 12) {
$monthcounter = 1;
$yearcounter++;
} else {
$monthcounter++;
}
} //end for loop
?>
<div class="hidden" for="help_for_month">
<br />
<?=gettext("Click individual date to select that date only. Click the appropriate weekday Header to select all occurrences of that weekday.");?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_time" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Time");?></td>
<td>
<table cellspacing="2" class="tabcont" summary="time">
<tr>
<td><?=gettext("Start Time");?></td>
<td><?=gettext("Stop Time");?></td>
</tr>
<tr>
<td>
<div class="input-group">
<select name="starttimehour" class="selectpicker form-control" data-width="auto" data-size="5" data-live-search="true" id="starttimehour">
<?php
for ($i=0; $i<24; $i++):?>
<option value="<?=$i;?>"><?=$i;?> </option>
<?php
endfor; ?>
</select>
<select name="starttimemin" class="selectpicker form-control" data-width="auto" data-size="5" data-live-search="true" id="starttimemin">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
<option value="59">59</option>
</select>
</div>
</td>
<td>
<div class="input-group">
<select name="stoptimehour" class="selectpicker form-control" data-width="auto" data-size="5" data-live-search="true" id="stoptimehour">
<?php
for ($i=0; $i<24; $i++):?>
<option value="<?=$i;?>"><?=$i;?> </option>
<?php
endfor; ?>
</select>
<select name="stoptimemin" class="selectpicker form-control" data-width="auto" data-size="5" data-live-search="true" id="stoptimemin">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
<option value="59" selected="selected">59</option>
</select>
</div>
</td>
</tr>
</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.")?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_timerange_desc" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Time Range Description")?></td>
<td>
<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).")?>
</div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<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();" />
</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<table class="table table-striped">
<thead>
<tr>
<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule repeat");?></td>
</tr>
</thead>
<tbody>
<tr>
<td><?=gettext("Configured Ranges");?></td>
<td>
<table id="scheduletable" summary="range">
<tbody>
<tr>
<td align="center" width="35%"><?=gettext("Day(s)");?></td>
<td align="center" width="12%"><?=gettext("Start Time");?></td>
<td align="center" width="11%"><?=gettext("Stop Time");?></td>
<td align="center" width="42%"><?=gettext("Description");?></td>
</tr>
<?php
if (isset($pconfig['timerange'])){
$counter = 0;
foreach($pconfig['timerange'] as $timerange) {
$tempFriendlyTime = "";
$tempID = "";
if ($timerange){
$dayFriendly = "";
$tempFriendlyTime = "";
$timedescr = $timerange['rangedescr'];
//get hours
$temptimerange = $timerange['hour'];
$temptimeseparator = strrpos($temptimerange, "-");
$starttime = substr ($temptimerange, 0, $temptimeseparator);
$stoptime = substr ($temptimerange, $temptimeseparator+1);
$currentDay = "";
$firstDay = "";
$nextDay = "";
$foundEnd = false;
$firstDayFound = false;
$firstPrint = false;
$firstprint2 = false;
if (!empty($timerange['month'])){
$tempmontharray = explode(",", $timerange['month']);
$tempdayarray = explode(",",$timerange['day']);
$arraycounter = 0;
foreach ($tempmontharray as $monthtmp){
$month = $tempmontharray[$arraycounter];
$day = $tempdayarray[$arraycounter];
$daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y")));
//if sunday, set position to 7 to get correct week number. This is due to php limitations on ISO-8601. When we move to php5.1 we can change this.
if ($daypos == 0){
$daypos = 7;
}
$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
$weeknumber = ltrim($weeknumber, "0");
if ($firstPrint) {
$tempID .= ",";
}
$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" . $month . "d" . $day;
$firstPrint = true;
if (!$firstDayFound) {
$firstDay = $day;
$firstmonth = $month;
$firstDayFound = true;
}
$currentDay = $day;
$nextDay = $tempdayarray[$arraycounter+1];
$currentDay++;
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
if ($firstprint2) {
$tempFriendlyTime .= ", ";
}
$currentDay--;
if ($currentDay != $firstDay) {
$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
} else {
$tempFriendlyTime .= $monthArray[$month-1] . " " . $day;
}
$firstDayFound = false;
$firstprint2 = true;
}
$arraycounter++;
}
} else {
$dayFriendly = $timerange['position'];
$tempID = $dayFriendly;
}
$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
$foundEnd = false;
$firstDayFound = false;
$firstprint = false;
$tempFriendlyDayArray = explode(",", $dayFriendly);
$currentDay = "";
$firstDay = "";
$nextDay = "";
$i = 0;
if (empty($timerange['month'])) {
foreach ($tempFriendlyDayArray as $day){
if ($day != ""){
if (!$firstDayFound) {
$firstDay = $tempFriendlyDayArray[$i];
$firstDayFound = true;
}
$currentDay =$tempFriendlyDayArray[$i];
//get next day
$nextDay = $tempFriendlyDayArray[$i+1];
$currentDay++;
if ($currentDay != $nextDay){
if ($firstprint){
$tempFriendlyTime .= ", ";
}
$currentDay--;
if ($currentDay != $firstDay) {
$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
} else {
$tempFriendlyTime .= $dayArray[$firstDay-1];
}
$firstDayFound = false;
$firstprint = true;
}
$i++;
}
}
}
?>
<tr>
<td>
<span><?=$tempFriendlyTime; ?></span>
</td>
<td>
<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>
<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>
<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>
<a onclick='editRow("<?=$tempTime; ?>",this); return false;' href='#' class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
</td>
<td>
<a onclick='removeRow(this); return false;' href='#' class="btn btn-default"><span class="glyphicon glyphicon-remove"></span></a>
</td>
<td>
<input type='hidden' id='schedule<?=$counter; ?>' name='schedule<?=$counter; ?>' value='<?=$tempID; ?>' />
</td>
</tr>
<?php
$counter++;
}//end if
} // end foreach
}//end if
?>
</tbody>
</table>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<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='<?=(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_schedule.php');?>'" />
<?php if (isset($id)): ?>
<input name="id" type="hidden" value="<?=$id;?>" />
<?php endif; ?>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2005 Bill Marquette <bill.marquette@gmail.com>.
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
Copyright (C) 2004-2005 Scott Ullrich <geekgod@pfsense.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2005 Bill Marquette <bill.marquette@gmail.com>.
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
Copyright (C) 2004-2005 Scott Ullrich <geekgod@pfsense.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("interfaces.inc");
require_once("filter.inc");
if (!isset($config['virtualip']['vip'])) {
$config['virtualip']['vip'] = array();
/**
* delete virtual ip
*/
function deleteVIPEntry($id) {
global $config;
$input_errors = array();
$a_vip = &$config['virtualip']['vip'];
/* make sure no inbound NAT mappings reference this entry */
if (isset($config['nat']['rule'])) {
foreach ($config['nat']['rule'] as $rule) {
if(!empty($rule['destination']['address'])) {
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.");
break;
}
}
}
}
if (is_ipaddrv6($a_vip[$id]['subnet'])) {
$is_ipv6 = true;
$subnet = gen_subnetv6($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']);
$if_subnet_bits = get_interface_subnetv6($a_vip[$id]['interface']);
$if_subnet = gen_subnetv6(get_interface_ipv6($a_vip[$id]['interface']), $if_subnet_bits);
} else {
$is_ipv6 = false;
$subnet = gen_subnet($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']);
$if_subnet_bits = get_interface_subnet($a_vip[$id]['interface']);
$if_subnet = gen_subnet(get_interface_ip($a_vip[$id]['interface']), $if_subnet_bits);
}
$subnet .= "/" . $a_vip[$id]['subnet_bits'];
$if_subnet .= "/" . $if_subnet_bits;
if (isset($config['gateways']['gateway_item'])) {
foreach($config['gateways']['gateway_item'] as $gateway) {
if ($a_vip[$id]['interface'] != $gateway['interface'])
continue;
if ($is_ipv6 && $gateway['ipprotocol'] == 'inet')
continue;
if (!$is_ipv6 && $gateway['ipprotocol'] == 'inet6')
continue;
if (ip_in_subnet($gateway['gateway'], $if_subnet))
continue;
if (ip_in_subnet($gateway['gateway'], $subnet)) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one Gateway.");
break;
}
}
}
if ($a_vip[$id]['mode'] == "ipalias") {
$subnet = gen_subnet($a_vip[$id]['subnet'], $a_vip[$id]['subnet_bits']) . "/" . $a_vip[$id]['subnet_bits'];
$found_if = false;
$found_carp = false;
$found_other_alias = false;
if ($subnet == $if_subnet)
$found_if = true;
$vipiface = $a_vip[$id]['interface'];
foreach ($a_vip as $vip_id => $vip) {
if ($vip_id != $id) {
if ($vip['interface'] == $vipiface && ip_in_subnet($vip['subnet'], $subnet)) {
if ($vip['mode'] == "carp") {
$found_carp = true;
} else if ($vip['mode'] == "ipalias") {
$found_other_alias = true;
}
}
}
}
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']}.";
}
}
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;
}
$a_vip = &$config['virtualip']['vip'];
if ($_POST) {
$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');
}
/**
* redirect user if config may not be saved.
*/
function redirectReadOnlyUser() {
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$user = getUserEntry($_SESSION['Username']);
if (is_array($user) && userHasPrivilege($user, "user-config-readonly")) {
header("Location: firewall_virtual_ip.php");
exit;
}
session_write_close();
}
if ($_GET['act'] == "del") {
if ($a_vip[$_GET['id']]) {
/* make sure no inbound NAT mappings reference this entry */
if (is_array($config['nat']['rule'])) {
foreach ($config['nat']['rule'] as $rule) {
if($rule['destination']['address'] <> "") {
if ($rule['destination']['address'] == $a_vip[$_GET['id']]['subnet']) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one NAT mapping.");
break;
}
}
}
}
if (is_ipaddrv6($a_vip[$_GET['id']]['subnet'])) {
$is_ipv6 = true;
$subnet = gen_subnetv6($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
$if_subnet_bits = get_interface_subnetv6($a_vip[$_GET['id']]['interface']);
$if_subnet = gen_subnetv6(get_interface_ipv6($a_vip[$_GET['id']]['interface']), $if_subnet_bits);
} else {
$is_ipv6 = false;
$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']);
$if_subnet_bits = get_interface_subnet($a_vip[$_GET['id']]['interface']);
$if_subnet = gen_subnet(get_interface_ip($a_vip[$_GET['id']]['interface']), $if_subnet_bits);
}
$subnet .= "/" . $a_vip[$_GET['id']]['subnet_bits'];
$if_subnet .= "/" . $if_subnet_bits;
if (isset($config['gateways']['gateway_item'])) {
foreach($config['gateways']['gateway_item'] as $gateway) {
if ($a_vip[$_GET['id']]['interface'] != $gateway['interface'])
continue;
if ($is_ipv6 && $gateway['ipprotocol'] == 'inet')
continue;
if (!$is_ipv6 && $gateway['ipprotocol'] == 'inet6')
continue;
if (ip_in_subnet($gateway['gateway'], $if_subnet))
continue;
if (ip_in_subnet($gateway['gateway'], $subnet)) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one Gateway.");
break;
}
}
}
if ($a_vip[$_GET['id']]['mode'] == "ipalias") {
$subnet = gen_subnet($a_vip[$_GET['id']]['subnet'], $a_vip[$_GET['id']]['subnet_bits']) . "/" . $a_vip[$_GET['id']]['subnet_bits'];
$found_if = false;
$found_carp = false;
$found_other_alias = false;
if ($subnet == $if_subnet)
$found_if = true;
$vipiface = $a_vip[$_GET['id']]['interface'];
foreach ($a_vip as $vip_id => $vip) {
if ($vip_id == $_GET['id'])
continue;
if ($vip['interface'] == $vipiface && ip_in_subnet($vip['subnet'], $subnet))
if ($vip['mode'] == "carp")
$found_carp = true;
else if ($vip['mode'] == "ipalias")
$found_other_alias = true;
}
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']}.";
}
if (!$input_errors) {
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$user = getUserEntry($_SESSION['Username']);
if (is_array($user) && userHasPrivilege($user, "user-config-readonly")) {
header("Location: firewall_virtual_ip.php");
exit;
}
session_write_close();
if (!isset($config['virtualip']['vip'])) {
$config['virtualip']['vip'] = array();
}
$a_vip = &$config['virtualip']['vip'];
// Special case since every proxyarp vip is handled by the same daemon.
if ($a_vip[$_GET['id']]['mode'] == "proxyarp") {
$viface = $a_vip[$_GET['id']]['interface'];
unset($a_vip[$_GET['id']]);
interface_proxyarp_configure($viface);
} else {
interface_vip_bring_down($a_vip[$_GET['id']]);
unset($a_vip[$_GET['id']]);
}
if (count($config['virtualip']['vip']) == 0)
unset($config['virtualip']['vip']);
write_config();
header("Location: firewall_virtual_ip.php");
exit;
}
}
} else if ($_GET['changes'] == "mods" && is_numericint($_GET['id']))
$id = $_GET['id'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pconfig = $_POST;
if (isset($pconfig['id']) && isset($a_vip[$pconfig['id']])) {
// id found and valid
$id = $pconfig['id'];
}
if (isset($pconfig['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 (!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();
header("Location: firewall_virtual_ip.php");
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;
}
}
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Addresses"));
include("head.inc");
$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>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php
if (isset($input_errors) && count($input_errors) > 0)
print_input_errors($input_errors);
else
if (isset($savemsg))
print_info_box($savemsg);
else
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."));
?>
<section class="col-xs-12">
<?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">
<input type="hidden" id="id" name="id" value="<?php echo htmlspecialchars($id); ?>" />
<div class="table-responsive">
<table class="table table-striped table-sort">
<thead>
<tr>
<td width="30%" class="listhdrr"><?=gettext("Virtual IP address");?></td>
<td width="10%" class="listhdrr"><?=gettext("Interface");?></td>
<td width="10%" class="listhdrr"><?=gettext("Type");?></td>
<td width="40%" class="listhdr"><?=gettext("Description");?></td>
<td width="10%" class="list"></td>
</tr>
</thead>
<tbody>
<?php
$interfaces = get_configured_interface_with_descr(false, true);
$interfaces['lo0'] = "Localhost";
?>
<?php $i = 0; foreach ($a_vip as $vipent): ?>
<?php if($vipent['subnet'] <> "" or $vipent['range'] <> "" or
$vipent['subnet_bits'] <> "" or (isset($vipent['range']['from']) && $vipent['range']['from'] <> "")): ?>
<tr>
<td class="listlr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$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 class="listr" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
<?=htmlspecialchars($interfaces[$vipent['interface']]);?>&nbsp;
</td>
<td class="listr" align="center" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
<?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";?>
</td>
<td class="listbg" ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
<?=htmlspecialchars($vipent['descr']);?>&nbsp;
</td>
<td class="list nowrap">
<table border="0" cellspacing="0" cellpadding="1" summary="icons">
<tr>
<td valign="middle">
<a href="firewall_virtual_ip_edit.php?id=<?=$i;?>" class="btn btn-default"><span class="glyphicon glyphicon-edit" title="<?=gettext("Edit");?>"></span></a>
<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>
</td>
</tr>
</table>
</td>
</tr>
<?php endif; ?>
<?php $i++; endforeach; ?>
</tbody>
</table>
</div>
<div class="container-fluid">
<p><span class="vexpl"><span class="text-danger"><strong><?=gettext("Note:");?><br />
</strong></span><?=gettext("The virtual IP addresses defined on this page may be used in");?><a href="firewall_nat.php"> <?=gettext("NAT"); ?> </a><?=gettext("mappings.");?><br />
<?=gettext("You can check the status of your CARP Virtual IPs and interfaces ");?><a href="carp_status.php"><?=gettext("here");?></a>.</span></p>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<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">
<div class="container-fluid">
<div class="row">
<?php
if (isset($input_errors) && count($input_errors) > 0)
print_input_errors($input_errors);
else
if (isset($savemsg))
print_info_box($savemsg);
else
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."));
?>
<section class="col-xs-12">
<div class="content-box-main content-box">
<form action="firewall_virtual_ip.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">
<table class="table table-striped">
<thead>
<tr>
<td></td>
<td><?=gettext("Virtual IP address");?></td>
<td><?=gettext("Interface");?></td>
<td><?=gettext("Type");?></td>
<td><?=gettext("Description");?></td>
<td></td>
</tr>
</thead>
<tbody>
<?php
$interfaces = get_configured_interface_with_descr(false, true);
$interfaces['lo0'] = "Localhost";
$i = 0;
foreach ($a_vip as $vipent):
if(!empty($vipent['subnet']) || !empty($vipent['range']) || !empty($vipent['subnet_bits']) || (isset($vipent['range']['from']) && !empty($vipent['range']['from']))): ?>
<tr ondblclick="document.location='firewall_virtual_ip_edit.php?id=<?=$i;?>';">
<td>
<input type="checkbox" name="rule[]" value="<?=$i;?>" />
</td>
<td>
<?=($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>
<?=htmlspecialchars($interfaces[$vipent['interface']]);?>
</td>
<td>
<?=$vipent['mode'] == "proxyarp" ? "Proxy ARP" : "";?>
<?=$vipent['mode'] == "carp" ? "CARP" : "";?>
<?=$vipent['mode'] == "other" ? "Other" : "";?>
<?=$vipent['mode'] == "ipalias" ? "IP Alias" :"";?>
</td>
<td>
<?=htmlspecialchars($vipent['descr']);?>
</td>
<td>
<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>
<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>
</tr>
<?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>
</tr>
</tbody>
</table>
</div>
<div class="container-fluid">
<p><span class="vexpl"><span class="text-danger"><strong><?=gettext("Note:");?><br />
</strong></span><?=gettext("The virtual IP addresses defined on this page may be used in");?><a href="firewall_nat.php"> <?=gettext("NAT"); ?> </a><?=gettext("mappings.");?><br />
<?=gettext("You can check the status of your CARP Virtual IPs and interfaces ");?><a href="carp_status.php"><?=gettext("here");?></a>.</span></p>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
......@@ -33,467 +33,460 @@ require_once("guiconfig.inc");
require_once("interfaces.inc");
require_once("pfsense-utils.inc");
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_virtual_ip.php');
/**
* find max vhid
*/
function find_last_used_vhid() {
global $config;
$vhid = 0;
if (isset($config['virtualip']['vip'])) {
foreach($config['virtualip']['vip'] as $vip) {
if(!empty($vip['vhid']) && $vip['vhid'] > $vhid) {
$vhid = $vip['vhid'];
}
}
}
return $vhid;
}
if (!is_array($config['virtualip']['vip'])) {
$config['virtualip']['vip'] = array();
// create new vip array if none existent
if (!isset($config['virtualip']) || !is_array($config['virtualip'])) {
$config['virtualip'] = array();
}
if (!isset($config['virtualip']['vip']) || !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];
}
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] ;
}
}
}
function find_last_used_vhid() {
global $config, $g;
$vhid = 0;
foreach($config['virtualip']['vip'] as $vip) {
if($vip['vhid'] > $vhid)
$vhid = $vip['vhid'];
}
return $vhid;
}
// 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;
// input record id, if valid
if (isset($pconfig['id']) && isset($a_vip[$pconfig['id']])) {
$id = $pconfig['id'];
}
// perform form validations
$reqdfields = array("mode");
$reqdfieldsn = array(gettext("Type"));
do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
if (isset($pconfig['subnet'])) {
$pconfig['subnet'] = trim($pconfig['subnet']);
if (!is_ipaddr($pconfig['subnet'])) {
$input_errors[] = gettext("A valid IP address must be specified.");
} else {
if ($pconfig['mode'] == 'carp') {
$ignore_if = $pconfig['interface']."_vip{$pconfig['vhid']}";
} else {
$ignore_if = $pconfig['interface'];
}
if (is_ipaddr_configured($pconfig['subnet'], $ignore_if)) {
$input_errors[] = gettext("This IP address is being used by another interface or VIP.");
}
}
}
$natiflist = get_configured_interface_with_descr();
foreach ($natiflist as $natif => $natdescr) {
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.");
}
}
/* ipalias and carp should not use network or broadcast address */
if ($pconfig['mode'] == "ipalias" || $pconfig['mode'] == "carp") {
if (is_ipaddrv4($pconfig['subnet']) && $pconfig['subnet_bits'] != "32") {
$network_addr = gen_subnet($pconfig['subnet'], $pconfig['subnet_bits']);
$broadcast_addr = gen_subnet_max($pconfig['subnet'], $pconfig['subnet_bits']);
} else if (is_ipaddrv6($pconfig['subnet']) && $_POST['subnet_bits'] != "128" ) {
$network_addr = gen_subnetv6($pconfig['subnet'], $pconfig['subnet_bits']);
$broadcast_addr = gen_subnetv6_max($pconfig['subnet'], $pconfig['subnet_bits']);
}
if (isset($network_addr) && $pconfig['subnet'] == $network_addr) {
$input_errors[] = gettext("You cannot use the network address for this VIP");
} else if (isset($broadcast_addr) && $pconfig['subnet'] == $broadcast_addr) {
$input_errors[] = gettext("You cannot use the broadcast address for this VIP");
}
}
/* make sure new ip is within the subnet of a valid ip
* on one of our interfaces (wan, lan optX)
*/
if ($pconfig['mode'] == 'carp') {
/* verify against reusage of vhids */
foreach($config['virtualip']['vip'] as $vipId => $vip) {
if(isset($vip['vhid']) && $vip['vhid'] == $pconfig['vhid'] && $vip['interface'] == $pconfig['interface'] && $vipId <> $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']));
}
}
if (empty($pconfig['password'])) {
$input_errors[] = gettext("You must specify a CARP password that is shared between the two VHID members.");
}
if (isset($id) && $a_vip[$id]) {
$pconfig['mode'] = $a_vip[$id]['mode'];
$pconfig['vhid'] = $a_vip[$id]['vhid'];
$pconfig['advskew'] = $a_vip[$id]['advskew'];
$pconfig['advbase'] = $a_vip[$id]['advbase'];
$pconfig['password'] = $a_vip[$id]['password'];
$pconfig['range'] = $a_vip[$id]['range'];
$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;
}
if (is_ipaddrv4($pconfig['subnet'])) {
$parent_ip = get_interface_ip($pconfig['interface']);
$parent_sn = get_interface_subnet($pconfig['interface']);
$subnet = gen_subnet($parent_ip, $parent_sn);
} else if (is_ipaddrv6($pconfig['subnet'])) {
$parent_ip = get_interface_ipv6($pconfig['interface']);
$parent_sn = get_interface_subnetv6($pconfig['interface']);
$subnet = gen_subnetv6($parent_ip, $parent_sn);
}
if (isset($parent_ip) && !ip_in_subnet($pconfig['subnet'], "{$subnet}/{$parent_sn}") && !ip_in_interface_alias_subnet($pconfig['interface'], $pconfig['subnet'])) {
$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);
}
if ($pconfig['interface'] == "lo0") {
$input_errors[] = gettext("For this type of vip localhost is not allowed.");
}
} else if ($pconfig['mode'] != 'ipalias' && $pconfig['interface'] == "lo0") {
$input_errors[] = gettext("For this type of vip localhost is not allowed.");
}
if (count($input_errors) == 0) {
$vipent = array();
// defaults
$vipent['type'] = "single";
$vipent['subnet_bits'] = "32";
// 1-on-1 copy attributes
foreach (array('mode', 'interface', 'descr', 'type', 'subnet_bits', 'subnet', 'vhid'
,'advskew','advbase','password') as $fieldname) {
if (!empty($pconfig[$fieldname])) {
$vipent[$fieldname] = $pconfig[$fieldname];
}
}
if (!empty($pconfig['noexpand'])) {
// 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')) {
$toapplylist = unserialize(file_get_contents('/tmp/.firewall_virtual_ip.apply'));
} else {
$toapplylist = array();
}
if (isset($id)) {
if (isset($toapplylist[$id])) {
$toapplylist[$id] = $a_vip[$id];
} else {
$toapplylist[] = $a_vip[$id];
}
}
if ($_POST) {
unset($input_errors);
$pconfig = $_POST;
/* input validation */
$reqdfields = explode(" ", "mode");
$reqdfieldsn = array(gettext("Type"));
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
if (isset($_POST['subnet'])) {
$_POST['subnet'] = trim($_POST['subnet']);
if (!is_ipaddr($_POST['subnet']))
$input_errors[] = gettext("A valid IP address must be specified.");
else {
if ($_POST['mode'] == 'carp') {
$ignore_if = $_POST['interface']."_vip{$_POST['vhid']}";
} else {
$ignore_if = $_POST['interface'];
}
if (is_ipaddr_configured($_POST['subnet'], $ignore_if)) {
$input_errors[] = gettext("This IP address is being used by another interface or VIP.");
}
unset($ignore_if);
}
}
$natiflist = get_configured_interface_with_descr();
foreach ($natiflist as $natif => $natdescr) {
if ($_POST['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.");
}
/* ipalias and carp should not use network or broadcast address */
if ($_POST['mode'] == "ipalias" || $_POST['mode'] == "carp") {
if (is_ipaddrv4($_POST['subnet']) && $_POST['subnet_bits'] != "32") {
$network_addr = gen_subnet($_POST['subnet'], $_POST['subnet_bits']);
$broadcast_addr = gen_subnet_max($_POST['subnet'], $_POST['subnet_bits']);
} else if (is_ipaddrv6($_POST['subnet']) && $_POST['subnet_bits'] != "128" ) {
$network_addr = gen_subnetv6($_POST['subnet'], $_POST['subnet_bits']);
$broadcast_addr = gen_subnetv6_max($_POST['subnet'], $_POST['subnet_bits']);
}
if (isset($network_addr) && $_POST['subnet'] == $network_addr)
$input_errors[] = gettext("You cannot use the network address for this VIP");
else if (isset($broadcast_addr) && $_POST['subnet'] == $broadcast_addr)
$input_errors[] = gettext("You cannot use the broadcast address for this VIP");
}
/* make sure new ip is within the subnet of a valid ip
* on one of our interfaces (wan, lan optX)
*/
if ($_POST['mode'] == 'carp') {
/* verify against reusage of vhids */
$idtracker = 0;
foreach($config['virtualip']['vip'] as $vip) {
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."),$_POST['vhid'], convert_friendly_interface_to_friendly_descr($_POST['interface']));
$idtracker++;
}
if (empty($_POST['password']))
$input_errors[] = gettext("You must specify a CARP password that is shared between the two VHID members.");
if (is_ipaddrv4($_POST['subnet'])) {
$parent_ip = get_interface_ip($_POST['interface']);
$parent_sn = get_interface_subnet($_POST['interface']);
$subnet = gen_subnet($parent_ip, $parent_sn);
} else if (is_ipaddrv6($_POST['subnet'])) {
$parent_ip = get_interface_ipv6($_POST['interface']);
$parent_sn = get_interface_subnetv6($_POST['interface']);
$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'])) {
$cannot_find = $_POST['subnet'] . "/" . $_POST['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);
}
if ($_POST['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.");
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']);
}
/* 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 */
$vipent['descr'] = $_POST['descr'];
if (isset($_POST['type']))
$vipent['type'] = $_POST['type'];
else
$vipent['type'] = "single";
if ($vipent['type'] == "single" || $vipent['type'] == "network") {
if (!isset($_POST['subnet_bits'])) {
$vipent['subnet_bits'] = "32";
} else {
$vipent['subnet_bits'] = $_POST['subnet_bits'];
}
$vipent['subnet'] = $_POST['subnet'];
}
if (!isset($id))
$id = count($a_vip);
if (file_exists('/tmp/.firewall_virtual_ip.apply')) {
$toapplylist = unserialize(file_get_contents('/tmp/.firewall_virtual_ip.apply'));
} else {
$toapplylist = array();
}
$toapplylist[$id] = $a_vip[$id];
if (!empty($a_vip[$id])) {
/* modify all virtual IP rules with this address */
for ($i = 0; isset($config['nat']['rule'][$i]); $i++) {
if ($config['nat']['rule'][$i]['destination']['address'] == $a_vip[$id]['subnet'])
$config['nat']['rule'][$i]['destination']['address'] = $vipent['subnet'];
}
}
$a_vip[$id] = $vipent;
if (write_config()) {
mark_subsystem_dirty('vip');
file_put_contents('/tmp/.firewall_virtual_ip.apply', serialize($toapplylist));
}
header("Location: firewall_virtual_ip.php");
exit;
}
if (isset($id)) {
/* modify all virtual IP rules with this address */
for ($i = 0; isset($config['nat']['rule'][$i]); $i++) {
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'];
}
}
}
// update or insert item in config
if (isset($id)) {
$a_vip[$id] = $vipent;
} else {
$a_vip[] = $vipent;
}
if (write_config()) {
mark_subsystem_dirty('vip');
file_put_contents('/tmp/.firewall_virtual_ip.apply', serialize($toapplylist));
}
header("Location: firewall_virtual_ip.php");
exit;
}
}
legacy_html_escape_form_data($pconfig);
$pgtitle = array(gettext("Firewall"),gettext("Virtual IP Address"),gettext("Edit"));
include("head.inc");
?>
<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">
//<![CDATA[
function get_radio_value(obj)
{
for (i = 0; i < obj.length; i++) {
if (obj[i].checked)
return obj[i].value;
<script type="text/javascript">
$( document ).ready(function() {
$("#mode").change(function(){
//$("#subnet").attr('disabled', true);
$("#type").attr('disabled', true);
$("#subnet_bits").attr('disabled', true);
$("#noexpand").attr('disabled', true);
$("#password").attr('disabled', true);
$("#vhid").attr('disabled', true);
$("#advskew").attr('disabled', true);
$("#advbase").attr('disabled', true);
$("#noexpand").attr('disabled', true);
$("#noexpandrow").addClass("hidden");
switch ($(this).val()) {
case "ipalias":
$("#type").prop("selectedIndex",0);
$("#typenote").html("<?=gettext("Please provide a single IP address");?>");
break;
case "carp":
$("#type").prop("selectedIndex",0);
$("#subnet_bits").attr('disabled', false);
$("#password").attr('disabled', false);
$("#vhid").attr('disabled', false);
$("#advskew").attr('disabled', false);
$("#advbase").attr('disabled', false);
$("#typenote").html("<?=gettext("This must be the network's subnet mask. It does not specify a CIDR range.");?>");
break;
case "proxyarp":
$("#type").attr('disabled', false);
$("#subnet_bits").attr('disabled', false);
$("#noexpand").attr('disabled', false);
$("#noexpandrow").removeClass("hidden");
$("#typenote").html("<?=gettext("This is a CIDR block of proxy ARP addresses.");?>");
break;
case "other":
$("#type").attr('disabled', false);
$("#subnet_bits").attr('disabled', false);
$("#typenote").html("<?=gettext("This must be the network's subnet mask. It does not specify a CIDR range.");?>");
break;
}
return null;
}
function set_note(noteMessage){
var note = document.getElementById("typenote");
if (note.firstChild != null)
note.removeChild(note.firstChild);
if (noteMessage)
note.appendChild(noteMessage);
}
function enable_change() {
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();
}
// 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();
});
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;
case 1: // network
document.iform.subnet.disabled = 0;
document.iform.subnet_bits.disabled = 0;
document.iform.noexpand.disabled = 0;
jQuery('#noexpandrow').css('display','');
//document.iform.range_from.disabled = 1;
//document.iform.range_to.disabled = 1;
break;
case 2: // range
document.iform.subnet.disabled = 1;
document.iform.subnet_bits.disabled = 1;
document.iform.noexpand.disabled = 1;
jQuery('#noexpandrow').css('display','none');
//document.iform.range_from.disabled = 0;
//document.iform.range_to.disabled = 0;
break;
case 3: // IP alias
document.iform.subnet.disabled = 1;
document.iform.subnet_bits.disabled = 0;
document.iform.noexpand.disabled = 1;
jQuery('#noexpandrow').css('display','none');
//document.iform.range_from.disabled = 0;
//document.iform.range_to.disabled = 0;
break;
}
}
//]]>
</script>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<div id="inputerrors"></div>
<section class="col-xs-12">
<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">
<div class="table-responsive">
<table class="table table-striped table-sort">
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Type");?></td>
<td width="78%" class="vtable">
<input name="mode" type="radio" onclick="enable_change()" value="ipalias"
<?php if ($pconfig['mode'] == "ipalias") echo "checked=\"checked\"";?> /> <?=gettext("IP Alias");?>
<input name="mode" type="radio" onclick="enable_change()" value="carp"
<?php if ($pconfig['mode'] == "carp") echo "checked=\"checked\"";?> /> <?=gettext("CARP"); ?>
<input name="mode" type="radio" onclick="enable_change()" value="proxyarp"
<?php if ($pconfig['mode'] == "proxyarp") echo "checked=\"checked\"";?> /> <?=gettext("Proxy ARP"); ?>
<input name="mode" type="radio" onclick="enable_change()" value="other"
<?php if ($pconfig['mode'] == "other") echo "checked=\"checked\"";?> /> <?=gettext("Other");?>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
<td width="78%" class="vtable">
<select name="interface" class="form-control">
<?php
$interfaces = get_configured_interface_with_descr(false, true);
$interfaces['lo0'] = "Localhost";
foreach ($interfaces as $iface => $ifacename): ?>
<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
<?=htmlspecialchars($ifacename);?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td valign="top" class="vncellreq"><?=gettext("IP Address(es)");?></td>
<td class="vtable">
<table border="0" cellspacing="0" cellpadding="0" summary="ip addresses">
<tr>
<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
<td><select name="type" class="form-control" onchange="typesel_change()">
<option value="single" <?php if ((!$pconfig['range'] && $pconfig['subnet_bits'] == 32) || (!isset($pconfig['subnet']))) echo "selected=\"selected\""; ?>>
<?=gettext("Single address");?></option>
<option value="network" <?php if (!$pconfig['range'] && $pconfig['subnet_bits'] != 32 && isset($pconfig['subnet'])) echo "selected=\"selected\""; ?>>
<?=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\""; ?>>
Range</option> -->
</select></td>
</tr>
<tr>
<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
<td><input name="subnet" type="text" class="form-control unknown ipv4v6" id="subnet" size="28" value="<?=htmlspecialchars($pconfig['subnet']);?>" />
/<select name="subnet_bits" class="form-control ipv4v6" id="select">
<?php for ($i = 128; $i >= 1; $i--): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['subnet_bits']) echo "selected=\"selected\""; ?>>
<?=$i;?>
</option>
<?php endfor; ?>
</select> <i id="typenote"></i>
</td>
</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>
</tr>
*/
?>
</table>
</td>
</tr>
<tr valign="top">
<td width="22%" class="vncellreq"><?=gettext("Virtual IP Password");?></td>
<td class="vtable"><input type='password' name='password' value="<?=htmlspecialchars($pconfig['password']);?>" />
<br /><?=gettext("Enter the VHID group password.");?>
</td>
</tr>
<tr valign="top">
<td width="22%" class="vncellreq"><?=gettext("VHID Group");?></td>
<td class="vtable"><select id='vhid' name='vhid'>
<?php for ($i = 1; $i <= 255; $i++): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['vhid']) echo "selected=\"selected\""; ?>>
<?=$i;?>
</option>
<?php endfor; ?>
</select>
<br /><?=gettext("Enter the VHID group that the machines will share");?>
</td>
</tr>
<tr valign="top">
<td width="22%" class="vncellreq"><?=gettext("Advertising Frequency");?></td>
<td class="vtable">
Base: <select id='advbase' name='advbase'>
<?php for ($i = 1; $i <= 254; $i++): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['advbase']) echo "selected=\"selected\""; ?>>
<?=$i;?>
</option>
<?php endfor; ?>
</select>
Skew: <select id='advskew' name='advskew'>
<?php for ($i = 0; $i <= 254; $i++): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['advskew']) echo "selected=\"selected\""; ?>>
<?=$i;?>
</option>
<?php endfor; ?>
</select>
<br /><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.");?>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
<td width="78%" class="vtable">
<input name="descr" type="text" class="form-control unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
<br /> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed).");?></span></td>
</tr>
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<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;?>'" />
<?php if (isset($id) && $a_vip[$id]): ?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php endif; ?>
</td>
</tr>
</table>
</div>
<div class="container-fluid">
<p class="vexpl">
<span class="text-danger">
<strong><?=gettext("Note:");?><br /></strong>
</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.");?>
<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>.
</p>
</div>
</form>
</div>
</div>
</section>
</div>
</div>
</section>
<script type="text/javascript">
//<![CDATA[
enable_change();
//]]>
</script>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<section class="col-xs-12">
<div class="content-box">
<form action="firewall_virtual_ip_edit.php" method="post" name="iform" id="iform">
<div class="table-responsive">
<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>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Type");?></td>
<td>
<select id="mode" name="mode" class="selectpicker" data-width="auto" data-live-search="true">
<option value="ipalias" <?=$pconfig['mode'] == "ipalias" ? "selected=\"selected\"" : ""; ?>><?=gettext("IP Alias");?></option>
<option value="carp" <?=$pconfig['mode'] == "carp" ? "selected=\"selected\"" : ""; ?>><?=gettext("carp");?></option>
<option value="proxyarp" <?=$pconfig['mode'] == "proxyarp" ? "selected=\"selected\"" : ""; ?>><?=gettext("Proxy ARP");?></option>
<option value="other" <?=$pconfig['mode'] == "other" ? "selected=\"selected\"" : ""; ?>><?=gettext("Other");?></option>
</select>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Interface");?></td>
<td>
<select name="interface" class="selectpicker" data-width="auto">
<?php
$interfaces = get_configured_interface_with_descr(false, true);
$interfaces['lo0'] = "Localhost";
foreach ($interfaces as $iface => $ifacename): ?>
<option value="<?=$iface;?>" <?= $iface == $pconfig['interface'] ? "selected=\"selected\"" :""; ?>>
<?=htmlspecialchars($ifacename);?>
</option>
<?php
endforeach; ?>
</select>
</td>
</tr>
<tr>
<td><?=gettext("IP Address(es)");?></td>
<td></td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Type:");?></td>
<td>
<select name="type" class="selectpicker" data-width="auto" id="type">
<option value="single" <?=(!empty($pconfig['subnet_bits']) && $pconfig['subnet_bits'] == 32) || !isset($pconfig['subnet']) ? "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>
</select>
</td>
</tr>
<tr>
<td><a id="help_for_address" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Address:");?></td>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<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\""; ?>>
<?=$i;?>
</option>
<?php
endfor; ?>
</select>
</td>
</tr>
</table>
<div class="hidden" for="help_for_address">
<i id="typenote"></i>
</div>
</td>
</tr>
<tr id="noexpandrow">
<td><a id="help_for_noexpand" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Expansion:");?> </td>
<td>
<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>
</tr>
<tr>
<td><a id="help_for_vhid" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("VHID Group");?></td>
<td>
<select id='vhid' name='vhid' class="selectpicker" data-size="10" data-width="auto">
<?php for ($i = 1; $i <= 255; $i++): ?>
<option value="<?=$i;?>" <?= $i == $pconfig['vhid'] ? "selected=\"selected\"" : ""; ?>>
<?=$i;?>
</option>
<?php endfor; ?>
</select>
<div class="hidden" for="help_for_vhid">
<?=gettext("Enter the VHID group that the machines will share");?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_adv" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Advertising Frequency");?></td>
<td>
<?=gettext("Base");?>:
<select id='advbase' name='advbase' class="selectpicker" data-size="10" data-width="auto">
<?php for ($i = 1; $i <= 254; $i++): ?>
<option value="<?=$i;?>" <?=$i == $pconfig['advbase'] ? "selected=\"selected\"" :""; ?>>
<?=$i;?>
</option>
<?php endfor; ?>
</select>
<?=gettext("Skew");?>:
<select id='advskew' name='advskew' class="selectpicker" data-size="10" data-width="auto">
<?php for ($i = 0; $i <= 254; $i++): ?>
<option value="<?=$i;?>" <?php if ($i == $pconfig['advskew']) echo "selected=\"selected\""; ?>>
<?=$i;?>
</option>
<?php endfor; ?>
</select>
<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.");?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_descr" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description");?></td>
<td>
<input name="descr" type="text" class="form-control unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
<div class="hidden" for="help_for_adv">
<?=gettext("You may enter a description here for your reference (not parsed).");?>
</div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<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='<?=(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_virtual_ip.php');?>'" />
<?php if (isset($id) && $a_vip[$id]): ?>
<input name="id" type="hidden" value="<?=$id;?>" />
<?php endif; ?>
</td>
</tr>
</tbody>
</table>
</div>
</form>
<div class="container-fluid">
<span class="text-danger">
<strong><?=gettext("Note:");?><br /></strong>
</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.");?>
<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>.
</div>
</div>
</section>
</div>
</div>
</section>
<?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