Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Huawei B525s-23a router's 'Domain Name Filter' filler script that allows users to automatically fill Domain Name Filter table with values from a normal hostname list...
// Huawei B525s-23a router's 'Domain Name Filter' filler script that allows users to automatically fill Domain Name Filter table with values from a normal hostname list
/*
# Blacklist example:
abtest.mistat.intl.xiaomi.com
abtest.mistat.xiaomi.com
account.preview.n.xiaomi.net
account.xiaomi.com
ad1.xiaomi.com
ad.mi.com
*/
{
let blacklistToBody = (function() {
let processBlacklist = function(rawBlacklist) {
rawBlacklist = rawBlacklist.replace(/#.*/g, "").trim();
return rawBlacklist.split("\n");
};
let blacklistItem = function(hostname, status) {
return `<urlfilter><value>${hostname}</value><status>${status}</status></urlfilter>`;
};
return function(rawBlacklist) {
let blacklist = processBlacklist(rawBlacklist);
let xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
xmlString += "<request><urlfilters>";
for(let hostname of blacklist) {
xmlString += blacklistItem(hostname, 1);
}
xmlString += "</urlfilters></request>";
return xmlString;
};
})();
let fetchList = async function(list_url) {
let rawBlacklist = await fetch(list_url).then(res => res.text());
return rawBlacklist;
};
let updateDomainNameFilter = function(newBlackList) {
return fetch(`${window.location.origin}/api/security/url-filter`, {
"headers": {
"__requestverificationtoken": g_requestVerificationToken[0],
"_responsesource": "Broswer",
"accept": "*/*",
"accept-language": "en-US,en;q=0.9",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"x-requested-with": "XMLHttpRequest"
},
"referrer": `${window.location.origin}/html/urlfilter.html`,
"referrerPolicy": "strict-origin-when-cross-origin",
"body": newBlackList,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
};
(async function(blacklist_url) {
let rawBlacklist = await fetchList(blacklist_url);
let newBody = blacklistToBody(rawBlacklist);
updateDomainNameFilter(newBody);
})("https://gist.githubusercontent.com/unknownFalleN/3f38e2daa8a98caff1b0d965c2b89b25/raw/3ed194e607624682615c1273a1c98ec8980e379d/xiaomi_dns_block.lst");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment