mirror of
https://gitlab.silvrtree.co.uk/martind2000/mdot_server.git
synced 2025-01-25 16:26:18 +00:00
Implemented basic authentication, moved static files out and used templates.
This commit is contained in:
parent
b9d035aa32
commit
6c6ab1092f
28
app.js
28
app.js
@ -14,14 +14,14 @@ var bodyparser = require('body-parser');
|
||||
var errorhandler = require('errorhandler');
|
||||
var log4js = require('log4js');
|
||||
var logger = log4js.getLogger();
|
||||
|
||||
var authentication = require('basic-authentication');
|
||||
|
||||
var WebSocketServer = require('websocket').server;
|
||||
|
||||
var EventEmitter = require('events');
|
||||
var busEmitter = new EventEmitter();
|
||||
|
||||
// var apn = require('apn');
|
||||
// Var apn = require('apn');
|
||||
|
||||
require('sugar-date');
|
||||
|
||||
@ -42,6 +42,13 @@ logger.warn('isProduction:', isProduction);
|
||||
|
||||
var app = express();
|
||||
|
||||
/*App.use(authentication(({
|
||||
hash: 'sha1', // type of hash
|
||||
file: 'htpasswd', // path of file
|
||||
suppress: true // suppress throwing Error if wrong user
|
||||
})));*/
|
||||
|
||||
|
||||
app.set('port', process.env.PORT || 4545);
|
||||
app.set('views', __dirname + '/views');
|
||||
app.set('view engine', 'ejs');
|
||||
@ -79,8 +86,19 @@ function originIsAllowed(origin) {
|
||||
// Put logic here to detect whether the specified origin is allowed.
|
||||
return true;
|
||||
}
|
||||
app.get('/graph', authentication(({
|
||||
hash: 'sha1', // Type of hash
|
||||
file: 'htpasswd', // Path of file
|
||||
suppress: true // Suppress throwing Error if wrong user
|
||||
})), function(req, res) {
|
||||
res.render('test',{delimiter: '^'});
|
||||
});
|
||||
|
||||
// glue routes
|
||||
app.get('/meeting', function(req, res) {
|
||||
res.render('meeting',{delimiter: '^'});
|
||||
});
|
||||
|
||||
// Glue routes
|
||||
mdotApi(app);
|
||||
mdotApiV2(app);
|
||||
trackApi(app);
|
||||
@ -98,6 +116,10 @@ if (isProduction) {
|
||||
var port = (process.env.VCAP_APP_PORT || 3010);
|
||||
var host = (process.env.VCAP_APP_HOST || 'localhost');
|
||||
|
||||
app.get('*', function(req, res) {
|
||||
res.status(404).render('404',{delimiter: '^'});
|
||||
});
|
||||
|
||||
app.listen(port, function() {
|
||||
logger.info('Express listening on ',host, port);
|
||||
|
||||
|
2
htpasswd
Normal file
2
htpasswd
Normal file
@ -0,0 +1,2 @@
|
||||
martind2000:ae7dfe3f3ba4d1132f8c7d7e5a2d05676127458a8842b9c28cea7662ad45393c
|
||||
censis:32e3248f334f9045106a86f561a4c9741c1e4f51
|
@ -35,7 +35,6 @@ module.exports = function(app) {
|
||||
|
||||
dbMdot.doGet(data)
|
||||
.then((d) => {
|
||||
logger.debug('returning:',d.occupancy);
|
||||
res.json({events:d});
|
||||
})
|
||||
.catch((e) => {
|
||||
|
@ -1,8 +1,9 @@
|
||||
applications:
|
||||
- path: .
|
||||
memory: 256M
|
||||
framework: node
|
||||
instances: 1
|
||||
domain: mybluemix.net
|
||||
name: mdotmqtt
|
||||
host: mdotmqtt
|
||||
name: mdotserver
|
||||
host: mdotserver
|
||||
disk_quota: 1024M
|
||||
|
@ -11,9 +11,38 @@
|
||||
<link href="css/style.css" rel="stylesheet" type="text/css"/>
|
||||
<link rel="stylesheet" href="css/notification.css">
|
||||
<!-- endbuild -->
|
||||
|
||||
<link rel="apple-touch-icon" sizes="57x57"
|
||||
href="/fav/apple-touch-icon-57x57.png">
|
||||
<link rel="apple-touch-icon" sizes="60x60"
|
||||
href="/fav/apple-touch-icon-60x60.png">
|
||||
<link rel="apple-touch-icon" sizes="72x72"
|
||||
href="/fav/apple-touch-icon-72x72.png">
|
||||
<link rel="apple-touch-icon" sizes="76x76"
|
||||
href="/fav/apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" sizes="114x114"
|
||||
href="/fav/apple-touch-icon-114x114.png">
|
||||
<link rel="apple-touch-icon" sizes="120x120"
|
||||
href="/fav/apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" sizes="144x144"
|
||||
href="/fav/apple-touch-icon-144x144.png">
|
||||
<link rel="apple-touch-icon" sizes="152x152"
|
||||
href="/fav/apple-touch-icon-152x152.png">
|
||||
<link rel="apple-touch-icon" sizes="180x180"
|
||||
href="/fav/apple-touch-icon-180x180.png">
|
||||
<link rel="icon" type="image/png" href="/fav/favicon-32x32.png" sizes="32x32">
|
||||
<link rel="icon" type="image/png" href="/fav/android-chrome-192x192.png"
|
||||
sizes="192x192">
|
||||
<link rel="icon" type="image/png" href="/fav/favicon-96x96.png" sizes="96x96">
|
||||
<link rel="icon" type="image/png" href="/fav/favicon-16x16.png" sizes="16x16">
|
||||
<link rel="manifest" href="/fav/manifest.json">
|
||||
<link rel="mask-icon" href="/fav/safari-pinned-tab.svg" color="#5bbad5">
|
||||
<link rel="shortcut icon" href="/fav/favicon.ico">
|
||||
<meta name="msapplication-TileColor" content="#da532c">
|
||||
<meta name="msapplication-TileImage" content="/fav/mstile-144x144.png">
|
||||
<meta name="msapplication-config" content="/fav/browserconfig.xml">
|
||||
<meta name="theme-color" content="#00aeef">
|
||||
</head>
|
||||
<body style="background-color:#171d25">
|
||||
<body style="background-color:#171d25" class="mui--no-user-select">
|
||||
<div class="mui-container">
|
||||
<div class='mui-row'>
|
||||
<div class="mui-col-md-3 panel">
|
@ -8,6 +8,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"atob": "^2.0.3",
|
||||
"basic-authentication": "^1.6.2",
|
||||
"body-parser": "^1.15.1",
|
||||
"btoa": "^1.1.2",
|
||||
"cfenv": "1.0.x",
|
||||
|
130457
sql/mdot.sql
Normal file
130457
sql/mdot.sql
Normal file
File diff suppressed because it is too large
Load Diff
76
views/meeting.ejs
Normal file
76
views/meeting.ejs
Normal file
@ -0,0 +1,76 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<title>Meetings</title>
|
||||
<link href="css/mui.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/notification.css" rel="stylesheet" type="text/css"/>
|
||||
<script src="lib/mui.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="mui-container">
|
||||
<div class='mui-row'>
|
||||
<div class="mui-panel">
|
||||
<div class="mui--text-title">Meeting Log</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='mui-row'>
|
||||
<div class="mui-panel">
|
||||
<form id="meetingForm">
|
||||
<legend>New Meeting</legend>
|
||||
<div class="mui-select">
|
||||
<select id="device" name="device" required>
|
||||
<option></option>
|
||||
<option value="1">
|
||||
Large Meeting Room
|
||||
</option>
|
||||
<option value="2">
|
||||
Small Meeting Room
|
||||
</option>
|
||||
<option value="3">
|
||||
Lab
|
||||
</option>
|
||||
</select> <label>Room</label>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-4">
|
||||
<div class="mui-textfield">
|
||||
<input type="date" placeholder="" id='from' name="from" required/>
|
||||
<label>Day</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-4">
|
||||
<div class="mui-textfield">
|
||||
<input type="time" placeholder="" id='start' name="start" required/>
|
||||
<label>Start</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-col-md-4">
|
||||
<div class="mui-textfield">
|
||||
<input type="time" placeholder="" id='end' name="end" required/>
|
||||
<label>End</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-textfield mui-textfield--float-label">
|
||||
<input type="number" value="0" id="occupancy" required/> <label>Occupants</label>
|
||||
</div>
|
||||
<button type="submit" class="mui-btn mui-btn--raised">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="lib/jquery.js"
|
||||
integrity="sha256-laXWtGydpwqJ8JA+X9x2miwmaiKhn8tVmOVEigRNtP4="
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="lib/underscore.js"></script>
|
||||
<script src="lib/backbone.js"></script>
|
||||
<script src="lib/sugar-date.js"></script>
|
||||
<script src="lib/notification.js"></script>
|
||||
<script src="js/meeting.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
233
views/test.ejs
Normal file
233
views/test.ejs
Normal file
@ -0,0 +1,233 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Graph</title>
|
||||
<meta name="viewport"
|
||||
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
|
||||
<!-- build:css -->
|
||||
<link href="css/mui.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/test.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/style.css" rel="stylesheet" type="text/css"/>
|
||||
<link rel="stylesheet" href="css/notification.css">
|
||||
<!-- endbuild -->
|
||||
<link rel="apple-touch-icon" sizes="57x57"
|
||||
href="/fav/apple-touch-icon-57x57.png">
|
||||
<link rel="apple-touch-icon" sizes="60x60"
|
||||
href="/fav/apple-touch-icon-60x60.png">
|
||||
<link rel="apple-touch-icon" sizes="72x72"
|
||||
href="/fav/apple-touch-icon-72x72.png">
|
||||
<link rel="apple-touch-icon" sizes="76x76"
|
||||
href="/fav/apple-touch-icon-76x76.png">
|
||||
<link rel="apple-touch-icon" sizes="114x114"
|
||||
href="/fav/apple-touch-icon-114x114.png">
|
||||
<link rel="apple-touch-icon" sizes="120x120"
|
||||
href="/fav/apple-touch-icon-120x120.png">
|
||||
<link rel="apple-touch-icon" sizes="144x144"
|
||||
href="/fav/apple-touch-icon-144x144.png">
|
||||
<link rel="apple-touch-icon" sizes="152x152"
|
||||
href="/fav/apple-touch-icon-152x152.png">
|
||||
<link rel="apple-touch-icon" sizes="180x180"
|
||||
href="/fav/apple-touch-icon-180x180.png">
|
||||
<link rel="icon" type="image/png" href="/fav/favicon-32x32.png" sizes="32x32">
|
||||
<link rel="icon" type="image/png" href="/fav/android-chrome-192x192.png"
|
||||
sizes="192x192">
|
||||
<link rel="icon" type="image/png" href="/fav/favicon-96x96.png" sizes="96x96">
|
||||
<link rel="icon" type="image/png" href="/fav/favicon-16x16.png" sizes="16x16">
|
||||
<link rel="manifest" href="/fav/manifest.json">
|
||||
<link rel="mask-icon" href="/fav/safari-pinned-tab.svg" color="#5bbad5">
|
||||
<link rel="shortcut icon" href="/fav/favicon.ico">
|
||||
<meta name="msapplication-TileColor" content="#da532c">
|
||||
<meta name="msapplication-TileImage" content="/fav/mstile-144x144.png">
|
||||
<meta name="msapplication-config" content="/fav/browserconfig.xml">
|
||||
<meta name="theme-color" content="#00aeef">
|
||||
</head>
|
||||
<body style="background-color:#171d25" class="mui--no-user-select">
|
||||
<div class="mui-container">
|
||||
<div class='mui-row'>
|
||||
<div class="mui-col-md-3 panel">
|
||||
<div class='mui-panel' id="main"></div>
|
||||
<div id="output"></div>
|
||||
</div>
|
||||
<div class="mui-col-md-9">
|
||||
<div class="mui-container">
|
||||
<div id="chartdiv" style="width:100%; height:600px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/template" id="loaded-template">
|
||||
<div
|
||||
style="background-color: darkred;color: white;font-weight: 900;text-align: center">Loaded
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/template" id="main-template">
|
||||
<div class="mui-container">
|
||||
<div class="mui-row">
|
||||
<div class="mui-select">
|
||||
<select id="device" name="device">
|
||||
<option></option>
|
||||
<option>
|
||||
HIE-mobile-1
|
||||
</option>
|
||||
<option>
|
||||
HIE-demo
|
||||
</option>
|
||||
<option>
|
||||
HIE-mobile-2
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-1
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-2
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-3
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-4
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-5
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-6
|
||||
</option>
|
||||
<option>
|
||||
HIE-smart-campus-7
|
||||
</option>
|
||||
<option>
|
||||
CENSIS-LoRa-1
|
||||
</option>
|
||||
<option>
|
||||
CENSIS-LoRa-2
|
||||
</option>
|
||||
<option>
|
||||
CENSIS-LoRa-3
|
||||
</option>
|
||||
<option>
|
||||
CENSIS-LoRa-4
|
||||
</option>
|
||||
<option>
|
||||
HIE-mDot-1
|
||||
</option>
|
||||
</select> <label>Device</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-12">
|
||||
<button id='refresh'
|
||||
class="mui-btn mui-btn--small mui-btn--primary">Refresh
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/template" id="list-template">
|
||||
<ul></ul>
|
||||
</script>
|
||||
<script type="text/template" id="item-template">
|
||||
<div class="mui-row">
|
||||
<div class="mui-col-md-2"><%= item.timestamp %></div>
|
||||
<div class="mui-col-md-2"><%= item.lux %></div>
|
||||
<div class="mui-col-md-2"><%= item.co2 %></div>
|
||||
<div class="mui-col-md-2"><%= item.temp %></div>
|
||||
<div class="mui-col-md-2"><%= item.humidity %></div>
|
||||
<div class="mui-col-md-2"><%= item.sound %></div>
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/template" id="AMChart-template">
|
||||
<div class="mui-container">
|
||||
<div class="mui-row">
|
||||
<div class="mui-select mui-col-md-12">
|
||||
<select id="displaymode" name="displaymode">
|
||||
<option value="0"></option>
|
||||
<option value="1">
|
||||
Light
|
||||
</option>
|
||||
<option value="2">
|
||||
Temp
|
||||
</option>
|
||||
<option value="3">
|
||||
Co2
|
||||
</option>
|
||||
<option value="4">
|
||||
Humidity
|
||||
</option>
|
||||
<option value="5">
|
||||
Noise
|
||||
</option>
|
||||
<option value="6">
|
||||
Light & Co2
|
||||
</option>
|
||||
<option value="7">
|
||||
Temperature & Humidity
|
||||
</option>
|
||||
|
||||
</select> <label>Graph</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/template" id="graph-template">
|
||||
<div class="mui-container">
|
||||
<div class="mui-row">
|
||||
<div class="mui-select mui-col-md-6">
|
||||
<select id="displaymode" name="displaymode">
|
||||
<option value="0"></option>
|
||||
<option value="1">
|
||||
Light
|
||||
</option>
|
||||
<option value="2">
|
||||
Temp
|
||||
</option>
|
||||
<option value="3">
|
||||
Co2
|
||||
</option>
|
||||
<option value="4">
|
||||
Humidity
|
||||
</option>
|
||||
<option value="5">
|
||||
Noise
|
||||
</option>
|
||||
</select> <label>Graph</label>
|
||||
</div>
|
||||
<div class="mui-col-md-6">
|
||||
<svg id="graphSVG" width="300" height="150" fill="blue">
|
||||
<line x1="46" y1="12" x2="280" y2="12"
|
||||
style="stroke:#004c6d;stroke-width:2;"></line>
|
||||
<text id="maxY" x="36" y="15" text-anchor="end">--</text>
|
||||
<line x1="46" y1="136" x2="280" y2="136"
|
||||
style="stroke:#004c6d;stroke-width:2;"></line>
|
||||
<text id="MinY" x="36" y="139" text-anchor="end">0</text>
|
||||
<polyline id="line" fill="none" stroke="#2196F3" text-anchor="end"
|
||||
stroke-width="1" points=""></polyline>
|
||||
<g id="datapoints"></g>
|
||||
<g id="baseline"></g>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- build:vendor -->
|
||||
<script src="lib/mui.js"></script>
|
||||
<script src="lib/notification.js"></script>
|
||||
<script src="lib/jquery.js"
|
||||
integrity="sha256-laXWtGydpwqJ8JA+X9x2miwmaiKhn8tVmOVEigRNtP4="
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="lib/base64.js"></script>
|
||||
<script src="lib/underscore.js"></script>
|
||||
<script src="lib/backbone.js"></script>
|
||||
<script src="lib/sugar-date.js"></script>
|
||||
<script src="lib/notification.js"></script>
|
||||
<script src="lib/amcharts.js"></script>
|
||||
<script src="lib/serial.js"></script>
|
||||
<script src="lib/amstock.js"></script>
|
||||
<!-- endbuild -->
|
||||
<!-- build:js -->
|
||||
<script src="js/mdot.js"></script>
|
||||
<!-- endbuild -->
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user