mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-01 03:05:13 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
@@ -0,0 +1,15 @@
|
||||
config droidnet 'device'
|
||||
option id 'id'
|
||||
option display_app '100'
|
||||
option display_msg '10'
|
||||
|
||||
config droidnet 'monitoring'
|
||||
option enable '0'
|
||||
option ping 'http'
|
||||
option host 'google.com'
|
||||
option success_limit '5'
|
||||
option failure_limit '3'
|
||||
option wait_time '3'
|
||||
option interface 'wan'
|
||||
option restart '0'
|
||||
option tunnel_service 'tunnel'
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
# This is free software, licensed under the Apache License, Version 2.0
|
||||
#
|
||||
# Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>
|
||||
|
||||
USE_PROCD=1
|
||||
START=99
|
||||
STOP=10
|
||||
NAME=droidnet
|
||||
LOG_FILE=/var/log/droidnet.log
|
||||
MONITORING_SERVICE=/usr/share/droidnet/monitoring
|
||||
|
||||
start_service() {
|
||||
echo "$(date +"%a, %b %d, %I:%M %p") - Activating DroidNet service." >> $LOG_FILE
|
||||
config_load $NAME
|
||||
config_get enable monitoring enable
|
||||
if [ $enable = 1 ]; then
|
||||
screen -dmS droidnet $MONITORING_SERVICE start
|
||||
fi
|
||||
}
|
||||
|
||||
# stop_service() {
|
||||
# echo "$(date +"%a, %b %d, %I:%M %p") - Deactivating DroidNet service." >> $LOG_FILE
|
||||
# echo "$(date +"%a, %b %d, %I:%M %p") - Monitoring service: Stopping service." >> $LOG_FILE
|
||||
# $MONITORING_SERVICE stop
|
||||
# }
|
||||
stop_service() {
|
||||
echo "$(date +"%a, %b %d, %I:%M %p") - Deactivating DroidNet service." >> $LOG_FILE
|
||||
echo "$(date +"%a, %b %d, %I:%M %p") - Monitoring service: Stopping service." >> $LOG_FILE
|
||||
session=$(screen -ls | awk '/droidnet/ {print $1}')
|
||||
screen -X -S $session quit
|
||||
screen -wipe
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop_service
|
||||
start_service
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger $NAME
|
||||
}
|
||||
|
||||
restart_service() {
|
||||
stop_service
|
||||
start_service
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
[ ! -f "/usr/share/ucitrack/luci-app-droidnet.json" ] && {
|
||||
cat > /usr/share/ucitrack/luci-app-droidnet.json << EEOF
|
||||
{
|
||||
"config": "droidnet",
|
||||
"init": "droidnet"
|
||||
}
|
||||
EEOF
|
||||
}
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@droidnet[-1]
|
||||
add ucitrack droidnet
|
||||
set ucitrack.@droidnet[-1].init=droidnet
|
||||
commit ucitrack
|
||||
EOF
|
||||
rm -rf /tmp/luci*
|
||||
exit 0
|
||||
@@ -0,0 +1,304 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This is free software, licensed under the Apache License, Version 2.0
|
||||
#
|
||||
# Copyright (C) 2024 Hilman Maulana <hilman0.0maulana@gmail.com>, Anas Fanani <anas@anasfanani.com>
|
||||
|
||||
# Environment
|
||||
COUNT_FAILURE=0
|
||||
COUNT_SUCCESS=0
|
||||
DEVICES_FOUND=0
|
||||
COMMAND_FOUND=0
|
||||
DEVICES_ROOT=0
|
||||
FAILURE_LIMIT=$(uci get droidnet.monitoring.failure_limit)
|
||||
SUCCESS_LIMIT=$(uci get droidnet.monitoring.success_limit)
|
||||
DEVICES_ID=$(uci get droidnet.device.id)
|
||||
WAIT_TIME=$(uci get droidnet.monitoring.wait_time)
|
||||
HOST=$(uci get droidnet.monitoring.host)
|
||||
PORT=$(uci get droidnet.monitoring.ping)
|
||||
INTERFACE_NAME=$(uci get droidnet.monitoring.interface)
|
||||
RESTART_TUNNEL=$(uci get droidnet.monitoring.restart)
|
||||
TOOL_TUNNELING=$(uci get droidnet.monitoring.tunnel_service)
|
||||
PING_SUCCESS="Ping to '$HOST' using '$PORT' succeeded."
|
||||
PING_BACKGROUND="Ping to '$HOST' using '$PORT' successfuly, starting continuous ping in the background."
|
||||
|
||||
# Functions
|
||||
log() {
|
||||
echo "$(date +"%a, %b %d, %I:%M:%S %p") - Monitoring service: $1" >> /var/log/droidnet.log
|
||||
}
|
||||
|
||||
check_devices() {
|
||||
log "Checking devices."
|
||||
for DEVICE in $(adb devices -l | awk 'NR>1 && /device/ {print $1}'); do
|
||||
if [ $DEVICE = $DEVICES_ID ]; then
|
||||
DEVICES_FOUND=1
|
||||
log "Device found in the list of connected devices."
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $DEVICES_FOUND -eq 1 ]; then
|
||||
log "Checking root status on device."
|
||||
if adb -s $DEVICES_ID shell su -v 2>&1 | grep -q "/system/bin/sh: su: not found"; then
|
||||
INFO_ROOT="Non-root"
|
||||
log "Device not rooted."
|
||||
else
|
||||
INFO_ROOT="Rooted"
|
||||
DEVICES_ROOT=1
|
||||
log "Device is rooted."
|
||||
fi
|
||||
log "Checking availability of airplane mode command on device."
|
||||
INFO_ANDROID=$(adb -s $DEVICES_ID shell getprop ro.build.version.release)
|
||||
INFO_VERSION=${INFO_ANDROID%%.*}
|
||||
if [ $INFO_VERSION -lt 10 ]; then
|
||||
if [ $DEVICES_ROOT -eq 1 ]; then
|
||||
COMMAND_FOUND=1
|
||||
log "Airplane mode can be turned on."
|
||||
else
|
||||
log "Airplane mode can't be turned on."
|
||||
fi
|
||||
else
|
||||
COMMAND_FOUND=1
|
||||
log "Airplane mode can be turned on."
|
||||
fi
|
||||
log "Device information"
|
||||
GET_INFO=$(adb devices -l | grep $DEVICES_ID)
|
||||
INFO_USB=$(echo $GET_INFO | awk '{for(i=1;i<=NF;i++) if($i ~ /^usb:/) print $i}')
|
||||
INFO_MODEL=$(echo $GET_INFO | awk '{for(i=1;i<=NF;i++) if($i ~ /^model:/) {split($i, a, ":"); print a[2]}}')
|
||||
log "ID: $DEVICES_ID, Model: $INFO_MODEL, Android: $INFO_ANDROID, Status: $INFO_ROOT, Connection: $INFO_USB"
|
||||
else
|
||||
log "Device not found in the list of connected devices."
|
||||
fi
|
||||
}
|
||||
|
||||
enable_airplane_mode() {
|
||||
log "Turning on Airplane mode."
|
||||
if [ $DEVICES_ROOT -eq 1 ] && [ $INFO_VERSION -lt 10 ]; then
|
||||
adb -s $DEVICES_ID shell su -c 'settings put global airplane_mode_on 1'
|
||||
adb -s $DEVICES_ID shell su -c 'am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true'
|
||||
else
|
||||
adb -s $DEVICES_ID shell cmd connectivity airplane-mode enable
|
||||
fi
|
||||
}
|
||||
|
||||
disable_airplane_mode() {
|
||||
log "Turning off Airplane mode."
|
||||
if [ $DEVICES_ROOT -eq 1 ] && [ $INFO_VERSION -lt 10 ]; then
|
||||
adb -s $DEVICES_ID shell su -c 'settings put global airplane_mode_on 0'
|
||||
adb -s $DEVICES_ID shell su -c 'am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false'
|
||||
else
|
||||
adb -s $DEVICES_ID shell cmd connectivity airplane-mode disable
|
||||
fi
|
||||
}
|
||||
|
||||
restart_interface() {
|
||||
log "Restarting interface $INTERFACE_NAME."
|
||||
ifup $INTERFACE_NAME
|
||||
}
|
||||
|
||||
disable_neko() {
|
||||
log "Disabling Neko."
|
||||
/etc/init.d/neko stop
|
||||
}
|
||||
|
||||
enable_neko() {
|
||||
log "Enabling Neko."
|
||||
/etc/init.d/neko start
|
||||
}
|
||||
|
||||
disable_openclash() {
|
||||
log "Disabling OpenClash."
|
||||
/etc/init.d/openclash stop
|
||||
}
|
||||
|
||||
enable_openclash() {
|
||||
log "Enabling OpenClash."
|
||||
/etc/init.d/openclash start
|
||||
}
|
||||
|
||||
disable_passwall() {
|
||||
log "Disabling PassWall."
|
||||
/etc/init.d/passwall stop
|
||||
}
|
||||
|
||||
enable_passwall() {
|
||||
log "Enabling PassWall."
|
||||
/etc/init.d/passwall start
|
||||
}
|
||||
|
||||
disable_v2ray() {
|
||||
log "Disabling V2Ray."
|
||||
start-stop-daemon -K -p /var/run/v2raya.pid
|
||||
}
|
||||
|
||||
enable_v2ray() {
|
||||
log "Enabling V2Ray."
|
||||
start-stop-daemon -b -S -m -p /var/run/v2raya.pid -x /usr/bin/enable_v2rayA
|
||||
}
|
||||
|
||||
reconnection() {
|
||||
log "Starting connection update service on the device."
|
||||
if [ $RESTART_TUNNEL = 1 ]; then
|
||||
log "Disabling tunneling tool."
|
||||
if [ $TOOL_TUNNELING = "neko" ]; then
|
||||
disable_neko
|
||||
elif [ $TOOL_TUNNELING = "openclash" ]; then
|
||||
disable_openclash
|
||||
elif [ $TOOL_TUNNELING = "passwall" ]; then
|
||||
disable_passwall
|
||||
elif [ $TOOL_TUNNELING = "v2ray" ]; then
|
||||
disable_v2ray
|
||||
else
|
||||
log "Tunneling tool '$TOOL_TUNNELING' not found, please install it first."
|
||||
fi
|
||||
elif [ $RESTART_TUNNEL = 0 ]; then
|
||||
log "Skipping disabling tunneling tool."
|
||||
fi
|
||||
enable_airplane_mode
|
||||
sleep $WAIT_TIME
|
||||
disable_airplane_mode
|
||||
sleep $WAIT_TIME
|
||||
restart_interface
|
||||
if [ $RESTART_TUNNEL = 1 ]; then
|
||||
log "Enabling tunneling tool."
|
||||
if [ $TOOL_TUNNELING = "neko" ]; then
|
||||
enable_neko
|
||||
elif [ $TOOL_TUNNELING = "openclash" ]; then
|
||||
enable_openclash
|
||||
elif [ $TOOL_TUNNELING = "passwall" ]; then
|
||||
enable_passwall
|
||||
elif [ $TOOL_TUNNELING = "v2ray" ]; then
|
||||
enable_v2ray
|
||||
else
|
||||
log "Tunneling tool '$TOOL_TUNNELING' not found, please install it first."
|
||||
fi
|
||||
elif [ $RESTART_TUNNEL = 0 ]; then
|
||||
log "Skipping enabling tunneling tool."
|
||||
fi
|
||||
log "Connection update service on the device has completed."
|
||||
COUNT_FAILURE=0
|
||||
}
|
||||
|
||||
ping_else() {
|
||||
log "Ping to '$HOST' using '$PORT' failed."
|
||||
COUNT_FAILURE=$((COUNT_FAILURE + 1))
|
||||
COUNT_SUCCESS=0
|
||||
if [ $COUNT_FAILURE -ge $FAILURE_LIMIT ]; then
|
||||
log "Failed ping to '$HOST' using '$PORT' $FAILURE_LIMIT times."
|
||||
reconnection
|
||||
fi
|
||||
}
|
||||
|
||||
ping_http() {
|
||||
if curl -Is "http://$HOST:80" > /dev/null; then
|
||||
COUNT_SUCCESS=$((COUNT_SUCCESS + 1))
|
||||
if [ $SUCCESS_LIMIT = "unlimited" ] || [ $COUNT_SUCCESS -le $SUCCESS_LIMIT ]; then
|
||||
log $PING_SUCCESS
|
||||
fi
|
||||
COUNT_FAILURE=0
|
||||
if [ $COUNT_SUCCESS -eq $SUCCESS_LIMIT ]; then
|
||||
log $PING_BACKGROUND
|
||||
fi
|
||||
else
|
||||
ping_else
|
||||
fi
|
||||
}
|
||||
|
||||
ping_https() {
|
||||
if curl -Is "https://$HOST:443" > /dev/null; then
|
||||
COUNT_SUCCESS=$((COUNT_SUCCESS + 1))
|
||||
if [ $SUCCESS_LIMIT = "unlimited" ] || [ $COUNT_SUCCESS -le $SUCCESS_LIMIT ]; then
|
||||
log $PING_SUCCESS
|
||||
fi
|
||||
COUNT_FAILURE=0
|
||||
if [ $COUNT_SUCCESS -eq $SUCCESS_LIMIT ]; then
|
||||
log $PING_BACKGROUND
|
||||
fi
|
||||
else
|
||||
ping_else
|
||||
fi
|
||||
}
|
||||
|
||||
ping_icmp() {
|
||||
ping -q -c 3 -W 3 -p 0 $HOST > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
COUNT_SUCCESS=$((COUNT_SUCCESS + 1))
|
||||
if [ $SUCCESS_LIMIT = "unlimited" ] || [ $COUNT_SUCCESS -le $SUCCESS_LIMIT ]; then
|
||||
log $PING_SUCCESS
|
||||
fi
|
||||
COUNT_FAILURE=0
|
||||
if [ $COUNT_SUCCESS -eq $SUCCESS_LIMIT ]; then
|
||||
log $PING_BACKGROUND
|
||||
fi
|
||||
else
|
||||
ping_else
|
||||
fi
|
||||
}
|
||||
|
||||
ping_tcp() {
|
||||
if nc -zvw 1 $HOST 80 2>&1 | grep -q succeeded; then
|
||||
COUNT_SUCCESS=$((COUNT_SUCCESS + 1))
|
||||
if [ $SUCCESS_LIMIT = "unlimited" ] || [ $COUNT_SUCCESS -le $SUCCESS_LIMIT ]; then
|
||||
log $PING_SUCCESS
|
||||
fi
|
||||
COUNT_FAILURE=0
|
||||
if [ $COUNT_SUCCESS -eq $SUCCESS_LIMIT ]; then
|
||||
log $PING_BACKGROUND
|
||||
fi
|
||||
else
|
||||
ping_else
|
||||
fi
|
||||
}
|
||||
|
||||
start_service() {
|
||||
log "Starting service."
|
||||
check_devices
|
||||
if [ $DEVICES_FOUND -eq 1 ] && [ $COMMAND_FOUND -eq 1 ]; then
|
||||
log "Starting ping to '$HOST' using '$PORT'."
|
||||
while true; do
|
||||
if [ $PORT = "http" ]; then
|
||||
ping_http
|
||||
elif [ $PORT = "https" ]; then
|
||||
ping_https
|
||||
elif [ $PORT = "icmp" ]; then
|
||||
ping_icmp
|
||||
elif [ $PORT = "tcp" ]; then
|
||||
ping_tcp
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
else
|
||||
log "Failed to start service."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
log "Stopping service."
|
||||
SERVICE_PID=$(pgrep -f /usr/share/droidnet/monitoring)
|
||||
kill $SERVICE_PID
|
||||
}
|
||||
|
||||
restart_service() {
|
||||
log "Restarting service."
|
||||
SERVICE_PID=$(pgrep -f /usr/share/droidnet/monitoring | head -n 1)
|
||||
start_service
|
||||
}
|
||||
|
||||
# Main script
|
||||
if [ "$1" = "start" ]; then
|
||||
start_service
|
||||
elif [ "$1" = "stop" ]; then
|
||||
stop_service
|
||||
elif [ "$1" = "restart" ]; then
|
||||
restart_service
|
||||
else
|
||||
echo "Syntax: Monitoring service [DroidNet]"
|
||||
echo "Available commands:"
|
||||
echo " start Start the service"
|
||||
echo " stop Stop the service"
|
||||
echo " restart Restart the service"
|
||||
fi
|
||||
|
||||
reload_service() {
|
||||
restart
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"admin/services/droidnet": {
|
||||
"title": "DroidNet",
|
||||
"order": 50,
|
||||
"action": {
|
||||
"type": "firstchild"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-droidnet" ]
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/device": {
|
||||
"title": "Device",
|
||||
"order": 1,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/device"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/network": {
|
||||
"title": "Network",
|
||||
"order": 2,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/network"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/service": {
|
||||
"title": "Service",
|
||||
"order": 3,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/service"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/inbox": {
|
||||
"title": "Inbox",
|
||||
"order": 4,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/inbox"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/log": {
|
||||
"title": "Logs",
|
||||
"order": 5,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/log"
|
||||
}
|
||||
},
|
||||
"admin/services/droidnet/setting": {
|
||||
"title": "Setting",
|
||||
"order": 6,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "droidnet/setting"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"luci-app-droidnet": {
|
||||
"description": "Grant access to luci-app-droidnet",
|
||||
"read": {
|
||||
"file": {
|
||||
"/var/log/droidnet.log": [ "read" ],
|
||||
"/usr/bin/adb": [ "exec" ],
|
||||
"/usr/bin/pgrep": [ "exec" ]
|
||||
},
|
||||
"uci": [ "droidnet" ]
|
||||
},
|
||||
"write": {
|
||||
"file": {
|
||||
"/var/log/droidnet.log": [ "write" ],
|
||||
"/tmp/upload.apk": [ "write" ]
|
||||
},
|
||||
"uci": [ "droidnet" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in new issue
Block a user