Add luci, based upon commit : ae8ddb0ca6dfe98cb842fe2c01b36c4df55a0894
[librecmc/librecmc.git] / package / luci / modules / luci-base / luasrc / view / cbi / firewall_zonelist.htm
1 <%+cbi/valueheader%>
2
3 <%-
4         local utl = require "luci.util"
5         local fwm = require "luci.model.firewall".init()
6         local nwm = require "luci.model.network".init()
7
8         local zone, net, iface
9         local zones = fwm:get_zones()
10         local value = self:formvalue(section)
11         if not value or value == "-" then
12                 value = self:cfgvalue(section) or self.default
13         end
14
15         local selected = false
16         local checked = { }
17
18         for value in utl.imatch(value) do
19                 checked[value] = true
20         end
21
22         if not next(checked) then
23                 checked[""] = true
24         end
25 -%>
26
27 <div class="cbi-dropdown" dropdown-items="5" placeholder="<%:-- please select -- %>"<%=
28         attr("name", cbid) ..
29         ifattr(self.widget == "checkbox", "multiple", "multiple") ..
30         ifattr(self.rmempty or self.optional, "optional", "optional")
31 %>>
32         <script type="item-template"><!--
33                 <li data-value="{{value}}">
34                         <span class="zonebadge" style="background:repeating-linear-gradient(45deg,rgba(204,204,204,0.5),rgba(204,204,204,0.5) 5px,rgba(255,255,255,0.5) 5px,rgba(255,255,255,0.5) 10px)">
35                                 <strong>{{value}}:</strong><em>(<%:create%>)</em>
36                         </span>
37                 </li>
38         --></script>
39         <ul>
40                 <% if self.allowlocal then %>
41                 <li data-value=""<%=ifattr(checked[""], "selected", "selected")%>>
42                         <span style="background-color:<%=fwm.zone.get_color()%>" class="zonebadge">
43                                 <strong><%:Device%></strong>
44                                 <% if self.allowany and self.allowlocal then -%>
45                                         (<%= self.alias ~= "dest"
46                                                 and translate("output") or translate("input") %>)
47                                 <%- end %>
48                         </span>
49                 </li>
50                 <% elseif self.widget ~= "checkbox" and (self.rmempty or self.optional) then %>
51                 <li data-value=""<%=ifattr(checked[""], "selected", "selected")%>>
52                         <span class="zonebadge">
53                                 <em><%:unspecified%></em>
54                         </span>
55                 </li>
56                 <% end %>
57                 <% if self.allowany then %>
58                 <li data-value="*"<%=ifattr(checked["*"], "selected", "selected")%>>
59                         <span style="background-color:<%=fwm.zone.get_color()%>" class="zonebadge">
60                                 <strong><%:Any zone%></strong>
61                                 <% if self.allowany and self.allowlocal then %>(<%:forward%>)<% end %>
62                         </span>
63                 </li>
64                 <% end %>
65                 <%
66                         for _, zone in utl.spairs(zones, function(a,b) return (zones[a]:name() < zones[b]:name()) end) do
67                                 if zone:name() ~= self.exclude then
68                                         selected = selected or (value == zone:name())
69                 %>
70                 <li<%=attr("data-value", zone:name()) .. ifattr(checked[zone:name()], "selected", "selected")%>>
71                         <span style="background-color:<%=zone:get_color()%>" class="zonebadge">
72                                 <strong><%=zone:name()%>:</strong>
73                                 <%-
74                                         local zempty = true
75                                         for _, net in ipairs(zone:get_networks()) do
76                                                 net = nwm:get_network(net)
77                                                 if net then
78                                                         zempty = false
79                                 -%>
80                                         <span class="ifacebadge<% if net:name() == self.network then %> ifacebadge-active<% end %>"><%=net:name()%>:
81                                         <%-
82                                                 local nempty = true
83                                                 for _, iface in ipairs(net:is_bridge() and net:get_interfaces() or { net:get_interface() }) do
84                                                         nempty = false
85                                         %>
86                                                 <img<%=attr("title", iface:get_i18n())%> src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" />
87                                         <% end %>
88                                         <% if nempty then %><em><%:(empty)%></em><% end -%>
89                                         </span>
90                                 <%- end end -%>
91                                 <%- if zempty then %><em><%:(empty)%></em><% end -%>
92                         </span>
93                 </li>
94                 <% end end %>
95
96                 <% if self.widget ~= "checkbox" and not self.nocreate then %>
97                 <li data-value="-">
98                         <span class="zonebadge">
99                                 <em><%:create%>:</em>
100                                 <input type="password" style="display:none" />
101                                 <input class="create-item-input" type="text" data-type="and(uciname,maxlength(11))" data-optional="true" />
102                         </span>
103                 </li>
104                 <% end %>
105         </ul>
106 </div>
107
108 <%+cbi/valuefooter%>