cbi_addsnat.htm 2.8 KB

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