Changeset 6952

Show
Ignore:
Timestamp:
03/13/11 15:00:45 (2 years ago)
Author:
jow
Message:

modules/admin-full: use luci.tools.status in network controller

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/modules/admin-full/luasrc/controller/admin/network.lua

    r6923 r6952  
    212212            local info 
    213213            local dev  = net:ifname() 
    214             local data = { id = iface, uptime = net:uptime() } 
     214            local data = { 
     215                id       = iface, 
     216                proto    = net:proto(), 
     217                uptime   = net:uptime(), 
     218                gwaddr   = net:gwaddr(), 
     219                dnsaddrs = net:dnsaddrs() 
     220            } 
    215221            for _, info in ipairs(nixio.getifaddrs()) do 
    216222                local name = info.name:match("[^:]+") 
     
    281287 
    282288        luci.sys.call("env -i /sbin/ifup %q >/dev/null 2>/dev/null" % iface) 
    283  
    284         require "luci.fs" 
    285         if luci.fs.access("/etc/config/radvd") then 
    286             luci.sys.call("/etc/init.d/radvd restart >/dev/null 2>/dev/null") 
    287         end 
    288  
    289289        luci.http.status(200, "Reconnected") 
    290290        return 
     
    329329    local netm  = require "luci.model.network".init() 
    330330    local path = luci.dispatcher.context.requestpath 
    331     local arp  = luci.sys.net.arptable() 
    332331    local rv   = { } 
    333332 
     
    364363 
    365364function lease_status() 
    366     local rv = { } 
    367     local leasefile = "/var/dhcp.leases" 
    368  
    369     local uci = require "luci.model.uci".cursor() 
    370     local nfs = require "nixio.fs" 
    371  
    372     uci:foreach("dhcp", "dnsmasq", 
    373         function(s) 
    374             if s.leasefile and nfs.access(s.leasefile) then 
    375                 leasefile = s.leasefile 
    376                 return false 
    377             end 
    378         end) 
    379  
    380     local fd = io.open(leasefile, "r") 
    381     if fd then 
    382         while true do 
    383             local ln = fd:read("*l") 
    384             if not ln then 
    385                 break 
    386             else 
    387                 local ts, mac, ip, name = ln:match("^(%d+) (%S+) (%S+) (%S+)") 
    388                 if ts and mac and ip and name then 
    389                     rv[#rv+1] = { 
    390                         expires  = os.difftime(tonumber(ts) or 0, os.time()), 
    391                         macaddr  = mac, 
    392                         ipaddr   = ip, 
    393                         hostname = (name ~= "*") and name 
    394                     } 
    395                 end 
    396             end 
    397         end 
    398         fd:close() 
    399     end 
     365    local s = require "luci.tools.status" 
    400366 
    401367    luci.http.prepare_content("application/json") 
    402     luci.http.write_json(rv) 
     368    luci.http.write_json(s.dhcp_leases()) 
    403369end 
    404370