Cloning design overhaul - daemon instead of cronjobs
[girocco.git] / cgi / regproj.cgi
blob61dfa65199d3401c407c324145a2ab96ff19b9df
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/";
26 if ($cgi->param('mail')) {
27 print "<p>Go away, bot.</p>";
28 exit;
31 if ($cgi->param('mode')) {
32 # submitted, let's see
33 # FIXME: racy, do a lock
34 my $name = $gcgi->wparam('name');
35 Girocco::Project::valid_name($name)
36 and Girocco::Project::does_exist($name)
37 and $gcgi->err("Project with the name '$name' already exists.");
38 $name =~ /\.git$/
39 and $gcgi->err("Project name should not end with <tt>.git</tt> - I'll add that automagically.");
41 my $mirror = $cgi->param('mode') eq 'mirror';
43 if ($mirror and $Girocco::Config::mirror_sources and not $cgi->param('url')) {
44 my $src = $cgi->param('source'); $src ||= '';
45 my $source; $src and $source = (grep { $_->{label} eq $src } @$Girocco::Config::mirror_sources)[0];
46 $source or $gcgi->err("Invalid or no mirror source $src specified");
48 my $n = $source->{label};
49 my $u = $source->{url};
50 if ($source->{inputs}) {
51 for my $i (0..$#{$source->{inputs}}) {
52 my $v = $cgi->param($n.'_i'.$i);
53 unless ($v) {
54 $gcgi->err("Source specifier '".$source->{inputs}->[$i]->{label}."' not filled.");
55 next;
57 my $ii = $i + 1;
58 $u =~ s/%$ii/$v/g;
60 } else {
61 $u = $cgi->param($n.'_url');
62 $u or $gcgi->err("Source URL not specified");
64 $cgi->param('url', $u);
67 my $proj = Girocco::Project->ghost($name, $mirror);
68 if ($proj->cgi_fill($gcgi)) {
69 if ($mirror) {
70 $| = 1;
71 unless ($Girocco::Config::mirror) {
72 $gcgi->err("Mirroring mode is not enabled at this site.");
73 exit;
75 $proj->premirror;
76 print "<p>Initiated mirroring of ".$cgi->param('url')." to $Girocco::Config::name project ".
77 "<a href=\"/w/$name.git\">$name</a>.git:</p>\n";
78 $proj->clone;
79 print "<pre>\n";
81 open LOG, $proj->{path}.'/.clonelog' or die "clonelog: $!";
82 tailf: for (;;) {
83 my $curpos;
84 for ($curpos = tell(LOG); <LOG>; $curpos = tell(LOG)) {
85 chomp;
86 $_ eq '@OVER@' and last tailf;
87 print "$_\n";
89 sleep 1;
90 seek(LOG, $curpos, 0); # seek to where we had been
92 close LOG;
94 print "</pre>\n";
96 } else {
97 unless ($Girocco::Config::push) {
98 $gcgi->err("Push mode is not enabled at this site.");
99 exit;
101 $proj->conjure;
102 print <<EOT;
104 Project <a href="/w/$name.git">$name</a> successfuly set up.</p>
106 print "<p>The push URL for the project is <tt>$Girocco::Config::pushurl/$name.git</tt>.</p>";
107 print "<p>The read-only URL for the project is <tt>" .
108 join("/$name.git</tt>, <tt>", $Girocco::Config::gitpullurl, $Girocco::Config::httppullurl) .
109 "/$name.git</tt>.</p>" if $Girocco::Config::gitpullurl or $Girocco::Config::httppullurl;
110 my $regnotice = '';
111 if ($Girocco::Config::manage_users) {
112 $regnotice = <<EOT;
113 Everyone who wants to push must <a href="reguser.cgi">register himself as a user</a> first.
114 (One user can have push access to multiple projects and multiple users can have push access to one project.)
117 print <<EOT;
118 <p>You can <a href="editproj.cgi?name=$name">assign users</a> now
119 - don't forget to assign yourself as a user as well if you want to push!
120 $regnotice
121 </p>
122 <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.</p>
123 <p>You may experience permission problems if you try to push right now.
124 If so, that should get fixed automagically in few minutes, please be patient.</p>
125 <p>Enjoy yourself, and have a lot of fun!</p>
128 exit;
132 my $mirror_mode = {
133 name => 'mirror',
134 desc => 'our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates',
135 pwpurp => 'mirroring URL'
137 my $push_mode = {
138 name => 'push',
139 desc => 'registered users with appropriate permissions will be able to push to the repository',
140 pwpurp => 'list of users allowed to push'
143 my $me = $Girocco::Config::mirror ? $mirror_mode : undef;
144 my $pe = $Girocco::Config::push ? $push_mode : undef;
145 if ($me and $pe) {
146 print <<EOT;
147 <p>At this site, you can host a project in one of two modes: $me->{name} mode and $pe->{name} mode.
148 In the <b>$me->{name} mode</b>, $me->{desc}.
149 In the <b>$pe->{name} mode</b>, $pe->{desc}.
150 You currently cannot switch freely between those two modes;
151 if you want to switch from mirroring to push mode, just delete and recreate
152 the project. If you want to switch the other way, please contact the administrator.</p>
154 } else {
155 my $mode = $me ? $me : $pe;
156 print "<p>This site will host your project in a <b>$mode->{name} mode</b>: $mode->{desc}.</p>\n";
159 my @pwpurp = ();
160 push @pwpurp, $me->{pwpurp} if $me;
161 push @pwpurp, $pe->{pwpurp} if $pe;
162 my $pwpurp = join(', ', @pwpurp);
164 print <<EOT;
165 <p>You will need the admin password to adjust the project settings later
166 ($pwpurp, project description, ...).</p>
169 unless ($name =~ m#/#) {
170 print <<EOT;
171 <p>Note that if your project is a <strong>fork of an existing project</strong>
172 (this does not mean anything socially bad), please instead go to the project's
173 gitweb page and click the 'fork' link in the top bar. This way, all of us
174 will save bandwidth and more importantly, your project will be properly categorized.
176 $me and print <<EOT;
177 If your project is a fork but the existing project is not registered here yet, please
178 consider registering it first; you do not have to be involved in the project
179 in order to register it here as a mirror.</p>
181 } else {
182 my $xname = $name; $xname =~ s#/$#.git#; #
183 my ($pushnote1, $pushnote2);
184 $pushnote1 = " and you will need to push only the data <em>you</em> created, not the whole project" if $pe;
185 $pushnote2 = "(That will be done automagically, you do not need to specify any extra arguments during the push.)" if $pe;
186 print <<EOT;
187 <p>Great, your project will be created as a subproject of the '$xname' project.
188 This means that it will be properly categorized$pushnote1. $pushnote2</p>
192 my $modechooser;
193 my $mirrorentry = '';
194 if ($me) {
195 $mirrorentry = '<tr id="mirror_url"><td class="formlabel">Mirror source:</td><td>';
196 if (!$Girocco::Config::mirror_sources) {
197 $mirrorentry .= '<input type="text" name="url" />';
198 } else {
199 $mirrorentry .= "<table>"."\n";
200 my $checked = ' checked=checked';
201 foreach my $source (@$Girocco::Config::mirror_sources) {
202 my $n = $source->{label};
203 $mirrorentry .= '<tr><td class="formlabel">';
204 $mirrorentry .= '<p><input type="radio" name="source" value="'.$n.'" '.$checked.' />';
205 $mirrorentry .= $n;
206 $mirrorentry .= '</p></td><td>';
207 $checked = '';
208 if ($source->{desc}) {
209 $mirrorentry .= '<p>';
210 $source->{link} and $mirrorentry .= '<a href="'.$source->{link}.'">';
211 $mirrorentry .= $source->{desc};
212 $source->{link} and $mirrorentry .= '</a>';
213 $mirrorentry .= '</p>';
215 if (!$source->{inputs}) {
216 $mirrorentry .= '<p>URL: <input type="text" name="'.$n.'_url" /></p>';
217 } else {
218 $mirrorentry .= '<p>';
219 my $i = 0;
220 foreach my $input (@{$source->{inputs}}) {
221 $mirrorentry .= $input->{label};
222 $mirrorentry .= ' <input type="text" name="'.$n.'_i'.$i.'" />';
223 $mirrorentry .= $input->{suffix} if $input->{suffix};
224 $mirrorentry .= '&nbsp; &nbsp;';
225 } continue { $i++; }
226 $mirrorentry .= '</p>';
228 $mirrorentry .= '</td></tr>'."\n";
230 $mirrorentry .= "</table>";
232 $mirrorentry .= '</td></tr>';
234 if ($me and $pe) {
235 $modechooser = <<EOT;
236 <tr><td class="formlabel">Hosting mode:</td><td><p>
237 <input type="radio" name="mode" value="mirror" id="mirror_radio" checked="checked" />Mirror mode<br />
238 <input type="radio" name="mode" value="push" id="push_radio" />Push mode
239 </p></td></tr>
241 } else {
242 $modechooser = '<input type="hidden" name="mode" value="'.($me ? $me->{name} : $pe->{name}).'" />';
245 print <<EOT;
246 $Girocco::Config::legalese
247 <form method="post">
248 <table class="form">
249 <tr><td class="formlabel">Project name:</td><td><input type="text" name="name" value="$name" />.git</td></tr>
250 <tr><td class="formlabel">Admin password (twice):</td><td><input type="password" name="pwd" /><br /><input type="password" name="pwd2" /></td></tr>
251 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" /></td></tr>
252 $modechooser
253 $mirrorentry
254 <tr><td class="formlabel">Homepage URL:</td><td><input type="text" name="hp" /></td></tr>
255 <tr><td class="formlabel">Short description:</td><td><input type="text" name="desc" size="80" /></td></tr>
256 <tr><td class="formlabel">README (HTML, lt 8kb):</td><td><textarea name="README" rows="5" cols="80"></textarea></td></tr>
257 <tr style="display:none"><td>Anti-captcha (leave empty!):</td><td><input type="text" name="mail" /></td></tr>
258 <tr><td></td><td><input type="submit" name="y0" value="Register" /></td></tr>
259 </table>
260 </form>