customHeaders.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!-- Notes: This should be open in its original path-->
  5. <meta charset="utf-8">
  6. <meta name="zoraxy.csrf.Token" content="{{.csrfToken}}">
  7. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  8. <script src="../script/jquery-3.6.0.min.js"></script>
  9. <script src="../script/semantic/semantic.min.js"></script>
  10. <script src="../script/utils.js"></script>
  11. <style>
  12. .ui.tabular.menu .item.narrowpadding{
  13. padding: 0.6em !important;
  14. margin: 0.15em !important;
  15. }
  16. #permissionPolicyEditor.disabled{
  17. opacity: 0.4;
  18. pointer-events: none;
  19. user-select: none;
  20. }
  21. #permissionPolicyEditor .experimental{
  22. background-color: rgb(241, 241, 241);
  23. }
  24. body.darkTheme #permissionPolicyEditor .experimental{
  25. background-color: rgb(41, 41, 41);
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <link rel="stylesheet" href="../darktheme.css">
  31. <script src="../script/darktheme.js"></script>
  32. <br>
  33. <div class="ui container">
  34. <div class="ui header">
  35. <div class="content">
  36. Custom Headers
  37. <div class="sub header" id="epname"></div>
  38. </div>
  39. </div>
  40. <div class="ui divider"></div>
  41. <div class="ui small pointing secondary menu">
  42. <a class="item active narrowpadding" data-tab="customheaders">Custom Headers</a>
  43. <a class="item narrowpadding" data-tab="security">Security Headers</a>
  44. </div>
  45. <div class="ui tab basic segment active" data-tab="customheaders">
  46. <table class="ui very basic compacted unstackable celled table">
  47. <thead>
  48. <tr>
  49. <th>Key</th>
  50. <th>Value</th>
  51. <th>Remove</th>
  52. </tr></thead>
  53. <tbody id="headerTable">
  54. <tr>
  55. <td colspan="3"><i class="ui green circle check icon"></i> No Additonal Header</td>
  56. </tr>
  57. </tbody>
  58. </table>
  59. <p>
  60. <i class="angle double right blue icon"></i> Add or remove headers before sending to origin server <br>
  61. <i class="angle double left orange icon"></i> Modify headers from origin server responses before sending to client
  62. </p>
  63. <div class="ui divider"></div>
  64. <h4>Edit Custom Header</h4>
  65. <p>Add or remove custom header(s) over this proxy target</p>
  66. <div class="scrolling content ui form">
  67. <div class="five small fields credentialEntry">
  68. <div class="field" align="center">
  69. <button id="toOriginButton" style="margin-top: 0.6em;" title="Downstream to Upstream" class="ui circular basic active button">Zoraxy <i class="angle double right blue icon" style="margin-right: 0.4em;"></i> Origin</button>
  70. <button id="toClientButton" style="margin-top: 0.6em;" title="Upstream to Downstream" class="ui circular basic button">Client <i class="angle double left orange icon" style="margin-left: 0.4em;"></i> Zoraxy</button>
  71. </div>
  72. <div class="field" align="center">
  73. <button id="headerModeAdd" style="margin-top: 0.6em;" class="ui circular basic active button"><i class="ui green circle add icon"></i> Add Header</button>
  74. <button id="headerModeRemove" style="margin-top: 0.6em;" class="ui circular basic button"><i class="ui red circle times icon"></i> Remove Header</button>
  75. </div>
  76. <div class="field">
  77. <label>Header Key</label>
  78. <input id="headerName" type="text" placeholder="X-Custom-Header" autocomplete="off">
  79. <small>The header key is <b>NOT</b> case sensitive</small>
  80. </div>
  81. <div class="field">
  82. <label>Header Value</label>
  83. <input id="headerValue" type="text" placeholder="value1,value2,value3" autocomplete="off">
  84. </div>
  85. <div class="field" >
  86. <button class="ui basic button" onclick="addCustomHeader();"><i class="green add icon"></i> Add Header Rewrite Rule</button>
  87. </div>
  88. <div class="ui divider"></div>
  89. </div>
  90. </div>
  91. <div class="ui divider"></div>
  92. <div class="ui basic segment advanceoptions">
  93. <div class="ui fluid accordion">
  94. <div class="title">
  95. <i class="dropdown icon" tabindex="0"><div class="menu" tabindex="-1"></div></i>
  96. Advance Settings
  97. </div>
  98. <div class="content">
  99. <br>
  100. <div class="ui container">
  101. <h4>Overwrite Host Header</h4>
  102. <p>Manual override the automatic "Host" header rewrite logic. Leave empty for automatic.</p>
  103. <div class="ui fluid action input">
  104. <input type="text" id="manualHostOverwrite" placeholder="Overwrite Host name">
  105. <button onclick="updateManualHostOverwrite();" class="ui basic icon button" title="Update"><i class="ui green save icon"></i></button>
  106. <button onclick="clearManualHostOverwrite();" class="ui basic icon button" title="Clear"><i class="ui grey remove icon"></i></button>
  107. </div>
  108. <div class="ui divider"></div>
  109. <h4>Remove Hop-by-hop Headers</h4>
  110. <p>Remove headers like "Connection" and "Keep-Alive" from both upstream and downstream requests. Set to ON by default.</p>
  111. <div class="ui toggle checkbox">
  112. <input type="checkbox" id="removeHopByHop" name="">
  113. <label>Remove Hop-by-hop Header<br>
  114. <small>This should be ON by default</small></label>
  115. </div>
  116. <div class="ui divider"></div>
  117. <h4> WebSocket Custom Headers</h4>
  118. <p>Copy custom headers from HTTP requests to WebSocket connections.
  119. Might be required by some projects like MeshCentral.</p>
  120. <div class="ui toggle checkbox">
  121. <input type="checkbox" id="copyCustomHeadersWS" name="">
  122. <label>Enable WebSocket Custom Header<br>
  123. <small>This should be OFF by default</small></label>
  124. </div>
  125. <div class="ui yellow message">
  126. <p><i class="exclamation triangle icon"></i>Settings in this section are for advanced users. Invalid settings might cause werid, unexpected behavior.</p>
  127. </div>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. <div class="ui tab basic segment" data-tab="security">
  134. <h4>HTTP Strict Transport Security</h4>
  135. <p>Force future attempts to access this site to only use HTTPS</p>
  136. <div class="ui toggle checkbox">
  137. <input type="checkbox" id="enableHSTS" name="enableHSTS">
  138. <label>Enable HSTS<br>
  139. <small>HSTS header will be automatically ignored if the site is accessed using HTTP</small></label>
  140. </div>
  141. <div class="ui divider"></div>
  142. <h4>Permission Policy</h4>
  143. <p>Explicitly declare what functionality can and cannot be used on this website. </p>
  144. <div class="ui toggle checkbox" style="margin-top: 0.6em;">
  145. <input type="checkbox" id="enablePP" name="enablePP">
  146. <label>Enable Permission Policy<br>
  147. <small>Enable Permission-Policy header with all allowed state.</small></label>
  148. </div>
  149. <div style="margin-top: 1em;" id="permissionPolicyEditor">
  150. <table class="ui celled unstackable very compact table">
  151. <thead>
  152. <tr><th>Feature</th>
  153. <th>Enabled</th>
  154. <th>Allow All (*)</th>
  155. <th>Self Only (self)</th>
  156. </tr></thead>
  157. <tbody id="permissionPolicyEditTable">
  158. <tr>
  159. <td colspan="4"><i class="ui loading spinner icon"></i> Generating</td>
  160. </tr>
  161. </tbody>
  162. </table>
  163. </div>
  164. <small><i class="ui yellow exclamation triangle icon"></i> Grey out fields are non-standard permission policies</small>
  165. <br><br>
  166. <button class="ui basic button" onclick="savePermissionPolicy();"><i class="green save icon"></i> Save</button>
  167. </div>
  168. <div class="field" >
  169. <button class="ui basic button" style="float: right;" onclick="closeThisWrapper();">Close</button>
  170. </div>
  171. </div>
  172. <br><br><br><br>
  173. <script>
  174. $('.menu .item').tab();
  175. $(".accordion").accordion();
  176. let permissionPolicyKeys = [];
  177. let editingEndpoint = {};
  178. if (window.location.hash.length > 1){
  179. let payloadHash = window.location.hash.substr(1);
  180. try{
  181. payloadHash = JSON.parse(decodeURIComponent(payloadHash));
  182. $("#epname").text(payloadHash.ep);
  183. editingEndpoint = payloadHash;
  184. }catch(ex){
  185. console.log("Unable to load endpoint data from hash")
  186. }
  187. }
  188. function closeThisWrapper(){
  189. parent.hideSideWrapper(true);
  190. }
  191. //Bind events to header mod mode
  192. $("#headerModeAdd").on("click", function(){
  193. $("#headerModeAdd").addClass("active");
  194. $("#headerModeRemove").removeClass("active");
  195. $("#headerValue").parent().show();
  196. });
  197. $("#headerModeRemove").on("click", function(){
  198. $("#headerModeAdd").removeClass("active");
  199. $("#headerModeRemove").addClass("active");
  200. $("#headerValue").parent().hide();
  201. $("#headerValue").val("");
  202. });
  203. //Bind events to header directions option
  204. $("#toOriginButton").on("click", function(){
  205. $("#toOriginButton").addClass("active");
  206. $("#toClientButton").removeClass("active");
  207. });
  208. $("#toClientButton").on("click", function(){
  209. $("#toOriginButton").removeClass("active");
  210. $("#toClientButton").addClass("active");
  211. });
  212. //Return "add" or "remove" depending on mode user selected
  213. function getHeaderEditMode(){
  214. if ($("#headerModeAdd").hasClass("active")){
  215. return "add";
  216. }
  217. return "remove";
  218. }
  219. //Return "toOrigin" or "toClient"
  220. function getHeaderDirection(){
  221. if ($("#toOriginButton").hasClass("active")){
  222. return "toOrigin";
  223. }
  224. return "toClient";
  225. }
  226. //$("#debug").text(JSON.stringify(editingEndpoint));
  227. function addCustomHeader(){
  228. let name = $("#headerName").val().trim();
  229. let value = $("#headerValue").val().trim();
  230. if (name == ""){
  231. $("#headerName").parent().addClass("error");
  232. return
  233. }else{
  234. $("#headerName").parent().removeClass("error");
  235. }
  236. if (getHeaderEditMode() == "add"){
  237. if (value == ""){
  238. $("#headerValue").parent().addClass("error");
  239. return
  240. }else{
  241. $("#headerValue").parent().removeClass("error");
  242. }
  243. }
  244. $.cjax({
  245. url: "/api/proxy/header/add",
  246. method: "POST",
  247. data: {
  248. "type": getHeaderEditMode(),
  249. "domain": editingEndpoint.ep,
  250. "direction":getHeaderDirection(),
  251. "name": name,
  252. "value": value
  253. },
  254. success: function(data){
  255. if (data.error != undefined){
  256. if (parent != undefined && parent.msgbox != undefined){
  257. parent.msgbox(data.error,false);
  258. }else{
  259. alert(data.error);
  260. }
  261. }else{
  262. listCustomHeaders();
  263. if (parent != undefined && parent.msgbox != undefined){
  264. parent.msgbox("Custom header added",true);
  265. }
  266. //Clear the form
  267. $("#headerName").val("");
  268. $("#headerValue").val("");
  269. }
  270. }
  271. });
  272. }
  273. function deleteCustomHeader(name){
  274. $.cjax({
  275. url: "/api/proxy/header/remove",
  276. method: "POST",
  277. data: {
  278. "domain": editingEndpoint.ep,
  279. "name": name,
  280. },
  281. success: function(data){
  282. listCustomHeaders();
  283. if (parent != undefined && parent.msgbox != undefined){
  284. parent.msgbox("Custom header removed",true);
  285. }
  286. }
  287. });
  288. }
  289. function listCustomHeaders(){
  290. $("#headerTable").html(`<tr><td colspan="3"><i class="ui loading spinner icon"></i> Loading</td></tr>`);
  291. $.ajax({
  292. url: "/api/proxy/header/list",
  293. method: "GET",
  294. data: {
  295. "type": editingEndpoint.ept,
  296. "domain": editingEndpoint.ep,
  297. },
  298. success: function(data){
  299. if (data.error != undefined){
  300. alert(data.error);
  301. }else{
  302. $("#headerTable").html("");
  303. data.forEach(header => {
  304. let editModeIcon = header.IsRemove?`<i class="ui red times circle icon"></i>`:`<i class="ui green add circle icon"></i>`;
  305. let direction = (header.Direction==0)?`<i class="angle double right blue icon"></i>`:`<i class="angle double left orange icon"></i>`;
  306. let valueField = header.Value;
  307. if (header.IsRemove){
  308. valueField = "<small style='color: grey;'>(Field Removed)</small>";
  309. }
  310. $("#headerTable").append(`
  311. <tr>
  312. <td>${direction} ${header.Key}</td>
  313. <td>${editModeIcon} ${valueField}</td>
  314. <td><button class="ui basic circular mini red icon button" onclick="deleteCustomHeader('${header.Key}');"><i class="ui trash icon"></i></button></td>
  315. </tr>
  316. `);
  317. });
  318. if (data.length == 0){
  319. $("#headerTable").html(`<tr>
  320. <td colspan="3"><i class="ui green circle check icon"></i> No Additonal Header</td>
  321. </tr>`);
  322. }
  323. }
  324. },
  325. });
  326. }
  327. listCustomHeaders();
  328. //Start HSTS state
  329. function initHSTSState(){
  330. $.get("/api/proxy/header/handleHSTS?domain=" + editingEndpoint.ep, function(data){
  331. if (data == 0){
  332. //HSTS disabled
  333. $("#enableHSTS").parent().checkbox("set unchecked");
  334. }else{
  335. //HSTS enabled
  336. $("#enableHSTS").parent().checkbox("set checked");
  337. }
  338. /* Bind events to toggles */
  339. $("#enableHSTS").on("change", function(){
  340. let HSTSEnabled = $("#enableHSTS")[0].checked;
  341. $.cjax({
  342. url: "/api/proxy/header/handleHSTS",
  343. method: "POST",
  344. data: {
  345. "domain": editingEndpoint.ep,
  346. "maxage": HSTSEnabled?31536000:0,
  347. },
  348. success: function(data){
  349. if (data.error != undefined){
  350. parent.msgbox(data.error, false);
  351. }else{
  352. parent.msgbox(`HSTS ${HSTSEnabled?"Enabled":"Disabled"}`);
  353. }
  354. }
  355. })
  356. });
  357. });
  358. }
  359. initHSTSState();
  360. //Return true if this is an proposed permission policy feature
  361. function isExperimentalFeature(header) {
  362. // List of experimental features
  363. const experimentalFeatures = [
  364. "clipboard-read",
  365. "clipboard-write",
  366. "gamepad",
  367. "speaker-selection",
  368. "conversion-measurement",
  369. "focus-without-user-activation",
  370. "hid",
  371. "idle-detection",
  372. "interest-cohort",
  373. "serial",
  374. "sync-script",
  375. "trust-token-redemption",
  376. "unload",
  377. "window-placement",
  378. "vertical-scroll"
  379. ];
  380. header = header.replaceAll("_","-");
  381. // Check if the header is in the list of experimental features
  382. return experimentalFeatures.includes(header);
  383. }
  384. /* List permission policy header from server */
  385. function initPermissionPolicy(){
  386. $.get("/api/proxy/header/handlePermissionPolicy?domain=" + editingEndpoint.ep, function(data){
  387. if (data.error != undefined){
  388. console.log(data.error);
  389. $("#enablePP").parent().addClass('disabled');
  390. return;
  391. }
  392. //Set checkbox initial state
  393. if (data.PPEnabled){
  394. $("#enablePP").parent().checkbox("set checked");
  395. $("#permissionPolicyEditor").removeClass("disabled");
  396. }else{
  397. $("#enablePP").parent().checkbox("set unchecked");
  398. $("#permissionPolicyEditor").addClass("disabled");
  399. }
  400. //Bind toggle change events
  401. $("#enablePP").on("change", function(evt){
  402. //Set checkbox state
  403. let ppEnabled = $("#enablePP")[0].checked;
  404. if (ppEnabled){
  405. $("#permissionPolicyEditor").removeClass("disabled");
  406. }else{
  407. $("#permissionPolicyEditor").addClass("disabled");
  408. }
  409. $.cjax({
  410. url: "/api/proxy/header/handlePermissionPolicy",
  411. method: "POST",
  412. data: {
  413. enable: ppEnabled,
  414. domain: editingEndpoint.ep
  415. },
  416. success: function(data){
  417. if (data.error != undefined){
  418. parent.msgbox(data.error, false);
  419. }else{
  420. parent.msgbox(`Permission Policy ${ppEnabled?"Enabled":"Disabled"}`)
  421. }
  422. }
  423. })
  424. });
  425. //Render the table to list
  426. $("#permissionPolicyEditTable").html("");
  427. for (const [key, value] of Object.entries(data.CurrentPolicy)) {
  428. let allowall = "";
  429. let allowself = "";
  430. let enabled = "checked";
  431. if (value.length == 1 && value[0] == "*"){
  432. allowall = "checked";
  433. }else if (value.length == 1 && value[0] == "self"){
  434. allowself = "checked";
  435. }
  436. if (value.length == 0){
  437. enabled = ""
  438. allowall = "checked"; //default state
  439. }
  440. let isExperimental = isExperimentalFeature(key);
  441. $("#permissionPolicyEditTable").append(`<tr class="${isExperimental?"experimental":""}">
  442. <td>${key.replaceAll("_","-")}</td>
  443. <td>
  444. <div class="ui checkbox">
  445. <input class="enabled" type="checkbox" name="${key}" ${enabled}>
  446. <label></label>
  447. </div>
  448. </td>
  449. <td>
  450. <div class="ui radio checkbox targetinput ${!enabled?"disabled":""}">
  451. <input type="radio" value="all" name="${key}-target" ${allowall} ${!enabled?"disabled=\"\"":""}>
  452. <label></label>
  453. </div>
  454. </td>
  455. <td>
  456. <div class="ui radio checkbox targetinput ${!enabled?"disabled":""}">
  457. <input type="radio" value="self" name="${key}-target" ${allowself} ${!enabled?"disabled=\"\"":""}>
  458. <label></label>
  459. </div>
  460. </td>
  461. </tr>`);
  462. permissionPolicyKeys.push(key);
  463. }
  464. $("#permissionPolicyEditTable .enabled").on("change", function(){
  465. console.log($(this)[0].checked);
  466. let fieldGroup = $(this).parent().parent().parent();
  467. if ($(this)[0].checked){
  468. fieldGroup.find(".targetinput").removeClass("disabled");
  469. fieldGroup.find("input[type=radio]").prop('disabled', false);
  470. }else{
  471. fieldGroup.find(".targetinput").addClass("disabled");
  472. fieldGroup.find("input[type=radio]").prop('disabled', true);
  473. }
  474. })
  475. });
  476. }
  477. initPermissionPolicy();
  478. //Generate the permission policy object for sending to backend
  479. function generatePermissionPolicyObject(){
  480. function getStructuredFieldValueFromDOM(fieldKey){
  481. var policyTarget = $(`#permissionPolicyEditTable input[name="${fieldKey}-target"]:checked`).val();
  482. var isPolicyEnabled = $(`#permissionPolicyEditTable input[name="${fieldKey}"]`).is(':checked');
  483. if (!isPolicyEnabled){
  484. return [];
  485. }
  486. if (policyTarget == "all"){
  487. //Rewrite all to correct syntax
  488. policyTarget = "*";
  489. }
  490. return [policyTarget];
  491. }
  492. let newPermissionPolicyKeyValuePair = {};
  493. permissionPolicyKeys.forEach(policyKey => {
  494. newPermissionPolicyKeyValuePair[policyKey] = getStructuredFieldValueFromDOM(policyKey);
  495. });
  496. console.log(newPermissionPolicyKeyValuePair);
  497. return newPermissionPolicyKeyValuePair;
  498. }
  499. //Handle saving of permission policy
  500. function savePermissionPolicy(){
  501. let permissionPolicy = generatePermissionPolicyObject();
  502. let domain = editingEndpoint.ep;
  503. $.cjax({
  504. url: "/api/proxy/header/handlePermissionPolicy",
  505. method: "PUT",
  506. data: {
  507. "domain": domain,
  508. "pp": JSON.stringify(permissionPolicy),
  509. },
  510. success: function(data){
  511. if (data.error != undefined){
  512. parent.msgbox(data.error, false);
  513. }else{
  514. parent.msgbox("Permission Policy Updated");
  515. }
  516. }
  517. })
  518. }
  519. /* Manual HOST header overwrite */
  520. function updateManualHostOverwrite(){
  521. updateManualHostOverwriteVal(function(data){
  522. if (data.error != undefined){
  523. parent.msgbox(data.error, false);
  524. }else{
  525. parent.msgbox("Host field Overwrite Updated");
  526. initManualHostOverwriteValue();
  527. }
  528. });
  529. }
  530. function clearManualHostOverwrite(){
  531. $('#manualHostOverwrite').val('');
  532. updateManualHostOverwriteVal(function(data){
  533. if (data.error != undefined){
  534. parent.msgbox(data.error, false);
  535. }else{
  536. parent.msgbox("Host field Overwrite Cleared");
  537. initManualHostOverwriteValue();
  538. }
  539. })
  540. }
  541. function updateManualHostOverwriteVal(callback=undefined){
  542. let newHostname = $("#manualHostOverwrite").val().trim();
  543. $.cjax({
  544. url: "/api/proxy/header/handleHostOverwrite",
  545. method: "POST",
  546. data: {
  547. "domain": editingEndpoint.ep,
  548. "hostname": newHostname,
  549. },
  550. success: function(data){
  551. callback(data);
  552. }
  553. })
  554. }
  555. /* Manual Hostname overwrite */
  556. function initManualHostOverwriteValue(){
  557. $.get("/api/proxy/header/handleHostOverwrite?domain=" + editingEndpoint.ep, function(data){
  558. if (data.error != undefined){
  559. parent.msgbox(data.error, false);
  560. }else{
  561. $("#manualHostOverwrite").val(data);
  562. }
  563. });
  564. }
  565. initManualHostOverwriteValue();
  566. /* Hop-by-hop headers */
  567. function initHopByHopRemoverState(){
  568. $.get("/api/proxy/header/handleHopByHop?domain=" + editingEndpoint.ep, function(data){
  569. if (data.error != undefined){
  570. parent.msgbox(data.error);
  571. }else{
  572. if (data == true){
  573. $("#removeHopByHop").parent().checkbox("set checked");
  574. }else{
  575. $("#removeHopByHop").parent().checkbox("set unchecked");
  576. }
  577. //Bind event to the checkbox
  578. $("#removeHopByHop").on("change", function(evt){
  579. let isChecked = $(this)[0].checked;
  580. $.cjax({
  581. url: "/api/proxy/header/handleHopByHop",
  582. method: "POST",
  583. data: {
  584. "domain": editingEndpoint.ep,
  585. "removeHopByHop": isChecked,
  586. },
  587. success: function(data){
  588. if (data.error != undefined){
  589. parent.msgbox(data.error, false);
  590. }else{
  591. parent.msgbox("Hop-by-Hop header rule updated");
  592. }
  593. }
  594. })
  595. })
  596. }
  597. })
  598. }
  599. initHopByHopRemoverState();
  600. /* WebSocket Custom Headers */
  601. function initWebSocketCustomHeaderState(){
  602. $.get("/api/proxy/header/handleWsHeaderBehavior?domain=" + editingEndpoint.ep, function(data){
  603. if (data.error != undefined){
  604. parent.msgbox(data.error);
  605. }else{
  606. if (data == true){
  607. $("#copyCustomHeadersWS").parent().checkbox("set checked");
  608. }else{
  609. $("#copyCustomHeadersWS").parent().checkbox("set unchecked");
  610. }
  611. //Bind event to the checkbox
  612. $("#copyCustomHeadersWS").on("change", function(evt){
  613. let isChecked = $(this)[0].checked;
  614. $.cjax({
  615. url: "/api/proxy/header/handleWsHeaderBehavior",
  616. method: "POST",
  617. data: {
  618. "domain": editingEndpoint.ep,
  619. "enable": isChecked,
  620. },
  621. success: function(data){
  622. if (data.error != undefined){
  623. parent.msgbox(data.error, false);
  624. }else{
  625. parent.msgbox("WebSocket Custom Header rule updated");
  626. }
  627. }
  628. })
  629. })
  630. }
  631. })
  632. }
  633. initWebSocketCustomHeaderState();
  634. </script>
  635. </body>
  636. </html>