-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69cfffc
commit c4d37be
Showing
6 changed files
with
147 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
__MACOSX | ||
.DS_Store | ||
/hosts | ||
__MACOSX | ||
.DS_Store | ||
/hosts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,78 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs').promises; | ||
const regexIp = new RegExp('^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)', 'i'); | ||
const saveDir = './'; | ||
const filename = 'hosts'; | ||
|
||
async function main() { | ||
const configObj = JSON.parse(await fs.readFile('config.json', 'utf8')); | ||
let blacks = []; | ||
let whites = []; | ||
for (const url of configObj.blackUrls) { | ||
const data = await fetchData(url); | ||
blacks = [...blacks, ...strToArray(data)]; | ||
} | ||
for (const url of configObj.whiteUrls) { | ||
const data = await fetchData(url); | ||
whites = [...whites, ...strToArray(data, false)]; | ||
} | ||
blacks = blacks.filter((el) => !whites.find(x => el.endsWith(x))); | ||
try { | ||
await fs.mkdir(saveDir, { recursive: true }); | ||
await fs.writeFile(saveDir + filename, blacks.join('\n')); | ||
console.log('Completed!'); | ||
} catch (e) { | ||
console.log('Error:', e.stack); | ||
} | ||
} | ||
|
||
async function fetchData(url) { | ||
const response = await fetch(url); | ||
if (response.status == 200) { | ||
return await response.text(); | ||
} else { | ||
throw new Error(`An error has occured: ${response.status}`); | ||
} | ||
} | ||
|
||
function strToArray(str, trimIp = false) { | ||
const array = str.split('\n'); | ||
const newArray = []; | ||
for (const item of array) { | ||
if (item.startsWith('#')) { | ||
continue; | ||
} | ||
let hostname = item.split('#')[0].trim().toLowerCase(); | ||
if (hostname === null || hostname === '') { | ||
continue; | ||
} | ||
if (trimIp && hasIP(hostname)) { | ||
hostname = removeIP(hostname); | ||
} | ||
if (!trimIp && !hasIP(hostname)) { | ||
hostname = appendIP(hostname); | ||
} | ||
if (hostname.endsWith('0.0.0.0') || hostname.endsWith('127.0.0.1')) { | ||
continue; | ||
} | ||
if (newArray.includes(hostname)) { | ||
continue; | ||
} | ||
newArray.push(hostname.replace(/^\./, '')); | ||
} | ||
return newArray; | ||
} | ||
|
||
function hasIP(ipaddress) { | ||
return regexIp.test(ipaddress) ? true : false; | ||
} | ||
|
||
function removeIP(str) { | ||
return str.replace(regexIp, '').trim(); | ||
} | ||
|
||
function appendIP(str) { | ||
return `0.0.0.0 ${str.trim()}`; | ||
} | ||
|
||
main(); | ||
#!/usr/bin/env node | ||
const fs = require('fs').promises; | ||
const regexIp = new RegExp('^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)', 'i'); | ||
const saveDir = './'; | ||
const filename = 'hosts'; | ||
|
||
async function main() { | ||
const configObj = JSON.parse(await fs.readFile('config.json', 'utf8')); | ||
let blacks = []; | ||
let whites = []; | ||
for (const url of configObj.blackUrls) { | ||
const data = await fetchData(url); | ||
blacks = [...blacks, ...strToArray(data)]; | ||
} | ||
for (const url of configObj.whiteUrls) { | ||
const data = await fetchData(url); | ||
whites = [...whites, ...strToArray(data, false)]; | ||
} | ||
blacks = blacks.filter((el) => !whites.find(x => el.endsWith(x))); | ||
try { | ||
await fs.mkdir(saveDir, { recursive: true }); | ||
await fs.writeFile(saveDir + filename, blacks.join('\n')); | ||
console.log('Completed!'); | ||
} catch (e) { | ||
console.log('Error:', e.stack); | ||
} | ||
} | ||
|
||
async function fetchData(url) { | ||
const response = await fetch(url); | ||
if (response.status == 200) { | ||
return await response.text(); | ||
} else { | ||
throw new Error(`An error has occured: ${response.status}`); | ||
} | ||
} | ||
|
||
function strToArray(str, trimIp = false) { | ||
const array = str.split('\n'); | ||
const newArray = []; | ||
for (const item of array) { | ||
if (item.startsWith('#')) { | ||
continue; | ||
} | ||
let hostname = item.split('#')[0].trim().toLowerCase(); | ||
if (hostname === null || hostname === '') { | ||
continue; | ||
} | ||
if (trimIp && hasIP(hostname)) { | ||
hostname = removeIP(hostname); | ||
} | ||
if (!trimIp && !hasIP(hostname)) { | ||
hostname = appendIP(hostname); | ||
} | ||
if (hostname.endsWith('0.0.0.0') || hostname.endsWith('127.0.0.1')) { | ||
continue; | ||
} | ||
if (newArray.includes(hostname)) { | ||
continue; | ||
} | ||
newArray.push(hostname.replace(/^\./, '')); | ||
} | ||
return newArray; | ||
} | ||
|
||
function hasIP(ipaddress) { | ||
return regexIp.test(ipaddress) ? true : false; | ||
} | ||
|
||
function removeIP(str) { | ||
return str.replace(regexIp, '').trim(); | ||
} | ||
|
||
function appendIP(str) { | ||
return `0.0.0.0 ${str.trim()}`; | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"blackUrls": [ | ||
"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" | ||
], | ||
"whiteUrls": [ | ||
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt", | ||
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt", | ||
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt" | ||
] | ||
{ | ||
"blackUrls": [ | ||
"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" | ||
], | ||
"whiteUrls": [ | ||
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt", | ||
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt", | ||
"https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
#!/sbin/sh | ||
|
||
################# | ||
# Initialization | ||
################# | ||
|
||
umask 022 | ||
|
||
# echo before loading util_functions | ||
ui_print() { echo "$1"; } | ||
|
||
require_new_magisk() { | ||
ui_print "*******************************" | ||
ui_print " Please install Magisk v20.4+! " | ||
ui_print "*******************************" | ||
exit 1 | ||
} | ||
|
||
######################### | ||
# Load util_functions.sh | ||
######################### | ||
|
||
OUTFD=$2 | ||
ZIPFILE=$3 | ||
|
||
mount /data 2>/dev/null | ||
|
||
[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk | ||
. /data/adb/magisk/util_functions.sh | ||
[ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk | ||
|
||
install_module | ||
#!/sbin/sh | ||
|
||
################# | ||
# Initialization | ||
################# | ||
|
||
umask 022 | ||
|
||
# echo before loading util_functions | ||
ui_print() { echo "$1"; } | ||
|
||
require_new_magisk() { | ||
ui_print "*******************************" | ||
ui_print " Please install Magisk v20.4+! " | ||
ui_print "*******************************" | ||
exit 1 | ||
} | ||
|
||
######################### | ||
# Load util_functions.sh | ||
######################### | ||
|
||
OUTFD=$2 | ||
ZIPFILE=$3 | ||
|
||
mount /data 2>/dev/null | ||
|
||
[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk | ||
. /data/adb/magisk/util_functions.sh | ||
[ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk | ||
|
||
install_module | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
#MAGISK | ||
#MAGISK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
#!/system/bin/sh | ||
MODDIR=${0%/*} | ||
UPDATER_FILE=./updater.sh | ||
CRON_DIR=./crontabs | ||
CRON_FILE=$CRON_DIR/root | ||
CRON_EX="0 0 * * 2" | ||
|
||
# This script will be executed in late_start service mode | ||
cd "$MODDIR" | ||
|
||
while [ command -v crond &> /dev/null ]; do | ||
sleep 3 | ||
done | ||
while [ ! -f $CRON_FILE ]; do | ||
sleep 3 | ||
done | ||
|
||
CRON_EXISTS=$(cat $CRON_FILE | grep $(realpath $UPDATER_FILE)) | ||
|
||
if [ -z "$CRON_EXISTS" ]; then | ||
echo "$CRON_EX sh $(realpath $UPDATER_FILE)" >> $CRON_FILE | ||
fi | ||
|
||
crond -b -c $(realpath $CRON_DIR) | ||
#!/system/bin/sh | ||
MODDIR=${0%/*} | ||
UPDATER_FILE=./updater.sh | ||
CRON_DIR=./crontabs | ||
CRON_FILE=$CRON_DIR/root | ||
CRON_EX="0 0 * * 2" | ||
|
||
# This script will be executed in late_start service mode | ||
cd "$MODDIR" | ||
|
||
while [ command -v crond &> /dev/null ]; do | ||
sleep 3 | ||
done | ||
while [ ! -f $CRON_FILE ]; do | ||
sleep 3 | ||
done | ||
|
||
CRON_EXISTS=$(cat $CRON_FILE | grep $(realpath $UPDATER_FILE)) | ||
|
||
if [ -z "$CRON_EXISTS" ]; then | ||
echo "$CRON_EX sh $(realpath $UPDATER_FILE)" >> $CRON_FILE | ||
fi | ||
|
||
crond -b -c $(realpath $CRON_DIR) |