Add instructions on how to import your project
[girocco/test-forks.git] / cgi / regproj.cgi
blob0b45264ea4877d292233f0bc7b8f01f3a7fd1a19
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 if (lc($cgi->param('mail')) ne lc('sun')) {
36 print "<p>Sorry, invalid captcha check.</p>";
37 exit;
40 my $mirror = $cgi->param('mode') eq 'mirror';
42 if ($mirror and $Girocco::Config::mirror_sources and not $cgi->param('url')) {
43 my $src = $cgi->param('source'); $src ||= '';
44 my $source; $src and $source = (grep { $_->{label} eq $src } @$Girocco::Config::mirror_sources)[0];
45 $source or $gcgi->err("Invalid or no mirror source $src specified");
47 my $n = $source->{label};
48 my $u = $source->{url};
49 if ($source->{inputs}) {
50 for my $i (0..$#{$source->{inputs}}) {
51 my $v = $cgi->param($n.'_i'.$i);
52 unless ($v) {
53 $gcgi->err("Source specifier '".$source->{inputs}->[$i]->{label}."' not filled.");
54 next;
56 my $ii = $i + 1;
57 $u =~ s/%$ii/$v/g;
59 } else {
60 $u = $cgi->param($n.'_url');
61 $u or $gcgi->err("Source URL not specified");
63 $cgi->param('url', $u);
66 my $proj = Girocco::Project->ghost($name, $mirror);
67 if ($proj->cgi_fill($gcgi)) {
68 if ($mirror) {
69 unless ($Girocco::Config::mirror) {
70 $gcgi->err("Mirroring mode is not enabled at this site.");
71 exit;
73 $proj->premirror;
74 print "<p>Please <a href=\"mirrorproj.cgi?name=$name\">pass onwards</a>.</p>\n";
75 print "<script language=\"javascript\">document.location='mirrorproj.cgi?name=$name'</script>\n";
77 } else {
78 unless ($Girocco::Config::push) {
79 $gcgi->err("Push mode is not enabled at this site.");
80 exit;
82 $proj->conjure;
83 print <<EOT;
84 <p>
85 Project <a href="$Girocco::Config::gitweburl/$name.git">$name</a> successfuly set up.</p>
86 EOT
87 print "<p>The push URL for the project is <tt>$Girocco::Config::pushurl/$name.git</tt>.</p>";
88 print "<p>The read-only URL for the project is <tt>" .
89 join("/$name.git</tt>, <tt>", $Girocco::Config::gitpullurl, $Girocco::Config::httppullurl) .
90 "/$name.git</tt>.</p>" if $Girocco::Config::gitpullurl or $Girocco::Config::httppullurl;
91 my $regnotice = '';
92 if ($Girocco::Config::manage_users) {
93 $regnotice = <<EOT;
94 Everyone who wants to push must <a href="reguser.cgi">register himself as a user</a> first.
95 (One user can have push access to multiple projects and multiple users can have push access to one project.)
96 EOT
98 print <<EOT;
99 <p>You can <a href="editproj.cgi?name=$name">assign users</a> now
100 - don't forget to assign yourself as a user as well if you want to push!
101 $regnotice
102 </p>
103 <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.
104 To import a new project, the procedure is roughly as follows:
105 <pre>
106 $ git init
107 $ git add
108 $ git commit
109 $ git remote add origin $Girocco::Config::pushurl/$name.git
110 $ git push --all origin
111 </pre>
112 </p>
113 <p>You may experience permission problems if you try to push right now.
114 If so, that should get fixed automagically in few minutes, please be patient.</p>
115 <p>Enjoy yourself, and have a lot of fun!</p>
118 exit;
122 my $mirror_mode = {
123 name => 'mirror',
124 desc => 'our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates',
125 pwpurp => 'mirroring URL'
127 my $push_mode = {
128 name => 'push',
129 desc => 'registered users with appropriate permissions will be able to push to the repository',
130 pwpurp => 'list of users allowed to push'
133 my $me = $Girocco::Config::mirror ? $mirror_mode : undef;
134 my $pe = $Girocco::Config::push ? $push_mode : undef;
135 if ($me and $pe) {
136 print <<EOT;
137 <p>At this site, you can host a project in one of two modes: $me->{name} mode and $pe->{name} mode.
138 In the <b>$me->{name} mode</b>, $me->{desc}.
139 In the <b>$pe->{name} mode</b>, $pe->{desc}.
140 You currently cannot switch freely between those two modes;
141 if you want to switch from mirroring to push mode, just delete and recreate
142 the project. If you want to switch the other way, please contact the administrator.</p>
144 } else {
145 my $mode = $me ? $me : $pe;
146 print "<p>This site will host your project in a <b>$mode->{name} mode</b>: $mode->{desc}.</p>\n";
149 my @pwpurp = ();
150 push @pwpurp, $me->{pwpurp} if $me;
151 push @pwpurp, $pe->{pwpurp} if $pe;
152 my $pwpurp = join(', ', @pwpurp);
154 if ($Girocco::Config::project_passwords) {
155 print <<EOT;
156 <p>You will need the admin password to adjust the project settings later
157 ($pwpurp, project description, ...).</p>
161 unless ($name =~ m#/#) {
162 print <<EOT;
163 <p>Note that if your project is a <strong>fork of an existing project</strong>
164 (this does not mean anything socially bad), please instead go to the project's
165 gitweb page and click the 'fork' link in the top bar. This way, all of us
166 will save bandwidth and more importantly, your project will be properly categorized.
168 $me and print <<EOT;
169 If your project is a fork but the existing project is not registered here yet, please
170 consider registering it first; you do not have to be involved in the project
171 in order to register it here as a mirror.</p>
173 } else {
174 my $xname = $name; $xname =~ s#/$#.git#; #
175 my ($pushnote1, $pushnote2);
176 if ($pe) {
177 $pushnote1 = " and you will need to push only the data <em>you</em> created, not the whole project";
178 $pushnote2 = <<EOT;
179 (That will be done automagically, you do not need to specify any extra arguments during the push.
182 print <<EOT;
183 <p>Great, your project will be created as a subproject of the '$xname' project.
184 This means that it will be properly categorized$pushnote1. $pushnote2</p>
188 my $modechooser;
189 my $mirrorentry = '';
190 if ($me) {
191 $mirrorentry = '<tr id="mirror_url"><td class="formlabel">Mirror source:</td><td>';
192 if (!$Girocco::Config::mirror_sources) {
193 $mirrorentry .= '<input type="text" name="url" />';
194 } else {
195 $mirrorentry .= "<table>"."\n";
196 my $checked = ' checked=checked';
197 foreach my $source (@$Girocco::Config::mirror_sources) {
198 my $n = $source->{label};
199 $mirrorentry .= '<tr><td class="formlabel">';
200 $mirrorentry .= '<p><input type="radio" name="source" value="'.$n.'" '.$checked.' />';
201 $mirrorentry .= $n;
202 $mirrorentry .= '</p></td><td>';
203 $checked = '';
204 if ($source->{desc}) {
205 $mirrorentry .= '<p>';
206 $source->{link} and $mirrorentry .= '<a href="'.$source->{link}.'">';
207 $mirrorentry .= $source->{desc};
208 $source->{link} and $mirrorentry .= '</a>';
209 $mirrorentry .= '</p>';
211 if (!$source->{inputs}) {
212 $mirrorentry .= '<p>URL: <input type="text" name="'.$n.'_url" /></p>';
213 } else {
214 $mirrorentry .= '<p>';
215 my $i = 0;
216 foreach my $input (@{$source->{inputs}}) {
217 $mirrorentry .= $input->{label};
218 my ($l, $v) = ($n.'_i'.$i, '');
219 if ($cgi->param($l)) {
220 $v = ' value="'.html_esc($cgi->param($l)).'"';
222 $mirrorentry .= ' <input type="text" name="'.$l.'"'.$v.' />';
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 my $forkentry = '';
246 if ($name =~ m#/#) {
247 $name =~ s#^(.*)/##;
248 $forkentry = '<input type="hidden" name="fork" value="'.$1.'" />'.$1.'/'
251 print <<EOT;
252 $Girocco::Config::legalese
253 <form method="post">
254 <table class="form">
255 <tr><td class="formlabel">Project name:</td><td>$forkentry<input type="text" name="name" value="$name" />.git</td></tr>
257 if ($Girocco::Config::project_passwords) {
258 print <<EOT;
259 <tr><td class="formlabel">Admin password (twice):</td><td><input type="password" name="pwd" /><br /><input type="password" name="pwd2" /></td></tr>
262 if ($Girocco::Config::project_owners eq 'email') {
263 print <<EOT;
264 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" /></td></tr>
267 print $modechooser;
268 print $mirrorentry;
270 $gcgi->print_form_fields($Girocco::Project::metadata_fields, undef, @Girocco::Config::project_fields);
272 print <<EOT;
275 print <<EOT;
276 <tr><td class="formlabel">Anti-captcha - please<br />enter name of our nearest star:</td><td><input type="text" name="mail" /></td></tr>
277 <tr><td></td><td><input type="submit" name="y0" value="Register" /></td></tr>
278 </table>
279 </form>