0d20d67223bdfd0d43dbb31ca7db706925edf603
[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 local routes6 = luci.sys.net.routes6()
18
19 if not arg or not arg[1] then
20         local routes = luci.sys.net.routes()
21
22         v = m:section(Table, routes, translate("a_n_routes_kernel4"))
23
24         net = v:option(DummyValue, "iface", translate("network"))
25         function net.cfgvalue(self, section)
26                 return luci.tools.webadmin.iface_get_network(routes[section].device)
27                  or routes[section].device
28         end
29
30         target  = v:option(DummyValue, "target", translate("target"))
31         function target.cfgvalue(self, section)
32                 return routes[section].dest:network():string()
33         end
34
35         netmask = v:option(DummyValue, "netmask", translate("netmask"))
36         function netmask.cfgvalue(self, section)
37                 return routes[section].dest:mask():string()
38         end
39
40         gateway = v:option(DummyValue, "gateway", translate("gateway"))
41         function gateway.cfgvalue(self, section)
42                 return routes[section].gateway:string()
43         end
44
45         metric = v:option(DummyValue, "Metric", translate("metric"))
46
47         if routes6 then
48                 v = m:section(Table, routes6, translate("a_n_routes_kernel6"))
49
50                 net = v:option(DummyValue, "iface", translate("network"))
51                 function net.cfgvalue(self, section)
52                         return luci.tools.webadmin.iface_get_network(routes6[section].device)
53                          or routes6[section].device
54                 end
55
56                 target  = v:option(DummyValue, "target", translate("target"))
57                 function target.cfgvalue(self, section)
58                         return routes6[section].dest:string()
59                 end
60
61                 gateway = v:option(DummyValue, "gateway", translate("gateway6"))
62                 function gateway.cfgvalue(self, section)
63                         return routes6[section].source:string()
64                 end
65
66                 metric = v:option(DummyValue, "Metric", translate("metric"))
67             function metric.cfgvalue(self, section)
68                 return string.format( "%08X", routes6[section].metric )
69             end
70         end
71 end
72
73
74 s = m:section(TypedSection, "route", translate("a_n_routes_static4"))
75 s.addremove = true
76 s.anonymous = true
77
78 s.template  = "cbi/tblsection"
79
80 iface = s:option(ListValue, "interface", translate("interface"))
81 luci.tools.webadmin.cbi_add_networks(iface)
82
83 if not arg or not arg[1] then
84         net.titleref = iface.titleref
85 end
86
87 s:option(Value, "target", translate("target"), translate("a_n_r_target1"))
88
89 s:option(Value, "netmask", translate("netmask"), translate("a_n_r_netmask1")).rmemepty = true
90
91 s:option(Value, "gateway", translate("gateway"))
92
93 if routes6 then
94         s = m:section(TypedSection, "route6", translate("a_n_routes_static6"))
95         s.addremove = true
96         s.anonymous = true
97
98         s.template  = "cbi/tblsection"
99
100         iface = s:option(ListValue, "interface", translate("interface"))
101         luci.tools.webadmin.cbi_add_networks(iface)
102
103         if not arg or not arg[1] then
104                 net.titleref = iface.titleref
105         end
106
107         s:option(Value, "target", translate("target"), translate("a_n_r_target6"))
108
109         s:option(Value, "gateway", translate("gateway6")).rmempty = true
110 end
111
112
113 return m