diff --git a/README.md b/README.md
index a46ecb0..7160d32 100644
--- a/README.md
+++ b/README.md
@@ -58,7 +58,7 @@ To run Surveillance using docker, decide between development/testing or producti
3. Run `docker compose up` and wait for services to start up
-3. Visit `http://localhost:8081/` in a browser to open the web interface
+3. Visit `http://localhost:8081/` in a browser; you should see an interactive OpenStreetMap
4. You can see most cameras on the map immediately; the `data_handler` background process continuously applies updates from OpenStreetMap which become visible after refrshing the page
diff --git a/data_handler/utils/create_camera_update_statements.php b/data_handler/utils/create_camera_update_statements.php
index a2a072c..cf18dfc 100755
--- a/data_handler/utils/create_camera_update_statements.php
+++ b/data_handler/utils/create_camera_update_statements.php
@@ -2,18 +2,6 @@
include "config.php";
-$seqNum = $_SERVER['argv'][1] ?? '';
-if (!ctype_digit($seqNum)) {
- echo "Invalid sequence number\n";
- exit(1);
-}
-
-// Quote a value for the generated SQL file. Values come from OSM data and are untrusted.
-function sqlString($value) {
- global $mysqli;
- return "'" . $mysqli->real_escape_string((string) $value) . "'";
-}
-
$elementTypes = array();
$count = 0;
$countDelete = 0;
@@ -103,7 +91,7 @@ function endElement ($parser, $name) {
$mode = '';
} else if ($name == 'node') {
if ($mode == 'delete') {
- $id = (int) $curNodeAttrs['id'];
+ $id = $curNodeAttrs['id'];
if (! $deleteTagStmt->execute()) {
echo "***** Error : Deleting tags $id : ". $deleteTagStmt->error . "\n";
@@ -131,7 +119,7 @@ function endElement ($parser, $name) {
- $id = (int) $curNodeAttrs['id'];
+ $id = $curNodeAttrs['id'];
if ($mode == 'modify') {
if (! $deleteTagStmt->execute()) {
@@ -152,36 +140,36 @@ function endElement ($parser, $name) {
$k = 'lat';
$v = $curNodeAttrs['lat'];
- $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, " . sqlString($k) . ", " . sqlString($v) . ");\n";
+ $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, '$k', '$v');\n";
$k = 'lon';
$v = $curNodeAttrs['lon'];
- $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, " . sqlString($k) . ", " . sqlString($v) . ");\n";
+ $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, '$k', '$v');\n";
$k = 'userid';
$v = $curNodeAttrs['user'];
- $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, " . sqlString($k) . ", " . sqlString($v) . ");\n";
+ $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, '$k', '$v');\n";
$k = 'version';
$v = $curNodeAttrs['version'];
- $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, " . sqlString($k) . ", " . sqlString($v) . ");\n";
+ $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, '$k', '$v');\n";
$k = 'timestamp';
$v = $curNodeAttrs['timestamp'];
- $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, " . sqlString($k) . ", " . sqlString($v) . ");\n";
+ $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, '$k', '$v');\n";
foreach($curNodeTags as $k => $v) {
- $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, " . sqlString($k) . ", " . sqlString($v) . ");\n";
+ $sql_statement = $sql_statement . "INSERT INTO tag (id, k, v) VALUES ($id, '$k', '$v');\n";
}
} else if ($mode == 'modify') {
// delete former surveillance nodes that were modified to non-surveillance nodes
- $id = (int) $curNodeAttrs['id'];
+ $id = $curNodeAttrs['id'];
if (! $deleteTagStmt->execute()) {
echo "***** Error : Deleting tags $id for non-surveillance node : ". $deleteTagStmt->error . "\n";
@@ -220,13 +208,11 @@ while ($data = fread($fp, 4096)) {
}
}
-$syncStmt = $mysqli->prepare("UPDATE sync_state SET v=? WHERE k='sequenceNumber'");
-$syncStmt->bind_param('s', $seqNum);
-$syncStmt->execute();
-$syncStmt->close();
-$sql_statement = $sql_statement . "UPDATE sync_state SET v='" . $seqNum ."' WHERE k='sequenceNumber';\n";
+$sql="UPDATE sync_state SET v='" . $_SERVER['argv'][1] ."' WHERE k='sequenceNumber';";
+$mysqli->query($sql);
+$sql_statement = $sql_statement . "UPDATE sync_state SET v='" . $_SERVER['argv'][1] ."' WHERE k='sequenceNumber';\n";
$sql_statement = $sql_statement . "COMMIT;";
-$sql_file = "/migrations/".$seqNum.".sql";
+$sql_file = "/migrations/".$_SERVER['argv'][1].".sql";
file_put_contents($sql_file, $sql_statement);
$mysqli->close();
diff --git a/data_handler/utils/update_camera.php b/data_handler/utils/update_camera.php
index 539e0ca..dc88e48 100755
--- a/data_handler/utils/update_camera.php
+++ b/data_handler/utils/update_camera.php
@@ -2,12 +2,6 @@
include "config.php";
-$seqNum = $_SERVER['argv'][1] ?? '';
-if (!ctype_digit($seqNum)) {
- echo "Invalid sequence number\n";
- exit(1);
-}
-
$elementTypes = array();
$count = 0;
$countDelete = 0;
@@ -287,10 +281,8 @@ while ($data = fread($fp, 4096)) {
}
}
-$syncStmt = $mysqli->prepare("UPDATE sync_state SET v=? WHERE k='sequenceNumber'");
-$syncStmt->bind_param('s', $seqNum);
-$syncStmt->execute();
-$syncStmt->close();
+$sql="UPDATE sync_state SET v='" . $_SERVER['argv'][1] ."' WHERE k='sequenceNumber';";
+$mysqli->query($sql);
$mysqli->commit();
printDebug();
diff --git a/docker-compose.yml b/docker-compose.yml
index 290227d..99ed328 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -31,7 +31,7 @@ services:
DEFAULT_LANGUAGE: en
IMPRESSUM_URL: https://hamburg.ccc.de/imprint/
ports:
- - "8080:80"
+ - "8081:80"
depends_on:
db:
condition: service_started
diff --git a/web/Containerfile b/web/Containerfile
index 984e64c..e8b5998 100644
--- a/web/Containerfile
+++ b/web/Containerfile
@@ -1,17 +1,4 @@
-FROM docker.io/library/php:8.5.12-apache
+FROM docker.io/library/php:apache
RUN docker-php-ext-install mysqli bcmath
-
-# Use PHP's production defaults (no error output to clients) and hide the PHP version.
-RUN cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \
- && printf 'expose_php = Off\n' > "$PHP_INI_DIR/conf.d/zz-hardening.ini"
-
-# Disable directory listings and reduce the server signature.
-RUN sed -i 's/^\(\s*Options\) Indexes FollowSymLinks/\1 FollowSymLinks/' /etc/apache2/apache2.conf \
- && sed -i -e 's/^ServerTokens .*/ServerTokens Prod/' -e 's/^ServerSignature .*/ServerSignature Off/' /etc/apache2/conf-available/security.conf
-
-COPY ./www/* /var/www/html
-
-# The web server must not be able to create or modify files in the document root.
-RUN chown -R root:root /var/www/html \
- && chmod -R u=rwX,go=rX /var/www/html
+COPY ./www/* /var/www/html
\ No newline at end of file
diff --git a/web/www/sunders/camera.php b/web/www/sunders/camera.php
index f7c26e4..9c94d7f 100644
--- a/web/www/sunders/camera.php
+++ b/web/www/sunders/camera.php
@@ -3,17 +3,6 @@
define('MAX_POINTS_FOR_QUICKHULL', 3000);
- // Fields set by this script; OSM tags with these keys are not passed on.
- define('RESERVED_KEYS', array('lat', 'lon', 'id', 'count', 'multi', 'poly'));
-
- define('JSON_FLAGS', JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_INVALID_UTF8_SUBSTITUTE);
-
- function exitWithError($message) {
- header('Content-type: application/json; charset=utf-8');
- echo json_encode(array('error' => $message), JSON_FLAGS);
- exit;
- }
-
class OsmPoint {
var $id;
var $lat;
@@ -189,47 +178,63 @@
|| !array_key_exists('zoom', $_GET)
|| !array_key_exists('width', $_GET)
|| !array_key_exists('height', $_GET)) {
- exitWithError('bbox, zoom, width and height parameters are required. '
+ header('Content-type: application/json');
+ $result = '{"error":"bbox, zoom, width and height parameters are required. '
.(array_key_exists('bbox', $_GET) ? '' : 'bbox is empty. ')
.(array_key_exists('zoom', $_GET) ? '' : 'zoom is empty. ')
.(array_key_exists('width', $_GET) ? '' : 'width is empty. ')
- .(array_key_exists('height', $_GET) ? '' : 'height is empty. '));
+ .(array_key_exists('height', $_GET) ? '' : 'height is empty. ')
+ .'"}';
+ echo $result;
+ exit;
}
/* Check zoom */
$zoom = $_GET['zoom'];
- if ( !is_string($zoom)
- || !is_numeric($zoom)
+ if ( !is_numeric($zoom)
|| intval($zoom) < 1
|| intval($zoom) > 19) {
- exitWithError('unexpected zoom value');
+ header('Content-type: application/json');
+ $result = '{"error":"unexpected zoom value : '
+ .htmlentities($zoom)
+ .'"}';
+ echo $result;
+ exit;
}
/* Check bounds box --> bbox=boundsSW.lng,boundsSW.lat,boundsNE.lng,boundsNE.lat */
- if (!is_string($_GET['bbox'])) {
- exitWithError('unexpected bbox value');
- }
$bbox = explode(',', $_GET['bbox']);
- if ( count($bbox) != 4
- || !is_numeric($bbox[0]) || $bbox[0] > 180 // 0 = SW.lng
+ if ( !is_numeric($bbox[0]) || $bbox[0] > 180 // 0 = SW.lng
|| !is_numeric($bbox[2]) || $bbox[2] < -180 // 2 = NE.lng
|| !is_numeric($bbox[1]) || $bbox[1] < -90 || $bbox[1] > 90 // 1 = SW.lat
|| !is_numeric($bbox[3]) || $bbox[3] < -90 || $bbox[3] > 90) { // 3 = NE.lat
- exitWithError('unexpected bbox longitude and latitude values : '
- .'lon ['.$bbox[0].', '.$bbox[2].'], '
- .'lat ['.$bbox[1].', '.$bbox[3].']');
+ header('Content-type: application/json');
+ $result = '{"error":"unexpected bbox longitude and latitude values : '
+ .'lon ['.htmlentities($bbox[0]).', '.htmlentities($bbox[2]).'], '
+ .'lat ['.htmlentities($bbox[1]).', '.htmlentities($bbox[3]).']'
+ .'"}';
+ echo $result;
+ exit;
}
if ($bbox[0] >= $bbox[2]) { // 0 = SW.lng | 2 = NE.lng
- exitWithError('min longitude greater than max longitude : '
- .'lon ['.$bbox[0].', '.$bbox[2].']');
+ header('Content-type: application/json');
+ $result = '{"error":"min longitude greater than max longitude : '
+ .'lon ['.htmlentities($bbox[0]).', '.htmlentities($bbox[2]).']'
+ .'"}';
+ echo $result;
+ exit;
}
if ($bbox[1] >= $bbox[3]) { // 1 = SW.lat | 3 = NE.lat
- exitWithError('min latitude greater than max latitude : '
- .'lat ['.$bbox[1].', '.$bbox[3].']');
+ header('Content-type: application/json');
+ $result = '{"error":"min latitude greater than max latitude : '
+ .'lat ['.htmlentities($bbox[1]).', '.htmlentities($bbox[3]).']'
+ .'"}';
+ echo $result;
+ exit;
}
$lonMin = $bbox[0]; // 0 = SW.lng
@@ -241,7 +246,12 @@
$pixelHeight = (int) $_GET['height'];
if ($pixelWidth == 0 || $pixelHeight == 0) {
- exitWithError('width or height is null : '.$pixelWidth.'x'.$pixelHeight);
+ header('Content-type: application/json');
+ $result = '{"error":"width or height is null : '
+ .htmlentities($pixelWidth).'x'.htmlentities($pixelHeight)
+ .'"}';
+ echo $result;
+ exit;
}
$lonWidth = $lonMax - $lonMin; // NE.lng - SW.lng
@@ -257,7 +267,10 @@
/* Connect to database */
$mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
if($mysqli->connect_errno) {
- exitWithError('error while connecting to db');
+ header('Content-type: application/json');
+ $result = '{"error":"error while connecting to db : ' . $mysqli->error . '"}';
+ echo $result;
+ exit;
}
$rqtLonMin = $lonMin; // SW.lng
@@ -351,7 +364,10 @@
$stmt->close();
} else {
$mysqli->close();
- exitWithError('error while querying db');
+ header('Content-type: application/json');
+ $result = '{"error":"Error while request : ' . $mysqli->error . '"}';
+ echo $result;
+ exit;
}
/* Unify some clusters if nodes center are near */
@@ -363,7 +379,8 @@
}
}
- $result = array();
+ $result='[';
+ $separator='';
/* Writing selected points */
$sql='SELECT k, v
@@ -375,49 +392,53 @@
$stmt->bind_param('d', $id);
$stmt->bind_result($k, $v);
- /* Writing grouped items or not. All values are passed on unescaped; the client
- must escape them before inserting them into HTML. */
+ /* Writing grouped items or not */
foreach($resArray as $val) {
if ($val['count'] > 0) {
- $entry = array(
- 'lat' => (string) ($val['latitude'] / $val['count']),
- 'lon' => (string) ($val['longitude'] / $val['count']));
+ $result = $result.$separator
+ .'{"lat":"'.($val['latitude'] / $val['count']).'"'
+ .',"lon":"'.($val['longitude'] / $val['count']).'"';
if ($val['count'] == 1) {
$id = $val['points'][0]->id;
- $entry['id'] = (string) $id;
+ $result = $result.',"id":"'.$id.'"';
$stmt->execute();
while($stmt->fetch()) {
- if (!in_array($k, RESERVED_KEYS, true)) {
- $entry[$k] = (string) $v;
- }
+ $result = $result.',"'.htmlentities($k).'":"'.htmlentities($v, ENT_COMPAT, 'UTF-8').'"';
}
} else {
- $entry['count'] = (string) $val['count'];
- $entry['multi'] = 'yes';
- $entry['poly'] = array();
+ $result = $result
+ .',"count":"'.$val['count'].'"'
+ .',"multi":"yes"'
+ .',"poly":[';
if ($pointsCount < MAX_POINTS_FOR_QUICKHULL) {
$convexPoly = quickHull($val['points'], $val['count']);
+ $sepPoly = '';
foreach($convexPoly as $point) {
- $entry['poly'][] = array(
- 'lat' => (string) $point->lat,
- 'id' => (string) $point->id,
- 'lon' => (string) $point->lon);
+ $result = $result.$sepPoly.'{'
+ .'"lat":"'.$point->lat.'"'
+ .',"id":"'.$point->id.'"'
+ .',"lon":"'.$point->lon.'"}';
+ $sepPoly=',';
}
}
+ $result=$result.']';
}
- $result[] = $entry;
+ $result = $result.'}';
+ $separator=',';
}
}
$stmt->close();
+ $result = $result . ']';
+
$mysqli->close();
- header('Content-type: application/json; charset=utf-8');
- echo json_encode($result, JSON_FLAGS);
+ header('Content-type: application/json; Charset : utf-8');
+ echo $result;
?>
diff --git a/web/www/sunders/js/leafletembed_functions.js b/web/www/sunders/js/leafletembed_functions.js
index a2db7a5..1cbdd46 100644
--- a/web/www/sunders/js/leafletembed_functions.js
+++ b/web/www/sunders/js/leafletembed_functions.js
@@ -129,11 +129,7 @@ function onClick(e) {
function onStateChanged() {
if (ajaxRequest.readyState == 4) { // 0 = UNSENT, 1 = OPENED, 2 = HEADERS_RECEIVED, 3 = LOADING, 4 = DONE
if (ajaxRequest.status == 200) { // 200 = OK, 404 = Page not found
- try {
- plotList = JSON.parse(ajaxRequest.responseText);
- } catch(e) {
- return;
- }
+ plotList = eval('(' + ajaxRequest.responseText + ')');
removeMarkers();
for (i=0; i
| id | ' + id + ' |
| user osm | ' + escapeHtml(plot.userid) + ' |
| latitude | ' + escapeHtml(plot.lat) + ' |
| longitude | ' + escapeHtml(plot.lon) + ' |
| id | ' + (plot.id) + ' |
| user osm | ' + (plot.userid) + ' |
| latitude | ' + (plot.lat) + ' |
| longitude | ' + (plot.lon) + ' |
| ' + escapeHtml(x) + ' | '; - var descr = String(plot[x]); - if (/^https?:\/\//i.test(descr)) { - var url = escapeHtml(descr); + popupDataTable = popupDataTable + ' |
| ' + x + ' | ';
+ var descr = plot[x];
+ if (descr.substr(0, 4) == 'http') {
var suffix = descr.slice(-3).toLowerCase();
if (suffix == 'jpg' || suffix == 'gif' || suffix == 'png') {
- popupDataTable = popupDataTable + ' |