gitweb: update index text
[girocco.git] / cgi / regproj.cgi
blob9b58798c242642fcab0a14c0c808707007c71af7
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::Project;
12 use Girocco::Util;
14 my $gcgi = Girocco::CGI->new('Project Registration');
15 my $cgi = $gcgi->cgi;
17 if (my $romsg=check_readonly(1)) {
18 print "<p>$romsg</p>\n";
19 exit;
22 my $name = $cgi->param('name');
23 defined($name) or $name = '';
25 my $fork = $cgi->param('fork');
26 if (defined($fork)) {
27 $fork =~ s/\.git$//;
28 $name = "$fork/$name";
30 my $escname = $name;
31 $escname =~ s/[+]/%2B/g;
32 my $mirror_mode_set = 1;
33 if ($Girocco::Config::mirror && $Girocco::Config::push) {
34 $mirror_mode_set = 0 unless ($Girocco::Config::initial_regproj_mode||'') eq 'mirror';
36 my %values = (
37 desc => '',
38 email => '',
39 hp => '',
40 mirror => $mirror_mode_set,
41 cleanmirror => 1,
42 notifymail => '',
43 reverseorder => 1,
44 summaryonly => '',
45 notifytag => '',
46 notifyjson => '',
47 notifycia => '',
48 README => '',
49 jsontype => 'application/json',
50 rmtype => 'Markdown',
51 source => 'Anywhere',
52 url => '',
53 Anywhere_url => '',
54 GitHub_i0 => '',
55 GitHub_i1 => '',
56 Gitorious_i0 => '',
57 Gitorious_i1 => '',
59 $values{'mirror'} = 0 unless $Girocco::Config::mirror;
60 $values{'mirror'} = 0 if $Girocco::Config::push && $name =~ m#/#;
61 if (@{[$name =~ m#/#g]} > 5) {
62 $gcgi->err("Unable to create a fork more than five levels deep, please fork the parent project instead.");
63 exit;
65 my $y0 = $cgi->param('y0') || '';
66 my $tok = $cgi->param('token') || '';
67 if ($cgi->param('mode') && $y0 eq 'Register' && $cgi->request_method eq 'POST') {
68 # Check for token validity
69 if (!check_timed_token($tok, "projedit", "", $Girocco::Config::project_edit_timeout)) {
70 $gcgi->err("Session has timed out or is invalid, please try again.");
72 # submitted, let's see
73 # FIXME: racy, do a lock
74 my $validname = 1;
75 if (Girocco::Project::valid_name($name)) {
76 Girocco::Project::does_exist($name,1)
77 and $gcgi->err("Project with the name '$name' already exists.");
78 } else {
79 $validname = 0;
80 if ($name =~ /^(.*)\.git$/i && Girocco::Project::valid_name($1)) {
81 $gcgi->err("Project name should not end with <tt>.git</tt> - I'll add that automagically.");
82 } else {
83 my $htmlname = html_esc($name);
84 $gcgi->err(
85 "Invalid project name \"$htmlname\" ".
86 "(contains bad characters or is a reserved project name). ".
87 "See <a href=\"@{[url_path($Girocco::Config::htmlurl)]}/names.html\">names</a>.");
91 my $check = $cgi->param('mail');
92 $check =~ tr/ \t/ /s; $check =~ s/^ //; $check =~ s/ $//;
93 if ($check !~ /^(?:(?:(?:the )?sun)|(?:sol))$/i) {
94 $gcgi->err("Sorry, invalid captcha check.");
97 foreach my $key (keys(%values)) {
98 $values{$key} = html_esc($cgi->param($key));
100 my $mirror = ($cgi->param('mode')||'') eq 'mirror';
101 $values{'mirror'} = $Girocco::Config::mirror && $mirror ? 1 : 0;
103 if ($mirror and $Girocco::Config::mirror_sources and not $cgi->param('url')) {
104 my $src = $cgi->param('source'); $src ||= '';
105 my $source; $src and $source = (grep { $_->{label} eq $src } @$Girocco::Config::mirror_sources)[0];
106 $source or $gcgi->err("Invalid or no mirror source $src specified");
108 my $n = $source->{label};
109 my $u = $source->{url};
110 if ($source->{inputs}) {
111 for my $i (0..$#{$source->{inputs}}) {
112 my $v = $cgi->param($n.'_i'.$i);
113 unless ($v) {
114 $gcgi->err("Source specifier '".$source->{inputs}->[$i]->{label}."' not filled.");
115 next;
117 my $ii = $i + 1;
118 $u =~ s/%$ii/$v/g;
120 } else {
121 $u = $cgi->param($n.'_url');
122 $u or $gcgi->err("Source URL not specified");
124 $cgi->param('url', $u);
127 my $proj = Girocco::Project->ghost($name, $mirror) if $validname;
128 if ($validname && $proj->cgi_fill($gcgi)) {
129 if ($mirror) {
130 unless ($Girocco::Config::mirror) {
131 $gcgi->err("Mirroring mode is not enabled at this site.");
132 exit;
134 $proj->premirror;
135 $proj->clone;
136 print "<p>Please <a href=\"@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname\">pass onwards</a>.</p>\n";
137 print "<script language=\"javascript\">document.location='@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname'</script>\n";
139 } else {
140 unless ($Girocco::Config::push) {
141 $gcgi->err("Push mode is not enabled at this site.");
142 exit;
144 $proj->conjure;
145 print <<EOT;
146 <p>Project <a href="@{[url_path($Girocco::Config::gitweburl)]}/$name.git">$name</a> successfully set up.</p>
148 my @pushurls = ();
149 push(@pushurls, "<tt>$Girocco::Config::pushurl/$name.git</tt>") if $Girocco::Config::pushurl;
150 push(@pushurls, "<tt>$Girocco::Config::httpspushurl/$name.git</tt> " .
151 "<sup class=\"sup\"><span><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html\">(learn more)</a></span></sup>")
152 if $Girocco::Config::httpspushurl;
153 print "<p>The push URL(s) for the project: " . join(", ", @pushurls) . "</p>" if @pushurls;
154 my @pullurls = ();
155 push(@pullurls, $Girocco::Config::gitpullurl) if $Girocco::Config::gitpullurl;
156 push(@pullurls, $Girocco::Config::httppullurl) if $Girocco::Config::httppullurl;
157 print "<p>The read-only URL(s) for the project: <tt>" .
158 join("/$name.git</tt>, <tt>", @pullurls) .
159 "/$name.git</tt></p>" if @pullurls;
160 my $regnotice = '';
161 if ($Girocco::Config::manage_users) {
162 $regnotice = <<EOT;
163 Everyone who wants to push must <a href="@{[url_path($Girocco::Config::webadmurl)]}/reguser.cgi">register oneself as a user</a> first.
164 (One user can have push access to multiple projects and multiple users can have push access to one project.)
167 my $pushy = $Girocco::Config::pushurl || $Girocco::Config::httpspushurl;
168 my $pushyhint = '';
169 $pushyhint = " # <span style='font-family:sans-serif;font-size:smaller;position:relative;bottom:1pt'>" .
170 "<a href=\"@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html\">(learn more)</a></span>"
171 if $pushy =~ /^https:/i;
172 print <<EOT;
173 <p>You can <a href="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi?name=$escname">assign users</a> now
174 - don't forget to assign yourself as a user as well if you want to push!
175 $regnotice
176 </p>
177 <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.
178 To import a new project, the procedure is roughly as follows:
179 <pre>
180 \$ git init
181 \$ git add
182 \$ git commit
183 \$ git remote add origin $pushy/$name.git$pushyhint
184 \$ git push --all origin
185 </pre>
186 </p>
187 <p>Enjoy yourself, and have a lot of fun!</p>
190 exit;
194 my $mirror_mode = {
195 name => 'mirror',
196 desc => 'our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates',
197 pwpurp => 'mirroring URL'
199 my $push_mode = {
200 name => 'push',
201 desc => 'registered users with appropriate permissions will be able to push to the repository',
202 pwpurp => 'list of users allowed to push'
205 my $me = $Girocco::Config::mirror ? $mirror_mode : undef;
206 my $pe = $Girocco::Config::push ? $push_mode : undef;
207 if ($me and $pe) {
208 print <<EOT;
209 <p>At this site, you can host a project in one of two modes: $me->{name} mode and $pe->{name} mode.
210 In the <b>$me->{name} mode</b>, $me->{desc}.
211 In the <b>$pe->{name} mode</b>, $pe->{desc}.
212 You currently cannot switch freely between those two modes;
213 if you want to switch from mirroring to push mode or vice versa just delete and recreate
214 the project.</p>
216 } else {
217 my $mode = $me ? $me : $pe;
218 print "<p>This site will host your project in a <b>$mode->{name} mode</b>: $mode->{desc}.</p>\n";
221 my @pwpurp = ();
222 push @pwpurp, $me->{pwpurp} if $me;
223 push @pwpurp, $pe->{pwpurp} if $pe;
224 my $pwpurp = join(', ', @pwpurp);
226 if ($Girocco::Config::project_passwords) {
227 print <<EOT;
228 <p>You will need the admin password to adjust the project settings later
229 ($pwpurp, project description, ...).</p>
233 unless ($name =~ m#/#) {
234 print <<EOT;
235 <p>Note that if your project is a <strong>fork of an existing project</strong>
236 (this does not mean anything socially bad), please instead go to the project's
237 gitweb page and click the 'fork' link in the top bar. This way, all of us
238 will save bandwidth and more importantly, your project will be properly categorized.</p>
240 $me and print <<EOT;
241 <p>If your project is a fork but the existing project is not registered here yet, please
242 consider registering it first; you do not have to be involved in the project
243 in order to register it here as a mirror.</p>
245 } else {
246 my $xname = $name; $xname =~ s#/$#.git#; #
247 my ($pushnote1, $pushnote2);
248 if ($pe) {
249 $pushnote1 = " and you will need to push only the data <em>you</em> created, not the whole project";
250 $pushnote2 = <<EOT;
251 (That will be done automagically, you do not need to specify any extra arguments during the push.)
254 print <<EOT;
255 <p>Great, your project will be created as a subproject of the '$xname' project.
256 This means that it will be properly categorized$pushnote1.$pushnote2</p>
260 my $modechooser;
261 my $mirrorentry = '';
262 if ($me) {
263 $mirrorentry = '<tr id="mirror_url"><td class="formlabel" style="vertical-align:middle">Mirror source:</td><td>';
264 if (!$Girocco::Config::mirror_sources) {
265 $mirrorentry .= "<input type='text' name='url' value='%values{'url'}' />";
266 } else {
267 $mirrorentry .= "<table>"."\n";
268 foreach my $source (@$Girocco::Config::mirror_sources) {
269 my $n = $source->{label};
270 $mirrorentry .= '<tr><td class="formlabel">';
271 $mirrorentry .= '<p><label><input type="radio" class="mirror_sources" name="source" value="'.$n.'"'.
272 ($n eq $values{'source'} ? ' checked="checked"' : '').' />';
273 $mirrorentry .= $n;
274 $mirrorentry .= '</label></p></td><td>';
275 if ($source->{desc}) {
276 $mirrorentry .= '<p>';
277 $source->{link} and $mirrorentry .= '<a href="'.$source->{link}.'">';
278 $mirrorentry .= $source->{desc};
279 $source->{link} and $mirrorentry .= '</a>';
280 $mirrorentry .= '</p>';
282 if (!$source->{inputs}) {
283 $mirrorentry .= '<p>URL: <input type="text" name="'.$n.'_url" '.
284 'value="'.$values{$n.'_url'}.
285 '" onchange="set_mirror_source('."'".$n."'".')" /></p>';
286 } else {
287 $mirrorentry .= '<p>';
288 my $i = 0;
289 foreach my $input (@{$source->{inputs}}) {
290 $mirrorentry .= $input->{label};
291 my ($l, $v) = ($n.'_i'.$i, '');
292 if ($cgi->param($l)) {
293 $v = ' value="'.html_esc($cgi->param($l)).'"';
295 $mirrorentry .= ' <input type="text" name="'.$l.'"'.$v.
296 ' onchange="set_mirror_source('."'".$n."'".')" />';
297 $mirrorentry .= $input->{suffix} if $input->{suffix};
298 $mirrorentry .= '&#160; &#160;';
299 } continue { $i++; }
300 $mirrorentry .= '</p>';
302 $mirrorentry .= '</td></tr>'."\n";
304 $mirrorentry .= "</table>";
306 $mirrorentry .= '</td></tr>'."\n";;
307 $mirrorentry .= '<tr id="mirror_refs"><td class="formlabel">Mirror refs:</td><td class="formdatatd">'.
308 '<label title="Unchecking this will mirror the entire refs namespace which is usually unnecessary. '.
309 'Non-git sources always mirror the entire refs namespace regardless of this setting.">'.
310 '<input type="checkbox" name="cleanmirror" value="1" '.($values{'cleanmirror'} ? 'checked="checked" ' : '').
311 'style="vertical-align:middle" /><span style="vertical-align:middle; margin-left:0.5ex">'.
312 'Only mirror <code>refs/heads/*</code>, <code>refs/tags/*</code> and <code>refs/notes/*</code></span></label></td></tr>'."\n"
313 if grep(/cleanmirror/, @Girocco::Config::project_fields);
315 if ($me and $pe) {
316 $modechooser = <<EOT;
317 <tr><td class="formlabel" style="vertical-align:middle">Hosting mode:</td><td><p>
318 <label><input type="radio" name="mode" value="mirror" id="mirror_radio"@{[$values{'mirror'}?' checked="checked"':'']} />Mirror mode</label><br />
319 <label><input type="radio" name="mode" value="push" id="push_radio"@{[$values{'mirror'}?'':' checked="checked"']} />Push mode</label>
320 </p></td></tr>
322 } else {
323 $modechooser = '<input type="hidden" name="mode" value="'.($me ? $me->{name} : $pe->{name}).'" />';
326 my $forkentry = '';
327 if ($name =~ m#/#) {
328 $name =~ s#^(.*)/##;
329 $forkentry = '<input type="hidden" name="fork" value="'.$1.'" /><span class="formdata" style="padding-left:0.5ex">' .
330 html_esc($1) . '/</span>';
332 $name = html_esc($name);
333 my $tokauth = get_token_field("projedit", "", $Girocco::Config::project_edit_timeout);
334 $tokauth and $tokauth = "\n".$tokauth;
336 print <<EOT;
337 $Girocco::Config::legalese
338 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/regproj.cgi">$tokauth
339 <table class="form">
340 <tr><td class="formlabel">Project name:</td>
341 <td>$forkentry<input type="text" name="name" value="$name" /><span class="formdata" style="padding-left:0">.git</span></td></tr>
343 if ($Girocco::Config::project_passwords) {
344 print <<EOT;
345 <tr><td class="formlabel">Admin password (twice):</td><td><input type="password" name="pwd" /><br /><input type="password" name="pwd2" /></td></tr>
348 if ($Girocco::Config::project_owners eq 'email') {
349 print <<EOT;
350 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" value="@{[$values{'email'}]}" /></td></tr>
353 print $modechooser;
354 print $mirrorentry;
356 $gcgi->print_form_fields($Girocco::Project::metadata_fields, \%values, @Girocco::Config::project_fields);
358 print <<EOT;
361 print <<EOT;
362 <tr><td class="formlabel" style="line-height:inherit">Anti-captcha &#x2013; please<br />enter name of our nearest star:</td>
363 <td style="vertical-align:middle"><input type="text" name="mail" /></td></tr>
364 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="Register" /></td></tr>
365 </table>
366 </form>