diff options
Diffstat (limited to 'web')
| -rw-r--r-- | web/nms-public.gathering.org/api/API.rst | 113 | ||||
| -rwxr-xr-x | web/nms-public.gathering.org/api/public/dhcp | 20 | ||||
| -rwxr-xr-x | web/nms-public.gathering.org/api/public/switch-state | 8 | ||||
| -rwxr-xr-x | web/nms-public.gathering.org/api/public/switches | 2 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/index.html | 29 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/js/nms-color-util.js | 3 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/js/nms-data.js | 33 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/js/nms-info-box.js | 198 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/js/nms-map-handlers.js | 95 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/js/nms-map.js | 129 | ||||
| -rw-r--r-- | web/nms-public.gathering.org/js/nms.js | 86 | ||||
| -rwxr-xr-x | web/nms.gathering.org/api/public/switches | 3 | ||||
| -rw-r--r-- | web/nms.gathering.org/index.html | 7 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms-info-box.js | 27 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms-map.js | 38 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms.js | 5 | 
16 files changed, 458 insertions, 338 deletions
| diff --git a/web/nms-public.gathering.org/api/API.rst b/web/nms-public.gathering.org/api/API.rst deleted file mode 100644 index 61fbb5a..0000000 --- a/web/nms-public.gathering.org/api/API.rst +++ /dev/null @@ -1,113 +0,0 @@ -API-dok -======= - -Work in progress. - -There are two relevant paths: /api/public and /api/private. One requires -user-login in, the other does not. - -General: All end-points that output time-based data accept the "now=<time>" -argument, where, <time> is YYYY-MM-DDThh:mm:ss. E.g: - -GET /api/public/switch-state?now=2015-04-02T15:00:00 - -There is no guarantee that the data is exact time-wise, thus each endpoint -should also output relevant time stamps. - -Currently error handling sucks. - -This document is in no way complete, but it's a start. It will be updated -as time permits and API's stabilize. - -Private -....... - -/api/private/comment-add ------------------------- - -Methods: POST - -Add a comment - -/api/private/comment-change ---------------------------- - -Methods: POST - -Note that comments are never really deleted, but the state can be set to -deleted, making sure they are never shown. - -/api/private/comments ---------------------- - -Methods: GET - -Update frequency: on user input - -Lists comments. - -/api/private/snmp ------------------ - -Methods: GET - -Update frequency: Every few seconds, based on SNMP data. - -Returns full SNMP-data, split into two trees. 'misc' and 'ports'. - - -/api/private/switches-management --------------------------------- - -Methods: GET - -Update frequency: Infrequent (on topology/config changes) - -List management information for switches. - -/api/private/switch-add ------------------------ - -Methods: POST - -Add or update switches, supports same format as tools/add_switches.txt.pl - -Accepts an array of switches. - -Magic: If you set placement to be "reset", it will re-calculate placement -based on sysname. For new switches, this is redundant as an empty -placement-field will trigger the same behavior. - - -Public -...... - -/api/public/ping ----------------- - -Methods: GET -Update frequency: every second or so. - -Used to report linknet latency. - -The switch latency is being integrated into switch-state.pl and linknet -latency will similarly be moved. - -/api/public/switches --------------------- - -Methods: GET -Update frequency: Infrequent (on topology/config changes) - -List all switches and map positions. - -Used to draw switches on a map and provide static information. - -/api/public/switch-state ------------------------- - -Methods: GET -Update frequency: Every second - -Provides state for each switch, including total port speed, uplink port -speed, latency and temperature. diff --git a/web/nms-public.gathering.org/api/public/dhcp b/web/nms-public.gathering.org/api/public/dhcp new file mode 100755 index 0000000..91d52af --- /dev/null +++ b/web/nms-public.gathering.org/api/public/dhcp @@ -0,0 +1,20 @@ +#! /usr/bin/perl +# vim:ts=8:sw=8 + +use lib '../../../../include'; +use nms::web qw (%json finalize_output); +use strict; +use warnings; +use Data::Dumper; + +nms::web::setwhen('60m'); +my $q = $nms::web::dbh->prepare('select distinct on (sysname) extract(epoch from date_trunc(\'second\',time)) as time,sysname from dhcp join switches on dhcp.switch = switches.switch where ' . $nms::web::when . ' order by sysname,time desc;'); +$q->execute(); +while ( my $ref = $q->fetchrow_hashref() ) { +	my $sysname = $ref->{'sysname'}; +	$json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'}; +} + +$nms::web::cc{'max-age'} = "5"; +$nms::web::cc{'stale-while-revalidate'} = "30"; +finalize_output(); diff --git a/web/nms-public.gathering.org/api/public/switch-state b/web/nms-public.gathering.org/api/public/switch-state index 6f7573c..7fa6ff5 100755 --- a/web/nms-public.gathering.org/api/public/switch-state +++ b/web/nms-public.gathering.org/api/public/switch-state @@ -19,8 +19,12 @@ while ( my $ref = $q->fetchrow_hashref() ) {  	for my $porti (keys %{$data{'ports'}}) {  		my %port = %{$data{'ports'}{$porti}};  		my $smallport = $porti; -		$smallport =~ s/[0-9-].*$//; -		if ($porti =~  /ge-0\/0\/4[4-7]/) { +		if (not $smallport =~ m/^ae/) { +			$smallport =~ s/[0-9-].*$//; +		} else { +			$json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; +		} +		if ($porti =~  /ge-0\/0\/4[4-7]$/) {  			$json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'};  			$json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'};  			if ($port{'ifOperStatus'} eq "up") { diff --git a/web/nms-public.gathering.org/api/public/switches b/web/nms-public.gathering.org/api/public/switches index 7e7f10b..3aa8af8 100755 --- a/web/nms-public.gathering.org/api/public/switches +++ b/web/nms-public.gathering.org/api/public/switches @@ -12,7 +12,7 @@ use Data::Dumper;  $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,ip,poll_frequency,community,last_updated from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null');  $q2->execute();  while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/nms-public.gathering.org/index.html b/web/nms-public.gathering.org/index.html index ae09a26..081c206 100644 --- a/web/nms-public.gathering.org/index.html +++ b/web/nms-public.gathering.org/index.html @@ -58,10 +58,27 @@  	      </a>  	      <ul class="dropdown-menu" role="menu">  		<li><a href="#ping" onclick="setUpdater(handler_ping)">Ping map</a></li> +		<li><a href="#uplink" onclick="setUpdater(handler_uplinks)">Uplink map</a></li> +		<li><a href="#dhcp" onclick="setUpdater(handler_dhcp)">DHCP map</a></li> +		<li><a href="#comment" onclick="setUpdater(handler_comment)">Comment spotter</a></li> +		<li><a href="#temp" onclick="setUpdater(handler_temp)">Temperature map</a></li> +		<li><a href="#traffic" onclick="setUpdater(handler_traffic)">Traffic map</a></li> +		<li><a href="#traffictot" onclick="setUpdater(handler_traffic_tot)">Total switch traffic</a></li>  		<li><a href="#disco" onclick="setUpdater(handler_disco)">DISCO</a></li>  		<li class="divider"> </li> +		<li><a href="#" onclick="toggleLayer('nowPickerBox');startNowPicker();">Travel in time</a></li> +		<li><a href="#" onclick="nms.playback.startReplay('2015-04-01T09:00:00','2015-04-05T12:00:00');" title="Replay from opening 120 minutes per second">Replay TG</a></li> +		<li class="divider"> </li> +		<li class="dropdown-header">View</li>  		<li><a href="#" onclick="toggleNightMode()">Toggle Night Mode</a></li>  		<li class="divider"> </li> +		<li class="dropdown-header">Move switches</li> +	  	<li><a href="#" onclick="nmsMap.moveSet(true);">Enable switch moving</a></li> +	  	<li><a href="#" onclick="nmsMap.moveSet(false);">Disable switch moving</a></li> +	  	<li><a href="#" onclick="nmsInfoBox.showWindow('addSwitch')">Add switch</a></li> +		<li class="divider"> </li> +		<li class="dropdown-header">Help</li> +	  	<li><a href="#" onclick="toggleLayer('aboutKeybindings');" >Keyboard Shortcuts</a></li>  	      </ul>  	    </li>  	    <li><p id="updater_name" class="navbar-text"></p></li> @@ -129,22 +146,26 @@  		</tr>  		<tr>  		  <td>3</td> -		  <td>View temperature map</td> +		  <td>View DHCP map</td>  		</tr>  		<tr>  		  <td>4</td> -		  <td>View uplink traffic map</td> +		  <td>View comment spotter map</td>  		</tr>  		<tr>  		  <td>5</td> -		  <td>View comment spotter map</td> +		  <td>View temperature map</td>  		</tr>  		<tr>  		  <td>6</td> -		  <td>View total switch traffic map</td> +		  <td>View uplink traffic map</td>  		</tr>  		<tr>  		  <td>7</td> +		  <td>View total switch traffic map</td> +		</tr> +		<tr> +		  <td>9</td>  		  <td>View Disco map</td>  		</tr>  		<tr> diff --git a/web/nms-public.gathering.org/js/nms-color-util.js b/web/nms-public.gathering.org/js/nms-color-util.js index f50ee04..6b5a4b5 100644 --- a/web/nms-public.gathering.org/js/nms-color-util.js +++ b/web/nms-public.gathering.org/js/nms-color-util.js @@ -89,6 +89,5 @@ function getColor(x,y) {  	var data = imageData.data;  	if (data.length < 4)  		return false; -	var ret = 'rgb(' + data[0] + ',' + data[1] + ',' + data[2] + ')'; -	return ret; +    return 'rgb(' + data[0] + ',' + data[1] + ',' + data[2] + ')';  } diff --git a/web/nms-public.gathering.org/js/nms-data.js b/web/nms-public.gathering.org/js/nms-data.js index 6432a8d..14e5fed 100644 --- a/web/nms-public.gathering.org/js/nms-data.js +++ b/web/nms-public.gathering.org/js/nms-data.js @@ -82,7 +82,7 @@ var nmsData = nmsData || {  nmsData._dropData = function (name) {  	delete this[name];  	delete this.old[name]; -} +};  nmsData.removeSource = function (name) {  	if (this._sources[name] == undefined) { @@ -94,7 +94,7 @@ nmsData.removeSource = function (name) {  		clearInterval(this._sources[name]['handle']);  	}  	delete this._sources[name]; -} +};  /*   * Register a source. @@ -121,7 +121,7 @@ nmsData.registerSource = function(name, target) {  	}  	this.stats.pollSets++; -} +};  /*   * Add a handler (callback) for a source, using an id. @@ -130,7 +130,6 @@ nmsData.registerSource = function(name, target) {   * old id, not add a copy.   */  nmsData.addHandler = function(name, id, cb, cbdata) { -	try {  	var cbob = {  		id: id,  		name: name, @@ -143,9 +142,7 @@ nmsData.addHandler = function(name, id, cb, cbdata) {  	}  	this._sources[name].cbs[id] = cbob;  	this.updateSource(name); -	} catch (e) { -	} -} +};  /*   * Unregister all handlers with the "id" for all sources. @@ -157,11 +154,11 @@ nmsData.unregisterHandlerWildcard = function(id) {  	for (var v in nmsData._sources) {  		this.unregisterHandler(v, id);  	} -} +};  nmsData.unregisterHandler = function(name, id) {  	delete this._sources[name].cbs[id]; -} +};  /*   * Updates a source. @@ -184,11 +181,11 @@ nmsData.updateSource = function(name) {  		return;  	}  	this._genericUpdater(name, true); -} +};  nmsData.invalidate = function(name) {  	this._genericUpdater(name, false); -} +};  /*   * Reset a source, deleting all data, including old.   * @@ -198,7 +195,7 @@ nmsData.resetSource = function(name) {  	this[name] = {};  	this.old[name] = {};  	this.updateSource(name); -} +};  /*   * Updates nmsData[name] and nmsData.old[name], issuing any callbacks where @@ -239,16 +236,16 @@ nmsData._genericUpdater = function(name, cacheok) {  				nmsData[name] = data;  				nmsMap.drawNow();  				for (var i in nmsData._sources[name].cbs) { -					var tmp = nmsData._sources[name].cbs[i]; -					if (tmp.cb != undefined) { -						tmp.cb(tmp.cbdata); +					var tmp2 = nmsData._sources[name].cbs[i]; +					if (tmp2.cb != undefined) { +						tmp2.cb(tmp2.cbdata);  					}  				}  			} else { -				for (var i in nmsData._sources[name].cbs) { -					var tmp = nmsData._sources[name].cbs[i]; +				for (var j in nmsData._sources[name].cbs) { +					var tmp = nmsData._sources[name].cbs[j];  					if (tmp.cb != undefined && tmp.fresh) { -						nmsData._sources[name].cbs[i].fresh = false; +						nmsData._sources[name].cbs[j].fresh = false;  						tmp.cb(tmp.cbdata);  					}  				} diff --git a/web/nms-public.gathering.org/js/nms-info-box.js b/web/nms-public.gathering.org/js/nms-info-box.js index 5fdf044..2d12d56 100644 --- a/web/nms-public.gathering.org/js/nms-info-box.js +++ b/web/nms-public.gathering.org/js/nms-info-box.js @@ -15,8 +15,8 @@ var nmsInfoBox = nmsInfoBox || {    stats: {},    _container: false, //Container window    _window: false, //Active window (reference to _windowTypes object or false) -  _windowTypes: [], //List of all avaliable window types -} +  _windowTypes: [] //List of all avaliable window types +};  /*   * Shows a window from the _windowTypes list @@ -34,26 +34,30 @@ nmsInfoBox.showWindow = function (windowName,argument) {        return;      }    } -} +};  /*   * Refresh the active window - * - * Todo: Could use a less aggressive refresh that doesn't hide-show everything - *   */  nmsInfoBox.refresh = function() { +	if(!nmsInfoBox._window) +		return;    nmsInfoBox._show(); +}; +nmsInfoBox.update = function(argument) { +	if(!nmsInfoBox._window) +		return; +	nmsInfoBox._window.update(argument);  }  /*   * Internal function to show the active _window and pass along any arguments   */  nmsInfoBox._show = function(argument) { -  nmsData.addHandler("comments","switchshower",nmsInfoBox.update,argument); -  nmsData.addHandler("switches","switchshower",nmsInfoBox.update,argument); -  nmsData.addHandler("smanagement","switchshower",nmsInfoBox.update,argument); -  nmsData.addHandler("snmp","switchshower",nmsInfoBox.update,argument); +  nmsData.addHandler("comments","switchshower",nmsInfoBox.update,'comments'); +  nmsData.addHandler("switches","switchshower",nmsInfoBox.update,'switches'); +  nmsData.addHandler("smanagement","switchshower",nmsInfoBox.update,'smanagement'); +  nmsData.addHandler("snmp","switchshower",nmsInfoBox.update,'snmp');    this._window.load(argument); @@ -84,13 +88,13 @@ nmsInfoBox._show = function(argument) {    }    this._container.appendChild(panel);    this._container.style.display = "block"; -} +};  /*   * Hide the active window and tell it to unload   */  nmsInfoBox.hide = function() { -  if(this._container == false || this._window == false) +  if(!this._container || !this._window)      return;    this._container.style.display = "none";    this._window.unload(); @@ -99,7 +103,7 @@ nmsInfoBox.hide = function() {  	nmsData.unregisterHandler("switches","switchshower");  	nmsData.unregisterHandler("smanagement","switchshower");  	nmsData.unregisterHandler("snmp","switchshower"); -} +};  /*   * Window type: Add Switch @@ -122,6 +126,8 @@ nmsInfoBox._windowTypes.addSwitch = {    },    load: function(argument) {    }, +	update: function(type) { +	},    unload: function() {    },    save: function() { @@ -129,12 +135,12 @@ nmsInfoBox._windowTypes.addSwitch = {      var myData = JSON.stringify([{'sysname':sysname}]);      $.ajax({        type: "POST", -      url: "/api/private/switch-add", +      url: "/api/write/switch-add",        dataType: "text",        data:myData,        success: function (data, textStatus, jqXHR) {          var result = JSON.parse(data); -        if(result.switches_addded.length > 0) { +        if(result.switches_addded.length > 0) { // FIXME unresolved variable switches_addded            nmsInfoBox.hide();          }          nmsData.invalidate("switches"); @@ -159,17 +165,18 @@ nmsInfoBox._windowTypes.switchInfo = {    sw: '',    swi: '',    swm: '', +	commentsHash: false, +	activeView: '',    load: function(sw) {      if(sw) {        this.sw = sw;      }      this.swi = nmsData.switches["switches"][this.sw]; -    try { -    this.swm = nmsData.smanagement.switches[this.sw]; -    } catch(e) { -	this.swm = []; -    } -     +		try { +			this.swm = nmsData.smanagement.switches[this.sw]; +		} catch(e) { +			this.swm = []; +		}      var content = []; @@ -193,6 +200,15 @@ nmsInfoBox._windowTypes.switchInfo = {      this.content = infotable;    }, +	update: function(type) { +		switch (type) { +			case 'comments': +				if(this.activeView == "comments" && this.commentsHash != nmsData.comments.hash) { +					nmsInfoBox._windowTypes.switchInfo.showComments(); +				} +				break; +		} +	},    getTitle: function() {      return '<button type="button" class="edit btn btn-xs btn-warning" onclick="nmsInfoBox._windowTypes.switchInfo.showEdit(\'' + this.sw + '\');">Edit</button> <button type="button" class="comments btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showComments(\'' + this.sw + '\');">Comments</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'ports\');">Ports</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'misc\');">Misc</button> ' + this.sw + '';    }, @@ -203,41 +219,60 @@ nmsInfoBox._windowTypes.switchInfo = {      return this.childContent;    },    showComments: function() { +			this.activeView = "comments";        var domObj = document.createElement("div");        var comments = []; -      if (nmsData.comments.comments != undefined && nmsData.comments.comments[this.sw] != undefined) { -        for (var c in nmsData.comments.comments[this.sw]["comments"]) { -          var comment = nmsData.comments.comments[this.sw]["comments"][c]; -          if (comment["state"] == "active" || comment["state"] == "persist" || comment["state"] == "inactive") { -            comments.push(comment); -          } -        } -      } -      if (comments.length > 0) { -        var commenttable = nmsInfoBox._makeCommentTable(comments); -        commenttable.id = "info-switch-comments-table"; -        domObj.appendChild(commenttable); -        $(function () { $('[data-toggle="popover"]').popover({placement:"top",continer:'body'}) }) -      }        var commentbox = document.createElement("div");        commentbox.id = "commentbox";        commentbox.className = "panel-body";        commentbox.style.width = "100%"; -      commentbox.innerHTML = '<div class="input-group"><input type="text" class="form-control" placeholder="Comment" id="' + this.sw + '-comment"><span class=\"input-group-btn\"><button class="btn btn-default" onclick="addComment(\'' + this.sw + '\',document.getElementById(\'' + this.sw + '-comment\').value); document.getElementById(\'' + this.sw + '-comment\').value = \'\'; document.getElementById(\'' + this.sw + '-comment\').placeholder = \'Comment added. Wait for next refresh.\'; nmsInfoBox.hide();">Add comment</button></span></div>'; -      domObj.appendChild(commentbox); +      commentbox.innerHTML = '<div class="input-group"><input type="text" class="form-control" placeholder="Comment" id="' + this.sw + '-comment"><span class=\"input-group-btn\"><button class="btn btn-default" onclick="addComment(\'' + this.sw + '\',document.getElementById(\'' + this.sw + '-comment\').value); document.getElementById(\'' + this.sw + '-comment\').value = \'\'; document.getElementById(\'' + this.sw + '-comment\').placeholder = \'Comment added. Wait for next refresh.\';">Add comment</button></span></div>'; + +			// If we have no switch data, so just show comment form +			if(!nmsData.comments || !nmsData.comments.comments) { +				this.commentsHash = false; + +			// We have data, but its old, so don't change data +			} else if(this.commentsHash != false && this.commentsHash == nmsData.comments.hash) { +				return; + +			// We have data, refresh +			} else if(nmsData.comments.comments[this.sw]) { +				this.commentsHash = nmsData.comments.hash; +				for (var c in nmsData.comments.comments[this.sw]["comments"]) { +					var comment = nmsData.comments.comments[this.sw]["comments"][c]; +					if (comment["state"] == "active" || comment["state"] == "persist" || comment["state"] == "inactive") { +						comments.push(comment); +					} +				} + +				if (comments.length > 0) { +					var commenttable = nmsInfoBox._makeCommentTable(comments); +					commenttable.id = "info-switch-comments-table"; +					domObj.appendChild(commenttable); +					$(function () { $('[data-toggle="popover"]').popover({placement:"top",continer:'body'}) }) +				} + +			// We have no data for this switch, but its still correct +			} else { +				this.commentsHash = nmsData.comments.hash; +			} +      domObj.appendChild(commentbox);        this.childContent = domObj;        nmsInfoBox.refresh();    },    showEdit: function() { +		this.activeView = "edit";      var domObj = document.createElement("div");      var template = {};      nmsInfoBox._editValues = {}; +    var place;      for (var v in this.swi) {        if (v == "placement") { -        var place = JSON.stringify(this.swi[v]); +        place = JSON.stringify(this.swi[v]);          template[v] = place;          continue;        } @@ -255,6 +290,8 @@ nmsInfoBox._windowTypes.switchInfo = {        content.push([v, html]);      } +		content.sort(); +      var table = nmsInfoBox._makeTable(content, "edit");      domObj.appendChild(table); @@ -280,6 +317,7 @@ nmsInfoBox._windowTypes.switchInfo = {      nmsInfoBox.refresh();    },    showSNMP: function(tree) { +		this.activeView = "snmp";      var domObj = document.createElement("div");      var output = document.createElement("output"); @@ -297,13 +335,14 @@ nmsInfoBox._windowTypes.switchInfo = {    },    unload: function() {      this.childContent = false; +		this.commentsHash = false; +		this.activeView = "";    },    save: function() {      var myData = nmsInfoBox._editStringify(this.sw); -    console.log(myData);      $.ajax({        type: "POST", -      url: "/api/private/switch-update", +      url: "/api/write/switch-update",        dataType: "text",        data:myData,        success: function (data, textStatus, jqXHR) { @@ -311,7 +350,6 @@ nmsInfoBox._windowTypes.switchInfo = {          nmsData.invalidate("smanagement");        }      }); -    nmsInfoBox.hide();    }  }; @@ -322,7 +360,8 @@ nmsInfoBox._windowTypes.switchInfo = {  nmsInfoBox.click = function(sw)  {    this.showWindow("switchInfo",sw); -} +  this._windowTypes.switchInfo.showComments(); +};  /*   * General-purpose table-maker? @@ -352,7 +391,7 @@ nmsInfoBox._makeTable = function(content, caption) {  		td2.innerHTML = content[v][1];  	}  	return table; -} +};  /*   * Create and return a table for comments. @@ -395,7 +434,7 @@ nmsInfoBox._makeCommentTable = function(content) {  		td2.innerHTML = comment["comment"];  	}  	return table; -} +};  nmsInfoBox._searchSmart = function(id, sw) {  	try { @@ -424,6 +463,15 @@ nmsInfoBox._searchSmart = function(id, sw) {  				}  			}  		} +		if (nmsData.smanagement.switches[sw].ip.match(id)) { +			return true; +		} +		if (nmsData.smanagement.switches[sw].subnet4.match(id)) { +			return true; +		} +		if (nmsData.smanagement.switches[sw].subnet6.match(id)) { +			return true; +		}  		if (nmsData.snmp.snmp[sw].misc.sysDescr[0].match(id)) {  			return true;  		} @@ -431,7 +479,7 @@ nmsInfoBox._searchSmart = function(id, sw) {  		return false;  	}  	return false; -} +};  /*   * FIXME: Not sure this belongs here, it's really part of the "Core" ui, @@ -445,50 +493,54 @@ nmsInfoBox._search = function() {  		id = el.value;  	}  	if(id) { +		nmsMap.enableHighlights();  		for(var sw in nmsData.switches.switches) { -			if (id[0] == "/") { -				if (nmsInfoBox._searchSmart(id.slice(1),sw)) { -					matches.push(sw); -					nmsMap.setSwitchHighlight(sw,true); -				} else { -					nmsMap.setSwitchHighlight(sw,false); -				} +			if(sw.indexOf(id) > -1) { +				matches.push(sw); +				nmsMap.setSwitchHighlight(sw,true); +			} else if (nmsInfoBox._searchSmart(id,sw)) { +				matches.push(sw); +				nmsMap.setSwitchHighlight(sw,true);  			} else { -				if(sw.indexOf(id) > -1) { -					matches.push(sw); -					nmsMap.setSwitchHighlight(sw,true); -				} else { -					nmsMap.setSwitchHighlight(sw,false); -				} +				nmsMap.setSwitchHighlight(sw,false);  			}  		}  	} else { -		nmsMap.removeAllSwitchHighlights(); +		nmsMap.disableHighlights();  	}  	if(matches.length == 1) {  		document.getElementById("searchbox-submit").classList.add("btn-primary");  		document.getElementById("searchbox").dataset.match = matches[0]; -		document.getElementById("searchbox").addEventListener("keydown",nmsInfoBox._searchKeyListener,false);  	} else {  		document.getElementById("searchbox-submit").classList.remove("btn-primary");  		document.getElementById("searchbox").dataset.match = ''; -		document.getElementById("searchbox").removeEventListener("keydown",nmsInfoBox._searchKeyListener,false);  	} -} +};  nmsInfoBox._searchKeyListener = function(e) { -	if(e.keyCode == 13) { -		var sw = document.getElementById("searchbox").dataset.match; -		nmsInfoBox.showWindow("switchInfo",sw); +	switch (e.keyCode) { +		case 13: +			var sw = document.getElementById("searchbox").dataset.match; +			if(sw != '') { +				nmsInfoBox.showWindow("switchInfo",sw); +				this._windowTypes.switchInfo.showComments(); +			} +			break; +		case 27: +			document.getElementById("searchbox").dataset.match = ''; +			document.getElementById("searchbox").value = ''; +			nmsInfoBox._search(); +			nmsInfoBox.hide(); +			break;  	} -} +};  nmsInfoBox._nullBlank = function(x) {  	if (x == null || x == false || x == undefined)  		return "";  	return x; -} +};  nmsInfoBox._editChange = function(sw, v) { @@ -509,13 +561,9 @@ nmsInfoBox._editChange = function(sw, v) {  	var myData = nmsInfoBox._editStringify(sw);  	var out = document.getElementById("edit-output");  	out.value = myData; -} +};  nmsInfoBox._editStringify = function(sw) { -	for (var key in nmsInfoBox._editValues) { -		var val = nmsInfoBox._editValues[key]; -	} -	nmsInfoBox._editValues['sysname'] = sw; -	var myData = JSON.stringify([nmsInfoBox._editValues]); -	return myData; -} +    nmsInfoBox._editValues['sysname'] = sw; +    return JSON.stringify([nmsInfoBox._editValues]); +}; diff --git a/web/nms-public.gathering.org/js/nms-map-handlers.js b/web/nms-public.gathering.org/js/nms-map-handlers.js index a6dc942..0bec084 100644 --- a/web/nms-public.gathering.org/js/nms-map-handlers.js +++ b/web/nms-public.gathering.org/js/nms-map-handlers.js @@ -49,6 +49,12 @@ var handler_traffic_tot = {  	name:"Switch traffic map"  }; +var handler_dhcp = { +	init:dhcpInit, +	tag:"dhcp", +	name:"DHCP map" +}; +  var handler_disco = {  	init:discoInit,  	tag:"disco", @@ -68,7 +74,8 @@ var handlers = [  	handler_traffic,  	handler_disco,  	handler_comment, -	handler_traffic_tot +	handler_traffic_tot, +	handler_dhcp  	];  /* @@ -84,7 +91,7 @@ function uplinkUpdater()  		return;  	if (!nmsData.switchstate.switches)  		return; -	for (sw in nmsData.switches.switches) { +	for (var sw in nmsData.switches.switches) {  		var uplinks=0;  		if (nmsData.switchstate.switches[sw] == undefined || nmsData.switchstate.switches[sw].uplinks == undefined) {  			uplinks=0; @@ -95,12 +102,12 @@ function uplinkUpdater()  		if (uplinks == 0) {  			nmsMap.setSwitchColor(sw,"white"); -		} else if (nuplinks == uplinks) { -			nmsMap.setSwitchColor(sw,green); -		} else if (nuplinks - uplinks == 1) { -			nmsMap.setSwitchColor(sw, orange); -		} else if (nuplinks - uplinks == 2) { +		} else if (uplinks == 1) {  			nmsMap. setSwitchColor(sw, red); +		} else if (uplinks == 2) { +			nmsMap.setSwitchColor(sw, orange); +		} else if (uplinks == 3) { +			nmsMap.setSwitchColor(sw,green);  		} else if (uplinks > 3) {  			nmsMap.setSwitchColor(sw, blue);  		} @@ -115,9 +122,9 @@ function uplinkInit()  	nmsData.addHandler("switches","mapHandler",uplinkUpdater);  	nmsData.addHandler("switchstate","mapHandler",uplinkUpdater);  	setLegend(1,"white","0 uplinks");	 -	setLegend(2,red,"2 missing");	 -	setLegend(3,orange,"1 missing");	 -	setLegend(4,green,"0 missing");	 +	setLegend(2,red,"1 uplink");	 +	setLegend(3,orange,"2 uplinks");	 +	setLegend(4,green,"3 uplinks");	  	setLegend(5,blue,"4 uplinks");	  } @@ -139,9 +146,9 @@ function trafficUpdater()  {  	if (!nms.switches_now["switches"])  		return; -	for (sw in nms.switches_now["switches"]) { +	for (var sw in nms.switches_now["switches"]) {  		var speed = 0; -		for (port in nms.switches_now["switches"][sw]["ports"]) { +		for (var port in nms.switches_now["switches"][sw]["ports"]) {  			if (/ge-0\/0\/44$/.exec(port) ||  			    /ge-0\/0\/45$/.exec(port) ||  			    /ge-0\/0\/46$/.exec(port) || @@ -177,9 +184,9 @@ function trafficTotUpdater()  {  	if (!nms.switches_now["switches"])  		return; -	for (sw in nms.switches_now["switches"]) { +	for (var sw in nms.switches_now["switches"]) {  		var speed = 0; -		for (port in nms.switches_now["switches"][sw]["ports"]) { +		for (var port in nms.switches_now["switches"][sw]["ports"]) {  			if (!nms.switches_then["switches"][sw] ||  			    !nms.switches_then["switches"][sw]["ports"] ||  			    !nms.switches_then["switches"][sw]["ports"][port]) @@ -220,14 +227,14 @@ function tempUpdater()  	if(!nmsData.switches)  		return; -	for (sw in nmsData.switches["switches"]) { +	for ( var sw in nmsData.switches["switches"]) {  		var t = "white";  		var temp = ""; - -		if(!nmsData.snmp || !nmsData.snmp.snmp[sw] || !nmsData.snmp.snmp[sw]["misc"] || !nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"]) +		 +		if(!nmsData.snmp || !nmsData.snmp.snmp || ! nmsData.snmp.snmp[sw] || !nmsData.snmp.snmp[sw]["misc"] || !nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"])  			continue; -		tempObj = nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"]; +		var tempObj = nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"];  		Object.keys(tempObj).forEach(function (key) {  			if(key == "") {  				temp = tempObj[key] + "°C"; @@ -259,6 +266,7 @@ function pingUpdater()  	}  	for (var sw in nmsData.switches.switches) {  		try { +            var c;  			if (nmsData.ping.switches[sw].age > 0) {  				c = red;  			} else { @@ -291,6 +299,8 @@ function commentUpdater()  	if (nmsData.comments == undefined || nmsData.comments.comments == undefined) {  		return  	} +	if(!nmsData.switches)  +		return;  	for (var sw in nmsData.switches.switches) {  		var c = "white";  		if (nmsData.comments.comments[sw] == undefined) { @@ -336,6 +346,55 @@ function commentInit()  	setLegend(5,green ,"Old/inactive only");	  } +function getDhcpColor(stop) +{ +	stop = parseInt(stop); +	stop = stop * 0.85; +	if (stop < 0) +		stop = 1000; +	if (stop > 1000) +		stop = 1000; +	return getColorStop(stop); +} + +function dhcpUpdater() +{ +	var realnow = Date.now(); +	var now = Math.floor(realnow / 1000); +	if (nmsData.dhcp == undefined || nmsData.dhcp.dhcp == undefined) { +		return +	} +	if (nmsData.switches == undefined || nmsData.switches.switches == undefined) { +		return; +	} +	try { +	for (var sw in nmsData.switches.switches) { +		var c = "white"; +		if (nmsData.dhcp.dhcp[sw] == undefined) { +			nmsMap.setSwitchColor(sw,c); +			continue; +		} +		var s = nmsData.dhcp.dhcp[sw]; +		var then = parseInt(s); +		c = getDhcpColor(now - then); +		nmsMap.setSwitchColor(sw, c); +	} +	} catch(e) { +		console.log(e); +	} +} + +function dhcpInit() +{ +	drawGradient([green,lightgreen,orange,red]); +	nmsData.addHandler("dhcp","mapHandler",dhcpUpdater); +	setLegend(1,"white","Undefined"); +	setLegend(2,getDhcpColor(1),"1 Second old"); +	setLegend(3,getDhcpColor(300),"300 Seconds old"); +	setLegend(4,getDhcpColor(900),"900 Seconds old"); +	setLegend(5,getDhcpColor(1200),"1200 Seconds old"); +} +  /*   * Testing-function to randomize colors of linknets and switches   */ diff --git a/web/nms-public.gathering.org/js/nms-map.js b/web/nms-public.gathering.org/js/nms-map.js index b74626a..648643c 100644 --- a/web/nms-public.gathering.org/js/nms-map.js +++ b/web/nms-public.gathering.org/js/nms-map.js @@ -10,7 +10,8 @@   * nmsMap.setSwitchColor(switch,color)   * nmsMap.setSwitchInfo(switch,info)   * nmsMap.setSwitchHighlight(switch,true/false) - * nmsMap.removeAllSwitchHighlights() + * nmsMap.enableHighlights() + * nmsMap.disableHighlights()   */ @@ -46,21 +47,24 @@ var nmsMap = nmsMap || {  	},  	_color: { }, +	_linknets: {} ,  	_highlight: { }, +	_highlightActive: false,  	_c: {} -} +};  nmsMap._loadEvent = function(e) {  	nmsMap._init = false;  	nmsMap._drawAllSwitches(); -} +}; +  nmsMap.init = function() {  	this._initContexts();  	this._init = true;  	nmsData.addHandler("switches","nmsMap",function(){nmsMap._resizeEvent();});  	window.addEventListener('resize',nmsMap._resizeEvent,true);  	window.addEventListener('load',nmsMap._loadEvent,true); -} +};  nmsMap.setSwitchColor = function(sw, color) {  	if (this._color[sw] != color) { @@ -70,22 +74,30 @@ nmsMap.setSwitchColor = function(sw, color) {  	} else {  		this.stats.colorSame++;  	} -} +}; +  nmsMap.setSwitchHighlight = function(sw, highlight) { -	if(highlight) -		highlight == true; -	if (this._highlight[sw] != highlight) { -		this._highlight[sw] = highlight; -		this._drawSwitch(sw); -		this.stats.highlightChange++; -	} -} +    if( highlight ) +        highlight = true; +    if ( this._highlight[sw] != highlight ) { +        this.stats.highlightChange++; +        this._highlight[sw] = highlight; +    } +    this._drawSwitch(sw); +}; + + +nmsMap.enableHighlights = function() { +    this._highlightActive = true; +}; + + +nmsMap.disableHighlights = function() { +    this._highlightActive = false; +    this._drawAllSwitches(); +}; -nmsMap.removeAllSwitchHighlights = function() { -	for(var sw in this._highlight) -		this.setSwitchHighlight(sw,false); -}  nmsMap.reset = function() {  	for (var sw in this._color) { @@ -94,7 +106,7 @@ nmsMap.reset = function() {  	for (var sw in this._info) {  		nmsMap.setSwitchInfo(sw, undefined);  	} -} +};  nmsMap.setSwitchInfo = function(sw,info) {  	if (this._info[sw] != info) { @@ -104,19 +116,19 @@ nmsMap.setSwitchInfo = function(sw,info) {  	} else {  		this.stats.switchInfoSame++;  	} -} +};  nmsMap._initContext = function(name) {  	this._c[name] = {};  	this._c[name].c = document.getElementById(name + "Canvas");  	this._c[name].ctx = this._c[name].c.getContext('2d'); -} +};  nmsMap._initContexts = function() {  	for (var context in this.contexts) {  		this._initContext(this.contexts[context]);  	} -} +};  nmsMap._resizeEvent = function() {  	var width = window.innerWidth - nmsMap._c.bg.c.offsetLeft; @@ -149,7 +161,7 @@ nmsMap._resizeEvent = function() {  		nmsMap.drawNow();  		nmsMap.stats.resizeEvents++;  	} -} +};  /*   * Draw current time-window @@ -177,10 +189,10 @@ nmsMap.drawNow = function ()  	ctx.fillStyle = "white";  	ctx.strokeStyle = "black";  	ctx.lineWidth = nms.fontLineFactor; -	ctx.strokeText(now, 0 + this._settings.textMargin, 25); -	ctx.fillText(now, 0 + this._settings.textMargin, 25); +	ctx.strokeText(now, this._settings.textMargin, 25); +	ctx.fillText(now, this._settings.textMargin, 25);  	ctx.restore(); -} +};  nmsMap.setNightMode = function(toggle) {  	if (this._nightmode == toggle) @@ -196,14 +208,14 @@ nmsMap.setNightMode = function(toggle) {  		this._c.blur.c.style.display = "";  	}  	nmsMap._drawBG(); -} +};  nmsMap._drawBG = function() {  	var imageObj = document.getElementById('source');  	this._c.bg.ctx.drawImage(imageObj, 0, 0, nmsMap._canvas.width, nmsMap._canvas.height);  	if(this._nightmode)  		nmsMap._invertBG(); -} +};  nmsMap._invertBG = function() {  	var imageData = this._c.bg.ctx.getImageData(0, 0, nmsMap._canvas.width, nmsMap._canvas.height); @@ -215,7 +227,7 @@ nmsMap._invertBG = function() {  		data[i + 2] = 255 - data[i + 2];  	}  	this._c.bg.ctx.putImageData(imageData, 0, 0); -} +};  nmsMap._getBox = function(sw) {  	var box = nmsData.switches.switches[sw]['placement']; @@ -224,7 +236,7 @@ nmsMap._getBox = function(sw) {  	box.width = parseInt(box.width);  	box.height = parseInt(box.height);  	return box; -} +};  nmsMap._drawSwitchBlur = function(sw)  { @@ -235,10 +247,11 @@ nmsMap._drawSwitchBlur = function(sw)  	this._c.blur.ctx.fillStyle = "red";  	this._c.blur.ctx.shadowBlur = 30;  	this._c.blur.ctx.shadowColor = "white"; -	this._c.blur.ctx.scale(this.scale, this.scale); // FIXME +	this._c.blur.ctx.scale(this.scale, this.scale); // FIXME <- fix what?!  	this._c.blur.ctx.fillRect(box['x'],box['y'],box['width'],box['height']);  	this._c.blur.ctx.restore(); -} +}; +  nmsMap._drawSwitch = function(sw)  {  	// XXX: If a handler sets a color before switches are loaded... The @@ -247,8 +260,12 @@ nmsMap._drawSwitch = function(sw)  		return;  	var box = this._getBox(sw);  	var color = nmsMap._color[sw]; -	if(nmsMap._highlight[sw]) { -		color = red; +	if(this._highlightActive) { +		if(nmsMap._highlight[sw]) { +			color = green; +		} else { +			color = white; +		}  	}  	if (color == undefined) {  		color = blue; @@ -257,7 +274,7 @@ nmsMap._drawSwitch = function(sw)  	this._drawBox(this._c.switch.ctx, box['x'],box['y'],box['width'],box['height']);  	this._c.switch.ctx.shadowBlur = 0;  	this._drawText(this._c.text.ctx, sw,box); -} +};  nmsMap._drawSwitchInfo = function(sw) {  	var box = this._getBox(sw); @@ -266,14 +283,14 @@ nmsMap._drawSwitchInfo = function(sw) {  	} else {  		this._drawText(this._c.textInfo.ctx, this._info[sw], box, "right");  	} -} +};  nmsMap._clearBox = function(ctx,box) {  	ctx.save();  	ctx.scale(this.scale,this.scale);  	ctx.clearRect(box['x'], box['y'], box['width'], box['height']);  	ctx.restore(); -} +};  nmsMap._drawText = function(ctx, text, box, align) {  	var rotate = false; @@ -309,8 +326,13 @@ nmsMap._drawText = function(ctx, text, box, align) {  	ctx.strokeText(text, 0, 0);  	ctx.fillText(text, 0, 0);  	ctx.restore(); -} +}; +nmsMap._drawAllLinknets = function() { +	for (var l in nmsData.switches.linknets) { +		nmsMap._connectSwitches(nmsData.switches.linknets[l].switch1, nmsData.switches.linknets[l].switch2); +	} +}  nmsMap._drawAllSwitches = function() {  	if (nmsData.switches == undefined) {  		this.stats.earlyDrawAll++; @@ -321,7 +343,7 @@ nmsMap._drawAllSwitches = function() {  	}  	if (this._nightmode)  		this._drawAllBlur(); -} +};  nmsMap._drawAllBlur = function() {  	if (nmsMap._blurDrawn == true) @@ -330,22 +352,22 @@ nmsMap._drawAllBlur = function() {  	for (var sw in nmsData.switches.switches) {  		nmsMap._drawSwitchBlur(sw);  	} -} +};  nmsMap._drawBox = function(ctx, x, y, boxw, boxh) {  	ctx.save(); -	ctx.scale(this.scale, this.scale); // FIXME +	ctx.scale(this.scale, this.scale); // FIXME <- what?!  	ctx.fillRect(x,y, boxw, boxh);  	ctx.lineWidth = 1;  	ctx.strokeStyle = "#000000";  	ctx.strokeRect(x,y, boxw, boxh);  	ctx.restore(); -} +};  nmsMap._connectSwitches = function(sw1, sw2, color1, color2) {  	nmsMap._connectBoxes(this._getBox(sw1), this._getBox(sw2),  			     color1, color2); -} +};  /*   * Draw a line between two boxes, with a gradient going from color1 to @@ -372,13 +394,13 @@ nmsMap._connectBoxes = function(box1, box2,color1, color2) {  	ctx.lineWidth = 5;  	ctx.stroke();  	ctx.restore(); -} +};  nmsMap.moveSet = function(toggle) {  	nmsMap._moveInProgress = toggle;  	if (!toggle)  		nmsMap._moveStopListen(); -} +};  /*   * onclick handler for the canvas. @@ -395,7 +417,7 @@ nmsMap.canvasClick = function(e)  			nmsInfoBox.click(sw);  		}  	} -} +};  nmsMap._clearOld = function(box) {  	if (box) { @@ -405,7 +427,7 @@ nmsMap._clearOld = function(box) {  		nmsMap._c.top.ctx.clearRect(box['x'] - 5, box['y'] - 5, box['width'] + 10, box['height'] + 10);  		nmsMap._c.top.ctx.restore();  	} -} +};  nmsMap._moveMove = function(e) {  	nmsMap._moveX = (e.pageX - e.target.offsetLeft) / nmsMap.scale; @@ -423,28 +445,29 @@ nmsMap._moveMove = function(e) {  	nmsMap._c.top.ctx.fillStyle = "red";  	nmsMap._drawBox(nmsMap._c.top.ctx, box['x'], box['y'], box['width'], box['height']);  	nmsMap._c.top.ctx.restore(); -} +};  nmsMap._moveSubmit = function() {  	var data = {  		sysname: nmsMap._moving,  		placement: nmsMap._moveOldBox -	} +	};  	var myData = JSON.stringify([data]);  	$.ajax({  		type: "POST", -		url: "/api/private/switch-update", +		url: "/api/write/switch-update",  		dataType: "text",  		data:myData,  		success: function (data, textStatus, jqXHR) {  			nmsData.invalidate("switches");  		}  	}); -} +}; +  nmsMap._moveStopListen = function() {  	nmsMap._c.input.c.removeEventListener('mousemove',nmsMap._moveMove, true);  	nmsMap._c.input.c.removeEventListener('mouseup',nmsMap._moveDone, true); -} +};  nmsMap._moveDone = function(e) {  	nmsMap._moveStopListen(); @@ -453,7 +476,7 @@ nmsMap._moveDone = function(e) {  	}  	nmsMap._moveSubmit();  	nmsMap._clearOld(nmsMap._moveOldBox); -} +};  nmsMap._moveStart = function(sw, e)  { @@ -464,7 +487,7 @@ nmsMap._moveStart = function(sw, e)  	nmsMap._moveBox = nmsData.switches.switches[sw].placement;  	nmsMap._c.input.c.addEventListener('mousemove',nmsMap._moveMove,true);  	nmsMap._c.input.c.addEventListener('mouseup',nmsMap._moveDone,true); -} +};  /* diff --git a/web/nms-public.gathering.org/js/nms.js b/web/nms-public.gathering.org/js/nms.js index fcb8437..f145177 100644 --- a/web/nms-public.gathering.org/js/nms.js +++ b/web/nms-public.gathering.org/js/nms.js @@ -16,8 +16,8 @@ var nms = {  	 * FIXME: Should just stop using these.  	 */  	timers: { -		playback:false, -	}, +		playback:false +    },  	menuShowing:true,  	/* @@ -84,7 +84,7 @@ function nmsTimer(handler, interval, name, description) {  		};  	this.setInterval = function(interval) { -		var started = this.handle == false ? false : true; +		var started = this.handle != false;  		this.stop();  		this.interval = parseInt(interval);  		if (started) @@ -162,27 +162,27 @@ function stringToEpoch(t)  function epochToString(t)  {  	// Adjust for timezone when converting from epoch (UTC) to string (local) -	var d = new Date(parseInt(t) * parseInt(1000)); -	var timezoneOffset = d.getTimezoneOffset() * -60; +	var date = new Date(parseInt(t) * parseInt(1000)); +	var timezoneOffset = date.getTimezoneOffset() * -60;  	t = t - timezoneOffset; -	var d = new Date(parseInt(t) * parseInt(1000)); -	var str = d.getFullYear() + "-"; -	if (parseInt(d.getMonth()) < 9) +    date = new Date(parseInt(t) * parseInt(1000)); +	var str = date.getFullYear() + "-"; +	if (parseInt(date.getMonth()) < 9)  		str += "0"; -	str += (parseInt(d.getMonth())+1) + "-"; -	if (d.getDate() < 10) +	str += (parseInt(date.getMonth())+1) + "-"; +	if (date.getDate() < 10)  		str += "0"; -	str += d.getDate() + "T"; -	if (d.getHours() < 10) +	str += date.getDate() + "T"; +	if (date.getHours() < 10)  		str += "0"; -	str += d.getHours() + ":"; -	if (d.getMinutes() < 10) +	str += date.getHours() + ":"; +	if (date.getMinutes() < 10)  		str += "0"; -	str += d.getMinutes() + ":"; -	if (d.getSeconds() < 10) +	str += date.getMinutes() + ":"; +	if (date.getSeconds() < 10)  		str += "0"; -	str += d.getSeconds(); +	str += date.getSeconds();  	return str;  } @@ -207,7 +207,7 @@ nms.playback.startReplay = function(startTime,stopTime) {  	nms.playback.stopTime = stringToEpoch(stopTime);  	nms.now = epochToString(nms.playback.startTime);  	nms.playback.play(); -} +};  /*   * Pause playback @@ -215,7 +215,7 @@ nms.playback.startReplay = function(startTime,stopTime) {  nms.playback.pause = function() {  	nms.timers.playback.stop();  	nms.playback.playing = false; -} +};  /*   * Start playback @@ -224,7 +224,7 @@ nms.playback.play = function() {  	nms.playback.tick();  	nms.timers.playback.start();  	nms.playback.playing = true; -} +};  /*   * Toggle playback @@ -235,19 +235,18 @@ nms.playback.toggle = function() {  	} else {  		nms.playback.play();  	} -} +};  /*   * Jump to place in time   */  nms.playback.setNow = function(now) { -	var now = parseNow(now); -	nms.now = now; +	nms.now = parseNow(now);  	nms.playback.stopTime = false;  	nms.playback.startTime = false;  	nms.playback.tick(); -} +};  /*   * Step forwards or backwards in timer @@ -260,7 +259,7 @@ nms.playback.stepTime = function(n)  	if(!nms.playback.playing)  		nms.playback.tick(); -} +};  /*   * Ticker to trigger updates, and advance time if replaying @@ -288,7 +287,7 @@ nms.playback.tick = function()  	if(nms.now !== false && nms.playback.playing) {  		nms.playback.stepTime(nms.playback.replayIncrement);  	} -} +};  /*   * Helper function for safely getting a valid now-epoch @@ -377,7 +376,7 @@ function commentChange(id,state)  	myData = JSON.stringify(myData);  	$.ajax({  		type: "POST", -		url: "/api/private/comment-change", +		url: "/api/write/comment-change",  		dataType: "text",  		data:myData,  		success: function (data, textStatus, jqXHR) { @@ -395,7 +394,7 @@ function addComment(sw,comment)  	myData = JSON.stringify(myData);  	$.ajax({  		type: "POST", -		url: "/api/private/comment-add", +		url: "/api/write/comment-add",  		dataType: "text",  		data:myData,  		success: function (data, textStatus, jqXHR) { @@ -412,11 +411,7 @@ function addComment(sw,comment)   */  function isIn(box, x, y)  { -	if ((x >= box.x) && (x <= (box.x + box.width)) && (y >= box.y) && (y <= (box.y + box.height))) { -		return true; -	} -	return false; - +    return ((x >= box.x) && (x <= (box.x + box.width)) && (y >= box.y) && (y <= (box.y + box.height)));  }  /* @@ -468,6 +463,7 @@ function initNMS() {  	nmsData.registerSource("switches","/api/public/switches");  	nmsData.registerSource("switchstate","/api/public/switch-state");  	nmsData.registerSource("dhcpsummary","/api/public/dhcp-summary"); +	nmsData.registerSource("dhcp","/api/public/dhcp");  	// This is a magic dummy-source, it's purpose is to give a unified  	// way to get ticks every second. It is mainly meant to allow map @@ -481,10 +477,10 @@ function initNMS() {  	detectHandler();  	nms.playback.play();  	setupKeyhandler(); +	setupSearchKeyHandler();  }  function detectHandler() { -	var url = document.URL;  	for (var i in handlers) {  		if (('#' + handlers[i].tag) == document.location.hash) {  			setUpdater(handlers[i]); @@ -524,18 +520,21 @@ function setMapModeFromN(e,key)  			setUpdater(handler_uplinks);  			break;  		case '3': -			setUpdater(handler_temp); +			setUpdater(handler_dhcp);  			break;  		case '4': -			setUpdater(handler_traffic); +			setUpdater(handler_comment);  			break;  		case '5': -			setUpdater(handler_comment); +			setUpdater(handler_temp);  			break;  		case '6': -			setUpdater(handler_traffic_tot); +			setUpdater(handler_traffic);  			break;  		case '7': +			setUpdater(handler_traffic_tot); +			break; +		case '9':  			setUpdater(handler_disco);  			break;  	} @@ -608,6 +607,13 @@ function setupKeyhandler()  	});  } +function setupSearchKeyHandler() +{ +	$("#searchbox").keyup(function(e) { +		nmsInfoBox._searchKeyListener(e); +	}); +} +  function getCookie(cname) {  	var name = cname + "="; @@ -625,8 +631,8 @@ function getCookie(cname) {  function saveSettings()  {  	var foo={}; -	for (var v in nms.settingsList) { -		foo[nms.settingsList[v]] = nms[nms.settingsList[v]]; +	for ( var v in nms.settingsList ) { +		foo[ nms.settingsList[v] ] = nms[ nms.settingsList[v] ];  	}  	document.cookie = 'nms='+btoa(JSON.stringify(foo));  } diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches index 3aa8af8..72c77be 100755 --- a/web/nms.gathering.org/api/public/switches +++ b/web/nms.gathering.org/api/public/switches @@ -12,7 +12,7 @@ use Data::Dumper;  $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null');  $q2->execute();  while (my $ref = $q2->fetchrow_hashref()) { @@ -23,6 +23,7 @@ while (my $ref = $q2->fetchrow_hashref()) {  	$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'y'} = $y2;  	$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'width'} = $x1 - $x2;  	$nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'height'} = $y1 - $y2; +	$nms::web::json{'switches'}{$ref->{'sysname'}}{'distro_name'} = $ref->{'distro_name'};  }  my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, (select sysname from switches where switch = switch2) as sysname2 from linknets'); diff --git a/web/nms.gathering.org/index.html b/web/nms.gathering.org/index.html index 081c206..2862c69 100644 --- a/web/nms.gathering.org/index.html +++ b/web/nms.gathering.org/index.html @@ -71,6 +71,7 @@  		<li class="divider"> </li>  		<li class="dropdown-header">View</li>  		<li><a href="#" onclick="toggleNightMode()">Toggle Night Mode</a></li> +		<li><a href="#" onclick="toggleConnect()">Toggle linknets</a></li>  		<li class="divider"> </li>  		<li class="dropdown-header">Move switches</li>  	  	<li><a href="#" onclick="nmsMap.moveSet(true);">Enable switch moving</a></li> @@ -169,6 +170,10 @@  		  <td>View Disco map</td>  		</tr>  		<tr> +		  <td>c</td> +		  <td>Toggle linknet connections</td> +		</tr> +		<tr>  		  <td>h</td>  		  <td>Step 1 hour back in time</td>  		</tr> @@ -236,7 +241,7 @@  	</div>  	<canvas id="bgCanvas" width="1920" height="1032" style="position: absolute; z-index: 1;"> </canvas> -	<canvas id="linkCanvas" width="1920" height="1032" style="position: absolute; z-index: 10;"> </canvas> +	<canvas id="linkCanvas" width="1920" height="1032" style="position: absolute; z-index: 10; display: none;"> </canvas>  	<canvas id="blurCanvas" width="1920" height="1032" style="position: absolute; z-index: 20;"> </canvas>  	<canvas id="switchCanvas" width="1920" height="1032" style="position: absolute; z-index: 30;"> </canvas>  	<canvas id="textCanvas" width="1920" height="1032" style="position: absolute; z-index: 40;"> </canvas> diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index a2d4f86..0b90d49 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -436,7 +436,7 @@ nmsInfoBox._makeCommentTable = function(content) {  nmsInfoBox._searchSmart = function(id, sw) {  	try { -		if (nmsData.smanagement.switches[sw].distro == id) { +		if (nmsData.switches.switches[sw].distro_name == id) {  			return true;  		}  		if (id.match("active")) { @@ -461,15 +461,22 @@ nmsInfoBox._searchSmart = function(id, sw) {  				}  			}  		} -		if (nmsData.smanagement.switches[sw].ip.match(id)) { -			return true; -		} -		if (nmsData.smanagement.switches[sw].subnet4.match(id)) { -			return true; -		} -		if (nmsData.smanagement.switches[sw].subnet6.match(id)) { -			return true; -		} +		try { +			if (nmsData.smanagement.switches[sw].mgmt_v4_addr.match(id)) { +				return true; +			} +			if (nmsData.smanagement.switches[sw].mgmt_v6_addr.match(id)) { +				return true; +			} +		} catch (e) {} +		try { +			if (nmsData.smanagement.switches[sw].subnet4.match(id)) { +				return true; +			} +			if (nmsData.smanagement.switches[sw].subnet6.match(id)) { +				return true; +			} +		} catch (e) {}  		if (nmsData.snmp.snmp[sw].misc.sysDescr[0].match(id)) {  			return true;  		} diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index 7cbf274..ada6886 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -47,6 +47,7 @@ var nmsMap = nmsMap || {  	},  	_color: { }, +	_linknets: {} ,  	_highlight: { },  	_highlightActive: false,  	_c: {} @@ -157,6 +158,7 @@ nmsMap._resizeEvent = function() {  		nmsMap._blurDrawn = false;  		nmsMap._drawBG();  		nmsMap._drawAllSwitches(); +		nmsMap._drawAllLinknets();  		nmsMap.drawNow();  		nmsMap.stats.resizeEvents++;  	} @@ -330,6 +332,40 @@ nmsMap._drawText = function(ctx, text, box, align) {  	ctx.restore();  }; +nmsMap._setLinknetColor = function(l, color1, color2) +{ +	var oldcolor1; +	var oldcolor2; +	try { +		oldcolor1 = nmsMap._linknets[l].sysname1; +		oldcolor2 = nmsMap._linknets[l].sysname2; +		if (oldcolor1 == color1 && oldcolor2 == color2) { +			return ; +		} +	} catch (e) {} +	nmsMap._linknets[l] = {}; +	nmsMap._linknets[l].sysname1 = color1; +	nmsMap._linknets[l].sysname2 = color2; +	nmsMap._drawLinknet(l) +} + +nmsMap._drawLinknet = function(l) { +	try { +		var color1 = blue; +		var color2 = blue; +		try { +			color1 = nmsMap._linknets[l].sysname1; +			color2 = nmsMap._linknets[l].sysname2; +		} catch(e) { } +		nmsMap._connectSwitches(nmsData.switches.linknets[l].sysname1, nmsData.switches.linknets[l].sysname2, color1, color2); +	} catch(e) { } +} + +nmsMap._drawAllLinknets = function() { +	for (var l in nmsData.switches.linknets) { +		nmsMap._drawLinknet(l); +	} +}  nmsMap._drawAllSwitches = function() {  	if (nmsData.switches == undefined) {  		this.stats.earlyDrawAll++; @@ -386,10 +422,12 @@ nmsMap._connectBoxes = function(box1, box2,color1, color2) {  	gradient.addColorStop(0, color1);  	gradient.addColorStop(1, color2);  	ctx.strokeStyle = gradient; +	ctx.beginPath();  	ctx.moveTo(x0,y0);  	ctx.lineTo(x1,y1);   	ctx.lineWidth = 5;  	ctx.stroke(); +	ctx.closePath();  	ctx.restore();  }; diff --git a/web/nms.gathering.org/js/nms.js b/web/nms.gathering.org/js/nms.js index 49cacde..964c73f 100644 --- a/web/nms.gathering.org/js/nms.js +++ b/web/nms.gathering.org/js/nms.js @@ -38,6 +38,7 @@ var nms = {  		'5':setMapModeFromN,  		'6':setMapModeFromN,  		'7':setMapModeFromN, +		'c':toggleConnect,  		'h':moveTimeFromKey,  		'j':moveTimeFromKey,  		'k':moveTimeFromKey, @@ -345,6 +346,10 @@ function toggleLayer(layer) {                 l.style.display = 'none';  } +function toggleConnect() { +	toggleLayer("linkCanvas"); +} +  function commentInactive(id)  {  	commentChange(id,"inactive"); | 
