d7b8519686de746113df06991923deaace259911
[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(Table, routes, translate("a_n_routes_kernel4"))
21         
22         net = v:option(DummyValue, "iface", translate("network"))
23         function net.cfgvalue(self, section)
24                 return luci.tools.webadmin.iface_get_network(routes[section].Iface)
25                  or routes[section].Iface
26         end
27         
28         target  = v:option(DummyValue, "target", translate("target"))
29         function target.cfgvalue(self, section)
30                 return luci.ip.Hex(routes[section].Destination, 32):string()
31         end
32         
33         netmask = v:option(DummyValue, "netmask", translate("netmask"))
34         function netmask.cfgvalue(self, section)
35                 return luci.ip.Hex(routes[section].Mask, 32):string()
36         end
37         
38         gateway = v:option(DummyValue, "gateway", translate("gateway"))
39         function gateway.cfgvalue(self, section)
40                 return luci.ip.Hex(routes[section].Gateway, 32):string()
41         end
42         
43         metric = v:option(DummyValue, "Metric", translate("metric"))
44 end
45
46
47 s = m:section(TypedSection, "route", translate("a_n_routes_static"))
48 s.addremove = true
49 s.anonymous = true
50
51 function s.render(...)
52         luci.model.uci.load_config("network")
53         TypedSection.render(...)
54 end
55
56 s.template  = "cbi/tblsection"
57
58 iface = s:option(ListValue, "interface", translate("interface"))
59 luci.tools.webadmin.cbi_add_networks(iface)
60
61 if not arg or not arg[1] then
62         net.titleref = iface.titleref
63 end
64
65 s:option(Value, "target", translate("target"), translate("a_n_r_target1"))
66
67 s:option(Value, "netmask", translate("netmask"), translate("a_n_r_netmask1")).rmemepty = true
68
69 s:option(Value, "gateway", translate("gateway"))
70
71 return m