Skip to content

Commit

Permalink
Refactored and optimized settings script:
Browse files Browse the repository at this point in the history
- Improved comments and formatting
- Introduced interface allow/ignore list from configuration
- Simplified logging and notification logic
  • Loading branch information
dependabot-preview[bot] committed Dec 13, 2024
1 parent 6033ddb commit 097a327
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 58 deletions.
15 changes: 15 additions & 0 deletions box/ap.list.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Allow access for network interfaces with the following prefixes: ap+, wlan+, rndis+, swlan+, ncm+, and eth+
# allow <interface name>
allow ap+
allow wlan+
# allow wlan1
allow rndis+
allow swlan+
allow ncm+
allow eth+
# -----------------🌼🌼----------------------- #
# Ignore network interface
# Ignore <interface name>
# ignore wlan0
# ignore swlan0
# ignore wlan+
139 changes: 81 additions & 58 deletions box/settings.ini
Original file line number Diff line number Diff line change
@@ -1,60 +1,54 @@
#!/system/bin/sh

# define the settings and path
# Define the path to the settings file
settings="/data/adb/box/settings.ini"

# Check if 'busybox' is installed; if not, add the necessary paths to the environment PATH variable
if ! command -v busybox &> /dev/null; then
export PATH="/data/adb/magisk:/data/adb/ksu/bin:/data/adb/ap/bin:$PATH:/system/bin"
fi

# Take the current time
# Retrieve the current time in 12-hour format
current_time=$(date +"%I:%M %P")

# set the port numbers for tproxy and redir
# Set the port numbers for tproxy and redir functionalities
tproxy_port="9898"
redir_port="9797"

# enable/disable port detection: true / false
# Enable or disable port detection: true / false
port_detect="false"

# enable/disable IPv6: true / false
# Enable or disable IPv6 support: true / false
ipv6="false"

# list of available kernel binaries
bin_list=( "clash" "sing-box" "xray" "v2fly" "hysteria" )
# Define a list of available kernel binaries
bin_list=("clash" "sing-box" "xray" "v2fly" "hysteria")

# for run and download premium or mihomo
# put kernel premium and mihomo into /data/adb/box/bin directory
# Specify which option to use for running and downloading premium or mihomo. Ensure premium and mihomo kernels are placed in the /data/adb/box/bin directory
xclash_option="mihomo"
# select the client to use : clash / sing-box / xray / v2fly

# Select the client to use: clash / sing-box / xray / v2fly / hysteria
bin_name="clash"

# This script is used to set the user and group for the BFM core files.
# This script is used to set the user and group for BFM core files, if setgiduid is unknown, set it to 0:3005.
box_user_group="root:net_admin"

# redirect: tcp + udp[direct]
# tproxy: tcp + udp
# Define the network modes:
# redirect: handles tcp + udp[direct]
# tproxy: handles tcp + udp
# mixed: redirect[tcp] + tun[udp]
# enhance: redirect[tcp] + tproxy[udp]
# tun: tcp + udp (auto-route)
# tun: handles tcp + udp (auto-route)
network_mode="tproxy"

# The gid in the list will be bypassed or proxied according to the proxy_mode configuration, and the gid can be arbitrarily specified by the busybox setuidgid command
gid_list=()

# Display AP info by typing "su -c ifconfig" in terminal "swlan+" "wlan+" "rndis+"
ap_list=("ap+" "wlan+" "rndis+" "swlan+" "ncm+" "eth+")
# Ignore AP in the out list, doesn't work in fake-ip mode
ignore_out_list=()

# Set cgroup to limit memory usage
# Configure cgroup to limit memory usage
cgroup_memcg="false"
memcg_limit="25M"

# Set cgroup to cpuset usage
# Configure cgroup for cpuset usage
cgroup_cpuset="false"

# Set cgroup to blkio usage
# Configure cgroup for blkio usage
cgroup_blkio="false"

# Set box directory variables
Expand All @@ -65,81 +59,111 @@ box_pid="${box_run}/box.pid"
bin_dir="${box_dir}/bin"
bin_path="${bin_dir}/${bin_name}"

# if you don't want to generate the /run/${bin_name}.log file (because it will grow in size over time), replace "${box_run}/${bin_name}.log" to "/dev/null"
# If you don't want to generate the /run/${bin_name}.log file (because it will grow in size over time), replace "${box_run}/${bin_name}.log" with "/dev/null"
bin_log="${box_run}/${bin_name}.log"
# bin_log="/dev/null"

system_packages_file="/data/system/packages.list"
uid_list=("/data/adb/box/run/appuid.list")

# Update subscription & geox
# Set update interval using cron, for more information: https://crontab.guru/
# set 'true' to enable Cron job
interva_update="0 0,6,12,18 * * *" # will update every hour 00,06,12,18
# Update subscription & geox. Set update interval using cron, for more information: https://crontab.guru/, set 'true' to enable Cron job
interva_update="0 0,6,12,18 * * *" # will update every hour at 00, 06, 12, 18
run_crontab="false"

# type "su -c /data/adb/box/scripts/box.tool geox" to update geox
# Type "su -c /data/adb/box/scripts/box.tool geox" to update geox
update_geo="true"

# if "renew=true" it will update config.yaml not subscription configuration
# type "su -c /data/adb/box/scripts/box.tool subs" to update subscription
# If "renew=true" it will update config.yaml not the subscription configuration. Type "su -c /data/adb/box/scripts/box.tool subs" to update subscription
renew=false
update_subscription="false"
# ex: clash subscription url
subscription_url_clash='https://proxy-list.cloudaccess.host/vless/api?cc=ID,US,JP,SG&cdn=true&tls=true&limit=10&format=clash' # this is just an example.

# clash configuration
# Example: clash subscription URL
subscription_url_clash='https://proxy-list.cloudaccess.host/vless/api?cc=ID,US,JP,SG&cdn=true&tls=true&limit=10&format=clash' # This is just an example.

# Clash configuration
name_clash_config="config.yaml"
clash_config="${box_dir}/clash/${name_clash_config}"
# clash subscription

# Clash subscription
name_provide_clash_config="subscription.yaml"
clash_provide_config="${box_dir}/clash/provide/${name_provide_clash_config}"
# support rules specified in subscriptions, This is useful when the subscription contains customized rules as well.

# Support rules specified in subscriptions. This is useful when the subscription contains customized rules as well.
custom_rules_subs="false"
name_provide_clash_rules="rules.yaml"
clash_provide_rules="${box_dir}/clash/provide/${name_provide_clash_rules}"

# sing configuration
# Sing configuration
name_sing_config="config.json"
sing_config="${box_dir}/sing-box/${name_sing_config}"

normal="\033[0m"
orange="\033[1;38;5;208m"
red="\033[1;31m"
green="\033[1;32m"
yellow="\033[1;33m"
blue="\033[1;34m"
write_listap=$(dirname "$settings")/ap.list.cfg
# Check pkg config file
[ -d ${write_listap} ] && rm -rf ${write_listap}
[ ! -f ${write_listap} ] && cat > ${write_listap}<<init
# Allow access for network interfaces with the following prefixes: ap+, wlan+, rndis+, swlan+, ncm+, and eth+
# allow <interface name>
allow ap+
allow wlan+
# allow wlan1
allow rndis+
allow swlan+
allow ncm+
allow eth+
# -----------------🌼🌼----------------------- #
# Ignore network interface
# Ignore <interface name>
# ignore wlan0
# ignore swlan0
# ignore wlan+
init

# define the package.list.cfg path
pkg_config=$(dirname "$settings")/package.list.cfg
# Read the list of allowed network interfaces from the configuration file "ap.list.cfg"
ap_list=($(busybox awk '/^allow / {print $2}' ${write_listap}))
# Read the list of ignored network interfaces from the configuration file "ap.list.cfg". These interfaces will be excluded from the output, not applicable in fake-ip mode.
ignore_out_list=($(busybox awk '/^ignore / {print $2}' ${write_listap}))

# check pkg config file
[ -d ${pkg_config} ]&&rm -rf ${pkg_config}
[ ! -f ${pkg_config} ]&&cat>${pkg_config}<<init
# Define the package.list.cfg path
pkg_config=$(dirname "$settings")/package.list.cfg
# Check pkg config file
[ -d ${pkg_config} ] && rm -rf ${pkg_config}
[ ! -f ${pkg_config} ] && cat > ${pkg_config}<<init
# 黑/白 名单模式;black/white list mode.
mode:whitelist
# 格式/format:
# package_name ▼
#com.topjohnwu.magisk
# com.topjohnwu.magisk
# Gid ▼
#10450 alook
#99910450 999_alook
# 10450 alook
# 99910450 999_alook
init
# blacklist / whitelist

# Extract mode, package list and gid list
# proxy_mode=$(busybox awk -F: '/^mode:/ {print $2}' ${pkg_config} | tr -d ' ')
# packages_list=($(busybox awk '!/^#/ && /^[^ ]*\.([^ ]*)/ {print $1}' ${pkg_config}))
# gid_list=($(busybox awk '!/^#/ && /^[0-9]{1,8}/ {print $1}' ${pkg_config}))

# Extract mode, package list and gid list
proxy_mode=$(sed -n 's/^mode:\([^ ]*\).*/\1/p' ${pkg_config})
packages_list=($(sed -n '/^[^#]/s/^\([^ ]*\.[^ ]*\).*/\1/p' ${pkg_config}))
gid_list=($(sed -n '/^[^#]/s/^\([0-9]\{1,8\}\).*/\1/p' ${pkg_config}))

# eg: notify $title $content
notify() {
# eg: notify $title $content
# using Xposed edge app toast
am start -a android.intent.action.VIEW -n com.jozein.xedgepro/.ui.ActivityPerformAction --ei __0 111 --es __1 "$2" >/dev/null 2>&1

# am start -a android.intent.action.VIEW -n com.jozein.xedgepro/.ui.ActivityPerformAction --ei __0 111 --es __1 "$2" >/dev/null 2>&1
true
# using system notification
# su -lp "2000" -c "cmd notification post -S messaging --conversation '$1' --message '$1':'$2' 'Tag' '$(echo $RANDOM)' " >/dev/null 2>&1
}

log() {
normal="\033[0m"
orange="\033[1;38;5;208m"
red="\033[1;31m"
green="\033[1;32m"
yellow="\033[1;33m"
blue="\033[1;34m"
# Selects the text color according to the parameters
case $1 in
Info) color="${blue}" ;;
Expand All @@ -160,5 +184,4 @@ log() {
if [[ $TOAST ]]; then
notify "box_for_root" "${message}"
fi

}

0 comments on commit 097a327

Please sign in to comment.