diff options
author | Stephen Beaver <sbeaver@netgate.com> | 2016-04-18 14:27:11 -0400 |
---|---|---|
committer | Stephen Beaver <sbeaver@netgate.com> | 2016-04-18 14:27:11 -0400 |
commit | dca4eadf2a7da5f60359f10843d1e107dd09c6a1 (patch) | |
tree | 78c95b2ec23b832f00b50e3f290e08aebc73fda6 /src | |
parent | bf1a013f15732ee3210e814ad0bfa23d3a7ba1eb (diff) | |
download | pfsense-dca4eadf2a7da5f60359f10843d1e107dd09c6a1.zip pfsense-dca4eadf2a7da5f60359f10843d1e107dd09c6a1.tar.gz |
Convert status_services and widget to POST
Diffstat (limited to 'src')
-rw-r--r-- | src/usr/local/www/firewall_rules_edit.php | 4 | ||||
-rw-r--r-- | src/usr/local/www/head.inc | 2 | ||||
-rw-r--r-- | src/usr/local/www/js/pfSenseHelpers.js | 356 | ||||
-rw-r--r-- | src/usr/local/www/status_openvpn.php | 6 | ||||
-rwxr-xr-x | src/usr/local/www/status_services.php | 128 | ||||
-rw-r--r-- | src/usr/local/www/widgets/widgets/services_status.widget.php | 9 |
6 files changed, 230 insertions, 275 deletions
diff --git a/src/usr/local/www/firewall_rules_edit.php b/src/usr/local/www/firewall_rules_edit.php index ee9b557..6fefbbe 100644 --- a/src/usr/local/www/firewall_rules_edit.php +++ b/src/usr/local/www/firewall_rules_edit.php @@ -194,7 +194,7 @@ if (isset($id) && $a_filter[$id]) { if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") { $pconfig['floating'] = $a_filter[$id]['floating']; if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "") { - $pconfig['interface'] = $a_filter[$id]['interface']; + $pconfig['interface'] = explode(",", $a_filter[$id]['interface']); } } @@ -1205,7 +1205,7 @@ if ($if == "FloatingRules" || isset($pconfig['floating'])) { $section->addInput($input = new Form_Select( 'interface', 'Interface', - explode(",", $pconfig['interface']), + $pconfig['interface'], build_if_list(), true ))->setHelp('Choose the interface(s) for this rule.'); diff --git a/src/usr/local/www/head.inc b/src/usr/local/www/head.inc index 891884e..4aa2963 100644 --- a/src/usr/local/www/head.inc +++ b/src/usr/local/www/head.inc @@ -575,7 +575,7 @@ if (!$hide_service_status && !empty($shortcuts[$shortcut_section]['service']) && } if (!empty($ssvc)) { // echo '<li>'. get_service_status_icon($ssvc, false). '</li>'; TODO: Add missing function - echo '<li>'. get_service_control_GET_links($ssvc, false). '</li>'; + echo '<li>'. get_service_control_links($ssvc, false). '</li>'; } } diff --git a/src/usr/local/www/js/pfSenseHelpers.js b/src/usr/local/www/js/pfSenseHelpers.js index c406d6d..1747c19 100644 --- a/src/usr/local/www/js/pfSenseHelpers.js +++ b/src/usr/local/www/js/pfSenseHelpers.js @@ -464,187 +464,233 @@ $('.container .panel-heading a[data-toggle="collapse"]').each(function (idx, el) }); }); - // Separator bar stuff ------------------------------------------------------------------------ +// Separator bar stuff ------------------------------------------------------------------------ - // Globals - gColor = 'bg-info'; - newSeperator = false; - saving = false; - dirty = false; +// Globals +gColor = 'bg-info'; +newSeperator = false; +saving = false; +dirty = false; + +$("#addsep").prop('type' ,'button'); + +$("#addsep").click(function() { + if (newSeperator) { + return(false); + } - $("#addsep").prop('type' ,'button'); + gColor = 'bg-info'; + // Inset a temporary bar in which the user can enter some optional text + sepcols = $( "#ruletable tr th" ).length - 2; + + $('#ruletable > tbody:last').append('<tr>' + + '<td class="' + gColor + '" colspan="' + sepcols + '"><input id="newsep" placeholder="' + svbtnplaceholder + '" class="col-md-12" type="text" /></td>' + + '<td class="' + gColor + '" colspan="2"><button class="btn btn-primary btn-sm" id="btnnewsep"><i class="fa fa-save icon-embed-btn"></i>' + svtxt + '</button>' + + '<button class="btn btn-info btn-sm" id="btncncsep"><i class="fa fa-undo icon-embed-btn"></i>' + cncltxt + '</button>' + + ' ' + + ' <a id="sepclrblue" value="bg-info"><i class="fa fa-circle text-info icon-pointer"></i></a>' + + ' <a id="sepclrred" value="bg-danger"><i class="fa fa-circle text-danger icon-pointer"></i></a>' + + ' <a id="sepclrgreen" value="bg-success"><i class="fa fa-circle text-success icon-pointer"></i></a>' + + ' <a id="sepclrorange" value="bg-warning"><i class="fa fa-circle text-warning icon-pointer"></i></button>' + + '</td></tr>'); + + $('#newsep').focus(); + newSeperator = true; + + $("#btnnewsep").prop('type' ,'button'); + + // Watch escape and enter keys + $('#newsep').keyup(function(e) { + if(e.which == 27) { + $('#btncncsep').trigger('click'); + } + }); - $("#addsep").click(function() { - if (newSeperator) { - return(false); + $('#newsep').keypress(function(e) { + if(e.which == 13) { + $('#btnnewsep').trigger('click'); } + }); + + handle_colors(); - gColor = 'bg-info'; - // Inset a temporary bar in which the user can enter some optional text - sepcols = $( "#ruletable tr th" ).length - 2; - - $('#ruletable > tbody:last').append('<tr>' + - '<td class="' + gColor + '" colspan="' + sepcols + '"><input id="newsep" placeholder="' + svbtnplaceholder + '" class="col-md-12" type="text" /></td>' + - '<td class="' + gColor + '" colspan="2"><button class="btn btn-primary btn-sm" id="btnnewsep"><i class="fa fa-save icon-embed-btn"></i>' + svtxt + '</button>' + - '<button class="btn btn-info btn-sm" id="btncncsep"><i class="fa fa-undo icon-embed-btn"></i>' + cncltxt + '</button>' + - ' ' + - ' <a id="sepclrblue" value="bg-info"><i class="fa fa-circle text-info icon-pointer"></i></a>' + - ' <a id="sepclrred" value="bg-danger"><i class="fa fa-circle text-danger icon-pointer"></i></a>' + - ' <a id="sepclrgreen" value="bg-success"><i class="fa fa-circle text-success icon-pointer"></i></a>' + - ' <a id="sepclrorange" value="bg-warning"><i class="fa fa-circle text-warning icon-pointer"></i></button>' + + // Replace the temporary separator bar with the final version containing the + // user's text and a delete icon + $("#btnnewsep").click(function() { + var septext = escapeHtml($('#newsep').val()); + sepcols = $( "#ruletable tr th" ).length - 1; + + $(this).parents('tr').replaceWith('<tr class="ui-sortable-handle separator">' + + '<td class="' + gColor + '" colspan="' + sepcols + '">' + '<span class="' + gColor + '">' + septext + '</span></td>' + + '<td class="' + gColor + '"><a href="#"><i class="fa fa-trash sepdel"></i></a>' + '</td></tr>'); - $('#newsep').focus(); - newSeperator = true; + $('#order-store').removeAttr('disabled'); + newSeperator = false; + dirty = true; + }); - $("#btnnewsep").prop('type' ,'button'); + // Cancel button + $('#btncncsep').click(function(e) { + e.preventDefault(); + $(this).parents('tr').remove(); + newSeperator = false; + }); +}); - // Watch escape and enter keys - $('#newsep').keyup(function(e) { - if(e.which == 27) { - $('#btncncsep').trigger('click'); - } - }); +// Delete a separator row +$(function(){ + $('table').on('click','tr a .sepdel',function(e){ + e.preventDefault(); + $(this).parents('tr').remove(); + $('#order-store').removeAttr('disabled'); + dirty = true; + }); +}); - $('#newsep').keypress(function(e) { - if(e.which == 13) { - $('#btnnewsep').trigger('click'); +// Compose an inout array containing the row #, color and text for each separator +function save_separators() { + var row = 0; + var sepinput; + var sepnum = 0; + + $('#ruletable > tbody > tr').each(function() { + if ($(this).hasClass('separator')) { + seprow = $(this).next('tr').attr("id"); + if (seprow == undefined) { + seprow = "fr" + row; } - }); - handle_colors(); - - // Replace the temporary separator bar with the final version containing the - // user's text and a delete icon - $("#btnnewsep").click(function() { - var septext = escapeHtml($('#newsep').val()); - sepcols = $( "#ruletable tr th" ).length - 1; + sepinput = '<input type="hidden" name="separator[' + sepnum + '][row]" value="' + seprow + '"></input>'; + $('form').append(sepinput); + sepinput = '<input type="hidden" name="separator[' + sepnum + '][text]" value="' + escapeHtml($(this).find('td').text()) + '"></input>'; + $('form').append(sepinput); + sepinput = '<input type="hidden" name="separator[' + sepnum + '][color]" value="' + $(this).find('td').prop('class') + '"></input>'; + $('form').append(sepinput); + sepinput = '<input type="hidden" name="separator[' + sepnum + '][if]" value="' + iface + '"></input>'; + $('form').append(sepinput); + sepnum++; + } else { + if ($(this).parent('tbody').hasClass('user-entries')) { + row++; + } + } + }); +} - $(this).parents('tr').replaceWith('<tr class="ui-sortable-handle separator">' + - '<td class="' + gColor + '" colspan="' + sepcols + '">' + '<span class="' + gColor + '">' + septext + '</span></td>' + - '<td class="' + gColor + '"><a href="#"><i class="fa fa-trash sepdel"></i></a>' + - '</td></tr>'); +function reindex_rules(section) { + var row = 0; - $('#order-store').removeAttr('disabled'); - newSeperator = false; - dirty = true; - }); + section.find('tr').each(function() { + if(this.id) { + $(this).attr("id", "fr" + row); + $(this).attr("onclick", "fr_toggle(" + row + ")") + $(this).find('input:checkbox:first').each(function() { + $(this).attr("id", "frc" + row); + $(this).attr("onclick", "fr_toggle(" + row + ")"); + }); - // Cancel button - $('#btncncsep').click(function(e) { - e.preventDefault(); - $(this).parents('tr').remove(); - newSeperator = false; - }); + row++; + } }); +} - // Delete a separator row - $(function(){ - $('table').on('click','tr a .sepdel',function(e){ - e.preventDefault(); - $(this).parents('tr').remove(); - $('#order-store').removeAttr('disabled'); - dirty = true; - }); +function handle_colors() { + $('[id^=sepclr]').prop("type", "button"); + + $('[id^=sepclr]').click(function () { + var color = $(this).attr('value'); + // Clear all the color classes + $(this).parent('td').prop('class', ''); + $(this).parent('td').prev('td').prop('class', ''); + // Install our new color class + $(this).parent('td').addClass(color); + $(this).parent('td').prev('td').addClass(color); + // Set the global color + gColor = color; }); +} - // Compose an inout array containing the row #, color and text for each separator - function save_separators() { - var row = 0; - var sepinput; - var sepnum = 0; - - $('#ruletable > tbody > tr').each(function() { - if ($(this).hasClass('separator')) { - seprow = $(this).next('tr').attr("id"); - if (seprow == undefined) { - seprow = "fr" + row; - } - - sepinput = '<input type="hidden" name="separator[' + sepnum + '][row]" value="' + seprow + '"></input>'; - $('form').append(sepinput); - sepinput = '<input type="hidden" name="separator[' + sepnum + '][text]" value="' + escapeHtml($(this).find('td').text()) + '"></input>'; - $('form').append(sepinput); - sepinput = '<input type="hidden" name="separator[' + sepnum + '][color]" value="' + $(this).find('td').prop('class') + '"></input>'; - $('form').append(sepinput); - sepinput = '<input type="hidden" name="separator[' + sepnum + '][if]" value="' + iface + '"></input>'; - $('form').append(sepinput); - sepnum++; - } else { - if ($(this).parent('tbody').hasClass('user-entries')) { - row++; - } - } - }); - } - - function reindex_rules(section) { - var row = 0; +//JS equivalent to PHP htmlspecialchars() +function escapeHtml(text) { + var map = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + + return text.replace(/[&<>"']/g, function(m) { return map[m]; }); +} +// -------------------------------------------------------------------------------------------- - section.find('tr').each(function() { - if(this.id) { - $(this).attr("id", "fr" + row); - $(this).attr("onclick", "fr_toggle(" + row + ")") - $(this).find('input:checkbox:first').each(function() { - $(this).attr("id", "frc" + row); - $(this).attr("onclick", "fr_toggle(" + row + ")"); - }); +// Select every option in the specified multiselect +function AllServers(id, selectAll) { + for (i = 0; i < id.length; i++) { + id.eq(i).prop('selected', selectAll); + } +} - row++; +// Move all selected options from one multiselect to another +function moveOptions(From, To) { + var len = From.length; + var option; + + if (len > 0) { + for (i=0; i<len; i++) { + if (From.eq(i).is(':selected')) { + option = From.eq(i).val(); + value = From.eq(i).text(); + To.append(new Option(value, option)); + From.eq(i).remove(); } - }); - } - - function handle_colors() { - $('[id^=sepclr]').prop("type", "button"); - - $('[id^=sepclr]').click(function () { - var color = $(this).attr('value'); - // Clear all the color classes - $(this).parent('td').prop('class', ''); - $(this).parent('td').prev('td').prop('class', ''); - // Install our new color class - $(this).parent('td').addClass(color); - $(this).parent('td').prev('td').addClass(color); - // Set the global color - gColor = color; - }); + } } +} - //JS equivalent to PHP htmlspecialchars() - function escapeHtml(text) { - var map = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; - - return text.replace(/[&<>"']/g, function(m) { return map[m]; }); - } - // -------------------------------------------------------------------------------------------- - // Select every option in the specified multiselect - function AllServers(id, selectAll) { - for (i = 0; i < id.length; i++) { - id.eq(i).prop('selected', selectAll); - } +// ------------- Service start/stop/restart functions. +// [id^=restartservice-], [id^=stopservice-], id^=startservice-] +// If a start/stop/restart button is clicked, parse teh button name and make a POST via AJAX +$('[id*=restartservice-], [id*=stopservice-], [id*=startservice-]').click(function(event) { + var args = this.id.split('-'); + var action, name, mode_zone, id; + + if (args[0] == "openvpn") { + action = args[1]; + name = args[0]; + mode_zone = args[2]; + id = args[3]; + } else if (args[0] == "cpativeportal") { + action = args[1]; + name = args[0]; + mode_zone = args[2]; + id = args[3]; + } else { + action = args[0]; + name = args[1]; } - // Move all selected options from one multiselect to another - function moveOptions(From, To) { - var len = From.length; - var option; - - if (len > 0) { - for (i=0; i<len; i++) { - if (From.eq(i).is(':selected')) { - option = From.eq(i).val(); - value = From.eq(i).text(); - To.append(new Option(value, option)); - From.eq(i).remove(); - } + $(this).children('i').removeClass().addClass('fa fa-cog fa-spin text-success'); + + ajaxRequest = $.ajax( + { + url: "/status_services.php", + type: "post", + data: { + ajax: "ajax", + mode: action, + service: name, + vpnmode: mode_zone, + zone: mode_zone, + id: id } } - } + ); + + // Once the AJAX call has returned, refresh the page to show the new service + ajaxRequest.done(function (response, textStatus, jqXHR) { + location.reload(true); + }); +}); diff --git a/src/usr/local/www/status_openvpn.php b/src/usr/local/www/status_openvpn.php index 8e58f28..8bf81cb 100644 --- a/src/usr/local/www/status_openvpn.php +++ b/src/usr/local/www/status_openvpn.php @@ -176,7 +176,7 @@ include("head.inc"); ?> <td> <?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?> <?= get_service_status_icon($ssvc, true, true); ?> - <?= get_service_control_GET_links($ssvc, true); ?> + <?= get_service_control_links($ssvc); ?> </td> </tr> </table> @@ -282,7 +282,7 @@ include("head.inc"); ?> <td> <?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?> <?= get_service_status_icon($ssvc, false, true); ?> - <?= get_service_control_GET_links($ssvc, true); ?> + <?= get_service_control_links($ssvc, true); ?> </td> </tr> </table> @@ -338,7 +338,7 @@ include("head.inc"); ?> <td> <?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?> <?= get_service_status_icon($ssvc, false, true); ?> - <?= get_service_control_GET_links($ssvc, true); ?> + <?= get_service_control_links($ssvc, true); ?> </td> </tr> </table> diff --git a/src/usr/local/www/status_services.php b/src/usr/local/www/status_services.php index 59bbd78..1753b4f 100755 --- a/src/usr/local/www/status_services.php +++ b/src/usr/local/www/status_services.php @@ -64,36 +64,26 @@ require_once("guiconfig.inc"); require_once("service-utils.inc"); require_once("shortcuts.inc"); -// Leave GET enabled in case any other pages use it. -// ToDo: Check other pages and remove GET completely -if (!$_GET && $_POST) { - $_GET = $_POST; -} - -$service_name = ''; -if (isset($_GET['service'])) { - $service_name = htmlspecialchars($_GET['service']); -} - -if (!empty($service_name)) { - switch ($_GET['mode']) { - case "restartservice": - $savemsg = service_control_restart($service_name, $_GET); - break; - case "startservice": - $savemsg = service_control_start($service_name, $_GET); - break; - case "stopservice": - $savemsg = service_control_stop($service_name, $_GET); - break; +if ($_REQUEST['ajax']) { + if (isset($_REQUEST['service'])) { + $service_name = htmlspecialchars($_REQUEST['service']); } - sleep(5); -} - + if (!empty($service_name)) { + switch ($_REQUEST['mode']) { + case "restartservice": + $savemsg = service_control_restart($service_name, $_REQUEST); + break; + case "startservice": + $savemsg = service_control_start($service_name, $_REQUEST); + break; + case "stopservice": + $savemsg = service_control_stop($service_name, $_REQUEST); + break; + } + sleep(5); + } -/* batch mode, allow other scripts to call this script */ -if ($_GET['batch']) { exit; } @@ -197,89 +187,5 @@ if (count($services) > 0) { } else { print_info_box(gettext("No services found."), 'danger'); } -?> -<script type="text/javascript"> -//<![CDATA[ -events.push(function() { - // If a restart button is clicked, populate the hidden inputs and submit the form (via POST) - $('[id^=restartservice-]').click(function(event) { - $('#mode').val('restartservice'); - $('#service').val(this.id.replace("restartservice-", "")); - $(this).parents('form').submit(); - }); - // If a stop button is clicked, populate the hidden inputs and submit the form (via POST) - $('[id^=stopservice-]').click(function(event) { - $('#mode').val('stopservice'); - $('#service').val(this.id.replace("stopservice-", "")); - $(this).parents('form').submit(); - }); - - // If a start button is clicked, populate the hidden inputs and submit the form (via POST) - $('[id^=startservice-]').click(function(event) { - $('#mode').val('startservice'); - $('#service').val(this.id.replace("startservice-", "")); - $(this).parents('form').submit(); - }); - - // If an openvpn start button is clicked, populate the hidden inputs and submit the form (via POST) - $('[id^=openvpn-startservice-]').click(function(event) { - var args = this.id.split('-'); - $('#mode').val('startservice'); - $('#service').val('openvpn'); - $('#id').val(args[3]); - $('#vpnmode').val(args[2]); - $(this).parents('form').submit(); - }); - - // If an openvpn restart button is clicked, populate the hidden inputs and submit the form (via POST) - $('[id^=openvpn-restartservice-]').click(function(event) { - var args = this.id.split('-'); - $('#mode').val('restartservice'); - $('#service').val('openvpn'); - $('#id').val(args[3]); - $('#vpnmode').val(args[2]); - $(this).parents('form').submit(); - }); - - // If an openvpn stop button is clicked, populate the hidden inputs and submit the form (via POST) - $('[id^=openvpn-stopservice-]').click(function(event) { - var args = this.id.split('-'); - $('#mode').val('stopservice'); - $('#service').val('openvpn'); - $('#id').val(args[3]); - $('#vpnmode').val(args[2]); - $(this).parents('form').submit(); - }); - - // If a captiveportal start button is clicked, populate the hidden inputs and submit the form (via POST) - $('[id^=captiveportal-startservice-]').click(function(event) { - var args = this.id.split('-'); - $('#mode').val('startservice'); - $('#service').val('captiveportal'); - $('#zone').val(args[2]); - $(this).parents('form').submit(); - }); - - // If a captiveportal restart button is clicked, populate the hidden inputs and submit the form (via POST) - $('[id^=captiveportal-restartservice-]').click(function(event) { - var args = this.id.split('-'); - $('#mode').val('restartservice'); - $('#service').val('captiveportal'); - $('#zone').val(args[2]); - $(this).parents('form').submit(); - }); - - // If a captiveportal stop button is clicked, populate the hidden inputs and submit the form (via POST) - $('[id^=captiveportal-stopservice-]').click(function(event) { - var args = this.id.split('-'); - $('#mode').val('stopservice'); - $('#service').val('captiveportal'); - $('#zone').val(args[2]); - $(this).parents('form').submit(); - }); -}); -//]]> -</script> -<?php include("foot.inc"); diff --git a/src/usr/local/www/widgets/widgets/services_status.widget.php b/src/usr/local/www/widgets/widgets/services_status.widget.php index 7e1d883..a6b065c 100644 --- a/src/usr/local/www/widgets/widgets/services_status.widget.php +++ b/src/usr/local/www/widgets/widgets/services_status.widget.php @@ -78,7 +78,7 @@ for ($idx=1; $idx < $numsvcs; $idx++) { for ($chk = $idx +1, $sfx=2; $chk <$numsvcs; $chk++) { if ($services[$chk]['dispname'] == $name) { $services[$chk]['dispname'] .= '_' . $sfx++; - } + } } } @@ -116,20 +116,23 @@ $skipservices = explode(",", $config['widgets']['servicestatusfilter']); if (count($services) > 0) { uasort($services, "service_dispname_compare"); + foreach ($services as $service) { if ((!$service['dispname']) || (in_array($service['dispname'], $skipservices)) || (!is_service_enabled($service['dispname']))) { continue; } + if (empty($service['description'])) { $service['description'] = get_pkg_descr($service['name']); } + $service_desc = explode(".",$service['description']); ?> <tr> <td><i class="fa fa-<?=get_service_status($service) ? 'check-circle text-success' : 'times-circle text-warning'?>"></i></td> <td><?=$service['dispname']?></td> <td><?=$service_desc[0]?></td> - <td><?=get_service_control_GET_links($service)?></td> + <td><?=get_service_control_links($service)?></td> </tr> <?php } @@ -149,7 +152,7 @@ if (count($services) > 0) { <div class="col-sm-6"> <select multiple id="servicestatusfilter" name="servicestatusfilter[]" class="form-control"> <?php - foreach ($services as $service): + foreach ($services as $service): if (!empty(trim($service['dispname'])) || is_numeric($service['dispname'])) { ?> <option <?=(in_array($service['dispname'], $skipservices)?'selected':'')?>><?=$service['dispname']?></option> |