index.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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="./favicon.png" />
  9. <title>Control Panel | Zoraxy</title>
  10. <link rel="stylesheet" href="script/semantic/semantic.min.css">
  11. <script src="script/jquery-3.6.0.min.js"></script>
  12. <script src="../script/ao_module.js"></script>
  13. <script src="script/semantic/semantic.min.js"></script>
  14. <script src="script/tablesort.js"></script>
  15. <style>
  16. body{
  17. background-color:white;
  18. }
  19. .functiontab{
  20. display:none;
  21. }
  22. .menubar{
  23. width: 100%;
  24. padding: 0.4em;
  25. padding-left: 1.2em;
  26. padding-right: 1.2em;
  27. background-color: #f5f5f5;
  28. margin-bottom: 1em;
  29. }
  30. .menubar .logo{
  31. height: 36px;
  32. }
  33. .menubar .item{
  34. display: inline-block;
  35. vertical-align: middle;
  36. }
  37. .wrapper{
  38. display: flex;
  39. flex-wrap: wrap;
  40. }
  41. .toolbar{
  42. width: 240px;
  43. }
  44. .contentWindow{
  45. padding: 1em;
  46. flex: 1;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div class="menubar">
  52. <div class="item">
  53. <img class="logo" src="img/logo.svg">
  54. </div>
  55. <div class="ui right floated buttons" style="padding-top: 2px;">
  56. <button class="ui basic icon button" onclick="logout();"><i class="sign-out icon"></i></button>
  57. </div>
  58. </div>
  59. <div id="errmsg" class="ui red message" style="display: none;"></div>
  60. <div class="wrapper">
  61. <div class="toolbar">
  62. <div id="mainmenu" class="ui secondary vertical pointing menu">
  63. <a class="item active" tag="status">
  64. <i class="info circle icon"></i>Status
  65. </a>
  66. <a class="item" tag="vdir">
  67. <i class="folder icon"></i> Virtual Directory
  68. </a>
  69. <a class="item" tag="subd">
  70. <i class="sitemap icon"></i> Subdomain Proxy
  71. </a>
  72. <a class="item" tag="rules">
  73. <i class="plus square icon"></i> Create Proxy Rules
  74. </a>
  75. <a class="item" tag="setroot">
  76. <i class="home icon"></i> Set Proxy Root
  77. </a>
  78. <div class="ui divider"></div>
  79. <a class="item" tag="cert">
  80. <i class="lock icon"></i> TLS / SSL certificate
  81. </a>
  82. <a class="item" tag="redirectset">
  83. <i class="level up alternate icon"></i> Redirection
  84. </a>
  85. </div>
  86. </div>
  87. <div class="contentWindow">
  88. <!-- Status Tab -->
  89. <div id="status" class="functiontab" target="status.html" style="display: block ;">
  90. <br><br><div class="ui active centered inline loader"></div>
  91. </div>
  92. <!-- Virtual Directory Tab -->
  93. <div id="vdir" class="functiontab" target="vdir.html"></div>
  94. <!-- Subdomain Proxy -->
  95. <div id="subd" class="functiontab" target="subd.html"></div>
  96. <!-- Create Rules -->
  97. <div id="rules" class="functiontab" target="rules.html"></div>
  98. <!-- Set proxy root -->
  99. <div id="setroot" class="functiontab" target="rproot.html"></div>
  100. <!-- Set TLS cert -->
  101. <div id="cert" class="functiontab" target="cert.html"></div>
  102. <!-- Redirections -->
  103. <div id="redirectset" class="functiontab" target="redirection.html"></div>
  104. </div>
  105. </div>
  106. </div>
  107. <br><br>
  108. <div class="ui divider"></div>
  109. <div class="ui container" style="color: grey; font-size: 90%">
  110. <p>CopyRight Zoraxy project and its author, 2022 - <span class="year"></span></p>
  111. </div>
  112. <br><br>
  113. <script>
  114. $(".year").text(new Date().getFullYear());
  115. /*
  116. Loader function
  117. Load all the components view from the
  118. components/ directory into their corrisponding divs
  119. */
  120. let loadingComponents = 0;
  121. function initTabs(callback=undefined){
  122. $('.functiontab').each(function(){
  123. let loadTarget = $(this).attr("target");
  124. if (loadTarget != undefined){
  125. $(this).load("./components/" + loadTarget, function(){
  126. loadingComponents--;
  127. });
  128. loadingComponents++;
  129. }else{
  130. $(this).html(`<p>Unable to load components for this tab</p>`);
  131. }
  132. })
  133. if (callback != undefined){
  134. waitInit(callback);
  135. }
  136. }
  137. function waitInit(callback = undefined, retryCount = 0){
  138. if (loadingComponents > 0 && retryCount < 5){
  139. setTimeout(function(){
  140. waitInit(callback, retryCount++);
  141. }, 300);
  142. }else if (loadingComponents == 0){
  143. callback();
  144. }else{
  145. alert("Missing component. Please check if your installation is complete.")
  146. }
  147. }
  148. initTabs(function(){
  149. initRPStaste();
  150. if (window.location.hash.length > 1){
  151. let tabID = window.location.hash.substr(1);
  152. openTabById(tabID);
  153. }else{
  154. openTabById("status");
  155. }
  156. $(".ui.dropdown").dropdown();
  157. $(".ui.checkbox").checkbox();
  158. //Click on the current tab
  159. $("#mainmenu").find(".item").each(function(){
  160. $(this).on("click", function(event){
  161. let tabid = $(this).attr("tag");
  162. openTabById(tabid);
  163. });
  164. });
  165. //Initialize all table that is sortable
  166. $('table').tablesort();
  167. });
  168. function logout() {
  169. $.get("/api/auth/logout", function(response) {
  170. if (response === "OK") {
  171. window.location.href = "/";
  172. }
  173. });
  174. }
  175. function getTabButtonById(targetTabId){
  176. let targetTabBtn = undefined;
  177. $("#mainmenu").find(".item").each(function(){
  178. let tabid = $(this).attr("tag");
  179. if (tabid == targetTabId){
  180. targetTabBtn = $(this);
  181. }
  182. });
  183. return targetTabBtn;
  184. }
  185. //Select and open a tab by its tag id
  186. function openTabById(tabID){
  187. let targetBtn = getTabButtonById(tabID);
  188. if (targetBtn == undefined){
  189. alert("Invalid tabid given");
  190. return;
  191. }
  192. $("#mainmenu").find(".item").removeClass("active");
  193. $(targetBtn).addClass("active");
  194. $(".functiontab").hide();
  195. $("#" + tabID).fadeIn('fast');
  196. $('html,body').animate({scrollTop: 0}, 'fast');
  197. window.location.hash = tabID;
  198. }
  199. //Generic functions
  200. function deleteEndpoint(ptype, epoint){
  201. if (confirm("Confirm remove proxy for :" + epoint + " (type: " + ptype + ")?")){
  202. $.ajax({
  203. url: "./del",
  204. data: {ep: epoint, ptype: ptype},
  205. success: function(){
  206. listVdirs();
  207. listSubd();
  208. }
  209. })
  210. }
  211. }
  212. function setProxyRoot(){
  213. var newpr = $("#proxyRoot").val();
  214. if (newpr.trim() == ""){
  215. $("#proxyRoot").parent().addClass('error');
  216. return
  217. }else{
  218. $("#proxyRoot").parent().removeClass('error');
  219. }
  220. var rootReqTls = $("#rootReqTLS")[0].checked;
  221. //Create the endpoint by calling add
  222. $.ajax({
  223. url: "./add",
  224. data: {"type": "root", tls: rootReqTls, ep: newpr},
  225. success: function(data){
  226. if (data.error != undefined){
  227. alert(data.error);
  228. }else{
  229. //OK
  230. initRootInfo();
  231. $("#ProxyRootUpdate").stop().slideDown('fast').delay(3000).slideUp('fast');
  232. }
  233. }
  234. });
  235. }
  236. //Show error message
  237. function errmsg(message){
  238. $("#errmsg").html(`<i class="red remove icon"></i> ${message}`);
  239. $("#errmsg").slideDown('fast').delay(5000).slideUp('fast');
  240. }
  241. </script>
  242. </body>
  243. </html>