Use Config.pm settings to avoid hard-coding /srv/git
[girocco.git] / cgi / regproj.cgi
blob480e5f3f30fa41627b5305bd3619ea6823578e19
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')) {
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=\"mirrorproj.cgi?name=$name\">pass onwards</a>.</p>\n";
78 print "<script language=\"javascript\">document.location='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>
88 Project <a href="$Girocco::Config::gitweburl/$name.git">$name</a> successfully set up.</p>
89 EOT
90 print "<p>The push URL for the project is <tt>$Girocco::Config::pushurl/$name.git</tt>.</p>";
91 print "<p>The read-only URL for the project is <tt>" .
92 join("/$name.git</tt>, <tt>", $Girocco::Config::gitpullurl, $Girocco::Config::httppullurl) .
93 "/$name.git</tt>.</p>" if $Girocco::Config::gitpullurl or $Girocco::Config::httppullurl;
94 my $regnotice = '';
95 if ($Girocco::Config::manage_users) {
96 $regnotice = <<EOT;
97 Everyone who wants to push must <a href="reguser.cgi">register himself as a user</a> first.
98 (One user can have push access to multiple projects and multiple users can have push access to one project.)
99 EOT
101 print <<EOT;
102 <p>You can <a href="editproj.cgi?name=$name">assign users</a> now
103 - don't forget to assign yourself as a user as well if you want to push!
104 $regnotice
105 </p>
106 <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.
107 To import a new project, the procedure is roughly as follows:
108 <pre>
109 \$ git init
110 \$ git add
111 \$ git commit
112 \$ git remote add origin $Girocco::Config::pushurl/$name.git
113 \$ git push --all origin
114 </pre>
115 </p>
116 <p>Enjoy yourself, and have a lot of fun!</p>
119 exit;
123 my $mirror_mode = {
124 name => 'mirror',
125 desc => 'our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates',
126 pwpurp => 'mirroring URL'
128 my $push_mode = {
129 name => 'push',
130 desc => 'registered users with appropriate permissions will be able to push to the repository',
131 pwpurp => 'list of users allowed to push'
134 my $me = $Girocco::Config::mirror ? $mirror_mode : undef;
135 my $pe = $Girocco::Config::push ? $push_mode : undef;
136 if ($me and $pe) {
137 print <<EOT;
138 <p>At this site, you can host a project in one of two modes: $me->{name} mode and $pe->{name} mode.
139 In the <b>$me->{name} mode</b>, $me->{desc}.
140 In the <b>$pe->{name} mode</b>, $pe->{desc}.
141 You currently cannot switch freely between those two modes;
142 if you want to switch from mirroring to push mode, just delete and recreate
143 the project. If you want to switch the other way, please contact the administrator.</p>
145 } else {
146 my $mode = $me ? $me : $pe;
147 print "<p>This site will host your project in a <b>$mode->{name} mode</b>: $mode->{desc}.</p>\n";
150 my @pwpurp = ();
151 push @pwpurp, $me->{pwpurp} if $me;
152 push @pwpurp, $pe->{pwpurp} if $pe;
153 my $pwpurp = join(', ', @pwpurp);
155 if ($Girocco::Config::project_passwords) {
156 print <<EOT;
157 <p>You will need the admin password to adjust the project settings later
158 ($pwpurp, project description, ...).</p>
162 unless ($name =~ m#/#) {
163 print <<EOT;
164 <p>Note that if your project is a <strong>fork of an existing project</strong>
165 (this does not mean anything socially bad), please instead go to the project's
166 gitweb page and click the 'fork' link in the top bar. This way, all of us
167 will save bandwidth and more importantly, your project will be properly categorized.
169 $me and print <<EOT;
170 If your project is a fork but the existing project is not registered here yet, please
171 consider registering it first; you do not have to be involved in the project
172 in order to register it here as a mirror.</p>
174 } else {
175 my $xname = $name; $xname =~ s#/$#.git#; #
176 my ($pushnote1, $pushnote2);
177 if ($pe) {
178 $pushnote1 = " and you will need to push only the data <em>you</em> created, not the whole project";
179 $pushnote2 = <<EOT;
180 (That will be done automagically, you do not need to specify any extra arguments during the push.
183 print <<EOT;
184 <p>Great, your project will be created as a subproject of the '$xname' project.
185 This means that it will be properly categorized$pushnote1. $pushnote2</p>
189 my $modechooser;
190 my $mirrorentry = '';
191 if ($me) {
192 $mirrorentry = '<tr id="mirror_url"><td class="formlabel" style="vertical-align:middle">Mirror source:</td><td>';
193 if (!$Girocco::Config::mirror_sources) {
194 $mirrorentry .= '<input type="text" name="url" />';
195 } else {
196 $mirrorentry .= "<table>"."\n";
197 my $checked = ' checked=checked';
198 foreach my $source (@$Girocco::Config::mirror_sources) {
199 my $n = $source->{label};
200 $mirrorentry .= '<tr><td class="formlabel">';
201 $mirrorentry .= '<p><input type="radio" name="source" value="'.$n.'" '.$checked.' />';
202 $mirrorentry .= $n;
203 $mirrorentry .= '</p></td><td>';
204 $checked = '';
205 if ($source->{desc}) {
206 $mirrorentry .= '<p>';
207 $source->{link} and $mirrorentry .= '<a href="'.$source->{link}.'">';
208 $mirrorentry .= $source->{desc};
209 $source->{link} and $mirrorentry .= '</a>';
210 $mirrorentry .= '</p>';
212 if (!$source->{inputs}) {
213 $mirrorentry .= '<p>URL: <input type="text" name="'.$n.'_url" /></p>';
214 } else {
215 $mirrorentry .= '<p>';
216 my $i = 0;
217 foreach my $input (@{$source->{inputs}}) {
218 $mirrorentry .= $input->{label};
219 my ($l, $v) = ($n.'_i'.$i, '');
220 if ($cgi->param($l)) {
221 $v = ' value="'.html_esc($cgi->param($l)).'"';
223 $mirrorentry .= ' <input type="text" name="'.$l.'"'.$v.' />';
224 $mirrorentry .= $input->{suffix} if $input->{suffix};
225 $mirrorentry .= '&nbsp; &nbsp;';
226 } continue { $i++; }
227 $mirrorentry .= '</p>';
229 $mirrorentry .= '</td></tr>'."\n";
231 $mirrorentry .= "</table>";
233 $mirrorentry .= '</td></tr>';
235 if ($me and $pe) {
236 $modechooser = <<EOT;
237 <tr><td class="formlabel" style="vertical-align:middle">Hosting mode:</td><td><p>
238 <input type="radio" name="mode" value="mirror" id="mirror_radio" checked="checked" />Mirror mode<br />
239 <input type="radio" name="mode" value="push" id="push_radio" />Push mode
240 </p></td></tr>
242 } else {
243 $modechooser = '<input type="hidden" name="mode" value="'.($me ? $me->{name} : $pe->{name}).'" />';
246 my $forkentry = '';
247 if ($name =~ m#/#) {
248 $name =~ s#^(.*)/##;
249 $forkentry = '<input type="hidden" name="fork" value="'.$1.'" /><span class="formdata" style="padding-left:0.5ex">'.$1.'/</span>';
252 print <<EOT;
253 $Girocco::Config::legalese
254 <form method="post">
255 <table class="form">
256 <tr><td class="formlabel">Project name:</td>
257 <td>$forkentry<input type="text" name="name" value="$name" /><span class="formdata" style="padding-left:0">.git</span></td></tr>
259 if ($Girocco::Config::project_passwords) {
260 print <<EOT;
261 <tr><td class="formlabel">Admin password (twice):</td><td><input type="password" name="pwd" /><br /><input type="password" name="pwd2" /></td></tr>
264 if ($Girocco::Config::project_owners eq 'email') {
265 print <<EOT;
266 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" /></td></tr>
269 print $modechooser;
270 print $mirrorentry;
272 $gcgi->print_form_fields($Girocco::Project::metadata_fields, undef, @Girocco::Config::project_fields);
274 print <<EOT;
277 print <<EOT;
278 <tr><td class="formlabel" style="line-height:inherit">Anti-captcha - please<br />enter name of our nearest star:</td>
279 <td style="vertical-align:middle"><input type="text" name="mail" /></td></tr>
280 <tr><td></td><td><input type="submit" name="y0" value="Register" /></td></tr>
281 </table>
282 </form>