svn clones: fix prefix computation
[girocco.git] / cgi / regproj.cgi
blob1f49c57ce5b6fb8878ed02d17bfb416fe9559255
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/$name";
26 my $y0 = $cgi->param('y0') || '';
27 if ($cgi->param('mode') && $y0 eq 'Register' && $cgi->request_method eq 'POST') {
28 # submitted, let's see
29 # FIXME: racy, do a lock
30 Girocco::Project::valid_name($name)
31 and Girocco::Project::does_exist($name,1)
32 and $gcgi->err("Project with the name '$name' already exists.");
33 $name =~ /\.git$/
34 and $gcgi->err("Project name should not end with <tt>.git</tt> - I'll add that automagically.");
36 my $check = $cgi->param('mail');
37 $check =~ tr/ \t/ /s; $check =~ s/^ //; $check =~ s/ $//;
38 if ($check !~ /^(?:(?:(?:the )?sun)|(?:sol))$/i) {
39 print "<p>Sorry, invalid captcha check.</p>";
40 exit;
43 my $mirror = $cgi->param('mode') eq 'mirror';
45 if ($mirror and $Girocco::Config::mirror_sources and not $cgi->param('url')) {
46 my $src = $cgi->param('source'); $src ||= '';
47 my $source; $src and $source = (grep { $_->{label} eq $src } @$Girocco::Config::mirror_sources)[0];
48 $source or $gcgi->err("Invalid or no mirror source $src specified");
50 my $n = $source->{label};
51 my $u = $source->{url};
52 if ($source->{inputs}) {
53 for my $i (0..$#{$source->{inputs}}) {
54 my $v = $cgi->param($n.'_i'.$i);
55 unless ($v) {
56 $gcgi->err("Source specifier '".$source->{inputs}->[$i]->{label}."' not filled.");
57 next;
59 my $ii = $i + 1;
60 $u =~ s/%$ii/$v/g;
62 } else {
63 $u = $cgi->param($n.'_url');
64 $u or $gcgi->err("Source URL not specified");
66 $cgi->param('url', $u);
69 my $proj = Girocco::Project->ghost($name, $mirror);
70 if ($proj->cgi_fill($gcgi)) {
71 if ($mirror) {
72 unless ($Girocco::Config::mirror) {
73 $gcgi->err("Mirroring mode is not enabled at this site.");
74 exit;
76 $proj->premirror;
77 $proj->clone;
78 print "<p>Please <a href=\"@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$name\">pass onwards</a>.</p>\n";
79 print "<script language=\"javascript\">document.location='@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$name'</script>\n";
81 } else {
82 unless ($Girocco::Config::push) {
83 $gcgi->err("Push mode is not enabled at this site.");
84 exit;
86 $proj->conjure;
87 print <<EOT;
88 <p>Project <a href="@{[url_path($Girocco::Config::gitweburl)]}/$name.git">$name</a> successfully set up.</p>
89 EOT
90 my @pushurls = ();
91 push(@pushurls, "<tt>$Girocco::Config::pushurl/$name.git</tt>") if $Girocco::Config::pushurl;
92 push(@pushurls, "<tt>$Girocco::Config::httpspushurl/$name.git</tt> " .
93 "<sup><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html\">(learn more)</a></sup>")
94 if $Girocco::Config::httpspushurl;
95 print "<p>The push URL(s) for the project: " . join(", ", @pushurls) . "</p>" if @pushurls;
96 my @pullurls = ();
97 push(@pullurls, $Girocco::Config::gitpullurl) if $Girocco::Config::gitpullurl;
98 push(@pullurls, $Girocco::Config::httppullurl) if $Girocco::Config::httppullurl;
99 print "<p>The read-only URL(s) for the project: <tt>" .
100 join("/$name.git</tt>, <tt>", @pullurls) .
101 "/$name.git</tt></p>" if @pullurls;
102 my $regnotice = '';
103 if ($Girocco::Config::manage_users) {
104 $regnotice = <<EOT;
105 Everyone who wants to push must <a href="@{[url_path($Girocco::Config::webadmurl)]}/reguser.cgi">register oneself as a user</a> first.
106 (One user can have push access to multiple projects and multiple users can have push access to one project.)
109 my $pushy = $Girocco::Config::pushurl || $Girocco::Config::httpspushurl;
110 my $pushyhint = '';
111 $pushyhint = " # <span style='font-family:sans-serif'><sup style='position:fixed'>" .
112 "<a href=\"@{[url_path($Girocco::Config::htmlurl)]}/httpspush.html\">(learn more)</a></sup>" .
113 "</span>" if $pushy =~ /^https:/i;
114 print <<EOT;
115 <p>You can <a href="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi?name=$name">assign users</a> now
116 - don't forget to assign yourself as a user as well if you want to push!
117 $regnotice
118 </p>
119 <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.
120 To import a new project, the procedure is roughly as follows:
121 <pre>
122 \$ git init
123 \$ git add
124 \$ git commit
125 \$ git remote add origin $pushy/$name.git$pushyhint
126 \$ git push --all origin
127 </pre>
128 </p>
129 <p>Enjoy yourself, and have a lot of fun!</p>
132 exit;
136 my $mirror_mode = {
137 name => 'mirror',
138 desc => 'our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates',
139 pwpurp => 'mirroring URL'
141 my $push_mode = {
142 name => 'push',
143 desc => 'registered users with appropriate permissions will be able to push to the repository',
144 pwpurp => 'list of users allowed to push'
147 my $me = $Girocco::Config::mirror ? $mirror_mode : undef;
148 my $pe = $Girocco::Config::push ? $push_mode : undef;
149 if ($me and $pe) {
150 print <<EOT;
151 <p>At this site, you can host a project in one of two modes: $me->{name} mode and $pe->{name} mode.
152 In the <b>$me->{name} mode</b>, $me->{desc}.
153 In the <b>$pe->{name} mode</b>, $pe->{desc}.
154 You currently cannot switch freely between those two modes;
155 if you want to switch from mirroring to push mode or vice versa just delete and recreate
156 the project.</p>
158 } else {
159 my $mode = $me ? $me : $pe;
160 print "<p>This site will host your project in a <b>$mode->{name} mode</b>: $mode->{desc}.</p>\n";
163 my @pwpurp = ();
164 push @pwpurp, $me->{pwpurp} if $me;
165 push @pwpurp, $pe->{pwpurp} if $pe;
166 my $pwpurp = join(', ', @pwpurp);
168 if ($Girocco::Config::project_passwords) {
169 print <<EOT;
170 <p>You will need the admin password to adjust the project settings later
171 ($pwpurp, project description, ...).</p>
175 unless ($name =~ m#/#) {
176 print <<EOT;
177 <p>Note that if your project is a <strong>fork of an existing project</strong>
178 (this does not mean anything socially bad), please instead go to the project's
179 gitweb page and click the 'fork' link in the top bar. This way, all of us
180 will save bandwidth and more importantly, your project will be properly categorized.</p>
182 $me and print <<EOT;
183 <p>If your project is a fork but the existing project is not registered here yet, please
184 consider registering it first; you do not have to be involved in the project
185 in order to register it here as a mirror.</p>
187 } else {
188 my $xname = $name; $xname =~ s#/$#.git#; #
189 my ($pushnote1, $pushnote2);
190 if ($pe) {
191 $pushnote1 = " and you will need to push only the data <em>you</em> created, not the whole project";
192 $pushnote2 = <<EOT;
193 (That will be done automagically, you do not need to specify any extra arguments during the push.)
196 print <<EOT;
197 <p>Great, your project will be created as a subproject of the '$xname' project.
198 This means that it will be properly categorized$pushnote1.$pushnote2</p>
202 my $modechooser;
203 my $mirrorentry = '';
204 if ($me) {
205 $mirrorentry = '<tr id="mirror_url"><td class="formlabel" style="vertical-align:middle">Mirror source:</td><td>';
206 if (!$Girocco::Config::mirror_sources) {
207 $mirrorentry .= '<input type="text" name="url" />';
208 } else {
209 $mirrorentry .= "<table>"."\n";
210 my $checked = ' checked=checked';
211 foreach my $source (@$Girocco::Config::mirror_sources) {
212 my $n = $source->{label};
213 $mirrorentry .= '<tr><td class="formlabel">';
214 $mirrorentry .= '<p><input type="radio" name="source" value="'.$n.'" '.$checked.' />';
215 $mirrorentry .= $n;
216 $mirrorentry .= '</p></td><td>';
217 $checked = '';
218 if ($source->{desc}) {
219 $mirrorentry .= '<p>';
220 $source->{link} and $mirrorentry .= '<a href="'.$source->{link}.'">';
221 $mirrorentry .= $source->{desc};
222 $source->{link} and $mirrorentry .= '</a>';
223 $mirrorentry .= '</p>';
225 if (!$source->{inputs}) {
226 $mirrorentry .= '<p>URL: <input type="text" name="'.$n.'_url" /></p>';
227 } else {
228 $mirrorentry .= '<p>';
229 my $i = 0;
230 foreach my $input (@{$source->{inputs}}) {
231 $mirrorentry .= $input->{label};
232 my ($l, $v) = ($n.'_i'.$i, '');
233 if ($cgi->param($l)) {
234 $v = ' value="'.html_esc($cgi->param($l)).'"';
236 $mirrorentry .= ' <input type="text" name="'.$l.'"'.$v.' />';
237 $mirrorentry .= $input->{suffix} if $input->{suffix};
238 $mirrorentry .= '&nbsp; &nbsp;';
239 } continue { $i++; }
240 $mirrorentry .= '</p>';
242 $mirrorentry .= '</td></tr>'."\n";
244 $mirrorentry .= "</table>";
246 $mirrorentry .= '</td></tr>';
248 if ($me and $pe) {
249 $modechooser = <<EOT;
250 <tr><td class="formlabel" style="vertical-align:middle">Hosting mode:</td><td><p>
251 <input type="radio" name="mode" value="mirror" id="mirror_radio" checked="checked" />Mirror mode<br />
252 <input type="radio" name="mode" value="push" id="push_radio" />Push mode
253 </p></td></tr>
255 } else {
256 $modechooser = '<input type="hidden" name="mode" value="'.($me ? $me->{name} : $pe->{name}).'" />';
259 my $forkentry = '';
260 if ($name =~ m#/#) {
261 $name =~ s#^(.*)/##;
262 $forkentry = '<input type="hidden" name="fork" value="'.$1.'" /><span class="formdata" style="padding-left:0.5ex">'.$1.'/</span>';
265 print <<EOT;
266 $Girocco::Config::legalese
267 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/regproj.cgi">
268 <table class="form">
269 <tr><td class="formlabel">Project name:</td>
270 <td>$forkentry<input type="text" name="name" value="$name" /><span class="formdata" style="padding-left:0">.git</span></td></tr>
272 if ($Girocco::Config::project_passwords) {
273 print <<EOT;
274 <tr><td class="formlabel">Admin password (twice):</td><td><input type="password" name="pwd" /><br /><input type="password" name="pwd2" /></td></tr>
277 if ($Girocco::Config::project_owners eq 'email') {
278 print <<EOT;
279 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" /></td></tr>
282 print $modechooser;
283 print $mirrorentry;
285 $gcgi->print_form_fields($Girocco::Project::metadata_fields, undef, @Girocco::Config::project_fields);
287 print <<EOT;
290 print <<EOT;
291 <tr><td class="formlabel" style="line-height:inherit">Anti-captcha - please<br />enter name of our nearest star:</td>
292 <td style="vertical-align:middle"><input type="text" name="mail" /></td></tr>
293 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="Register" /></td></tr>
294 </table>
295 </form>