Changeset 2186


Ignore:
Timestamp:
Sep 19, 2012, 3:29:04 PM (7 years ago)
Author:
matthijs
Message:

luci-openvpn: Don't error out when OpenVPN is not running.

When OpenVPN is not running, /tmp/openvpn.clients does not exist,
previously causing a lua error. Now, luci just skips reading that file,
assuming all clients are offline.

This should occur in normal operation, but it doesn't hurt making this a
bit more robust.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/luci/applications/luci-openvpn/luasrc/model/cbi/openvpn.lua

    r2185 r2186  
    4646-- Make a list of connected clients and their IP addresses
    4747local clients = {}
    48 for line in io.lines("/tmp/openvpn.clients") do
    49         local first, last, name, ip = line:find("^CLIENT_LIST,([^,]*),[^,]*,([^,]*),.*")
    50         if first then
    51                 clients[name] = ip
     48local f = io.open("/tmp/openvpn.clients", "r")
     49if f then
     50        for line in f:lines() do
     51                local first, last, name, ip = line:find("^CLIENT_LIST,([^,]*),[^,]*,([^,]*),.*")
     52                if first then
     53                        clients[name] = ip
     54                end
    5255        end
    5356end
Note: See TracChangeset for help on using the changeset viewer.