-
-
Save LeiHao0/4a4235df0fb97d559f9876eab0ebb5a4 to your computer and use it in GitHub Desktop.
// https://github.com/AdguardTeam/AdGuardHome/blob/master/openapi/openapi.yaml | |
old_blist = []; | |
blist = [ | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts", | |
"https://v.firebog.net/hosts/static/w3kbl.txt", | |
"https://raw.githubusercontent.com/matomo-org/referrer-spam-blacklist/master/spammers.txt", | |
"https://someonewhocares.org/hosts/zero/hosts", | |
"https://raw.githubusercontent.com/VeleSila/yhosts/master/hosts", | |
"https://winhelp2002.mvps.org/hosts.txt", | |
"https://v.firebog.net/hosts/neohostsbasic.txt", | |
"https://raw.githubusercontent.com/RooneyMcNibNug/pihole-stuff/master/SNAFU.txt", | |
"https://paulgb.github.io/BarbBlock/blacklists/hosts-file.txt", | |
"https://adaway.org/hosts.txt", | |
"https://v.firebog.net/hosts/AdguardDNS.txt", | |
"https://v.firebog.net/hosts/Admiral.txt", | |
"https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt", | |
"https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt", | |
"https://v.firebog.net/hosts/Easylist.txt", | |
"https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts", | |
"https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts", | |
"https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts", | |
"https://v.firebog.net/hosts/Easyprivacy.txt", | |
"https://v.firebog.net/hosts/Prigent-Ads.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts", | |
"https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt", | |
"https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt", | |
"https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/android-tracking.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/AmazonFireTV.txt", | |
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt", | |
"https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt", | |
"https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt", | |
"https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt", | |
"https://v.firebog.net/hosts/Prigent-Crypto.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts", | |
"https://bitbucket.org/ethanr/dns-blacklists/raw/8575c9f96e5b4a1308f2f12394abd86d0927a4a0/bad_lists/Mandiant_APT1_Report_Appendix_D.txt", | |
"https://phishing.army/download/phishing_army_blocklist_extended.txt", | |
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt", | |
"https://v.firebog.net/hosts/RPiList-Malware.txt", | |
"https://v.firebog.net/hosts/RPiList-Phishing.txt", | |
"https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt", | |
"https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts", | |
"https://urlhaus.abuse.ch/downloads/hostfile/", | |
"https://malware-filter.gitlab.io/malware-filter/phishing-filter-hosts.txt", | |
"https://v.firebog.net/hosts/Prigent-Malware.txt", | |
"https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser", | |
]; | |
alist = [ | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt", | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt", | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt", | |
]; | |
url = "http://127.0.0.1/control/filtering/"; | |
function updateList(list, mode) { | |
path = mode == "rm" ? "remove_url" : "add_url"; | |
whitelist = mode == "whitelist" ? true : false; | |
for (i in list) { | |
l = list[i]; | |
fetch(url + path, { | |
method: "POST", | |
body: | |
mode == "rm" | |
? JSON.stringify({ | |
url: l, | |
whitelist: whitelist, | |
}) | |
: JSON.stringify({ | |
name: l.substr(-10), | |
url: l, | |
whitelist: whitelist, | |
}), | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
}) | |
.then((response) => response.text()) | |
.then((data) => console.log(data)); | |
} | |
} | |
updateList(old_blist, "rm"); | |
updateList(blist, "add"); | |
updateList(alist, "whitelist"); |
from requests.adapters import HTTPAdapter | |
from requests.packages.urllib3.poolmanager import PoolManager | |
import ssl | |
import requests | |
import json | |
## CHANGE HERE ## | |
# ip address of AdGuard Home | |
# "http(s)://<adguardHomeIp:<port>" | |
host = "http://192.168.2.2:80" | |
proxies = { | |
"http": "http://127.0.0.1:7890", | |
"https": "http://127.0.0.1:7890", | |
} | |
# user name | |
userName = "" | |
# password | |
password = "" | |
# block list | |
# taken from Wally3K's Firebog https://firebog.net/ | |
urls = [ | |
"https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts", | |
"https://v.firebog.net/hosts/static/w3kbl.txt", | |
"https://raw.githubusercontent.com/matomo-org/referrer-spam-blacklist/master/spammers.txt", | |
"https://someonewhocares.org/hosts/zero/hosts", | |
"https://raw.githubusercontent.com/VeleSila/yhosts/master/hosts", | |
"https://winhelp2002.mvps.org/hosts.txt", | |
"https://v.firebog.net/hosts/neohostsbasic.txt", | |
"https://raw.githubusercontent.com/RooneyMcNibNug/pihole-stuff/master/SNAFU.txt", | |
"https://paulgb.github.io/BarbBlock/blacklists/hosts-file.txt", | |
"https://adaway.org/hosts.txt", | |
"https://v.firebog.net/hosts/AdguardDNS.txt", | |
"https://v.firebog.net/hosts/Admiral.txt", | |
"https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt", | |
"https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt", | |
"https://v.firebog.net/hosts/Easylist.txt", | |
"https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts", | |
"https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts", | |
"https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts", | |
"https://v.firebog.net/hosts/Easyprivacy.txt", | |
"https://v.firebog.net/hosts/Prigent-Ads.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts", | |
"https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt", | |
"https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt", | |
"https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/android-tracking.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV.txt", | |
"https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/AmazonFireTV.txt", | |
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt", | |
"https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt", | |
"https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt", | |
"https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt", | |
"https://v.firebog.net/hosts/Prigent-Crypto.txt", | |
"https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts", | |
"https://bitbucket.org/ethanr/dns-blacklists/raw/8575c9f96e5b4a1308f2f12394abd86d0927a4a0/bad_lists/Mandiant_APT1_Report_Appendix_D.txt", | |
"https://phishing.army/download/phishing_army_blocklist_extended.txt", | |
"https://malware-filter.gitlab.io/malware-filter/phishing-filter-hosts.txt", | |
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt", | |
"https://v.firebog.net/hosts/RPiList-Malware.txt", | |
"https://v.firebog.net/hosts/RPiList-Phishing.txt", | |
"https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt", | |
"https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts", | |
"https://urlhaus.abuse.ch/downloads/hostfile/", | |
"https://v.firebog.net/hosts/Prigent-Malware.txt", | |
"https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser", | |
] | |
allow_urls = [ | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt", | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt", | |
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt", | |
] | |
############ End Edits ################# | |
# Open TLSv1 Adapter | |
class MyAdapter(HTTPAdapter): | |
def init_poolmanager(self, connections, maxsize, block=False): | |
self.poolmanager = PoolManager(num_pools=connections, | |
maxsize=maxsize, | |
block=block, | |
ssl_version=ssl.PROTOCOL_TLSv1) | |
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0', 'Content-Type':'application/json'} | |
s = requests.Session() | |
s.mount(host, MyAdapter()) | |
x = s.post(host + "/control/login", json.dumps({"name": userName, "password" : password}), headers=headers, proxies=proxies) | |
print(x.text) | |
for u in urls: | |
filterObj = json.dumps({'url':u, "name":u,"whitelist":False}) | |
print(filterObj) | |
x = s.post(host + "/control/filtering/add_url", data = filterObj, headers=headers) | |
print(x.text) | |
for u in allow_urls: | |
filterObj = json.dumps({'url':u, "name":u,"whitelist":True}) | |
print(filterObj) | |
x = s.post(host + "/control/filtering/add_url", data = filterObj, headers=headers) | |
print(x.text) | |
# help from | |
# https://stackoverflow.com/questions/30946370/using-requests-to-login-to-a-website-that-has-javascript-login-form | |
# https://stackoverflow.com/questions/33818206/python-login-into-a-website-with-javascript-form |
it was enough to modify the following line and the script started working again:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0', 'Content-Type':'application/json'}
Hi @vannimb, thank you for your commands. You can try the javascript version. It's more straightforward and can be executed with the chrome console.
Hello @LeiHao0, i tried from the chrome console as you suggested the items are added but i get the following error:
Uncaught (in promise) SyntaxError: Unexpected token 'F', "Filter URL"... is not valid JSON
should the js version be modiified for this latest adguard version?
@vannimb fixed.
the SyntaxError caused by AdGuardHome API response is a string
instead of a json
. This means the list still can be added in for the previous version.
Dear @LeiHao0 ,
thanks for your work, i find the gistfile1.py very useful!
apparently adguardhome had some recent chnages regarding the json requests that make your script not working...
Here the adguardhome changelog link: https://github.com/AdguardTeam/AdGuardHome/blob/master/CHANGELOG.md#v010714---2022-09-29
i get this kind of output with the current script version:
{"url": "https://urlhaus.abuse.ch/downloads/hostfile/", "name": "https://urlhaus.abuse.ch/downloads/hostfile/", "whitelist": false}
Forbidden
Would it be possible for you to update the gistfile1.py to make it work again?
many thanks