#!/bin/bash

gh api https://api.github.com/repos/curbengh/urlhaus-filter/contents/urlhaus-filter-dnscrypt-blocked-names-online.txt?ref=gh-pages -H "Accept: application/vnd.github.raw" | sed -e 's/^\(|\|@\|\*\|\.\|\-\|0\.0\.0\.0\|127\.0\.0\.1\)*//g' -e 's/\^.*$//g' -e '/!\|?\|@\|#\|\*\|_\|\\\|\/\|\[\|]\|\[\|\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/d' -e '/\.$/d' -e '/^\s*$/d' | awk '{$1=$1};1' | dos2unix | idn2 --no-alabelroundtrip --no-tr46 | LC_ALL=C sort -u > malware-temp.txt
gh api https://api.github.com/repos/curbengh/urlhaus-filter/contents/urlhaus-filter-dnscrypt-blocked-ips-online.txt?ref=gh-pages -H "Accept: application/vnd.github.raw" | sed -e '/#/d' -e '/^$/d' > malware-ip.txt
[[ -s malware-ip.txt ]] || gh api https://api.github.com/repos/Chocolate4U/Iran-v2ray-rules/contents/text/malware.txt?ref=release -H "Accept: application/vnd.github.raw" > malware-ip.txt
sed -e 's/^/\./' -e 's/\./\\./g' -e 's/\-/\\-/g' -e 's/$/\$/' malware-temp.txt > malware-sub.txt
cat malware-temp.txt | LC_ALL=C grep -f malware-sub.txt | LC_ALL=C sort -u > malware-redundant-sub.txt
comm -23 malware-temp.txt malware-redundant-sub.txt > malware.txt
mv malware.txt domains
