index.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. ob_start();
  4. $TAB = "BACKUP";
  5. include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
  6. // Edit as someone else?
  7. if ($_SESSION["userContext"] === "admin" && !empty($_GET["user"])) {
  8. $user = quoteshellarg($_GET["user"]);
  9. }
  10. // List backup exclustions
  11. exec(HESTIA_CMD . "v-list-user-backup-exclusions " . $user . " 'json'", $output, $return_var);
  12. check_return_code($return_var, $output);
  13. $data = json_decode(implode("", $output), true);
  14. unset($output);
  15. // Parse web
  16. $v_username = $user;
  17. foreach ($data["WEB"] as $key => $value) {
  18. if (!empty($value)) {
  19. $v_web .= $key . ":" . str_replace(",", ":", $value) . "\n";
  20. } else {
  21. $v_web .= $key . "\n";
  22. }
  23. }
  24. // Parse dns
  25. foreach ($data["DNS"] as $key => $value) {
  26. if (!empty($value)) {
  27. $v_dns .= $key . ":" . $value . "\n";
  28. } else {
  29. $v_dns .= $key . "\n";
  30. }
  31. }
  32. // Parse mail
  33. foreach ($data["MAIL"] as $key => $value) {
  34. if (!empty($value)) {
  35. $v_mail .= $key . ":" . $value . "\n";
  36. } else {
  37. $v_mail .= $key . "\n";
  38. }
  39. }
  40. // Parse databases
  41. foreach ($data["DB"] as $key => $value) {
  42. if (!empty($value)) {
  43. $v_db .= $key . ":" . $value . "\n";
  44. } else {
  45. $v_db .= $key . "\n";
  46. }
  47. }
  48. // Parse user directories
  49. foreach ($data["USER"] as $key => $value) {
  50. if (!empty($value)) {
  51. $v_userdir .= $key . ":" . $value . "\n";
  52. } else {
  53. $v_userdir .= $key . "\n";
  54. }
  55. }
  56. // Check POST request
  57. if (!empty($_POST["save"])) {
  58. // Check token
  59. verify_csrf($_POST);
  60. $v_web = $_POST["v_web"];
  61. $v_web_tmp = str_replace("\r\n", ",", $_POST["v_web"]);
  62. $v_web_tmp = rtrim($v_web_tmp, ",");
  63. $v_web_tmp = "WEB=" . quoteshellarg($v_web_tmp);
  64. $v_dns = $_POST["v_dns"];
  65. $v_dns_tmp = str_replace("\r\n", ",", $_POST["v_dns"]);
  66. $v_dns_tmp = rtrim($v_dns_tmp, ",");
  67. $v_dns_tmp = "DNS=" . quoteshellarg($v_dns_tmp);
  68. $v_mail = $_POST["v_mail"];
  69. $v_mail_tmp = str_replace("\r\n", ",", $_POST["v_mail"]);
  70. $v_mail_tmp = rtrim($v_mail_tmp, ",");
  71. $v_mail_tmp = "MAIL=" . quoteshellarg($v_mail_tmp);
  72. $v_db = $_POST["v_db"];
  73. $v_db_tmp = str_replace("\r\n", ",", $_POST["v_db"]);
  74. $v_db_tmp = rtrim($v_db_tmp, ",");
  75. $v_db_tmp = "DB=" . quoteshellarg($v_db_tmp);
  76. $v_cron = $_POST["v_cron"];
  77. $v_cron_tmp = str_replace("\r\n", ",", $_POST["v_cron"]);
  78. $v_cron_tmp = rtrim($v_cron_tmp, ",");
  79. $v_cron_tmp = "CRON=" . quoteshellarg($v_cron_tmp);
  80. $v_userdir = $_POST["v_userdir"];
  81. $v_userdir_tmp = str_replace("\r\n", ",", $_POST["v_userdir"]);
  82. $v_userdir_tmp = rtrim($v_userdir_tmp, ",");
  83. $v_userdir_tmp = "USER=" . quoteshellarg($v_userdir_tmp);
  84. // Create temporary exeption list on a filesystem
  85. exec("mktemp", $mktemp_output, $return_var);
  86. $tmp = $mktemp_output[0];
  87. $fp = fopen($tmp, "w");
  88. fwrite(
  89. $fp,
  90. $v_web_tmp .
  91. "\n" .
  92. $v_dns_tmp .
  93. "\n" .
  94. $v_mail_tmp .
  95. "\n" .
  96. $v_db_tmp .
  97. "\n" .
  98. $v_userdir_tmp .
  99. "\n",
  100. );
  101. fclose($fp);
  102. unset($mktemp_output);
  103. // Save changes
  104. exec(
  105. HESTIA_CMD . "v-update-user-backup-exclusions " . $user . " " . $tmp,
  106. $output,
  107. $return_var,
  108. );
  109. check_return_code($return_var, $output);
  110. unset($output);
  111. // Set success message
  112. if (empty($_SESSION["error_msg"])) {
  113. $_SESSION["ok_msg"] = _("Changes have been saved.");
  114. }
  115. }
  116. // Render page
  117. render_page($user, $TAB, "edit_backup_exclusions");
  118. // Flush session messages
  119. unset($_SESSION["error_msg"]);
  120. unset($_SESSION["ok_msg"]);