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