cbi_addforward.htm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <%-
  2. local fw = require "luci.model.firewall".init()
  3. local izl = { }
  4. local ezl = { }
  5. local _, z
  6. for _, z in ipairs(fw:get_zones()) do
  7. if z:name() ~= "wan" then
  8. izl[#izl+1] = z
  9. end
  10. if z:name() ~= "lan" then
  11. ezl[#ezl+1] = z
  12. end
  13. end
  14. -%>
  15. <div class="cbi-section-create cbi-tblsection-create">
  16. <br />
  17. <table class="cbi-section-table" style="width:810px; margin-left:5px">
  18. <tr class="cbi-section-table-titles">
  19. <th class="cbi-section-table-cell" colspan="8"><%:New port forward%>:</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"><%:Protocol%></th>
  24. <th class="cbi-section-table-cell"><%:External zone%></th>
  25. <th class="cbi-section-table-cell"><%:External port%></th>
  26. <th class="cbi-section-table-cell"><%:Internal zone%></th>
  27. <th class="cbi-section-table-cell"><%:Internal IP address%></th>
  28. <th class="cbi-section-table-cell"><%:Internal port%></th>
  29. <th class="cbi-section-table-cell"></th>
  30. </tr>
  31. <tr class="cbi-section-table-row">
  32. <td class="cbi-section-table-cell">
  33. <input type="text" class="cbi-input-text" id="_newfwd.name" name="_newfwd.name" placeholder="<%:New port forward%>" />
  34. </td>
  35. <td class="cbi-section-table-cell" style="width:110px">
  36. <select class="cbi-input-select" id="_newfwd.proto" name="_newfwd.proto">
  37. <option value="tcp udp">TCP+UDP</option>
  38. <option value="tcp">TCP</option>
  39. <option value="udp">UDP</option>
  40. <option value="other"><%:Other...%></option>
  41. </select>
  42. </td>
  43. <td class="cbi-section-table-cell" style="width:55px">
  44. <select class="cbi-input-select" id="_newfwd.extzone" name="_newfwd.extzone">
  45. <% for _, z in ipairs(ezl) do -%><option value="<%=z:name()%>"><%=z:name()%></option><%- end %>
  46. </select>
  47. </td>
  48. <td class="cbi-section-table-cell" style="width:110px">
  49. <input type="text" class="cbi-input-text" id="_newfwd.extport" name="_newfwd.extport" />
  50. </td>
  51. <td class="cbi-section-table-cell" style="width:55px">
  52. <select class="cbi-input-select" id="_newfwd.intzone" name="_newfwd.intzone">
  53. <% for _, z in ipairs(izl) do -%><option value="<%=z:name()%>"><%=z:name()%></option><%- end %>
  54. </select>
  55. </td>
  56. <td class="cbi-section-table-cell" style="width:110px">
  57. <input type="text" class="cbi-input-text" id="_newfwd.intaddr" name="_newfwd.intaddr" />
  58. </td>
  59. <td class="cbi-section-table-cell" style="width:110px">
  60. <input type="text" class="cbi-input-text" id="_newfwd.intport" name="_newfwd.intport" />
  61. </td>
  62. <td class="cbi-section-table-cell">
  63. <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
  64. </td>
  65. </tr>
  66. </table>
  67. <script type="text/javascript">//<![CDATA[
  68. cbi_validate_field('_newfwd.extport', true, 'portrange');
  69. cbi_validate_field('_newfwd.intaddr', true, 'host');
  70. cbi_validate_field('_newfwd.intport', true, 'portrange');
  71. cbi_combobox_init('_newfwd.intaddr', {
  72. <% first = true; luci.sys.net.ipv4_hints(function(ip, name) %>
  73. <%- if first then first = false else %>,<% end -%>'<%=ip%>': '<%=ip%> (<%=name%>)'
  74. <%- end) %> }, '', '<%: -- custom -- %>');
  75. cbi_bind(document.getElementById('_newfwd.extport'), 'blur',
  76. function() {
  77. var n = document.getElementById('_newfwd.name');
  78. var p = document.getElementById('_newfwd.proto');
  79. var i = document.getElementById('_newfwd.intport');
  80. var hints = {
  81. /* port name 0=both, 1=tcp, 2=udp, 3=other */
  82. 21: [ 'FTP', 1 ],
  83. 22: [ 'SSH', 1 ],
  84. 53: [ 'DNS', 0 ],
  85. 80: [ 'HTTP', 1 ],
  86. 443: [ 'HTTPS', 1 ],
  87. 3389: [ 'RDP', 1 ],
  88. 5900: [ 'VNC', 1 ],
  89. };
  90. if (!this.className.match(/invalid/))
  91. {
  92. if (!i.value) i.value = this.value;
  93. var hint = hints[this.value || 0] || hints[i.value || 0];
  94. if (hint)
  95. {
  96. p.selectedIndex = hint[1];
  97. if (!n.value)
  98. n.value = hint[0];
  99. }
  100. else if (!n.value)
  101. {
  102. n.value = 'Forward' + this.value;
  103. }
  104. }
  105. });
  106. cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>', true, 'uciname');
  107. //]]></script>
  108. </div>