diff --git a/.gitignore b/.gitignore index 3e052f5..1f0476d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -__MACOSX -.DS_Store -/hosts +__MACOSX +.DS_Store +/hosts diff --git a/build_hosts.js b/build_hosts.js index c6971a0..f859c9f 100644 --- a/build_hosts.js +++ b/build_hosts.js @@ -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(); diff --git a/config.json b/config.json index a2fd1ae..86d40fd 100644 --- a/config.json +++ b/config.json @@ -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" + ] } \ No newline at end of file diff --git a/module/META-INF/com/google/android/update-binary b/module/META-INF/com/google/android/update-binary index f342a3b..ea4889e 100644 --- a/module/META-INF/com/google/android/update-binary +++ b/module/META-INF/com/google/android/update-binary @@ -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 \ No newline at end of file diff --git a/module/META-INF/com/google/android/updater-script b/module/META-INF/com/google/android/updater-script index f225797..11d5c96 100644 --- a/module/META-INF/com/google/android/updater-script +++ b/module/META-INF/com/google/android/updater-script @@ -1 +1 @@ -#MAGISK +#MAGISK diff --git a/module/service.sh b/module/service.sh index 4812cd4..c51efbc 100644 --- a/module/service.sh +++ b/module/service.sh @@ -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)