From e4c8faaa57d3b4e28976c88d13d11752096d4254 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 2 Sep 2017 09:59:36 -0500 Subject: [PATCH] Fix form input highlights on initial load/ajax requests - add alert settings - slack integration --- app.js | 2 + config/glass_config.json | 9 ++++- lib/render_template.js | 2 +- public/assets/js/glass-core.js | 39 ++++++++++++++++++++ public/images/slack-icon.png | Bin 0 -> 5677 bytes public/templates/glass_alerts.html | 46 +++++++++++++++++++++++ public/templates/index.html | 3 -- routes/glass_alert_settings_save.js | 26 +++++++++++++ routes/glass_alerts.js | 55 ++++++++++++++++++++++++++++ routes/glass_settings_save.js | 12 +++++- 10 files changed, 186 insertions(+), 8 deletions(-) create mode 100644 public/images/slack-icon.png create mode 100644 public/templates/glass_alerts.html create mode 100644 routes/glass_alert_settings_save.js create mode 100644 routes/glass_alerts.js diff --git a/app.js b/app.js index a1ab72a..c443ff7 100644 --- a/app.js +++ b/app.js @@ -33,6 +33,8 @@ 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('/glass_settings', require('./routes/glass_settings')); +app.use('/glass_alerts', require('./routes/glass_alerts')); +app.use('/glass_alert_settings_save', require('./routes/glass_alert_settings_save')); app.use('/glass_settings_save', require('./routes/glass_settings_save')); /* API Routes */ diff --git a/config/glass_config.json b/config/glass_config.json index 7b0c860..78976a0 100644 --- a/config/glass_config.json +++ b/config/glass_config.json @@ -2,6 +2,11 @@ "admin_user": "glassadmin", "admin_password": "glassadmin", "leases_file": "/var/lib/dhcp/dhcpd.leases", - "log_file": "/var/lib/dhcp.log", - "config_file": "/etc/dhcp/dhcpd.conf" + "log_file": "/var/log/dhcp.log", + "config_file": "/etc/dhcp/dhcpd.conf", + "shared_network_critical_threshold": 95, + "shared_network_warning_threshold": 80, + "lease_per_second_threshold": 0, + "slack_webhook_url": "", + "slack_alert_channel": "" } diff --git a/lib/render_template.js b/lib/render_template.js index f26f460..b9d1792 100644 --- a/lib/render_template.js +++ b/lib/render_template.js @@ -24,7 +24,7 @@ module.exports = { return template.replace("[" + variable + "]", value); }, form_body: function (id, inputs) { - return '
' + inputs + '
'; + return '
' + inputs + '
'; }, form_input: function (title, input) { return '
' + input + '
'; diff --git a/public/assets/js/glass-core.js b/public/assets/js/glass-core.js index ee1b434..d186597 100644 --- a/public/assets/js/glass-core.js +++ b/public/assets/js/glass-core.js @@ -4,6 +4,45 @@ $( document ).ajaxComplete(function( event, request, settings ) { check_dashboard_active(); + + + /* + * Form input highlighting events + */ + + //On focus event + $('.form-control').focus(function () { + $(this).parent().addClass('focused'); + }); + + //On focusout event + $('.form-control').focusout(function () { + var $this = $(this); + if ($this.parents('.form-group').hasClass('form-float')) { + if ($this.val() == '') { $this.parents('.form-line').removeClass('focused'); } + } + else { + $this.parents('.form-line').removeClass('focused'); + } + }); + + //On label click + $('body').on('click', '.form-float .form-line .form-label', function () { + $(this).parent().find('input').focus(); + }); + + //Not blank form + $('.form-control').each(function () { + if ($(this).val() !== '') { + $(this).parents('.form-line').addClass('focused'); + } + }); + + $('.form-line').removeClass("focused"); +}); + +$( document ).ready(function() { + $('.form-line').removeClass("focused"); }); function check_dashboard_active() { diff --git a/public/images/slack-icon.png b/public/images/slack-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..50d2644254a03c13aecdbde6b05b3bdb33213696 GIT binary patch literal 5677 zcmai2RaBJW*8Uh!1`ugMYAESOa_AaBLb@BIL%JCdVdxM9>5v>6hYk@WL`p=E29d4- zhmN1~-=B5%TDvax&5n0H?-Tn{6Gn(njSm0-p{k0a&b^2KN5K#8ZJ)ID$i2hymRHpS z-%AMC4soC3d8!zD1Hj|{|0q@l*JBz0pcq$Gl+z2y-OmdS(Vxy3>~Sdw_Q;nF0ONoW zjyUTi^wJEE<7O|!PAc70Ic*zICgrEAJ{5j*ud8?z@|?@1ouIas2EB3m)UwcmBsz%7 z14Wk32dK{HvR{NG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d+Rc@4e~(1OdB2>Sk2F|kLJH~-hm_%Y z)NbD=qNi&~$Ud2sVU_gtnTiPvj@BP{t)b<=QH|njpQE-tF+LO~K9>AmFP)Y8c6K#1 zc9Z2S>*WLWw8!FflCQ>vpf2KRH%Ft0lb zf&v9!tc^l)WH&|%T?n3x&;IyyOtf3Zc*&zTpJ2k_EVubw(e@ASa;G~iMVdt|raX!V z;%R>8O2!LoGfD+T*%r4e>sit_oopL$1-9@XT;K-T&l{l-^Gylzn8xWuY%vW?n%?Z~ zc_B!BW}DNil>IA1zKwrX{f`zuceI9w?^Xvk)C{Oi=WRc;Cu#dOt(h{dIL0DjAAzs~ zS7(El&aL)xjdRf;u~+-@`e)qK0y}0$m+I>Yl(P00i_?+3{-_dzg%+xD*|C88=f$8J zN$7GjEqCr!hHfB+d+de$B_A1{DsnY#koNl}1$-G)1h{Iuf-|e6KR5?-okpA*f%5S} zxN(39y=9;BDpop}p;2du??1}@)u|7k2bF;g(eHDIG*=w@q%ua8dY2lB1yZJWSF5%x z0Gy(rJs1_$s&0+0tktc@mublw<|-TYs>66a^d5kL=54-wfoP%=7Al79D^79s6qmI3 v(pnGiE)yFMp%lsA{})ku&!KKrU&~xNvm4*OEYrN_djVA?O~qPytH}QY8!p*> literal 0 HcmV?d00001 diff --git a/public/templates/glass_alerts.html b/public/templates/glass_alerts.html new file mode 100644 index 0000000..856ff21 --- /dev/null +++ b/public/templates/glass_alerts.html @@ -0,0 +1,46 @@ +
+
+
+
+
+

+ Glass Alerts +

+
+
+ [c_content] +
+
+
+
+ +
+
+
+
+

+ Notification Settings + +

+
+
+ [n_content] +
+
+
+
+ +
+
+ +[save_button] + + \ No newline at end of file diff --git a/public/templates/index.html b/public/templates/index.html index b068822..bcb3270 100644 --- a/public/templates/index.html +++ b/public/templates/index.html @@ -203,9 +203,6 @@ - - - diff --git a/routes/glass_alert_settings_save.js b/routes/glass_alert_settings_save.js new file mode 100644 index 0000000..96bfbbe --- /dev/null +++ b/routes/glass_alert_settings_save.js @@ -0,0 +1,26 @@ +/** + * Created by cmiles on 8/9/2017. + */ + +var express = require('express'); +var router = express.Router(); + +router.post('/', function(req, res, next) { + var request = req.body; + var json_file = require('jsonfile'); + var glass_config = json_file.readFileSync('config/glass_config.json'); + + glass_config.shared_network_critical_threshold = request.shared_network_critical_threshold; + glass_config.shared_network_warning_threshold = request.shared_network_warning_threshold; + glass_config.lease_per_second_threshold = request.lease_per_second_threshold; + glass_config.slack_webhook_url = request.slack_webhook_url; + glass_config.slack_alert_channel = request.slack_alert_channel; + + json_file.writeFile('./config/glass_config.json', glass_config, {spaces: 2}, function(err) { + console.error(err); + }); + + res.send(''); +}); + +module.exports = router; \ No newline at end of file diff --git a/routes/glass_alerts.js b/routes/glass_alerts.js new file mode 100644 index 0000000..14fca3e --- /dev/null +++ b/routes/glass_alerts.js @@ -0,0 +1,55 @@ +/** + * Created by cmiles on 8/9/2017. + */ + +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) { + + glass_settings_template = template_render.get_template("glass_alerts"); + + var json_file = require('jsonfile'); + + /* Read Config */ + glass_config = json_file.readFileSync('config/glass_config.json'); + + /* Shared Network Alert Threshold (Critical) */ + input = template_render.form_input('Shared Network Alert Threshold (Critical)', ''); + + /* Shared Network Alert Threshold (Warning) */ + input = input + template_render.form_input('Shared Network Alert Threshold (Warning)', ''); + + /* Leases Per Second Threshold */ + input = input + template_render.form_input('Alert when Leases Per Second Reaches Below this Number', ''); + + //
+ + form_data = template_render.form_body("glass-alerts-form", input); + + glass_settings_template = template_render.set_template_variable(glass_settings_template, "c_content", form_data); + + /* Shared Network Alert Threshold (Critical) */ + input = template_render.form_input('Slack Webhook URL ', ''); + + /* Shared Network Alert Threshold (Warning) */ + input = input + template_render.form_input('Slack Channel ', ''); + + //
+ + form_data = template_render.form_body("glass-notifications-form", input); + + glass_settings_template = template_render.set_template_variable(glass_settings_template, "n_content", form_data); + + glass_settings_template = template_render.set_template_variable( + glass_settings_template, + "save_button", + '' + ); + + res.send(template_render.get_index_template(glass_settings_template, req.url)); +}); + +module.exports = router; \ No newline at end of file diff --git a/routes/glass_settings_save.js b/routes/glass_settings_save.js index 67591a4..61b7e40 100644 --- a/routes/glass_settings_save.js +++ b/routes/glass_settings_save.js @@ -9,8 +9,16 @@ router.post('/', function(req, res, next) { var request = req.body; var json_file = require('jsonfile'); - json_file.writeFile('./config/glass_config.json', request, {spaces: 2}, function(err) { - console.error(err); + var glass_config = json_file.readFileSync('config/glass_config.json'); + + glass_config.admin_user = request.admin_user; + glass_config.admin_password = request.admin_password; + glass_config.leases_file = request.leases_file; + glass_config.log_file = request.log_file; + glass_config.config_file = request.config_file; + + json_file.writeFile('./config/glass_config.json', glass_config, {spaces: 2}, function(err) { + console.error(err) }); res.send('');