diff --git a/dae/files/dae.init b/dae/files/dae.init index 6fe8197b..8dd2116b 100755 --- a/dae/files/dae.init +++ b/dae/files/dae.init @@ -39,6 +39,13 @@ update_cron() { rm -f "$temp_cron" } +cleanup_netns() { + if [ -e "/run/netns/daens" ]; then + ip netns del daens 2>/dev/null + rm -f /run/netns/daens 2>/dev/null + fi +} + hijack_resolv_conf() { grep -q ' /tmp/resolv\.conf ' /proc/mounts && return 0 @@ -78,6 +85,7 @@ start_service() { set_chmod_640 update_cron "add" hijack_resolv_conf + cleanup_netns config_get log_maxbackups "config" "log_maxbackups" "1" config_get log_maxsize "config" "log_maxsize" "1" @@ -101,7 +109,7 @@ start_service() { stop_service() { update_cron "remove" restore_resolv_conf - [ -f "$DAENETNS" ] && umount "$DAENETNS" 2>/dev/null || true + cleanup_netns } service_triggers() { diff --git a/luci-app-daed/root/etc/hotplug.d/iface/98-daed b/luci-app-daed/root/etc/hotplug.d/iface/98-daed index 3489a39b..83df5ffd 100755 --- a/luci-app-daed/root/etc/hotplug.d/iface/98-daed +++ b/luci-app-daed/root/etc/hotplug.d/iface/98-daed @@ -1,22 +1,31 @@ #!/bin/sh -[ "${ACTION}" = "ifup" ] || exit 0 +[ "$ACTION" = "ifup" ] || [ "$ACTION" = "ifupdate" ] || exit 0 +[ "$ACTION" = "ifupdate" ] && [ -z "$IFUPDATE_ADDRESSES" ] && [ -z "$IFUPDATE_DATA" ] && exit 0 -DEVICE=$(logread | grep "link is up" | tail -n 1 | awk -F "'" '{print $2}') -DEVICE_TYPE=$(ip link show dev "$DEVICE") +UPTIME=$(cut -d. -f1 /proc/uptime 2>/dev/null) +[ -n "$UPTIME" ] && [ "$UPTIME" -lt 30 ] && exit 0 -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 +. /lib/functions/network.sh +network_find_wan6 NET_IF6 +network_find_wan NET_IF +[ "$INTERFACE" != "$NET_IF6" ] && [ "$INTERFACE" != "$NET_IF" ] && exit 0 + +[ "$(uci -q get daed.config.enabled)" = "1" ] || exit 0 + +DEBOUNCE_FILE="/tmp/run/daed_hotplug_gen" +mkdir -p /tmp/run + +my_gen="$$.$(date +%s)" +echo "$my_gen" > "$DEBOUNCE_FILE" + +( + sleep 5 + [ "$(cat "$DEBOUNCE_FILE" 2>/dev/null)" = "$my_gen" ] || exit 0 + + if /etc/init.d/daed running; then + /etc/init.d/daed restart + else + /etc/init.d/daed start + fi +) & diff --git a/luci-app-daed/root/etc/init.d/luci_daed b/luci-app-daed/root/etc/init.d/luci_daed index 5805e4cb..46dc063b 100755 --- a/luci-app-daed/root/etc/init.d/luci_daed +++ b/luci-app-daed/root/etc/init.d/luci_daed @@ -7,42 +7,52 @@ 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)) +RESOLV_DAED="/tmp/resolv.conf.daed" -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 +update_cron() { + local temp_cron="/tmp/root.cron" + + if [ -f /etc/crontabs/root ]; then + grep -v '/etc/daed/daed_sub.sh' /etc/crontabs/root > "$temp_cron" 2>/dev/null + fi + : >> "$temp_cron" + + local auto_update + auto_update=$(uci -q get daed.config.subscribe_auto_update) + if [ "$1" = "add" ] && [ "${auto_update:-0}" -eq 1 ]; then + local min=$((RANDOM % 60)) + local hr=$(uci -q get daed.config.subscribe_update_day_time) + local wk=$(uci -q get daed.config.subscribe_update_week_time) + echo "$min ${hr:-*} * * ${wk:-*} /etc/daed/daed_sub.sh >/dev/null 2>&1" >> "$temp_cron" + fi + + crontab "$temp_cron" 2>/dev/null + rm -f "$temp_cron" } -delcron() { - sed -i '/daed_sub.sh/d' $CRON_FILE 2>/dev/null - crontab $CRON_FILE +hijack_resolv_conf() { + grep -q ' /tmp/resolv\.conf ' /proc/mounts && return 0 + + cat /dev/null > "$RESOLV_DAED" + + if [ -f "/tmp/resolv.conf.d/resolv.conf.auto" ]; then + grep '^nameserver' "/tmp/resolv.conf.d/resolv.conf.auto" >> "$RESOLV_DAED" + fi + + if [ ! -s "$RESOLV_DAED" ]; then + echo "nameserver 223.5.5.5" > "$RESOLV_DAED" + echo "nameserver 119.29.29.29" >> "$RESOLV_DAED" + fi + + mount --bind "$RESOLV_DAED" /tmp/resolv.conf + mount -o remount,ro,bind /tmp/resolv.conf } -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 +restore_resolv_conf() { + grep -q ' /tmp/resolv\.conf ' /proc/mounts || return 0 + mount -o remount,rw,bind /tmp/resolv.conf 2>/dev/null + umount /tmp/resolv.conf 2>/dev/null + rm -f "$RESOLV_DAED" } start_service() { @@ -52,17 +62,17 @@ start_service() { local enabled config_get_bool enabled "config" "enabled" "0" if [ "$enabled" -eq 0 ]; then - #delcron - setlocaluse + update_cron "remove" + restore_resolv_conf return 1 fi - #setcron - dellocaluse + update_cron "add" + hijack_resolv_conf } stop_service() { - #delcron - setlocaluse + update_cron "remove" + restore_resolv_conf } service_triggers() { diff --git a/luci-app-log/htdocs/luci-static/resources/view/log-viewer/log-base.js b/luci-app-log/htdocs/luci-static/resources/view/log-viewer/log-base.js index b34c8574..62141bf7 100644 --- a/luci-app-log/htdocs/luci-static/resources/view/log-viewer/log-base.js +++ b/luci-app-log/htdocs/luci-static/resources/view/log-viewer/log-base.js @@ -724,7 +724,7 @@ return baseclass.extend({ if(!fPattern) { return entriesArray; }; - fPattern = this.htmlEntities(fPattern); + //fPattern = this.htmlEntities(fPattern); return (this.msgFilterReValue) ? this.setRegexpFilter(entriesArray, 5, fPattern) : this.setStringFilter(entriesArray, 5, fPattern);