Util.pm: new filedb_atomic_grep function
[girocco.git] / cgi / reguser.cgi
blob17fed9b2212329356bff82cbc267fecf1e37791c
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::User;
12 use Girocco::Util;
14 my $gcgi = Girocco::CGI->new('User Registration');
15 my $cgi = $gcgi->cgi;
17 unless ($Girocco::Config::manage_users) {
18 print "<p>I don't manage users.</p>";
19 exit;
22 if ($cgi->param('mail')) {
23 print "<p>Go away, bot.</p>";
24 exit;
27 if ($cgi->param('name')) {
28 # submitted, let's see
29 # FIXME: racy, do a lock
30 my $name = $gcgi->wparam('name');
31 Girocco::User::valid_name($name)
32 and Girocco::User::does_exist($name)
33 and $gcgi->err("User with that name already exists.");
35 my $user = Girocco::User->ghost($name);
36 if ($user->cgi_fill($gcgi)) {
37 $user->conjure;
38 my $keysdiv = '';
39 my $keylist = $user->keys_html_list;
40 if ($keylist) {
41 $keysdiv = <<EOT;
43 <div id="keys"><p>The following keys have been registered for user $name as
44 shown below along with their <tt>ssh-keygen -l</tt> fingerprint:</p>
45 $keylist</div>
46 EOT
48 print <<EOT;
49 <p>User $name successfully registered.</p>
50 <p>Project administrators can now give you push access to their projects.</p>
51 <p>Congratulations, and have a lot of fun!</p>$keysdiv
52 EOT
53 exit;
57 my $httpspara = '';
58 $httpspara = <<EOT if $Girocco::Config::httpspushurl;
59 <p>Please be sure to include at least one RSA key (starts with the <tt>ssh-rsa</tt> prefix) in
60 order to enable HTTPS pushing. <sup><a href="$Girocco::Config::htmlurl/httpspush.html">(learn more)</a></sup><br />
61 X.509 (e.g. OpenSSL) format public keys can be converted to SSH .pub format with the
62 <a href="http://repo.or.cz/w/ezcert.git/blob/master:/ConvertPubKey">ConvertPubKey</a> utility.</p>
63 EOT
64 print <<EOT;
65 <p>Here you can register a user.
66 You need to register a user so that you can push to the hosted projects.</p>
67 <p>SSH (the <tt>ssh</tt> protocol) or HTTPS is used for pushing, your SSH key authenticates you -
68 there is no password (though we recommend that your SSH key is password-protected;
69 use <code>ssh-agent</code> to help your fingers).
70 You can find your public key in <tt>~/.ssh/id_rsa.pub</tt> or <tt>~/.ssh/id_dsa.pub</tt>.
71 If you do not have any yet, generate it using the <code>ssh-keygen</code> command.
72 You can paste multiple keys in the box below, each on a separate line.
73 Paste each key <em>including</em> the <tt>ssh-</tt>whatever prefix and email-like postfix.</p>
74 $httpspara<p>We won't bother to verify your email contact,
75 but fill in something sensible in your own interest
76 so that we can contact you or confirm your identity should the need arise.
77 We also need to send you an e-mail if you want to update your SSH keys later.</p>
78 $Girocco::Config::legalese
79 <form method="post">
80 <table class="form">
81 <tr><td class="formlabel">Login:</td><td><input type="text" name="name" /></td></tr>
82 <tr><td class="formlabel">Email:</td><td><input type="text" name="email" /></td></tr>
83 <tr><td class="formlabel">Public SSH key(s):</td><td><textarea wrap="off" name="keys" rows="5" cols="80"></textarea></td></tr>
84 <tr style="display:none"><td class="formlabel">Anti-captcha (leave empty!):</td><td><input type="text" name="mail" /></td></tr>
85 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="Register" /></td></tr>
86 </table>
87 </form>
88 EOT