// OwlBoard - © Fred Boniface 2022 - Licensed under GPLv3 (or later) // Please see the included LICENSE file statically served fonts are // licensed separately, each folder contains a license file // Version Number: var version = "0.0.1" console.log(`Starting OwlBoard version ${version}`) // Load & prepare modules: const fs = require('fs'); const ldb = require('ldbs-json'); const express = require('express'); const app = express(); // Get API Keys: try { var keys = JSON.parse(fs.readFileSync('/srv/keys/owlboard/keys.json', 'utf8')); console.log('API Keys loaded from /srv/keys/ownboard/keys.json'); } catch (err) { var keys = 'ERR'; console.error('Unable to obtain API Keys from file'); console.error(err); }; // Get Settings: try { var settings = JSON.parse(fs.readFileSync('./settings.json', 'utf8')); console.log("Settings loaded from .settings.json"); } catch (err) { console.warn('Unable to load settings, using defaults', err); var settings = {"webPort":8460,"listen":"localhost"}; }; // Create Web Service: app.use(express.json()); //JSON Parsing for POST Requests app.use(express.static('static')); //Serve static content from static app.listen(settings.webPort, (error) =>{ if(!error) console.log(`Server is running on http://${settings.listen}:${settings.webPort}`) else console.log("Error occurred, server can't start", error); } ); // Create/Connect to database: // Routes: app.get('/api', (req, res)=>{ res.status(200); res.set('Content-Type', 'application/json'); res.send(JSON.stringify({"OwlBoard_Status":"ready","OwlBoard_Version":version})); }); app.post('/api/test', (req, res)=>{ //Check auth and return status const {test} = req.body; res.status(200); res.set('Content-Type', 'application/json'); res.send(JSON.stringify({"test_outcome":"success","post_value":test})) }) app.post('/api/arrdep', (req, res)=>{ //Check Validity and Auth then return ArrDep JSON const {reqCode} = req.body; const {auth} = req.body; const permit = checkAuth(auth); const valid = checkValid(reqCode); res.set('Content-Type', 'application/json'); if (permit == false) { //This should be the other way round - If Valid&Auth then return, elif not auth, elif invalid elif UnknownError res.status(401); res.send(JSON.stringify({"status":"fail","error":"Not Authorised"})); } else if (valid == false) { res.status(404); res.send(JSON.stringify({"status":"fail","error":"Location not Recognized"})); } }) app.post('/api/stations', (req, res)=>{ //Return JSON of all available stations - No Auth Required }) app.post('/api/send-issue', (req, res)=>{ //Submit issue to Gitea (based on existing PHP Athena function) }) // General Functions function checkValid(input){ // Check validity of the entered CRS/Tiploc against DB } function checkAuth(downstreamKey){ // Check the downstream requester has authority to get depBoards }