|
@@ -0,0 +1,172 @@
|
|
1
|
+# /bin/sh
|
|
2
|
+
|
|
3
|
+setled() {
|
|
4
|
+ if [ -e /sys/class/leds/${led_sysfs}/brightness ]
|
|
5
|
+ then
|
|
6
|
+ [ $led_default -eq 1 ] && echo 1 >/sys/class/leds/${led_sysfs}/brightness
|
|
7
|
+ [ $led_default -eq 1 ] || echo 0 >/sys/class/leds/${led_sysfs}/brightness
|
|
8
|
+
|
|
9
|
+ echo $led_trigger > /sys/class/leds/${led_sysfs}/trigger
|
|
10
|
+
|
|
11
|
+ [ "$led_trigger" == "netdev" -a -n "$led_dev" ] && {
|
|
12
|
+ echo $led_dev > /sys/class/leds/${led_sysfs}/device_name
|
|
13
|
+ echo $led_mode > /sys/class/leds/${led_sysfs}/mode
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ [ "$led_trigger" == "timer" ] && {
|
|
17
|
+ [ -n "$led_delayon" ] && echo $led_delayon > /sys/class/leds/${led_sysfs}/delay_on
|
|
18
|
+ [ -n "$led_delayoff" ] && echo $led_delayoff > /sys/class/leds/${led_sysfs}/delay_off
|
|
19
|
+ }
|
|
20
|
+ else
|
|
21
|
+ logger -p user.err -t "wifitoggle" "led: ${led_sysfs} not found"
|
|
22
|
+ fi
|
|
23
|
+}
|
|
24
|
+
|
|
25
|
+load_wireless() {
|
|
26
|
+ disabled="$(uci get wireless.${1}.disabled)"
|
|
27
|
+}
|
|
28
|
+
|
|
29
|
+save_wireless() {
|
|
30
|
+ [ "$device" = "all" -o "$device" = "${1}" ] && {
|
|
31
|
+ uci set "wireless.${1}.disabled=$disabled"
|
|
32
|
+ }
|
|
33
|
+}
|
|
34
|
+
|
|
35
|
+setwifi() {
|
|
36
|
+ setled
|
|
37
|
+
|
|
38
|
+ config_load wireless
|
|
39
|
+ config_foreach save_wireless wifi-device
|
|
40
|
+
|
|
41
|
+ if ubus list network.wireless >/dev/null 2>/dev/null; then
|
|
42
|
+ ubus call network reload
|
|
43
|
+ else
|
|
44
|
+ wifi
|
|
45
|
+ fi
|
|
46
|
+}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+save_system() {
|
|
50
|
+ config_get sysfs $1 sysfs
|
|
51
|
+ [ "$sysfs" = "$led_sysfs" ] && {
|
|
52
|
+ uci set "system.${1}.trigger=$led_trigger"
|
|
53
|
+ uci set "system.${1}.dev=$led_dev"
|
|
54
|
+ uci set "system.${1}.mode=$led_mode"
|
|
55
|
+ uci set "system.${1}.default=$led_default"
|
|
56
|
+ uci set "system.${1}.delayon=$led_delayon"
|
|
57
|
+ uci set "system.${1}.delayoff=$led_delayoff"
|
|
58
|
+
|
|
59
|
+ ledset=1
|
|
60
|
+ }
|
|
61
|
+}
|
|
62
|
+
|
|
63
|
+commit_changes() {
|
|
64
|
+ ledset=""
|
|
65
|
+
|
|
66
|
+ config_load system
|
|
67
|
+ config_foreach save_system led
|
|
68
|
+
|
|
69
|
+ [ "$ledset" -eq 1 ] || {
|
|
70
|
+ section=$(uci add system led)
|
|
71
|
+ uci set "system.${section}.sysfs=$led_sysfs"
|
|
72
|
+ uci set "system.${section}.trigger=$led_trigger"
|
|
73
|
+ uci set "system.${section}.dev=$led_dev"
|
|
74
|
+ uci set "system.${section}.mode=$led_mode"
|
|
75
|
+ uci set "system.${section}.default=$led_default"
|
|
76
|
+ uci set "system.${section}.delayon=$led_delayon"
|
|
77
|
+ uci set "system.${section}.delayoff=$led_delayoff"
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ uci commit
|
|
81
|
+}
|
|
82
|
+
|
|
83
|
+enable() {
|
|
84
|
+
|
|
85
|
+ led_trigger="$led_enable_trigger"
|
|
86
|
+ led_trigger="$led_enable_trigger"
|
|
87
|
+ led_dev="$led_enable_dev"
|
|
88
|
+ led_mode="$led_enable_mode"
|
|
89
|
+ led_default="$led_enable_default"
|
|
90
|
+ led_delayon="$led_enable_delayon"
|
|
91
|
+ led_delayoff="$led_enable_delayoff"
|
|
92
|
+ disabled=0
|
|
93
|
+
|
|
94
|
+ setwifi
|
|
95
|
+
|
|
96
|
+ [ "$timer" -le 0 -a "$persistent" -eq 1 ] && commit_changes
|
|
97
|
+
|
|
98
|
+ logger -p user.info -t "wifitoggle" "device($device) enabled"
|
|
99
|
+
|
|
100
|
+ [ "$timer" -gt 0 ] && {
|
|
101
|
+ sleep "$timer" && disable && rm /tmp/run/wirelesstoggle_${1}.pid &
|
|
102
|
+ echo $! > /tmp/run/wirelesstoggle_${1}.pid
|
|
103
|
+ logger -p user.info -t "wifitoggle" "auto-disable timer started($timer seconds)"
|
|
104
|
+ }
|
|
105
|
+}
|
|
106
|
+
|
|
107
|
+disable() {
|
|
108
|
+
|
|
109
|
+ led_trigger="$led_disable_trigger"
|
|
110
|
+ led_trigger="$led_disable_trigger"
|
|
111
|
+ led_dev="$led_disable_dev"
|
|
112
|
+ led_mode="$led_disable_mode"
|
|
113
|
+ led_default="$led_disable_default"
|
|
114
|
+ led_delayon="$led_disable_delayon"
|
|
115
|
+ led_delayoff="$led_disable_delayoff"
|
|
116
|
+ disabled=1
|
|
117
|
+
|
|
118
|
+ setwifi
|
|
119
|
+
|
|
120
|
+ [ "$timer" -le 0 -a "$persistent" -eq 1 ] && commit_changes
|
|
121
|
+
|
|
122
|
+ logger -p user.info -t "wifitoggle" "device($device) disabled"
|
|
123
|
+}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+load_wifitoggle() {
|
|
127
|
+ config_get device $1 device "all"
|
|
128
|
+ config_get button $1 button "wps"
|
|
129
|
+ config_get action $1 action "pressed"
|
|
130
|
+ config_get_bool persistent $1 persistent "0"
|
|
131
|
+ config_get timer $1 timer "0"
|
|
132
|
+
|
|
133
|
+ config_get led_sysfs $1 led_sysfs
|
|
134
|
+
|
|
135
|
+ config_get led_enable_trigger $1 led_enable_trigger "none"
|
|
136
|
+ config_get led_enable_dev $1 led_enable_dev
|
|
137
|
+ config_get led_enable_mode $1 led_enable_mode "link"
|
|
138
|
+ config_get_bool led_enable_default $1 led_enable_default "1"
|
|
139
|
+ config_get led_enable_delayon $1 led_enable_delayon
|
|
140
|
+ config_get led_enable_delayoff $1 led_enable_delayoff
|
|
141
|
+
|
|
142
|
+ config_get led_disable_trigger $1 led_disable_trigger "none"
|
|
143
|
+ config_get led_disable_dev $1 led_disable_dev
|
|
144
|
+ config_get led_disable_mode $1 led_disable_mode "link"
|
|
145
|
+ config_get_bool led_disable_default $1 led_disable_default "0"
|
|
146
|
+ config_get led_disable_delayon $1 led_disable_delayon
|
|
147
|
+ config_get led_disable_delayoff $1 led_disable_delayoff
|
|
148
|
+
|
|
149
|
+ [ "$ACTION" = "$action" -a "$BUTTON" = "$button" ] && {
|
|
150
|
+
|
|
151
|
+ [ -f /tmp/run/wirelesstoggle_${1}.pid ] && read PID < /tmp/run/wirelesstoggle_${1}.pid && kill $PID && rm /tmp/run/wirelesstoggle_${1}.pid
|
|
152
|
+
|
|
153
|
+ if [ "$device" = "all" ]
|
|
154
|
+ then
|
|
155
|
+ config_load wireless
|
|
156
|
+ config_foreach load_wireless wifi-device
|
|
157
|
+ else
|
|
158
|
+ disabled="$(uci get wireless."$device".disabled)"
|
|
159
|
+ fi
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+ if [ "$disabled" = "1" ]
|
|
163
|
+ then
|
|
164
|
+ enable $1
|
|
165
|
+ else
|
|
166
|
+ disable
|
|
167
|
+ fi
|
|
168
|
+ }
|
|
169
|
+}
|
|
170
|
+
|
|
171
|
+config_load wifitoggle
|
|
172
|
+config_foreach load_wifitoggle wifitoggle
|