admin-notes.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. require_once('../include/prepend.php');
  3. require_once('../include/cvs-auth.inc');
  4. require_once('../include/email-validation.inc');
  5. $referer = isset($_POST['referer']) ? $_POST['referer'] : null;
  6. if ($user = get_user()) {
  7. if (!$referer) {
  8. $referer = '../admin-login.php';
  9. }
  10. /* set up a test db and a cookie to notify the rest of the site */
  11. if (array_key_exists('test', $_GET) && in_array($user, $docteam)) {
  12. print "<form method = 'POST' action = '{$_SERVER['PHP_SELF']}'>";
  13. print "<p>Please enter a valid email address where you can accept test messages:</p>";
  14. print "<input type = 'text' name = 'adminmail' size = '40' maxlength = '40' />";
  15. print "<input type = 'hidden' name = 'referer' value = '$referer' />";
  16. print "<input type = 'submit' value = 'Submit' />";
  17. print "</form>";
  18. exit;
  19. }
  20. if (isset($_POST['adminmail']) && in_array($user, $docteam)) {
  21. /* validate it */
  22. if (!preg_match($email_regex, $_POST['adminmail']) || strstr($_POST['adminmail'], 'lists.php')) {
  23. header("Location: $referer");
  24. exit;
  25. }
  26. if (file_exists($notesfile) && file_exists($queuefile) && file_exists($last_id)) {
  27. if (!file_exists(DB_DIR."/$user.notes.sqlite")) {
  28. if (!copy($notesfile, DB_DIR."/$user.notes.sqlite") ||
  29. !copy($queuefile, DB_DIR."/$user.queue.sqlite") ||
  30. !copy($last_id, DB_DIR."/$user.lastid.txt")) {
  31. if (file_exists(DB_DIR."/$user.notes.sqlite")) unlink(DB_DIR."/$user.notes.sqlite");
  32. if (file_exists(DB_DIR."/$user.queue.sqlite")) unlink(DB_DIR."/$user.queue.sqlite");
  33. if (file_exists(DB_DIR."/$user.lastid.txt")) unlink(DB_DIR."/$user.lastid.txt");
  34. print "<p>Unable to create a test environment at this time. Complain to Steph!</p>";
  35. print "<a href = '$referer'>Back</a>";
  36. exit;
  37. }
  38. }
  39. $adminmail = trim($_POST['adminmail']);
  40. setcookie($user, $adminmail, time()+(3600*6), '/');
  41. }
  42. } elseif (array_key_exists('m', $_GET)) {
  43. /* switch outgoing mail on/off */
  44. if (in_array($user, $systems)) {
  45. if (file_exists($mailfile)) {
  46. unlink($mailfile);
  47. } else {
  48. file_put_contents($mailfile, 'OK');
  49. }
  50. }
  51. } else {
  52. /* switch public viewing of manual notes on/off */
  53. if (in_array($user, $systems)) {
  54. if (file_exists($okfile)) {
  55. unlink($okfile);
  56. } else {
  57. file_put_contents($okfile, 'OK');
  58. }
  59. }
  60. }
  61. }
  62. if (!$referer) {
  63. $referer = '/';
  64. }
  65. header("Location: $referer");
  66. ?>