cgi/*proj.cgi: Rearrange the retype-password inputs horizontally
[girocco/mytab.git] / cgi / regproj.cgi
bloba249fa936a63e43e359030abd0a7b79c69944dd0
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::Project;
12 use Girocco::Util;
14 my $gcgi = Girocco::CGI->new('Project Registration');
15 my $cgi = $gcgi->cgi;
17 my $name = $cgi->param('name');
18 $name ||= '';
20 my $fork = $cgi->param('fork');
21 if ($fork) {
22 $fork =~ s/\.git$//;
23 $name = "$fork/";
26 if ($cgi->param('mail')) {
27 print "<p>Go away, bot.</p>";
28 exit;
31 if ($cgi->param('mode')) {
32 # submitted, let's see
33 # FIXME: racy, do a lock
34 my $name = $gcgi->wparam('name');
35 Girocco::Project::valid_name($name)
36 and Girocco::Project::does_exist($name)
37 and $gcgi->err("Project with the name '$name' already exists.");
38 $name =~ /\.git$/
39 and $gcgi->err("Project name should not end with <tt>.git</tt> - I'll add that automagically.");
41 my $mirror = $cgi->param('mode') eq 'mirror';
42 my $proj = Girocco::Project->ghost($name, $mirror);
43 if ($proj->cgi_fill($gcgi)) {
44 if ($mirror) {
45 unless ($Girocco::Config::mirror) {
46 $gcgi->err("Mirroring mode is not enabled at this site.");
47 exit;
49 $proj->premirror;
50 print "<p>Initiated mirroring. You will be notified about the result by mail.</p>\n";
51 } else {
52 unless ($Girocco::Config::push) {
53 $gcgi->err("Push mode is not enabled at this site.");
54 exit;
56 $proj->conjure;
57 print <<EOT;
58 <p>
59 Project <a href="/w/$name.git">$name</a> successfuly set up.</p>
60 EOT
61 print "<p>The push URL for the project is <tt>$Girocco::Config::pushurl/$name.git</tt>.</p>";
62 print "<p>The read-only URL for the project is <tt>" .
63 join("/$name.git</tt>, <tt>", $Girocco::Config::gitpullurl, $Girocco::Config::httppullurl) .
64 "/$name.git</tt>.</p>" if $Girocco::Config::gitpullurl or $Girocco::Config::httppullurl;
65 my $regnotice = '';
66 if ($Girocco::Config::manage_users) {
67 $regnotice = <<EOT;
68 Everyone who wants to push must <a href="reguser.cgi">register himself as a user</a> first.
69 (One user can have push access to multiple projects and multiple users can have push access to one project.)
70 EOT
72 print <<EOT;
73 <p>You can <a href="editproj.cgi?name=$name">assign users</a> now (use project name (without <tt>.git</tt>) as username, admin password as password)
74 - don't forget to assign yourself as a user as well if you want to push!
75 $regnotice
76 </p>
77 <p>Note that you cannot clone an empty repository since it contains no branches; you need to make the first push from an existing repository.</p>
78 <p>You may experience permission problems if you try to push right now.
79 If so, that should get fixed automagically in few minutes, please be patient.</p>
80 <p>Enjoy yourself, and have a lot of fun!</p>
81 EOT
83 exit;
87 my $mirror_mode = {
88 name => 'mirror',
89 desc => 'our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates',
90 pwpurp => 'mirroring URL'
92 my $push_mode = {
93 name => 'push',
94 desc => 'registered users with appropriate permissions will be able to push to the repository',
95 pwpurp => 'list of users allowed to push'
98 my $me = $Girocco::Config::mirror ? $mirror_mode : undef;
99 my $pe = $Girocco::Config::push ? $push_mode : undef;
100 if ($me and $pe) {
101 print <<EOT;
102 <p>At this site, you can host a project in one of two modes: $me->{name} mode and $pe->{name} mode.
103 In the <b>$me->{name} mode</b>, $me->{desc}.
104 In the <b>$pe->{name} mode</b>, $pe->{desc}.
105 You currently cannot switch freely between those two modes;
106 if you want to switch from mirroring to push mode, just delete and recreate
107 the project. If you want to switch the other way, please contact the administrator.</p>
109 } else {
110 my $mode = $me ? $me : $pe;
111 print "<p>This site will host your project in a <b>$mode->{name} mode</b>: $mode->{desc}.</p>\n";
114 my @pwpurp = ();
115 push @pwpurp, $me->{pwpurp} if $me;
116 push @pwpurp, $pe->{pwpurp} if $pe;
117 my $pwpurp = join(', ', @pwpurp);
119 print <<EOT;
120 <p>You will need the admin password to adjust the project settings later
121 ($pwpurp, project description, ...).
122 Use the project name (without <tt>.git</tt>) as the username when asked by the browser.</p>
125 unless ($name =~ m#/#) {
126 print <<EOT;
127 <p>Note that if your project is a <strong>fork of an existing project</strong>
128 (this does not mean anything socially bad), please instead go to the project's
129 gitweb page and click the 'fork' link in the top bar. This way, all of us
130 will save bandwidth and more importantly, your project will be properly categorized.
132 $me and print <<EOT;
133 If your project is a fork but the existing project is not registered here yet, please
134 consider registering it first; you do not have to be involved in the project
135 in order to register it here as a mirror.</p>
137 } else {
138 my $xname = $name; $xname =~ s#/$#.git#; #
139 my ($pushnote1, $pushnote2);
140 $pushnote1 = " and you will need to push only the data <em>you</em> created, not the whole project" if $pe;
141 $pushnote2 = "(That will be done automagically, you do not need to specify any extra arguments during the push.)" if $pe;
142 print <<EOT;
143 <p>Great, your project will be created as a subproject of the '$xname' project.
144 This means that it will be properly categorized$pushnote1. $pushnote2</p>
148 my $modechooser;
149 my $mirrorentry = 'Repository URL: <input type="text" name="url" />';
150 if ($me and $pe) {
151 $modechooser = <<EOT;
152 <p>Hosting mode:</p><ul>
153 <li><input type="radio" name="mode" value="mirror" />Mirror mode. $mirrorentry</li>
154 <li><input type="radio" name="mode" value="push" />Push mode.</li></ul>
156 } else {
157 $modechooser = '<input type="hidden" name="mode" value="'.($me ? $me->{name} : $pe->{name}).'">';
158 $me and $modechooser .= "<p>$mirrorentry</p>";
161 print <<EOT;
162 $Girocco::Config::legalese
163 <form method="post">
164 <p>Project name (w/o the .git suffix): <input type="text" name="name" value="$name" /></p>
165 <p>Admin password (twice): <input type="password" name="pwd" /> <input type="password" name="pwd2" /></p>
166 <p>E-mail contact: <input type="text" name="email" /></p>
167 $modechooser
168 <p>Description: <input type="text" name="desc" /></p>
169 <p>Homepage URL: <input type="text" name="hp" /></p>
170 <p>README (HTML, lt 8kb): <textarea name="README" rows="5" cols="80"></textarea></p>
171 <p style="display:none">Anti-captcha (leave empty!): <input type="text" name="mail" /></p>
172 <p><input type="submit" name="y0" value="Register" /></p>
173 </form>