1
0

configTools.html 4.7 KB

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