modules/admin-core: extend network scheme to cover ipv6 routes and metric options
[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
45
46         local routes6 = luci.sys.net.routes6()
47
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].dst_ip .. "/" .. routes6[section].dst_prefix
59         end
60 --[[
61         netmask = v:option(DummyValue, "prefix", translate("prefix"))
62         function netmask.cfgvalue(self, section)
63                 return luci.ip.Hex(routes6[section].Mask, 32):string()
64         end
65 ]]
66         gateway = v:option(DummyValue, "gateway", translate("gateway6"))
67         function gateway.cfgvalue(self, section)
68                 return routes6[section].src_ip .. "/" .. routes6[section].src_prefix
69         end
70
71         metric = v:option(DummyValue, "Metric", translate("metric"))
72     function metric.cfgvalue(self, section)
73         return string.format( "%08X", routes6[section].metric )
74     end
75 end
76
77
78 s = m:section(TypedSection, "route", translate("a_n_routes_static"))
79 s.addremove = true
80 s.anonymous = true
81
82 s.template  = "cbi/tblsection"
83
84 iface = s:option(ListValue, "interface", translate("interface"))
85 luci.tools.webadmin.cbi_add_networks(iface)
86
87 if not arg or not arg[1] then
88         net.titleref = iface.titleref
89 end
90
91 s:option(Value, "target", translate("target"), translate("a_n_r_target1"))
92
93 s:option(Value, "netmask", translate("netmask"), translate("a_n_r_netmask1")).rmemepty = true
94
95 s:option(Value, "gateway", translate("gateway"))
96
97
98 s = m:section(TypedSection, "route6", translate("a_n_routes_static6"))
99 s.addremove = true
100 s.anonymous = true
101
102 s.template  = "cbi/tblsection"
103
104 iface = s:option(ListValue, "interface", translate("interface"))
105 luci.tools.webadmin.cbi_add_networks(iface)
106
107 if not arg or not arg[1] then
108         net.titleref = iface.titleref
109 end
110
111 s:option(Value, "target", translate("target"), translate("a_n_r_target6"))
112
113 s:option(Value, "gateway", translate("gateway6")).rmempty = true
114
115
116 return m