luci實現的wifidog認證服務

來源:互聯網
上載者:User

利用luci寫了個wifidog認證服務,實現直接openwrt路由器本地認證。直接安裝ipk安裝包,然後修改/etc/wifidog.conf檔案(需要先安裝wifidog),如下:

AuthServer {    Hostname 192.168.1.1    Path /cgi-bin/luci/wdas/    MsgScriptPathFragment gw_message/?}

主要源碼:

--[[wdas -- wifidog auth servermail: xzm2@qq.comQQ: 529698939]]--module("luci.controller.wifidog.wdas", package.seeall)local session = require "luci.wifidogsession"local http = luci.httplocal translate = luci.i18n.translatelocal wdcfg = require("luci.wifidogconfig")function index()    local page    = node("wdas")    page.target   = alias("wdas", "login")    page.order    = 90    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"))endfunction login()    --login/?gw_id=&gw_address=&gw_port=&mac=&url=    luci.template.render("wifidog/wdas_login")endfunction logincheck()    local username, password = wdcfg.auth.username, 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("application/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(16)        local sdt = {id=id, addr=addr, port=port, mac=mac, url=url, timestamp=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:"http://' .. 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    endendfunction 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 = http.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")    endendfunction ping()    --ping/?gw_id=&sys_load=&sys_memfree=&sys_load=&wifidog_uptime=    local id, sys_uptime, sys_memfree, sys_load, wifidog_uptime    id = http.formvalue("gw_id")    sys_uptime = http.formvalue("sys_uptime")    sys_memfree = http.formvalue("sys_memfree")    sys_load = http.formvalue("sys_load")    wifidog_uptime = http.formvalue("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}")    endendfunction portal()    --portal/?gw_id=%s    local token, sdt, url    token = http.getcookie("wdastok")    sdt = token and session.read(token)    url = sdt and sdt.url or "http://www.baidu.com"    http.redirect(url)endfunction gw_message()    local msg = http.formvalue("message")    http.write(msg)end

源碼編譯說明:

modules目錄下的wifidogauth目錄放到./feeds/luci/modules/下。

po/zh_CN/wifidogauth.po檔案放到./feeds/luci/po/zh_CN/下。

./feeds/luci/contrib/package/luci/Makefile增加如下語句:

(eval (eval (call module,wifidogauth,wifidog auth server,+luci-base))

然後 make menuconfig在luci–>Modules下找到luci-mod-wifidogauth選上。

make package/feeds/luci/luci/compile V=s

認證的使用者名稱、密碼的設定檔路徑/etc/config/wifidogauth

轉載自:https://my.oschina.net/osbin/blog/360779

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.