2 LuCI - Lua Configuration Interface
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 $Id: init.lua 6731 2011-01-14 19:44:03Z soma $
15 module("luci.controller.ahcp", package.seeall)
18 if not nixio.fs.access("/etc/config/ahcpd") then
23 luci.i18n.loadc("ahcp")
25 entry({"admin", "network", "ahcpd"}, cbi("ahcp"), luci.i18n.translate("AHCP Server"), 90).i18n = "ahcp"
26 entry({"admin", "network", "ahcpd", "status"}, call("ahcp_status"))
29 function ahcp_status()
30 local nfs = require "nixio.fs"
31 local uci = require "luci.model.uci".cursor()
32 local lsd = uci:get_first("ahcpd", "ahcpd", "lease_dir") or "/var/lib/leases"
33 local idf = uci:get_first("ahcpd", "ahcpd", "id_file") or "/var/lib/ahcpd-unique-id"
36 uid = "00:00:00:00:00:00:00:00",
40 idf = nfs.readfile(idf)
41 if idf and #idf == 8 then
42 rv.uid = "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X" %{ idf:byte(1, 8) }
45 local itr = nfs.dir(lsd)
49 if addr:match("^%d+%.%d+%.%d+%.%d+$") then
50 local s = nfs.stat(lsd .. "/" .. addr)
51 rv.leases[#rv.leases+1] = {
53 age = s and (os.time() - s.mtime) or 0
59 table.sort(rv.leases, function(a, b) return a.age < b.age end)
61 luci.http.prepare_content("application/json")
62 luci.http.write_json(rv)