mirror of
https://github.com/Akkadius/glass-isc-dhcp.git
synced 2025-07-31 01:24:56 +02:00
DHCP Server start / stop / restart - Fix dashboard refresh
This commit is contained in:
parent
ccf8f9d1ba
commit
8a73d5bb5d
1
app.js
1
app.js
@ -30,6 +30,7 @@ app.use('/dhcp_config', require('./routes/dhcp_config'));
|
|||||||
app.use('/dhcp_config_snapshots', require('./routes/dhcp_config_snapshots'));
|
app.use('/dhcp_config_snapshots', require('./routes/dhcp_config_snapshots'));
|
||||||
app.use('/dhcp_config_snapshot_view', require('./routes/dhcp_config_snapshot_view'));
|
app.use('/dhcp_config_snapshot_view', require('./routes/dhcp_config_snapshot_view'));
|
||||||
app.use('/dhcp_config_save', require('./routes/dhcp_config_save'));
|
app.use('/dhcp_config_save', require('./routes/dhcp_config_save'));
|
||||||
|
app.use('/dhcp_start_stop_restart', require('./routes/dhcp_start_stop_restart'));
|
||||||
app.use('/api_examples', require('./routes/api_examples'));
|
app.use('/api_examples', require('./routes/api_examples'));
|
||||||
app.use('/glass_settings', require('./routes/glass_settings'));
|
app.use('/glass_settings', require('./routes/glass_settings'));
|
||||||
app.use('/glass_settings_save', require('./routes/glass_settings_save'));
|
app.use('/glass_settings_save', require('./routes/glass_settings_save'));
|
||||||
|
@ -2,7 +2,21 @@
|
|||||||
* Created by cmiles on 8/9/2017.
|
* Created by cmiles on 8/9/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$( document ).ajaxComplete(function( event, request, settings ) {
|
||||||
|
check_dashboard_active();
|
||||||
|
});
|
||||||
|
|
||||||
|
function check_dashboard_active() {
|
||||||
|
if(window.location.pathname == "/" && in_dashboard != 1) {
|
||||||
|
in_dashboard = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
in_dashboard = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function modal (title, content, buttons) {
|
function modal (title, content, buttons) {
|
||||||
|
$('#modal-buttons').html('');
|
||||||
$('#modal-title').html(title);
|
$('#modal-title').html(title);
|
||||||
$('#modal-body').html(content);
|
$('#modal-body').html(content);
|
||||||
|
|
||||||
|
59
public/templates/dhcp_start_stop_restart.html
Normal file
59
public/templates/dhcp_start_stop_restart.html
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="header">
|
||||||
|
<h2>
|
||||||
|
[title]
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div class="body">
|
||||||
|
[c_content]
|
||||||
|
<div id="dhcp_start_stop_restart_result"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function process_action(action) {
|
||||||
|
switch (action) {
|
||||||
|
case "stop":
|
||||||
|
modal(
|
||||||
|
"Are you sure you want to stop server?",
|
||||||
|
"Stopping the server can be service affecting! Are you sure?",
|
||||||
|
'<button type="button" class="btn btn-link waves-effect" onclick="process_action(\'confirm_stop\')">STOP SERVER</button>'
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "confirm_stop":
|
||||||
|
$('#body-content .btn').attr('disabled', true);
|
||||||
|
$.post( "/dhcp_start_stop_restart", "action=stop", function( data ) {
|
||||||
|
$( "#dhcp_start_stop_restart_result" ).html( data );
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "restart":
|
||||||
|
modal(
|
||||||
|
"Are you sure you want to restart the server?",
|
||||||
|
"Restarting the server can cause very brief interruption. Are you sure?",
|
||||||
|
'<button type="button" class="btn btn-link waves-effect" onclick="process_action(\'confirm_restart\')">RESTART SERVER</button>'
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "confirm_restart":
|
||||||
|
$('#body-content .btn').attr('disabled', true);
|
||||||
|
$.post( "/dhcp_start_stop_restart", "action=restart", function( data ) {
|
||||||
|
$( "#dhcp_start_stop_restart_result" ).html( data );
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "start":
|
||||||
|
$('#body-content .btn').attr('disabled', true);
|
||||||
|
$.post( "/dhcp_start_stop_restart", "action=start", function( data ) {
|
||||||
|
$( "#dhcp_start_stop_restart_result" ).html( data );
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -105,7 +105,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="/start_stop_restart" pjax="1">
|
<a href="/dhcp_start_stop_restart" pjax="1">
|
||||||
<i class="material-icons">refresh</i>
|
<i class="material-icons">refresh</i>
|
||||||
<span>Start / Stop / Restart</span>
|
<span>Start / Stop / Restart</span>
|
||||||
</a>
|
</a>
|
||||||
@ -119,6 +119,13 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<a href="/glass_alerts" pjax="1">
|
||||||
|
<i class="material-icons">add_alert</i>
|
||||||
|
<span>Glass Alerts</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li class="header">Glass API</li>
|
<li class="header">Glass API</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="/api_examples" pjax="1">
|
<a href="/api_examples" pjax="1">
|
||||||
@ -155,7 +162,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<div id="modal-buttons"></div>
|
<div id="modal-buttons" style="display:inline-block"></div>
|
||||||
<button type="button" class="btn btn-link waves-effect" data-dismiss="modal">CLOSE</button>
|
<button type="button" class="btn btn-link waves-effect" data-dismiss="modal">CLOSE</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -212,6 +219,8 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var in_dashboard = 0;
|
||||||
|
|
||||||
function get_dashboard() {
|
function get_dashboard() {
|
||||||
$.get( "/get_dashboard", function( data ) {
|
$.get( "/get_dashboard", function( data ) {
|
||||||
$('#body-content').html(data);
|
$('#body-content').html(data);
|
||||||
@ -227,20 +236,21 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(window.location.pathname);
|
dashboard_timer = setInterval(function () {
|
||||||
|
if (window_focus && $('#shared-networks').length && in_dashboard == 1) {
|
||||||
|
get_dashboard();
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
if(window.location.pathname == "/") {
|
get_stats_timer = setInterval(function () {
|
||||||
dashboard_timer = setInterval(function () {
|
if (window_focus && $('#cpu-utilization').length && in_dashboard == 1) {
|
||||||
if (window_focus && $('#shared-networks').length) {
|
get_stats();
|
||||||
get_dashboard();
|
}
|
||||||
}
|
}, 5000);
|
||||||
}, 5000);
|
|
||||||
get_stats_timer = setInterval(function () {
|
if(window.location.pathname == "/") {
|
||||||
if (window_focus && $('#cpu-utilization').length) {
|
get_stats();
|
||||||
get_stats();
|
get_dashboard();
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
get_dashboard(); get_stats();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var window_focus = true;
|
var window_focus = true;
|
||||||
|
@ -31,7 +31,7 @@ router.post('/', function(req, res, next) {
|
|||||||
|
|
||||||
output = output.replace("\n", "<br>");
|
output = output.replace("\n", "<br>");
|
||||||
res.send(
|
res.send(
|
||||||
'<script type="text/javascript">modal (\'DHCP Config Save\', ' + JSON.stringify('Syntax OK') + ', "");'
|
'<script type="text/javascript">modal (\'DHCP Config Save\', ' + JSON.stringify('Syntax OK <br><br> Config Snapshot created') + ', "");'
|
||||||
);
|
);
|
||||||
/* Read Config */
|
/* Read Config */
|
||||||
var json_file = require('jsonfile');
|
var json_file = require('jsonfile');
|
||||||
|
70
routes/dhcp_start_stop_restart.js
Normal file
70
routes/dhcp_start_stop_restart.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
var express = require('express');
|
||||||
|
var router = express.Router();
|
||||||
|
var fs = require('fs');
|
||||||
|
var template_render = require('../lib/render_template.js');
|
||||||
|
|
||||||
|
router.get('/', function(req, res, next) {
|
||||||
|
|
||||||
|
var content = "";
|
||||||
|
|
||||||
|
content = template_render.get_template("dhcp_start_stop_restart");
|
||||||
|
content = template_render.set_template_variable(content, "title", "Start / Stop / Restart");
|
||||||
|
|
||||||
|
var exec = require('child_process').exec;
|
||||||
|
|
||||||
|
exec(' ps aux | grep dhcpd | grep -v "grep"', function(err, stdout, stderr) {
|
||||||
|
is_running = 0;
|
||||||
|
var result = stdout.split("\n");
|
||||||
|
for (var i = 0; i < result.length; i++) {
|
||||||
|
if(/dhcpd/i.test(result[i])){
|
||||||
|
is_running = 1;
|
||||||
|
}
|
||||||
|
// console.log('line ' + result[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var return_content = "";
|
||||||
|
|
||||||
|
if(is_running){
|
||||||
|
return_content = return_content + 'DHCP Server is online!<br><br>';
|
||||||
|
return_content = return_content + '<button type="button" onclick="process_action(\'stop\')" class="btn btn-default waves-effect">Stop Server</button> ';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return_content = return_content + 'DHCP Server is offline!<br><br>';
|
||||||
|
return_content = return_content + '<button type="button" onclick="process_action(\'start\')" class="btn btn-default waves-effect">Start Server</button> ';
|
||||||
|
}
|
||||||
|
|
||||||
|
return_content = return_content + '<button type="button" onclick="process_action(\'restart\')" class="btn btn-default waves-effect">Restart Server</button> ';
|
||||||
|
|
||||||
|
content = template_render.set_template_variable(content, "c_content", return_content);
|
||||||
|
|
||||||
|
res.send(template_render.get_index_template(content, req.url));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/', function(req, res, next) {
|
||||||
|
var request = req.body;
|
||||||
|
|
||||||
|
const execSync = require('child_process').execSync;
|
||||||
|
|
||||||
|
switch (request.action) {
|
||||||
|
case "stop":
|
||||||
|
dhcp_exec = execSync('service isc-dhcp-server stop && sleep 1');
|
||||||
|
res.send("<script type='text/javascript'>notification('DHCP Server Stopped');ignore_cache = 1;do_pjax_request('/dhcp_start_stop_restart');$('#mdModal').modal('hide');</script>");
|
||||||
|
break;
|
||||||
|
case "start":
|
||||||
|
dhcp_exec = execSync('service isc-dhcp-server start');
|
||||||
|
res.send("<script type='text/javascript'>notification('DHCP Server Started');ignore_cache = 1;do_pjax_request('/dhcp_start_stop_restart');</script>");
|
||||||
|
break;
|
||||||
|
case "restart":
|
||||||
|
dhcp_exec = execSync('service isc-dhcp-server restart && sleep 1');
|
||||||
|
res.send("<script type='text/javascript'>notification('DHCP Server Restarted " + dhcp_exec + "');ignore_cache = 1;do_pjax_request('/dhcp_start_stop_restart');$('#mdModal').modal('hide');</script>");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(request);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
Loading…
x
Reference in New Issue
Block a user