Advertisement
Guest User

Untitled

a guest
Feb 10th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. module("luci.controller.userpanel", package.seeall)
  2.  
  3. function index()
  4. local nw = require "luci.dispatcher"
  5. local user = nw.get_user()
  6. if user ~= "root" then -- if user is not logged in as root then ...
  7. entry({"admin", "userpanel"}, alias("admin", "userpanel", "dashboard"), "")
  8. entry({"admin", "userpanel", "dashboard"}, template("user_panel/dashboard_test"), "")
  9. entry({"admin", "userpanel", "devices"}, template("/user_panel/devices"), "")
  10. entry({"admin", "userpanel", "alert"}, template("/user_panel/alert"), "")
  11. entry({"admin", "userpanel", "help"}, template("/user_panel/help"), "")
  12.  
  13. entry({"admin", "userpanel", "dashboard", "process"}, call("action_wifi_connection"), "")
  14. entry({"admin", "userpanel", "devices", "action_kick_sta"}, call("action_kick_sta"), "")
  15. entry({"admin", "userpanel", "vpn"}, cbi("openvpn_test"), _("OpenVPNTEST") )
  16.  
  17.  
  18. entry({"admin", "userpanel", "loadwifi"}, call("loadwifi"), "")
  19.  
  20.  
  21. entry({"admin", "userpanel", "shutdown"}, call("action_shutdown"), _("Logout"), 70)
  22. entry({"admin", "userpanel", "logout"}, call("action_logout"), _("Logout"), 80)
  23. entry({"admin", "userpanel", "restart"}, call("action_restart"), _("Logout"), 90)
  24. end
  25.  
  26. end
  27.  
  28.  
  29. function action_shutdown()
  30.  
  31. end
  32. function action_logout()
  33. local dsp = require "luci.dispatcher"
  34. local utl = require "luci.util"
  35. local sid = dsp.context.authsession
  36.  
  37. if sid then
  38. utl.ubus("session", "destroy", { ubus_rpc_session = sid })
  39.  
  40. luci.http.header("Set-Cookie", "sysauth=%s; expires=%s; path=%s/" %{
  41. sid, 'Thu, 01 Jan 1970 01:00:00 GMT', dsp.build_url()
  42. })
  43. end
  44.  
  45. luci.http.redirect(dsp.build_url())
  46. end
  47.  
  48.  
  49. function action_wifi_connection()
  50. luci.http.prepare_content("text/plain")
  51. -- luci.http.write("Open a tor page")
  52. -- local enviro = luci.http.getenv()
  53. local formvs = luci.http.formvalue()
  54. -- for k,v in pairs(enviro) do
  55. -- luci.http.write(k)
  56. -- luci.http.write(' ')
  57. -- luci.http.write(v)
  58. -- luci.http.write('\n')
  59. -- end
  60. local ssid
  61. local pass
  62. local encrypt
  63. for k,v in pairs(formvs) do
  64. local formstring = k .. " : " .. v
  65. if k == "ssid" then
  66. ssid = v:gsub("%s+","*s*") -- Hack for whitespace
  67. ssid = ssid:gsub("(||)","*b*") -- Hack for brackets
  68. elseif k == "pass" then
  69. pass = v
  70. elseif k == "encrypt" then
  71. encrypt = v
  72. end
  73. end
  74.  
  75. pass = pass == nil and "" or pass
  76. -- call connection script
  77.  
  78. connect_status = luci.sys.call('sh /usr/lib/lua/shellscripts/connect.sh ' .. ssid .. ' ' .. encrypt .. ' ' .. pass) == 0 and "Success" or "Failed"
  79. luci.http.write(connect_status)
  80. end
  81.  
  82.  
  83. function action_kick_sta()
  84. luci.http.prepare_content("text/plain")
  85. formvs = luci.http.formvalue()
  86. mac = ""
  87. for k,v in pairs(formvs) do
  88. mac = mac .. v
  89. end
  90.  
  91. luci.sys.call('hostapd_cli deauthenticate ' .. mac)
  92.  
  93. luci.http.write("Success")
  94. end
  95.  
  96. function loadwifi()
  97. luci.http.prepare_content("text/plain")
  98. scan_results = luci.sys.exec("python /parse_iw.py wlan0")
  99. luci.http.write(scan_results)
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement