configTools.html 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. <button class="ui basic button" onclick="downloadConfig();"><i class="ui blue download icon"></i> Download</button>
  21. <div class="ui divider"></div>
  22. <h3>Restore from Config</h3>
  23. <p>You can restore your previous settings and database from a zip file config backup. <b style="color: rgba(255, 0, 0, 0.644);">DO NOT UPLOAD ZIP FILE FROM UNKNOWN SOURCE</b></p>
  24. <form class="ui form" id="uploadForm" action="/api/conf/import" method="POST" enctype="multipart/form-data">
  25. <input type="file" name="file" id="fileInput" accept=".zip">
  26. <button style="margin-top: 0.6em;" class="ui basic button" type="submit"><i class="ui green upload icon"></i> Upload</button>
  27. </form>
  28. <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>
  29. <br><br>
  30. <button class="ui basic button" style="float: right;" onclick="parent.hideSideWrapper();"><i class="remove icon"></i> Cancel</button>
  31. </div>
  32. <script>
  33. function downloadConfig(){
  34. window.open("/api/conf/export");
  35. }
  36. document.getElementById("uploadForm").addEventListener("submit", function(event) {
  37. event.preventDefault(); // Prevent the form from submitting normally
  38. var fileInput = document.getElementById("fileInput");
  39. var file = fileInput.files[0];
  40. if (!file) {
  41. alert("Missing file.");
  42. return;
  43. }
  44. var formData = new FormData();
  45. formData.append("file", file);
  46. var xhr = new XMLHttpRequest();
  47. xhr.open("POST", "/api/conf/import", true);
  48. xhr.onreadystatechange = function() {
  49. if (xhr.readyState === XMLHttpRequest.DONE) {
  50. if (xhr.status === 200) {
  51. parent.msgbox("Config restore succeed. Restart Zoraxy to apply changes.")
  52. } else {
  53. parent.msgbox("Restore failed: " + xhr.responseText, false, 5000);
  54. }
  55. }
  56. };
  57. xhr.send(formData);
  58. });
  59. </script>
  60. </body>
  61. </html>