regproj: improve push creation success output
[girocco/ztw.git] / cgi / regproj.cgi
blobd64ba8bbc78391dddee66fb8d93d85f508519d2d
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib qw(/home/repo/repomgr/cgi);
9 use Git::RepoCGI;
11 my $captcha_question = "What is the name of Earth's nearest star?";
12 my $captcha_answer = 'sun';
14 my $repo = Git::RepoCGI->new('Project Registration');
15 my $name = $repo->sparam('name');
17 if ($repo->sparam('mode')) {
18 # we permit the name to include '.git' suffix, but strip it off
19 my $name = $repo->wparam('name');
20 $name = $1 if $name =~ /(.*)\.git$/;
22 # for local forks, the name must be prefixed with origin
23 my $origin = $repo->wparam('origin');
24 $name = "$origin/$name" if $origin;
26 # FIXME: racy, do a lock
27 valid_proj_name($name)
28 and Git::RepoCGI::Project::does_exist($name)
29 and $repo->err("Project with the name '$name' already exists.");
31 if (lc($repo->sparam('mail')) ne lc('sun')) {
32 print "<p>Sorry, invalid captcha check.</p>";
33 exit;
36 my $mirror = $repo->sparam('mode') eq 'mirror';
37 my $proj = Git::RepoCGI::Project->ghost($name, $mirror);
38 if ($proj->cgi_fill($repo)) {
39 if ($mirror) {
40 $proj->premirror;
41 print "<p>Initiated mirroring. You will be notified about the result by mail.</p>\n";
42 } else {
43 $proj->conjure;
44 print <<EOT;
45 <p>The project <a href="/w/$name.git">$name</a> was created successfuly.</p>
46 <p>The push URL for your project is <tt>git+ssh://repo.or.cz/srv/git/$name.git</tt>.</p>
48 <p>To push changes, you must add yourself as a user first!</p> You must
49 <a href="reguser.cgi">register as a user</a> and provide a SSH key to
50 use for authenticating access to the server. A user may be given push
51 access to many projects, so other users may be given push access to your
52 project. You can <a href="editproj.cgi?name=$name">assign users</a>
53 now, supplying the admin password when submitting your changes.</p>
55 <p>You cannot clone the repository until you push from an existing local
56 repository to create one or more branch.</p>
58 <p>If you experience permission problems trying to push, make sure that
59 your user account has permission. A server script fixes some problems
60 periodically; if you get errors immediately after creating your project,
61 you may need to wait for its magic.</p>
63 <p>Enjoy your new project!</p>
64 EOT
66 exit;
70 my $origin = $repo->wparam('origin');
71 # if not specified, derive the project fork origin from its name
72 if (!$origin && $name =~ m{^(.*)/(.*?)(\.git)?$}) {
73 $origin = $1;
74 # user should edit only the final portion of specified name.
75 $name = $2;
77 $origin ||= '';
79 print <<EOT;
80 <p>Here you can register a project.
81 It can be hosted in two modes: mirror mode and push mode.
82 In the <b>mirror mode</b>, our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates.
83 In the <b>push mode</b>, registered users with appropriate permissions will be able to push to the repository.
84 You currently cannot switch freely between those two modes;
85 if you want to switch from mirroring to push mode, just delete and recreate
86 the project. If you want to switch the other way, please contact the administrator.</p>
87 <p>You will need the admin password to adjust the project settings later
88 (mirroring URL, list of users allowed to push, project description, ...).
89 Use the project name (without <tt>.git</tt>) as the username when asked by the browser.</p>
90 EOT
92 unless ($origin) {
93 print <<EOT;
94 <p>Note that if your project is a <strong>fork of an existing project</strong>
95 (this does not mean anything socially bad), please instead go to the project's
96 gitweb page and click the 'fork' link in the top bar. This way, all of us
97 will save bandwidth and more importantly, your project will be properly categorized.
98 If your project is a fork but the existing project is not registered here yet, please
99 consider registering it first; you do not have to be involved in the project
100 in order to register it here as a mirror.</p>
102 } else {
103 print <<EOT;
104 <p>Great, your project will be created as a subproject of the '$origin.git' project.
105 This means that it will be properly categorized and you will need to push only
106 the data <em>you</em> created, not the whole project. (That will be done automagically,
107 you do not need to specify any extra arguments during the push.)</p>
108 <p>Please note that you should not use <code>push --mirror</code> on your project!
109 If you also have push permissions to the forkee, you will erase its refs hierarchy
110 by that operation; we are working on the proper fix for that.</p>
113 print <<EOT;
114 <p>By submitting this form, you are confirming that the repository contains only free software
115 and redistributing it does not violate any law of Czech Republic. Read <a href="/about.html">more details</a>
116 about the hosting and terms and conditions.</p>
117 <p>Have fun!</p>
118 <form method="post">
119 <input type="hidden" name="origin" value="$origin" />
120 <p>Project name: <b>$origin/</b><input type="text" name="name" value="$name" /></p>
121 <p>Admin password: <input type="password" name="pwd" /></p>
122 <p>Admin password (retype): <input type="password" name="pwd2" /></p>
123 <p>E-mail contact: <input type="text" name="email" /></p>
126 if ($origin) {
127 print '<input type="hidden" name="mode" value="push" />';
128 } else {
129 print <<EOT;
130 <p>Hosting mode:</p><ul>
131 <li><input type="radio" name="mode" value="mirror" />Mirror mode. Repository URL: <input type="text" name="url" /></li>
132 <li><input type="radio" name="mode" value="push" />Push mode.</li></ul>
136 print <<EOT;
137 <p>Description: <input type="text" name="desc" /></p>
138 <p>Homepage URL: <input type="text" name="hp" /></p>
139 <p>README (HTML, lt 8kb): <textarea name="README" rows="5" cols="80"></textarea></p>
140 <p>$captcha_question <input type="text" name="mail" /></p>
141 <p><input type="submit" name="y0" value="Register" /></p>
142 </form>