From 552a6406007d808c6932b8f67f5c4040740ca19e Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Fri, 15 May 2020 18:23:53 +0100
Subject: [PATCH 1/5] Bugfix: Correct SQL. Fixes #63

---
 logic/Repositories/MariaDBDeviceRepository.php | 2 +-
 package.json                                   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/logic/Repositories/MariaDBDeviceRepository.php b/logic/Repositories/MariaDBDeviceRepository.php
index df071a6..12a0b45 100644
--- a/logic/Repositories/MariaDBDeviceRepository.php
+++ b/logic/Repositories/MariaDBDeviceRepository.php
@@ -95,7 +95,7 @@ class MariaDBDeviceRepository implements IDeviceRepository {
 		WHERE {$s("table_name")}.{$s("column_visible")} != 0";
 		
 		if($only_with_location)
-			$sql .= "\nWHERE
+			$sql .= "\nAND
 				{$s("column_lat")} IS NOT NULL
 				AND {$s("column_long")} IS NOT NULL";
 		
diff --git a/package.json b/package.json
index fd692d8..4f34897 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "air-quality-mapper",
-	"version": "0.13.4-dev",
+	"version": "0.13.4",
 	"description": "The web interface and JSON api for the ConnectedHumber Air Quality Monitoring Project.",
 	"private": true,
 	"main": "index.mjs",

From 78aed87ddd2d42b025e0aee5f26f2a71067e8786 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 21 May 2020 19:16:30 +0100
Subject: [PATCH 2/5] Add CORS header support

---
 Changelog.md          |  6 ++++++
 api.php               |  4 ++++
 settings.default.toml | 13 +++++++++++++
 3 files changed, 23 insertions(+)

diff --git a/Changelog.md b/Changelog.md
index 618f5f5..530fe23 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -9,10 +9,16 @@ This is the changelog for the air quality web interface and its associated HTTP
  - `[Code]` refers to internal changes to the code that have no direct impact on the web interface or the HTTP API, but are significant enough to warrant note.
  - `[Docs]` refers to changes to the [documentation](https://aq.connectedhumber.org/__nightdocs/00-Welcome.html).
 
+
+## v0.13.6
+ - [Code] Add option to allow cross-origin-request sharing HTTP API requests
+
+
 ## v0.13.5
  - Disable the tour, as it's now causing a crash on startup :-(
  - [API] Don't return devices in the device lists that have the `visible` flag in the database set to `0`
 
+
 ## v0.13.4
  - [API] Fix crash in `list-devices-near` action
 
diff --git a/api.php b/api.php
index 7806037..c4ba6cc 100644
--- a/api.php
+++ b/api.php
@@ -78,6 +78,10 @@ if(!class_exists($handler_name)) {
 	exit("Error: No action with the name '$action' could be found.");
 }
 
+if($settings->get("http.cors") !== false) {
+	header("access-control-allow-origin: " . $settings->get("http.cors"));
+}
+
 $handler = $di_container->get($handler_name);
 
 $perfcounter->start("handle");
diff --git a/settings.default.toml b/settings.default.toml
index 44b5d73..139277d 100644
--- a/settings.default.toml
+++ b/settings.default.toml
@@ -7,6 +7,19 @@
 # The operating mode. Can be either "development", or "production" (default; activates a number of optimisations which might make development harder, such as 3rd-party library caches)
 mode = "production"
 
+[http]
+# HTTP related settings
+
+# Whether to enable cross-origin-request-sharing. This allows HTTP API queries
+# from origins other than that of the origin of the HTTP API itself.
+# For example, if the HTTP API is running on sensors.connectedhumber.org, then
+# Without CORS a client-side Javascript program running on foo.example.com would
+# not be able to request data.
+# Possible values: false (disabled), a string (an origin to allow; set via the access-control-allow-origin header), or the special string "*" (allows all origins)
+cors = false
+# cors = "subdomain.example.com"
+# cors = "*"
+
 [database]
 # Settings that control the database, or the connection to it
 

From 57c1c797447868db89e00e9693bc9e4d075d9854 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 21 May 2020 19:35:28 +0100
Subject: [PATCH 3/5] we've got a symlink issue again

---
 build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build b/build
index e5bd805..c7d6133 100755
--- a/build
+++ b/build
@@ -340,7 +340,7 @@ task_deploy() {
 	subtask_end $?;
 	
 	subtask_begin "Unwinding symlinks";
-	find "${temp_dir}" -type l -not -path "./beta" -exec bash -c 'ln -f "$(readlink -m "$0")" "$0"' {} \;
+	find "${temp_dir}" -D exec -type l -not -path "./beta" -exec bash -c 'ln -f "$(readlink -m "$0")" "$0"' {} \;
 	subtask_end $?;
 	
 	task_end $?;

From e30cb5b79cd64830293f91b646fc540479e72a04 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 21 May 2020 19:56:03 +0100
Subject: [PATCH 4/5] build: comment out symlink code, and update nightdocs
 Let's see if this helps.

---
 build             |  6 +++---
 package-lock.json | 29 ++++++++++++++++-------------
 package.json      |  4 ++--
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/build b/build
index c7d6133..c5ce878 100755
--- a/build
+++ b/build
@@ -339,9 +339,9 @@ task_deploy() {
 	rm -r "${temp_dir}/data"; # Delete the default data directory - there's one on the server already
 	subtask_end $?;
 	
-	subtask_begin "Unwinding symlinks";
-	find "${temp_dir}" -D exec -type l -not -path "./beta" -exec bash -c 'ln -f "$(readlink -m "$0")" "$0"' {} \;
-	subtask_end $?;
+	# subtask_begin "Unwinding symlinks";
+	# find "${temp_dir}" -D exec -type l -not -path "./beta" -exec bash -c 'ln -f "$(readlink -m "$0")" "$0"' {} \;
+	# subtask_end $?;
 	
 	task_end $?;
 	
diff --git a/package-lock.json b/package-lock.json
index 491695d..6e2845e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "air-quality-mapper",
-  "version": "0.13.4-dev",
+  "version": "0.13.4",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
@@ -36,9 +36,9 @@
       "integrity": "sha512-yEvVC8RfhRPkD9TUn7cFcLcgoJePgZRAOR7T21rcRY5I8tpuhzeWfGa7We7tB14fe9R7wENdqUABcMdwD4SQLw=="
     },
     "@types/chart.js": {
-      "version": "2.9.19",
-      "resolved": "https://registry.npmjs.org/@types/chart.js/-/chart.js-2.9.19.tgz",
-      "integrity": "sha512-sFxlMb+ElfJelXh0Z8spmiLRrnXCd7CaT6WGQtckhjETK1H5i1nYKN4TOExhqPeDZ6u+w4bJ20UYqELWOEfAKQ==",
+      "version": "2.9.21",
+      "resolved": "https://registry.npmjs.org/@types/chart.js/-/chart.js-2.9.21.tgz",
+      "integrity": "sha512-bjwdC+SvE/c3rHYYcX8UbRmTvjEUP9Dhuk/iWXygH6EFDYf4OcofnwxBpJx+A4qU3YBr54a7wtPdswfg9Yt3rg==",
       "dev": true,
       "requires": {
         "moment": "^2.10.2"
@@ -252,7 +252,8 @@
         },
         "kind-of": {
           "version": "6.0.2",
-          "resolved": "",
+          "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
+          "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
           "dev": true
         }
       }
@@ -1257,7 +1258,8 @@
         },
         "kind-of": {
           "version": "6.0.2",
-          "resolved": "",
+          "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
+          "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
           "dev": true
         }
       }
@@ -1463,9 +1465,9 @@
       "dev": true
     },
     "html-entities": {
-      "version": "1.2.1",
-      "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-1.2.1.tgz",
-      "integrity": "sha1-DfKTUfByEWNRXfueVUPl9u7VFi8=",
+      "version": "1.3.1",
+      "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-1.3.1.tgz",
+      "integrity": "sha512-rhE/4Z3hIhzHAUKbW8jVcCyuT5oJCXXqhN/6mXXVCpzTmvJnoH2HL/bt3EZ6p55jbFJBeAe1ZNpL5BugLujxNA==",
       "dev": true
     },
     "icss-replace-symbols": {
@@ -2010,9 +2012,9 @@
       "integrity": "sha1-qiEiUSr49vpr3G8y1nqm3whvfK0="
     },
     "nightdocs": {
-      "version": "1.0.6",
-      "resolved": "https://registry.npmjs.org/nightdocs/-/nightdocs-1.0.6.tgz",
-      "integrity": "sha512-oo9+q4nuztpnzefbasM4Pn3sKSYRGuZHFh18Km9AiDqQFqHUZrwPzy8zmAUkAP5ajUcUMS4j2vutg5hHb8pZcw==",
+      "version": "1.0.7",
+      "resolved": "https://registry.npmjs.org/nightdocs/-/nightdocs-1.0.7.tgz",
+      "integrity": "sha512-oExfdLtKq3IqkVTLao7NMyKjIfpQpD2QOO/tjPCmEDNjWKUF7pAZ3wicoO6stDv69M4K3IIw1uq8BcGdw9iJyQ==",
       "dev": true,
       "requires": {
         "marked": "^0.7.0",
@@ -4294,7 +4296,8 @@
         },
         "kind-of": {
           "version": "6.0.2",
-          "resolved": "",
+          "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
+          "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
           "dev": true
         }
       }
diff --git a/package.json b/package.json
index 4f34897..bb5ef5b 100644
--- a/package.json
+++ b/package.json
@@ -36,13 +36,13 @@
 		"xml-writer": "^1.7.0"
 	},
 	"devDependencies": {
-		"@types/chart.js": "^2.9.19",
+		"@types/chart.js": "^2.9.21",
 		"@types/chroma-js": "^2.0.0",
 		"@types/d3-delaunay": "^4.1.0",
 		"@types/event-emitter-es6": "^1.1.0",
 		"@types/leaflet": "^1.5.12",
 		"@types/leaflet-fullscreen": "^1.0.4",
-		"nightdocs": "^1.0.6",
+		"nightdocs": "^1.0.7",
 		"postcss-copy": "^7.1.0",
 		"postcss-import": "^12.0.1",
 		"rollup": "^2.7.2",

From f19ada971574ff67fa2cb3d5a3d373d317fc8296 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 21 May 2020 20:09:27 +0100
Subject: [PATCH 5/5] Fix nightdocs.... again

---
 package-lock.json | 6 +++---
 package.json      | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 6e2845e..2ef5254 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2012,9 +2012,9 @@
       "integrity": "sha1-qiEiUSr49vpr3G8y1nqm3whvfK0="
     },
     "nightdocs": {
-      "version": "1.0.7",
-      "resolved": "https://registry.npmjs.org/nightdocs/-/nightdocs-1.0.7.tgz",
-      "integrity": "sha512-oExfdLtKq3IqkVTLao7NMyKjIfpQpD2QOO/tjPCmEDNjWKUF7pAZ3wicoO6stDv69M4K3IIw1uq8BcGdw9iJyQ==",
+      "version": "1.0.8",
+      "resolved": "https://registry.npmjs.org/nightdocs/-/nightdocs-1.0.8.tgz",
+      "integrity": "sha512-Jqg0Ql3ZLlZSKCBWG8ci7XxVMQOfh605vX21FUiEuCD4woSOhbmMpUiVBgKZjDBm0ztCcz28qSFLJi9ZJRyAkQ==",
       "dev": true,
       "requires": {
         "marked": "^0.7.0",
diff --git a/package.json b/package.json
index bb5ef5b..59c3651 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,7 @@
 		"@types/event-emitter-es6": "^1.1.0",
 		"@types/leaflet": "^1.5.12",
 		"@types/leaflet-fullscreen": "^1.0.4",
-		"nightdocs": "^1.0.7",
+		"nightdocs": "^1.0.8",
 		"postcss-copy": "^7.1.0",
 		"postcss-import": "^12.0.1",
 		"rollup": "^2.7.2",
