configTools.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!-- Notes: This should be open in its original path-->
  5. <meta charset="utf-8">
  6. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  7. <script src="../script/jquery-3.6.0.min.js"></script>
  8. <script src="../script/semantic/semantic.min.js"></script>
  9. </head>
  10. <body>
  11. <br>
  12. <div class="ui container">
  13. <div class="ui header">
  14. <div class="content">
  15. Config Export and Import Tool
  16. <div class="sub header">Painless migration with one click</div>
  17. </div>
  18. </div>
  19. <h3>Backup Current Configs</h3>
  20. <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>
  21. <div class="ui form">
  22. <div class="grouped fields">
  23. <label>Backup Mode</label>
  24. <div class="field">
  25. <div class="ui radio checkbox">
  26. <input type="radio" value="rules" name="backupmode" checked="checked">
  27. <label>Proxy Settings, Redirect Rules and Certificates Only</label>
  28. </div>
  29. </div>
  30. <div class="field">
  31. <div class="ui radio checkbox">
  32. <input type="radio" value="full" name="backupmode">
  33. <label>Full System Snapshot</label>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. <br>
  39. <button class="ui basic button" onclick="downloadConfig();"><i class="ui blue download icon"></i> Download</button>
  40. <div class="ui divider"></div>
  41. <h3>Restore from Config</h3>
  42. <p>You can restore your previous settings and database from a zip file config backup.
  43. <br><b style="color: rgba(255, 0, 0, 0.644);">RESTORE FULL SYSTEM SNAPSHOT WILL CAUSE THE SYSTEM TO SHUTDOWN AFTER COMPLETED. Make sure your Zoraxy is configured to work with systemd to automatic restart Zoraxy after system restore completed.<br>
  44. </b></p>
  45. <form class="ui form" id="uploadForm" action="/api/conf/import" method="POST" enctype="multipart/form-data">
  46. <input type="file" name="file" id="fileInput" accept=".zip">
  47. <button style="margin-top: 0.6em;" class="ui basic button" type="submit"><i class="ui green upload icon"></i> Restore & Exit</button>
  48. </form>
  49. <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>
  50. <br><br>
  51. <button class="ui basic button" style="float: right;" onclick="parent.hideSideWrapper();"><i class="remove icon"></i> Cancel</button>
  52. </div>
  53. <script>
  54. $(".checkbox").checkbox();
  55. function getCheckedRadioValue() {
  56. var checkedValue = $("input[name='backupmode']:checked").val();
  57. return checkedValue;
  58. }
  59. function downloadConfig(){
  60. let backupMode = getCheckedRadioValue();
  61. if (backupMode == "full"){
  62. window.open("/api/conf/export?includeDB=true");
  63. }else{
  64. window.open("/api/conf/export");
  65. }
  66. }
  67. document.getElementById("uploadForm").addEventListener("submit", function(event) {
  68. event.preventDefault(); // Prevent the form from submitting normally
  69. var fileInput = document.getElementById("fileInput");
  70. var file = fileInput.files[0];
  71. if (!file) {
  72. alert("Missing file.");
  73. return;
  74. }
  75. var formData = new FormData();
  76. formData.append("file", file);
  77. var xhr = new XMLHttpRequest();
  78. xhr.open("POST", "/api/conf/import", true);
  79. xhr.onreadystatechange = function() {
  80. if (xhr.readyState === XMLHttpRequest.DONE) {
  81. if (xhr.status === 200) {
  82. parent.msgbox("Config restore succeed. Restart Zoraxy to apply changes.")
  83. } else {
  84. parent.msgbox("Restore failed: " + xhr.responseText, false, 5000);
  85. }
  86. }
  87. };
  88. xhr.send(formData);
  89. });
  90. </script>
  91. </body>
  92. </html>