login/emulate: request page as different user v3.6
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 9 Aug 2018 16:12:42 +0000 (18:12 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 11 Aug 2018 08:09:44 +0000 (10:09 +0200)
Admin feature to download user-customised texts
(in particular the welcoming letter to be sent to everyone).

auth.inc.php
login/emulate/index.php [new file with mode: 0644]

index 631bf8b06cccb33f6e64bce65d217c29cdb50acf..a2db9f31f1b385b8284c5a97360ed6edeb35abbb 100644 (file)
@@ -5,6 +5,9 @@ class User
 {
        function __construct($dir)
        {
 {
        function __construct($dir)
        {
+               if (!file_exists($dir)) {
+                       throw new Exception("Gebruiker niet gevonden in $dir");
+               }
                $this->dir = $dir;
                $this->login = basename($dir);
        }
                $this->dir = $dir;
                $this->login = basename($dir);
        }
diff --git a/login/emulate/index.php b/login/emulate/index.php
new file mode 100644 (file)
index 0000000..b5c3e69
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+ob_clean();
+
+@list ($username, $request) = explode('/', ltrim($Args, '/'), 2);
+try {
+       $user = new User("profile/$username");
+}
+catch (Exception $e) {
+       printf('<p class=warn>%s</p>', $e->getMessage());
+       return;
+}
+
+$Place['login/name'] = $user->name ?: 'bewoner';
+$Place['user'] = $user->login;
+if ( $password = trim(@file_get_contents("{$user->dir}/.passwd")) ) {
+       if (substr($password, 0, 1) == '$') {
+               $password = NULL; // hashed
+       }
+       $Place['pass'] = htmlspecialchars($password) ?: '<em>zelf ingesteld</em>';
+}
+include ($request ?: 'index').'.html';