index.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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 class="ui green message" id="proxyaddSucc" style="display:none">
  140. <i class="ui checkmark icon"></i> Proxy Endpoint Added
  141. </div>
  142. </div>
  143. </div>
  144. <!-- Set proxy root -->
  145. <div id="setroot" class="functiontab">
  146. <h3><i class="ui home icon"></i> Set Proxy Root</h3>
  147. <p>For all routing not found in the proxy rule, will be redirected to the proxy root server.</p>
  148. <div class="ui form">
  149. <div class="field">
  150. <label>Proxy Root</label>
  151. <input type="text" id="proxyRoot">
  152. <small>E.g. localhost:8080</small>
  153. </div>
  154. <div class="field">
  155. <div class="ui checkbox">
  156. <input type="checkbox" id="rootReqTLS">
  157. <label>Root require TLS Connection (Not Recommended)</label>
  158. </div>
  159. </div>
  160. </div>
  161. <br>
  162. <button class="ui teal button" onclick="setProxyRoot()"><i class="home icon" ></i> Set Proxy Root</button>
  163. <div class="ui green message" id="ProxyRootUpdate" style="display:none">
  164. <i class="ui checkmark icon"></i> Proxy Root Updated
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. <br><br>
  171. <div class="ui divider"></div>
  172. <div class="ui container" style="color: grey; font-size: 90%">
  173. <p>Reverse Proxy Subservice. CopyRight imuslab, Licensed under MIT</p>
  174. </div>
  175. </div>
  176. <script>
  177. initRPStaste();
  178. $("#status").slideDown('fast');
  179. $(".ui.dropdown").dropdown();
  180. $(".ui.checkbox").checkbox();
  181. $("#mainmenu").find(".item").each(function(){
  182. $(this).on("click", function(e){
  183. $("#mainmenu").find(".item").removeClass("active");
  184. $(this).addClass("active");
  185. let targetOpeningTab = $(this).attr("tag");
  186. $(".functiontab").hide();
  187. $("#" + targetOpeningTab).slideDown('fast');
  188. });
  189. });
  190. function initRPStaste(){
  191. $.get("status", function(data){
  192. if (data.Running == true){
  193. $("#startbtn").addClass("disabled");
  194. $("#stopbtn").removeClass("disabled");
  195. $("#serverstatus").addClass("green");
  196. $("#statusTitle").text("Online");
  197. $("#statusText").text("Reverse proxying request on port: " + data.ListenPort);
  198. }else{
  199. $("#startbtn").removeClass("disabled");
  200. $("#stopbtn").addClass("disabled");
  201. $("#statusTitle").text("Offline");
  202. $("#statusText").text("Reverse proxy server is offline");
  203. $("#serverstatus").removeClass("green");
  204. }
  205. });
  206. }
  207. function deleteEndpoint(ptype, epoint){
  208. if (confirm("Confirm remove proxy for :" + epoint + " (type: " + ptype + ")?")){
  209. $.ajax({
  210. url: "./del",
  211. data: {ep: epoint, ptype: ptype},
  212. success: function(){
  213. listVdirs();
  214. listSubd();
  215. }
  216. })
  217. }
  218. }
  219. function startService(){
  220. $.post("enable", {enable: true}, function(data){
  221. if (data.error != undefined){
  222. errmsg(data.error);
  223. }
  224. initRPStaste();
  225. });
  226. }
  227. function stopService(){
  228. $.post("enable", {enable: false}, function(data){
  229. if (data.error != undefined){
  230. errmsg(data.error);
  231. }
  232. initRPStaste();
  233. });
  234. }
  235. //Virtual directories functions
  236. listVdirs();
  237. function listVdirs(){
  238. $("#vdirList").html(``);
  239. $.get("list?type=vdir", function(data){
  240. if (data.error !== undefined){
  241. $("#vdirList").append(`<tr>
  242. <td data-label="" colspan="3"><i class="remove icon"></i> ${data.error}</td>
  243. </tr>`);
  244. }else if (data.length == 0){
  245. $("#vdirList").append(`<tr>
  246. <td data-label="" colspan="3"><i class="question icon"></i> No Virtual Directory Record</td>
  247. </tr>`);
  248. }else{
  249. data.forEach(vdir => {
  250. let tlsIcon = "";
  251. if (vdir.RequireTLS){
  252. tlsIcon = `<i class="lock icon"></i>`;
  253. }
  254. $("#vdirList").append(`<tr>
  255. <td data-label="">${vdir.Root}</td>
  256. <td data-label="">${vdir.Domain} ${tlsIcon}</td>
  257. <td data-label=""><button class="ui circular mini red basic button" onclick='deleteEndpoint("subd","${subd.Root}")'><i class="remove icon"></i> Remove Vdir</button></td>
  258. </tr>`);
  259. });
  260. }
  261. });
  262. }
  263. listSubd();
  264. function listSubd(){
  265. $("#subdList").html(``);
  266. $.get("list?type=subd", function(data){
  267. if (data.error !== undefined){
  268. $("#subdList").append(`<tr>
  269. <td data-label="" colspan="3"><i class="remove icon"></i> ${data.error}</td>
  270. </tr>`);
  271. }else if (data.length == 0){
  272. $("#subdList").append(`<tr>
  273. <td data-label="" colspan="3"><i class="question icon"></i> No Subdomain Proxy Record</td>
  274. </tr>`);
  275. }else{
  276. data.forEach(subd => {
  277. let tlsIcon = "";
  278. if (subd.RequireTLS){
  279. tlsIcon = `<i class="lock icon"></i>`;
  280. }
  281. $("#subdList").append(`<tr>
  282. <td data-label="">${subd.MatchingDomain}</td>
  283. <td data-label="">${subd.Domain} ${tlsIcon}</td>
  284. <td data-label=""><button class="ui circular mini red basic button" onclick='deleteEndpoint("subd","${subd.MatchingDomain}")'><i class="remove icon"></i> Remove Subd</button></td>
  285. </tr>`);
  286. });
  287. }
  288. });
  289. }
  290. //New Proxy Endpoint
  291. function newProxyEndpoint(){
  292. var type = $("#ptype").val();
  293. var rootname = $("#rootname").val();
  294. var proxyDomain = $("#proxyDomain").val();
  295. var useTLS = $("#reqTls")[0].checked;
  296. if (rootname.trim() == ""){
  297. $("#rootname").parent().addClass("error");
  298. return
  299. }else{
  300. $("#rootname").parent().removeClass("error");
  301. }
  302. if (proxyDomain.trim() == ""){
  303. $("#proxyDomain").parent().addClass("error");
  304. return
  305. }else{
  306. $("#proxyDomain").parent().removeClass("error");
  307. }
  308. //Create the endpoint by calling add
  309. $.ajax({
  310. url: "./add",
  311. data: {type: type, rootname: rootname, tls: useTLS, ep: proxyDomain},
  312. success: function(data){
  313. if (data.error != undefined){
  314. alert(data.error);
  315. }else{
  316. //OK
  317. listVdirs();
  318. listSubd();
  319. $("#proxyaddSucc").stop().slideDown('fast').delay(3000).slideUp('fast');
  320. }
  321. }
  322. });
  323. }
  324. function setProxyRoot(){
  325. var newpr = $("#proxyRoot").val();
  326. if (newpr.trim() == ""){
  327. $("#proxyRoot").parent().addClass('error');
  328. return
  329. }else{
  330. $("#proxyRoot").parent().removeClass('error');
  331. }
  332. var rootReqTls = $("#rootReqTLS")[0].checked;
  333. //Create the endpoint by calling add
  334. $.ajax({
  335. url: "./add",
  336. data: {"type": "root", tls: rootReqTls, ep: newpr},
  337. success: function(data){
  338. if (data.error != undefined){
  339. alert(data.error);
  340. }else{
  341. //OK
  342. initRootInfo();
  343. $("#ProxyRootUpdate").stop().slideDown('fast').delay(3000).slideUp('fast');
  344. }
  345. }
  346. });
  347. }
  348. initRootInfo();
  349. function initRootInfo(){
  350. $.get("list?type=root", function(data){
  351. if (data == null){
  352. }else{
  353. $("#proxyRoot").val(data.Domain);
  354. }
  355. });
  356. }
  357. function errmsg(message){
  358. $("#errmsg").html(`<i class="red remove icon"></i> ${message}`);
  359. $("#errmsg").slideDown('fast').delay(5000).slideUp('fast');
  360. }
  361. </script>
  362. </body>
  363. </html>