From e8caa8c592395161ef3fa40fe41794520294f905 Mon Sep 17 00:00:00 2001 From: LordJavi <20624591+LordJavi@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:33:04 +0200 Subject: [PATCH 01/13] not used --- src/routes/api.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/routes/api.js b/src/routes/api.js index afa945e..0e5fa12 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -22,23 +22,6 @@ const ScheduleManager = require('../models/schedule-manager.js'); const logger = require('../services/logger.js'); const utils = require('../services/utils.js'); -router.use(async (req, res, next) => { - if (req.path === '/api/login' || req.path === '/login' || - req.path === '/api/register' || req.path === '/register' || - req.path === '/config' || req.path === '/log/new') { - return next(); - } - if (!await Migrator.getValueForKey('SETUP')) { - res.redirect('/register'); - return; - } - if (req.session.loggedin) { - next(); - return; - } - res.redirect('/login'); -}); - router.post('/register', async (req, res) => { const isSetup = await Migrator.getValueForKey('SETUP'); if (isSetup) { From 7bd4e9b1532e23f7ba6de0281db11b2128c5cc2b Mon Sep 17 00:00:00 2001 From: LordJavi <20624591+LordJavi@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:34:08 +0200 Subject: [PATCH 02/13] Add download --- src/routes/api.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/routes/api.js b/src/routes/api.js index 0e5fa12..56b79c0 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -387,6 +387,15 @@ router.get('/configs', async (req, res) => { } }); +router.post('/download/:file', AuthTokenMiddleware, async (req, res) => { + const { uuid } = req.body; + const clientip = ((req.headers['x-forwarded-for'] || '').split(', ')[0]) || (req.connection.remoteAddress || req.connection.localAddress).match('[0-9]+.[0-9].+[0-9]+.[0-9]+$')[0]; + var filePath = 'downloads/' + req.params.file; + var fileName = req.params.file; + logger('dcm').info(`Client ${uuid} at ${clientip} is requesting ` + req.params.file); + res.download(filePath, fileName); +}); + router.post('/config', AuthTokenMiddleware, async (req, res) => { const { uuid, ios_version, ipa_version, model, webserver_port } = req.body; let device = await Device.getByName(uuid); From 051b152daa3de779696c36c0b759fff524efc827 Mon Sep 17 00:00:00 2001 From: LordJavi <20624591+LordJavi@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:35:12 +0200 Subject: [PATCH 03/13] Add api/download to login middleware --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e998caf..726490e 100644 --- a/src/index.js +++ b/src/index.js @@ -110,6 +110,7 @@ const run = async () => { app.use(async (req, res, next) => { if (req.path === '/api/login' || req.path === '/login' || req.path === '/api/register' || req.path === '/register' || + req.path.includes('/api/download') || req.path === '/api/config' || req.path == '/api/log/new') { return next(); } @@ -159,4 +160,4 @@ run().then(x => { console.log('Initialized'); }).catch(err => { console.error('Error:', err); -}); \ No newline at end of file +}); From 1fe8bf38e4f93492422b40daf7782390a61b310b Mon Sep 17 00:00:00 2001 From: LordJavi <20624591+LordJavi@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:36:39 +0200 Subject: [PATCH 04/13] Create .gitkeep --- static/files/.gitkeep | 1 + 1 file changed, 1 insertion(+) create mode 100644 static/files/.gitkeep diff --git a/static/files/.gitkeep b/static/files/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/static/files/.gitkeep @@ -0,0 +1 @@ + From 5484e7f089053469df8700718e4a56cd88e13469 Mon Sep 17 00:00:00 2001 From: LordJavi <20624591+LordJavi@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:37:34 +0200 Subject: [PATCH 05/13] ignore files --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f2d8947..52f3c7d 100644 --- a/.gitignore +++ b/.gitignore @@ -116,4 +116,7 @@ screenshots schedules.json # No docker-compose.yml -docker-compose.yml \ No newline at end of file +docker-compose.yml + +# No files +static/files/* From 2148a61be830d3d4d3e4c2dff5f10fdefe81ce4c Mon Sep 17 00:00:00 2001 From: LordJavi <20624591+LordJavi@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:38:23 +0200 Subject: [PATCH 06/13] Update download function --- src/routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/api.js b/src/routes/api.js index 56b79c0..b9ef062 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -390,7 +390,7 @@ router.get('/configs', async (req, res) => { router.post('/download/:file', AuthTokenMiddleware, async (req, res) => { const { uuid } = req.body; const clientip = ((req.headers['x-forwarded-for'] || '').split(', ')[0]) || (req.connection.remoteAddress || req.connection.localAddress).match('[0-9]+.[0-9].+[0-9]+.[0-9]+$')[0]; - var filePath = 'downloads/' + req.params.file; + var filePath = 'static/file/' + req.params.file; var fileName = req.params.file; logger('dcm').info(`Client ${uuid} at ${clientip} is requesting ` + req.params.file); res.download(filePath, fileName); From 37f1a1029eec0bf7e3205e08217c7b3546f46775 Mon Sep 17 00:00:00 2001 From: LordJavi <20624591+LordJavi@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:49:04 +0200 Subject: [PATCH 07/13] typo --- src/routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/api.js b/src/routes/api.js index b9ef062..b556fda 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -390,7 +390,7 @@ router.get('/configs', async (req, res) => { router.post('/download/:file', AuthTokenMiddleware, async (req, res) => { const { uuid } = req.body; const clientip = ((req.headers['x-forwarded-for'] || '').split(', ')[0]) || (req.connection.remoteAddress || req.connection.localAddress).match('[0-9]+.[0-9].+[0-9]+.[0-9]+$')[0]; - var filePath = 'static/file/' + req.params.file; + var filePath = 'static/files/' + req.params.file; var fileName = req.params.file; logger('dcm').info(`Client ${uuid} at ${clientip} is requesting ` + req.params.file); res.download(filePath, fileName); From d378a200d51ca74a2ce09927d40a35b6507f05d9 Mon Sep 17 00:00:00 2001 From: LordJavi <20624591+LordJavi@users.noreply.github.com> Date: Wed, 19 Apr 2023 09:51:28 +0200 Subject: [PATCH 08/13] Update settings.mustache --- src/views/settings.mustache | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/views/settings.mustache b/src/views/settings.mustache index a0023aa..b7f0638 100644 --- a/src/views/settings.mustache +++ b/src/views/settings.mustache @@ -19,6 +19,9 @@