Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module("luci.controller.userpanel", package.seeall)
- function index()
- local nw = require "luci.dispatcher"
- local user = nw.get_user()
- if user ~= "root" then -- if user is not logged in as root then ...
- entry({"admin", "userpanel"}, alias("admin", "userpanel", "dashboard"), "")
- entry({"admin", "userpanel", "dashboard"}, template("user_panel/dashboard_test"), "")
- entry({"admin", "userpanel", "devices"}, template("/user_panel/devices"), "")
- entry({"admin", "userpanel", "alert"}, template("/user_panel/alert"), "")
- entry({"admin", "userpanel", "help"}, template("/user_panel/help"), "")
- entry({"admin", "userpanel", "dashboard", "process"}, call("action_wifi_connection"), "")
- entry({"admin", "userpanel", "devices", "action_kick_sta"}, call("action_kick_sta"), "")
- entry({"admin", "userpanel", "vpn"}, cbi("openvpn_test"), _("OpenVPNTEST") )
- entry({"admin", "userpanel", "loadwifi"}, call("loadwifi"), "")
- entry({"admin", "userpanel", "shutdown"}, call("action_shutdown"), _("Logout"), 70)
- entry({"admin", "userpanel", "logout"}, call("action_logout"), _("Logout"), 80)
- entry({"admin", "userpanel", "restart"}, call("action_restart"), _("Logout"), 90)
- end
- end
- function action_shutdown()
- end
- function action_logout()
- local dsp = require "luci.dispatcher"
- local utl = require "luci.util"
- local sid = dsp.context.authsession
- if sid then
- utl.ubus("session", "destroy", { ubus_rpc_session = sid })
- luci.http.header("Set-Cookie", "sysauth=%s; expires=%s; path=%s/" %{
- sid, 'Thu, 01 Jan 1970 01:00:00 GMT', dsp.build_url()
- })
- end
- luci.http.redirect(dsp.build_url())
- end
- function action_wifi_connection()
- luci.http.prepare_content("text/plain")
- -- luci.http.write("Open a tor page")
- -- local enviro = luci.http.getenv()
- local formvs = luci.http.formvalue()
- -- for k,v in pairs(enviro) do
- -- luci.http.write(k)
- -- luci.http.write(' ')
- -- luci.http.write(v)
- -- luci.http.write('\n')
- -- end
- local ssid
- local pass
- local encrypt
- for k,v in pairs(formvs) do
- local formstring = k .. " : " .. v
- if k == "ssid" then
- ssid = v:gsub("%s+","*s*") -- Hack for whitespace
- ssid = ssid:gsub("(||)","*b*") -- Hack for brackets
- elseif k == "pass" then
- pass = v
- elseif k == "encrypt" then
- encrypt = v
- end
- end
- pass = pass == nil and "" or pass
- -- call connection script
- connect_status = luci.sys.call('sh /usr/lib/lua/shellscripts/connect.sh ' .. ssid .. ' ' .. encrypt .. ' ' .. pass) == 0 and "Success" or "Failed"
- luci.http.write(connect_status)
- end
- function action_kick_sta()
- luci.http.prepare_content("text/plain")
- formvs = luci.http.formvalue()
- mac = ""
- for k,v in pairs(formvs) do
- mac = mac .. v
- end
- luci.sys.call('hostapd_cli deauthenticate ' .. mac)
- luci.http.write("Success")
- end
- function loadwifi()
- luci.http.prepare_content("text/plain")
- scan_results = luci.sys.exec("python /parse_iw.py wlan0")
- luci.http.write(scan_results)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement