Impliment blocklist logic and db. TODO: Add web UI
This commit is contained in:
parent
3f0ff73d59
commit
2594a7a8f7
22
index.js
22
index.js
|
|
@ -1071,6 +1071,23 @@ const genCall = (req, res, apiKey, ani, number) => {
|
|||
|
||||
conn.query('SELECT * FROM routes WHERE block_start <= ? AND block_start + block_length >= ?', [number, number]).then((rows) => {
|
||||
const row = rows[0];
|
||||
|
||||
// Check blocklist. Type 1 is exact match, Type 2 is prefix match NNNXXXX where NNN is the prefix value.
|
||||
// Check if the ANI is blocked from calling this route
|
||||
const routeId = row ? row.id : null;
|
||||
if (!routeId) {
|
||||
res.status(404).send(`${process.env.MSG_ROUTE_ADDRESS}/404`);
|
||||
return;
|
||||
}
|
||||
|
||||
conn.query('SELECT * FROM blocklist WHERE (blockType = 1 AND blockValue = ?) OR (blockType = 2 AND ? BETWEEN blockValue AND blockValue + ?);', [ani, ani, row.block_length]).then((blockRows) => {
|
||||
if (blockRows.length > 0) {
|
||||
// ANI is blocked from calling this route
|
||||
console.log(`Blocked Call Attempt: ${ani} -> ${number}`);
|
||||
res.status(403).send(`${process.env.MSG_ROUTE_ADDRESS}/403`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (row) {
|
||||
// Check if the ANI is within the block range
|
||||
// If it is, return `local`
|
||||
|
|
@ -1087,6 +1104,11 @@ const genCall = (req, res, apiKey, ani, number) => {
|
|||
} else {
|
||||
res.status(404).send(`${process.env.MSG_ROUTE_ADDRESS}/404`);
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('Error checking blocklist:', err);
|
||||
res.status(500).send(`${process.env.MSG_ROUTE_ADDRESS}/500`);
|
||||
return;
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error('Error getting route:', err);
|
||||
res.status(500).send(`${process.env.MSG_ROUTE_ADDRESS}/500`)
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ function runMigrations(pool) {
|
|||
resolve();
|
||||
})
|
||||
.catch(err => {
|
||||
console.errorr('Error running migrations:', err);
|
||||
console.error('Error running migrations:', err);
|
||||
reject(err);
|
||||
})
|
||||
.finally(() => {
|
||||
|
|
|
|||
8
migrations/010_add_blocklist_table.sql
Normal file
8
migrations/010_add_blocklist_table.sql
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CREATE TABLE IF NOT EXISTS blocklist (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
ownerId INT NOT NULL,
|
||||
blockType INT NOT NULL,
|
||||
blockValue VARCHAR(255) NOT NULL,
|
||||
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (ownerId) REFERENCES routes(id) ON DELETE CASCADE
|
||||
);
|
||||
Loading…
Reference in a new issue