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