Basic cleanup before going public

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-24 16:45:54 -04:00
parent a7d3af3323
commit f70142b7b0
5 changed files with 56 additions and 46 deletions
+24
View File
@@ -1,3 +1,27 @@
# DeHaze
Port the Haze Explr API to GEOJSON for use in GIS applications.
This was a quick and dirty project, and will probably get some updates slowly in the future. I put what I learned from this in the [HacDC Wiki](https://wiki.hacdc.org/en/Projects/API/HazeExplr).
## Usage
```bash
npm i
node serve.js
```
To use the endpoint, replace 'EMAIL' and 'PASSWORD' with your Haze Explr account details:
```bash
echo "EMAIL:`echo 'PASSWORD' | sha256sum | sed -e 's/ -//'`" | base64
```
Then, make a request to the endpoint with the resulting string as the value of the `auth` query parameter:
```bash
curl "http://localhost:3000/locations?auth=BASE64_ENCODED_STRING"
```
`basicauth_serve.js` does the same thing bus expects account details to be passed via basic HTTP auth, but does not work with QGIS.
+22 -10
View File
@@ -1,9 +1,10 @@
const express = require('express');
const auth = require('express-basic-auth');
const { createHash } = require('crypto');
const app = express();
const port = 8356;
const port = 8355;
const geonJsonTemplate = {
type: "FeatureCollection",
features: [],
@@ -12,20 +13,32 @@ const geonJsonTemplate = {
"star-stroked": "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'><path fill='currentColor' d='M64 32C28.7 32 0 60.7 0 96L0 416c0 35.3 28.7 64 64 64l320 0c35.3 0 64-28.7 64-64l0-320c0-35.3-28.7-64-64-64L64 32zm73.8 149.3c7.9-22.3 29.1-37.3 52.8-37.3l58.3 0c34.9 0 63.1 28.3 63.1 63.1 0 22.6-12.1 43.5-31.7 54.8L248 280.4c-.2 13-10.9 23.6-24 23.6-13.3 0-24-10.7-24-24l0-13.5c0-8.6 4.6-16.5 12.1-20.8l44.3-25.4c4.7-2.7 7.6-7.7 7.6-13.1 0-8.4-6.8-15.1-15.1-15.1l-58.3 0c-3.4 0-6.4 2.1-7.5 5.3l-.4 1.2c-4.4 12.5-18.2 19-30.6 14.6s-19-18.2-14.6-30.6l.4-1.2zM192 368a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zM48 104a24 24 0 1 1 48 0 24 24 0 1 1 -48 0zM376 80a24 24 0 1 1 0 48 24 24 0 1 1 0-48zM48 408a24 24 0 1 1 48 0 24 24 0 1 1 -48 0zm328-24a24 24 0 1 1 0 48 24 24 0 1 1 0-48z'/></svg>"
}
};
app.use(auth({
authorizer: (username, password) => {
return true;
}
}));
app.all('/locations.geojson', (req, res) => {
// Verify Inputs
if (!req.query.auth) {
if ((!req.auth.user || !req.auth.password) && (!req.query.auth)) {
res.status(401).send('Unauthorized');
return;
}
// Query Haze API Websocket
let hazePwHash = null;
let hazeUser = null;
if (req.query.auth){
let paramAuth = Buffer.from(req.query.auth, 'base64').toString('utf-8').replaceAll('\n', '');
hazeUser = paramAuth.split(":")[0];
if (req.query.auth) {
let paramAuth = Buffer.from(req.query.auth, 'base64').toString('utf-8');
hawUser = paramAuth.split(":")[0];
hazePwHash = paramAuth.split(":")[1];
} else {
hazeUser = req.auth.user;
if (/\b[A-Fa-f0-9]{64}\b/.test(req.auth.password)) {
hazePwHash = req.auth.password;
} else {
hazePwHash = createHash('sha256').update(req.auth.password).digest('hex');
}
}
const haze = new WebSocket('wss://do.ecven.com:8120/explr');
haze.addEventListener('message', (event) => {
@@ -33,7 +46,7 @@ app.all('/locations.geojson', (req, res) => {
let haze_authToken = '', haze_username = '';
switch (data['event']) {
case "connected":
let pld = {
haze.send(JSON.stringify({
"event": "authenticateAccount_request",
"body": [
{
@@ -42,8 +55,7 @@ app.all('/locations.geojson', (req, res) => {
}
],
"socketMessageId": 0
};
haze.send(JSON.stringify(pld));
}));
break;
case "authenticateAccount_response":
if (data['body']['response'] === 1) {
@@ -51,8 +63,8 @@ app.all('/locations.geojson', (req, res) => {
haze_username = data['body']['username'];
haze.send('{"event": "getMyLocationsRequest_request","body": [{"higlightImages": true}],"socketMessageId": 0}');
} else {
console.dir(req.query);
res.status(401).json({ ...data, password: req.query.auth });
console.dir(req.query);
res.status(401).json({ ...data, password: req.auth.password });
haze.close();
res.end();
}
-10
View File
@@ -1,10 +0,0 @@
[Unit]
Descripton=HazeExplr API porting tool
[Service]
ExecStart=/home/liz/dehaze/run.sh
User=liz
[Install]
WantedBy=multi-user.target
-4
View File
@@ -1,4 +0,0 @@
#!/bin/bash
cd /home/liz/dehaze
/home/liz/.nvm/versions/node/v24.14.1/bin/node aserve.js &
/home/liz/.nvm/versions/node/v24.14.1/bin/node serve.js
+10 -22
View File
@@ -1,10 +1,8 @@
const express = require('express');
const auth = require('express-basic-auth');
const { createHash } = require('crypto');
const app = express();
const port = 8355;
const port = 8356;
const geonJsonTemplate = {
type: "FeatureCollection",
features: [],
@@ -13,32 +11,20 @@ const geonJsonTemplate = {
"star-stroked": "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'><path fill='currentColor' d='M64 32C28.7 32 0 60.7 0 96L0 416c0 35.3 28.7 64 64 64l320 0c35.3 0 64-28.7 64-64l0-320c0-35.3-28.7-64-64-64L64 32zm73.8 149.3c7.9-22.3 29.1-37.3 52.8-37.3l58.3 0c34.9 0 63.1 28.3 63.1 63.1 0 22.6-12.1 43.5-31.7 54.8L248 280.4c-.2 13-10.9 23.6-24 23.6-13.3 0-24-10.7-24-24l0-13.5c0-8.6 4.6-16.5 12.1-20.8l44.3-25.4c4.7-2.7 7.6-7.7 7.6-13.1 0-8.4-6.8-15.1-15.1-15.1l-58.3 0c-3.4 0-6.4 2.1-7.5 5.3l-.4 1.2c-4.4 12.5-18.2 19-30.6 14.6s-19-18.2-14.6-30.6l.4-1.2zM192 368a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zM48 104a24 24 0 1 1 48 0 24 24 0 1 1 -48 0zM376 80a24 24 0 1 1 0 48 24 24 0 1 1 0-48zM48 408a24 24 0 1 1 48 0 24 24 0 1 1 -48 0zm328-24a24 24 0 1 1 0 48 24 24 0 1 1 0-48z'/></svg>"
}
};
app.use(auth({
authorizer: (username, password) => {
return true;
}
}));
app.all('/locations.geojson', (req, res) => {
// Verify Inputs
if ((!req.auth.user || !req.auth.password) && (!req.query.auth)) {
if (!req.query.auth) {
res.status(401).send('Unauthorized');
return;
}
// Query Haze API Websocket
let hazePwHash = null;
let hazeUser = null;
if (req.query.auth){
let paramAuth = Buffer.from(req.query.auth, 'base64').toString('utf-8');
hawUser = paramAuth.split(":")[0];
if (req.query.auth) {
let paramAuth = Buffer.from(req.query.auth, 'base64').toString('utf-8').replaceAll('\n', '');
hazeUser = paramAuth.split(":")[0];
hazePwHash = paramAuth.split(":")[1];
} else {
hazeUser = req.auth.user;
if (/\b[A-Fa-f0-9]{64}\b/.test(req.auth.password)) {
hazePwHash = req.auth.password;
} else {
hazePwHash = createHash('sha256').update(req.auth.password).digest('hex');
}
}
const haze = new WebSocket('wss://do.ecven.com:8120/explr');
haze.addEventListener('message', (event) => {
@@ -46,7 +32,7 @@ app.all('/locations.geojson', (req, res) => {
let haze_authToken = '', haze_username = '';
switch (data['event']) {
case "connected":
haze.send(JSON.stringify({
let pld = {
"event": "authenticateAccount_request",
"body": [
{
@@ -55,7 +41,8 @@ app.all('/locations.geojson', (req, res) => {
}
],
"socketMessageId": 0
}));
};
haze.send(JSON.stringify(pld));
break;
case "authenticateAccount_response":
if (data['body']['response'] === 1) {
@@ -63,7 +50,8 @@ app.all('/locations.geojson', (req, res) => {
haze_username = data['body']['username'];
haze.send('{"event": "getMyLocationsRequest_request","body": [{"higlightImages": true}],"socketMessageId": 0}');
} else {
res.status(401).json({ ...data, password: req.auth.password });
console.dir(req.query);
res.status(401).json({ ...data, password: req.query.auth });
haze.close();
res.end();
}