Forum OpenACS Q&A: users and "~user" apache emulation

Posted by Rafael Calvo on
I posted this inthe opennsd bboard but it seems kind of "sleepy" so I
repost it here.
      I am trying to replace an Apache server por aolserver,and later
add openACS. Each user had a public_html directory in their $HOME and
apache pointed to http://hostname/~user. How can I emulate this in
aolserver? with the least effort for users (and admin :-)

Posted by Todd Gillespie on
proc tilde_to_user_filter {} {
    set tilde_user_name [lindex [ns_conn urlv] 0]
    set user_name [url_decode [string range $tilde_user_name 2 end]]
    set db [ns_db gethandle] 
    set user_id [database_to_tcl_string $db "select user_id from users 
	where screen_name = '[DoubleApos $user_name]'"]
    ns_db releasehandle $db
    ns_returnredirect "/shared/community-member.tcl?user_id=$user_id"

ns_registerproc GET /~* tilde_to_user_filter
This is easy to do with AOLserver, but not so much with OpenACS. Reason why is because there is some functional overlap between screen_name, email, and first_names + last_name; at least in terms of which is the valid name to use as ~user. Also, since usernames can have spaces & other unix- and url-forbidden characters, a user typing "" will have to type URL encodings, like "todd g" as "". Not very pleasing unto the eye and tongue.
Posted by Rafael Calvo on
Thanks Todd,

Anyway I think I wasn't clear. The "user" I am talking about is the login name in the server machine. It is not a openacs user and is not in any DB. I should probably check at how Apache does it, from the admin perspective is just turning on some parameter in the config file.

Posted by David Walker on
You can mess with the procedure some. This procedure works if /home/user/public_html is a symlink to /var/public_html/user

if your permissions allow it you could change /var/public_html/${user_name}/ to /home/${user_name}/public_html/

I haven't tested this so it might not work right off.
proc tilde_to_user_filter {} {
    set urlv [ns_conn urlv]

    set tilde_user_name [lindex $urlv 0]
    set user_name [string range $tilde_user_name 1 end]
    set filename /var/public_html/${user_name}/[join [lrange $urlv 1 
end] /]
    # remove any characters or strings you find undesirable
    set filename [string map { " " "_"  ";" "" "|" "" } $filename]
    ns_returnfile 200 [ns_guesstype $filename] $filename

ns_registerproc GET /~* tilde_to_user_filter
Posted by Cynthia Kiser on
AOLServer 2.3.3 used to do just what Rafael wanted. Sometimes there is still support for old features even if they are not mentioned in the docs for the 3.x versions. Try:
Or a suitable equivalent if you are using .tcl style initialization files. It may not work but the worst it should do is ignore you if the feature is not supported any more.
Posted by Rafael Calvo on
thanks to both, I will try it this weekend


Posted by Rafael Calvo on
I tried Cynthia's idea but didn't work. I looked in the aolserver documentation but couln't find any thing. What I did was:

ns_section "ns/server/${servername}"
ns_param  UserMapDir      public_html

I also tried
ns_param  UserMapDir      ~/public_html

In both cases I get a page not found.

When loading with openacs I get a security error. I guest the request procesor would be checking if I have permission to go to that dir, so I would have to explicit that all ~public_html should be public.

This is a petty. It would be a nice feature if we want to replace Apache instalations.