portforward.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  6. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  7. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  8. <title>UPnP Port Forward</title>
  9. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  10. <style>
  11. </style>
  12. </head>
  13. <body>
  14. <br>
  15. <div class="ui container">
  16. <div class="ui header">
  17. Port Forwarding
  18. <div class="sub header">Manual UPnP Port Forwarding / Virtual Server</div>
  19. </div>
  20. <div class="ui divider"></div>
  21. <div id="errormessagedialog" class="ui red message" style="display:none;">
  22. <h4 class="ui header">
  23. <i class="remove icon"></i>
  24. <div class="content">
  25. <span id="errmsg"></span>
  26. <div class="sub header"><p>If you are sure you have enabled UPnP services in your startup parameter, it might cause by the ArozOS was unable to discover your UPnP router in the local area network. <br>Please restart your router and ArozOS system and try again.</p></div>
  27. </div>
  28. </h4>
  29. </div>
  30. <div>
  31. <button class="ui green basic small button" onclick="toggleNewRule();"><i class="add icon"></i> Add</button>
  32. <button class="ui red basic small button" onclick="deleteSelected();"><i class="trash icon"></i> Remove</button>
  33. </div>
  34. <div id="addRule" class="ui segment" style="display: none;">
  35. <h4>Add New Port Forward Rule</h4>
  36. <form class="ui form" onsubmit="handleNewRule(event)">
  37. <div class="field">
  38. <label>Port Number</label>
  39. <input type="number" id="portnum" name="port" placeholder="8081" min="1" max="65535">
  40. </div>
  41. <div class="field">
  42. <label>Forward Rule Name</label>
  43. <input type="text" id="polyname" name="polcyname" placeholder="Unnamed Forwarding Rule">
  44. <small>An unique name that register to the router UPnP client list for administration purposes. Usually a short sentence that describe the reason you forward this port.</small>
  45. </div>
  46. <button class="ui right floated button" onclick="toggleNewRule(event);">Cancel</button>
  47. <button class="ui green right floated button" type="submit"><i class="add icon"></i> Add Rule</button>
  48. <br><br>
  49. </form>
  50. </div>
  51. <table class="ui celled table">
  52. <thead>
  53. <tr>
  54. <th></th>
  55. <th>Service</th>
  56. <th>External Port</th>
  57. <th>Protocol</th>
  58. <th>Modify</th>
  59. </tr>
  60. </thead>
  61. <tbody id="pfwlist">
  62. </tbody>
  63. </table>
  64. </div>
  65. <script>
  66. initPortForwardList();
  67. //Submit the new rule
  68. function handleNewRule(e){
  69. e.preventDefault();
  70. var portNumber = $("#portnum").val();
  71. var polyname = $("#polyname").val();
  72. //Create port forward rule
  73. $.ajax({
  74. url: "../../system/network/portforward",
  75. data: {opr: "add", port: portNumber, name: polyname},
  76. success: function(data){
  77. if (data.error !== undefined){
  78. alert(data.error);
  79. }else{
  80. //Refresh list
  81. initPortForwardList();
  82. //Hide add new interface
  83. $("#addRule").slideUp();
  84. }
  85. }
  86. })
  87. }
  88. function toggleNewRule(event){
  89. if (event != undefined){
  90. event.preventDefault();
  91. }
  92. $("#addRule").stop().finish().slideToggle();
  93. }
  94. function initPortForwardList(){
  95. $.ajax({
  96. url: "../../system/network/portforward",
  97. data: {},
  98. success: function(data){
  99. $("#pfwlist").html("");
  100. if (data.error !== undefined){
  101. $('button').addClass("disabled");
  102. $("#errmsg").text(data.error);
  103. $("#errormessagedialog").show();
  104. return
  105. }else{
  106. data.forEach(rule => {
  107. $("#pfwlist").append(`<tr>`);
  108. if (rule.ReadOnly == false){
  109. $("#pfwlist").append(`
  110. <td class="collapsing" data-label="">
  111. <div class="ui fitted checkbox">
  112. <input class="multi" port="${rule.Port}" type="checkbox">
  113. <label></label>
  114. </div>
  115. </td>`);
  116. }else{
  117. $("#pfwlist").append(`<td class="collapsing" data-label=""> <i class="square full icon"></i> </td>`);
  118. }
  119. var deleteButton = `<a href="#" onclick="deleteForwardRule(this);" port="${rule.Port}"><i class="trash large icon"></i></a>`;
  120. if (rule.ReadOnly == true){
  121. deleteButton = `READ ONLY`;
  122. }
  123. $("#pfwlist").append(`
  124. <td data-label="">${rule.Name}</td>
  125. <td data-label="">${rule.Port}</td>
  126. <td data-label="">ALL</td>
  127. <td data-label="">
  128. ${deleteButton}
  129. </td>
  130. </tr>`);
  131. })
  132. }
  133. },
  134. error: function(){
  135. $('button').addClass("disabled");
  136. $("#errmsg").text("UPnP Servie is Disabled");
  137. $("#errormessagedialog").show();
  138. }
  139. })
  140. }
  141. function deleteSelected(){
  142. var ports = [];
  143. $("input:checkbox[class=multi]:checked").each(function(){
  144. var thisPort = $(this).attr("port");
  145. ports.push(parseInt(thisPort));
  146. });
  147. if (ports.length == 0){
  148. //Not selecting anything
  149. return;
  150. }
  151. //Confirm removal
  152. if (confirm("Confirm removing forward on: " + ports.join(", ") + "?")){
  153. ports.forEach(port => {
  154. $.ajax({
  155. url: "../../system/network/portforward",
  156. data: {opr: "remove", port: port},
  157. success: function(data){
  158. if (data.error !== undefined){
  159. alert(data.error);
  160. }else{
  161. //Refresh list
  162. initPortForwardList();
  163. }
  164. }
  165. })
  166. })
  167. }
  168. }
  169. function deleteForwardRule(object){
  170. var port = $(object).attr("port");
  171. if (confirm("Confirm Removing forward to: " + port + "?")){
  172. $.ajax({
  173. url: "../../system/network/portforward",
  174. data: {opr: "remove", port: port},
  175. success: function(data){
  176. if (data.error !== undefined){
  177. alert(data.error);
  178. }else{
  179. //Refresh list
  180. initPortForwardList();
  181. }
  182. }
  183. })
  184. }
  185. }
  186. </script>
  187. </body>
  188. </html>