// This function might be passed either an OpenLayers.LonLat (so has // lon and lat) or an OpenLayers.Geometry.Point (so has x and y) function fixmystreet_update_pin(lonlat) { lonlat = lonlat.clone().transform( fixmystreet.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326") ); document.getElementById('fixmystreet.latitude').value = lonlat.lat || lonlat.y; document.getElementById('fixmystreet.longitude').value = lonlat.lon || lonlat.x; $.getJSON('/report/new/ajax', { latitude: $('#fixmystreet\\.latitude').val(), longitude: $('#fixmystreet\\.longitude').val() }, function(data) { if (data.error) { if (!$('#side-form-error').length) { $('
').insertAfter($('#side-form')); } $('#side-form-error').html('

' + translation_strings.reporting_a_problem + '

' + data.error + '

').show(); $('#side-form').hide(); $('body').removeClass('with-notes'); return; } $('#side-form, #site-logo').show(); var old_category = $("select#form_category").val(); $('#councils_text').html(data.councils_text); $('#form_category_row').html(data.category); if ($("select#form_category option[value=\""+old_category+"\"]").length) { $("select#form_category").val(old_category); } if ( data.extra_name_info && !$('#form_fms_extra_title').length ) { // there might be a first name field on some cobrands var lb = $('#form_first_name').prev(); if ( lb.length === 0 ) { lb = $('#form_name').prev(); } lb.before(data.extra_name_info); } // If the category filter appears on the map and the user has selected // something from it, then pre-fill the category field in the report, // if it's a value already present in the drop-down. var category = $("#filter_categories").val(); if (category !== undefined && $("#form_category option[value="+category+"]").length) { $("#form_category").val(category); } var category_select = $("select#form_category"); if (category_select.val() != '-- Pick a category --') { category_select.change(); } }); if (!$('#side-form-error').is(':visible')) { $('#side-form, #site-logo').show(); window.scrollTo(0, 0); } } function fixmystreet_activate_drag() { fixmystreet.drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, { onComplete: function(feature, e) { fixmystreet_update_pin( feature.geometry ); } } ); fixmystreet.map.addControl( fixmystreet.drag ); fixmystreet.drag.activate(); } function fixmystreet_zoomToBounds(bounds) { if (!bounds) { return; } var center = bounds.getCenterLonLat(); var z = fixmystreet.map.getZoomForExtent(bounds); if ( z < 13 && $('html').hasClass('mobile') ) { z = 13; } fixmystreet.map.setCenter(center, z); } function fms_markers_list(pins, transform) { var markers = []; var size = fms_marker_size_for_zoom(fixmystreet.map.getZoom() + fixmystreet.zoomOffset); for (var i=0; i= 15) { return 'normal'; } else if (zoom >= 13) { return 'small'; } else { return 'mini'; } } function fms_markers_resize() { var size = fms_marker_size_for_zoom(fixmystreet.map.getZoom() + fixmystreet.zoomOffset); for (var i = 0; i < fixmystreet.markers.features.length; i++) { fixmystreet.markers.features[i].attributes.size = size; } fixmystreet.markers.redraw(); } // `markers.redraw()` in fms_markers_highlight will trigger an // `overFeature` event if the mouse cursor is still over the same // marker on the map, which would then run fms_markers_highlight // again, causing an infinite flicker while the cursor remains over // the same marker. We really only want to redraw the markers when // the cursor moves from one marker to another (ie: when there is an // overFeature followed by an outFeature followed by an overFeature). // Therefore, we keep track of the previous event in // fixmystreet.latest_map_hover_event and only call fms_markers_highlight // if we know the previous event was different to the current one. // (See the `overFeature` and `outFeature` callbacks inside of // fixmystreet.select_feature). function fms_markers_highlight(problem_id) { for (var i = 0; i < fixmystreet.markers.features.length; i++) { if (typeof problem_id == 'undefined') { // There is no highlighted marker, so unfade this marker fixmystreet.markers.features[i].attributes.faded = 0; } else if (problem_id == fixmystreet.markers.features[i].attributes.id) { // This is the highlighted marker, unfade it fixmystreet.markers.features[i].attributes.faded = 0; } else { // This is not the hightlighted marker, fade it fixmystreet.markers.features[i].attributes.faded = 1; } } fixmystreet.markers.redraw(); } function fms_sidebar_highlight(problem_id) { if (typeof problem_id !== 'undefined') { var $a = $('.item-list--reports a[href$="' + problem_id + '"]'); $a.parent().addClass('hovered'); } else { $('.item-list--reports .hovered').removeClass('hovered'); } } function fms_marker_click(problem_id) { var $a = $('.item-list--reports a[href$="' + problem_id + '"]'); $a[0] && $a[0].click(); } function fms_categories_or_status_changed() { // If the category or status has changed we need to re-fetch
#! /usr/bin/perl
use strict;
use warnings;
use BER;
use DBI;
use POSIX;
use Time::HiRes;
use Net::Ping;

use lib '../include';
use nms;
use threads;

poll_loop();	

sub poll_loop {
	my $dbh = nms::db_connect();
	my $qcores = $dbh->prepare('SELECT DISTINCT coreswitches.sysname, coreswitches.switch, coreswitches.ip, coreswitches.community FROM uplinks JOIN switches AS coreswitches ON (uplinks.coreswitch = coreswitches.switch)');
	my $qaps = $dbh->prepare("SELECT switches.sysname, switches.switch, uplinks.blade, uplinks.port FROM uplinks NATURAL JOIN switches WHERE uplinks.coreswitch = ?");
	my $qpoll = $dbh->prepare("UPDATE ap_poll SET model=?, last_poll=now() WHERE switch = ?");

	while (1) {
		$qcores->execute();
		my $cores = $qcores->fetchall_hashref("sysname");

		foreach my $core (keys %$cores) {
			my $ip = $cores->{$core}{'ip'};
			my $community = $cores->{$core}{'community'};
			printf "Polling %s (%s)\n", $core, $ip;
			eval {
				my $session = nms::snmp_open_session($ip, $community);
				$qaps->execute($cores->{$core}{'switch'});
				while (my $aps = $qaps->fetchrow_hashref()) {
					my $sysname = $aps->{'sysname'};
					my $blade = $aps->{'blade'};
					my $port = $aps->{'port'};
					my $oid = "1.3.6.1.2.1.105.1.1.1.9.$blade.$port";     # POWER-ETHERNET-MIB...pethPsePortType
					my $mode = $session->get($oid);
					$qpoll->execute($mode, $aps->{'switch'});
					printf "%s (%s:%s/%s): %s\n", $sysname, $core, $blade, $port, $mode;
				}
			};
			if ($@) {
				mylog("ERROR: $@ (during poll of $ip)");
				$dbh->rollback;
			}
		}
		sleep 2;
	}
}

sub mylog {
	my $msg = shift;
	my $time = POSIX::ctime(time);
	$time =~ s/\n.*$//;
	printf STDERR "[%s] %s\n", $time, $msg;
}
nds(bounds.toArray()); } return bounds; }, // The above isn't enough, however, because Strategy.BBOX's getMapBounds // and calculateBounds work out the bounds in different ways, the former by // transforming the map's extent to the layer projection, the latter by // adding or subtracting from the centre. As we have a ratio of 1, rounding // errors can still occur. This override makes calculateBounds always equal // getMapBounds (so no movement means no update). calculateBounds: function(mapBounds) { if (!mapBounds) { mapBounds = this.getMapBounds(); } this.bounds = mapBounds; } }); /* Pan data request handler */ // This class is used to get a JSON object from /ajax that contains // pins for the map and HTML for the sidebar. It does a fetch whenever the map // is dragged (modulo a buffer extending outside the viewport). // This subclass is required so we can pass the 'filter_category' and 'status' query // params to /ajax if the user has filtered the map. OpenLayers.Protocol.FixMyStreet = OpenLayers.Class(OpenLayers.Protocol.HTTP, { read: function(options) { // Pass the values of the category and status fields as query params var filter_category = $("#filter_categories").val(); if (filter_category !== undefined) { options.params = options.params || {}; options.params.filter_category = filter_category; } var status = $("#statuses").val(); if (status !== undefined) { options.params = options.params || {}; options.params.status = status; } return OpenLayers.Protocol.HTTP.prototype.read.apply(this, [options]); }, CLASS_NAME: "OpenLayers.Protocol.FixMyStreet" }); /* Pan data handler */ OpenLayers.Format.FixMyStreet = OpenLayers.Class(OpenLayers.Format.JSON, { read: function(json, filter) { // Check we haven't received the data after the map has been clicked. if (fixmystreet.page == 'new') { // If we have, we want to do nothing, which means returning an // array of the back-projected version of the current pin var pin = fixmystreet.markers.features[0].clone(); pin.geometry.transform( fixmystreet.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326") ); return [ pin ]; } if (typeof json == 'string') { obj = OpenLayers.Format.JSON.prototype.read.apply(this, [json, filter]); } else { obj = json; } var current; if (typeof(obj.current) != 'undefined' && (current = document.getElementById('current'))) { current.innerHTML = obj.current; } return fms_markers_list( obj.pins, false ); }, CLASS_NAME: "OpenLayers.Format.FixMyStreet" }); /* Click handler */ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { defaultHandlerOptions: { 'single': true, 'double': false, 'pixelTolerance': 4, 'stopSingle': false, 'stopDouble': false }, initialize: function(options) { this.handlerOptions = OpenLayers.Util.extend( {}, this.defaultHandlerOptions); OpenLayers.Control.prototype.initialize.apply( this, arguments ); this.handler = new OpenLayers.Handler.Click( this, { 'click': this.trigger }, this.handlerOptions); }, trigger: function(e) { var cobrand = $('meta[name="cobrand"]').attr('content'); var lonlat = fixmystreet.map.getLonLatFromViewPortPx(e.xy); if (fixmystreet.page == 'new') { /* Already have a pin */ fixmystreet.markers.features[0].move(lonlat); } else { var markers = fms_markers_list( [ [ lonlat.lat, lonlat.lon, 'green' ] ], false ); fixmystreet.bbox_strategy.deactivate(); fixmystreet.markers.removeAllFeatures(); fixmystreet.markers.addFeatures( markers ); fixmystreet_activate_drag(); } // check to see if markers are visible. We click the // link so that it updates the text in case they go // back if ( ! fixmystreet.markers.getVisibility() ) { fixmystreet.state_pins_were_hidden = true; $('#hide_pins_link').click(); } // Store pin location in form fields, and check coverage of point fixmystreet_update_pin(lonlat); // It's possible to invoke the OpenLayers.Control `trigger` callback // multiple times in a row (eg: by clicking on the map multiple times, // to reposition your report). // But there is some stuff we only want to happen the first time you // switch from the "around" view to the "new" report view. // So, here we check whether we've already transitioned into the "new" // report view, and if so, we return from the callback early, // skipping the remainder of the setup stuff. if (fixmystreet.page == 'new') { fixmystreet.map.panDuration = 100; fixmystreet.map.panTo(lonlat); fixmystreet.map.panDuration = 50; return; } // If there are notes to be displayed, add the .with-notes class // to make the sidebar wider. if ($('#report-a-problem-sidebar').length) { $('body').addClass('with-notes'); } /* For some reason on IOS5 if you use the jQuery show method it * doesn't display the JS validation error messages unless you do this * or you cause a screen redraw by changing the phone orientation. * NB: This has to happen after the call to show() in fixmystreet_update_pin */ if ( navigator.userAgent.match(/like Mac OS X/i)) { document.getElementById('side-form').style.display = 'block'; } $('#side').hide(); fixmystreet.map.updateSize(); // required after changing the size of the map element fixmystreet.map.panDuration = 100; fixmystreet.map.panTo(lonlat); fixmystreet.map.panDuration = 50; $('#sub_map_links').hide(); if ($('html').hasClass('mobile')) { var $map_box = $('#map_box'), width = $map_box.width(), height = $map_box.height(); $map_box.append( '' ).css({ position: 'relative', width: width, height: height, marginBottom: '1em' }); // Making it relative here makes it much easier to do the scrolling later $('.mobile-map-banner').html('' + translation_strings.home + ' ' + translation_strings.right_place); // mobile user clicks 'ok' on map $('#mob_ok').toggle(function(){ //scroll the height of the map box instead of the offset //of the #side-form or whatever as we will probably want //to do this on other pages where #side-form might not be $('html, body').animate({ scrollTop: height-60 }, 1000, function(){ $('#mob_sub_map_links').addClass('map_complete'); $('#mob_ok').text(translation_strings.map); }); }, function(){ $('html, body').animate({ scrollTop: 0 }, 1000, function(){ $('#mob_sub_map_links').removeClass('map_complete'); $('#mob_ok').text(translation_strings.ok); }); }); } fixmystreet.page = 'new'; location.hash = 'report'; if ( typeof ga !== 'undefined' && cobrand == 'fixmystreet' ) { ga('send', 'pageview', { 'page': '/map_click' } ); } } });