rules.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <!-- Proxy Create Form-->
  2. <style>
  3. .rulesInstructions{
  4. background: var(--theme_background) !important;
  5. color: var(--theme_lgrey);
  6. border-radius: 1em !important;
  7. }
  8. </style>
  9. <div class="standardContainer">
  10. <div class="ui stackable grid">
  11. <div class="ten wide column">
  12. <div class="ui basic segment" style="border-radius: 1em; padding: 1em !important;">
  13. <h2>New Proxy Rule</h2>
  14. <p>You can add more proxy rules to support more site via domain / subdomains</p>
  15. <div class="ui form">
  16. <div class="field">
  17. <label>Matching Keyword / Domain</label>
  18. <input type="text" id="rootname" placeholder="mydomain.com">
  19. <small>Support subdomain and wildcard, e.g. s1.mydomain.com or *.test.mydomain.com</small>
  20. </div>
  21. <div class="field">
  22. <label>Target IP Address or Domain Name with port</label>
  23. <input type="text" id="proxyDomain" onchange="autoCheckTls(this.value);">
  24. <small>E.g. 192.168.0.101:8000 or example.com</small>
  25. </div>
  26. <div class="field">
  27. <div class="ui checkbox">
  28. <input type="checkbox" id="reqTls">
  29. <label>Proxy Target require TLS Connection <br><small>(i.e. Your proxy target starts with https://)</small></label>
  30. </div>
  31. </div>
  32. <!-- Advance configs -->
  33. <div class="ui basic segment" style="background-color: #f7f7f7; border-radius: 1em;">
  34. <div id="advanceProxyRules" class="ui fluid accordion">
  35. <div class="title">
  36. <i class="dropdown icon"></i>
  37. Advance Settings
  38. </div>
  39. <div class="content">
  40. <p></p>
  41. <div class="field">
  42. <div class="ui checkbox">
  43. <input type="checkbox" id="skipTLSValidation">
  44. <label>Ignore TLS/SSL Verification Error<br><small>For targets that is using self-signed, expired certificate (Not Recommended)</small></label>
  45. </div>
  46. </div>
  47. <div class="field">
  48. <div class="ui checkbox">
  49. <input type="checkbox" id="skipWebsocketOriginCheck" checked>
  50. <label>Skip WebSocket Origin Check<br><small>Allow cross-origin websocket requests (Usually not a security concern)</small></label>
  51. </div>
  52. </div>
  53. <div class="field">
  54. <div class="ui checkbox">
  55. <input type="checkbox" id="bypassGlobalTLS">
  56. <label>Allow plain HTTP access<br><small>Allow this subdomain to be connected without TLS (Require HTTP server enabled on port 80)</small></label>
  57. </div>
  58. </div>
  59. <div class="field">
  60. <div class="ui checkbox">
  61. <input type="checkbox" id="requireBasicAuth">
  62. <label>Require Basic Auth<br><small>Require client to login in order to view the page</small></label>
  63. </div>
  64. </div>
  65. <div id="basicAuthCredentials" class="field">
  66. <p>Enter the username and password for allowing them to access this proxy endpoint</p>
  67. <table class="ui very basic celled table">
  68. <thead>
  69. <tr>
  70. <th>Username</th>
  71. <th>Password</th>
  72. <th>Remove</th>
  73. </tr></thead>
  74. <tbody id="basicAuthCredentialTable">
  75. <tr>
  76. <td colspan="3"><i class="ui green circle check icon"></i> No Entered Credential</td>
  77. </tr>
  78. </tbody>
  79. </table>
  80. <div class="three small fields credentialEntry">
  81. <div class="field">
  82. <input id="basicAuthCredUsername" type="text" placeholder="Username" autocomplete="off">
  83. </div>
  84. <div class="field">
  85. <input id="basicAuthCredPassword" type="password" placeholder="Password" autocomplete="off">
  86. </div>
  87. <div class="field">
  88. <button class="ui basic button" onclick="addCredentials();"><i class="blue add icon"></i> Add Credential</button>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. <br>
  96. <button class="ui basic button" onclick="newProxyEndpoint();"><i class="green add icon"></i> Create Endpoint</button>
  97. <br><br>
  98. </div>
  99. </div>
  100. </div>
  101. <div class="six wide column">
  102. <div class="ui basic segment rulesInstructions">
  103. <span style="font-size: 1.2em; font-weight: 300;"><i class="ui yellow star icon"></i> Domain</span><br>
  104. Example of domain matching keyword:<br>
  105. <code>arozos.com</code> <br>Any acess requesting arozos.com will be proxy to the IP address below<br>
  106. <div class="ui divider"></div>
  107. <span style="font-size: 1.2em; font-weight: 300;"><i class="ui yellow star icon"></i> Subdomain</span><br>
  108. Example of subdomain matching keyword:<br>
  109. <code>s1.arozos.com</code> <br>Any request starting with s1.arozos.com will be proxy to the IP address below<br>
  110. <div class="ui divider"></div>
  111. <span style="font-size: 1.2em; font-weight: 300;"><i class="ui yellow star icon"></i> Wildcard</span><br>
  112. Example of wildcard matching keyword:<br>
  113. <code>*.arozos.com</code> <br>Any request with a host name matching *.arozos.com will be proxy to the IP address below. Here are some examples.<br>
  114. <div class="ui list">
  115. <div class="item"><code>www.arozos.com</code></div>
  116. <div class="item"><code>foo.bar.arozos.com</code></div>
  117. </div>
  118. <br>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <script>
  124. $("#advanceProxyRules").accordion();
  125. //New Proxy Endpoint
  126. function newProxyEndpoint(){
  127. var rootname = $("#rootname").val();
  128. var proxyDomain = $("#proxyDomain").val();
  129. var useTLS = $("#reqTls")[0].checked;
  130. var skipTLSValidation = $("#skipTLSValidation")[0].checked;
  131. var bypassGlobalTLS = $("#bypassGlobalTLS")[0].checked;
  132. var requireBasicAuth = $("#requireBasicAuth")[0].checked;
  133. var skipWebSocketOriginCheck = $("#skipWebsocketOriginCheck")[0].checked;
  134. if (rootname.trim() == ""){
  135. $("#rootname").parent().addClass("error");
  136. return
  137. }else{
  138. $("#rootname").parent().removeClass("error");
  139. }
  140. if (proxyDomain.trim() == ""){
  141. $("#proxyDomain").parent().addClass("error");
  142. return
  143. }else{
  144. $("#proxyDomain").parent().removeClass("error");
  145. }
  146. //Create the endpoint by calling add
  147. $.ajax({
  148. url: "/api/proxy/add",
  149. data: {
  150. type: "host",
  151. rootname: rootname,
  152. tls: useTLS,
  153. ep: proxyDomain,
  154. tlsval: skipTLSValidation,
  155. bpwsorg: skipWebSocketOriginCheck,
  156. bypassGlobalTLS: bypassGlobalTLS,
  157. bauth: requireBasicAuth,
  158. cred: JSON.stringify(credentials),
  159. },
  160. success: function(data){
  161. if (data.error != undefined){
  162. msgbox(data.error, false, 5000);
  163. }else{
  164. //Clear old data
  165. $("#rootname").val("");
  166. $("#proxyDomain").val("");
  167. credentials = [];
  168. updateTable();
  169. reloadUptimeList();
  170. //Check if it is a new subdomain and TLS enabled
  171. if ($("#tls").checkbox("is checked")){
  172. confirmBox("Request new SSL Cert for this subdomain?", function(choice){
  173. if (choice == true){
  174. //Load the prefer CA from TLS page
  175. let defaultCA = $("#defaultCA").dropdown("get value");
  176. if (defaultCA.trim() == ""){
  177. defaultCA = "Let's Encrypt";
  178. }
  179. //Get a new cert using ACME
  180. msgbox("Requesting certificate via " + defaultCA +"...");
  181. console.log("Trying to get a new certificate via ACME");
  182. //Request ACME for certificate, see cert.html component
  183. obtainCertificate(rootname, defaultCA.trim(), function(){
  184. // Renew the parent certificate list
  185. initManagedDomainCertificateList();
  186. });
  187. }else{
  188. msgbox("Proxy Endpoint Added");
  189. }
  190. });
  191. }else{
  192. msgbox("Proxy Endpoint Added");
  193. }
  194. }
  195. }
  196. });
  197. }
  198. //Generic functions for delete rp endpoints
  199. function deleteEndpoint(epoint){
  200. epoint = decodeURIComponent(epoint).hexDecode();
  201. if (confirm("Confirm remove proxy for :" + epoint + "?")){
  202. $.ajax({
  203. url: "/api/proxy/del",
  204. data: {ep: epoint, },
  205. success: function(){
  206. listProxyEndpoints();
  207. msgbox("Proxy Rule Deleted", true);
  208. reloadUptimeList();
  209. }
  210. })
  211. }
  212. }
  213. function autoCheckTls(targetDomain){
  214. $.ajax({
  215. url: "/api/proxy/tlscheck",
  216. data: {url: targetDomain},
  217. success: function(data){
  218. if (data.error != undefined){
  219. }else if (data == "https"){
  220. $("#reqTls").parent().checkbox("set checked");
  221. }else if (data == "http"){
  222. $("#reqTls").parent().checkbox("set unchecked");
  223. }
  224. }
  225. })
  226. }
  227. function toggleBasicAuth() {
  228. var basicAuthDiv = document.getElementById('basicAuthOnly');
  229. if ($("#requireBasicAuth").parent().checkbox("is checked")) {
  230. $("#basicAuthCredentials").removeClass("disabled");
  231. } else {
  232. $("#basicAuthCredentials").addClass("disabled");
  233. }
  234. }
  235. $("#requireBasicAuth").on('change', toggleBasicAuth);
  236. toggleBasicAuth();
  237. /*
  238. Credential Managements
  239. */
  240. let credentials = []; // Global variable to store credentials
  241. function addCredentials() {
  242. // Retrieve the username and password input values
  243. var username = $('#basicAuthCredUsername').val();
  244. var password = $('#basicAuthCredPassword').val();
  245. if(username == "" || password == ""){
  246. msgbox("Username or password cannot be empty", false, 5000);
  247. return;
  248. }
  249. // Create a new credential object
  250. var credential = {
  251. username: username,
  252. password: password
  253. };
  254. // Add the credential to the global credentials array
  255. credentials.push(credential);
  256. // Clear the input fields
  257. $('#basicAuthCredUsername').val('');
  258. $('#basicAuthCredPassword').val('');
  259. // Update the table body with the credentials
  260. updateTable();
  261. }
  262. function updateTable() {
  263. var tableBody = $('#basicAuthCredentialTable');
  264. tableBody.empty();
  265. if (credentials.length === 0) {
  266. tableBody.append('<tr><td colspan="3"><i class="ui green circle check icon"></i> No Entered Credential</td></tr>');
  267. } else {
  268. for (var i = 0; i < credentials.length; i++) {
  269. var credential = credentials[i];
  270. var username = credential.username;
  271. var password = credential.password.replace(/./g, '*'); // Replace each character with '*'
  272. var row = '<tr>' +
  273. '<td>' + username + '</td>' +
  274. '<td>' + password + '</td>' +
  275. '<td><button class="ui basic button" onclick="removeCredential(' + i + ');"><i class="red remove icon"></i> Remove</button></td>' +
  276. '</tr>';
  277. tableBody.append(row);
  278. }
  279. }
  280. }
  281. function removeCredential(index) {
  282. // Remove the credential from the credentials array
  283. credentials.splice(index, 1);
  284. // Update the table body
  285. updateTable();
  286. }
  287. //Update v3.0.0
  288. //Since some proxy rules now contains wildcard characters
  289. //all uuid are converted to hex code before use in DOM selector
  290. String.prototype.hexEncode = function(){
  291. var hex, i;
  292. var result = "";
  293. for (i=0; i<this.length; i++) {
  294. hex = this.charCodeAt(i).toString(16);
  295. result += ("000"+hex).slice(-4);
  296. }
  297. return result
  298. }
  299. String.prototype.hexDecode = function(){
  300. var j;
  301. var hexes = this.match(/.{1,4}/g) || [];
  302. var back = "";
  303. for(j = 0; j<hexes.length; j++) {
  304. back += String.fromCharCode(parseInt(hexes[j], 16));
  305. }
  306. return back;
  307. }
  308. </script>