index.html 10 KB

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