Add notes and ASN name display to asn blocking map

dev
Thomas Lynch 8 months ago
parent 87cb5f0c67
commit dde5a337f6
  1. 9
      components/MapRow.js
  2. 36
      controllers/maps.js
  3. 85909
      maps/asn.json
  4. 85906
      maps/asn.map
  5. 18
      maps/asn.mjs
  6. 5
      maps/asn.sh
  7. 9
      pages/map/[name].js
  8. 3
      util.js

@ -1,4 +1,6 @@
export default function MapRow({ row, onDeleteSubmit, name, csrf, showValues, mapValueNames, columnKeys }) {
import asnMap from '../maps/asn.json';
export default function MapRow({ row, onDeleteSubmit, name, csrf, showValues, mapValueNames, columnKeys, mapNote }) {
const { _id, key, value } = row;
@ -13,8 +15,11 @@ export default function MapRow({ row, onDeleteSubmit, name, csrf, showValues, ma
</a>
</td>
<td>
{key}
{key}{name === 'blockedasn' && asnMap[key] && ` (${asnMap[key]})`}
</td>
{mapNote && <td>
{mapNote}
</td>}
{typeof value === 'string' && showValues === true && (
<td>
{mapValueNames[value] || value}

@ -1,5 +1,6 @@
import { extractMap, dynamicResponse } from '../util.js';
import { createCIDR, parse } from 'ip6addr';
import * as db from '../db.js';
import url from 'url';
import countries from 'i18n-iso-countries';
const countryMap = countries.getAlpha2Codes();
@ -19,8 +20,17 @@ const continentMap = {
export async function mapData(req, res, next) {
let map,
mapInfo,
showValues = false;
showValues = false,
mapNotes = {};
try {
mapNotes = await db.db().collection('mapnotes').find({
username: res.locals.user.username,
map: req.params.name
}).toArray();
mapNotes = mapNotes.reduce((acc, note) => {
acc[note.key] = note.note;
return acc;
}, {});
mapInfo = await res.locals
.dataPlaneRetry('getOneRuntimeMap', req.params.name)
.then(res => res.data)
@ -80,6 +90,7 @@ export async function mapData(req, res, next) {
return dynamicResponse(req, res, 400, { error: 'Invalid map' });
}
return {
mapValueNames: { '0': 'None', '1': 'Proof-of-work', '2': 'Proof-of-work+Captcha' },
mapInfo,
@ -87,6 +98,7 @@ export async function mapData(req, res, next) {
csrf: req.csrfToken(),
name: req.params.name,
showValues,
mapNotes,
};
}
@ -106,9 +118,12 @@ export async function mapJson(req, res, next) {
* Delete the map entries of the body 'domain'
*/
export async function deleteMapForm(req, res, next) {
if(!req.body || !req.body.key || typeof req.body.key !== 'string' || req.body.key.length === 0) {
if (!req.body || !req.body.key || typeof req.body.key !== 'string' || req.body.key.length === 0) {
return dynamicResponse(req, res, 400, { error: 'Invalid value' });
}
if (req.body && req.body.note && (typeof req.body.note !== 'string' || req.body.note.length > 200)) {
return dynamicResponse(req, res, 400, { error: 'Invalid note' });
}
if (req.params.name === process.env.BLOCKED_IP_MAP_NAME
|| req.params.name === process.env.BLOCKED_ASN_MAP_NAME
@ -198,6 +213,11 @@ export async function deleteMapForm(req, res, next) {
return next(e);
}
}
await db.db().collection('mapnotes').deleteMany({
username: res.locals.user.username,
map: req.params.name,
key: req.body.key,
});
return dynamicResponse(req, res, 302, { redirect: `/map/${req.params.name}` });
}
@ -462,6 +482,18 @@ export async function patchMapForm(req, res, next) {
value: value,
}]);
}
await db.db().collection('mapnotes').replaceOne({
username: res.locals.user.username,
map: req.params.name,
key: req.body.key,
}, {
username: res.locals.user.username,
map: req.params.name,
key: req.body.key,
note: req.body.note,
}, {
upsert: true,
});
return dynamicResponse(req, res, 302, { redirect: req.body.onboarding ? '/onboarding' : `/map/${req.params.name}` });
} catch (e) {
return next(e);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,18 @@
import { readFileSync, writeFileSync } from 'fs';
const data = readFileSync('./asn.map', { encoding: 'utf8', flag: 'r' });
const lines = data.split('\n');
const asnMap = lines.reduce((acc, line) => {
const split = line.split(',');
const asn = split.shift();
let name = split.join(',');
if (name.startsWith('"')) {
name = name
.substring(1, name.length-1)
.replaceAll('""', '"');
}
acc[asn] = name;
return acc;
}, {});
writeFileSync('./asn.json', JSON.stringify(asnMap, null, '\t'));

@ -0,0 +1,5 @@
#!/bin.bash
wget -O asn-ipv4.csv https://cdn.jsdelivr.net/npm/@ip-location-db/asn/asn-ipv4.csv
wget -O asn-ipv6.csv https://cdn.jsdelivr.net/npm/@ip-location-db/asn/asn-ipv6.csv
cat asn-ipv* | cut -d ',' -f 3- | sort | uniq > asn.map
rm *.csv

@ -52,7 +52,7 @@ const MapPage = (props) => {
);
}
const { user, mapValueNames, mapInfo, map, csrf, showValues } = state;
const { user, mapValueNames, mapInfo, map, csrf, showValues, mapNotes } = state;
if (user && !user.onboarding) {
router.push('/onboarding');
@ -65,6 +65,7 @@ const MapPage = (props) => {
//general maps
key: e.target.key.value,
value: e.target.value?.value,
note: e.target.note?.value,
//ddos_config
pd: e.target.pd?.value,
pt: e.target.pt?.value,
@ -101,6 +102,7 @@ const MapPage = (props) => {
showValues={showValues}
mapValueNames={mapValueNames}
onDeleteSubmit={deleteFromMap}
mapNote={mapNotes[row.key]}
columnKeys={mapInfo.columnKeys}
/>
);
@ -267,6 +269,9 @@ const MapPage = (props) => {
<td>
<input className='form-control' type='text' name='key' placeholder='ASN' required />
</td>
<td>
<input className='form-control' type='text' name='note' placeholder='Note' />
</td>
</>
);
break;
@ -409,7 +414,7 @@ const MapPage = (props) => {
<th>
{mapInfo.columnNames[0]}
</th>
{showValues === true && mapInfo.columnNames.slice(1).map((x, mci) => (
{(showValues === true || mapInfo.showAllColumns === true) && mapInfo.columnNames.slice(1).map((x, mci) => (
<th key={`mci_${mci}`}>
{x}
</th>

@ -39,7 +39,8 @@ const fMap = {
[process.env.BLOCKED_ASN_MAP_NAME]: {
fname: 'ASN Blacklist',
description: 'ASNs that are outright blocked',
columnNames: ['AS Number', ''],
columnNames: ['AS Number', 'Note'],
showAllColumns: true,
},
[process.env.BLOCKED_CC_MAP_NAME]: {

Loading…
Cancel
Save