be6629774fda4f9b830be0180db6757bf724014f
[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 function metric.cfgvalue(self, section)
47 return routes[section].metric
48 end
49
50 if routes6 then
51 v = m:section(Table, routes6, translate("a_n_routes_kernel6"))
52
53 net = v:option(DummyValue, "iface", translate("network"))
54 function net.cfgvalue(self, section)
55 return luci.tools.webadmin.iface_get_network(routes6[section].device)
56 or routes6[section].device
57 end
58
59 target = v:option(DummyValue, "target", translate("target"))
60 function target.cfgvalue(self, section)
61 return routes6[section].dest:string()
62 end
63
64 gateway = v:option(DummyValue, "gateway", translate("gateway6"))
65 function gateway.cfgvalue(self, section)
66 return routes6[section].source:string()
67 end
68
69 metric = v:option(DummyValue, "metric", translate("metric"))
70 function metric.cfgvalue(self, section)
71 return string.format( "%08X", routes6[section].metric )
72 end
73 end
74 end
75
76
77 s = m:section(TypedSection, "route", translate("a_n_routes_static4"))
78 s.addremove = true
79 s.anonymous = true
80
81 s.template = "cbi/tblsection"
82
83 iface = s:option(ListValue, "interface", translate("interface"))
84 luci.tools.webadmin.cbi_add_networks(iface)
85
86 if not arg or not arg[1] then
87 net.titleref = iface.titleref
88 end
89
90 s:option(Value, "target", translate("target"), translate("a_n_r_target1"))
91
92 s:option(Value, "netmask", translate("netmask"), translate("a_n_r_netmask1")).rmemepty = true
93
94 s:option(Value, "gateway", translate("gateway"))
95
96 if routes6 then
97 s = m:section(TypedSection, "route6", translate("a_n_routes_static6"))
98 s.addremove = true
99 s.anonymous = true
100
101 s.template = "cbi/tblsection"
102
103 iface = s:option(ListValue, "interface", translate("interface"))
104 luci.tools.webadmin.cbi_add_networks(iface)
105
106 if not arg or not arg[1] then
107 net.titleref = iface.titleref
108 end
109
110 s:option(Value, "target", translate("target"), translate("a_n_r_target6"))
111
112 s:option(Value, "gateway", translate("gateway6")).rmempty = true
113 end
114
115
116 return m