firewall_zonelist.htm 3.5 KB

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