diff --git a/app.js b/app.js index f6c96b5..08bad73 100644 --- a/app.js +++ b/app.js @@ -27,6 +27,8 @@ app.use('/get_stats', require('./routes/get_stats')); app.use('/dhcp_leases', require('./routes/dhcp_leases')); app.use('/dhcp_log', require('./routes/dhcp_log')); app.use('/dhcp_config', require('./routes/dhcp_config')); +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_save', require('./routes/dhcp_config_save')); app.use('/api_examples', require('./routes/api_examples')); app.use('/glass_settings', require('./routes/glass_settings')); diff --git a/public/assets/js/glass-pages/dhcp-config-snapshots.js b/public/assets/js/glass-pages/dhcp-config-snapshots.js new file mode 100644 index 0000000..146e582 --- /dev/null +++ b/public/assets/js/glass-pages/dhcp-config-snapshots.js @@ -0,0 +1,13 @@ +function view_snapshot(snapshot) { + $.post( "/dhcp_config_snapshot_view", "snapshot=" + encodeURIComponent(snapshot), function( data ) { + + $('#modal-title').html("Snapshot '" + snapshot + "'"); + $('#modal-body').html('
' + data + '
'); + + config_snapshot = ace.edit("snapshot"); + config_snapshot.setTheme("ace/theme/terminal"); + config_snapshot.$blockScrolling = Infinity; + + $('#mdModal').modal('show'); + }); +} \ No newline at end of file diff --git a/public/assets/js/glass-pages/page-dhcp-config.js b/public/assets/js/glass-pages/dhcp-config.js similarity index 100% rename from public/assets/js/glass-pages/page-dhcp-config.js rename to public/assets/js/glass-pages/dhcp-config.js diff --git a/public/assets/js/glass-pages/page-dhcp-logs.js b/public/assets/js/glass-pages/dhcp-logs.js similarity index 95% rename from public/assets/js/glass-pages/page-dhcp-logs.js rename to public/assets/js/glass-pages/dhcp-logs.js index df7270c..2bd2aed 100644 --- a/public/assets/js/glass-pages/page-dhcp-logs.js +++ b/public/assets/js/glass-pages/dhcp-logs.js @@ -10,6 +10,11 @@ function log_action (action){ editor.setValue(""); break; case "download_logs": + if(editor.getValue() == ''){ + notification('There is nothing to save!'); + return; + } + var d = new Date(); var am_pm = format_am_pm(d); var df = d.getMonth() + '-' + d.getDate() + '-' + d.getFullYear() + '_' + (d.getHours()) + '-' + d.getMinutes() + ' ' + am_pm; diff --git a/public/templates/dhcp_config.html b/public/templates/dhcp_config.html index 4654656..f9b7a7b 100644 --- a/public/templates/dhcp_config.html +++ b/public/templates/dhcp_config.html @@ -32,5 +32,5 @@ - + diff --git a/public/templates/dhcp_config_snapshots.html b/public/templates/dhcp_config_snapshots.html new file mode 100644 index 0000000..016d801 --- /dev/null +++ b/public/templates/dhcp_config_snapshots.html @@ -0,0 +1,20 @@ +
+
+
+
+

+ [title] +

+
+
+ [c_content] +
+
+
+
+
+ + + + + diff --git a/public/templates/dhcp_log.html b/public/templates/dhcp_log.html index ae9a9ce..b40ce3c 100644 --- a/public/templates/dhcp_log.html +++ b/public/templates/dhcp_log.html @@ -34,4 +34,4 @@ - + diff --git a/public/templates/index.html b/public/templates/index.html index dabbb92..3eca6be 100644 --- a/public/templates/index.html +++ b/public/templates/index.html @@ -98,6 +98,18 @@ DHCP Config +
  • + + cloud_download + DHCP Config Snapshots + +
  • +
  • + + refresh + Start / Stop / Restart + +
  • Settings
  • @@ -107,8 +119,6 @@
  • - -
  • Glass API
  • diff --git a/routes/dhcp_config_snapshot_view.js b/routes/dhcp_config_snapshot_view.js new file mode 100644 index 0000000..4556c44 --- /dev/null +++ b/routes/dhcp_config_snapshot_view.js @@ -0,0 +1,11 @@ +var express = require('express'); +var router = express.Router(); +var fs = require('fs'); +var template_render = require('../lib/render_template.js'); + +router.post('/', function(req, res, next) { + var request = req.body; + res.send(fs.readFileSync("./config_backups/" + request.snapshot, 'utf8')); +}); + +module.exports = router; \ No newline at end of file diff --git a/routes/dhcp_config_snapshots.js b/routes/dhcp_config_snapshots.js new file mode 100644 index 0000000..c16cafe --- /dev/null +++ b/routes/dhcp_config_snapshots.js @@ -0,0 +1,32 @@ +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_config_snapshots"); + + /* Read Config */ + var json_file = require('jsonfile'); + var glass_config = json_file.readFileSync('config/glass_config.json'); + + content = template_render.set_template_variable(content, "title", "DHCP Config Snaphots"); + + var backups = ''; + fs.readdirSync("./config_backups").forEach(function(file) { + backups = backups + "
  • " + file + '
  • '; + }); + + if(backups == ''){ + backups = 'There are no snapshots present at this time...'; + } + + content = template_render.set_template_variable(content, "c_content", backups); + + res.send(template_render.get_index_template(content, req.url)); +}); + +module.exports = router; \ No newline at end of file