diff --git a/config.sample.js b/config.sample.js
index afb313f..b7351c0 100644
--- a/config.sample.js
+++ b/config.sample.js
@@ -19,12 +19,13 @@ var config = {
baseDriveDownloadPathMapping: '/realdata', // path mapping of above download url for expressjs, prefix with "/"
storagePath: 'realdata/', // relative or absolute ( "/..." for absolute path )
-
+
deviceStorageQuotaMb: 200000,
- deviceDriveQuota: 1000,
deviceDriveExpirationDays: 30,
- cabanaUrl: 'http://192.168.1.165:3001/'
+ cabanaUrl: 'http://192.168.1.165:3001/',
+
+ welcomeMessage: `<><><><><><><><><><><><><><><><><><><><><><>
2021 RetroPilot`
};
module.exports = config;
diff --git a/server.js b/server.js
index 896ed1e..296f130 100644
--- a/server.js
+++ b/server.js
@@ -23,11 +23,16 @@ const sendmail = require('sendmail')();
const htmlspecialchars = require('htmlspecialchars');
const dirTree = require("directory-tree");
+const execSync = require('child_process').execSync;
const adapter = new FileSync(config.databaseFile);
const db = low(adapter);
+const ALL = 1E8;
+
+var totalStorageUsed=null; // global variable that is regularly updated in the background to track the total used storage
+
log4js.configure({
appenders: { logfile: { type: "file", filename: "server.log" }, out: { type: "console"} },
@@ -192,6 +197,13 @@ function getAuthenticatedAccount(req) {
return account.value();
}
+function updateTotalStorageUsed() {
+ var verifiedPath = mkDirByPathSync(config.storagePath, {isRelativeToScript: (config.storagePath.indexOf("/")===0 ? false : true)});
+ if (verifiedPath!==null) {
+ totalStorageUsed = execSync("du -hs "+verifiedPath+" | awk -F'\t' '{print $1;}'").toString();
+ }
+ setTimeout(function() {updateTotalStorageUsed();}, 120000); // update the used storage each 120 seconds
+}
// CREATE OUR SERVER EXPRESS APP
@@ -271,7 +283,7 @@ app.put('/backend/post_upload', bodyParser.raw({ inflate: true, limit: '100000kb
// DRIVE & BOOT/CRASH LOG FILE UPLOAD URL REQUEST
app.get('/v1.3/:dongleId/upload_url/', (req, res) => {
- var path = req.query.path; // todo: validate filename
+ var path = req.query.path;
logger.info("HTTP.UPLOAD_URL called for "+req.params.dongleId+" and file "+path+": "+JSON.stringify(req.headers));
var device = db.get('devices').find({ dongle_id: req.params.dongleId});
@@ -425,7 +437,7 @@ app.post('/v2/pilotauth/', bodyParser.urlencoded({ extended: true }), (req, res)
var device = db.get('devices').find({dongle_id: dongleId}).value();
if (!device) {
var resultingDevice = db.get('devices')
- .push({ dongle_id: dongleId, account_id: 0, imei: imei1, serial: serial, device_type: 'freon', public_key: public_key, created: Date.now(), last_ping: Date.now()})
+ .push({ dongle_id: dongleId, account_id: 0, imei: imei1, serial: serial, device_type: 'freon', public_key: public_key, created: Date.now(), last_ping: Date.now(), storage_used: 0})
.write();
var device = db.get('devices').find({dongle_id: dongleId}).value();
@@ -529,12 +541,6 @@ app.get('/useradmin', (req, res) => {
return;
}
- var verifiedPath = mkDirByPathSync(config.storagePath, {isRelativeToScript: (config.storagePath.indexOf("/")===0 ? false : true)});
- if (verifiedPath!==null) {
- const execSync = require('child_process').execSync;
- bytes = execSync("du -hs "+verifiedPath+" | awk -F'\t' '{print $1;}'").toString();
- }
-
res.status(200);
res.send('