020589f8b16092c5c01db28930d2af5d91e83f8e
[project/luci.git] / protocols / core / luasrc / tools / proto.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2012 Jo-Philipp Wich <xm@subsignal.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 ]]--
13
14 module("luci.tools.proto", package.seeall)
15
16 local uci = require "luci.model.uci".cursor()
17 local net = require "luci.model.network"
18
19 function opt_macaddr(s, ifc, ...)
20         local v = luci.cbi.Value
21         local o = s:taboption("advanced", v, "macaddr", ...)
22
23         o.placeholder = ifc and ifc:mac()
24         o.datatype    = "macaddr"
25
26         function o.cfgvalue(self, section)
27                 local w = ifc and ifc:get_wifinet()
28                 if w then
29                         return w:get("macaddr")
30                 else
31                         return v.cfgvalue(self, section)
32                 end
33         end
34
35         function o.write(self, section, value)
36                 local w = ifc and ifc:get_wifinet()
37                 if w then
38                         w:set("macaddr", value)
39                 elseif value then
40                         v.write(self, section, value)
41                 else
42                         v.remove(self, section)
43                 end
44         end
45
46         function o.remove(self, section)
47                 self:write(self, section, nil)
48         end
49 end