diff options
-rwxr-xr-x | web/api/write/linknet-add | 32 | ||||
-rw-r--r-- | web/index.html | 8 | ||||
-rw-r--r-- | web/js/nms-admin-pane.js | 19 | ||||
-rw-r--r-- | web/js/nms-map.js | 2 |
4 files changed, 60 insertions, 1 deletions
diff --git a/web/api/write/linknet-add b/web/api/write/linknet-add new file mode 100755 index 0000000..13ccd17 --- /dev/null +++ b/web/api/write/linknet-add @@ -0,0 +1,32 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 +use lib '/opt/gondul/include'; +use utf8; +use nms::web qw($dbh db_safe_quote get_input finalize_output); +use strict; +use warnings; + +my $in = get_input(); +my %tmp = %{JSON::XS::decode_json($in)}; + +my $q = $nms::web::dbh->prepare("INSERT INTO linknets (switch1, switch2) VALUES((SELECT switch FROM switches WHERE sysname = ? LIMIT 1), (SELECT switch FROM switches WHERE sysname = ? LIMIT 1));"); +my $sth = $nms::web::dbh->prepare("SELECT linknet FROM linknets WHERE switch1 = (SELECT switch FROM switches WHERE sysname = ? LIMIT 1) and switch2 = (SELECT switch FROM switches WHERE sysname = ? LIMIT 1);"); + +$sth->execute($tmp{'switch1'}, $tmp{'switch2'}); +my $affected = 0; +while ( my @row = $sth->fetchrow_array ) { + $affected += 1; +} + +print "X-affected: $affected\n"; +if ($affected eq 0) { + $q->execute($tmp{'switch1'}, $tmp{'switch2'}); +} + +$dbh->commit; +$nms::web::cc{'max-age'} = '0'; +$nms::web::cc{'stale-while-revalidate'} = '0'; +$nms::web::json{'state'} = 'ok'; + +print "X-ban: /api/public/.*\n"; +finalize_output(); diff --git a/web/index.html b/web/index.html index 63a9bd0..7617368 100644 --- a/web/index.html +++ b/web/index.html @@ -181,6 +181,14 @@ <div class="container-fluid" id="admin"> <div class="row-fluid" id="admin-row"> + <div> + <p>Add linknet</p> + <input id="admin-input-linknet1" type="text" placeholder="Switch 1" /> + <input id="admin-input-linknet2" type="text" placeholder="Switch 2" /> + <button class="btn btn-primary" + onclick="nmsAdmin.addLinknet()">Add</button> + </div> + <hr> </div> </div> <div class="container-fluid" id="oplog"> diff --git a/web/js/nms-admin-pane.js b/web/js/nms-admin-pane.js index 9edf9f9..235da8d 100644 --- a/web/js/nms-admin-pane.js +++ b/web/js/nms-admin-pane.js @@ -78,3 +78,22 @@ nmsAdmin.updateConfigPane = function() { } } } + +nmsAdmin.addLinknet = function() { + var myData = { + "switch1": document.getElementById("admin-input-linknet1").value, + "switch2": document.getElementById("admin-input-linknet2").value + }; + myData = JSON.stringify(myData); + $.ajax({ + type: "POST", + url: "/api/write/linknet-add", + dataType: "text", + data:myData, + success: function (data, textStatus, jqXHR) { + nmsData.invalidate("switches"); + document.getElementById("admin-input-linknet1").value = ""; + document.getElementById("admin-input-linknet2").value = ""; + } + }); +} diff --git a/web/js/nms-map.js b/web/js/nms-map.js index 224b3db..94e0173 100644 --- a/web/js/nms-map.js +++ b/web/js/nms-map.js @@ -408,7 +408,7 @@ nmsMap._drawBox = function(ctx, x, y, boxw, boxh) { }; nmsMap._connectSwitches = function(sw1, sw2, color1, color2) { - nmsMap._connectBoxes(this._getBox(sw1), this._getBox(sw2), + nmsMap._connectBoxes(nmsMap._getBox(sw1), nmsMap._getBox(sw2), color1, color2); }; |