Skip to content

Commit

Permalink
fix: convert CRLF to LF
Browse files Browse the repository at this point in the history
  • Loading branch information
dongcodebmt committed Dec 13, 2023
1 parent 69cfffc commit c4d37be
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 147 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__MACOSX
.DS_Store
/hosts
__MACOSX
.DS_Store
/hosts
156 changes: 78 additions & 78 deletions build_hosts.js
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();
18 changes: 9 additions & 9 deletions config.json
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"
]
}
64 changes: 32 additions & 32 deletions module/META-INF/com/google/android/update-binary
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
2 changes: 1 addition & 1 deletion module/META-INF/com/google/android/updater-script
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#MAGISK
#MAGISK
48 changes: 24 additions & 24 deletions module/service.sh
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)

0 comments on commit c4d37be

Please sign in to comment.