diff options
author | Renato Botelho <garga@FreeBSD.org> | 2015-05-30 09:57:46 -0300 |
---|---|---|
committer | Renato Botelho <garga@FreeBSD.org> | 2015-05-30 09:57:46 -0300 |
commit | b033e2977831381ece15c21708b7765496d59b57 (patch) | |
tree | 4bc2a2a364e2f06cc3c7087d1f324f16da5cf837 /usr/local | |
parent | 5d15bda8a30dc5bff4e530163b0f130d1c5fa21b (diff) | |
parent | e0c7b2feb9ccabdb54d885679666d7cdb90d9ccf (diff) | |
download | pfsense-b033e2977831381ece15c21708b7765496d59b57.zip pfsense-b033e2977831381ece15c21708b7765496d59b57.tar.gz |
Merge pull request #1699 from phil-davis/system-g
Diffstat (limited to 'usr/local')
-rw-r--r-- | usr/local/www/system_gateway_groups.php | 202 | ||||
-rw-r--r-- | usr/local/www/system_gateway_groups_edit.php | 323 | ||||
-rw-r--r-- | usr/local/www/system_gateways.php | 51 | ||||
-rw-r--r-- | usr/local/www/system_gateways_edit.php | 326 | ||||
-rw-r--r-- | usr/local/www/system_groupmanager.php | 110 | ||||
-rw-r--r-- | usr/local/www/system_groupmanager_addprivs.php | 108 |
6 files changed, 627 insertions, 493 deletions
diff --git a/usr/local/www/system_gateway_groups.php b/usr/local/www/system_gateway_groups.php index 5de3930..aeb0bad 100644 --- a/usr/local/www/system_gateway_groups.php +++ b/usr/local/www/system_gateway_groups.php @@ -46,8 +46,9 @@ require_once("filter.inc"); require_once("shaper.inc"); require_once("openvpn.inc"); -if (!is_array($config['gateways']['gateway_group'])) +if (!is_array($config['gateways']['gateway_group'])) { $config['gateways']['gateway_group'] = array(); +} $a_gateway_groups = &$config['gateways']['gateway_group']; $a_gateways = &$config['gateways']['gateway_item']; @@ -68,8 +69,9 @@ if ($_POST) { setup_gateways_monitor(); $savemsg = get_std_save_message($retval); - if ($retval == 0) + if ($retval == 0) { clear_subsystem_dirty('staticroutes'); + } foreach ($a_gateway_groups as $gateway_group) { $gw_subsystem = 'gwgroup.' . $gateway_group['name']; @@ -85,8 +87,9 @@ if ($_GET['act'] == "del") { if ($a_gateway_groups[$_GET['id']]) { $changedesc .= gettext("removed gateway group") . " {$_GET['id']}"; foreach ($config['filter']['rule'] as $idx => $rule) { - if ($rule['gateway'] == $a_gateway_groups[$_GET['id']]['name']) + if ($rule['gateway'] == $a_gateway_groups[$_GET['id']]['name']) { unset($config['filter']['rule'][$idx]['gateway']); + } } unset($a_gateway_groups[$_GET['id']]); write_config($changedesc); @@ -96,7 +99,7 @@ if ($_GET['act'] == "del") { } } -$pgtitle = array(gettext("System"),gettext("Gateway Groups")); +$pgtitle = array(gettext("System"), gettext("Gateway Groups")); $shortcut_section = "gateway-groups"; include("head.inc"); @@ -111,9 +114,9 @@ include("head.inc"); <?php if (is_subsystem_dirty('staticroutes')): ?><br/> <?php print_info_box_np(sprintf(gettext("The gateway configuration has been changed.%sYou must apply the changes in order for them to take effect."), "<br />"));?><br /><br /> <?php endif; ?> - <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system groups"> - <tr> - <td> +<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="system groups"> + <tr> + <td> <?php $tab_array = array(); $tab_array[0] = array(gettext("Gateways"), false, "system_gateways.php"); @@ -121,89 +124,112 @@ include("head.inc"); $tab_array[2] = array(gettext("Groups"), true, "system_gateway_groups.php"); display_top_tabs($tab_array); ?> -</td></tr> - <tr> - <td> - <div id="mainarea"> - <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area"> - <thead> - <tr> - <td width="15%" class="listhdrr"><?=gettext("Group Name");?></td> - <td width="15%" class="listhdrr"><?=gettext("Gateways");?></td> - <td width="20%" class="listhdrr"><?=gettext("Priority");?></td> - <td width="30%" class="listhdr"><?=gettext("Description");?></td> - <td width="10%" class="list"> - <table border="0" cellspacing="0" cellpadding="1" summary="icons"> - <tr> - <td width="17"></td> - <td><a href="system_gateway_groups_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" /></a></td> - </tr> - </table> - </td> - </tr> - </thead> - <tfoot> - <tr><td class="list" colspan="4"></td> - <td class="list"> - <table border="0" cellspacing="0" cellpadding="1" summary="edit"> - <tr> - <td width="17"></td> - <td><a href="system_gateway_groups_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" /></a></td> - </tr> - </table> - </td> - </tr> - </tfoot> - <tbody> - <?php $i = 0; foreach ($a_gateway_groups as $gateway_group): ?> - <tr> - <td class="listlr" ondblclick="document.location='system_gateway_groups_edit.php?id=<?=$i;?>';"> - <?php - echo $gateway_group['name']; - ?> - </td> - <td class="listr" ondblclick="document.location='system_gateway_groups_edit.php?id=<?=$i;?>';"> - <?php - foreach($gateway_group['item'] as $item) { - $itemsplit = explode("|", $item); - echo htmlspecialchars(strtoupper($itemsplit[0])) . "<br />\n"; - } - ?> - </td> - <td class="listr" ondblclick="document.location='system_gateway_groups_edit.php?id=<?=$i;?>';"> - <?php - foreach($gateway_group['item'] as $item) { - $itemsplit = explode("|", $item); - echo "Tier ". htmlspecialchars($itemsplit[1]) . "<br />\n"; - } - ?> - </td> - <td class="listbg" ondblclick="document.location='system_gateway_groups_edit.php?id=<?=$i;?>';"> - <?=htmlspecialchars($gateway_group['descr']);?> - </td> - <td valign="middle" class="list nowrap"> - <table border="0" cellspacing="0" cellpadding="1" summary="edit"> - <tr> - <td><a href="system_gateway_groups_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="edit" /></a></td> - <td><a href="system_gateway_groups.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this gateway group?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" /></a></td> - </tr> - <tr> - <td width="17"></td> - <td><a href="system_gateway_groups_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="duplicate" /></a></td> - </tr> - </table> - </td> - </tr> - <?php $i++; endforeach; ?> - <tr style="display:none;"><td></td></tr> - </tbody> + </td> + </tr> + <tr> + <td> + <div id="mainarea"> + <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area"> + <thead> + <tr> + <td width="15%" class="listhdrr"><?=gettext("Group Name");?></td> + <td width="15%" class="listhdrr"><?=gettext("Gateways");?></td> + <td width="20%" class="listhdrr"><?=gettext("Priority");?></td> + <td width="30%" class="listhdr"><?=gettext("Description");?></td> + <td width="10%" class="list"> + <table border="0" cellspacing="0" cellpadding="1" summary="icons"> + <tr> + <td width="17"></td> + <td> + <a href="system_gateway_groups_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" /></a> + </td> + </tr> + </table> + </td> + </tr> + </thead> + <tfoot> + <tr> + <td class="list" colspan="4"></td> + <td class="list"> + <table border="0" cellspacing="0" cellpadding="1" summary="edit"> + <tr> + <td width="17"></td> + <td> + <a href="system_gateway_groups_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="edit" /></a> + </td> + </tr> + </table> + </td> + </tr> + </tfoot> + <tbody> +<?php + $i = 0; + foreach ($a_gateway_groups as $gateway_group): +?> + <tr> + <td class="listlr" ondblclick="document.location='system_gateway_groups_edit.php?id=<?=$i;?>';"> + <?php + echo $gateway_group['name']; + ?> + </td> + <td class="listr" ondblclick="document.location='system_gateway_groups_edit.php?id=<?=$i;?>';"> + <?php + foreach ($gateway_group['item'] as $item) { + $itemsplit = explode("|", $item); + echo htmlspecialchars(strtoupper($itemsplit[0])) . "<br />\n"; + } + ?> + </td> + <td class="listr" ondblclick="document.location='system_gateway_groups_edit.php?id=<?=$i;?>';"> + <?php + foreach ($gateway_group['item'] as $item) { + $itemsplit = explode("|", $item); + echo "Tier ". htmlspecialchars($itemsplit[1]) . "<br />\n"; + } + ?> + </td> + <td class="listbg" ondblclick="document.location='system_gateway_groups_edit.php?id=<?=$i;?>';"> + <?=htmlspecialchars($gateway_group['descr']);?> + </td> + <td valign="middle" class="list nowrap"> + <table border="0" cellspacing="0" cellpadding="1" summary="edit"> + <tr> + <td> + <a href="system_gateway_groups_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="edit" /></a> + </td> + <td> + <a href="system_gateway_groups.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this gateway group?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" /></a> + </td> + </tr> + <tr> + <td width="17"></td> + <td> + <a href="system_gateway_groups_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="duplicate" /></a> + </td> + </tr> + </table> + </td> + </tr> +<?php + $i++; + endforeach; +?> + <tr style="display:none;"> + <td></td> + </tr> + </tbody> </table> </div> - </td> - </tr> - </table> - </form> - <p><b><?=gettext("Note:");?></b> <?=gettext("Remember to use these Gateway Groups in firewall rules in order to enable load balancing, failover, or policy-based routing. Without rules directing traffic into the Gateway Groups, they will not be used.");?></p> + </td> + </tr> +</table> +</form> +<p> + <b><?=gettext("Note:");?></b> + <?=gettext("Remember to use these Gateway Groups in firewall rules in order to enable load balancing, failover, or policy-based routing. Without rules directing traffic into the Gateway Groups, they will not be used.");?> +</p> <?php include("fend.inc"); ?> </body> </html> diff --git a/usr/local/www/system_gateway_groups_edit.php b/usr/local/www/system_gateway_groups_edit.php index 01dede2..81b6dfa 100644 --- a/usr/local/www/system_gateway_groups_edit.php +++ b/usr/local/www/system_gateway_groups_edit.php @@ -1,23 +1,23 @@ -<?php +<?php /* $Id$ */ /* system_gateway_groups_edit.php part of pfSense (https://www.pfsense.org) - + Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>. Copyright (C) 2013-2015 Electric Sheep Fencing, LP 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 @@ -46,24 +46,29 @@ require_once("vpn.inc"); $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_gateway_groups.php'); -if (!is_array($config['gateways']['gateway_group'])) +if (!is_array($config['gateways']['gateway_group'])) { $config['gateways']['gateway_group'] = array(); +} $a_gateway_groups = &$config['gateways']['gateway_group']; $a_gateways = return_gateways_array(); -$categories = array('down' => gettext("Member Down"), - 'downloss' => gettext("Packet Loss"), - 'downlatency' => gettext("High Latency"), - 'downlosslatency' => gettext("Packet Loss or High Latency")); +$categories = array( + 'down' => gettext("Member Down"), + 'downloss' => gettext("Packet Loss"), + 'downlatency' => gettext("High Latency"), + 'downlosslatency' => gettext("Packet Loss or High Latency")); -if (is_numericint($_GET['id'])) +if (is_numericint($_GET['id'])) { $id = $_GET['id']; -if (isset($_POST['id']) && is_numericint($_POST['id'])) +} +if (isset($_POST['id']) && is_numericint($_POST['id'])) { $id = $_POST['id']; +} -if (isset($_GET['dup']) && is_numericint($_GET['dup'])) +if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { $id = $_GET['dup']; +} if (isset($id) && $a_gateway_groups[$id]) { $pconfig['name'] = $a_gateway_groups[$id]['name']; @@ -72,8 +77,9 @@ if (isset($id) && $a_gateway_groups[$id]) { $pconfig['trigger'] = $a_gateway_groups[$id]['trigger']; } -if (isset($_GET['dup']) && is_numericint($_GET['dup'])) +if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { unset($id); +} if ($_POST) { @@ -83,23 +89,24 @@ if ($_POST) { /* input validation */ $reqdfields = explode(" ", "name"); $reqdfieldsn = explode(",", "Name"); - + do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - - if (! isset($_POST['name'])) { + + if (!isset($_POST['name'])) { $input_errors[] = gettext("A valid gateway group name must be specified."); } - if (! is_validaliasname($_POST['name'])) { + if (!is_validaliasname($_POST['name'])) { $input_errors[] = gettext("The gateway name must not contain invalid characters."); } if (isset($_POST['name'])) { /* check for overlaps */ - if(is_array($a_gateway_groups)) { + if (is_array($a_gateway_groups)) { foreach ($a_gateway_groups as $gateway_group) { if (isset($id) && ($a_gateway_groups[$id]) && ($a_gateway_groups[$id] === $gateway_group)) { - if ($gateway_group['name'] != $_POST['name']) + if ($gateway_group['name'] != $_POST['name']) { $input_errors[] = gettext("Changing name on a gateway group is not allowed."); + } continue; } @@ -113,19 +120,21 @@ if ($_POST) { /* Build list of items in group with priority */ $pconfig['item'] = array(); - foreach($a_gateways as $gwname => $gateway) { - if($_POST[$gwname] > 0) { + foreach ($a_gateways as $gwname => $gateway) { + if ($_POST[$gwname] > 0) { $vipname = "{$gwname}_vip"; /* we have a priority above 0 (disabled), add item to list */ $pconfig['item'][] = "{$gwname}|{$_POST[$gwname]}|{$_POST[$vipname]}"; } /* check for overlaps */ - if ($_POST['name'] == $gwname) + if ($_POST['name'] == $gwname) { $input_errors[] = sprintf(gettext('A gateway group cannot have the same name with a gateway "%s" please choose another name.'), $_POST['name']); + } } - if(count($pconfig['item']) == 0) + if (count($pconfig['item']) == 0) { $input_errors[] = gettext("No gateway(s) have been selected to be used in this group"); + } if (!$input_errors) { $gateway_group = array(); @@ -134,22 +143,23 @@ if ($_POST) { $gateway_group['trigger'] = $_POST['trigger']; $gateway_group['descr'] = $_POST['descr']; - if (isset($id) && $a_gateway_groups[$id]) + if (isset($id) && $a_gateway_groups[$id]) { $a_gateway_groups[$id] = $gateway_group; - else + } else { $a_gateway_groups[] = $gateway_group; - + } + mark_subsystem_dirty('staticroutes'); mark_subsystem_dirty('gwgroup.' . $gateway_group['name']); - + write_config(); - + header("Location: system_gateway_groups.php"); exit; } } -$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway group")); +$pgtitle = array(gettext("System"), gettext("Gateways"), gettext("Edit gateway group")); $shortcut_section = "gateway-groups"; function build_gateway_protocol_map (&$a_gateways) { @@ -189,8 +199,7 @@ jQuery(function ($) { if (value !== '0' /* i.e., an option is selected */) { if (which_protocol_to_show === undefined) { which_protocol_to_show = protocol; - } - else if (which_protocol_to_show !== protocol) { + } else if (which_protocol_to_show !== protocol) { which_protocol_to_show = 'ALL OF THEM'; // this shouldn't happen } } @@ -225,131 +234,139 @@ jQuery(function ($) { <?php include("fbegin.inc"); ?> <?php if ($input_errors) print_input_errors($input_errors); ?> - <form action="system_gateway_groups_edit.php" method="post" name="iform" id="iform"> - <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="system groups edit"> +<form action="system_gateway_groups_edit.php" method="post" name="iform" id="iform"> + <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="system groups edit"> <tr> <td colspan="2" valign="top" class="listtopic"><?=gettext("Edit gateway group entry"); ?></td> - </tr> - <tr> - <td width="22%" valign="top" class="vncellreq"><?=gettext("Group Name"); ?></td> - <td width="78%" class="vtable"> - <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" /> - <br /> <span class="vexpl"><?=gettext("Group Name"); ?></span></td> - </tr> + </tr> <tr> - <td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway Priority"); ?></td> - <td width="78%" class="vtable"> - <table border="0" cellpadding="6" cellspacing="0" summary="gateway priority"> - <tr> - <td class="listhdrr">Gateway</td> - <td class="listhdrr">Tier</td> - <td class="listhdrr">Virtual IP</td> - <td class="listhdrr">Description</td> - </tr> - <?php - $carplist = get_configured_carp_interface_list($interface); - foreach($a_gateways as $gwname => $gateway) { - if(!empty($pconfig['item'])) { - $af = explode("|", $pconfig['item'][0]); - $family = $a_gateways[$af[0]]['ipprotocol']; - if($gateway['ipprotocol'] != $family) - continue; - } - $interface = $gateway['friendlyiface']; - $selected = array(); - foreach((array)$pconfig['item'] as $item) { - $itemsplit = explode("|", $item); - if($itemsplit[0] == $gwname) { - $selected[$itemsplit[1]] = "selected=\"selected\""; - break; - } else { - $selected[0] = "selected=\"selected\""; - } - } - $tr_id = $gwname . "_row"; - echo "<tr class='gateway_row' id='{$tr_id}'>\n"; - echo "<td class='listlr'>"; - echo "<strong>{$gateway['name']} </strong>"; - echo "</td><td class='listr'>"; - echo "<select name='{$gwname}' class='gateway_tier_selector formfldselect' id='{$gwname}'>\n"; - echo "<option value='0' $selected[0] >" . gettext("Never") . "</option>\n"; - echo "<option value='1' $selected[1] >" . gettext("Tier 1") . "</option>\n"; - echo "<option value='2' $selected[2] >" . gettext("Tier 2") . "</option>\n"; - echo "<option value='3' $selected[3] >" . gettext("Tier 3") . "</option>\n"; - echo "<option value='4' $selected[4] >" . gettext("Tier 4") . "</option>\n"; - echo "<option value='5' $selected[5] >" . gettext("Tier 5") . "</option>\n"; - echo "</select>\n"; - echo "</td>"; - - $selected = array(); - foreach((array)$pconfig['item'] as $item) { - $itemsplit = explode("|", $item); - if($itemsplit[0] == $gwname) { - $selected[$itemsplit[2]] = "selected=\"selected\""; - break; - } else { - $selected['address'] = "selected=\"selected\""; + <td width="22%" valign="top" class="vncellreq"><?=gettext("Group Name"); ?></td> + <td width="78%" class="vtable"> + <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" /> + <br /> <span class="vexpl"><?=gettext("Group Name"); ?></span> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway Priority"); ?></td> + <td width="78%" class="vtable"> + <table border="0" cellpadding="6" cellspacing="0" summary="gateway priority"> + <tr> + <td class="listhdrr">Gateway</td> + <td class="listhdrr">Tier</td> + <td class="listhdrr">Virtual IP</td> + <td class="listhdrr">Description</td> + </tr> + <?php + $carplist = get_configured_carp_interface_list($interface); + foreach ($a_gateways as $gwname => $gateway) { + if (!empty($pconfig['item'])) { + $af = explode("|", $pconfig['item'][0]); + $family = $a_gateways[$af[0]]['ipprotocol']; + if ($gateway['ipprotocol'] != $family) { + continue; + } + } + $interface = $gateway['friendlyiface']; + $selected = array(); + foreach ((array)$pconfig['item'] as $item) { + $itemsplit = explode("|", $item); + if ($itemsplit[0] == $gwname) { + $selected[$itemsplit[1]] = "selected=\"selected\""; + break; + } else { + $selected[0] = "selected=\"selected\""; + } + } + $tr_id = $gwname . "_row"; + echo "<tr class='gateway_row' id='{$tr_id}'>\n"; + echo "<td class='listlr'>"; + echo "<strong>{$gateway['name']} </strong>"; + echo "</td><td class='listr'>"; + echo "<select name='{$gwname}' class='gateway_tier_selector formfldselect' id='{$gwname}'>\n"; + echo "<option value='0' $selected[0] >" . gettext("Never") . "</option>\n"; + echo "<option value='1' $selected[1] >" . gettext("Tier 1") . "</option>\n"; + echo "<option value='2' $selected[2] >" . gettext("Tier 2") . "</option>\n"; + echo "<option value='3' $selected[3] >" . gettext("Tier 3") . "</option>\n"; + echo "<option value='4' $selected[4] >" . gettext("Tier 4") . "</option>\n"; + echo "<option value='5' $selected[5] >" . gettext("Tier 5") . "</option>\n"; + echo "</select>\n"; + echo "</td>"; + + $selected = array(); + foreach ((array)$pconfig['item'] as $item) { + $itemsplit = explode("|", $item); + if ($itemsplit[0] == $gwname) { + $selected[$itemsplit[2]] = "selected=\"selected\""; + break; + } else { + $selected['address'] = "selected=\"selected\""; + } + } + echo "<td class='listr'>"; + echo "<select name='{$gwname}_vip' class='gateway_vip_selector formfldselect' id='{$gwname}_vip'>\n"; + echo "<option value='address' {$selected['address']} >" . gettext("Interface Address") . "</option>\n"; + foreach ($carplist as $vip => $address) { + echo "<!-- $vip - $address - $interface -->\n"; + if (($gateway['ipprotocol'] == "inet") && (!is_ipaddrv4($address))) { + continue; + } + if (($gateway['ipprotocol'] == "inet6") && (!is_ipaddrv6($address))) { + continue; + } + echo "<option value='{$vip}' $selected[$vip] >$vip - $address</option>\n"; + } + echo "</select></td>"; + echo "<td class='listr'><strong>{$gateway['descr']} </strong>"; + echo "</td></tr>"; + } + ?> + </table> + <br /><span class="vexpl"> + <strong><?=gettext("Link Priority"); ?></strong> <br /> + <?=gettext("The priority selected here defines in what order failover and balancing of links will be done. " . + "Multiple links of the same priority will balance connections until all links in the priority will be exhausted. " . + "If all links in a priority level are exhausted we will use the next available link(s) in the next priority level.") ?> + <br /> + <strong><?=gettext("Virtual IP"); ?></strong> <br /> + <?=gettext("The virtual IP field selects what (virtual) IP should be used when this group applies to a local Dynamic DNS, IPsec or OpenVPN endpoint") ?> + </span><br /> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncellreq"><?=gettext("Trigger Level"); ?></td> + <td width="78%" class="vtable"> + <select name='trigger' class='formfldselect trigger_level_selector' id='trigger'> + <?php + foreach ($categories as $category => $categoryd) { + echo "<option value=\"$category\""; + if ($category == $pconfig['trigger']) { + echo " selected=\"selected\""; + } + echo ">" . htmlspecialchars($categoryd) . "</option>\n"; } - } - echo "<td class='listr'>"; - echo "<select name='{$gwname}_vip' class='gateway_vip_selector formfldselect' id='{$gwname}_vip'>\n"; - echo "<option value='address' {$selected['address']} >" . gettext("Interface Address") . "</option>\n"; - foreach($carplist as $vip => $address) { - echo "<!-- $vip - $address - $interface -->\n"; - if(($gateway['ipprotocol'] == "inet") && (!is_ipaddrv4($address))) - continue; - if(($gateway['ipprotocol'] == "inet6") && (!is_ipaddrv6($address))) - continue; - echo "<option value='{$vip}' $selected[$vip] >$vip - $address</option>\n"; - } - echo "</select></td>"; - echo "<td class='listr'><strong>{$gateway['descr']} </strong>"; - echo "</td></tr>"; - } - ?> - </table> - <br /><span class="vexpl"> - <strong><?=gettext("Link Priority"); ?></strong> <br /> - <?=gettext("The priority selected here defines in what order failover and balancing of links will be done. " . - "Multiple links of the same priority will balance connections until all links in the priority will be exhausted. " . - "If all links in a priority level are exhausted we will use the next available link(s) in the next priority level.") ?> - <br /> - <strong><?=gettext("Virtual IP"); ?></strong> <br /> - <?=gettext("The virtual IP field selects what (virtual) IP should be used when this group applies to a local Dynamic DNS, IPsec or OpenVPN endpoint") ?> - </span><br /> - </td> - </tr> - <tr> - <td width="22%" valign="top" class="vncellreq"><?=gettext("Trigger Level"); ?></td> - <td width="78%" class="vtable"> - <select name='trigger' class='formfldselect trigger_level_selector' id='trigger'> - <?php - foreach ($categories as $category => $categoryd) { - echo "<option value=\"$category\""; - if ($category == $pconfig['trigger']) echo " selected=\"selected\""; - echo ">" . htmlspecialchars($categoryd) . "</option>\n"; - } - ?> - </select> - <br /> <span class="vexpl"><?=gettext("When to trigger exclusion of a member"); ?></span></td> - </tr> + ?> + </select> + <br /> <span class="vexpl"><?=gettext("When to trigger exclusion of a member"); ?></span> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td> + <td width="78%" class="vtable"> + <input name="descr" type="text" class="formfld 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" class="vncell"><?=gettext("Description"); ?></td> - <td width="78%" class="vtable"> - <input name="descr" type="text" class="formfld 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"> </td> - <td width="78%"> - <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> - <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" /> - <?php if (isset($id) && $a_gateway_groups[$id]): ?> - <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" /> - <?php endif; ?> - </td> - </tr> - </table> + <td width="22%" valign="top"> </td> + <td width="78%"> + <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> + <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" /> + <?php if (isset($id) && $a_gateway_groups[$id]): ?> + <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" /> + <?php endif; ?> + </td> + </tr> + </table> </form> <?php include("fend.inc"); ?> </body> diff --git a/usr/local/www/system_gateways.php b/usr/local/www/system_gateways.php index 1f1efc2..0e21706 100644 --- a/usr/local/www/system_gateways.php +++ b/usr/local/www/system_gateways.php @@ -47,12 +47,14 @@ require_once("shaper.inc"); $a_gateways = return_gateways_array(true, false, true); $a_gateways_arr = array(); -foreach ($a_gateways as $gw) +foreach ($a_gateways as $gw) { $a_gateways_arr[] = $gw; +} $a_gateways = $a_gateways_arr; -if (!is_array($config['gateways']['gateway_item'])) +if (!is_array($config['gateways']['gateway_item'])) { $config['gateways']['gateway_item'] = array(); +} $a_gateway_item = &$config['gateways']['gateway_item']; @@ -70,16 +72,18 @@ if ($_POST) { setup_gateways_monitor(); $savemsg = get_std_save_message($retval); - if ($retval == 0) + if ($retval == 0) { clear_subsystem_dirty('staticroutes'); + } } } function can_delete_gateway_item($id) { global $config, $input_errors, $a_gateways; - if (!isset($a_gateways[$id])) + if (!isset($a_gateways[$id])) { return false; + } if (is_array($config['gateways']['gateway_group'])) { foreach ($config['gateways']['gateway_group'] as $group) { @@ -102,8 +106,9 @@ function can_delete_gateway_item($id) { } } - if (isset($input_errors)) + if (isset($input_errors)) { return false; + } return true; } @@ -111,22 +116,25 @@ function can_delete_gateway_item($id) { function delete_gateway_item($id) { global $config, $a_gateways; - if (!isset($a_gateways[$id])) + if (!isset($a_gateways[$id])) { return; + } /* NOTE: Cleanup static routes for the monitor ip if any */ if (!empty($a_gateways[$id]['monitor']) && - $a_gateways[$id]['monitor'] != "dynamic" && - is_ipaddr($a_gateways[$id]['monitor']) && - $a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) { - if (is_ipaddrv4($a_gateways[$id]['monitor'])) + $a_gateways[$id]['monitor'] != "dynamic" && + is_ipaddr($a_gateways[$id]['monitor']) && + $a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) { + if (is_ipaddrv4($a_gateways[$id]['monitor'])) { mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor'])); - else + } else { mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor'])); + } } - if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) + if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) { unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']); + } unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]); } @@ -145,9 +153,11 @@ if ($_GET['act'] == "del") { if (isset($_POST['del_x'])) { /* delete selected items */ if (is_array($_POST['rule']) && count($_POST['rule'])) { - foreach ($_POST['rule'] as $rulei) - if(!can_delete_gateway_item($rulei)) + foreach ($_POST['rule'] as $rulei) { + if (!can_delete_gateway_item($rulei)) { break; + } + } if (!isset($input_errors)) { $items_deleted = ""; @@ -167,19 +177,21 @@ if (isset($_POST['del_x'])) { } else if ($_GET['act'] == "toggle" && $a_gateways[$_GET['id']]) { $realid = $a_gateways[$_GET['id']]['attribute']; - if(isset($a_gateway_item[$realid]['disabled'])) + if (isset($a_gateway_item[$realid]['disabled'])) { unset($a_gateway_item[$realid]['disabled']); - else + } else { $a_gateway_item[$realid]['disabled'] = true; + } - if (write_config("Gateways: enable/disable")) + if (write_config("Gateways: enable/disable")) { mark_subsystem_dirty('staticroutes'); + } header("Location: system_gateways.php"); exit; } -$pgtitle = array(gettext("System"),gettext("Gateways")); +$pgtitle = array(gettext("System"), gettext("Gateways")); $shortcut_section = "gateways"; include("head.inc"); @@ -284,8 +296,9 @@ include("head.inc"); <?php echo $textss; echo $gateway['name']; - if(isset($gateway['defaultgw'])) + if (isset($gateway['defaultgw'])) { echo " <strong>(default)</strong>"; + } echo $textse; ?> </td> diff --git a/usr/local/www/system_gateways_edit.php b/usr/local/www/system_gateways_edit.php index 8432e60..12958ec 100644 --- a/usr/local/www/system_gateways_edit.php +++ b/usr/local/www/system_gateways_edit.php @@ -47,24 +47,28 @@ $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/syste $a_gateways = return_gateways_array(true, false, true); $a_gateways_arr = array(); -foreach($a_gateways as $gw) { +foreach ($a_gateways as $gw) { $a_gateways_arr[] = $gw; } $a_gateways = $a_gateways_arr; -if (!is_array($config['gateways']['gateway_item'])) +if (!is_array($config['gateways']['gateway_item'])) { $config['gateways']['gateway_item'] = array(); +} $a_gateway_item = &$config['gateways']['gateway_item']; $apinger_default = return_apinger_defaults(); -if (is_numericint($_GET['id'])) +if (is_numericint($_GET['id'])) { $id = $_GET['id']; -if (isset($_POST['id']) && is_numericint($_POST['id'])) +} +if (isset($_POST['id']) && is_numericint($_POST['id'])) { $id = $_POST['id']; +} -if (isset($_GET['dup']) && is_numericint($_GET['dup'])) +if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { $id = $_GET['dup']; +} if (isset($id) && $a_gateways[$id]) { $pconfig = array(); @@ -80,8 +84,9 @@ if (isset($id) && $a_gateways[$id]) { $pconfig['interface'] = $a_gateways[$id]['interface']; $pconfig['friendlyiface'] = $a_gateways[$id]['friendlyiface']; $pconfig['ipprotocol'] = $a_gateways[$id]['ipprotocol']; - if (isset($a_gateways[$id]['dynamic'])) + if (isset($a_gateways[$id]['dynamic'])) { $pconfig['dynamic'] = true; + } $pconfig['gateway'] = $a_gateways[$id]['gateway']; $pconfig['defaultgw'] = isset($a_gateways[$id]['defaultgw']); $pconfig['force_down'] = isset($a_gateways[$id]['force_down']); @@ -102,8 +107,9 @@ if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { unset($pconfig['attribute']); } -if (isset($id) && $a_gateways[$id]) +if (isset($id) && $a_gateways[$id]) { $realid = $a_gateways[$id]['attribute']; +} if ($_POST) { @@ -115,10 +121,10 @@ if ($_POST) { do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - if (! isset($_POST['name'])) { + if (!isset($_POST['name'])) { $input_errors[] = "A valid gateway name must be specified."; } - if (! is_validaliasname($_POST['name'])) { + if (!is_validaliasname($_POST['name'])) { $input_errors[] = gettext("The gateway name must not contain invalid characters."); } /* skip system gateways which have been automatically added */ @@ -127,69 +133,78 @@ if ($_POST) { } if ($_POST['gateway'] && (is_ipaddr($_POST['gateway'])) && !$_REQUEST['isAjax']) { - if(is_ipaddrv4($_POST['gateway'])) { + if (is_ipaddrv4($_POST['gateway'])) { $parent_ip = get_interface_ip($_POST['interface']); $parent_sn = get_interface_subnet($_POST['interface']); - if(empty($parent_ip) || empty($parent_sn)) { + if (empty($parent_ip) || empty($parent_sn)) { $input_errors[] = gettext("Cannot add IPv4 Gateway Address because no IPv4 address could be found on the interface."); } else { $subnets = array(gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn); $vips = link_interface_to_vips($_POST['interface']); - if (is_array($vips)) - foreach($vips as $vip) { - if (!is_ipaddrv4($vip['subnet'])) + if (is_array($vips)) { + foreach ($vips as $vip) { + if (!is_ipaddrv4($vip['subnet'])) { continue; + } $subnets[] = gen_subnet($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits']; } + } $found = false; - foreach($subnets as $subnet) - if(ip_in_subnet($_POST['gateway'], $subnet)) { + foreach ($subnets as $subnet) { + if (ip_in_subnet($_POST['gateway'], $subnet)) { $found = true; break; } + } - if ($found === false) + if ($found === false) { $input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $_POST['gateway']); + } } - } - else if(is_ipaddrv6($_POST['gateway'])) { + } else if (is_ipaddrv6($_POST['gateway'])) { /* do not do a subnet match on a link local address, it's valid */ - if(!is_linklocal($_POST['gateway'])) { + if (!is_linklocal($_POST['gateway'])) { $parent_ip = get_interface_ipv6($_POST['interface']); $parent_sn = get_interface_subnetv6($_POST['interface']); - if(empty($parent_ip) || empty($parent_sn)) { + if (empty($parent_ip) || empty($parent_sn)) { $input_errors[] = gettext("Cannot add IPv6 Gateway Address because no IPv6 address could be found on the interface."); } else { $subnets = array(gen_subnetv6($parent_ip, $parent_sn) . "/" . $parent_sn); $vips = link_interface_to_vips($_POST['interface']); - if (is_array($vips)) - foreach($vips as $vip) { - if (!is_ipaddrv6($vip['subnet'])) + if (is_array($vips)) { + foreach ($vips as $vip) { + if (!is_ipaddrv6($vip['subnet'])) { continue; + } $subnets[] = gen_subnetv6($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits']; } + } $found = false; - foreach($subnets as $subnet) - if(ip_in_subnet($_POST['gateway'], $subnet)) { + foreach ($subnets as $subnet) { + if (ip_in_subnet($_POST['gateway'], $subnet)) { $found = true; break; } + } - if ($found === false) + if ($found === false) { $input_errors[] = sprintf(gettext("The gateway address %1\$s does not lie within one of the chosen interface's subnets."), $_POST['gateway']); + } } } } if (!empty($config['interfaces'][$_POST['interface']]['ipaddr'])) { - if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddr']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic")) + if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddr']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic")) { $input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv4 configuration."); + } } if (!empty($config['interfaces'][$_POST['interface']]['ipaddrv6'])) { - if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddrv6']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic")) + if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddrv6']) && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic")) { $input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static IPv6 configuration."); + } } } if (($_POST['monitor'] <> "") && !is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") { @@ -197,19 +212,19 @@ if ($_POST) { } /* only allow correct IPv4 and IPv6 gateway addresses */ if (($_POST['gateway'] <> "") && is_ipaddr($_POST['gateway']) && $_POST['gateway'] != "dynamic") { - if(is_ipaddrv6($_POST['gateway']) && ($_POST['ipprotocol'] == "inet")) { + if (is_ipaddrv6($_POST['gateway']) && ($_POST['ipprotocol'] == "inet")) { $input_errors[] = gettext("The IPv6 gateway address '{$_POST['gateway']}' can not be used as a IPv4 gateway'."); } - if(is_ipaddrv4($_POST['gateway']) && ($_POST['ipprotocol'] == "inet6")) { + if (is_ipaddrv4($_POST['gateway']) && ($_POST['ipprotocol'] == "inet6")) { $input_errors[] = gettext("The IPv4 gateway address '{$_POST['gateway']}' can not be used as a IPv6 gateway'."); } } /* only allow correct IPv4 and IPv6 monitor addresses */ if (($_POST['monitor'] <> "") && is_ipaddr($_POST['monitor']) && $_POST['monitor'] != "dynamic") { - if(is_ipaddrv6($_POST['monitor']) && ($_POST['ipprotocol'] == "inet")) { + if (is_ipaddrv6($_POST['monitor']) && ($_POST['ipprotocol'] == "inet")) { $input_errors[] = gettext("The IPv6 monitor address '{$_POST['monitor']}' can not be used on a IPv4 gateway'."); } - if(is_ipaddrv4($_POST['monitor']) && ($_POST['ipprotocol'] == "inet6")) { + if (is_ipaddrv4($_POST['monitor']) && ($_POST['ipprotocol'] == "inet6")) { $input_errors[] = gettext("The IPv4 monitor address '{$_POST['monitor']}' can not be used on a IPv6 gateway'."); } } @@ -218,23 +233,24 @@ if ($_POST) { /* check for overlaps */ foreach ($a_gateways as $gateway) { if (isset($id) && ($a_gateways[$id]) && ($a_gateways[$id] === $gateway)) { - if ($gateway['name'] != $_POST['name']) + if ($gateway['name'] != $_POST['name']) { $input_errors[] = gettext("Changing name on a gateway is not allowed."); + } continue; } - if($_POST['name'] <> "") { + if ($_POST['name'] <> "") { if (($gateway['name'] <> "") && ($_POST['name'] == $gateway['name']) && ($gateway['attribute'] !== "system")) { $input_errors[] = sprintf(gettext('The gateway name "%s" already exists.'), $_POST['name']); break; } } - if(is_ipaddr($_POST['gateway'])) { + if (is_ipaddr($_POST['gateway'])) { if (($gateway['gateway'] <> "") && ($_POST['gateway'] == $gateway['gateway']) && ($gateway['attribute'] !== "system")) { $input_errors[] = sprintf(gettext('The gateway IP address "%s" already exists.'), $_POST['gateway']); break; } } - if(is_ipaddr($_POST['monitor'])) { + if (is_ipaddr($_POST['monitor'])) { if (($gateway['monitor'] <> "") && ($_POST['monitor'] == $gateway['monitor']) && ($gateway['attribute'] !== "system")) { $input_errors[] = sprintf(gettext('The monitor IP address "%s" is already in use. You must choose a different monitor IP.'), $_POST['monitor']); break; @@ -244,8 +260,8 @@ if ($_POST) { } /* input validation of apinger advanced parameters */ - if($_POST['latencylow']) { - if (! is_numeric($_POST['latencylow'])) { + if ($_POST['latencylow']) { + if (!is_numeric($_POST['latencylow'])) { $input_errors[] = gettext("The low latency threshold needs to be a numeric value."); } else { if ($_POST['latencylow'] < 1) { @@ -254,8 +270,8 @@ if ($_POST) { } } - if($_POST['latencyhigh']) { - if (! is_numeric($_POST['latencyhigh'])) { + if ($_POST['latencyhigh']) { + if (!is_numeric($_POST['latencyhigh'])) { $input_errors[] = gettext("The high latency threshold needs to be a numeric value."); } else { if ($_POST['latencyhigh'] < 1) { @@ -264,8 +280,8 @@ if ($_POST) { } } - if($_POST['losslow']) { - if (! is_numeric($_POST['losslow'])) { + if ($_POST['losslow']) { + if (!is_numeric($_POST['losslow'])) { $input_errors[] = gettext("The low Packet Loss threshold needs to be a numeric value."); } else { if ($_POST['losslow'] < 1) { @@ -277,8 +293,8 @@ if ($_POST) { } } - if($_POST['losshigh']) { - if (! is_numeric($_POST['losshigh'])) { + if ($_POST['losshigh']) { + if (!is_numeric($_POST['losshigh'])) { $input_errors[] = gettext("The high Packet Loss threshold needs to be a numeric value."); } else { if ($_POST['losshigh'] < 1) { @@ -290,54 +306,54 @@ if ($_POST) { } } - if(($_POST['latencylow']) && ($_POST['latencyhigh'])) { + if (($_POST['latencylow']) && ($_POST['latencyhigh'])) { if ((is_numeric($_POST['latencylow'])) && (is_numeric($_POST['latencyhigh']))) { - if(($_POST['latencylow'] > $_POST['latencyhigh'])) { + if (($_POST['latencylow'] > $_POST['latencyhigh'])) { $input_errors[] = gettext("The high latency threshold needs to be higher than the low latency threshold"); } } } else { - if($_POST['latencylow']){ + if ($_POST['latencylow']) { if (is_numeric($_POST['latencylow'])) { - if($_POST['latencylow'] > $apinger_default['latencyhigh']) { + if ($_POST['latencylow'] > $apinger_default['latencyhigh']) { $input_errors[] = gettext(sprintf("The low latency threshold needs to be less than the default high latency threshold (%d)", $apinger_default['latencyhigh'])); } } } - if($_POST['latencyhigh']){ + if ($_POST['latencyhigh']) { if (is_numeric($_POST['latencyhigh'])) { - if($_POST['latencyhigh'] < $apinger_default['latencylow']) { + if ($_POST['latencyhigh'] < $apinger_default['latencylow']) { $input_errors[] = gettext(sprintf("The high latency threshold needs to be higher than the default low latency threshold (%d)", $apinger_default['latencylow'])); } } } } - if(($_POST['losslow']) && ($_POST['losshigh'])){ + if (($_POST['losslow']) && ($_POST['losshigh'])) { if ((is_numeric($_POST['losslow'])) && (is_numeric($_POST['losshigh']))) { - if($_POST['losslow'] > $_POST['losshigh']) { + if ($_POST['losslow'] > $_POST['losshigh']) { $input_errors[] = gettext("The high Packet Loss threshold needs to be higher than the low Packet Loss threshold"); } } } else { - if($_POST['losslow']){ + if ($_POST['losslow']) { if (is_numeric($_POST['losslow'])) { - if($_POST['losslow'] > $apinger_default['losshigh']) { + if ($_POST['losslow'] > $apinger_default['losshigh']) { $input_errors[] = gettext(sprintf("The low Packet Loss threshold needs to be less than the default high Packet Loss threshold (%d)", $apinger_default['losshigh'])); } } } - if($_POST['losshigh']){ + if ($_POST['losshigh']) { if (is_numeric($_POST['losshigh'])) { - if($_POST['losshigh'] < $apinger_default['losslow']) { + if ($_POST['losshigh'] < $apinger_default['losslow']) { $input_errors[] = gettext(sprintf("The high Packet Loss threshold needs to be higher than the default low Packet Loss threshold (%d)", $apinger_default['losslow'])); } } } } - if($_POST['interval']) { - if (! is_numeric($_POST['interval'])) { + if ($_POST['interval']) { + if (!is_numeric($_POST['interval'])) { $input_errors[] = gettext("The probe interval needs to be a numeric value."); } else { if ($_POST['interval'] < 1) { @@ -346,8 +362,8 @@ if ($_POST) { } } - if($_POST['down']) { - if (! is_numeric($_POST['down'])) { + if ($_POST['down']) { + if (!is_numeric($_POST['down'])) { $input_errors[] = gettext("The down time setting needs to be a numeric value."); } else { if ($_POST['down'] < 1) { @@ -356,31 +372,31 @@ if ($_POST) { } } - if(($_POST['interval']) && ($_POST['down'])){ + if (($_POST['interval']) && ($_POST['down'])) { if ((is_numeric($_POST['interval'])) && (is_numeric($_POST['down']))) { - if($_POST['interval'] > $_POST['down']) { + if ($_POST['interval'] > $_POST['down']) { $input_errors[] = gettext("The probe interval needs to be less than the down time setting."); } } } else { - if($_POST['interval']){ + if ($_POST['interval']) { if (is_numeric($_POST['interval'])) { - if($_POST['interval'] > $apinger_default['down']) { + if ($_POST['interval'] > $apinger_default['down']) { $input_errors[] = gettext(sprintf("The probe interval needs to be less than the default down time setting (%d)", $apinger_default['down'])); } } } - if($_POST['down']){ + if ($_POST['down']) { if (is_numeric($_POST['down'])) { - if($_POST['down'] < $apinger_default['interval']) { + if ($_POST['down'] < $apinger_default['interval']) { $input_errors[] = gettext(sprintf("The down time setting needs to be higher than the default probe interval (%d)", $apinger_default['interval'])); } } } } - if($_POST['avg_delay_samples']) { - if (! is_numeric($_POST['avg_delay_samples'])) { + if ($_POST['avg_delay_samples']) { + if (!is_numeric($_POST['avg_delay_samples'])) { $input_errors[] = gettext("The average delay replies qty needs to be a numeric value."); } else { if ($_POST['avg_delay_samples'] < 1) { @@ -389,8 +405,8 @@ if ($_POST) { } } - if($_POST['avg_loss_samples']) { - if (! is_numeric($_POST['avg_loss_samples'])) { + if ($_POST['avg_loss_samples']) { + if (!is_numeric($_POST['avg_loss_samples'])) { $input_errors[] = gettext("The average packet loss probes qty needs to be a numeric value."); } else { if ($_POST['avg_loss_samples'] < 1) { @@ -399,8 +415,8 @@ if ($_POST) { } } - if($_POST['avg_loss_delay_samples']) { - if (! is_numeric($_POST['avg_loss_delay_samples'])) { + if ($_POST['avg_loss_delay_samples']) { + if (!is_numeric($_POST['avg_loss_delay_samples'])) { $input_errors[] = gettext("The lost probe delay needs to be a numeric value."); } else { if ($_POST['avg_loss_delay_samples'] < 1) { @@ -413,93 +429,111 @@ if ($_POST) { $reloadif = ""; $gateway = array(); - if (empty($_POST['interface'])) + if (empty($_POST['interface'])) { $gateway['interface'] = $pconfig['friendlyiface']; - else + } else { $gateway['interface'] = $_POST['interface']; - if (is_ipaddr($_POST['gateway'])) + } + if (is_ipaddr($_POST['gateway'])) { $gateway['gateway'] = $_POST['gateway']; - else + } else { $gateway['gateway'] = "dynamic"; + } $gateway['name'] = $_POST['name']; $gateway['weight'] = $_POST['weight']; $gateway['ipprotocol'] = $_POST['ipprotocol']; $gateway['interval'] = $_POST['interval']; $gateway['avg_delay_samples'] = $_POST['avg_delay_samples']; - if ($_POST['avg_delay_samples_calculated'] == "yes" || $_POST['avg_delay_samples_calculated'] == "on") + if ($_POST['avg_delay_samples_calculated'] == "yes" || $_POST['avg_delay_samples_calculated'] == "on") { $gateway['avg_delay_samples_calculated'] = true; + } $gateway['avg_loss_samples'] = $_POST['avg_loss_samples']; - if ($_POST['avg_loss_samples_calculated'] == "yes" || $_POST['avg_loss_samples_calculated'] == "on") + if ($_POST['avg_loss_samples_calculated'] == "yes" || $_POST['avg_loss_samples_calculated'] == "on") { $gateway['avg_loss_samples_calculated'] = true; + } $gateway['avg_loss_delay_samples'] = $_POST['avg_loss_delay_samples']; - if ($_POST['avg_loss_delay_samples_calculated'] == "yes" || $_POST['avg_loss_delay_samples_calculated'] == "on") + if ($_POST['avg_loss_delay_samples_calculated'] == "yes" || $_POST['avg_loss_delay_samples_calculated'] == "on") { $gateway['avg_loss_delay_samples_calculated'] = true; + } $gateway['descr'] = $_POST['descr']; - if ($_POST['monitor_disable'] == "yes") + if ($_POST['monitor_disable'] == "yes") { $gateway['monitor_disable'] = true; - if ($_POST['force_down'] == "yes") + } + if ($_POST['force_down'] == "yes") { $gateway['force_down'] = true; - if (is_ipaddr($_POST['monitor'])) + } + if (is_ipaddr($_POST['monitor'])) { $gateway['monitor'] = $_POST['monitor']; + } /* NOTE: If monitor ip is changed need to cleanup the old static route */ if ($_POST['monitor'] != "dynamic" && !empty($a_gateway_item[$realid]) && is_ipaddr($a_gateway_item[$realid]['monitor']) && - $_POST['monitor'] != $a_gateway_item[$realid]['monitor'] && $gateway['gateway'] != $a_gateway_item[$realid]['monitor']) { - if (is_ipaddrv4($a_gateway_item[$realid]['monitor'])) + $_POST['monitor'] != $a_gateway_item[$realid]['monitor'] && $gateway['gateway'] != $a_gateway_item[$realid]['monitor']) { + if (is_ipaddrv4($a_gateway_item[$realid]['monitor'])) { mwexec("/sbin/route delete " . escapeshellarg($a_gateway_item[$realid]['monitor'])); - else + } else { mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateway_item[$realid]['monitor'])); + } } if ($_POST['defaultgw'] == "yes" || $_POST['defaultgw'] == "on") { $i = 0; /* remove the default gateway bits for all gateways with the same address family */ - foreach($a_gateway_item as $gw) { + foreach ($a_gateway_item as $gw) { if ($gateway['ipprotocol'] == $gw['ipprotocol']) { unset($config['gateways']['gateway_item'][$i]['defaultgw']); - if ($gw['interface'] != $_POST['interface'] && $gw['defaultgw']) + if ($gw['interface'] != $_POST['interface'] && $gw['defaultgw']) { $reloadif = $gw['interface']; + } } $i++; } $gateway['defaultgw'] = true; } - if ($_POST['latencylow']) + if ($_POST['latencylow']) { $gateway['latencylow'] = $_POST['latencylow']; - if ($_POST['latencyhigh']) + } + if ($_POST['latencyhigh']) { $gateway['latencyhigh'] = $_POST['latencyhigh']; - if ($_POST['losslow']) + } + if ($_POST['losslow']) { $gateway['losslow'] = $_POST['losslow']; - if ($_POST['losshigh']) + } + if ($_POST['losshigh']) { $gateway['losshigh'] = $_POST['losshigh']; - if ($_POST['down']) + } + if ($_POST['down']) { $gateway['down'] = $_POST['down']; + } - if(isset($_POST['disabled'])) + if (isset($_POST['disabled'])) { $gateway['disabled'] = true; - else + } else { unset($gateway['disabled']); + } /* when saving the manual gateway we use the attribute which has the corresponding id */ - if (isset($realid) && $a_gateway_item[$realid]) + if (isset($realid) && $a_gateway_item[$realid]) { $a_gateway_item[$realid] = $gateway; - else + } else { $a_gateway_item[] = $gateway; + } mark_subsystem_dirty('staticroutes'); write_config(); - if($_REQUEST['isAjax']) { + if ($_REQUEST['isAjax']) { echo $_POST['name']; exit; - } else if (!empty($reloadif)) + } else if (!empty($reloadif)) { send_event("interface reconfigure {$reloadif}"); + } header("Location: system_gateways.php"); exit; @@ -514,13 +548,14 @@ if ($_POST) { } $pconfig = $_POST; - if (empty($_POST['friendlyiface'])) + if (empty($_POST['friendlyiface'])) { $pconfig['friendlyiface'] = $_POST['interface']; + } } } -$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway")); +$pgtitle = array(gettext("System"), gettext("Gateways"), gettext("Edit gateway")); $shortcut_section = "gateways"; include("head.inc"); @@ -556,32 +591,35 @@ function samples_change(calculated_obj, samples_obj) { function calculated_change(calculated_obj, samples_obj) { switch (samples_obj.name) { - case 'avg_delay_samples': - // How many replies should be used to compute average delay - // for controlling "delay" alarms. - // Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60). - if (calculated_obj.checked && (document.iform.interval.value > 0)) - samples_obj.value = 60 * (1/6) / Math.pow(document.iform.interval.value, 0.333); // Calculate & Round to Integer - valid_value(samples_obj, 1, 100); - break; - - case 'avg_loss_samples': - // How many probes should be used to compute average loss. - // Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60). - if (calculated_obj.checked && (document.iform.interval.value > 0)) - samples_obj.value = 60 / document.iform.interval.value; // Calculate & Round to Integer - valid_value(samples_obj, 1, 1000); - break; - - case 'avg_loss_delay_samples': - // The delay (in samples) after which loss is computed - // without this delays larger than interval would be treated as loss. - // Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60). - if (calculated_obj.checked && (document.iform.interval.value > 0)) - samples_obj.value = 60 * (1/3) / document.iform.interval.value; // Calculate & Round to Integer - valid_value(samples_obj, 1, 200); - break; - default: + case 'avg_delay_samples': + // How many replies should be used to compute average delay + // for controlling "delay" alarms. + // Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60). + if (calculated_obj.checked && (document.iform.interval.value > 0)) { + samples_obj.value = 60 * (1/6) / Math.pow(document.iform.interval.value, 0.333); // Calculate & Round to Integer + } + valid_value(samples_obj, 1, 100); + break; + + case 'avg_loss_samples': + // How many probes should be used to compute average loss. + // Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60). + if (calculated_obj.checked && (document.iform.interval.value > 0)) { + samples_obj.value = 60 / document.iform.interval.value; // Calculate & Round to Integer + } + valid_value(samples_obj, 1, 1000); + break; + + case 'avg_loss_delay_samples': + // The delay (in samples) after which loss is computed + // without this delays larger than interval would be treated as loss. + // Calculate a reasonable value based on gateway probe interval and RRD 1 minute average graph step size (60). + if (calculated_obj.checked && (document.iform.interval.value > 0)) { + samples_obj.value = 60 * (1/3) / document.iform.interval.value; // Calculate & Round to Integer + } + valid_value(samples_obj, 1, 200); + break; + default: } calculate_state_change(); @@ -605,8 +643,7 @@ function calculate_state_change() { document.iform.avg_delay_samples.disabled = document.iform.avg_delay_samples_calculated.checked; document.iform.avg_loss_samples.disabled = document.iform.avg_loss_samples_calculated.checked; document.iform.avg_loss_delay_samples.disabled = document.iform.avg_loss_delay_samples_calculated.checked; - } - else { + } else { document.iform.avg_delay_samples_calculated.disabled = true; document.iform.avg_loss_samples_calculated.disabled = true; document.iform.avg_loss_delay_samples_calculated.disabled = true; @@ -634,7 +671,7 @@ function enable_change() { <?php /* If this is a system gateway we need this var */ - if(($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) { + if (($pconfig['attribute'] == "system") || is_numeric($pconfig['attribute'])) { echo "<input type='hidden' name='attribute' id='attribute' value=\"" . htmlspecialchars($pconfig['attribute']) . "\" />\n"; } echo "<input type='hidden' name='friendlyiface' id='friendlyiface' value=\"" . htmlspecialchars($pconfig['friendlyiface']) . "\" />\n"; @@ -659,8 +696,9 @@ function enable_change() { $interfaces = get_configured_interface_with_descr(false, true); foreach ($interfaces as $iface => $ifacename) { echo "<option value=\"{$iface}\""; - if ($iface == $pconfig['friendlyiface']) + if ($iface == $pconfig['friendlyiface']) { echo " selected='selected'"; + } echo ">" . htmlspecialchars($ifacename) . "</option>"; } ?> @@ -676,8 +714,9 @@ function enable_change() { $options = array("inet" => "IPv4", "inet6" => "IPv6"); foreach ($options as $name => $string) { echo "<option value=\"{$name}\""; - if ($name == $pconfig['ipprotocol']) + if ($name == $pconfig['ipprotocol']) { echo " selected='selected'"; + } echo ">" . htmlspecialchars($string) . "</option>\n"; } ?> @@ -719,16 +758,17 @@ function enable_change() { <td width="22%" valign="top" class="vncell"><?=gettext("Monitor IP"); ?></td> <td width="78%" class="vtable"> <?php - if ($pconfig['gateway'] == $pconfig['monitor']) + if ($pconfig['gateway'] == $pconfig['monitor']) { $monitor = ""; - else + } else { $monitor = htmlspecialchars($pconfig['monitor']); + } ?> <input name="monitor" type="text" id="monitor" value="<?php echo htmlspecialchars($monitor); ?>" size="28" /> <strong><?=gettext("Alternative monitor IP"); ?></strong> <br /> <?=gettext("Enter an alternative address here to be used to monitor the link. This is used for the " . - "quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond " . - "to ICMP echo requests (pings)"); ?>. + "quality RRD graphs as well as the load balancer entries. Use this if the gateway does not respond " . + "to ICMP echo requests (pings)"); ?>. <br /> </td> </tr> @@ -756,8 +796,9 @@ function enable_change() { <?php for ($i = 1; $i < 6; $i++) { $selected = ""; - if ($pconfig['weight'] == $i) + if ($pconfig['weight'] == $i) { $selected = "selected='selected'"; + } echo "<option value='{$i}' {$selected} >{$i}</option>"; } ?> @@ -794,7 +835,8 @@ function enable_change() { <td width="78%" class="vtable"> <input name="interval" type="text" class="formfld unknown" id="interval" size="2" value="<?=htmlspecialchars($pconfig['interval']);?>" onchange="interval_change(this)" /> - <br /><span class="vexpl"> + <br /> + <span class="vexpl"> <?=gettext(sprintf("How often that an ICMP probe will be sent in seconds. Default is %d.", $apinger_default['interval']));?><br /><br /> <?=gettext("NOTE: The quality graph is averaged over seconds, not intervals, so as the probe interval is increased the accuracy of the quality graph is decreased.");?> </span> @@ -812,9 +854,9 @@ function enable_change() { <td width="22%" valign="top" class="vncellreq"><?=gettext("Average Delay Replies Qty");?></td> <td width="78%" class="vtable"> <input name="avg_delay_samples" type="text" class="formfld unknown" id="avg_delay_samples" size="2" - value="<?=htmlspecialchars($pconfig['avg_delay_samples']);?>" onchange="samples_change(document.iform.avg_delay_samples_calculated, this)" /> + value="<?=htmlspecialchars($pconfig['avg_delay_samples']);?>" onchange="samples_change(document.iform.avg_delay_samples_calculated, this)" /> <input name="avg_delay_samples_calculated" type="checkbox" id="avg_delay_samples_calculated" value="yes" <?php if ($pconfig['avg_delay_samples_calculated'] == true) echo "checked=\"checked\""; ?> onclick="calculated_change(this, document.iform.avg_delay_samples)" /> - <?=gettext("Use calculated value."); ?> + <?=gettext("Use calculated value."); ?> <br /><span class="vexpl"><?=gettext(sprintf("How many replies should be used to compute average delay for controlling \"delay\" alarms? Default is %d.", $apinger_default['avg_delay_samples']));?><br /><br /></span> </td> </tr> @@ -824,7 +866,7 @@ function enable_change() { <input name="avg_loss_samples" type="text" class="formfld unknown" id="avg_loss_samples" size="2" value="<?=htmlspecialchars($pconfig['avg_loss_samples']);?>" onchange="samples_change(document.iform.avg_loss_samples_calculated, this)" /> <input name="avg_loss_samples_calculated" type="checkbox" id="avg_loss_samples_calculated" value="yes" <?php if ($pconfig['avg_loss_samples_calculated'] == true) echo "checked=\"checked\""; ?> onclick="calculated_change(this, document.iform.avg_loss_samples)" /> - <?=gettext("Use calculated value."); ?> + <?=gettext("Use calculated value."); ?> <br /><span class="vexpl"><?=gettext(sprintf("How many probes should be useds to compute average packet loss? Default is %d.", $apinger_default['avg_loss_samples']));?><br /><br /></span> </td> </tr> @@ -834,7 +876,7 @@ function enable_change() { <input name="avg_loss_delay_samples" type="text" class="formfld unknown" id="avg_loss_delay_samples" size="2" value="<?=htmlspecialchars($pconfig['avg_loss_delay_samples']);?>" onchange="samples_change(document.iform.avg_loss_delay_samples_calculated, this)" /> <input name="avg_loss_delay_samples_calculated" type="checkbox" id="avg_loss_delay_samples_calculated" value="yes" <?php if ($pconfig['avg_loss_delay_samples_calculated'] == true) echo "checked=\"checked\""; ?> onclick="calculated_change(this, document.iform.avg_loss_delay_samples)" /> - <?=gettext("Use calculated value."); ?> + <?=gettext("Use calculated value."); ?> <br /><span class="vexpl"><?=gettext(sprintf("The delay (in qty of probe samples) after which loss is computed. Without this, delays longer than the probe interval would be treated as packet loss. Default is %d.", $apinger_default['avg_loss_delay_samples']));?><br /><br /></span> </td> </tr> diff --git a/usr/local/www/system_groupmanager.php b/usr/local/www/system_groupmanager.php index 7132a45..17b0f73 100644 --- a/usr/local/www/system_groupmanager.php +++ b/usr/local/www/system_groupmanager.php @@ -52,14 +52,16 @@ require("guiconfig.inc"); $pgtitle = array(gettext("System"), gettext("Group manager")); -if (!is_array($config['system']['group'])) +if (!is_array($config['system']['group'])) { $config['system']['group'] = array(); +} $a_group = &$config['system']['group']; unset($id); -if (isset($_POST['groupid']) && is_numericint($_POST['groupid'])) +if (isset($_POST['groupid']) && is_numericint($_POST['groupid'])) { $id = $_POST['groupid']; +} $act = (isset($_POST['act']) ? $_POST['act'] : ''); @@ -76,8 +78,8 @@ if ($act == "delgroup") { $groupdeleted = $a_group[$id]['name']; unset($a_group[$id]); write_config(); - $savemsg = gettext("Group")." {$groupdeleted} ". - gettext("successfully deleted")."<br />"; + $savemsg = gettext("Group") . " {$groupdeleted} " . + gettext("successfully deleted") . "<br />"; } if ($act == "delpriv") { @@ -93,15 +95,16 @@ if ($act == "delpriv") { if (is_array($a_group[$id]['member'])) { foreach ($a_group[$id]['member'] as $uid) { $user = getUserEntryByUID($uid); - if ($user) + if ($user) { local_user_set($user); + } } } write_config(); $act = "edit"; - $savemsg = gettext("Privilege")." {$privdeleted} ". - gettext("successfully deleted")."<br />"; + $savemsg = gettext("Privilege") . " {$privdeleted} " . + gettext("successfully deleted") . "<br />"; } if ($act == "edit") { @@ -115,13 +118,13 @@ if ($act == "edit") { } } -if(isset($_POST['dellall_x'])) { +if (isset($_POST['dellall_x'])) { $del_groups = $_POST['delete_check']; - if(!empty($del_groups)) { - foreach($del_groups as $groupid) { - if(isset($a_group[$groupid]) && $a_group[$groupid]['scope'] != "system") { + if (!empty($del_groups)) { + foreach ($del_groups as $groupid) { + if (isset($a_group[$groupid]) && $a_group[$groupid]['scope'] != "system") { conf_mount_rw(); local_group_del($a_group[$groupid]); conf_mount_ro(); @@ -144,11 +147,13 @@ if (isset($_POST['save'])) { do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname'])) + if (preg_match("/[^a-zA-Z0-9\.\-_ ]/", $_POST['groupname'])) { $input_errors[] = gettext("The group name contains invalid characters."); + } - if (strlen($_POST['groupname']) > 16) + if (strlen($_POST['groupname']) > 16) { $input_errors[] = gettext("The group name is longer than 16 characters."); + } if (!$input_errors && !(isset($id) && $a_group[$id])) { /* make sure there are no dupes */ @@ -162,20 +167,22 @@ if (isset($_POST['save'])) { if (!$input_errors) { $group = array(); - if (isset($id) && $a_group[$id]) + if (isset($id) && $a_group[$id]) { $group = $a_group[$id]; + } $group['name'] = $_POST['groupname']; $group['description'] = $_POST['description']; - if (empty($_POST['members'])) + if (empty($_POST['members'])) { unset($group['member']); - else if ($group['gid'] != 1998) // all group + } else if ($group['gid'] != 1998) { // all group $group['member'] = $_POST['members']; + } - if (isset($id) && $a_group[$id]) + if (isset($id) && $a_group[$id]) { $a_group[$id] = $group; - else { + } else { $group['gid'] = $config['system']['nextgid']++; $a_group[] = $group; } @@ -188,8 +195,9 @@ if (isset($_POST['save'])) { if (is_array($group['member'])) { $a_user = &$config['system']['user']; foreach ($a_user as & $user) { - if (in_array($user['uid'], $group['member'])) + if (in_array($user['uid'], $group['member'])) { local_user_set($user); + } } } @@ -213,31 +221,37 @@ include("head.inc"); function setall_selected(id) { selbox = document.getElementById(id); count = selbox.options.length; - for (index = 0; index<count; index++) + for (index = 0; index<count; index++) { selbox.options[index].selected = true; + } } function delete_empty(id) { selbox = document.getElementById(id); count = selbox.options.length; - for (index = 0; index<count; index++) - if (selbox.options[index].value == '') + for (index = 0; index<count; index++) { + if (selbox.options[index].value == '') { selbox.remove(index); + } + } } function clear_selected(id) { selbox = document.getElementById(id); count = selbox.options.length; - for (index = 0; index<count; index++) + for (index = 0; index<count; index++) { selbox.options[index].selected = false; + } } function remove_selected(id) { selbox = document.getElementById(id); index = selbox.options.length - 1; - for (; index >= 0; index--) - if (selbox.options[index].selected) + for (; index >= 0; index--) { + if (selbox.options[index].selected) { selbox.remove(index); + } + } } function copy_selected(srcid, dstid) { @@ -275,10 +289,12 @@ function presubmit() { //]]> </script> <?php - if ($input_errors) + if ($input_errors) { print_input_errors($input_errors); - if ($savemsg) + } + if ($savemsg) { print_info_box($savemsg); + } ?> <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="group manager"> <tr> @@ -298,7 +314,7 @@ function presubmit() { <div class="tabcont"> <?php - if($act == "new" || $act == "edit"): + if ($act == "new" || $act == "edit"): ?> <form action="system_groupmanager.php" method="post" name="iform" id="iform" onsubmit="presubmit()"> <input type="hidden" id="act" name="act" value="" /> @@ -307,8 +323,9 @@ function presubmit() { <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area"> <?php $ro = ""; - if ($pconfig['gtype'] == "system") + if ($pconfig['gtype'] == "system") { $ro = "readonly=\"readonly\""; + } ?> <tr> <td width="22%" valign="top" class="vncell"><?=gettext("Defined by");?></td> @@ -342,12 +359,13 @@ function presubmit() { <td align="center" width="50%"> <strong><?=gettext("Not Members");?></strong><br /> <br /> - <select size="10" style="width: 75%" name="notmembers[]" class="formselect" id="notmembers" onchange="clear_selected('members')" multiple="multiple"> + <select size="10" style="width: 75%" name="notmembers[]" class="formselect" id="notmembers" onchange="clear_selected('members')" multiple="multiple"> <?php $rowIndex = 0; foreach ($config['system']['user'] as $user): - if (is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members'])) + if (is_array($pconfig['members']) && in_array($user['uid'], $pconfig['members'])) { continue; + } $rowIndex++; ?> <option value="<?=$user['uid'];?>" <?=$selected;?>> @@ -355,19 +373,20 @@ function presubmit() { </option> <?php endforeach; - if ($rowIndex == 0) + if ($rowIndex == 0) { echo "<option></option>"; + } ?> </select> <br /> </td> <td> <br /> - <a href="javascript:move_selected('notmembers','members')"> + <a href="javascript:move_selected('notmembers', 'members')"> <img src="/themes/<?= $g['theme'];?>/images/icons/icon_right.gif" title="<?=gettext("Add Members");?>" alt="<?=gettext("Add Members");?>" width="17" height="17" border="0" /> </a> <br /><br /> - <a href="javascript:move_selected('members','notmembers')"> + <a href="javascript:move_selected('members', 'notmembers')"> <img src="/themes/<?= $g['theme'];?>/images/icons/icon_left.gif" title="<?=gettext("Remove Members");?>" alt="<?=gettext("Remove Members");?>" width="17" height="17" border="0" /> </a> </td> @@ -378,8 +397,9 @@ function presubmit() { <?php $rowIndex = 0; foreach ($config['system']['user'] as $user): - if (!(is_array($pconfig['members']) && in_array($user['uid'],$pconfig['members']))) + if (!(is_array($pconfig['members']) && in_array($user['uid'], $pconfig['members']))) { continue; + } $rowIndex++; ?> <option value="<?=$user['uid'];?>"> @@ -387,8 +407,9 @@ function presubmit() { </option> <?php endforeach; - if ($rowIndex == 0) + if ($rowIndex == 0) { echo "<option></option>"; + } ?> </select> <br /> @@ -412,7 +433,7 @@ function presubmit() { <td class="list"></td> </tr> <?php - if(is_array($pconfig['priv'])): + if (is_array($pconfig['priv'])): $i = 0; foreach ($pconfig['priv'] as $priv): ?> @@ -447,7 +468,6 @@ function presubmit() { </td> </tr> - </table> </td> </tr> @@ -509,20 +529,22 @@ function presubmit() { <tbody> <?php $i = 0; - foreach($a_group as $group): - if($group['scope'] == "system") + foreach ($a_group as $group): + if ($group['scope'] == "system") { $grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group-grey.png"; - else + } else { $grpimg = "/themes/{$g['theme']}/images/icons/icon_system-group.png"; + } $groupcount = count($group['member']); - if ($group["name"] == "all") + if ($group["name"] == "all") { $groupcount = count($config['system']['user']); + } ?> <tr ondblclick="document.getElementById('act').value='<?php echo "edit";?>'; document.getElementById('groupid').value='<?=$i;?>'; document.iform2.submit();" id="fr<?=$i?>"> <td class="list" id="frd<?=$i?>"> - <?php if($group['scope'] != "system") : ?> + <?php if ($group['scope'] != "system") : ?> <input type="checkbox" id="frc<?=$i?>" onclick="fr_bgcolor(<?=$i?>)" name="delete_check[]" value="<?=$i?>" /> <?php endif; ?> </td> @@ -552,7 +574,7 @@ function presubmit() { title="<?=gettext("edit group");?>" /> <?php - if($group['scope'] != "system"): + if ($group['scope'] != "system"): ?> <input type="image" name="delgroup[]" width="17" height="17" border="0" src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" diff --git a/usr/local/www/system_groupmanager_addprivs.php b/usr/local/www/system_groupmanager_addprivs.php index ae7e884..00c86f0 100644 --- a/usr/local/www/system_groupmanager_addprivs.php +++ b/usr/local/www/system_groupmanager_addprivs.php @@ -44,22 +44,25 @@ function cpusercmp($a, $b) { } function admin_groups_sort() { - global $config; + global $config; - if (!is_array($config['system']['group'])) - return; + if (!is_array($config['system']['group'])) { + return; + } - usort($config['system']['group'], "cpusercmp"); + usort($config['system']['group'], "cpusercmp"); } require("guiconfig.inc"); -$pgtitle = array(gettext("System"),gettext("Group manager"),gettext("Add privileges")); +$pgtitle = array(gettext("System"), gettext("Group manager"), gettext("Add privileges")); -if (is_numericint($_GET['groupid'])) +if (is_numericint($_GET['groupid'])) { $groupid = $_GET['groupid']; -if (isset($_POST['groupid']) && is_numericint($_POST['groupid'])) +} +if (isset($_POST['groupid']) && is_numericint($_POST['groupid'])) { $groupid = $_POST['groupid']; +} $a_group = & $config['system']['group'][$groupid]; @@ -68,8 +71,9 @@ if (!is_array($a_group)) { exit; } -if (!is_array($a_group['priv'])) +if (!is_array($a_group['priv'])) { $a_group['priv'] = array(); +} if ($_POST) { @@ -83,26 +87,29 @@ if ($_POST) { do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); /* if this is an AJAX caller then handle via JSON */ - if(isAjax() && is_array($input_errors)) { + if (isAjax() && is_array($input_errors)) { input_errors2Ajax($input_errors); exit; } if (!$input_errors) { - if (!is_array($pconfig['sysprivs'])) + if (!is_array($pconfig['sysprivs'])) { $pconfig['sysprivs'] = array(); + } - if (!count($a_group['priv'])) + if (!count($a_group['priv'])) { $a_group['priv'] = $pconfig['sysprivs']; - else + } else { $a_group['priv'] = array_merge($a_group['priv'], $pconfig['sysprivs']); + } if (is_array($a_group['member'])) { foreach ($a_group['member'] as $uid) { $user = getUserEntryByUID($uid); - if ($user) + if ($user) { local_user_set($user); + } } } @@ -117,8 +124,9 @@ if ($_POST) { } /* if ajax is calling, give them an update message */ -if(isAjax()) +if (isAjax()) { print_info_box_np($savemsg); +} include("head.inc"); ?> @@ -134,9 +142,10 @@ if (is_array($priv_list)) { $id = 0; $jdescs = "var descs = new Array();\n"; - foreach($priv_list as $pname => $pdata) { - if (in_array($pname, $a_group['priv'])) + foreach ($priv_list as $pname => $pdata) { + if (in_array($pname, $a_group['priv'])) { continue; + } $desc = addslashes($pdata['descr']); $jdescs .= "descs[{$id}] = '{$desc}';\n"; $id++; @@ -155,10 +164,12 @@ function update_description() { //]]> </script> <?php - if ($input_errors) + if ($input_errors) { print_input_errors($input_errors); - if ($savemsg) + } + if ($savemsg) { print_info_box($savemsg); + } ?> <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="group manager add privileges"> <tr> @@ -182,35 +193,38 @@ function update_description() { <td width="22%" valign="top" class="vncellreq"><?=gettext("System Privileges");?></td> <td width="78%" class="vtable"> <table> - <tr><td> - <select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple="multiple" size="35"> - <?php - foreach($priv_list as $pname => $pdata): - if (in_array($pname, $a_group['priv'])) - continue; - ?> - <option value="<?=$pname;?>"><?=$pdata['name'];?></option> - <?php endforeach; ?> - </select> - <br /> - <?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?> - </td><td> - <a href='#'onClick="selectAll();">Select all</a> - <script type="text/javascript"> - //<![CDATA[ - function selectAll() { - var options = jQuery('select#sysprivs option'); - var len = options.length; - for (var i = 0; i < len; i++) { - options[i].selected = true; - } - } - selectAll(); - //]]> - </script> - <br /> - </td> - </tr> + <tr> + <td> + <select name="sysprivs[]" id="sysprivs" class="formselect" onchange="update_description();" multiple="multiple" size="35"> + <?php + foreach ($priv_list as $pname => $pdata): + if (in_array($pname, $a_group['priv'])) { + continue; + } + ?> + <option value="<?=$pname;?>"><?=$pdata['name'];?></option> + <?php endforeach; ?> + </select> + <br /> + <?=gettext("Hold down CTRL (pc)/COMMAND (mac) key to select multiple items");?> + </td> + <td> + <a href='#'onClick="selectAll();">Select all</a> + <script type="text/javascript"> + //<![CDATA[ + function selectAll() { + var options = jQuery('select#sysprivs option'); + var len = options.length; + for (var i = 0; i < len; i++) { + options[i].selected = true; + } + } + selectAll(); + //]]> + </script> + <br /> + </td> + </tr> </table> </td> </tr> |