various: add read-only mode support
[girocco.git] / cgi / reguser.cgi
blob98989a518408170a413ee5ce4c18b43bf2561d1f
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib "__BASEDIR__";
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 (my $romsg=check_readonly(1)) {
28 print "<p>$romsg</p>\n";
29 exit;
32 my $y0 = $cgi->param('y0') || '';
33 if ($cgi->param('name') && $y0 eq 'Register' && $cgi->request_method eq 'POST') {
34 # submitted, let's see
35 # FIXME: racy, do a lock
36 my $name = $gcgi->wparam('name');
37 if (!Girocco::User::valid_name($name)) {
38 my $htmlname = html_esc($name);
39 $gcgi->err(
40 "Invalid user name \"$htmlname\" ".
41 "(contains bad characters or is a reserved user name). ".
42 "See <a href=\"@{[url_path($Girocco::Config::htmlurl)]}/names.html#user\">names</a>.");
43 $gcgi->err_check;
44 } elsif (Girocco::User::does_exist($name)) {
45 $gcgi->err("A user with that name already exists.");
46 $gcgi->err_check;
47 } else {
48 my $user = Girocco::User->ghost($name);
49 if ($user->cgi_fill($gcgi)) {
50 $user->conjure;
51 my $keysdiv = '';
52 my $keylist = $user->keys_html_list;
53 if ($keylist) {
54 $keysdiv = <<EOT;
56 <div id="keys"><p>The following keys have been registered for user $name as
57 shown below along with their <tt>ssh-keygen -l -E md5</tt> fingerprint:</p>
58 $keylist</div>
59 EOT
61 print <<EOT;
62 <p>User $name successfully registered.</p>
63 <p>Project administrators can now give you push access to their projects.</p>
64 <p>Congratulations, and have a lot of fun!</p>$keysdiv
65 EOT
66 exit;
71 my $httpspara = '';
72 $httpspara = <<EOT if $Girocco::Config::httpspushurl;
73 <p>Please be sure to include at least one RSA key (starts with the <tt>ssh-rsa</tt> prefix) in
74 order to enable HTTPS pushing. <sup class="sup"><span><a href="@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html">(learn more)</a></span></sup><br />
75 X.509 (e.g. OpenSSL) format public keys can be converted to SSH .pub format with the
76 <a href="http://repo.or.cz/w/ezcert.git/blob/master:/ConvertPubKey">ConvertPubKey</a> utility thus obviating the
77 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>
78 EOT
79 my $dsablurb = '';
80 $dsablurb = ' or <tt>~/.ssh/id_dsa.pub</tt>' unless $Girocco::Config::disable_dsa;
81 print <<EOT;
82 <p>Here you can register a user.
83 You need to register a user so that you can push to the hosted projects.</p>
84 <p>If you already have a user account you may
85 <a href="@{[url_path($Girocco::Config::webadmurl)]}/edituser.cgi">edit user</a> instead.</p>
86 <p>SSH (the <tt>ssh</tt> protocol) or HTTPS is used for pushing, your SSH key authenticates you -
87 there is no password (though we recommend that your SSH key is password-protected;
88 use <code>ssh-agent</code> to help your fingers).
89 You can find your public key in <tt>~/.ssh/id_rsa.pub</tt>$dsablurb.
90 If you do not have any yet, generate it using the <code>ssh-keygen</code> command.
91 You can paste multiple keys in the box below, each on a separate line.
92 Paste each key <em>including</em> the <tt>ssh-</tt>whatever prefix and email-like postfix.</p>
93 $httpspara<p>We won't bother to verify your email contact,
94 but fill in something sensible in your own interest
95 so that we may contact you or confirm your identity should the need arise.
96 We also need to send you an e-mail if you want to update your SSH keys later.</p>
97 $Girocco::Config::legalese
98 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/reguser.cgi">
99 <table class="form">
100 <tr><td class="formlabel">Login:</td><td><input type="text" name="name" /></td></tr>
101 <tr><td class="formlabel">Email:</td><td><input type="text" name="email" /></td></tr>
102 <tr><td class="formlabel">Public SSH key(s):</td><td><textarea wrap="off" name="keys" rows="5" cols="80"></textarea></td></tr>
103 <tr style="display:none"><td class="formlabel">Anti-captcha (leave empty!):</td><td><input type="text" name="mail" /></td></tr>
104 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="Register" /></td></tr>
105 </table>
106 </form>