[gollem] tilde notation in "change directory"

Liam Hoekenga liamr at umich.edu
Tue Dec 17 14:49:06 PST 2002


I'm trying to get "change directory" to accept ~username notation (as used
in most shell or ftp session).  What I've got thusfar works, but is
shaping up to be too site specific, and I'm looking for advice.  I'd love
to see a more generic version of this get included - then we can maintain
localizations if we have to.

Our user names are words consisting of all lowercase letters 3-8
characters long.  "real" user UIDs begin at 1000.  So, I figure, if it's a
user, we can build the home directory from some sort of rule (maybe
params['home'] could be leveraged towards this end?).

We also have group home directories, and that's fairly site specific
(there is no computer predictable rule as to where those directories lay),
so I'm doing a posix_getpwnam() to fetch the home directory information.
If the home directory is located within the vfsroot, we can use it.  We
could do this for users too, but I thought that building a safe path using
some sort of rule would be better when we can.

In both cases, I'd like to see the path displayed as
"~username/directory/" instead of
"/location/of/user/directory/from/vfsroot/username/directory", but that'll
take some changes to setLabel() in lib/Gollem.php.

Anyhoo.. this feels messy.  Suggestions?   My diff is attached.

Liam

Index: manager.php
===================================================================
RCS file: /repository/gollem/manager.php,v
retrieving revision 1.46
diff -U2 -r1.46 manager.php
--- manager.php 17 Dec 2002 02:58:37 -0000      1.46
+++ manager.php 17 Dec 2002 19:35:43 -0000
@@ -55,5 +55,20 @@
     if (array_key_exists('change_directory', $_POST) &&
         !empty($_POST['change_directory'])) {
-        $_SESSION['gollem']['dir'] = $_POST['change_directory'];
+        if ( preg_match('|^~(/.*)*$|', $_POST['change_directory'], $a) )
{
+            $_SESSION['gollem']['dir'] =
$_SESSION['gollem']['params']['home'] . $a[1];
+        } elseif ( preg_match('|^~([a-z]{3,8})(/.*)*$|',
+            $_POST['change_directory'], $a) ) {
+                $pw_entry = posix_getpwnam($a[1]);
+                if ( $pw_entry['uid'] >= 1000) {
+                    $_SESSION['gollem']['dir'] = '/user/'
+                    . substr( $a[1], 0, 1) . '/' . substr( $a[1], 1, 1)
+                    . '/' . $a[1] . $a[2];
+                } else {
+                    if ( preg_match('|^' .
$_SESSION['gollem']['params']['vfsroot'] . '(/.*)*$|', $pw_entry['dir'],
$b) )
+                    $_SESSION['gollem']['dir'] = $b[1] . $a[2];
+                }
+        } else {
+            $_SESSION['gollem']['dir'] = $_POST['change_directory'];
+        }
         Gollem::setLabel();
     }



More information about the gollem mailing list