Compare commits
2 commits
3f0ff73d59
...
da5a029161
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da5a029161 | ||
|
|
2594a7a8f7 |
24
index.js
24
index.js
|
|
@ -831,7 +831,7 @@ app.post('/api/v1/user/dir/massUpdate', async (req, res) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(replace) {
|
if (replace) {
|
||||||
// Delete all existing entries for this route
|
// Delete all existing entries for this route
|
||||||
await pool.query('DELETE FROM directory WHERE route = ?', [route.id]);
|
await pool.query('DELETE FROM directory WHERE route = ?', [route.id]);
|
||||||
}
|
}
|
||||||
|
|
@ -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) => {
|
conn.query('SELECT * FROM routes WHERE block_start <= ? AND block_start + block_length >= ?', [number, number]).then((rows) => {
|
||||||
const row = rows[0];
|
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) {
|
if (row) {
|
||||||
// Check if the ANI is within the block range
|
// Check if the ANI is within the block range
|
||||||
// If it is, return `local`
|
// If it is, return `local`
|
||||||
|
|
@ -1087,6 +1104,11 @@ const genCall = (req, res, apiKey, ani, number) => {
|
||||||
} else {
|
} else {
|
||||||
res.status(404).send(`${process.env.MSG_ROUTE_ADDRESS}/404`);
|
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 => {
|
}).catch(err => {
|
||||||
console.error('Error getting route:', err);
|
console.error('Error getting route:', err);
|
||||||
res.status(500).send(`${process.env.MSG_ROUTE_ADDRESS}/500`)
|
res.status(500).send(`${process.env.MSG_ROUTE_ADDRESS}/500`)
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ function runMigrations(pool) {
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.errorr('Error running migrations:', err);
|
console.error('Error running migrations:', err);
|
||||||
reject(err);
|
reject(err);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.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