cbi_addsnat.htm 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <%
  2. local fw = require "luci.model.firewall".init()
  3. local nw = require "luci.model.network".init()
  4. local zones = fw:get_zones()
  5. local keys, vals, a, k, v = {}, {}
  6. for k, v in ipairs(nw:get_interfaces()) do
  7. for k, a in ipairs(v:ipaddrs()) do
  8. keys[#keys+1] = a:host():string()
  9. vals[#vals+1] = '%s (%s)' %{ a:host(), v:shortname() }
  10. end
  11. end
  12. %>
  13. <% if #zones > 1 then %>
  14. <h4><%:New source NAT%></h4>
  15. <div class="table">
  16. <div class="tr cbi-section-table-titles">
  17. <div class="th"><%:Name%></div>
  18. <div class="th"><%:Source zone%></div>
  19. <div class="th"><%:Destination zone%></div>
  20. <div class="th"><%:To source IP%></div>
  21. <div class="th"><%:To source port%></div>
  22. <div class="th"></div>
  23. </div>
  24. <div class="tr">
  25. <div class="td">
  26. <input type="text" class="cbi-input-text" id="_newsnat.name" name="_newsnat.name" placeholder="<%:New SNAT rule%>" />
  27. </div>
  28. <div class="td">
  29. <select class="cbi-input-text" id="_newsnat.src" name="_newsnat.src">
  30. <% local k, v; for k, v in ipairs(fw:get_zones()) do -%>
  31. <option<%=ifattr(v:name() == "lan", "selected", "selected")%> value="<%=v:name()%>"><%=v:name()%></option>
  32. <%- end %>
  33. </select>
  34. </div>
  35. <div class="td">
  36. <select class="cbi-input-text" id="_newsnat.dest" name="_newsnat.dest">
  37. <% local k, v; for k, v in ipairs(fw:get_zones()) do -%>
  38. <option<%=ifattr(v:name() == "wan", "selected", "selected")%> value="<%=v:name()%>"><%=v:name()%></option>
  39. <%- end %>
  40. </select>
  41. </div>
  42. <div class="td">
  43. <input type="text" class="cbi-input-text" id="_newsnat.dip" name="_newsnat.dip" placeholder="<%:Do not rewrite%>" data-type="ip4addr" data-optional="true"<%=
  44. ifattr(#keys > 0, "data-choices", { keys, vals })
  45. %> />
  46. </div>
  47. <div class="td">
  48. <input type="text" class="cbi-input-text" id="_newsnat.dport" name="_newsnat.dport" placeholder="<%:Do not rewrite%>" data-type="portrange" data-optional="true" />
  49. </div>
  50. <div class="td bottom">
  51. <input type="submit" class="cbi-button cbi-button-link" name="_newsnat.submit" value="<%:Add and edit...%>" />
  52. </div>
  53. </div>
  54. </div>
  55. <% else %>
  56. <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
  57. <% end %>