12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/usr/bin/lua
- local timestamp = os.time()
- local uci = require('luci.model.uci').cursor()
- function compare(list, value)
- if not list then
- return nil
- end
- for _, v in ipairs(list) do
- if v == value then
- return true
- end
- end
- return false
- end
- function getDay()
- local type = uci:get('ap-timer','settings','type')
- if type == 'day' then return 'all'
- elseif type == 'week' then return os.date('%a', timestamp)
- elseif type == 'month' then return os.date('%d', timestamp)
- else return nil
- end
- end
- function apSet(value)
- local execWifi = false
- local radios = {'client_radio0', 'client_radio1'}
- for _, radio in ipairs(radios) do
- if uci:get('wireless', radio) then
- uci:set('wireless', radio, 'disabled', value and 0 or 1)
- execWifi = true
- end
- end
- if execWifi then
- uci:save('wireless')
- os.execute('wifi')
- end
- end
- if uci:get_bool('ap-timer','settings','enabled') then
- local day = getDay()
- local current = os.date("%H:%M", timestamp)
- local off = compare(uci:get_list('ap-timer', day, 'off'), current)
- local on = compare(uci:get_list('ap-timer', day, 'on'), current)
- if on and not off then
- apSet(true)
- end
- if off and not on then
- apSet(false)
- end
- end
|