index.php 3.7 KB

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