-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
53 lines (43 loc) · 1.13 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { readFileSync } from 'fs'
import { parse } from 'yaml'
import { AbuseIPDB } from './src/Helpers/AbuseIPDB'
import IPtables from './src/Parsers/IPtables'
import { Config } from './src/types'
import { Error, Info, renameAndExit, writeStack } from './src/Utils/logger'
const config = parse(readFileSync('./Settings.yml', 'utf-8')) as Config
saveMySelf()
Info('Starting')
const abuseIPDB = new AbuseIPDB(config.AbuseIPDB.Key, config.AbuseIPDB.Categories)
switch (config.UseParser.toLowerCase()) {
case 'iptables': {
IPtables(abuseIPDB)
break
}
case 'pfsense': {
Error('Not implemented yet.')
break
}
default: {
Error('Invalid parser')
process.exit(0)
}
}
function saveMySelf (): void {
process.on('uncaughtException', (ex: Error) => {
Error('uncaughtException: %s', ex)
console.log(ex)
writeStack(ex)
})
process.on('unhandledRejection', (ex: Error) => {
Error('unhandledRejection: %s', ex)
console.log(ex)
writeStack(ex)
})
//* Rename the log when the app exits
process.on('SIGINT', () => {
renameAndExit()
})
process.on('SIGQUIT', () => {
renameAndExit()
})
}