configTools.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!-- Notes: This should be open in its original path-->
  5. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  6. <script src="../script/jquery-3.6.0.min.js"></script>
  7. <script src="../script/semantic/semantic.min.js"></script>
  8. </head>
  9. <body>
  10. <br>
  11. <div class="ui container">
  12. <div class="ui header">
  13. <div class="content">
  14. Config Export and Import Tool
  15. <div class="sub header">Painless migration with one click</div>
  16. </div>
  17. </div>
  18. <h3>Backup Current Configs</h3>
  19. <p>This will download all your configuration on zoraxy in a zip file. This includes all the proxy configs and certificates. Please keep it somewhere safe and after migration, delete this if possible.</p>
  20. <div class="ui form">
  21. <div class="grouped fields">
  22. <label>Backup Mode</label>
  23. <div class="field">
  24. <div class="ui radio checkbox">
  25. <input type="radio" value="rules" name="backupmode" checked="checked">
  26. <label>Proxy Settings, Redirect Rules and Certificates Only</label>
  27. </div>
  28. </div>
  29. <div class="field">
  30. <div class="ui radio checkbox">
  31. <input type="radio" value="full" name="backupmode">
  32. <label>Full System Snapshot</label>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. <br>
  38. <button class="ui basic button" onclick="downloadConfig();"><i class="ui blue download icon"></i> Download</button>
  39. <div class="ui divider"></div>
  40. <h3>Restore from Config</h3>
  41. <p>You can restore your previous settings and database from a zip file config backup.
  42. <b style="color: rgba(255, 0, 0, 0.644);">DO NOT UPLOAD ZIP FILE FROM UNKNOWN SOURCE<br>
  43. </b></p>
  44. <form class="ui form" id="uploadForm" action="/api/conf/import" method="POST" enctype="multipart/form-data">
  45. <input type="file" name="file" id="fileInput" accept=".zip">
  46. <button style="margin-top: 0.6em;" class="ui basic button" type="submit"><i class="ui green upload icon"></i> Upload</button>
  47. </form>
  48. <small>The current config will be backup to ./conf_old{timestamp}. If you screw something up, you can always restore it by ssh to your host and restore the configs from the old folder.</small>
  49. <br><br>
  50. <button class="ui basic button" style="float: right;" onclick="parent.hideSideWrapper();"><i class="remove icon"></i> Cancel</button>
  51. </div>
  52. <script>
  53. $(".checkbox").checkbox();
  54. function getCheckedRadioValue() {
  55. var checkedValue = $("input[name='backupmode']:checked").val();
  56. return checkedValue;
  57. }
  58. function downloadConfig(){
  59. let backupMode = getCheckedRadioValue();
  60. if (backupMode == "full"){
  61. window.open("/api/conf/export?includeDB=true");
  62. }else{
  63. window.open("/api/conf/export");
  64. }
  65. }
  66. document.getElementById("uploadForm").addEventListener("submit", function(event) {
  67. event.preventDefault(); // Prevent the form from submitting normally
  68. var fileInput = document.getElementById("fileInput");
  69. var file = fileInput.files[0];
  70. if (!file) {
  71. alert("Missing file.");
  72. return;
  73. }
  74. var formData = new FormData();
  75. formData.append("file", file);
  76. var xhr = new XMLHttpRequest();
  77. xhr.open("POST", "/api/conf/import", true);
  78. xhr.onreadystatechange = function() {
  79. if (xhr.readyState === XMLHttpRequest.DONE) {
  80. if (xhr.status === 200) {
  81. parent.msgbox("Config restore succeed. Restart Zoraxy to apply changes.")
  82. } else {
  83. parent.msgbox("Restore failed: " + xhr.responseText, false, 5000);
  84. }
  85. }
  86. };
  87. xhr.send(formData);
  88. });
  89. </script>
  90. </body>
  91. </html>