2022-01-08 09:31:58 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const { stream: gotStream } = require('got')
|
2022-03-19 05:33:26 +00:00
|
|
|
const got = require('got')
|
2022-01-08 09:31:58 +00:00
|
|
|
const unzip = require('extract-zip')
|
2022-03-20 06:51:12 +00:00
|
|
|
const { basename, join } = 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-03-19 05:33:26 +00:00
|
|
|
const projects = [
|
|
|
|
'urlhaus-filter',
|
|
|
|
'phishing-filter',
|
|
|
|
'pup-filter',
|
2022-03-20 06:51:12 +00:00
|
|
|
'tracking-filter',
|
|
|
|
'vn-badsite-filter'
|
2022-03-19 05:33:26 +00:00
|
|
|
]
|
2022-01-25 09:10:43 +00:00
|
|
|
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-03-19 05:33:26 +00:00
|
|
|
const pipelineStatus = async (url) => {
|
|
|
|
try {
|
|
|
|
const svg = await got(url).text()
|
|
|
|
if (!svg.includes('passed')) throw new Error('last gitlab pipeline failed')
|
|
|
|
} catch ({ message }) {
|
|
|
|
throw new Error(message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const dl = async (project) => {
|
|
|
|
const filename = project + '.zip'
|
|
|
|
const link = `https://gitlab.com/curben/${project}/-/jobs/artifacts/main/download?job=pages`
|
2022-01-11 06:23:08 +00:00
|
|
|
const zipPath = join(tmpPath, filename)
|
2022-03-19 05:33:26 +00:00
|
|
|
const pipelineUrl = `https://gitlab.com/curben/${project}/badges/main/pipeline.svg`
|
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)
|
|
|
|
)
|
2022-03-19 05:33:26 +00:00
|
|
|
await pipelineStatus(pipelineUrl)
|
2022-01-11 06:23:08 +00:00
|
|
|
} 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
|
|
|
|
2022-03-19 05:33:26 +00:00
|
|
|
const mirrorLink = `https://nightly.link/curbengh/${project}/workflows/pages/main/public.zip`
|
2022-01-25 09:10:43 +00:00
|
|
|
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-03-19 05:33:26 +00:00
|
|
|
await Promise.all(projects.map((project) => { return dl(project) }))
|
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()
|