2 # (c) Petr Baudis <pasky@suse.cz>
14 my $gcgi = Girocco
::CGI
->new('Project Registration');
17 my $name = $cgi->param('name');
18 defined($name) or $name = '';
20 my $fork = $cgi->param('fork');
23 $name = "$fork/$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';
35 mirror
=> $mirror_mode_set,
52 $values{'mirror'} = 0 unless $Girocco::Config
::mirror
;
53 $values{'mirror'} = 0 if $Girocco::Config
::push && $name =~ m
#/#;
54 if (@
{[$name =~ m
#/#g]} > 5) {
55 $gcgi->err("Unable to create a fork more than five levels deep, please fork the parent project instead.");
58 my $y0 = $cgi->param('y0') || '';
59 if ($cgi->param('mode') && $y0 eq 'Register' && $cgi->request_method eq 'POST') {
60 # submitted, let's see
61 # FIXME: racy, do a lock
63 if (Girocco
::Project
::valid_name
($name)) {
64 Girocco
::Project
::does_exist
($name,1)
65 and $gcgi->err("Project with the name '$name' already exists.");
68 if ($name =~ /^(.*)\.git$/i && Girocco
::Project
::valid_name
($1)) {
69 $gcgi->err("Project name should not end with <tt>.git</tt> - I'll add that automagically.");
71 my $htmlname = html_esc
($name);
73 "Invalid project name \"$htmlname\" ".
74 "(contains bad characters or is a reserved project name). ".
75 "See <a href=\"@{[url_path($Girocco::Config::htmlurl)]}/names.html\">names</a>.");
79 my $check = $cgi->param('mail');
80 $check =~ tr/ \t/ /s; $check =~ s/^ //; $check =~ s/ $//;
81 if ($check !~ /^(?:(?:(?:the )?sun)|(?:sol))$/i) {
82 $gcgi->err("Sorry, invalid captcha check.");
85 foreach my $key (keys(%values)) {
86 $values{$key} = html_esc
($cgi->param($key));
88 my $mirror = ($cgi->param('mode')||'') eq 'mirror';
89 $values{'mirror'} = $Girocco::Config
::mirror
&& $mirror ?
1 : 0;
91 if ($mirror and $Girocco::Config
::mirror_sources
and not $cgi->param('url')) {
92 my $src = $cgi->param('source'); $src ||= '';
93 my $source; $src and $source = (grep { $_->{label
} eq $src } @
$Girocco::Config
::mirror_sources
)[0];
94 $source or $gcgi->err("Invalid or no mirror source $src specified");
96 my $n = $source->{label
};
97 my $u = $source->{url
};
98 if ($source->{inputs
}) {
99 for my $i (0..$#{$source->{inputs}}) {
100 my $v = $cgi->param($n.'_i'.$i);
102 $gcgi->err("Source specifier '".$source->{inputs
}->[$i]->{label
}."' not filled.");
109 $u = $cgi->param($n.'_url');
110 $u or $gcgi->err("Source URL not specified");
112 $cgi->param('url', $u);
115 my $proj = Girocco
::Project
->ghost($name, $mirror) if $validname;
116 if ($validname && $proj->cgi_fill($gcgi)) {
118 unless ($Girocco::Config
::mirror
) {
119 $gcgi->err("Mirroring mode is not enabled at this site.");
124 print "<p>Please <a href=\"@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname\">pass onwards</a>.</p>\n";
125 print "<script language=\"javascript\">document.location='@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname'</script>\n";
128 unless ($Girocco::Config
::push) {
129 $gcgi->err("Push mode is not enabled at this site.");
134 <p>Project <a href="@{[url_path($Girocco::Config::gitweburl)]}/$name.git">$name</a> successfully set up.</p>
137 push(@pushurls, "<tt>$Girocco::Config::pushurl/$name.git</tt>") if $Girocco::Config
::pushurl
;
138 push(@pushurls, "<tt>$Girocco::Config::httpspushurl/$name.git</tt> " .
139 "<sup class=\"sup\"><span><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html\">(learn more)</a></span></sup>")
140 if $Girocco::Config
::httpspushurl
;
141 print "<p>The push URL(s) for the project: " . join(", ", @pushurls) . "</p>" if @pushurls;
143 push(@pullurls, $Girocco::Config
::gitpullurl
) if $Girocco::Config
::gitpullurl
;
144 push(@pullurls, $Girocco::Config
::httppullurl
) if $Girocco::Config
::httppullurl
;
145 print "<p>The read-only URL(s) for the project: <tt>" .
146 join("/$name.git</tt>, <tt>", @pullurls) .
147 "/$name.git</tt></p>" if @pullurls;
149 if ($Girocco::Config
::manage_users
) {
151 Everyone who wants to push must <a href="@{[url_path($Girocco::Config::webadmurl)]}/reguser.cgi">register oneself as a user</a> first.
152 (One user can have push access to multiple projects and multiple users can have push access to one project.)
155 my $pushy = $Girocco::Config
::pushurl
|| $Girocco::Config
::httpspushurl
;
157 $pushyhint = " # <span style='font-family:sans-serif;font-size:smaller;position:relative;bottom:1pt'>" .
158 "<a href=\"@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html\">(learn more)</a></span>"
159 if $pushy =~ /^https:/i;
161 <p>You can <a href="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi?name=$escname">assign users</a> now
162 - don't forget to assign yourself as a user as well if you want to push!
165 <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.
166 To import a new project, the procedure is roughly as follows:
171 \$ git remote add origin $pushy/$name.git$pushyhint
172 \$ git push --all origin
175 <p>Enjoy yourself, and have a lot of fun!</p>
184 desc
=> 'our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates',
185 pwpurp
=> 'mirroring URL'
189 desc
=> 'registered users with appropriate permissions will be able to push to the repository',
190 pwpurp
=> 'list of users allowed to push'
193 my $me = $Girocco::Config
::mirror ?
$mirror_mode : undef;
194 my $pe = $Girocco::Config
::push ?
$push_mode : undef;
197 <p>At this site, you can host a project in one of two modes: $me->{name} mode and $pe->{name} mode.
198 In the <b>$me->{name} mode</b>, $me->{desc}.
199 In the <b>$pe->{name} mode</b>, $pe->{desc}.
200 You currently cannot switch freely between those two modes;
201 if you want to switch from mirroring to push mode or vice versa just delete and recreate
205 my $mode = $me ?
$me : $pe;
206 print "<p>This site will host your project in a <b>$mode->{name} mode</b>: $mode->{desc}.</p>\n";
210 push @pwpurp, $me->{pwpurp
} if $me;
211 push @pwpurp, $pe->{pwpurp
} if $pe;
212 my $pwpurp = join(', ', @pwpurp);
214 if ($Girocco::Config
::project_passwords
) {
216 <p>You will need the admin password to adjust the project settings later
217 ($pwpurp, project description, ...).</p>
221 unless ($name =~ m
#/#) {
223 <p>Note that if your project is a <strong>fork of an existing project</strong>
224 (this does not mean anything socially bad), please instead go to the project's
225 gitweb page and click the 'fork' link in the top bar. This way, all of us
226 will save bandwidth and more importantly, your project will be properly categorized.</p>
229 <p>If your project is a fork but the existing project is not registered here yet, please
230 consider registering it first; you do not have to be involved in the project
231 in order to register it here as a mirror.</p>
234 my $xname = $name; $xname =~ s
#/$#.git#; #
235 my ($pushnote1, $pushnote2);
237 $pushnote1 = " and you will need to push only the data <em>you</em> created, not the whole project";
239 (That will be done automagically, you do not need to specify any extra arguments during the push.)
243 <p>Great, your project will be created as a subproject of the '$xname' project.
244 This means that it will be properly categorized$pushnote1.$pushnote2</p>
249 my $mirrorentry = '';
251 $mirrorentry = '<tr id="mirror_url"><td class="formlabel" style="vertical-align:middle">Mirror source:</td><td>';
252 if (!$Girocco::Config
::mirror_sources
) {
253 $mirrorentry .= "<input type='text' name='url' value='%values{'url'}' />";
255 $mirrorentry .= "<table>"."\n";
256 foreach my $source (@
$Girocco::Config
::mirror_sources
) {
257 my $n = $source->{label
};
258 $mirrorentry .= '<tr><td class="formlabel">';
259 $mirrorentry .= '<p><label><input type="radio" class="mirror_sources" name="source" value="'.$n.'"'.
260 ($n eq $values{'source'} ?
' checked="checked"' : '').' />';
262 $mirrorentry .= '</label></p></td><td>';
263 if ($source->{desc
}) {
264 $mirrorentry .= '<p>';
265 $source->{link} and $mirrorentry .= '<a href="'.$source->{link}.'">';
266 $mirrorentry .= $source->{desc
};
267 $source->{link} and $mirrorentry .= '</a>';
268 $mirrorentry .= '</p>';
270 if (!$source->{inputs
}) {
271 $mirrorentry .= '<p>URL: <input type="text" name="'.$n.'_url" '.
272 'value="'.$values{$n.'_url'}.
273 '" onchange="set_mirror_source('."'".$n."'".')" /></p>';
275 $mirrorentry .= '<p>';
277 foreach my $input (@
{$source->{inputs
}}) {
278 $mirrorentry .= $input->{label
};
279 my ($l, $v) = ($n.'_i'.$i, '');
280 if ($cgi->param($l)) {
281 $v = ' value="'.html_esc
($cgi->param($l)).'"';
283 $mirrorentry .= ' <input type="text" name="'.$l.'"'.$v.
284 ' onchange="set_mirror_source('."'".$n."'".')" />';
285 $mirrorentry .= $input->{suffix
} if $input->{suffix
};
286 $mirrorentry .= '   ';
288 $mirrorentry .= '</p>';
290 $mirrorentry .= '</td></tr>'."\n";
292 $mirrorentry .= "</table>";
294 $mirrorentry .= '</td></tr>'."\n";;
295 $mirrorentry .= '<tr id="mirror_refs"><td class="formlabel">Mirror refs:</td><td class="formdatatd">'.
296 '<label title="Unchecking this will mirror the entire refs namespace which is usually unnecessary. '.
297 'Non-git sources always mirror the entire refs namespace regardless of this setting.">'.
298 '<input type="checkbox" name="cleanmirror" value="1" '.($values{'cleanmirror'} ?
'checked="checked" ' : '').
299 'style="vertical-align:middle" /><span style="vertical-align:middle; margin-left:0.5ex">'.
300 'Only mirror <code>refs/heads/*</code>, <code>refs/tags/*</code> and <code>refs/notes/*</code></span></label></td></tr>'."\n"
301 if grep(/cleanmirror/, @Girocco::Config
::project_fields
);
304 $modechooser = <<EOT;
305 <tr><td class="formlabel" style="vertical-align:middle">Hosting mode:</td><td><p>
306 <label><input type="radio" name="mode" value="mirror" id="mirror_radio"@{[$values{'mirror'}?' checked="checked"':'']} />Mirror mode</label><br />
307 <label><input type="radio" name="mode" value="push" id="push_radio"@{[$values{'mirror'}?'':' checked="checked"']} />Push mode</label>
311 $modechooser = '<input type="hidden" name="mode" value="'.($me ?
$me->{name
} : $pe->{name
}).'" />';
317 $forkentry = '<input type="hidden" name="fork" value="'.$1.'" /><span class="formdata" style="padding-left:0.5ex">' .
318 html_esc
($1) . '/</span>';
320 $name = html_esc
($name);
323 $Girocco::Config::legalese
324 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/regproj.cgi">
326 <tr><td class="formlabel">Project name:</td>
327 <td>$forkentry<input type="text" name="name" value="$name" /><span class="formdata" style="padding-left:0">.git</span></td></tr>
329 if ($Girocco::Config
::project_passwords
) {
331 <tr><td class="formlabel">Admin password (twice):</td><td><input type="password" name="pwd" /><br /><input type="password" name="pwd2" /></td></tr>
334 if ($Girocco::Config
::project_owners
eq 'email') {
336 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" value="@{[$values{'email'}]}" /></td></tr>
342 $gcgi->print_form_fields($Girocco::Project
::metadata_fields
, \
%values, @Girocco::Config
::project_fields
);
348 <tr><td class="formlabel" style="line-height:inherit">Anti-captcha – please<br />enter name of our nearest star:</td>
349 <td style="vertical-align:middle"><input type="text" name="mail" /></td></tr>
350 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="Register" /></td></tr>