Implement friendly Git commit names via Personal SSL certs.
authorEdward Z. Yang <edwardzyang@thewritingpot.com>
Sun, 11 Jan 2009 06:25:54 +0000 (01:25 -0500)
committerEdward Z. Yang <edwardzyang@thewritingpot.com>
Mon, 12 Jan 2009 04:24:24 +0000 (23:24 -0500)
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
IkiWiki/CGI.pm
IkiWiki/Plugin/git.pm
IkiWiki/Plugin/httpauth.pm
IkiWiki/UserInfo.pm
IkiWiki/Wrapper.pm
po/ikiwiki.pot

index 9a5f00b13b36a61a1f3a0ea7bd1ac796bf150559..c6ae831846e52e23f1c3ba2ae76fa2f221a51bed 100644 (file)
@@ -203,13 +203,16 @@ sub cgi_prefs ($$) {
                force => 1);
        $form->field(name => "sid", type => "hidden", value => $session->id,
                force => 1);
-       $form->field(name => "email", size => 50, fieldset => "preferences");
+            #$form->field(name => "email", size => 50, fieldset => "preferences");
+       $form->field(name => "realname", size => 50, fieldset => "preferences");
        
        my $user_name=$session->param("name");
 
        if (! $form->submitted) {
-               $form->field(name => "email", force => 1,
-                       value => userinfo_get($user_name, "email"));
+            #$form->field(name => "email", force => 1,
+            #value => userinfo_get($user_name, "email"));
+               $form->field(name => "realname", force => 1,
+                       value => userinfo_get($user_name, "realname"));
        }
        
        if ($form->submitted eq 'Logout') {
@@ -226,7 +229,10 @@ sub cgi_prefs ($$) {
                        userinfo_set($user_name, 'email', $form->field('email')) ||
                                error("failed to set email");
                }
-
+               if (defined $form->field('realname')) {
+                       userinfo_set($user_name, 'realname', $form->field('realname')) ||
+                               error("failed to set realname");
+                }
                $form->text(gettext("Preferences saved."));
        }
        
index 23e8d9c29c69604dbef0e75356e6733b68579de8..b88e787bac34a8ff3d89ca66e91a0b8133ff0dc6 100644 (file)
@@ -4,6 +4,7 @@ package IkiWiki::Plugin::git;
 use warnings;
 use strict;
 use IkiWiki;
+use IkiWiki::UserInfo;
 use Encode;
 use open qw{:utf8 :std};
 
@@ -442,7 +443,8 @@ sub rcs_commit_staged ($$$) {
        my %env=%ENV;
        if (defined $user || defined $ipaddr) {
                my $u=defined $user ? $user : $ipaddr;
-               $ENV{GIT_AUTHOR_NAME}=$u;
+               # MITLOGIN This algorithm could be improved
+               $ENV{GIT_AUTHOR_NAME}=IkiWiki::userinfo_get($u, "realname");
                $ENV{GIT_AUTHOR_EMAIL}="$u\@mit.edu";
        }
 
index 1816c9d74c27aaee1e2b6114e62dd06b8fca1d4c..c2e55b015bba003701522130b0ca6dfd376154cf 100644 (file)
@@ -5,6 +5,7 @@ package IkiWiki::Plugin::httpauth;
 use warnings;
 use strict;
 use IkiWiki 3.00;
+use Data::Dumper;
 
 sub import {
        hook(type => "getsetup", id => "httpauth", call => \&getsetup);
@@ -24,7 +25,14 @@ sub auth ($$) {
        my $session=shift;
 
        if (defined $cgi->remote_user()) {
-               $session->param("name", $cgi->remote_user());
+               my $user = $cgi->remote_user();
+               $session->param("name", $user);
+               eval IkiWiki::possibly_foolish_untaint($ENV{SSL_CLIENT_S_DN_CN});
+               my $realname = IkiWiki::userinfo_get($user, "realname");
+               if ((!defined $realname || $realname eq "") &&
+                   defined $ENV{SSL_CLIENT_S_DN_CN}) {
+               IkiWiki::userinfo_set($user, "realname", $ENV{SSL_CLIENT_S_DN_CN});
+               }
        }
 }
 
index 0bf100a959c934d23c8f73ac1f0962f856732a35..31f20c51736ad930908676c0e694ddacfceb3cac 100644 (file)
@@ -36,8 +36,17 @@ sub userinfo_get ($$) {
        if (! defined $userinfo ||
            ! exists $userinfo->{$user} || ! ref $userinfo->{$user} ||
             ! exists $userinfo->{$user}->{$field}) {
+               if ($field eq "realname" && defined $ENV{SSL_CLIENT_S_DN_CN}) {
+                       userinfo_set($user, "realname", $ENV{SSL_CLIENT_S_DN_CN});
+                       return $ENV{SSL_CLIENT_S_DN_CN};
+               }
                return "";
        }
+       if ($field eq "realname" && $userinfo->{$user}->{$field} eq "" &&
+           defined $ENV{SSL_CLIENT_S_DN_CN}) {
+               userinfo_set($user, "realname", $ENV{SSL_CLIENT_S_DN_CN});
+               return $ENV{SSL_CLIENT_S_DN_CN};
+       }
        return $userinfo->{$user}->{$field};
 }
 
index d74f83b1c3d893a7fe0ebb49453a016237fc2104..fe29b0fc42e68936e592f85a178d8e44ec280a01 100644 (file)
@@ -28,7 +28,7 @@ sub gen_wrapper () {
        my @envsave;
        push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
                       CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE
-                      HTTP_COOKIE REMOTE_USER HTTPS} if $config{cgi};
+                      HTTP_COOKIE REMOTE_USER HTTPS SSL_CLIENT_S_DN_CN} if $config{cgi};
        my $envsave="";
        foreach my $var (@envsave) {
                $envsave.=<<"EOF";
index 8e1fb0515537cf23a350a6424428b1a3229e2064..310c624455b4672743b09739baa48a9d1d13d922 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-01-10 23:23-0500\n"
+"POT-Creation-Date: 2009-01-11 01:24-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -20,7 +20,7 @@ msgstr ""
 msgid "login failed, perhaps you need to turn on cookies?"
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:167 ../IkiWiki/CGI.pm:285
+#: ../IkiWiki/CGI.pm:167 ../IkiWiki/CGI.pm:290
 msgid "Your login session has expired."
 msgstr ""
 
@@ -36,15 +36,15 @@ msgstr ""
 msgid "Admin"
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:231
+#: ../IkiWiki/CGI.pm:236
 msgid "Preferences saved."
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:246
+#: ../IkiWiki/CGI.pm:251
 msgid "You are banned."
 msgstr ""
 
-#: ../IkiWiki/CGI.pm:376 ../IkiWiki/CGI.pm:377 ../IkiWiki.pm:1204
+#: ../IkiWiki/CGI.pm:381 ../IkiWiki/CGI.pm:382 ../IkiWiki.pm:1204
 msgid "Error"
 msgstr ""
 
@@ -300,18 +300,18 @@ msgstr ""
 msgid "fortune failed"
 msgstr ""
 
-#: ../IkiWiki/Plugin/git.pm:618 ../IkiWiki/Plugin/git.pm:636
+#: ../IkiWiki/Plugin/git.pm:620 ../IkiWiki/Plugin/git.pm:638
 #: ../IkiWiki/Receive.pm:129
 #, perl-format
 msgid "you are not allowed to change %s"
 msgstr ""
 
-#: ../IkiWiki/Plugin/git.pm:658
+#: ../IkiWiki/Plugin/git.pm:660
 #, perl-format
 msgid "you cannot act on a file with mode %s"
 msgstr ""
 
-#: ../IkiWiki/Plugin/git.pm:662
+#: ../IkiWiki/Plugin/git.pm:664
 msgid "you are not allowed to change file modes"
 msgstr ""