index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. // Init
  3. error_reporting(NULL);
  4. ob_start();
  5. $TAB = 'BACKUP';
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. // Edit as someone else?
  8. if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
  9. $user=escapeshellarg($_GET['user']);
  10. }
  11. // List backup exclustions
  12. exec (VESTA_CMD."v-list-user-backup-exclusions ".$user." json", $output, $return_var);
  13. check_return_code($return_var,$output);
  14. $data = json_decode(implode('', $output), true);
  15. unset($output);
  16. // Parse web
  17. $v_username = $user;
  18. foreach ($data['WEB'] as $key => $value) {
  19. if (!empty($value)){
  20. $v_web .= $key . ":" . $value. "\n";
  21. } else {
  22. $v_web .= $key . "\n";
  23. }
  24. }
  25. // Parse dns
  26. foreach ($data['DNS'] as $key => $value) {
  27. if (!empty($value)){
  28. $v_dns .= $key . ":" . $value. "\n";
  29. } else {
  30. $v_dns .= $key . "\n";
  31. }
  32. }
  33. // Parse mail
  34. foreach ($data['MAIL'] as $key => $value) {
  35. if (!empty($value)){
  36. $v_mail .= $key . ":" . $value. "\n";
  37. } else {
  38. $v_mail .= $key . "\n";
  39. }
  40. }
  41. // Parse databases
  42. foreach ($data['DB'] as $key => $value) {
  43. if (!empty($value)){
  44. $v_db .= $key . ":" . $value. "\n";
  45. } else {
  46. $v_db .= $key . "\n";
  47. }
  48. }
  49. // Parse user directories
  50. foreach ($data['USER'] as $key => $value) {
  51. if (!empty($value)){
  52. $v_userdir .= $key . ":" . $value. "\n";
  53. } else {
  54. $v_userdir .= $key . "\n";
  55. }
  56. }
  57. // Check POST request
  58. if (!empty($_POST['save'])) {
  59. // Check token
  60. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  61. header('location: /login/');
  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. // Render page
  105. render_page($user, $TAB, 'edit_backup_exclusions');
  106. // Flush session messages
  107. unset($_SESSION['error_msg']);
  108. unset($_SESSION['ok_msg']);