🐶 Sync 2025-11-02 14:26:26
This commit is contained in:
36
luci-app-daed/root/etc/daed/daed_sub.sh
Executable file
36
luci-app-daed/root/etc/daed/daed_sub.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
|
||||
USERNAME=$(uci -q get daed.config.daed_username)
|
||||
PASSWORD=$(uci -q get daed.config.daed_password)
|
||||
PORT=$(echo "$(uci -q get daed.config.listen_addr)" | grep -oE '[0-9]+$' | sed -n '1p')
|
||||
GRAPHQL_URL="http://127.0.0.1:"$PORT"/graphql"
|
||||
CRON_FILE="/etc/crontabs/root"
|
||||
RANDOM_SEED=$RANDOM
|
||||
RANDOM_NUM=$((RANDOM_SEED % 10 + 1))
|
||||
|
||||
login() {
|
||||
LOGIN=$(curl -s -X POST -H "Content-Type: application/json" -d '{"query":"query Token($username: String!, $password: String!) {\n token(username: $username, password: $password)\n}","variables":{"username":"'"$USERNAME"'","password":"'"$PASSWORD"'"}}' $GRAPHQL_URL)
|
||||
JSON=${LOGIN#\"}
|
||||
JSON=${LOGIN%\"}
|
||||
TOKEN=$(echo $JSON | sed -n 's/.*"token":"\([^"]*\)".*/\1/p')
|
||||
}
|
||||
|
||||
update_subscription() {
|
||||
SUBSCRIPTION_ID_LIST=$(curl -s -X POST -H "Authorization: $TOKEN" -d '{"query": "query Subscriptions {\n subscriptions {\nid\ntag\nstatus\nlink\ninfo\nupdatedAt\nnodes {\nedges {\nid\nname\nprotocol\nlink\n}\n}\n}\n}", "operationName": "Subscriptions"}' $GRAPHQL_URL | grep -o '"id":"[^"]*","tag"' | grep -o 'id":"[^"]*' | grep -o '[^"]*$')
|
||||
echo "$SUBSCRIPTION_ID_LIST" | while read -r id; do
|
||||
curl -X POST -H "Authorization: $TOKEN" -d '{"query":"mutation UpdateSubscription($id: ID!) {\n updateSubscription(id: $id) {\n id\n }\n}","variables":{"id":"'"$id"'"},"operationName":"UpdateSubscription"}' $GRAPHQL_URL
|
||||
done
|
||||
}
|
||||
|
||||
reload() {
|
||||
curl -X POST -H "Authorization: $TOKEN" -d '{"query":"mutation Run($dry: Boolean!) {\n run(dry: $dry)\n}","variables":{"dry":false},"operationName":"Run"}' $GRAPHQL_URL
|
||||
}
|
||||
|
||||
resetcron() {
|
||||
touch $CRON_FILE
|
||||
sed -i '/daed_sub.sh/d' $CRON_FILE 2>/dev/null
|
||||
[ "$(uci -q get daed.config.subscribe_auto_update)" -eq 1 ] && echo "${RANDOM_NUM} $(uci -q get daed.config.subscribe_update_day_time) * * $(uci -q get daed.config.subscribe_update_week_time) /etc/daed/daed_sub.sh >/dev/null 2>&1" >>$CRON_FILE
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
login && update_subscription && reload && resetcron
|
||||
22
luci-app-daed/root/etc/hotplug.d/iface/98-daed
Executable file
22
luci-app-daed/root/etc/hotplug.d/iface/98-daed
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "${ACTION}" = "ifup" ] || exit 0
|
||||
|
||||
DEVICE=$(logread | grep "link is up" | tail -n 1 | awk -F "'" '{print $2}')
|
||||
DEVICE_TYPE=$(ip link show dev "$DEVICE")
|
||||
|
||||
case "$DEVICE_TYPE" in
|
||||
*"link/ether"*)
|
||||
(
|
||||
LOCK_FILE="/tmp/lock/daed_hotplug_lock"
|
||||
if [ -f "$LOCK_FILE" ]; then
|
||||
exit 1
|
||||
else
|
||||
echo $$ > "$LOCK_FILE" 2>/dev/null
|
||||
trap 'rm -f "$LOCK_FILE"' EXIT
|
||||
sleep 60
|
||||
/etc/init.d/daed restart 2>&1
|
||||
fi
|
||||
) &
|
||||
;;
|
||||
esac
|
||||
70
luci-app-daed/root/etc/init.d/luci_daed
Executable file
70
luci-app-daed/root/etc/init.d/luci_daed
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2023 Tianling Shen <cnsztl@immortalwrt.org>
|
||||
|
||||
USE_PROCD=0
|
||||
START=98
|
||||
|
||||
CONF="daed"
|
||||
PROG="/usr/bin/daed"
|
||||
LOG="/var/log/daed/daed.log"
|
||||
CRON_FILE="/etc/crontabs/root"
|
||||
RANDOM_SEED=$RANDOM
|
||||
RANDOM_NUM=$((RANDOM_SEED % 10 + 1))
|
||||
|
||||
setcron() {
|
||||
touch $CRON_FILE
|
||||
sed -i '/daed_sub.sh/d' $CRON_FILE 2>/dev/null
|
||||
[ "$(uci -q get daed.config.subscribe_auto_update)" -eq 1 ] && echo "${RANDOM_NUM} $(uci -q get daed.config.subscribe_update_day_time) * * $(uci -q get daed.config.subscribe_update_week_time) /etc/daed/daed_sub.sh >/dev/null 2>&1" >>$CRON_FILE
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
delcron() {
|
||||
sed -i '/daed_sub.sh/d' $CRON_FILE 2>/dev/null
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
setlocaluse() {
|
||||
uci set dhcp.@dnsmasq[0].localuse="1"
|
||||
uci commit dhcp
|
||||
/etc/init.d/dnsmasq restart
|
||||
}
|
||||
|
||||
dellocaluse() {
|
||||
uci set dhcp.@dnsmasq[0].localuse="0"
|
||||
uci commit dhcp
|
||||
/etc/init.d/dnsmasq restart
|
||||
. /lib/functions/network.sh
|
||||
network_find_wan LOGICAL_WAN || exit 1
|
||||
dns_list=$(ubus call network.interface.$LOGICAL_WAN status | jsonfilter -e '@["dns-server"]' | sed 's/[]["]//g' | sed 's/,/\n/g' | grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b')
|
||||
[ -z "$dns_list" ] && dns_list="119.29.29.29 180.76.76.76 223.5.5.5"
|
||||
grep -v '^nameserver ' /etc/resolv.conf > /tmp/resolv.conf.new.daed 2>/dev/null
|
||||
for dns in $dns_list; do
|
||||
echo "nameserver $dns" >> /tmp/resolv.conf.new.daed
|
||||
done
|
||||
cat /tmp/resolv.conf.new.daed > /etc/resolv.conf
|
||||
rm -f /tmp/resolv.conf.new.daed
|
||||
}
|
||||
|
||||
start_service() {
|
||||
[ -f "/etc/init.d/daed" ] && grep -q "DAE_LOCATION_ASSET" "/etc/init.d/daed" || sed -i '/run/i\ procd_set_param env DAE_LOCATION_ASSET="/usr/share/v2ray"' "/etc/init.d/daed"
|
||||
config_load "$CONF"
|
||||
|
||||
local enabled
|
||||
config_get_bool enabled "config" "enabled" "0"
|
||||
if [ "$enabled" -eq 0 ]; then
|
||||
delcron
|
||||
setlocaluse
|
||||
return 1
|
||||
fi
|
||||
setcron
|
||||
dellocaluse
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
delcron
|
||||
setlocaluse
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "$CONF"
|
||||
}
|
||||
11
luci-app-daed/root/usr/share/rpcd/acl.d/luci-app-daed.json
Normal file
11
luci-app-daed/root/usr/share/rpcd/acl.d/luci-app-daed.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-daed": {
|
||||
"description": "Grant UCI access for luci-app-daed",
|
||||
"read": {
|
||||
"uci": [ "daed" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "daed" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user