Luci implementation of WiFiDog certification services

Source: Internet
Author: User
Tags auth i18n require

Use Luci to write a WiFiDog authentication service, realize the direct OpenWrt router local authentication. Install the IPK installation package directly, and then modify the/etc/wifidog.conf file (you need to install WiFiDog first), as follows:

authserver {
    Hostname 192.168.1.1
    path/cgi-bin/luci/wdas/
    msgscriptpathfragment gw_message/?
}

Main Source:

--[[Wdas--wifidog auth server mail:xzm2@qq.com qq:529698939]]--module ("Luci.controller.wifidog.wdas", package.seeal  L) Local session = require "luci.wifidogsession" local http = luci.http Local translate = Luci.i18n.translate local wdcfg = Require ("Luci.wifidogconfig") function index () local page = node ("Wdas") Page.target = Alias ("Wdas", "Log

    In ") Page.order = page.i18n =" Wifidogauth "Page.setuser =" nobody "Page.setgroup =" Nogroup " Entry ({"Wdas", "Login"}, call ("Login")) entry ({"Wdas", "Logincheck"}, Call ("Logincheck")) entry ({"Wdas", "auth"}, Call ("auth")) entry ({"Wdas", "ping"}, call ("ping")) entry ({"Wdas", "Portal"}, call ("Portal")) entry ({"Wdas", " Gw_message "}, Call (" Gw_message ")) End Function login ()--login/?gw_id=&gw_address=&gw_port=&mac=& Url= Luci.template.render ("wifidog/wdas_login") End Function Logincheck () local username, password = wdcfg.auth.u Sername, Wdcfg.auth.password
    Local user, PWD, id, addr, port, Mac, URL, token user = Http.formvalue ("user") pwd = Http.formvalue ("pwd") id = http.formvalue ("gw_id") addr = Http.formvalue ("gw_address") port = Http.formvalue ("Gw_port") Mac = http . Formvalue ("mac") url = http.formvalue ("url") token = Http.getcookie ("Wdastok") http.prepare_content ("Applicat Ion/json ") if addr and port and Mac and (user = = username) and (pwd = = password) Then token = token and token: Match ("^[a-f0-9]*$") or Luci.sys.uniqueid (+) Local SDT = {id=id, addr=addr, Port=port, Mac=mac, Url=url, Timestam P=luci.sys.uptime ()} Local Path = (http.getenv ("Script_name") or ""): " /wdas "Session.write (token, SDT) http.header (" Set-cookie "," wdastok= ": Token: "; Path= ". Path) http.write (' {url: '/'/') '. Addr. ':' ..
            Port.. '/wifidog/auth?token= '. token. '} ') else if addr and port and Mac then Http.write (' {error: "' .. Translate ("Invalid username or password."). '} ') Else Http.write (' {error: ') '. Translate ("Invalid parameter.").
    '} ') end End Function auth ()--auth/?stage=&ip=&mac=&token=&incoming=&outgoing=
    Local stage, IP, Mac, token, incoming, outgoing stage = Http.formvalue ("stage") IP = http.formvalue ("IP") Mac = Http.formvalue ("Mac") token = Http.formvalue ("token") incoming = Http.formvalue ("incoming") outgoing = h
    Ttp.formvalue ("outgoing") token = token and Token:match ("^[a-f0-9]*$") Local SDT = token and session.read (token) 
If token and SDT and (Mac = = Sdt.mac) then Http.write ("Auth:1") Else Http.write ("auth:0") end End Function Ping ()--ping/?gw_id=&sys_load=&sys_memfree=&sys_load=&wifidog_uptime= local ID, sy S_uptime, Sys_memfree, sys_load, wifidog_uptime id = http.formvalue ("gw_id") Sys_uptime = Http.formvalue ("Sys_upti ME ") Sys_memfree = Http.formvalue (" Sys_memfree ") Sys_load = Http.formvalue (" sys_load ") Wifidog_uptime = Http.fo Rmvalue ("Wifidog_uptime") if ID and Sys_uptime and Sys_memfree and Sys_load and Wifidog_uptime then Http.write ("Pong") Else Http.write ("{error:2}") End End Function portal ()--portal/?gw_id=%s local token, s DT, URL token = Http.getcookie ("Wdastok") SDT = token and session.read (token) URL = SDT and Sdt.url or "http:/ /www.baidu.com "http.redirect (URL) End Function gw_message () Local msg = Http.formvalue (" message ") Http.write
 (msg) End

Source Code Compilation Instructions:

The Wifidogauth directory under the modules directory is placed under the./feeds/luci/modules/.

The Po/zh_cn/wifidogauth.po file is placed under the./feeds/luci/po/zh_cn/.

The./feeds/luci/contrib/package/luci/makefile adds the following statement:

(Eval (call Module,wifidogauth,wifidog auth server,+luci-base)

Then make Menuconfig find the Luci-mod-wifidogauth on the luci–>modules.

Make Package/feeds/luci/luci/compile V=s

The profile path of the authenticated user name and password/etc/config/wifidogauth

Reprinted from: https://my.oschina.net/osbin/blog/360779

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.