mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 10:04:41 +00:00
add legacy style high availability backup status page for easy service restart/configure
This commit is contained in:
parent
2c5768dce5
commit
eebc4bec0b
105
src/etc/inc/xmlrpc/service.inc
Normal file
105
src/etc/inc/xmlrpc/service.inc
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2016 Deciso B.V.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
require_once("services.inc");
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function xmlrpc_publishable_service()
|
||||
{
|
||||
return array("list_services_xmlrpc", "stop_service_xmlrpc", "start_service_xmlrpc", "restart_service_xmlrpc",
|
||||
"configd_reload_all_templates_xmlrpc");
|
||||
}
|
||||
|
||||
/**
|
||||
* list configured services
|
||||
* @return string
|
||||
*/
|
||||
function list_services_xmlrpc()
|
||||
{
|
||||
$services = services_get();
|
||||
if (count($services) > 0) {
|
||||
uasort($services, "service_name_compare");
|
||||
}
|
||||
foreach ($services as &$service) {
|
||||
$service['status'] = get_service_status($service);
|
||||
}
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* stop service
|
||||
*/
|
||||
function stop_service_xmlrpc($params)
|
||||
{
|
||||
$filter = array();
|
||||
$name = $params["service"];
|
||||
if (!empty($params["id"])) {
|
||||
$filter['id'] = $params["id"];
|
||||
}
|
||||
|
||||
return service_control_stop($name, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* start service
|
||||
*/
|
||||
function start_service_xmlrpc($params)
|
||||
{
|
||||
$filter = array();
|
||||
$name = $params["service"];
|
||||
if (!empty($params["id"])) {
|
||||
$filter['id'] = $params["id"];
|
||||
}
|
||||
|
||||
return service_control_start($name, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* restart service
|
||||
*/
|
||||
function restart_service_xmlrpc($params)
|
||||
{
|
||||
$filter = array();
|
||||
$name = $params["service"];
|
||||
if (!empty($params["id"])) {
|
||||
$filter['id'] = $params["id"];
|
||||
}
|
||||
|
||||
return service_control_restart($name, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* generate all templates
|
||||
*/
|
||||
function configd_reload_all_templates_xmlrpc($params)
|
||||
{
|
||||
configd_run('template reload *');
|
||||
return array("status" => "done");
|
||||
}
|
||||
@ -36,6 +36,7 @@
|
||||
<HighAvailability order="50" VisibleName="High Availability" cssClass="fa fa-refresh fa-fw">
|
||||
<Synchronization url="/system_hasync.php"/>
|
||||
<CARPStatus order="100" VisibleName="CARP Status" url="/carp_status.php"/>
|
||||
<HAStatus order="200" VisibleName="HA backup status" url="/status_habackup.php"/>
|
||||
</HighAvailability>
|
||||
<Routes order="40" cssClass="fa fa-map-signs fa-fw">
|
||||
<All order="10" url="/system_routes.php">
|
||||
|
||||
@ -769,6 +769,13 @@
|
||||
"carp_status.php*"
|
||||
]
|
||||
},
|
||||
"page-status-habackup": {
|
||||
"name": "WebCfg - Status: HA backup page",
|
||||
"descr": "Allow access to the 'Status: HA backup' page.",
|
||||
"match": [
|
||||
"status_habackup.php"
|
||||
]
|
||||
},
|
||||
"page-status-dhcpleases": {
|
||||
"name": "WebCfg - Status: DHCP leases page",
|
||||
"descr": "Allow access to the 'Status: DHCP leases' page.",
|
||||
|
||||
318
src/www/status_habackup.php
Normal file
318
src/www/status_habackup.php
Normal file
@ -0,0 +1,318 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2016 Deciso B.V.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
require_once("guiconfig.inc");
|
||||
require_once("XMLRPC_Client.inc") ;
|
||||
require_once("util.inc");
|
||||
|
||||
function xmlrpc_exec($method, $params=array(), $debug=false)
|
||||
{
|
||||
global $config;
|
||||
$synchronizeto = null;
|
||||
$hasync = $config['hasync'];
|
||||
if (is_ipaddrv6($hasync['synchronizetoip'])) {
|
||||
$hasync['synchronizetoip'] = "[{$hasync['synchronizetoip']}]";
|
||||
}
|
||||
|
||||
if (!empty($hasync['synchronizetoip'])) {
|
||||
// determine target url
|
||||
if (substr($hasync['synchronizetoip'],0, 4) == 'http') {
|
||||
// URL provided
|
||||
if (substr($hasync['synchronizetoip'], strlen($hasync['synchronizetoip'])-1, 1) == '/') {
|
||||
$synchronizeto = $hasync['synchronizetoip']."xmlrpc.php";
|
||||
} else {
|
||||
$synchronizeto = $hasync['synchronizetoip']."/xmlrpc.php";
|
||||
}
|
||||
} elseif (!empty($config['system']['webgui']['protocol'])) {
|
||||
// no url provided, assume the backup is using the same settings as our box.
|
||||
$port = $config['system']['webgui']['port'];
|
||||
if (!empty($port)) {
|
||||
$synchronizeto = $config['system']['webgui']['protocol'] . '://'.$hasync['synchronizetoip'].':'.$port."/xmlrpc.php";
|
||||
} else {
|
||||
$synchronizeto = $config['system']['webgui']['protocol'] . '://'.$hasync['synchronizetoip']."/xmlrpc.php" ;
|
||||
}
|
||||
}
|
||||
|
||||
$username = empty($hasync['username']) ? "root" : $hasync['username'];
|
||||
$client = new SimpleXMLRPC_Client($synchronizeto,240);
|
||||
$client->debug=$debug;
|
||||
$client->setCredentials($username, $hasync['password']);
|
||||
if ($client->query($method, $params)) {
|
||||
return $client->getResponse();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_xmlrpc_backup_version()
|
||||
{
|
||||
return xmlrpc_exec('opnsense.firmware_version');
|
||||
}
|
||||
|
||||
function get_xmlrpc_services()
|
||||
{
|
||||
return xmlrpc_exec('opnsense.list_services');
|
||||
}
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (!empty($_POST["action"])) {
|
||||
switch ($_POST["action"]) {
|
||||
case 'stop':
|
||||
$result=xmlrpc_exec('opnsense.stop_service', array("service" => $_POST['service'], "id" => $_POST['id']));
|
||||
echo json_encode(array("response" => $result));
|
||||
break;
|
||||
case 'start':
|
||||
$result=xmlrpc_exec('opnsense.start_service', array("service" => $_POST['service'], "id" => $_POST['id']));
|
||||
echo json_encode(array("response" => $result));
|
||||
break;
|
||||
case 'restart':
|
||||
$result=xmlrpc_exec('opnsense.restart_service', array("service" => $_POST['service'], "id" => $_POST['id']));
|
||||
echo json_encode(array("response" => $result));
|
||||
break;
|
||||
case 'reload_templates':
|
||||
xmlrpc_exec('opnsense.configd_reload_all_templates');
|
||||
echo json_encode(array("status" => "done"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$carp_backup_version = get_xmlrpc_backup_version();
|
||||
include("head.inc");
|
||||
?>
|
||||
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
$( document ).ready(function() {
|
||||
function perform_actions_reload(todo)
|
||||
{
|
||||
var this_element = todo.shift();
|
||||
this_element['handle'].parent().hide();
|
||||
if (this_element['handle'].parent().data('busy-id') != "") {
|
||||
$("#"+this_element['handle'].parent().data('busy-id')).show();
|
||||
}
|
||||
$.post(window.location,this_element['params'], function(data) {
|
||||
if (this_element['handle'].parent().data('busy-id') != "") {
|
||||
$("#"+this_element['handle'].parent().data('busy-id')).hide();
|
||||
$("#"+this_element['handle'].parent().data('busy-id')+"_done").show();
|
||||
}
|
||||
// refresh page after last service action
|
||||
if (todo.length > 0) {
|
||||
perform_actions_reload(todo);
|
||||
} else {
|
||||
location.reload(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
$(".xmlrpc_srv_status_act").click(function(event){
|
||||
event.preventDefault();
|
||||
var todo = [];
|
||||
if ($(this).data('service_action') == 'restart_all') {
|
||||
$(this).parent().hide(); // hide button
|
||||
// reload all services
|
||||
$(".xmlrpc_srv_status_act").each(function(){
|
||||
if ($(this).data('service_action') == 'restart') {
|
||||
params = {};
|
||||
params['action'] = $(this).data('service_action');
|
||||
params['service'] = $(this).data('service_name');
|
||||
params['id'] = $(this).data('service_id');
|
||||
todo.push({'handle': $(this), 'params': params});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// reload single service
|
||||
params = {};
|
||||
params['action'] = $(this).data('service_action');
|
||||
params['service'] = $(this).data('service_name');
|
||||
params['id'] = $(this).data('service_id');
|
||||
todo.push({'handle': $(this), 'params': params});
|
||||
}
|
||||
// reload all templates first
|
||||
$("#action_templates").show();
|
||||
$.post(window.location, {action: 'reload_templates'}, function(data) {
|
||||
$("#action_templates").hide();
|
||||
$("#action_templates_done").show();
|
||||
perform_actions_reload(todo);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include("fbegin.inc"); ?>
|
||||
|
||||
<section class="page-content-main">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<?php
|
||||
if ($carp_backup_version === false):?>
|
||||
<?=print_info_box(gettext("The backup firewall doesn't seem to be accesible or is not configured"));?>
|
||||
<?php
|
||||
else:?>
|
||||
<section class="col-xs-12">
|
||||
<div class="content-box">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3"><?=gettext("Backup firewall versions");?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?=gettext("Firmware");?></th>
|
||||
<th><?=gettext("Base");?></th>
|
||||
<th><?=gettext("Kernel");?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><?=$carp_backup_version['firmware']['version'];?></td>
|
||||
<td><?=$carp_backup_version['base']['version'];?></td>
|
||||
<td><?=$carp_backup_version['kernel']['version'];?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="col-xs-12">
|
||||
<div class="content-box">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-condensed table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="4"><?=gettext("Backup services");?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?=gettext("Service");?></th>
|
||||
<th><?=gettext("Description");?></th>
|
||||
<th><?=gettext("Status");?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$xmlrpc_services = get_xmlrpc_services();
|
||||
$xmlrpc_services = empty($xmlrpc_services) ? array() : $xmlrpc_services;
|
||||
foreach ($xmlrpc_services as $sequence => $service):?>
|
||||
<tr>
|
||||
<td><?=$service['name'];?></td>
|
||||
<td><?=$service['description'];?></td>
|
||||
<td>
|
||||
<div data-busy-id="action_<?=$sequence;?>">
|
||||
<span class="btn btn-xs btn-<?=!empty($service['status']) ?"success" : "danger";?>">
|
||||
<span class="glyphicon glyphicon-<?=!empty($service['status']) ?"play" : "stop";?>"></span>
|
||||
</span>
|
||||
<?php
|
||||
if (!empty($service['status'])):?>
|
||||
<span
|
||||
data-service_action="restart"
|
||||
data-service_id="<?=!empty($service['id']) ? $service['id'] : "";?>"
|
||||
data-service_name="<?=$service['name'];?>"
|
||||
data-toggle="tooltip"
|
||||
data-placement="bottom"
|
||||
title="<?=sprintf(gettext('Restart %sService'), $service['name']);?>"
|
||||
class="btn btn-xs btn-default xmlrpc_srv_status_act glyphicon glyphicon-refresh">
|
||||
</span>
|
||||
<span
|
||||
data-service_action="stop"
|
||||
data-service_id="<?=!empty($service['id']) ? $service['id'] : "";?>"
|
||||
data-service_name="<?=$service['name'];?>"
|
||||
data-toggle="tooltip"
|
||||
data-placement="bottom"
|
||||
title="<?=sprintf(gettext('Stop %sService'), $service['name']);?>"
|
||||
class="btn btn-xs btn-default xmlrpc_srv_status_act glyphicon glyphicon-stop">
|
||||
</span>
|
||||
<?php
|
||||
else:?>
|
||||
<span
|
||||
data-service_action="start"
|
||||
data-service_id="<?=!empty($service['id']) ? $service['id'] : "";?>"
|
||||
data-service_name="<?=$service['name'];?>"
|
||||
data-toggle="tooltip"
|
||||
data-placement="bottom"
|
||||
title="<?=sprintf(gettext('Start %sService'), $service['name']);?>"
|
||||
class="btn btn-xs btn-default xmlrpc_srv_status_act glyphicon glyphicon-play">
|
||||
</span>
|
||||
<?php
|
||||
endif;?>
|
||||
</div>
|
||||
<div id="action_<?=$sequence;?>" style="display:none;">
|
||||
<i class="fa fa-spinner fa-pulse" aria-hidden="true"></i>
|
||||
</div>
|
||||
<div id="action_<?=$sequence;?>_done" style="display:none;">
|
||||
<i class="fa fa-check" aria-hidden="true"></i>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;?>
|
||||
<tr>
|
||||
<td><?=gettext("templates");?></td>
|
||||
<td></td>
|
||||
<td>
|
||||
<div id="action_templates" style="display:none;">
|
||||
<i class="fa fa-spinner fa-pulse" aria-hidden="true"></i>
|
||||
</div>
|
||||
<div id="action_templates_done" style="display:none;">
|
||||
<i class="fa fa-check" aria-hidden="true"></i>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?=gettext("all (*)");?></td>
|
||||
<td></td>
|
||||
<td>
|
||||
<div data-sequence="">
|
||||
<span
|
||||
data-service_action="restart_all"
|
||||
data-service_name="all"
|
||||
data-toggle="tooltip"
|
||||
data-placement="bottom"
|
||||
title="<?=gettext('Restart all services');?>"
|
||||
class="btn btn-xs btn-default xmlrpc_srv_status_act glyphicon glyphicon-refresh">
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php
|
||||
endif;?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php include("foot.inc"); ?>
|
||||
Loading…
x
Reference in New Issue
Block a user