{"thread":{"id":"6530","subject":"[PATCH] gitweb: Allow users to have their own project directories.","startedAt":"2007-01-25T20:10:11Z","lastAt":"2007-01-26T13:44:51Z","messageCount":2,"participants":["Mark Wooding","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"32637","messageId":"11697558112701-git-send-email-mdw@distorted.org.uk","threadId":"6530","inReplyTo":null,"subject":"[PATCH] gitweb: Allow users to have their own project directories.","fromName":"Mark Wooding","fromEmail":"mdw@distorted.org.uk","sentAt":"2007-01-25T20:10:11Z","receivedAt":"2007-01-25T20:10:11Z","isPatch":true,"sender":{"key":"mdw@distorted.org.uk","avatar":null},"body":"The git-daemon understands `~USER/...' as referring to a project within\nUSER's home directory.  This change makes gitweb able to serve each\nuser's personal projects without them all having to be linked into one\nplace.\n\nIf the gitweb_config.perl file defines $user_path then a username given\nin the `u' argument, or as a leading `/~USER/' string in the PATH_INFO,\ncauses gitweb to look for projects in $homedir/$user_path (where\n$homedir is USER's home directory).\n\nRather than expose all their projects, or the ones with an export file\nin them, a user can write a file listing the projects to be exported by\ngitweb.  (Maybe this ought to force strict_export on, but it doesn't at\nthe moment.)\n\nThis patch leaves it as someone else's problem to actually work out\nwhich users have exported GIT repositories, and maybe compile them into\na list.\n\nSigned-off-by: Mark Wooding <mdw@distorted.org.uk>\n---\n gitweb/gitweb.perl |   56 +++++++++++++++++++++++++++++++++++++++++++++++++--\n 1 files changed, 53 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 88af2e6..14c344d 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -35,6 +35,12 @@ our $GIT = \"++GIT_BINDIR++/git\";\n #our $projectroot = \"/pub/scm\";\n our $projectroot = \"++GITWEB_PROJECTROOT++\";\n \n+# subdirectory of user home to look for projects, or empty to not do that\n+our $user_path = \"\";\n+\n+# file naming user's projects\n+our $user_projects = \"projects\";\n+\n # target of the home link on top of all pages\n our $home_link = $my_uri || \"/\";\n \n@@ -285,6 +291,8 @@ $projects_list ||= $projectroot;\n \n # ======================================================================\n # input validation and dispatch\n+our $path_info = $ENV{\"PATH_INFO\"};\n+\n our $action = $cgi->param('a');\n if (defined $action) {\n \tif ($action =~ m/[^0-9a-zA-Z\\.\\-_]/) {\n@@ -292,6 +300,37 @@ if (defined $action) {\n \t}\n }\n \n+our $user = $cgi->param('u');\n+if (!defined($user && $path_info)) {\n+\t$path_info =~ s:^/+::;\n+\tif ($path_info =~ m:\\~([^/]+)(/.*$|):) {\n+\t\t$user = $1;\n+\t\t$path_info = $2;\n+\t}\n+}\n+if (defined $user) {\n+\tif (!$user_path || $user =~ m/[^0-9a-zA-Z\\.\\-_]/) {\n+\t\tdie_error(undef, \"Invalid user parameter\");\n+\t}\n+\tmy @pw = getpwnam($user);\n+\tmy $ok = 0;\n+\tif (@pw) {\n+\t\t$projectroot = $pw[7] . \"/\" . $user_path;\n+\t\tif (-d $projectroot) {\n+\t\t\t$ok = 1;\n+\t\t}\n+\t\tif ($user_projects && -f \"$projectroot/$user_projects\") {\n+\t\t\t$projects_list = \"$projectroot/$user_projects\";\n+\t\t} else {\n+\t\t\t$projects_list = $projectroot;\n+\t\t}\n+\t\t$home_text = \"$projectroot/$home_text\";\n+\t}\n+\tif (!$ok) {\n+\t\tdie_error(\"No such user as $user\");\n+\t}\n+}\n+\n # parameters which are pathnames\n our $project = $cgi->param('p');\n if (defined $project) {\n@@ -377,7 +416,7 @@ if (defined $searchtype) {\n # now read PATH_INFO and use it as alternative to parameters\n sub evaluate_path_info {\n \treturn if defined $project;\n-\tmy $path_info = $ENV{\"PATH_INFO\"};\n+\tmy $path_info = $::path_info;\n \treturn if !$path_info;\n \t$path_info =~ s,^/+,,;\n \treturn if !$path_info;\n@@ -482,6 +521,7 @@ sub href(%) {\n \n \tmy @mapping = (\n \t\tproject => \"p\",\n+\t\tuser => \"u\",\n \t\taction => \"a\",\n \t\tfile_name => \"f\",\n \t\tfile_parent => \"fp\",\n@@ -497,12 +537,15 @@ sub href(%) {\n \tmy %mapping = @mapping;\n \n \t$params{'project'} = $project unless exists $params{'project'};\n+\t$params{'user'} = $user unless exists $params{'user'};\n \n \tmy ($use_pathinfo) = gitweb_check_feature('pathinfo');\n \tif ($use_pathinfo) {\n \t\t# use PATH_INFO for project name\n+\t\t$href .= \"/~$user\" if defined $params{'user'};\n \t\t$href .= \"/$params{'project'}\" if defined $params{'project'};\n \t\tdelete $params{'project'};\n+\t\tdelete $params{'user'};\n \n \t\t# Summary just uses the project path URL\n \t\tif (defined $params{'action'} && $params{'action'} eq 'summary') {\n@@ -1771,6 +1814,9 @@ EOF\n \t               -title => $logo_label},\n \t              qq(<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" class=\"logo\"/>));\n \tprint $cgi->a({-href => esc_url($home_link)}, $home_link_str) . \" / \";\n+\tif (defined $user) {\n+\t\tprint $cgi->a({-href => href(action=>\"summary\", project=>undef)}, esc_html(\"~\" . $user)) . \" / \";\n+\t}\n \tif (defined $project) {\n \t\tprint $cgi->a({-href => href(action=>\"summary\")}, esc_html($project));\n \t\tif (defined $action) {\n@@ -1794,9 +1840,11 @@ EOF\n \t\t$cgi->param(\"a\", \"search\");\n \t\t$cgi->param(\"h\", $search_hash);\n \t\t$cgi->param(\"p\", $project);\n+\t\tif (defined $user) { $cgi->param(\"u\", $user); }\n \t\tprint $cgi->startform(-method => \"get\", -action => $my_uri) .\n \t\t      \"<div class=\\\"search\\\">\\n\" .\n \t\t      $cgi->hidden(-name => \"p\") . \"\\n\" .\n+\t\t      (defined $user ? $cgi->hidden(-name => \"u\") . \"\\n\" : \"\") .\n \t\t      $cgi->hidden(-name => \"a\") . \"\\n\" .\n \t\t      $cgi->hidden(-name => \"h\") . \"\\n\" .\n \t\t      $cgi->popup_menu(-name => 'st', -default => 'commit',\n@@ -4715,8 +4763,10 @@ XML\n \t\t}\n \n \t\tmy $path = esc_html(chop_str($proj{'path'}, 25, 5));\n-\t\tmy $rss  = \"$my_url?p=$proj{'path'};a=rss\";\n-\t\tmy $html = \"$my_url?p=$proj{'path'};a=summary\";\n+\t\tmy $base  = \"$my_url?p=$proj{'path'}\";\n+\t\tif (defined $user) { $base .= \";u=$user\"; }\n+\t\tmy $rss  = \"$base;a=rss\";\n+\t\tmy $html = \"$base;a=summary\";\n \t\tprint \"<outline type=\\\"rss\\\" text=\\\"$path\\\" title=\\\"$path\\\" xmlUrl=\\\"$rss\\\" htmlUrl=\\\"$html\\\"/>\\n\";\n \t}\n \tprint <<XML;\n-- \n1.5.0.rc2.gc9a89\n"},{"id":"32735","messageId":"epd0id$a7e$1@sea.gmane.org","threadId":"6530","inReplyTo":"11697558112701-git-send-email-mdw@distorted.org.uk","subject":"Re: [PATCH] gitweb: Allow users to have their own project directories.","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-01-26T13:44:51Z","receivedAt":"2007-01-26T13:44:51Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Mark Wooding wrote:\n\n> The git-daemon understands `~USER/...' as referring to a project within\n> USER's home directory.  This change makes gitweb able to serve each\n> user's personal projects without them all having to be linked into one\n> place.\n> \n> If the gitweb_config.perl file defines $user_path then a username given\n> in the `u' argument, or as a leading `/~USER/' string in the PATH_INFO,\n> causes gitweb to look for projects in $homedir/$user_path (where\n> $homedir is USER's home directory).\n> \n> Rather than expose all their projects, or the ones with an export file\n> in them, a user can write a file listing the projects to be exported by\n> gitweb.  (Maybe this ought to force strict_export on, but it doesn't at\n> the moment.)\n> \n> This patch leaves it as someone else's problem to actually work out\n> which users have exported GIT repositories, and maybe compile them into\n> a list.\n\nNice idea. Thanks.\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"}]}