gc.sh: run git svn gc on svn repositories
[girocco.git] / cgi / regproj.cgi
blob50b64414089bb93966793dc0fc9d1d3fdfacf7f0
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 defined($name) or $name = '';
20 my $fork = $cgi->param('fork');
21 if (defined($fork)) {
22 $fork =~ s/\.git$//;
23 $name = "$fork/$name";
25 my $escname = $name;
26 $escname =~ s/[+]/%2B/g;
27 my $mirror_mode_set = 1;
28 if ($Girocco::Config::mirror && $Girocco::Config::push) {
29 $mirror_mode_set = 0 unless ($Girocco::Config::initial_regproj_mode||'') eq 'mirror';
31 my %values = (
32 desc => '',
33 email => '',
34 hp => '',
35 mirror => $mirror_mode_set,
36 notifymail => '',
37 notifyjson => '',
38 notifycia => '',
39 README => '',
40 source => 'Anywhere',
41 url => '',
42 Anywhere_url => '',
43 GitHub_i0 => '',
44 GitHub_i1 => '',
45 Gitorious_i0 => '',
46 Gitorious_i1 => '',
48 $values{'mirror'} = 0 unless $Girocco::Config::mirror;
49 $values{'mirror'} = 0 if $Girocco::Config::push && $name =~ m#/#;
50 if (@{[$name =~ m#/#g]} > 5) {
51 $gcgi->err("Unable to create a fork more than five levels deep, please fork the parent project instead.");
52 exit;
54 my $y0 = $cgi->param('y0') || '';
55 if ($cgi->param('mode') && $y0 eq 'Register' && $cgi->request_method eq 'POST') {
56 # submitted, let's see
57 # FIXME: racy, do a lock
58 my $validname = 1;
59 if (Girocco::Project::valid_name($name)) {
60 Girocco::Project::does_exist($name,1)
61 and $gcgi->err("Project with the name '$name' already exists.");
62 } else {
63 $validname = 0;
64 if ($name =~ /^(.*)\.git$/i && Girocco::Project::valid_name($1)) {
65 $gcgi->err("Project name should not end with <tt>.git</tt> - I'll add that automagically.");
66 } else {
67 my $htmlname = html_esc($name);
68 $gcgi->err(
69 "Invalid project name \"$htmlname\" ".
70 "(contains bad characters or is a reserved project name). ".
71 "See <a href=\"@{[url_path($Girocco::Config::htmlurl)]}/names.html\">names</a>.");
75 my $check = $cgi->param('mail');
76 $check =~ tr/ \t/ /s; $check =~ s/^ //; $check =~ s/ $//;
77 if ($check !~ /^(?:(?:(?:the )?sun)|(?:sol))$/i) {
78 $gcgi->err("Sorry, invalid captcha check.");
81 foreach my $key (keys(%values)) {
82 $values{$key} = html_esc($cgi->param($key));
84 my $mirror = ($cgi->param('mode')||'') eq 'mirror';
85 $values{'mirror'} = $Girocco::Config::mirror && $mirror ? 1 : 0;
87 if ($mirror and $Girocco::Config::mirror_sources and not $cgi->param('url')) {
88 my $src = $cgi->param('source'); $src ||= '';
89 my $source; $src and $source = (grep { $_->{label} eq $src } @$Girocco::Config::mirror_sources)[0];
90 $source or $gcgi->err("Invalid or no mirror source $src specified");
92 my $n = $source->{label};
93 my $u = $source->{url};
94 if ($source->{inputs}) {
95 for my $i (0..$#{$source->{inputs}}) {
96 my $v = $cgi->param($n.'_i'.$i);
97 unless ($v) {
98 $gcgi->err("Source specifier '".$source->{inputs}->[$i]->{label}."' not filled.");
99 next;
101 my $ii = $i + 1;
102 $u =~ s/%$ii/$v/g;
104 } else {
105 $u = $cgi->param($n.'_url');
106 $u or $gcgi->err("Source URL not specified");
108 $cgi->param('url', $u);
111 my $proj = Girocco::Project->ghost($name, $mirror) if $validname;
112 if ($validname && $proj->cgi_fill($gcgi)) {
113 if ($mirror) {
114 unless ($Girocco::Config::mirror) {
115 $gcgi->err("Mirroring mode is not enabled at this site.");
116 exit;
118 $proj->premirror;
119 $proj->clone;
120 print "<p>Please <a href=\"@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname\">pass onwards</a>.</p>\n";
121 print "<script language=\"javascript\">document.location='@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname'</script>\n";
123 } else {
124 unless ($Girocco::Config::push) {
125 $gcgi->err("Push mode is not enabled at this site.");
126 exit;
128 $proj->conjure;
129 print <<EOT;
130 <p>Project <a href="@{[url_path($Girocco::Config::gitweburl)]}/$name.git">$name</a> successfully set up.</p>
132 my @pushurls = ();
133 push(@pushurls, "<tt>$Girocco::Config::pushurl/$name.git</tt>") if $Girocco::Config::pushurl;
134 push(@pushurls, "<tt>$Girocco::Config::httpspushurl/$name.git</tt> " .
135 "<sup><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html\">(learn more)</a></sup>")
136 if $Girocco::Config::httpspushurl;
137 print "<p>The push URL(s) for the project: " . join(", ", @pushurls) . "</p>" if @pushurls;
138 my @pullurls = ();
139 push(@pullurls, $Girocco::Config::gitpullurl) if $Girocco::Config::gitpullurl;
140 push(@pullurls, $Girocco::Config::httppullurl) if $Girocco::Config::httppullurl;
141 print "<p>The read-only URL(s) for the project: <tt>" .
142 join("/$name.git</tt>, <tt>", @pullurls) .
143 "/$name.git</tt></p>" if @pullurls;
144 my $regnotice = '';
145 if ($Girocco::Config::manage_users) {
146 $regnotice = <<EOT;
147 Everyone who wants to push must <a href="@{[url_path($Girocco::Config::webadmurl)]}/reguser.cgi">register oneself as a user</a> first.
148 (One user can have push access to multiple projects and multiple users can have push access to one project.)
151 my $pushy = $Girocco::Config::pushurl || $Girocco::Config::httpspushurl;
152 my $pushyhint = '';
153 $pushyhint = " # <span style='font-family:sans-serif'><sup style='position:fixed'>" .
154 "<a href=\"@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html\">(learn more)</a></sup>" .
155 "</span>" if $pushy =~ /^https:/i;
156 print <<EOT;
157 <p>You can <a href="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi?name=$escname">assign users</a> now
158 - don't forget to assign yourself as a user as well if you want to push!
159 $regnotice
160 </p>
161 <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.
162 To import a new project, the procedure is roughly as follows:
163 <pre>
164 \$ git init
165 \$ git add
166 \$ git commit
167 \$ git remote add origin $pushy/$name.git$pushyhint
168 \$ git push --all origin
169 </pre>
170 </p>
171 <p>Enjoy yourself, and have a lot of fun!</p>
174 exit;
178 my $mirror_mode = {
179 name => 'mirror',
180 desc => 'our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates',
181 pwpurp => 'mirroring URL'
183 my $push_mode = {
184 name => 'push',
185 desc => 'registered users with appropriate permissions will be able to push to the repository',
186 pwpurp => 'list of users allowed to push'
189 my $me = $Girocco::Config::mirror ? $mirror_mode : undef;
190 my $pe = $Girocco::Config::push ? $push_mode : undef;
191 if ($me and $pe) {
192 print <<EOT;
193 <p>At this site, you can host a project in one of two modes: $me->{name} mode and $pe->{name} mode.
194 In the <b>$me->{name} mode</b>, $me->{desc}.
195 In the <b>$pe->{name} mode</b>, $pe->{desc}.
196 You currently cannot switch freely between those two modes;
197 if you want to switch from mirroring to push mode or vice versa just delete and recreate
198 the project.</p>
200 } else {
201 my $mode = $me ? $me : $pe;
202 print "<p>This site will host your project in a <b>$mode->{name} mode</b>: $mode->{desc}.</p>\n";
205 my @pwpurp = ();
206 push @pwpurp, $me->{pwpurp} if $me;
207 push @pwpurp, $pe->{pwpurp} if $pe;
208 my $pwpurp = join(', ', @pwpurp);
210 if ($Girocco::Config::project_passwords) {
211 print <<EOT;
212 <p>You will need the admin password to adjust the project settings later
213 ($pwpurp, project description, ...).</p>
217 unless ($name =~ m#/#) {
218 print <<EOT;
219 <p>Note that if your project is a <strong>fork of an existing project</strong>
220 (this does not mean anything socially bad), please instead go to the project's
221 gitweb page and click the 'fork' link in the top bar. This way, all of us
222 will save bandwidth and more importantly, your project will be properly categorized.</p>
224 $me and print <<EOT;
225 <p>If your project is a fork but the existing project is not registered here yet, please
226 consider registering it first; you do not have to be involved in the project
227 in order to register it here as a mirror.</p>
229 } else {
230 my $xname = $name; $xname =~ s#/$#.git#; #
231 my ($pushnote1, $pushnote2);
232 if ($pe) {
233 $pushnote1 = " and you will need to push only the data <em>you</em> created, not the whole project";
234 $pushnote2 = <<EOT;
235 (That will be done automagically, you do not need to specify any extra arguments during the push.)
238 print <<EOT;
239 <p>Great, your project will be created as a subproject of the '$xname' project.
240 This means that it will be properly categorized$pushnote1.$pushnote2</p>
244 my $modechooser;
245 my $mirrorentry = '';
246 if ($me) {
247 $mirrorentry = '<tr id="mirror_url"><td class="formlabel" style="vertical-align:middle">Mirror source:</td><td>';
248 if (!$Girocco::Config::mirror_sources) {
249 $mirrorentry .= "<input type='text' name='url' value=%values{'url'}/>";
250 } else {
251 $mirrorentry .= "<table>"."\n";
252 foreach my $source (@$Girocco::Config::mirror_sources) {
253 my $n = $source->{label};
254 $mirrorentry .= '<tr><td class="formlabel">';
255 $mirrorentry .= '<p><input type="radio" class="mirror_sources" name="source" value="'.$n.'"'.
256 ($n eq $values{'source'} ? ' checked="checked"' : '').' />';
257 $mirrorentry .= $n;
258 $mirrorentry .= '</p></td><td>';
259 if ($source->{desc}) {
260 $mirrorentry .= '<p>';
261 $source->{link} and $mirrorentry .= '<a href="'.$source->{link}.'">';
262 $mirrorentry .= $source->{desc};
263 $source->{link} and $mirrorentry .= '</a>';
264 $mirrorentry .= '</p>';
266 if (!$source->{inputs}) {
267 $mirrorentry .= '<p>URL: <input type="text" name="'.$n.'_url" '.
268 'value="'.$values{$n.'_url'}.
269 '" onchange="set_mirror_source('."'".$n."'".')" /></p>';
270 } else {
271 $mirrorentry .= '<p>';
272 my $i = 0;
273 foreach my $input (@{$source->{inputs}}) {
274 $mirrorentry .= $input->{label};
275 my ($l, $v) = ($n.'_i'.$i, '');
276 if ($cgi->param($l)) {
277 $v = ' value="'.html_esc($cgi->param($l)).'"';
279 $mirrorentry .= ' <input type="text" name="'.$l.'"'.$v.
280 ' onchange="set_mirror_source('."'".$n."'".')" />';
281 $mirrorentry .= $input->{suffix} if $input->{suffix};
282 $mirrorentry .= '&#160; &#160;';
283 } continue { $i++; }
284 $mirrorentry .= '</p>';
286 $mirrorentry .= '</td></tr>'."\n";
288 $mirrorentry .= "</table>";
290 $mirrorentry .= '</td></tr>';
292 if ($me and $pe) {
293 $modechooser = <<EOT;
294 <tr><td class="formlabel" style="vertical-align:middle">Hosting mode:</td><td><p>
295 <input type="radio" name="mode" value="mirror" id="mirror_radio"@{[$values{'mirror'}?' checked="checked"':'']} />Mirror mode<br />
296 <input type="radio" name="mode" value="push" id="push_radio"@{[$values{'mirror'}?'':' checked="checked"']} />Push mode
297 </p></td></tr>
299 } else {
300 $modechooser = '<input type="hidden" name="mode" value="'.($me ? $me->{name} : $pe->{name}).'" />';
303 my $forkentry = '';
304 if ($name =~ m#/#) {
305 $name =~ s#^(.*)/##;
306 $forkentry = '<input type="hidden" name="fork" value="'.$1.'" /><span class="formdata" style="padding-left:0.5ex">' .
307 html_esc($1) . '/</span>';
309 $name = html_esc($name);
311 print <<EOT;
312 $Girocco::Config::legalese
313 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/regproj.cgi">
314 <table class="form">
315 <tr><td class="formlabel">Project name:</td>
316 <td>$forkentry<input type="text" name="name" value="$name" /><span class="formdata" style="padding-left:0">.git</span></td></tr>
318 if ($Girocco::Config::project_passwords) {
319 print <<EOT;
320 <tr><td class="formlabel">Admin password (twice):</td><td><input type="password" name="pwd" /><br /><input type="password" name="pwd2" /></td></tr>
323 if ($Girocco::Config::project_owners eq 'email') {
324 print <<EOT;
325 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" value="@{[$values{'email'}]}" /></td></tr>
328 print $modechooser;
329 print $mirrorentry;
331 $gcgi->print_form_fields($Girocco::Project::metadata_fields, \%values, @Girocco::Config::project_fields);
333 print <<EOT;
336 print <<EOT;
337 <tr><td class="formlabel" style="line-height:inherit">Anti-captcha - please<br />enter name of our nearest star:</td>
338 <td style="vertical-align:middle"><input type="text" name="mail" /></td></tr>
339 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="Register" /></td></tr>
340 </table>
341 </form>