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