tcpprox.html 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <div class="standardContainer">
  2. <div class="ui basic segment">
  3. <h2>TCP Proxy</h2>
  4. <p>Proxy traffic flow on layer 3 via TCP/IP</p>
  5. </div>
  6. <button class="ui basic orange button" onclick="$('#addproxyConfig').slideToggle('fast');"><i class="ui add icon"></i> Add Proxy Config</button>
  7. <button class="ui basic circular right floated icon button" title="Refresh List"><i class="ui green refresh icon"></i></button>
  8. <div class="ui divider"></div>
  9. <div class="ui basic segment" id="addproxyConfig">
  10. <h3>New TCP Proxy Config</h3>
  11. <p>Create a new proxy instance</p>
  12. <form id="tcpProxyForm" class="ui form">
  13. <div class="field">
  14. <label>Name</label>
  15. <input type="text" name="name" placeholder="Config Name">
  16. </div>
  17. <div class="field">
  18. <label>Port A</label>
  19. <input type="text" name="portA" placeholder="First address or port">
  20. </div>
  21. <div class="field">
  22. <label>Port B</label>
  23. <input type="text" name="portB" placeholder="Second address or port">
  24. </div>
  25. <div class="field">
  26. <label>Timeout (s)</label>
  27. <input type="text" name="timeout" placeholder="Timeout (s)">
  28. </div>
  29. <div class="field">
  30. <label>Mode</label>
  31. <select name="mode" class="ui dropdown">
  32. <option value="">Select Mode</option>
  33. <option value="listen">Listen</option>
  34. <option value="transport">Transport</option>
  35. <option value="starter">Starter</option>
  36. </select>
  37. </div>
  38. <button class="ui basic button" type="submit"><i class="ui blue add icon"></i> Add Proxy Config</button>
  39. <table class="ui celled padded table">
  40. <thead>
  41. <tr><th class="single line">Mode</th>
  42. <th>Public-IP</th>
  43. <th>Concurrent Access</th>
  44. <th>Flow Diagram</th>
  45. </tr></thead>
  46. <tbody>
  47. <tr>
  48. <td>
  49. <h3 class="ui center aligned header">Listen</h3>
  50. </td>
  51. <td class="single line">
  52. Server: <i class="ui green check icon"></i><br>
  53. A: <i class="ui remove icon"></i><br>
  54. B: <i class="ui remove icon"></i><br>
  55. </td>
  56. <td>
  57. <i class="ui red times icon"></i>
  58. </td>
  59. <td>Port A (e.g. 8080) <i class="arrow right icon"></i> Server<br>
  60. Port B (e.g. 8081) <i class="arrow right icon"></i> Server<br>
  61. <small>Server will act as a bridge to proxy traffic between Port A and B</small>
  62. </td>
  63. </tr>
  64. <tr>
  65. <td>
  66. <h3 class="ui center aligned header">Transport</h3>
  67. </td>
  68. <td class="single line">
  69. Server: <i class="ui green check icon"></i><br>
  70. A: <i class="ui remove icon"></i><br>
  71. B: <i class="ui green check icon"></i> (or same LAN)<br>
  72. </td>
  73. <td>
  74. <i class="ui green check icon"></i>
  75. </td>
  76. <td>Port A (e.g. 25565) <i class="arrow right icon"></i> Server<br>
  77. Server <i class="arrow right icon"></i> Port B (e.g. 192.168.0.2:25565)<br>
  78. <small>Traffic from Port A will be forward to Port B's (IP if provided and) Port</small>
  79. </td>
  80. </tr>
  81. <tr>
  82. <td>
  83. <h3 class="ui center aligned header">Starter</h3>
  84. </td>
  85. <td class="single line">
  86. Server: <i class="ui times icon"></i><br>
  87. A: <i class="ui green check icon"></i><br>
  88. B: <i class="ui green check icon"></i><br>
  89. </td>
  90. <td>
  91. <i class="ui red times icon"></i>
  92. </td>
  93. <td>Server <i class="arrow right icon"></i> Port A (e.g. remote.local.:8080) <br>
  94. Server <i class="arrow right icon"></i> Port B (e.g. recv.local.:8081) <br>
  95. <small>Port A and B will be actively bridged</small>
  96. </td>
  97. </tr>
  98. </tbody>
  99. </table>
  100. </form>
  101. <div class="ui divider"></div>
  102. </div>
  103. <div class="ui basic segment">
  104. <div style="overflow-x: auto;">
  105. <h3>TCP Proxy Configs</h3>
  106. <p>A list of TCP proxy configs created on this host. To enable them, use the toggle button on the right.</p>
  107. <table id="proxyTable" class="ui basic celled unstackable table">
  108. <thead>
  109. <tr>
  110. <th>Name</th>
  111. <th>PortA</th>
  112. <th>PortB</th>
  113. <th>Mode</th>
  114. <th>Timeout (s)</th>
  115. <th>Validate / Start</th>
  116. </tr>
  117. </thead>
  118. <tbody>
  119. </tbody>
  120. </table>
  121. </div>
  122. </div>
  123. <script>
  124. $("#tcpProxyForm .dropdown").dropdown();
  125. $('#tcpProxyForm').on('submit', function(event) {
  126. event.preventDefault();
  127. var form = $(this);
  128. var url = '/api/tcpprox/config/add';
  129. var data = form.serialize();
  130. // Validate timeout is an integer
  131. var timeout = parseInt(form.find('input[name="timeout"]').val());
  132. if (isNaN(timeout)) {
  133. form.find('input[name="timeout"]').parent().addClass("error");
  134. msgbox('Timeout must be a valid integer', false, 5000);
  135. return;
  136. }else{
  137. form.find('input[name="timeout"]').parent().removeClass("error");
  138. }
  139. // Validate mode is selected
  140. var mode = form.find('select[name="mode"]').val();
  141. if (mode === '') {
  142. form.find('select[name="mode"]').parent().addClass("error");
  143. msgbox('Please select a mode', false, 5000);
  144. return;
  145. }else{
  146. form.find('select[name="mode"]').parent().removeClass("error");
  147. }
  148. // Send the AJAX POST request
  149. $.ajax({
  150. type: 'POST',
  151. url: url,
  152. data: data,
  153. success: function(response) {
  154. if (response.error) {
  155. msgbox(response.error, false, 6000);
  156. }else{
  157. msgbox("Config Added");
  158. }
  159. },
  160. error: function() {
  161. msgbox('An error occurred while processing the request', false);
  162. }
  163. });
  164. });
  165. function renderProxyConfigs(proxyConfigs) {
  166. var tableBody = $('#proxyTable tbody');
  167. if (proxyConfigs.length === 0) {
  168. var noResultsRow = $('<tr><td colspan="7"><i class="green check circle icon"></i>No Proxy Configs</td></tr>');
  169. tableBody.append(noResultsRow);
  170. } else {
  171. proxyConfigs.forEach(function(config) {
  172. var runningLogo = '<i class="red circle icon"></i>';
  173. var startButton = `<button onclick="startTcpProx('${config.UUID}');" class="ui basic icon button" title="Start Proxy"><i class="play icon"></i></button>`;
  174. if (config.Running){
  175. runningLogo = '<i class="green circle icon"></i>';
  176. startButton = `<button onclick="stopTcpProx('${config.UUID}');" class="ui basic icon button" title="Start Proxy"><i class="red stop icon"></i></button>`;
  177. }
  178. var modeText = "Unknown";
  179. if (config.Mode == 0){
  180. modeText = "Listen";
  181. }else if (config.Mode == 1){
  182. modeText = "Transport";
  183. }else if (config.Mode == 2){
  184. modeText = "Starter";
  185. }
  186. var row = $(`<tr uuid="${config.UUID}">`);
  187. row.append($('<td>').html(runningLogo + config.Name));
  188. row.append($('<td>').text(config.PortA));
  189. row.append($('<td>').text(config.PortB));
  190. row.append($('<td>').text(modeText));
  191. row.append($('<td>').text(config.Timeout));
  192. row.append($('<td>').html(`
  193. <div class="ui basic buttons">
  194. <button class="ui basic icon button" title="Validate Config"><i class="green check icon"></i></button>
  195. ${startButton}
  196. </div>
  197. `));
  198. tableBody.append(row);
  199. });
  200. }
  201. }
  202. function initProxyConfigList(){
  203. $.ajax({
  204. type: 'GET',
  205. url: '/api/tcpprox/config/list',
  206. success: function(response) {
  207. renderProxyConfigs(response);
  208. },
  209. error: function() {
  210. msgbox('Unable to load proxy configs', false);
  211. }
  212. });
  213. }
  214. initProxyConfigList();
  215. </script>
  216. </div>