From 70eecac6be332fd177612821bc8f5d8f8fc8d9ef Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Sat, 29 Oct 2016 14:05:13 +0200 Subject: [PATCH] Fix: some resources were insecure when using ssl --- api_gmaps.js | 82 +++++++++---------- api_openlayers.js | 197 +++++++++++++++++++++++----------------------- auth.php | 24 +++--- config.php | 10 +-- download.php | 52 ++++++------ getpositions.php | 34 ++++---- gettrips.php | 12 +-- index.php | 39 +++++---- lang.php | 14 ++-- logout.php | 2 +- main.css | 10 +-- main.js | 148 +++++++++++++++++----------------- trackme.sql | 4 +- 13 files changed, 315 insertions(+), 313 deletions(-) diff --git a/api_gmaps.js b/api_gmaps.js index 3d42bd0..c1493d8 100755 --- a/api_gmaps.js +++ b/api_gmaps.js @@ -16,7 +16,7 @@ * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + // google maps var map; var polies = new Array(); @@ -31,25 +31,25 @@ function init() { strokeColor: '#FF0000', strokeOpacity: 1.0, strokeWeight: 2 - } + } mapOptions = { center: new google.maps.LatLng(init_latitude,init_longitude), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP, scaleControl: true - }; + }; map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); } - + function displayTrack(xml,update) { altitudes.length = 0; var totalMeters = 0; var totalSeconds = 0; // init polyline var poly = new google.maps.Polyline(polyOptions); - poly.setMap(map); - var path = poly.getPath(); - var latlngbounds = new google.maps.LatLngBounds( ); + poly.setMap(map); + var path = poly.getPath(); + var latlngbounds = new google.maps.LatLngBounds( ); var positions = xml.getElementsByTagName('position'); var posLen = positions.length; for (var i=0; i'+lang_user+': '+p.username.toUpperCase()+'
'+lang_track+': '+p.trackname.toUpperCase()+ @@ -139,7 +139,7 @@ function setMarker(p,i,posLen) { ''+lang_aspeed+': '+((p.totalSeconds>0)?((p.totalMeters/p.totalSeconds).toKmH()*factor_kmh).toFixed():0)+' '+unit_kmh+'
'+ ''+lang_tdistance+': '+(p.totalMeters.toKm()*factor_km).toFixed(2)+' '+unit_km+'
'+''):'')+ '
'+lang_point+' '+(i+1)+' '+lang_of+' '+(posLen)+'
'+ - ''; + ''; popup = new google.maps.InfoWindow(); popup.listener = google.maps.event.addListener(marker, 'click', (function(marker,content) { return function() { @@ -149,37 +149,37 @@ function setMarker(p,i,posLen) { chart.setSelection([{row:i,column:null}]); } } - })(marker,content)); - markers.push(marker); - popups.push(popup); + })(marker,content)); + markers.push(marker); + popups.push(popup); } function addChartEvent(chart) { - google.visualization.events.addListener(chart, 'select', function() { - if (popup) {popup.close(); clearTimeout(altTimeout);} - var selection = chart.getSelection()[0]; - if (selection) { - var id = selection.row; - var icon = markers[id].getIcon(); - markers[id].setIcon('http://maps.google.com/mapfiles/marker_orange.png'); - altTimeout = setTimeout(function() { markers[id].setIcon(icon); },2000); - } - }); + google.visualization.events.addListener(chart, 'select', function() { + if (popup) {popup.close(); clearTimeout(altTimeout);} + var selection = chart.getSelection()[0]; + if (selection) { + var id = selection.row; + var icon = markers[id].getIcon(); + markers[id].setIcon('//maps.google.com/mapfiles/marker_orange.png'); + altTimeout = setTimeout(function() { markers[id].setIcon(icon); },2000); + } + }); } //((52.20105108685229, 20.789387865580238), (52.292069558807135, 21.172192736185707)) function getBounds() { - var b = map.getBounds().toString(); - var bounds = b.split(',',4); - var lat_sw = bounds[0].replace(/\(/g,''); - var lon_sw = bounds[1].replace(/[ )]/g,''); - var lat_ne = bounds[2].replace(/[ (]/g,''); - var lon_ne = bounds[3].replace(/[ )]/g,''); - return [lon_sw,lat_sw,lon_ne,lat_ne]; + var b = map.getBounds().toString(); + var bounds = b.split(',',4); + var lat_sw = bounds[0].replace(/\(/g,''); + var lon_sw = bounds[1].replace(/[ )]/g,''); + var lat_ne = bounds[2].replace(/[ (]/g,''); + var lon_ne = bounds[3].replace(/[ )]/g,''); + return [lon_sw,lat_sw,lon_ne,lat_ne]; } function zoomToBounds(b) { - var sw = new google.maps.LatLng(b[1],b[0]); - var ne = new google.maps.LatLng(b[3],b[2]); - var bounds = new google.maps.LatLngBounds(sw,ne); - map.fitBounds(bounds); + var sw = new google.maps.LatLng(b[1],b[0]); + var ne = new google.maps.LatLng(b[3],b[2]); + var bounds = new google.maps.LatLngBounds(sw,ne); + map.fitBounds(bounds); } diff --git a/api_openlayers.js b/api_openlayers.js index 1dc0882..2e280d0 100755 --- a/api_openlayers.js +++ b/api_openlayers.js @@ -16,70 +16,73 @@ * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + // openlayers var map; var layerTrack; var layerMarkers; -var lineStyle = {strokeColor: '#FF0000', strokeOpacity: 1, strokeWidth: 2}; +var lineStyle = {strokeColor: '#FF0000', strokeOpacity: 1, strokeWidth: 2}; var wgs84; var mercator; var loadedAPI = 'openlayers'; function init() { - wgs84 = new OpenLayers.Projection('EPSG:4326'); // from WGS 1984 - mercator = new OpenLayers.Projection('EPSG:900913'); // to Mercator - var options = { controls: [ - new OpenLayers.Control.ArgParser(), // default - new OpenLayers.Control.Attribution(), // default - new OpenLayers.Control.LayerSwitcher(), - new OpenLayers.Control.Navigation(), // default - new OpenLayers.Control.PanZoomBar(),// do we need it? - new OpenLayers.Control.ScaleLine() - ] - }; - map = new OpenLayers.Map('map-canvas', options); - // default layer: OpenStreetMap - var mapnik = new OpenLayers.Layer.OSM(); - map.addLayer(mapnik); - if (layer_ocm==1) { - // OpenCycleMap + wgs84 = new OpenLayers.Projection('EPSG:4326'); // from WGS 1984 + mercator = new OpenLayers.Projection('EPSG:900913'); // to Mercator + var options = { controls: [ + new OpenLayers.Control.ArgParser(), // default + new OpenLayers.Control.Attribution(), // default + new OpenLayers.Control.LayerSwitcher(), + new OpenLayers.Control.Navigation(), // default + new OpenLayers.Control.PanZoomBar(),// do we need it? + new OpenLayers.Control.ScaleLine() + ] + }; + map = new OpenLayers.Map('map-canvas', options); + // default layer: OpenStreetMap + var mapnik = new OpenLayers.Layer.OSM('OpenStreetMap', + ['//a.tile.openstreetmap.org/${z}/${x}/${y}.png', + '//b.tile.openstreetmap.org/${z}/${x}/${y}.png', + '//c.tile.openstreetmap.org/${z}/${x}/${y}.png']); + map.addLayer(mapnik); + if (layer_ocm==1) { + // OpenCycleMap var ocm = new OpenLayers.Layer.OSM('OpenCycleMap', - ['http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png', - 'http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png', - 'http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png']); + ['//a.tile.thunderforest.com/cycle/${z}/${x}/${y}.png', + '//b.tile.thunderforest.com/cycle/${z}/${x}/${y}.png', + '//c.tile.thunderforest.com/cycle/${z}/${x}/${y}.png']); map.addLayer(ocm); } - if (layer_mq==1) { - // MapQuest-OSM + if (layer_mq==1) { + // MapQuest-OSM var mq = new OpenLayers.Layer.OSM('MapQuest-OSM', - ['http://otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg', - 'http://otile2.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg', - 'http://otile3.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg', - 'http://otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg']); + ['//otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg', + '//otile2.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg', + '//otile3.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg', + '//otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg']); map.addLayer(mq); } - if (layer_osmapa==1) { - // osmapa.pl - var osmapa = new OpenLayers.Layer.OSM('osmapa.pl', - ['http://a.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png', - 'http://b.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png', - 'http://c.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png']); + if (layer_osmapa==1) { + // osmapa.pl + var osmapa = new OpenLayers.Layer.OSM('osmapa.pl', + ['//a.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png', + '//b.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png', + '//c.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png']); map.addLayer(osmapa); } - if (layer_ump==1) { - // UMP - var ump = new OpenLayers.Layer.OSM('UMP', - ['http://1.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png', - 'http://2.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png', - 'http://3.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png']); + if (layer_ump==1) { + // UMP + var ump = new OpenLayers.Layer.OSM('UMP', + ['//1.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png', + '//2.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png', + '//3.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png']); map.addLayer(ump); - } + } var position = new OpenLayers.LonLat(init_longitude,init_latitude).transform(wgs84, mercator); - var zoom = 8; - map.setCenter(position, zoom); + var zoom = 8; + map.setCenter(position, zoom); // init layers layerTrack = new OpenLayers.Layer.Vector('Track'); - layerMarkers = new OpenLayers.Layer.Markers('Markers'); + layerMarkers = new OpenLayers.Layer.Markers('Markers'); } function displayTrack(xml,update) { altitudes.length = 0; @@ -104,21 +107,21 @@ function displayTrack(xml,update) { // save altitudes for chart altitudes[i] = p.altitude; } - var lineString = new OpenLayers.Geometry.LineString(points); - var lineFeature = new OpenLayers.Feature.Vector(lineString, null, lineStyle); - layerTrack.addFeatures([lineFeature]); - map.addLayer(layerTrack); - map.addLayer(layerMarkers); + var lineString = new OpenLayers.Geometry.LineString(points); + var lineFeature = new OpenLayers.Feature.Vector(lineString, null, lineStyle); + layerTrack.addFeatures([lineFeature]); + map.addLayer(layerTrack); + map.addLayer(layerMarkers); if (update) { map.zoomToExtent(latlngbounds); if (i==1) { - // only one point, zoom out + // only one point, zoom out map.zoomOut(); } } latestTime = p.dateoccured; //polies.push(poly); - + updateSummary(p.dateoccured,totalMeters,totalSeconds); if (p.tid!=trackid) { trackid=p.tid; @@ -144,18 +147,18 @@ function setMarker(p,i,posLen) { // marker var lonLat = new OpenLayers.LonLat(p.longitude,p.latitude).transform(wgs84,mercator); var size = new OpenLayers.Size(21, 25); - var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); - if (latest==1) { var icon = new OpenLayers.Icon('http://www.openstreetmap.org/openlayers/img/marker.png',size,offset); } - else if (i==0) { var icon = new OpenLayers.Icon('http://www.openstreetmap.org/openlayers/img/marker-green.png',size,offset); } - else if (i==posLen-1) { var icon = new OpenLayers.Icon('http://www.openstreetmap.org/openlayers/img/marker.png',size,offset); } - else { - size = new OpenLayers.Size(12, 20); - offset = new OpenLayers.Pixel(-(size.w/2), -size.h); - var icon = new OpenLayers.Icon('http://labs.google.com/ridefinder/images/mm_20_gray.png',size,offset); + var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); + if (latest==1) { var icon = new OpenLayers.Icon('//www.openstreetmap.org/openlayers/img/marker.png',size,offset); } + else if (i==0) { var icon = new OpenLayers.Icon('//www.openstreetmap.org/openlayers/img/marker-green.png',size,offset); } + else if (i==posLen-1) { var icon = new OpenLayers.Icon('//www.openstreetmap.org/openlayers/img/marker.png',size,offset); } + else { + size = new OpenLayers.Size(12, 20); + offset = new OpenLayers.Pixel(-(size.w/2), -size.h); + var icon = new OpenLayers.Icon('//maps.gstatic.com/mapfiles/ridefinder-images/mm_20_gray.png',size,offset); } var marker = new OpenLayers.Marker(lonLat,icon); - layerMarkers.addMarker(marker); - + layerMarkers.addMarker(marker); + // popup var content = ''):'')+ '
'+lang_point+' '+(i+1)+' '+lang_of+' '+(posLen)+'
'+ - ''; - marker.events.register("mousedown", marker, (function() { - return function() { - // remove popups - if (map.popups.length>0) { - for (var j = map.popups.length-1; j>=0; j-- ) { - map.removePopup(map.popups[j]) - }; - } - // show popup - var popup = new OpenLayers.Popup.FramedCloud("id "+(i+1),lonLat,null,content,icon,true); - map.addPopup(popup); - if (document.getElementById('bottom').style.display=='block') { - chart.setSelection([{row:i,column:null}]); - } - } - })()); + ''; + marker.events.register("mousedown", marker, (function() { + return function() { + // remove popups + if (map.popups.length>0) { + for (var j = map.popups.length-1; j>=0; j-- ) { + map.removePopup(map.popups[j]) + }; + } + // show popup + var popup = new OpenLayers.Popup.FramedCloud("id "+(i+1),lonLat,null,content,icon,true); + map.addPopup(popup); + if (document.getElementById('bottom').style.display=='block') { + chart.setSelection([{row:i,column:null}]); + } + } + })()); } function addChartEvent(chart) { - google.visualization.events.addListener(chart, 'select', function() { - var selection = chart.getSelection()[0]; - if (selection) { - var id = selection.row; - var marker = layerMarkers.markers[id]; - var url = marker.icon.url; - marker.setUrl('http://www.openstreetmap.org/openlayers/img/marker-gold.png'); - altTimeout = setTimeout(function() { marker.setUrl(url); },2000); - } - }); + google.visualization.events.addListener(chart, 'select', function() { + var selection = chart.getSelection()[0]; + if (selection) { + var id = selection.row; + var marker = layerMarkers.markers[id]; + var url = marker.icon.url; + marker.setUrl('//www.openstreetmap.org/openlayers/img/marker-gold.png'); + altTimeout = setTimeout(function() { marker.setUrl(url); },2000); + } + }); } //20.597985430276808,52.15547181298076,21.363595171488573,52.33750879522563 function getBounds() { - var b = map.getExtent().transform(mercator,wgs84).toString(); - var bounds = b.split(',',4); - var lon_sw = bounds[0]; - var lat_sw = bounds[1]; - var lon_ne = bounds[2]; - var lat_ne = bounds[3]; - return [lon_sw,lat_sw,lon_ne,lat_ne]; + var b = map.getExtent().transform(mercator,wgs84).toString(); + var bounds = b.split(',',4); + var lon_sw = bounds[0]; + var lat_sw = bounds[1]; + var lon_ne = bounds[2]; + var lat_ne = bounds[3]; + return [lon_sw,lat_sw,lon_ne,lat_ne]; } function zoomToBounds(b) { - var bounds = new OpenLayers.Bounds(b).transform(wgs84,mercator); - map.zoomToExtent(bounds); + var bounds = new OpenLayers.Bounds(b).transform(wgs84,mercator); + map.zoomToExtent(bounds); } diff --git a/auth.php b/auth.php index 96a12c3..bb58436 100755 --- a/auth.php +++ b/auth.php @@ -26,8 +26,8 @@ if (isset($_COOKIE["phpTrackme_interval"])) { $interval = $_COOKIE["phpTrackme_i require_once("lang.php"); $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname); if ($mysqli->connect_errno) { - printf("Connect failed: %s\n", $mysqli->connect_error); - exit(); + printf("Connect failed: %s\n", $mysqli->connect_error); + exit(); } $mysqli->set_charset("utf8"); $auth = NULL; @@ -37,18 +37,18 @@ if ($require_authentication) { session_name('trackme'); session_start(); $sid = session_id(); - + $auth = (isset($_SESSION['auth']) ? $_SESSION['auth'] : ""); $admin = (isset($_SESSION['admin']) ? $_SESSION['admin'] : ""); $user = (isset($_REQUEST['user']) ? $_REQUEST['user'] : ""); $pass = (isset($_REQUEST['pass']) ? md5($salt.$_REQUEST['pass']) : ""); $ssl = ((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "" || $_SERVER['HTTPS'] == "off") ? "http" : "https"); $auth_error = (isset($_REQUEST['auth_error']) ? $_REQUEST['auth_error'] : 0); - + // not authenticated and username not submited // load form - if ((!$auth) && (!$user)){ - print + if ((!$auth) && (!$user)){ + print ' @@ -92,13 +92,13 @@ if ($require_authentication) { $query->free_result(); //correct pass - if (($user==$rec_user) && ($pass==$rec_pass)) { + if (($user==$rec_user) && ($pass==$rec_pass)) { // login successful //delete old session $_SESSION = NULL; - session_destroy(); + session_destroy(); // start new session - session_name('trackme'); + session_name('trackme'); session_start(); if (($user==$admin_user) && ($admin_user != "")) { $_SESSION['admin'] = $admin_user; @@ -106,7 +106,7 @@ if ($require_authentication) { $_SESSION['auth'] = $rec_ID; $url = str_replace("//", "/", $_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])."/index.php"); header("Location: $ssl://$url"); - exit; + exit; } else { // unsuccessful $error = "?auth_error=1"; @@ -115,8 +115,8 @@ if ($require_authentication) { if (isset($_COOKIE[session_name('trackme')])) { setcookie(session_name('trackme'),'',time()-42000,'/'); } - session_destroy(); - $mysqli->close(); + session_destroy(); + $mysqli->close(); $url = str_replace("//", "/", $_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])."/index.php"); header("Location: $ssl://$url$error"); exit; diff --git a/config.php b/config.php index b52a1b6..a6538a8 100755 --- a/config.php +++ b/config.php @@ -17,9 +17,9 @@ * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -$version = "2.3"; +$version = "2.3"; -// default map drawing framework +// default map drawing framework // (gmaps = google maps, openlayers = openlayers/osm) //$mapapi = "gmaps"; $mapapi = "openlayers"; @@ -50,7 +50,7 @@ $dbname = ""; // database name $salt = ""; // fill in random string here, it will increase security of password hashes // other -// require login/password authentication +// require login/password authentication // (0 = no, 1 = yes) $require_authentication = 1; @@ -58,12 +58,12 @@ $require_authentication = 1; // none if empty $admin_user = ""; -// allow automatic registration of new users +// allow automatic registration of new users // (0 = no, 1 = yes) $allow_registration = 0; // Default interval in seconds for live auto reload -$interval = 10; +$interval = 10; // Default language // (en, pl, de) diff --git a/download.php b/download.php index 995f190..46c7d8b 100755 --- a/download.php +++ b/download.php @@ -29,7 +29,7 @@ if ($units=="imperial") { $unit_m = "ft"; $factor_km = 0.62; // to miles $unit_km = "mi"; -} +} else { $factor_kmh = 1; $unit_kmh = "km/h"; @@ -55,10 +55,10 @@ function addStyle($xml,$name,$url) { $xml->startElement("IconStyle"); $xml->writeAttribute("id", $name."Icon"); $xml->startElement("Icon"); - $xml->writeElement("href", $url); - $xml->endElement(); - $xml->endElement(); - $xml->endElement(); + $xml->writeElement("href", $url); + $xml->endElement(); + $xml->endElement(); + $xml->endElement(); } function toHMS($s) { $d = floor($s/86400); @@ -100,7 +100,7 @@ if ($trackid>0 && $userid>0) { // marker styles addStyle($xml,"red","http://maps.google.com/mapfiles/markerA.png"); addStyle($xml,"green","http://maps.google.com/mapfiles/marker_greenB.png"); - addStyle($xml,"gray","http://labs.google.com/ridefinder/images/mm_20_gray.png"); + addStyle($xml,"gray","http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_gray.png"); $style = "#redStyle"; // for first element $i = 0; $totalMeters = 0; @@ -113,12 +113,12 @@ if ($trackid>0 && $userid>0) { $prev_dateoccured = $dateoccured; $totalMeters += $distance; $totalSeconds += $seconds; - + if(++$i == $query->num_rows) { $style = "#greenStyle"; } // last element $xml->startElement("Placemark"); $xml->writeAttribute("id", $positionid); //$xml->writeElement("name", $i); - $description = + $description = "
".$lang_user.": ".strtoupper($username)."
".$lang_track.": ".strtoupper($trackname). "
". "
". @@ -138,7 +138,7 @@ if ($trackid>0 && $userid>0) { $coordinate[$i] = $longitude.",".$latitude.(($altitude) ? ",".$altitude : ""); $xml->writeElement("coordinates", $coordinate[$i]); $xml->endElement(); - $xml->endElement(); + $xml->endElement(); $style = "#grayStyle"; // other elements } $coordinates = implode("\n",$coordinate); @@ -147,16 +147,16 @@ if ($trackid>0 && $userid>0) { $xml->startElement("LineString"); $xml->writeElement("coordinates", $coordinates); $xml->endElement(); - $xml->endElement(); - - + $xml->endElement(); + + $xml->endElement(); $xml->endElement(); - $xml->endDocument(); + $xml->endDocument(); $xml->flush(); - + break; - + case "gpx": header("Content-type: application/application/gpx+xm"); header("Content-Disposition: attachment; filename=\"track$trackid.gpx\""); @@ -164,10 +164,10 @@ if ($trackid>0 && $userid>0) { $xml->openURI("php://output"); $xml->startDocument("1.0"); $xml->startElement("gpx"); - $xml->writeAttribute("xmlns", "http://www.topografix.com/GPX/1/1"); - $xml->writeAttribute("xmlns:gpxdata", "http://www.cluetrust.com/XML/GPXDATA/1/0"); - $xml->writeAttribute("creator", "phpTrackme"); - $xml->writeAttribute("version", "1.1"); + $xml->writeAttribute("xmlns", "http://www.topografix.com/GPX/1/1"); + $xml->writeAttribute("xmlns:gpxdata", "http://www.cluetrust.com/XML/GPXDATA/1/0"); + $xml->writeAttribute("creator", "phpTrackme"); + $xml->writeAttribute("version", "1.1"); $xml->startElement("metadata"); $xml->writeElement("name", $trackname); $xml->writeElement("time", str_replace(" ","T",$dateoccured)); @@ -185,7 +185,7 @@ if ($trackid>0 && $userid>0) { $seconds = (isset($prev_dateoccured))?(strtotime($dateoccured)-strtotime($prev_dateoccured)):0; $prev_dateoccured = $dateoccured; $totalMeters += $distance; - $totalSeconds += $seconds; + $totalSeconds += $seconds; $xml->startElement("trkpt"); $xml->writeAttribute("lat", $latitude); $xml->writeAttribute("lon", $longitude); @@ -193,7 +193,7 @@ if ($trackid>0 && $userid>0) { $xml->writeElement("time", str_replace(" ","T",$dateoccured)); $xml->writeElement("name", ++$i); $xml->startElement("desc"); - $description = + $description = $lang_user.": ".strtoupper($username)." ".$lang_track.": ".strtoupper($trackname). " ".$lang_time.": ".$dateoccured. (($speed)?" ".$lang_speed.": ".round($speed*3.6,2*$factor_kmh)." ".$unit_kmh:""). @@ -205,14 +205,14 @@ if ($trackid>0 && $userid>0) { $xml->writeCData($description); $xml->endElement(); $xml->endElement(); - } + } $xml->endElement(); $xml->endElement(); $xml->endElement(); - $xml->endDocument(); - $xml->flush(); - - break; + $xml->endDocument(); + $xml->flush(); + + break; } $query->free_result(); $query->close(); diff --git a/getpositions.php b/getpositions.php index 9a3acc1..3e82c50 100755 --- a/getpositions.php +++ b/getpositions.php @@ -42,7 +42,7 @@ if ($userid) { else { // get data only for latest point $query = $mysqli->prepare("SELECT positions.ID,positions.Latitude,positions.Longitude,positions.Altitude,positions.Speed,positions.Angle,positions.DateOccurred,positions.Comments,users.username,trips.Name,trips.ID FROM positions LEFT JOIN users ON (positions.FK_Users_ID=users.ID) LEFT JOIN trips ON (positions.FK_Trips_ID=trips.ID) WHERE positions.FK_Users_ID=? ORDER BY positions.DateOccurred DESC LIMIT 1"); - $query->bind_param('i', $userid); + $query->bind_param('i', $userid); } $query->execute(); $query->bind_result($positionid,$latitude,$longitude,$altitude,$speed,$angle,$dateoccured,$comments,$username,$trackname,$trackid); @@ -53,32 +53,32 @@ if ($userid) { $xml->startDocument("1.0"); $xml->setIndent(true); $xml->startElement('root'); - + while ($query->fetch()) { $xml->startElement("position"); $xml->writeAttribute("id", $positionid); - $xml->writeElement("latitude", $latitude); - $xml->writeElement("longitude", $longitude); - $xml->writeElement("altitude", ($altitude)?round($altitude):$altitude); - $xml->writeElement("speed", $speed); - $xml->writeElement("angle", $angle); - $xml->writeElement("dateoccured", $dateoccured); - $xml->writeElement("comments", $comments); - $xml->writeElement("username", $username); - $xml->writeElement("trackid", $trackid); - $xml->writeElement("trackname", $trackname); + $xml->writeElement("latitude", $latitude); + $xml->writeElement("longitude", $longitude); + $xml->writeElement("altitude", ($altitude)?round($altitude):$altitude); + $xml->writeElement("speed", $speed); + $xml->writeElement("angle", $angle); + $xml->writeElement("dateoccured", $dateoccured); + $xml->writeElement("comments", $comments); + $xml->writeElement("username", $username); + $xml->writeElement("trackid", $trackid); + $xml->writeElement("trackname", $trackname); $distance = (isset($prev_latitude))?haversine_distance($prev_latitude,$prev_longitude,$latitude,$longitude):0; $prev_latitude = $latitude; $prev_longitude = $longitude; - $xml->writeElement("distance", round($distance)); + $xml->writeElement("distance", round($distance)); $seconds = (isset($prev_dateoccured))?(strtotime($dateoccured)-strtotime($prev_dateoccured)):0; $prev_dateoccured = $dateoccured; - $xml->writeElement("seconds", $seconds); - $xml->endElement(); + $xml->writeElement("seconds", $seconds); + $xml->endElement(); } - + $xml->endElement(); - $xml->endDocument(); + $xml->endDocument(); $xml->flush(); $query->free_result(); diff --git a/gettrips.php b/gettrips.php index 6883d08..b9cb9f2 100755 --- a/gettrips.php +++ b/gettrips.php @@ -33,16 +33,16 @@ if ($userid) { $xml->startDocument("1.0"); $xml->setIndent(true); $xml->startElement('root'); - + while ($query->fetch()) { $xml->startElement("trip"); - $xml->writeElement("trackid", $trackid); - $xml->writeElement("trackname", $trackname); - $xml->endElement(); + $xml->writeElement("trackid", $trackid); + $xml->writeElement("trackname", $trackname); + $xml->endElement(); } - + $xml->endElement(); - $xml->endDocument(); + $xml->endDocument(); $xml->flush(); $query->free_result(); diff --git a/index.php b/index.php index edb38b0..029dace 100755 --- a/index.php +++ b/index.php @@ -22,14 +22,14 @@ require_once("auth.php"); if ($auth && !$admin) { // get username - $query = "SELECT username FROM users WHERE ID='$auth' LIMIT 1"; + $query = "SELECT username FROM users WHERE ID='$auth' LIMIT 1"; $result = $mysqli->query($query); $row = $result->fetch_assoc(); $user = $row["username"]; - + // users $user_form = ''.$lang_user.'
'.$user.' ('.$lang_logout.')'; -} +} else { // free access or admin user // prepare user select form @@ -40,12 +40,12 @@ else { '.$lang_user.' '; if ($auth) { $user_form .= ' '.$user.' ('.$lang_logout.')'; - } + } $user_form .= '
@@ -79,7 +79,7 @@ if ($auth && !$admin) { // or user who did last move $userid = $last_id; } -$query = "SELECT * FROM trips WHERE FK_Users_ID='$userid' ORDER BY ID DESC"; +$query = "SELECT * FROM trips WHERE FK_Users_ID='$userid' ORDER BY ID DESC"; $result = $mysqli->query($query); $trackid = ""; @@ -111,7 +111,6 @@ $lang_form = ' -
'; @@ -126,7 +125,7 @@ $units_form = ' '; -print +print ' @@ -164,14 +163,14 @@ print '; if ($mapapi == "gmaps") { - print -' - + print +' + '; } else { print -' +' '; } @@ -180,7 +179,7 @@ print ' - +
'.$track_form.' - '.$lang_autoreload.' ('.$interval.' s)
+ '.$lang_autoreload.' ('.$interval.' s)
'.$lang_reload.'
-
+
'.$api_form.'
-
+
'.$lang_form.'
-
+
'.$units_form.'
@@ -220,7 +219,7 @@ print ' +
'; diff --git a/lang.php b/lang.php index 7e61392..4efbb86 100755 --- a/lang.php +++ b/lang.php @@ -53,7 +53,7 @@ switch($lang) { $lang_metric = "Metric"; $lang_imperial = "Imperial/US"; break; - + case "pl": $lang_title = "• phpTrackme •"; $lang_private = "Aby się zalogować musisz podać login i hasło"; @@ -75,20 +75,20 @@ switch($lang) { $lang_suser = "wybierz login"; $lang_point = "Punkt"; $lang_of = "z"; - $lang_summary = "Podsumowanie"; + $lang_summary = "Podsumowanie"; $lang_logout = "wyloguj"; $lang_login = "zaloguj"; $lang_username = "Login"; $lang_password = "Hasło"; $lang_language = "Język"; $lang_newinterval = "Podaj częstotliwość odświeżania (w sekundach)"; - $lang_api = "Map API"; + $lang_api = "Map API"; $lang_language = "Język"; $lang_units = "Jednostki"; $lang_metric = "Metryczne"; $lang_imperial = "Anglosaskie"; break; - + case "de": $lang_title = "• phpTrackme •"; $lang_private = "Sie müssen Benutzernamen und Kennwort eingeben, um auf diese Seite zuzugreifen."; @@ -122,7 +122,7 @@ switch($lang) { $lang_units = "Maßsystem"; $lang_metric = "Metrisches"; $lang_imperial = "Angloamerikanisches"; - break; + break; case "hu": $lang_title = "• phpTrackme •"; @@ -145,14 +145,14 @@ switch($lang) { $lang_suser = "Felhasználónév"; $lang_point = "Rögzített pontok száma"; $lang_of = "/"; - $lang_summary = "Utazás adatai"; + $lang_summary = "Utazás adatai"; $lang_logout = "Kilépés"; $lang_login = "Belépés"; $lang_username = "Felhasználó"; $lang_password = "Jelszó"; $lang_language = "Nyelv"; $lang_newinterval = "Automatikus frissítés ideje (másodpercben)"; - $lang_api = "Map API"; + $lang_api = "Map API"; $lang_language = "Nyelv"; $lang_units = "Mértékegység"; $lang_metric = "Metrikus"; diff --git a/logout.php b/logout.php index a786403..91bcb8f 100755 --- a/logout.php +++ b/logout.php @@ -23,7 +23,7 @@ $_SESSION = NULL; if (isset($_COOKIE[session_name('trackme')])) { setcookie(session_name('trackme'),'',time()-42000,'/'); } -session_destroy(); +session_destroy(); $ssl = ((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "" || $_SERVER['HTTPS'] == "off") ? "http" : "https"); $url = str_replace("//", "/", $_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])."/index.php"); header("Location: $ssl://$url"); diff --git a/main.css b/main.css index 049a5b8..e697bcd 100755 --- a/main.css +++ b/main.css @@ -78,7 +78,7 @@ select { position: fixed; width: 165px; bottom:0; - padding: 10px; + padding: 10px; background-color:rgba(102, 102, 102, 0.9); color: lightgray; } @@ -103,7 +103,7 @@ select { padding-bottom: 10px; } #login { - font-family: Verdana, sans-serif; + font-family: Verdana, sans-serif; position: relative; top: 10%; background-color: #444; @@ -141,7 +141,7 @@ select { border-bottom: 1px solid gray; } #pcomments { - clear: both; + clear: both; color: #903; } #pleft,#pright { @@ -161,8 +161,8 @@ select { position: absolute; z-index: 10000; } -#chart { - position: fixed; +#chart { + position: fixed; bottom: 0; left:0; right: 0; height: 200px; margin-right: 165px; diff --git a/main.js b/main.js index 4692ea1..9eb008a 100755 --- a/main.js +++ b/main.js @@ -16,7 +16,7 @@ * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + // general stuff if (units=='imperial') { factor_kmh = 0.62; //to mph @@ -25,7 +25,7 @@ if (units=='imperial') { unit_m = 'ft'; factor_km = 0.62; // to miles unit_km = 'mi'; -} +} else { factor_kmh = 1; unit_kmh = 'km/h'; @@ -58,18 +58,18 @@ function displayChart() { chart = new google.visualization.LineChart(document.getElementById('chart')); chart.draw(data, options); - + addChartEvent(chart); } function toggleChart(i) { var altLen = altitudes.length; - if (altLen<=1) { return; } + if (altLen<=1) { return; } var e = document.getElementById('bottom'); if (arguments.length < 1) { if (e.style.display == 'block') { i = 0 } else { i = 1; } - } + } if (i==0) { chart.clearChart(); e.style.display = 'none'; @@ -80,14 +80,14 @@ function toggleChart(i) { } } -function toggleMenu(i) { +function toggleMenu(i) { var emenu = document.getElementById('menu'); var emain = document.getElementById('main'); var ebutton = document.getElementById('menu-close'); if (arguments.length < 1) { if (ebutton.innerHTML == '»') { i = 0 } else { i = 1; } - } + } if (i==0) { emenu.style.width = '0'; emain.style.marginRight = '0'; @@ -99,7 +99,7 @@ function toggleMenu(i) { emain.style.marginRight = '165px'; ebutton.style.right = '165px'; ebutton.innerHTML = '»'; - } + } } function getXHR() { @@ -120,8 +120,8 @@ function loadTrack(userid,trackid,update) { if (xhr.readyState==4 && xhr.status==200) { var xml = xhr.responseXML; var positions = xml.getElementsByTagName('position'); - if (positions.length>0) { - clearMap(); + if (positions.length>0) { + clearMap(); displayTrack(xml,update); } xhr = null; @@ -161,7 +161,7 @@ function parsePosition(p) { 'dateoccured': dateoccured, 'distance': distance, 'seconds': seconds - }; + }; } function load(type,userid,trackid) { @@ -246,7 +246,7 @@ function getTrips(userid) { var trackSelect = document.getElementsByName('track')[0]; clearOptions(trackSelect); var trips = xml.getElementsByTagName('trip'); - if (trips.length>0) { + if (trips.length>0) { fillOptions(xml); } else { clearMap(); @@ -255,7 +255,7 @@ function getTrips(userid) { } } xhr.open('GET','gettrips.php?userid='+userid,true); - xhr.send(); + xhr.send(); } function fillOptions(xml) { @@ -269,7 +269,7 @@ function fillOptions(xml) { option.value = trackid; option.innerHTML = trackname; trackSelect.appendChild(option); - } + } var defaultTrack = getNode(trips[0],'trackid'); loadTrack(userid,defaultTrack,1); } @@ -300,94 +300,94 @@ function setTime() { interval = i; document.getElementById('auto').innerHTML = interval; // if live tracking on, reload with new interval - if (live==1) { + if (live==1) { live = 0; clearInterval(auto); autoReload(); } // save current state as default - setCookie('interval',interval,30); - } + setCookie('interval',interval,30); + } } // dynamic change of map api var savedBounds; function loadMapAPI(api) { - savedBounds = getBounds(); - document.getElementById("map-canvas").innerHTML = ''; - var url = new Array(); - if (api=='gmaps') { - url.push('api_gmaps.js'); - url.push('//maps.googleapis.com/maps/api/js?'+((gkey!==null)?('key='+gkey+'&'):'')+'sensor=false&callback=init'); - } - else { - url.push('api_openlayers.js'); - url.push('http://openlayers.org/api/OpenLayers.js'); - } - addScript(url[0]); - waitAndLoad(api,url); + savedBounds = getBounds(); + document.getElementById("map-canvas").innerHTML = ''; + var url = new Array(); + if (api=='gmaps') { + url.push('api_gmaps.js'); + url.push('//maps.googleapis.com/maps/api/js?'+((gkey!==null)?('key='+gkey+'&'):'')+'callback=init'); + } + else { + url.push('api_openlayers.js'); + url.push('//openlayers.org/api/OpenLayers.js'); + } + addScript(url[0]); + waitAndLoad(api,url); } var loadTime = 0; function waitAndLoad(api,url) { - // wait till first script loaded - if (loadTime>5000) { loadTime = 0; alert('Sorry, can\'t load '+api+' API'); return; } - if (loadedAPI!==api) { - setTimeout(function() { loadTime += 50; waitAndLoad(api,url); }, 50); - return; - } - if(!isScriptLoaded(url[1])){ - addScript(url[1]); - } - loadTime = 0; - waitAndInit(api); + // wait till first script loaded + if (loadTime>5000) { loadTime = 0; alert('Sorry, can\'t load '+api+' API'); return; } + if (loadedAPI!==api) { + setTimeout(function() { loadTime += 50; waitAndLoad(api,url); }, 50); + return; + } + if(!isScriptLoaded(url[1])){ + addScript(url[1]); + } + loadTime = 0; + waitAndInit(api); } function waitAndInit(api) { - // wait till main api loads - if (loadTime>10000) { loadTime = 0; alert('Sorry, can\'t load '+api+' API'); return; } - try { - init(); - } - catch(e) { - setTimeout(function() { loadTime += 50; waitAndInit(api); }, 50); - return; - } - loadTime = 0; - zoomToBounds(savedBounds); - loadTrack(userid,trackid,0); - // save current api as default - setCookie('api',api,30); + // wait till main api loads + if (loadTime>10000) { loadTime = 0; alert('Sorry, can\'t load '+api+' API'); return; } + try { + init(); + } + catch(e) { + setTimeout(function() { loadTime += 50; waitAndInit(api); }, 50); + return; + } + loadTime = 0; + zoomToBounds(savedBounds); + loadTrack(userid,trackid,0); + // save current api as default + setCookie('api',api,30); } function addScript(url) { - var tag = document.createElement('script'); - tag.setAttribute('type','text/javascript'); - tag.setAttribute('src', url); - if (typeof tag!='undefined') { - document.getElementsByTagName('head')[0].appendChild(tag); - } + var tag = document.createElement('script'); + tag.setAttribute('type','text/javascript'); + tag.setAttribute('src', url); + if (typeof tag!='undefined') { + document.getElementsByTagName('head')[0].appendChild(tag); + } } function isScriptLoaded(url) { - scripts = document.getElementsByTagName('script'); - for (var i = scripts.length; i--;) { - // check if url matches src - var scriptUrl = scripts[i].src.replace(/https?:/,''); - if (scriptUrl != '' && url.indexOf(scriptUrl) !== -1) return true; - } - return false; + scripts = document.getElementsByTagName('script'); + for (var i = scripts.length; i--;) { + // check if url matches src + var scriptUrl = scripts[i].src.replace(/https?:/,''); + if (scriptUrl != '' && url.indexOf(scriptUrl) !== -1) return true; + } + return false; } function setCookie(name,value,days) { - if (days) { + if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = '; expires='+date.toGMTString(); - } - else { - var expires = ''; - } - document.cookie = 'phpTrackme_'+name+'='+value+expires+'; path=/'; + } + else { + var expires = ''; + } + document.cookie = 'phpTrackme_'+name+'='+value+expires+'; path=/'; } function setLang(lang) { diff --git a/trackme.sql b/trackme.sql index 5c47d24..f3ca4e9 100755 --- a/trackme.sql +++ b/trackme.sql @@ -1,8 +1,8 @@ --- +-- -- Database layout inherited from TrackMe -- Some tables/columns are not used by the viewer at the moment. -- Kept for compatibility with old data. --- +-- SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00";