mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-14 01:37:48 -05:00
Add system authorization check function.
This commit is contained in:
@@ -144,3 +144,37 @@ exports.get_systems = async function (req, res) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.authorize_system = async function (req, res) {
|
||||||
|
|
||||||
|
var shortName = req.params.shortName.toLowerCase();
|
||||||
|
var apiKey = req.body.api_key;
|
||||||
|
let item = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
item = await System.findOne({ 'shortName': shortName }, ["key"]);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("[" + req.params.shortName + "] Error /:shortName/authorize - Error: " + err);
|
||||||
|
res.status(500);
|
||||||
|
res.send("Invalid System Name\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!item) {
|
||||||
|
console.info("[" + req.params.shortName + "] Error /:shortName/authorize ShortName does not exist");
|
||||||
|
res.status(500);
|
||||||
|
res.send("Invalid System Name\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiKey != item.key) {
|
||||||
|
console.warn("[" + req.params.shortName + "] Error /:shortName/authorize API Key Mismatch - Provided key: " + apiKey);
|
||||||
|
res.status(403);
|
||||||
|
res.send("Invalid API Key\n");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// System shortName exists and the API Key is valid.
|
||||||
|
res.status(200).end();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ app.post('/:shortName/upload', upload.single('call'), uploads.upload, async func
|
|||||||
/*------ SYSTEMS ----------*/
|
/*------ SYSTEMS ----------*/
|
||||||
app.get('/systems', addSystemClients, systems.get_systems);
|
app.get('/systems', addSystemClients, systems.get_systems);
|
||||||
app.post('/:shortName/contact', systems.contact_system);
|
app.post('/:shortName/contact', systems.contact_system);
|
||||||
|
app.post('/:shortName/authorize', systems.authorize_system);
|
||||||
|
|
||||||
/*------ TALKGROUPS ----------*/
|
/*------ TALKGROUPS ----------*/
|
||||||
app.get('/:shortName/talkgroups', talkgroups.get_talkgroups);
|
app.get('/:shortName/talkgroups', talkgroups.get_talkgroups);
|
||||||
|
|||||||
Reference in New Issue
Block a user