settings.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Settings: admin password change plus the legal pages (Impressum /
  4. * Datenschutz), which are stored as basic Markdown in data/site.json.
  5. */
  6. require dirname(__DIR__) . '/app/bootstrap.php';
  7. auth_require();
  8. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  9. csrf_verify();
  10. if (($_POST['section'] ?? '') === 'legal') {
  11. $site = site_get();
  12. $site['impressum'] = trim((string)($_POST['impressum'] ?? ''));
  13. $site['datenschutz'] = trim((string)($_POST['datenschutz'] ?? ''));
  14. site_save($site);
  15. flash_set('Legal pages saved.');
  16. redirect('settings.php');
  17. }
  18. $new = (string)($_POST['new_password'] ?? '');
  19. if ($new !== (string)($_POST['new_password2'] ?? '')) {
  20. flash_set('New passwords do not match.', 'error');
  21. } else {
  22. $err = auth_change_password((string)($_POST['current_password'] ?? ''), $new);
  23. flash_set($err ?? 'Password changed.', $err ? 'error' : 'ok');
  24. }
  25. redirect('settings.php');
  26. }
  27. $site = site_get();
  28. admin_header('Settings', 'settings');
  29. flash_render();
  30. ?>
  31. <h1>Settings</h1>
  32. <form method="post" class="card" style="max-width:26rem">
  33. <?= csrf_field() ?>
  34. <h2 style="margin-top:0">Change password</h2>
  35. <label for="c">Current password</label>
  36. <input type="password" id="c" name="current_password" autocomplete="current-password">
  37. <label for="n1">New password</label>
  38. <input type="password" id="n1" name="new_password" autocomplete="new-password">
  39. <label for="n2">Repeat new password</label>
  40. <input type="password" id="n2" name="new_password2" autocomplete="new-password">
  41. <p class="help">At least 8 characters. Written to config/credentials.php.</p>
  42. <button type="submit">Change password</button>
  43. </form>
  44. <form method="post" class="card">
  45. <?= csrf_field() ?>
  46. <input type="hidden" name="section" value="legal">
  47. <h2 style="margin-top:0">Legal pages</h2>
  48. <p class="help" style="margin-top:0">
  49. Basic Markdown is supported: <code># Heading</code>, <code>- list item</code>,
  50. <code>**bold**</code>, <code>*italic*</code>, <code>[text](https://…)</code>.
  51. </p>
  52. <label for="imp">Impressum <a href="../impressum.php" target="_blank" rel="noopener">view ↗</a></label>
  53. <textarea id="imp" name="impressum" style="min-height:14rem"><?= e($site['impressum'] ?? '') ?></textarea>
  54. <label for="dsg">Datenschutz <a href="../datenschutz.php" target="_blank" rel="noopener">view ↗</a></label>
  55. <textarea id="dsg" name="datenschutz" style="min-height:14rem"><?= e($site['datenschutz'] ?? '') ?></textarea>
  56. <button type="submit">Save legal pages</button>
  57. </form>
  58. <p class="help">
  59. Username and S3 settings are edited directly in the files under <code>config/</code>.
  60. </p>
  61. <?php admin_footer(); ?>