2 # (c) Petr Baudis <pasky@suse.cz>
3 # (c) Jan Krueger <jk@jk.gs>
15 my $gcgi = Girocco
::CGI
->new('User Email & SSH Key Update');
18 unless ($Girocco::Config
::manage_users
) {
19 print "<p>I don't manage users.</p>";
23 if ($cgi->param('mail')) {
24 print "<p>Go away, bot.</p>";
32 $fields = '' if (!$fields);
34 my $authtag = ($auth ?
qq(<input type
="hidden" name
="auth" value
="$auth" />) :
35 qq(<p
>Authorization code
: <input name
="auth" size
="50" /></p>));
38 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/edituser.cgi">
39 <input type="hidden" name="name" value="$name" />
41 $fields<p><input type="submit" name="y0" value="$submit" /></p>
47 my $y0 = $cgi->param('y0') || '';
48 if ($cgi->param('name') && $y0 && $cgi->request_method eq 'POST') {
49 # submitted, let's see
50 # FIXME: racy, do a lock
51 my $name = $gcgi->wparam('name');
52 (Girocco
::User
::valid_name
($name)
53 and Girocco
::User
::does_exist
($name))
54 or $gcgi->err("Username is not registered.");
56 $gcgi->err_check and exit;
59 ($user = Girocco
::User
->load($name)) && valid_email
($user->{email
})
60 or $gcgi->err("Username may not be updated.");
62 $gcgi->err_check and exit;
64 if (!$cgi->param('auth')) {
65 if ($y0 ne 'Send authorization code') {
66 print "<p>Invalid data. Go away, sorcerer.</p>\n";
70 my $auth = $user->gen_auth;
73 open(MAIL
, '|-', '/usr/bin/mail', '-s', "[$Girocco::Config::name] Account update authorization", $user->{email
}) or
74 die "Sorry, could not send authorization code: $!";
78 you have requested an authorization code to be sent to you for updating
79 your account's email and/or SSH keys. If you don't want to actually update
80 your email or SSH keys, just ignore this e-mail. Otherwise, use this code
85 Should you run into any problems, please let us know.
91 print "<p>You should shortly receive an e-mail containing an authorization code.
92 Please enter this code below to update your SSH keys.
93 The code will expire in 24 hours or after you have used it.</p>";
94 _auth_form
($name, "'Login'");
97 $user->{auth
} && $user->{authtype
} ne 'DEL' or do {
98 print "<p>There currently isn't any authorization code filed under your account. ".
99 "Please <a href=\"@{[url_path($Girocco::Config::webadmurl)]}/edituser.cgi\">generate one</a>.</p>";
104 my $email = $cgi->param('email');
105 my $keys = $cgi->param('keys');
107 my $auth = $gcgi->wparam('auth');
108 if ($auth ne $user->{auth
}) {
109 print "<p>Invalid authorization code, please re-enter or ".
110 "<a href=\"@{[url_path($Girocco::Config::webadmurl)]}/edituser.cgi\">generate a new one</a>.</p>";
111 _auth_form
($name, "'Login'");
115 if (defined($email) && defined($keys)) {
116 if ($y0 ne 'Update') {
117 print "<p>Invalid data. Go away, sorcerer.</p>\n";
121 # Auth valid, keys given -> save
122 if (($email eq $user->{email
} || $user->update_email($gcgi, $email)) && $user->keys_fill($gcgi)) {
125 print "<p>Your Email & SSH keys have been updated.</p>";
126 my $keylist = $user->keys_html_list;
130 <div id="keys"><p>The following keys have been registered for user $name as
131 shown below along with their <tt>ssh-keygen -l</tt> fingerprint:</p>
140 # Otherwise pre-fill fields
141 $email = $user->{email
};
142 $keys = $user->{keys};
145 if ($y0 ne "'Login'") {
146 print "<p>Invalid data. Go away, sorcerer.</p>\n";
151 $httpspara = <<EOT if $Girocco::Config::httpspushurl;
152 <p>Please be sure to include at least one RSA key (starts with the <tt>ssh-rsa</tt> prefix) in
153 order to enable HTTPS pushing. <sup><a href="@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html">(learn more)</a></sup><br />
154 An X.509 (e.g. OpenSSL) format public key can be converted to SSH .pub format with the
155 <a href="http://repo.or.cz/w/ezcert.git/blob/master:/ConvertPubKey">ConvertPubKey</a> utility thus obviating the
156 need for OpenSSH if all pushing is to be done using HTTPS (see the example in the TIPS section of the <tt>ConvertPubKey -h</tt> output).</p>
158 my $emailval = CGI
::escapeHTML
($email);
159 my $keysval = CGI
::escapeHTML
($keys);
161 $blurb = 'SSH (the <tt>ssh</tt> protocol)'
162 if $Girocco::Config
::pushurl
&& !$Girocco::Config
::httpspushurl
;
163 $blurb = 'HTTPS (the <tt>https</tt> protocol)'
164 if !$Girocco::Config
::pushurl
&& $Girocco::Config
::httpspushurl
;
165 $blurb = 'SSH (the <tt>ssh</tt> protocol) or HTTPS (the <tt>https</tt> protocol)'
166 if $Girocco::Config
::pushurl
&& $Girocco::Config
::httpspushurl
;
168 $dsablurb = ' or <tt>~/.ssh/id_dsa.pub</tt>' unless $Girocco::Config
::disable_dsa
;
170 <p>Authorization code validated (for now).</p>
171 <p>$blurb is used for pushing, your SSH key authenticates you -
172 there is no password (though we recommend that your SSH key is password-protected;
173 use <code>ssh-agent</code> to help your fingers).
174 You can find your public key in <tt>~/.ssh/id_rsa.pub</tt>$dsablurb.
175 If you do not have any yet, generate it using the <code>ssh-keygen</code> command.</p>
176 <p>You can paste multiple keys in the box below, each on a separate line.
177 Paste each key <em>including</em> the <tt>ssh-</tt>whatever prefix and email-like postfix.</p>
178 $httpspara<form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/edituser.cgi">
179 <input type="hidden" name="name" value="$name" />
180 <input type="hidden" name="auth" value="$auth" />
182 <tr><td class="formlabel">Login:</td><td class="formdata">$name</td></tr>
183 <tr><td class="formlabel">Email:</td><td><input type="text" name="email" value="$emailval"/></td></tr>
184 <tr><td class="formlabel">Public SSH key(s):</td><td><textarea wrap="off" name="keys" rows="5" cols="80">$keysval</textarea></td></tr>
185 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="Update" /></td></tr>
188 my $keylist = $savefail ?
'' : $user->keys_html_list;
192 <div id="keys"><p>The following keys are currently registered for user $name as
193 shown below along with their <tt>ssh-keygen -l</tt> fingerprint:</p>
203 $blurb1 = 'SSH (the <tt>ssh</tt> protocol)'
204 if $Girocco::Config
::pushurl
&& !$Girocco::Config
::httpspushurl
;
205 $blurb1 = 'HTTPS (the <tt>https</tt> protocol)'
206 if !$Girocco::Config
::pushurl
&& $Girocco::Config
::httpspushurl
;
207 $blurb1 = 'SSH (the <tt>ssh</tt> protocol) or HTTPS (the <tt>https</tt> protocol)'
208 if $Girocco::Config
::pushurl
&& $Girocco::Config
::httpspushurl
;
210 $blurb2 = ' and download https push user authentication certificate(s)'
211 if $Girocco::Config
::httpspushurl
;
213 $dsablurb = ' or <tt>~/.ssh/id_dsa.pub</tt>' unless $Girocco::Config
::disable_dsa
;
215 <p>Here you may update the email and public SSH key(s) associated with your user account$blurb2.
216 You may <a href="@{[url_path($Girocco::Config::webadmurl)]}/deluser.cgi">request an authorization
217 code in order to remove your user account from this site</a>.</p>
218 <p>The public SSH key(s) are required for you to push to projects.
219 $blurb1 is used for pushing, your SSH key authenticates you -
220 there is no password (though we recommend that your SSH key is password-protected;
221 use <code>ssh-agent</code> to help your fingers).
222 You can find your public key in <tt>~/.ssh/id_rsa.pub</tt>$dsablurb.
223 If you do not have any yet, generate it using the <code>ssh-keygen</code> command.</p>
225 <p>Please enter your username below;
226 we will send you an email with an authorization code
227 and further instructions.</p>
229 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/edituser.cgi">
231 <tr><td class="formlabel">Login:</td><td><input type="text" name="name" /></td></tr>
232 <tr style="display:none"><td class="formlabel">Anti-captcha (leave empty!):</td><td><input type="text" name="mail" /></td></tr>
233 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="Send authorization code" /></td></tr>