index.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // Init
  3. error_reporting(NULL);
  4. ob_start();
  5. session_start();
  6. $TAB = 'BACKUP';
  7. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  8. // Edit as someone else?
  9. if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
  10. $user = $_GET['user'];
  11. }
  12. // List backup exclustions
  13. v_exec('v-list-user-backup-exclusions', [$user, 'json'], true, $output);
  14. $data = json_decode($output, true);
  15. // Parse web
  16. $v_username = $user;
  17. foreach ($data['WEB'] as $key => $value) {
  18. if (!empty($value)){
  19. $v_web .= $key . ":" . $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. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  60. header('location: /login/');
  61. exit;
  62. }
  63. // TODO: Use array?
  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. v_exec('v-update-user-backup-exclusions', [$user, $tmp]);
  97. // Set success message
  98. if (empty($_SESSION['error_msg'])) {
  99. $_SESSION['ok_msg'] = __("Changes has been saved.");
  100. }
  101. }
  102. // Header
  103. include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
  104. // Panel
  105. top_panel($user,$TAB);
  106. // Display body
  107. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/edit_backup_exclusions.html');
  108. // Flush session messages
  109. unset($_SESSION['error_msg']);
  110. unset($_SESSION['ok_msg']);
  111. // Footer
  112. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');