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
22 entry({"admin", "network", "ahcpd"}, cbi("ahcp"), _("AHCP Server"), 90)
23 entry({"admin", "network", "ahcpd", "status"}, call("ahcp_status"))
26 function ahcp_status()
27 local nfs = require "nixio.fs"
28 local uci = require "luci.model.uci".cursor()
29 local lsd = uci:get_first("ahcpd", "ahcpd", "lease_dir") or "/var/lib/leases"
30 local idf = uci:get_first("ahcpd", "ahcpd", "id_file") or "/var/lib/ahcpd-unique-id"
33 uid = "00:00:00:00:00:00:00:00",
37 idf = nfs.readfile(idf)
38 if idf and #idf == 8 then
39 rv.uid = "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X" %{ idf:byte(1, 8) }
42 local itr = nfs.dir(lsd)
46 if addr:match("^%d+%.%d+%.%d+%.%d+$") then
47 local s = nfs.stat(lsd .. "/" .. addr)
48 rv.leases[#rv.leases+1] = {
50 age = s and (os.time() - s.mtime) or 0
56 table.sort(rv.leases, function(a, b) return a.age < b.age end)
58 luci.http.prepare_content("application/json")
59 luci.http.write_json(rv)