HTML-escape the project description
[girocco.git] / cgi / reguser.cgi
blob3da2706a337302e4bb18e0bea4a065fb86462e76
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib qw(/home/repo/repomgr/cgi);
9 use Git::RepoCGI;
11 my $repo = Git::RepoCGI->new('User Registration');
12 my $cgi = $repo->cgi;
14 sub add_user {
15 my ($name, $email) = @_;
16 my $uid = 65536;
17 # racy!
18 open F, "/home/repo/j/etc/passwd" or die "passwd failed: $!";
19 while (<F>) {
20 my $auid = (split /:/)[2];
21 $uid = $auid + 1 if ($auid >= $uid);
23 close F;
24 open F, ">>/home/repo/j/etc/passwd" or die "passwd append failed: $!";
25 print F "$name:x:$uid:65534:$email:/:/bin/git-shell\n";
26 close F;
27 $uid;
30 sub setup_user {
31 my ($name, $email, $keys) = @_;
32 add_user($name, $email);
33 open F, ">/home/repo/j/etc/sshkeys/$name" or die "sshkey failed: $!";
34 print F "$keys\n";
35 close F;
36 chmod 0664, "/home/repo/j/etc/sshkeys/$name";
37 print <<EOT;
38 <p>
39 User successfuly registered.
40 You (or whoever knows the project password) can <a href="p/editproj.pl">assign it</a> to a project now
41 (use project name as username, admin password as password).
42 (One user can have push access to multiple projects and multiple users can have push access to one project.)
43 </p>
44 <p>Congratulations!</p>
45 EOT
48 if ($cgi->param('name')) {
49 # submitted, let's see
50 # FIXME: racy, do a lock
51 my $err = 0;
52 sub err { print "<p style=\"text-color: red\">@_</p>\n"; $err++; }
53 my $name = $cgi->param('name'); $name =~ s/^\s*(.*?)\s*$/$1/;
54 my $email = $cgi->param('email'); $email =~ s/^\s*(.*?)\s*$/$1/;
55 my $keys = $cgi->param('keys');
56 $name =~ /^[a-zA-Z0-9_+-]+$/
57 or err "Name contains invalid characters.";
58 (-e "/home/repo/j/etc/sshkeys/$name")
59 and err "User with that name already exists.";
60 $email =~ /^[a-zA-Z0-9+._-]+@[a-zA-Z0-9-.]+$/
61 or err "Your email sure looks weird...?";
62 length($keys) <= 4096
63 or err "The list of keys is more than 4kb. Do you really need that much?";
64 if ($err) {
65 print "<p>Registration aborted due to $err errors.</p>\n";
66 } else {
67 setup_user($name, $email, $keys);
68 exit;
72 print <<EOT;
73 <p>Here you can register a user. You need to register a user so that it can be granted push access to project(s). SSH is used for pushing (the git+ssh protocol) and what authenticates you is your SSH key - there is no password (though we recommend that your SSH key is password-protected). You can find your public key in ~/.ssh/id_rsa.pub or ~/.ssh/id_dsa.pub; if you do not have any yet, generate it using the ssh-keygen command. You can paste multiple keys in the box below, if you wish, each on a separate line. Changing the keys later is not implemented yet - if you need to do that, please contact the administrator.</p>
74 <p>We won't bother to verify your email contact, but fill in something sensible in your own interest so that we can contact you or confirm your identity shall the need arise.</p>
75 <p>By submitting this form, you are confirming that you will push only free software and no content that would violate any law of Czech Republic. Have fun!</p>
76 <form method="post">
77 <p>Login: <input type="text" name="name" /></p>
78 <p>Email: <input type="text" name="email" /></p>
79 <p>Public SSH key(s): <textarea name="keys" cols="80" rows="10"></textarea></p>
80 <p><input type="submit" name="y0" value="Register" /></p>
81 </form>
82 EOT