1
0

configTools.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. </head>
  12. <body>
  13. <link rel="stylesheet" href="../darktheme.css">
  14. <script src="../script/darktheme.js"></script>
  15. <br>
  16. <div class="ui container">
  17. <div class="ui header">
  18. <div class="content">
  19. Config Export and Import Tool
  20. <div class="sub header">Painless migration with one click</div>
  21. </div>
  22. </div>
  23. <h3>Backup Current Configs</h3>
  24. <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>
  25. <div class="ui form">
  26. <div class="grouped fields">
  27. <label>Backup Mode</label>
  28. <div class="field">
  29. <div class="ui radio checkbox">
  30. <input type="radio" value="rules" name="backupmode" checked="checked">
  31. <label>Proxy Settings, Redirect Rules and Certificates Only</label>
  32. </div>
  33. </div>
  34. <div class="field">
  35. <div class="ui radio checkbox">
  36. <input type="radio" value="full" name="backupmode">
  37. <label>Full System Snapshot</label>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. <br>
  43. <button class="ui basic button" onclick="downloadConfig();"><i class="ui blue download icon"></i> Download</button>
  44. <div class="ui divider"></div>
  45. <h3>Restore from Config</h3>
  46. <p>You can restore your previous settings and database from a zip file config backup.
  47. <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>
  48. </b></p>
  49. <form class="ui form" id="uploadForm" action="/api/conf/import" method="POST" enctype="multipart/form-data">
  50. <input type="file" name="file" id="fileInput" accept=".zip">
  51. <button style="margin-top: 0.6em;" class="ui basic button" type="submit"><i class="ui green upload icon"></i> Restore & Exit</button>
  52. </form>
  53. <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>
  54. <br><br>
  55. <button class="ui basic button" style="float: right;" onclick="parent.hideSideWrapper();"><i class="remove icon"></i> Cancel</button>
  56. </div>
  57. <script>
  58. $(".checkbox").checkbox();
  59. function getCheckedRadioValue() {
  60. var checkedValue = $("input[name='backupmode']:checked").val();
  61. return checkedValue;
  62. }
  63. function downloadConfig(){
  64. let backupMode = getCheckedRadioValue();
  65. if (backupMode == "full"){
  66. window.open("/api/conf/export?includeDB=true");
  67. }else{
  68. window.open("/api/conf/export");
  69. }
  70. }
  71. $("#uploadForm").submit(function(event) {
  72. event.preventDefault(); // Prevent the form from submitting normally
  73. var fileInput = $("#fileInput")[0];
  74. var file = fileInput.files[0];
  75. if (!file) {
  76. alert("Missing file.");
  77. return;
  78. }
  79. var formData = new FormData();
  80. formData.append("file", file);
  81. $.cjax({
  82. url: "/api/conf/import",
  83. type: "POST",
  84. data: formData,
  85. processData: false, // Not to process the data
  86. contentType: false, // Not to set contentType
  87. success: function(response) {
  88. parent.msgbox("Config restore succeed. Restart Zoraxy to apply changes.");
  89. },
  90. error: function(xhr) {
  91. parent.msgbox("Restore failed: " + xhr.responseText, false, 5000);
  92. }
  93. });
  94. });
  95. </script>
  96. </body>
  97. </html>