Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DCM as dmon fileserver #103

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,7 @@ screenshots
schedules.json

# No docker-compose.yml
docker-compose.yml
docker-compose.yml

# No files
static/files/*
6 changes: 5 additions & 1 deletion src/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
"database": "dcm",
"charset": "utf8mb4"
},
"jailbreak": {
"pogo_version": "0",
"gc_version": "0"
}
"autoSyncIP": true
}
}
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/version.txt' ||
req.path === '/api/config' || req.path == '/api/log/new') {
return next();
}
Expand Down Expand Up @@ -159,4 +160,4 @@ run().then(x => {
console.log('Initialized');
}).catch(err => {
console.error('Error:', err);
});
});
38 changes: 21 additions & 17 deletions src/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -145,6 +128,10 @@ router.post('/settings/change', (req, res) => {
database: data.database,
charset: data.charset
};
newConfig.jailbreak = {
pogo_version: data.pogo_version,
gc_version: data.gc_version
};
fs.writeFileSync(path.resolve(__dirname, '../config.json'), JSON.stringify(newConfig, null, 4));
res.redirect('/settings');
});
Expand Down Expand Up @@ -404,6 +391,23 @@ 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/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);
});

router.get('/version.txt', AuthTokenMiddleware, async (req, res) => {
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];
// TODO: Do better
res.status(200)
.attachment(`version.txt`)
.send('gc: '+ config.jailbreak.gc_version +'\npogo: ' + config.jailbreak.pogo_version)
});

router.post('/config', AuthTokenMiddleware, async (req, res) => {
const { uuid, ios_version, ipa_version, model, webserver_port } = req.body;
let device = await Device.getByName(uuid);
Expand Down
2 changes: 2 additions & 0 deletions src/routes/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ router.get('/settings', (req, res) => {
data.logging = config.logging.enabled ? 'checked' : '';
data.max_size = config.logging.max_size;
data.log_format = config.logging.format || 'YYYY-MM-DD hh:mm:ss A';
data.gc_version = config.jailbreak.gc_version;
data.pogo_version = config.jailbreak.pogo_version;
res.render('settings', data);
});

Expand Down
22 changes: 22 additions & 0 deletions src/views/settings.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#logging">{{Logging}}</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#jailbreak">{{Jailbreak}}</a>
</li>
</ul>
<form action="/api/settings/change" method="post" novalidate>
<div class="tab-content">
Expand Down Expand Up @@ -158,6 +161,25 @@
</div>
</div>
<!-- End Logging Tab -->
<!-- Start Jailbreak Tab -->
<div class="tab-pane container" id="jailbreak">
<div class="card bg-dark p-1 m-3">
<div class="card-header text-center bg-dark"><b>{{Jailbreak}}</b></div>
<div class="card-body">
<div class="container">
<div class="form-group">
{{Pokémon GO version}}
<input type="number" class="form-control" name="pogo_version" value="{{pogo_version}}" placeholder="" required>
</div>
<div class="form-group">
{{GoCheats version}}
<input type="text" class="form-control" name="gc_version" value="{{gc_version}}" placeholder="" required>
</div>
</div>
</div>
</div>
</div>
<!-- End Jailbreak Tab -->
<br>
<div class="text-center">
<button type="submit" class="btn btn-primary">{{Save}}</button>
Expand Down
1 change: 1 addition & 0 deletions static/files/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@