ec659a521ff1f25e97077e8cf9f3faf5226da950
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / routes.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
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
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 require("luci.tools.webadmin")
15 m = Map("network", translate("a_n_routes"), translate("a_n_routes1"))
16
17 if not arg or not arg[1] then
18         local routes = luci.sys.net.routes()
19         
20         v = m:section(TypedSection, "_virtual", translate("a_n_routes_kernel4"))
21         v.anonymous = true
22         v.rowcolors = true
23         v.template  = "cbi/tblsection"
24         
25         function v.cfgsections(self)
26                 local sections = {}
27                 for i=1,#routes do
28                         table.insert(sections, i)
29                 end
30                 return sections
31         end
32         
33         net = v:option(DummyValue, "iface", translate("network"))
34         function net.cfgvalue(self, section)
35                 return luci.tools.webadmin.iface_get_network(routes[section].Iface)
36                  or routes[section].Iface
37         end
38         
39         target  = v:option(DummyValue, "target", translate("target"))
40         function target.cfgvalue(self, section)
41                 return luci.ip.Hex(routes[section].Destination, 32):string()
42         end
43         
44         netmask = v:option(DummyValue, "netmask", translate("netmask"))
45         function netmask.cfgvalue(self, section)
46                 return luci.ip.Hex(routes[section].Mask, 32):string()
47         end
48         
49         gateway = v:option(DummyValue, "gateway", translate("gateway"))
50         function gateway.cfgvalue(self, section)
51                 return luci.ip.Hex(routes[section].Gateway, 32):string()
52         end
53         
54         metric = v:option(DummyValue, "metric", translate("metric"))
55         function metric.cfgvalue(self, section)
56                 return routes[section].Metric
57         end
58 end
59
60
61 s = m:section(TypedSection, "route", translate("a_n_routes_static"))
62 s.addremove = true
63 s.anonymous = true
64 s.template  = "cbi/tblsection"
65
66 iface = s:option(ListValue, "interface", translate("interface"))
67 luci.tools.webadmin.cbi_add_networks(iface)
68
69 if not arg or not arg[1] then
70         net.titleref = iface.titleref
71 end
72
73 s:option(Value, "target", translate("target"), translate("a_n_r_target1"))
74
75 s:option(Value, "netmask", translate("netmask"), translate("a_n_r_netmask1")).rmemepty = true
76
77 s:option(Value, "gateway", translate("gateway"))
78
79 return m