cbi_addrule.htm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <%
  2. local fw = require "luci.model.firewall".init()
  3. local wz = fw:get_zone("wan")
  4. local lz = fw:get_zone("lan")
  5. %>
  6. <div class="cbi-section-create cbi-tblsection-create">
  7. <% if wz and lz then %>
  8. <br />
  9. <table class="cbi-section-table" style="margin-left:5px">
  10. <tr class="cbi-section-table-titles">
  11. <th class="cbi-section-table-cell left" colspan="4"><%:Open ports on router%>:</th>
  12. </tr>
  13. <tr class="cbi-section-table-descr">
  14. <th class="cbi-section-table-cell"><%:Name%></th>
  15. <th class="cbi-section-table-cell"><%:Protocol%></th>
  16. <th class="cbi-section-table-cell"><%:External port%></th>
  17. <th class="cbi-section-table-cell"></th>
  18. </tr>
  19. <tr class="cbi-section-table-row">
  20. <td class="cbi-section-table-cell" style="width:130px">
  21. <input type="text" class="cbi-input-text" id="_newopen.name" name="_newopen.name" placeholder="<%:New input rule%>" />
  22. </td>
  23. <td class="cbi-section-table-cell" style="width:110px">
  24. <select class="cbi-input-select" id="_newopen.proto" name="_newopen.proto">
  25. <option value="tcp udp">TCP+UDP</option>
  26. <option value="tcp">TCP</option>
  27. <option value="udp">UDP</option>
  28. <option value="other"><%:Other...%></option>
  29. </select>
  30. </td>
  31. <td class="cbi-section-table-cell" style="width:110px">
  32. <input type="text" class="cbi-input-text" id="_newopen.extport" name="_newopen.extport" />
  33. </td>
  34. <td class="cbi-section-table-cell left">
  35. <input type="submit" class="cbi-button cbi-button-add" name="_newopen.submit" value="<%:Add%>" />
  36. </td>
  37. </tr>
  38. </table>
  39. <table class="cbi-section-table" style="margin-left:5px">
  40. <tr class="cbi-section-table-titles">
  41. <th class="cbi-section-table-cell left" colspan="6"><br /><%:New forward rule%>:</th>
  42. </tr>
  43. <tr class="cbi-section-table-descr">
  44. <th class="cbi-section-table-cell"><%:Name%></th>
  45. <th class="cbi-section-table-cell"><%:Source zone%></th>
  46. <th class="cbi-section-table-cell"><%:Destination zone%></th>
  47. <th class="cbi-section-table-cell"></th>
  48. </tr>
  49. <tr class="cbi-section-table-row">
  50. <td class="cbi-section-table-cell" style="width:130px">
  51. <input type="text" class="cbi-input-text" id="_newfwd.name" name="_newfwd.name" placeholder="<%:New forward rule%>" />
  52. </td>
  53. <td class="cbi-section-table-cell" style="width:110px">
  54. <select class="cbi-input-text" id="_newfwd.src" name="_newfwd.src">
  55. <% local k, v; for k, v in ipairs(fw:get_zones()) do -%>
  56. <option<%=ifattr(v:name() == "lan", "selected", "selected")%> value="<%=v:name()%>"><%=v:name()%></option>
  57. <%- end %>
  58. </select>
  59. </td>
  60. <td class="cbi-section-table-cell" style="width:110px">
  61. <select class="cbi-input-text" id="_newfwd.dest" name="_newfwd.dest">
  62. <% local k, v; for k, v in ipairs(fw:get_zones()) do -%>
  63. <option<%=ifattr(v:name() == "wan", "selected", "selected")%> value="<%=v:name()%>"><%=v:name()%></option>
  64. <%- end %>
  65. </select>
  66. </td>
  67. <td class="cbi-section-table-cell left">
  68. <input type="submit" class="cbi-button cbi-button-link" name="_newfwd.submit" value="<%:Add and edit...%>" />
  69. </td>
  70. </tr>
  71. </table>
  72. <script type="text/javascript">//<![CDATA[
  73. cbi_validate_field('_newopen.extport', true, 'list(neg(portrange))');
  74. cbi_bind(document.getElementById('_newopen.extport'), 'blur',
  75. function() {
  76. var n = document.getElementById('_newopen.name');
  77. var p = document.getElementById('_newopen.proto');
  78. var hints = {
  79. /* port name 0=both, 1=tcp, 2=udp, 3=other */
  80. 22: [ 'SSH', 1 ],
  81. 53: [ 'DNS', 0 ],
  82. 80: [ 'HTTP', 1 ],
  83. 443: [ 'HTTPS', 1 ],
  84. };
  85. if (!this.className.match(/invalid/))
  86. {
  87. var hint = hints[this.value || 0];
  88. if (hint)
  89. {
  90. p.selectedIndex = hint[1];
  91. if (!n.value)
  92. n.value = hint[0];
  93. }
  94. else if (!n.value && this.value)
  95. {
  96. n.value = 'Open' + this.value;
  97. }
  98. }
  99. });
  100. cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>', true, 'uciname');
  101. //]]></script>
  102. <% else %>
  103. <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
  104. <% end %>
  105. </div>