1
0

index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="apple-mobile-web-app-capable" content="yes" />
  5. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  6. <meta charset="UTF-8">
  7. <meta name="theme-color" content="#4b75ff">
  8. <link rel="icon" type="image/png" href="img/small_icon.png"/>
  9. <link rel="stylesheet" href="script/semantic/semantic.min.css">
  10. <script src="script/jquery-3.6.0.min.js"></script>
  11. <script src="../script/ao_module.js"></script>
  12. <script src="script/semantic/semantic.min.js"></script>
  13. <title>Reverse Proxy</title>
  14. <style>
  15. body{
  16. background-color:white;
  17. }
  18. .functiontab{
  19. display:none;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <br>
  25. <div class="ui container">
  26. <h3><img class="ui middle aligned mini image" src="img/desktop_icon.png" style="margin-right: 4px;"> Reverse Proxy Settings</h3>
  27. <div class="ui divider"></div>
  28. <div id="errmsg" class="ui red message" style="display: none;"></div>
  29. <div class="ui stackable grid">
  30. <div class="four wide column">
  31. <div id="mainmenu" class="ui secondary vertical pointing menu">
  32. <a class="item active" tag="status">
  33. Status
  34. </a>
  35. <a class="item" tag="vdir">
  36. Virtual Directory
  37. </a>
  38. <a class="item" tag="subd">
  39. Subdomain Proxy
  40. </a>
  41. <a class="item" tag="rules">
  42. Create Proxy Rules
  43. </a>
  44. <a class="item" tag="setroot">
  45. Set Proxy Root
  46. </a>
  47. </div>
  48. </div>
  49. <div class="twelve wide column">
  50. <!-- Status Tab -->
  51. <div id="status" class="functiontab">
  52. <div id="serverstatus" class="ui message">
  53. <h3 class="ui header">
  54. <i class="power off icon"></i>
  55. <div class="content">
  56. <span id="statusTitle">Offline</span>
  57. <div class="sub header" id="statusText">Reverse proxy server is offline</div>
  58. </div>
  59. </h3>
  60. </div>
  61. <div class="ui divider"></div>
  62. <button id="startbtn" class="ui teal button" onclick="startService();">Start Service</button>
  63. <button id="stopbtn" class="ui red disabled button" onclick="stopService();">Stop Service</button>
  64. </div>
  65. <!-- Virtual Directory Tab -->
  66. <div id="vdir" class="functiontab">
  67. <table class="ui celled table">
  68. <thead>
  69. <tr>
  70. <th>Virtual Directory</th>
  71. <th>Proxy To</th>
  72. <th>Remove</th>
  73. </tr>
  74. </thead>
  75. <tbody id="vdirList">
  76. <tr>
  77. <td data-label="">test</td>
  78. <td data-label="">test</td>
  79. <td data-label=""><button class="ui circular mini red basic button"><i class="remove icon"></i> Remove Proxy</button></td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. </div>
  84. <!-- Subdomain Proxy -->
  85. <div id="subd" class="functiontab">
  86. <table class="ui celled table">
  87. <thead>
  88. <tr>
  89. <th>Subdomain</th>
  90. <th>Proxy To</th>
  91. <th>Remove</th>
  92. </tr>
  93. </thead>
  94. <tbody id="subdList">
  95. </tbody>
  96. </table>
  97. </div>
  98. <!-- Create Rules -->
  99. <div id="rules" class="functiontab">
  100. <div class="">
  101. <h3><i class="ui exchange icon"></i> New Proxy Endpoint</h3>
  102. <p>You can create a proxy endpoing by subdomain or virtual directories</p>
  103. <div class="ui form">
  104. <div class="field">
  105. <label>Proxy Type</label>
  106. <div class="ui selection dropdown">
  107. <input type="hidden" id="ptype" value="subd">
  108. <i class="dropdown icon"></i>
  109. <div class="default text">Proxy Type</div>
  110. <div class="menu">
  111. <div class="item" data-value="subd">Sub-domain</div>
  112. <div class="item" data-value="vdir">Virtual Directory</div>
  113. </div>
  114. </div>
  115. </div>
  116. <div class="field">
  117. <label>Subdomain Matching Keyword / Virtual Directory Name</label>
  118. <input type="text" id="rootname" placeholder="s1">
  119. <div class="ui message">
  120. Example of subdomain matching keyword:<br>
  121. <code>s1.arozos.com</code> <br>(Any access starting with s1.arozos.com will be proxy to the IP address below)<br>
  122. Example of virtual directory name: <br>
  123. <code>/s1/home</code> <br>(Any access to {this_server}/s1/ will be proxy to the IP address below)
  124. </div>
  125. </div>
  126. <div class="field">
  127. <label>IP Address or Domain Name with port</label>
  128. <input type="text" id="proxyDomain">
  129. <small>E.g. 192.168.0.101:8000 or example.com</small>
  130. </div>
  131. <div class="field">
  132. <div class="ui checkbox">
  133. <input type="checkbox" id="reqTls">
  134. <label>Proxy Target require TLS Connection (Unstable)</label>
  135. </div>
  136. </div>
  137. <button class="ui teal button" onclick="newProxyEndpoint();">Create Proxy Endpoint</button>
  138. </div>
  139. </div>
  140. </div>
  141. <!-- Set proxy root -->
  142. <div id="setroot" class="functiontab">
  143. <h3><i class="ui home icon"></i> Set Proxy Root</h3>
  144. <p>For all routing not found in the proxy rule, will be redirected to the proxy root server.</p>
  145. <button class="ui button" onclick=""><i class="edit icon"></i> Set Proxy Root</button>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. <br><br>
  151. <div class="ui divider"></div>
  152. <div class="ui container" style="color: grey; font-size: 90%">
  153. <p>Reverse Proxy Subservice. CopyRight imuslab, Licensed under MIT</p>
  154. </div>
  155. </div>
  156. <script>
  157. initRPStaste();
  158. $("#status").slideDown('fast');
  159. $(".ui.dropdown").dropdown();
  160. $(".ui.checkbox").checkbox();
  161. $("#mainmenu").find(".item").each(function(){
  162. $(this).on("click", function(e){
  163. $("#mainmenu").find(".item").removeClass("active");
  164. $(this).addClass("active");
  165. let targetOpeningTab = $(this).attr("tag");
  166. $(".functiontab").hide();
  167. $("#" + targetOpeningTab).slideDown('fast');
  168. });
  169. });
  170. function initRPStaste(){
  171. $.get("status", function(data){
  172. if (data.Running == true){
  173. $("#startbtn").addClass("disabled");
  174. $("#stopbtn").removeClass("disabled");
  175. $("#serverstatus").addClass("green");
  176. $("#statusTitle").text("Online");
  177. $("#statusText").text("Reverse proxying request on port: " + data.ListenPort);
  178. }else{
  179. $("#startbtn").removeClass("disabled");
  180. $("#stopbtn").addClass("disabled");
  181. $("#statusTitle").text("Offline");
  182. $("#statusText").text("Reverse proxy server is offline");
  183. $("#serverstatus").removeClass("green");
  184. }
  185. });
  186. }
  187. function startService(){
  188. $.post("enable", {enable: true}, function(data){
  189. if (data.error != undefined){
  190. errmsg(data.error);
  191. }
  192. initRPStaste();
  193. });
  194. }
  195. function stopService(){
  196. $.post("enable", {enable: false}, function(data){
  197. if (data.error != undefined){
  198. errmsg(data.error);
  199. }
  200. initRPStaste();
  201. });
  202. }
  203. //Virtual directories functions
  204. listVdirs();
  205. function listVdirs(){
  206. $("#vdirList").html(``);
  207. $.get("list?type=vdir", function(data){
  208. if (data.error !== undefined){
  209. $("#vdirList").append(`<tr>
  210. <td data-label="" colspan="3"><i class="remove icon"></i> ${data.error}</td>
  211. </tr>`);
  212. }else if (data.length == 0){
  213. $("#vdirList").append(`<tr>
  214. <td data-label="" colspan="3"><i class="question icon"></i> No Virtual Directory Record</td>
  215. </tr>`);
  216. }else{
  217. data.forEach(vdir => {
  218. let tlsIcon = "";
  219. if (vdir.RequireTLS){
  220. tlsIcon = `<i class="lock icon"></i>`;
  221. }
  222. $("#vdirList").append(`<tr>
  223. <td data-label="">${vdir.Root}</td>
  224. <td data-label="">${vdir.Domain} ${tlsIcon}</td>
  225. <td data-label=""><button class="ui circular mini red basic button"><i class="remove icon"></i> Remove Vdir</button></td>
  226. </tr>`);
  227. });
  228. }
  229. });
  230. }
  231. listSubd();
  232. function listSubd(){
  233. $("#subdList").html(``);
  234. $.get("list?type=subd", function(data){
  235. if (data.error !== undefined){
  236. $("#subdList").append(`<tr>
  237. <td data-label="" colspan="3"><i class="remove icon"></i> ${data.error}</td>
  238. </tr>`);
  239. }else if (data.length == 0){
  240. $("#subdList").append(`<tr>
  241. <td data-label="" colspan="3"><i class="question icon"></i> No Subdomain Proxy Record</td>
  242. </tr>`);
  243. }else{
  244. data.forEach(subd => {
  245. let tlsIcon = "";
  246. if (subd.RequireTLS){
  247. tlsIcon = `<i class="lock icon"></i>`;
  248. }
  249. $("#subdList").append(`<tr>
  250. <td data-label="">${subd.MatchingDomain}</td>
  251. <td data-label="">${subd.Domain} ${tlsIcon}</td>
  252. <td data-label=""><button class="ui circular mini red basic button"><i class="remove icon"></i> Remove Subd</button></td>
  253. </tr>`);
  254. });
  255. }
  256. });
  257. }
  258. //New Proxy Endpoint
  259. function newProxyEndpoint(){
  260. var type = $("#ptype").val();
  261. var rootname = $("#rootname").val();
  262. var proxyDomain = $("#proxyDomain").val();
  263. var useTLS = $("#reqTls")[0].checked;
  264. if (rootname.trim() == ""){
  265. $("#rootname").parent().addClass("error");
  266. return
  267. }else{
  268. $("#rootname").parent().removeClass("error");
  269. }
  270. if (proxyDomain.trim() == ""){
  271. $("#proxyDomain").parent().addClass("error");
  272. return
  273. }else{
  274. $("#proxyDomain").parent().removeClass("error");
  275. }
  276. //Create the endpoint by calling add
  277. $.ajax({
  278. url: "./add",
  279. data: {type: type, rootname: rootname, tls: useTLS, ep: proxyDomain},
  280. success: function(data){
  281. if (data.error != undefined){
  282. alert(data.error);
  283. }else{
  284. //OK
  285. listVdirs();
  286. listSubd();
  287. }
  288. }
  289. });
  290. }
  291. function errmsg(message){
  292. $("#errmsg").html(`<i class="red remove icon"></i> ${message}`);
  293. $("#errmsg").slideDown('fast').delay(5000).slideUp('fast');
  294. }
  295. </script>
  296. </body>
  297. </html>