-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
69 lines (56 loc) · 1.6 KB
/
main.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require('dotenv').config({ path: process.env.DOTENV_FILE_PATH || './.env' })
const { logger } = require('./logger.js')
const Browser = require('./browser.js')
const { CronJob } = require('cron')
const blackList = process.env.BLACK_LIST.split(',')
let activationJob, deActivationJob
const activateFilter = async () => {
logger.log('info', "activating filter")
let b = new Browser({
wifiCreds: {
username: process.env.WIFI_ADMIN_USERNAME,
pwd: process.env.WIFI_ADMIN_PASSWORD
}
}, blackList)
await b.launch()
await b.newWifiPage()
await b.wifiPageActivateFilter()
await b.close()
}
const deactivateFilter = async () => {
logger.log('info', "deactivating filter")
let b = new Browser({
wifiCreds: {
username: process.env.WIFI_ADMIN_USERNAME,
pwd: process.env.WIFI_ADMIN_PASSWORD
}
}, blackList)
await b.launch()
await b.newWifiPage()
await b.wifiPageDeactivateFilter()
await b.close()
}
const main = () => {
logger.log('info', "started program")
activationJob = new CronJob('0 0 23 * * *', activateFilter, null, true)
deActivationJob = new CronJob('0 0 7 * * *', deactivateFilter, null, true)
activationJob.start()
deActivationJob.start()
if (process.env.LAUNCH_ACTIVATION) {
activateFilter()
}
else if (process.env.LAUNCH_DEACTIVATION) {
deactivateFilter()
}
}
process.once('SIGINT', (code) => {
logger.log('info', "Stop signal received.")
})
process.once('SIGTERM', (code) => {
logger.log('info', "Stop signal received.")
})
process.on('uncaughtException', (err, origin) => {
logger.error(err.message)
process.exit(1)
})
main()