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