2022-01-08 09:31:58 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const { stream: gotStream } = require('got')
|
|
|
|
const unzip = require('extract-zip')
|
2022-01-25 09:10:43 +00:00
|
|
|
const { basename, join, parse: pathParse } = require('path')
|
2022-01-11 06:23:08 +00:00
|
|
|
const { mkdir } = require('fs/promises')
|
2022-01-08 09:31:58 +00:00
|
|
|
const { createWriteStream } = require('fs')
|
|
|
|
const { pipeline } = require('stream/promises')
|
2022-01-25 09:10:43 +00:00
|
|
|
const envVar = process.env
|
2022-01-08 09:31:58 +00:00
|
|
|
|
|
|
|
const rootPath = join(__dirname, '..')
|
|
|
|
const tmpPath = join(rootPath, 'tmp')
|
2022-01-25 09:10:43 +00:00
|
|
|
const publicPath = join(rootPath, 'public')
|
2022-01-11 06:23:08 +00:00
|
|
|
const artifacts = {
|
|
|
|
'https://gitlab.com/curben/urlhaus-filter/-/jobs/artifacts/main/download?job=pages': 'urlhaus-filter.zip',
|
|
|
|
'https://gitlab.com/curben/phishing-filter/-/jobs/artifacts/main/download?job=pages': 'phishing-filter.zip',
|
|
|
|
'https://gitlab.com/curben/pup-filter/-/jobs/artifacts/main/download?job=pages': 'pup-filter.zip',
|
|
|
|
'https://gitlab.com/curben/tracking-filter/-/jobs/artifacts/main/download?job=pages': 'tracking-filter.zip'
|
|
|
|
}
|
2022-01-25 09:10:43 +00:00
|
|
|
const ghMirror = {
|
|
|
|
'urlhaus-filter': 'https://nightly.link/curbengh/urlhaus-filter/workflows/pages/main/public.zip',
|
|
|
|
'phishing-filter': 'https://nightly.link/curbengh/phishing-filter/workflows/pages/main/public.zip',
|
|
|
|
'pup-filter': 'https://nightly.link/curbengh/pup-filter/workflows/pages/main/public.zip',
|
|
|
|
'tracking-filter': 'https://nightly.link/curbengh/tracking-filter/workflows/pages/main/public.zip'
|
|
|
|
}
|
|
|
|
const oisdFilters = {
|
|
|
|
'https://abp.oisd.nl/basic/': 'oisd_abp_light.txt',
|
|
|
|
'https://abp.oisd.nl/': 'oisd_abp.txt',
|
|
|
|
'https://dbl.oisd.nl/basic/': 'oisd_dbl_light.txt',
|
|
|
|
'https://dbl.oisd.nl/': 'oisd_dbl.txt',
|
|
|
|
'https://dblw.oisd.nl/': 'oisd_dblw_light.txt',
|
|
|
|
'https://dblw.oisd.nl/basic/': 'oisd_dblw.txt',
|
|
|
|
'https://hosts.oisd.nl/basic/': 'oisd_hosts_light.txt',
|
|
|
|
'https://hosts.oisd.nl/': 'oisd_hosts.txt',
|
|
|
|
'https://dnsmasq.oisd.nl/basic/': 'oisd_dnsmasq_light.txt',
|
|
|
|
'https://dnsmasq.oisd.nl/': 'oisd_dnsmasq.txt',
|
|
|
|
'https://rpz.oisd.nl/basic/': 'oisd_rpz_light.txt',
|
|
|
|
'https://rpz.oisd.nl/': 'oisd_rpz.txt',
|
|
|
|
}
|
2022-01-08 09:31:58 +00:00
|
|
|
|
2022-01-11 06:23:08 +00:00
|
|
|
const dl = async (link, filename) => {
|
|
|
|
const zipPath = join(tmpPath, filename)
|
2022-01-25 09:10:43 +00:00
|
|
|
let isMirror = false
|
|
|
|
|
2022-01-11 06:23:08 +00:00
|
|
|
console.log(`Downloading ${filename} from "${link}"`)
|
|
|
|
try {
|
|
|
|
await pipeline(
|
|
|
|
gotStream(link),
|
|
|
|
createWriteStream(zipPath)
|
|
|
|
)
|
|
|
|
} catch ({ message }) {
|
2022-01-25 09:10:43 +00:00
|
|
|
console.error(JSON.stringify({
|
2022-01-11 06:23:08 +00:00
|
|
|
error: message,
|
|
|
|
link,
|
|
|
|
filename
|
|
|
|
}))
|
2022-01-25 09:10:43 +00:00
|
|
|
|
|
|
|
const mirrorLink = ghMirror[pathParse(filename).name]
|
|
|
|
console.log(`Downloading ${filename} from "${mirrorLink}"`)
|
|
|
|
isMirror = true
|
|
|
|
|
|
|
|
try {
|
|
|
|
await pipeline(
|
|
|
|
gotStream(mirrorLink),
|
|
|
|
createWriteStream(zipPath)
|
|
|
|
)
|
|
|
|
} catch ({ message }) {
|
|
|
|
throw new Error(JSON.stringify({
|
|
|
|
error: message,
|
|
|
|
link: mirrorLink,
|
|
|
|
filename
|
|
|
|
}))
|
|
|
|
}
|
2022-01-11 06:23:08 +00:00
|
|
|
}
|
2022-01-08 09:31:58 +00:00
|
|
|
|
2022-01-11 06:23:08 +00:00
|
|
|
console.log(`Extracting ${basename(zipPath)}...`)
|
2022-01-25 09:10:43 +00:00
|
|
|
if (isMirror === false) {
|
|
|
|
await unzip(zipPath, { dir: rootPath })
|
|
|
|
} else {
|
|
|
|
await unzip(zipPath, { dir: publicPath })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const oisdDl = async (link, filename) => {
|
|
|
|
const txtPath = join(publicPath, filename)
|
|
|
|
console.log(`Downloading ${filename} from "${link}"`)
|
|
|
|
try {
|
|
|
|
await pipeline(
|
|
|
|
gotStream(link),
|
|
|
|
createWriteStream(txtPath)
|
|
|
|
)
|
|
|
|
} catch ({ message }) {
|
|
|
|
console.error(JSON.stringify({
|
|
|
|
error: message,
|
|
|
|
link,
|
|
|
|
filename
|
|
|
|
}))
|
|
|
|
}
|
2022-01-11 06:23:08 +00:00
|
|
|
}
|
2022-01-08 22:12:56 +00:00
|
|
|
|
2022-01-11 06:23:08 +00:00
|
|
|
const f = async () => {
|
|
|
|
await mkdir(tmpPath, { recursive: true })
|
2022-01-25 09:10:43 +00:00
|
|
|
await mkdir(publicPath, { recursive: true })
|
2022-01-11 06:23:08 +00:00
|
|
|
await Promise.all(Object.entries(artifacts).map(([link, filename]) => { return dl(link, filename) }))
|
2022-01-08 09:31:58 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 09:10:43 +00:00
|
|
|
const oisd = async () => {
|
|
|
|
await mkdir(publicPath, { recursive: true })
|
|
|
|
if (Object.prototype.hasOwnProperty.call(envVar, 'CI_PROJECT_PATH') && envVar.CI_PROJECT_PATH === 'curben/malware-filter') {
|
|
|
|
await Promise.all(Object.entries(oisdFilters).map(([link, filename]) => { return oisdDl(link, filename) }))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 09:31:58 +00:00
|
|
|
f()
|
2022-01-25 09:10:43 +00:00
|
|
|
oisd()
|