index.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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/small_icon.png" style="margin-right:1em;"> 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="exchange 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. <p>Inbound Port (Port to be proxied)</p>
  63. <div class="ui action fluid input">
  64. <input type="text" id="incomingPort" placeholder="Incoming Port" value="80">
  65. <button class="ui button" onclick="handlePortChange();">Apply</button>
  66. </div>
  67. <Br>
  68. <button id="startbtn" class="ui teal button" onclick="startService();">Start Service</button>
  69. <button id="stopbtn" class="ui red disabled button" onclick="stopService();">Stop Service</button>
  70. </div>
  71. <!-- Virtual Directory Tab -->
  72. <div id="vdir" class="functiontab">
  73. <table class="ui celled table">
  74. <thead>
  75. <tr>
  76. <th>Virtual Directory</th>
  77. <th>Proxy To</th>
  78. <th>Remove</th>
  79. </tr>
  80. </thead>
  81. <tbody id="vdirList">
  82. <tr>
  83. <td data-label="">test</td>
  84. <td data-label="">test</td>
  85. <td data-label=""><button class="ui circular mini red basic button"><i class="remove icon"></i> Remove Proxy</button></td>
  86. </tr>
  87. </tbody>
  88. </table>
  89. </div>
  90. <!-- Subdomain Proxy -->
  91. <div id="subd" class="functiontab">
  92. <table class="ui celled table">
  93. <thead>
  94. <tr>
  95. <th>Matching Domain</th>
  96. <th>Proxy To</th>
  97. <th>Remove</th>
  98. </tr>
  99. </thead>
  100. <tbody id="subdList">
  101. </tbody>
  102. </table>
  103. </div>
  104. <!-- Create Rules -->
  105. <div id="rules" class="functiontab">
  106. <div class="">
  107. <h3><i class="ui exchange icon"></i> New Proxy Endpoint</h3>
  108. <p>You can create a proxy endpoing by subdomain or virtual directories</p>
  109. <div class="ui form">
  110. <div class="field">
  111. <label>Proxy Type</label>
  112. <div class="ui selection dropdown">
  113. <input type="hidden" id="ptype" value="subd">
  114. <i class="dropdown icon"></i>
  115. <div class="default text">Proxy Type</div>
  116. <div class="menu">
  117. <div class="item" data-value="subd">Sub-domain</div>
  118. <div class="item" data-value="vdir">Virtual Directory</div>
  119. </div>
  120. </div>
  121. </div>
  122. <div class="field">
  123. <label>Subdomain Matching Keyword / Virtual Directory Name</label>
  124. <input type="text" id="rootname" placeholder="s1.mydomain.com">
  125. <div class="ui message">
  126. Example of subdomain matching keyword:<br>
  127. <code>s1.arozos.com</code> <br>(Any access starting with s1.arozos.com will be proxy to the IP address below)<br>
  128. Example of virtual directory name: <br>
  129. <code>/s1/home</code> <br>(Any access to {this_server}/s1/ will be proxy to the IP address below)
  130. </div>
  131. </div>
  132. <div class="field">
  133. <label>IP Address or Domain Name with port</label>
  134. <input type="text" id="proxyDomain">
  135. <small>E.g. 192.168.0.101:8000 or example.com</small>
  136. </div>
  137. <div class="field">
  138. <div class="ui checkbox">
  139. <input type="checkbox" id="reqTls">
  140. <label>Proxy Target require TLS Connection (Unstable)</label>
  141. </div>
  142. </div>
  143. <button class="ui teal button" onclick="newProxyEndpoint();">Create Proxy Endpoint</button>
  144. </div>
  145. <div class="ui green message" id="proxyaddSucc" style="display:none">
  146. <i class="ui checkmark icon"></i> Proxy Endpoint Added
  147. </div>
  148. </div>
  149. </div>
  150. <!-- Set proxy root -->
  151. <div id="setroot" class="functiontab">
  152. <h3><i class="ui home icon"></i> Set Proxy Root</h3>
  153. <p>For all routing not found in the proxy rule, will be redirected to the proxy root server.</p>
  154. <div class="ui form">
  155. <div class="field">
  156. <label>Proxy Root</label>
  157. <input type="text" id="proxyRoot">
  158. <small>E.g. localhost:8080</small>
  159. </div>
  160. <div class="field">
  161. <div class="ui checkbox">
  162. <input type="checkbox" id="rootReqTLS">
  163. <label>Root require TLS Connection (Not Recommended)</label>
  164. </div>
  165. </div>
  166. </div>
  167. <br>
  168. <button class="ui teal button" onclick="setProxyRoot()"><i class="home icon" ></i> Set Proxy Root</button>
  169. <div class="ui green message" id="ProxyRootUpdate" style="display:none">
  170. <i class="ui checkmark icon"></i> Proxy Root Updated
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. </div>
  176. <br><br>
  177. <div class="ui divider"></div>
  178. <div class="ui container" style="color: grey; font-size: 90%">
  179. <p>Reverse Proxy Subservice. CopyRight imuslab, Licensed under MIT</p>
  180. </div>
  181. </div>
  182. <script>
  183. initRPStaste();
  184. $("#status").slideDown('fast');
  185. $(".ui.dropdown").dropdown();
  186. $(".ui.checkbox").checkbox();
  187. $("#mainmenu").find(".item").each(function(){
  188. $(this).on("click", function(e){
  189. $("#mainmenu").find(".item").removeClass("active");
  190. $(this).addClass("active");
  191. let targetOpeningTab = $(this).attr("tag");
  192. $(".functiontab").hide();
  193. $("#" + targetOpeningTab).slideDown('fast');
  194. });
  195. });
  196. function initRPStaste(){
  197. $.get("status", function(data){
  198. if (data.Running == true){
  199. $("#startbtn").addClass("disabled");
  200. $("#stopbtn").removeClass("disabled");
  201. $("#serverstatus").addClass("green");
  202. $("#statusTitle").text("Online");
  203. $("#statusText").text("Reverse proxying request on port: " + data.ListenPort);
  204. }else{
  205. $("#startbtn").removeClass("disabled");
  206. $("#stopbtn").addClass("disabled");
  207. $("#statusTitle").text("Offline");
  208. $("#statusText").text("Reverse proxy server is offline");
  209. $("#serverstatus").removeClass("green");
  210. }
  211. $("#incomingPort").val(data.ListenPort);
  212. });
  213. }
  214. function deleteEndpoint(ptype, epoint){
  215. if (confirm("Confirm remove proxy for :" + epoint + " (type: " + ptype + ")?")){
  216. $.ajax({
  217. url: "./del",
  218. data: {ep: epoint, ptype: ptype},
  219. success: function(){
  220. listVdirs();
  221. listSubd();
  222. }
  223. })
  224. }
  225. }
  226. function startService(){
  227. $.post("enable", {enable: true}, function(data){
  228. if (data.error != undefined){
  229. errmsg(data.error);
  230. }
  231. initRPStaste();
  232. });
  233. }
  234. function stopService(){
  235. $.post("enable", {enable: false}, function(data){
  236. if (data.error != undefined){
  237. errmsg(data.error);
  238. }
  239. initRPStaste();
  240. });
  241. }
  242. function handlePortChange(){
  243. var newPortValue = $("#incomingPort").val();
  244. if (isNaN(newPortValue - 1)){
  245. alert("Invalid incoming port value");
  246. return;
  247. }
  248. $.post("setIncoming", {incoming: newPortValue}, function(data){
  249. if (data.error != undefined){
  250. errmsg(data.error);
  251. }
  252. initRPStaste();
  253. });
  254. }
  255. //Virtual directories functions
  256. listVdirs();
  257. function listVdirs(){
  258. $("#vdirList").html(``);
  259. $.get("list?type=vdir", function(data){
  260. if (data.error !== undefined){
  261. $("#vdirList").append(`<tr>
  262. <td data-label="" colspan="3"><i class="remove icon"></i> ${data.error}</td>
  263. </tr>`);
  264. }else if (data.length == 0){
  265. $("#vdirList").append(`<tr>
  266. <td data-label="" colspan="3"><i class="checkmark icon"></i> No Virtual Directory Record</td>
  267. </tr>`);
  268. }else{
  269. data.forEach(vdir => {
  270. let tlsIcon = "";
  271. if (vdir.RequireTLS){
  272. tlsIcon = `<i class="lock icon"></i>`;
  273. }
  274. $("#vdirList").append(`<tr>
  275. <td data-label="">${vdir.Root}</td>
  276. <td data-label="">${vdir.Domain} ${tlsIcon}</td>
  277. <td data-label=""><button class="ui circular mini red basic button" onclick='deleteEndpoint("vdir","${vdir.Root}")'><i class="remove icon"></i> Remove Vdir</button></td>
  278. </tr>`);
  279. });
  280. }
  281. });
  282. }
  283. listSubd();
  284. function listSubd(){
  285. $("#subdList").html(``);
  286. $.get("list?type=subd", function(data){
  287. if (data.error !== undefined){
  288. $("#subdList").append(`<tr>
  289. <td data-label="" colspan="3"><i class="remove icon"></i> ${data.error}</td>
  290. </tr>`);
  291. }else if (data.length == 0){
  292. $("#subdList").append(`<tr>
  293. <td data-label="" colspan="3"><i class="checkmark icon"></i> No Subdomain Proxy Record</td>
  294. </tr>`);
  295. }else{
  296. data.forEach(subd => {
  297. let tlsIcon = "";
  298. if (subd.RequireTLS){
  299. tlsIcon = `<i class="lock icon"></i>`;
  300. }
  301. $("#subdList").append(`<tr>
  302. <td data-label="">${subd.MatchingDomain}</td>
  303. <td data-label="">${subd.Domain} ${tlsIcon}</td>
  304. <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>
  305. </tr>`);
  306. });
  307. }
  308. });
  309. }
  310. //New Proxy Endpoint
  311. function newProxyEndpoint(){
  312. var type = $("#ptype").val();
  313. var rootname = $("#rootname").val();
  314. var proxyDomain = $("#proxyDomain").val();
  315. var useTLS = $("#reqTls")[0].checked;
  316. if (rootname.trim() == ""){
  317. $("#rootname").parent().addClass("error");
  318. return
  319. }else{
  320. $("#rootname").parent().removeClass("error");
  321. }
  322. if (proxyDomain.trim() == ""){
  323. $("#proxyDomain").parent().addClass("error");
  324. return
  325. }else{
  326. $("#proxyDomain").parent().removeClass("error");
  327. }
  328. //Create the endpoint by calling add
  329. $.ajax({
  330. url: "./add",
  331. data: {type: type, rootname: rootname, tls: useTLS, ep: proxyDomain},
  332. success: function(data){
  333. if (data.error != undefined){
  334. alert(data.error);
  335. }else{
  336. //OK
  337. listVdirs();
  338. listSubd();
  339. $("#proxyaddSucc").stop().slideDown('fast').delay(3000).slideUp('fast');
  340. //Clear old data
  341. $("#rootname").val("");
  342. $("#proxyDomain").val("");
  343. }
  344. }
  345. });
  346. }
  347. function setProxyRoot(){
  348. var newpr = $("#proxyRoot").val();
  349. if (newpr.trim() == ""){
  350. $("#proxyRoot").parent().addClass('error');
  351. return
  352. }else{
  353. $("#proxyRoot").parent().removeClass('error');
  354. }
  355. var rootReqTls = $("#rootReqTLS")[0].checked;
  356. //Create the endpoint by calling add
  357. $.ajax({
  358. url: "./add",
  359. data: {"type": "root", tls: rootReqTls, ep: newpr},
  360. success: function(data){
  361. if (data.error != undefined){
  362. alert(data.error);
  363. }else{
  364. //OK
  365. initRootInfo();
  366. $("#ProxyRootUpdate").stop().slideDown('fast').delay(3000).slideUp('fast');
  367. }
  368. }
  369. });
  370. }
  371. initRootInfo();
  372. function initRootInfo(){
  373. $.get("list?type=root", function(data){
  374. if (data == null){
  375. }else{
  376. $("#proxyRoot").val(data.Domain);
  377. }
  378. });
  379. }
  380. function errmsg(message){
  381. $("#errmsg").html(`<i class="red remove icon"></i> ${message}`);
  382. $("#errmsg").slideDown('fast').delay(5000).slideUp('fast');
  383. }
  384. </script>
  385. </body>
  386. </html>