2 # (c) Petr Baudis <pasky@suse.cz>
3 # (c) Jan Krueger <jk@jk.gs>
15 my $gcgi = Girocco
::CGI
->new('User 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
="40" /></p>));
39 <input type="hidden" name="name" value="$name">
41 $fields<p><input type="submit" value="$submit" /></p>
45 if ($cgi->param('name')) {
46 # submitted, let's see
47 # FIXME: racy, do a lock
48 my $name = $gcgi->wparam('name');
49 !Girocco
::User
::valid_name
($name)
50 or !Girocco
::User
::does_exist
($name)
51 and $gcgi->err("Username is not registered.");
53 $gcgi->err_check and exit;
55 my $user = Girocco
::User
->load($name) or
56 die "Failed loading user but this can't really happen here";
58 if (!$cgi->param('auth')) {
59 my $auth = $user->gen_auth;
62 open(MAIL
, '|-', '/usr/bin/mail', '-s', "[$Girocco::Config::name] Account update authorization", $user->{email
}) or
63 die "Sorry, could not send authorization code: $!";
67 you have requested that an authorization code be sent to you for updating your
68 account's SSH keys. If you don't want to actually update your SSH keys, just
69 ignore this e-mail. Otherwise, use this code within 24 hours:
73 Should you run into any problems, please let us know.
79 print "<p>You should shortly receive an e-mail containing an authorization code. Please enter this code below to update your SSH keys.
80 The code will expire in 24 hours or after you have used it.</p>";
81 _auth_form
($name, "'Login'");
85 die("There currently isn't any authorization code filed under your account. Please <a href=\"edituser.cgi\">generate one</a>.");
88 my $keys = $cgi->param('keys') || '';
90 $fields = "<p>Public SSH key(s): <textarea name=\"keys\" cols=\"80\" rows=\"5\">$keys</textarea></p>\n";
93 my $auth = $gcgi->wparam('auth');
94 if ($auth ne $user->{auth
}) {
95 print '<p>Invalid authorization code, please re-enter or <a href="edituser.cgi">generate a new one</a>.</p>';
96 _auth_form
($name, "'Login'", $fields);
100 # Auth valid, keys given -> save
102 $user->keys_fill($gcgi);
105 print "<p>Your SSH keys have been updated.</p>";
109 # Otherwise pre-fill keys
110 $keys = $user->{keys};
111 $fields = "<p>Public SSH key(s): <textarea name=\"keys\" cols=\"80\" rows=\"5\">$keys</textarea></p>\n";
113 print "<p>Authorization code validated (for now).</p>
114 <p>You can paste multiple keys in the box below, each on a separate line.
115 Paste each key <em>including</em> the <tt>ssh-</tt>whatever prefix and email-like postfix.</p>\n";
116 _auth_form
($name, "Update keys", $fields, $auth);
123 <p>Here you can update the public SSH keys associated with your user account. These keys are required for you to push to projects.</p>
124 <p>SSH is used for pushing (the <tt>ssh</tt> protocol), your SSH key authenticates you -
125 there is no password (though we recommend that your SSH key is password-protected; use <code>ssh-agent</code> to help your fingers).
126 You can find your public key in <tt>~/.ssh/id_rsa.pub</tt> or <tt>~/.ssh/id_dsa.pub</tt>.
127 If you do not have any yet, generate it using the <code>ssh-keygen</code> command.</p>
129 <p>Please enter your username below so we can send you an authorization code to the e-mail address you gave us when you registered the account.</p>
132 <p>Login: <input type="text" name="name" /></p>
133 <p style="display:none">Anti-captcha (leave empty!): <input type="text" name="mail" /></p>
134 <p><input type="submit" value="Send authorization code" /></p>