Big module renaming: Git::RepoCGI -> Girocco::*
[girocco.git] / cgi / regproj.cgi
blob066968b5e836198271e6ce177b1ee16d65fa94d6
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;
11 my $repo = Girocco::CGI->new('Project Registration');
12 my $cgi = $repo->cgi;
14 my $name = $cgi->param('name');
15 $name ||= '';
17 if ($cgi->param('mail')) {
18 print "<p>Go away, bot.</p>";
19 exit;
22 if ($cgi->param('mode')) {
23 # submitted, let's see
24 # FIXME: racy, do a lock
25 my $name = $repo->wparam('name');
26 valid_proj_name($name)
27 and Girocco::Project::does_exist($name)
28 and $repo->err("Project with the name '$name' already exists.");
29 $name =~ /\.git$/
30 and $repo->err("Project name should not end with <tt>.git</tt> - I'll add that automagically.");
32 my $mirror = $cgi->param('mode') eq 'mirror';
33 my $proj = Girocco::Project->ghost($name, $mirror);
34 if ($proj->cgi_fill($repo)) {
35 if ($mirror) {
36 $Girocco::Config::mirror or $repo->err("Mirroring mode is not enabled at this site.");
37 $proj->premirror;
38 print "<p>Initiated mirroring. You will be notified about the result by mail.</p>\n";
39 } else {
40 $Girocco::Config::push or $repo->err("Push mode is not enabled at this site.");
41 $proj->conjure;
42 print <<EOT;
43 <p>
44 Project <a href="/w/$name.git">$name</a> successfuly set up.</p>
45 EOT
46 print "<p>The push URL for the project is <tt>$Girocco::Config::pushurl/$name.git</tt>.</p>";
47 print "<p>The read-only URL for the project is <tt>" .
48 join("/$name.git</tt>, <tt>", $Girocco::Config::gitpullurl, $Girocco::Config::httppullurl) .
49 "/$name.git</tt>.</p>" if $Girocco::Config::gitpullurl or $Girocco::Config::httppullurl;
50 print <<EOT;
51 <p>You can <a href="editproj.cgi?name=$name">assign users</a> now (use project name (without <tt>.git</tt>) as username, admin password as password)
52 - don't forget to assign yourself as a user as well if you want to push!
53 Everyone who wants to push must <a href="reguser.cgi">register himself as a user</a> first.
54 (One user can have push access to multiple projects and multiple users can have push access to one project.)
55 </p>
56 <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>
57 <p>You may experience permission problems if you try to push right now.
58 If so, that should get fixed automagically in few minutes, please be patient.</p>
59 <p>Enjoy yourself!</p>
60 EOT
62 exit;
66 my $mirror_mode = {
67 name => 'mirror',
68 desc => 'our dedicated git monkeys will check another repository at a given URL every hour and mirror any new updates',
69 pwpurp => 'mirroring URL'
71 my $push_mode = {
72 name => 'push',
73 desc => 'registered users with appropriate permissions will be able to push to the repository',
74 pwpurp => 'list of users allowed to push'
77 my $me = $Girocco::Config::mirror ? $mirror_mode : undef;
78 my ($me, $pe) = $Girocco::Config::push ? $push_mode : undef;
79 if ($me and $pe) {
80 print <<EOT;
81 <p>At this site, you can host a project in one of two modes: $me->{name} mode and $pe->{name} mode.
82 In the <b>$me->{name} mode</b>, $me->{desc}.
83 In the <b>$pe->{name} mode</b>, $pe->{desc}.
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 EOT
88 } else {
89 my $mode = $me ? $me : $pe;
90 print "<p>This site will host your project in a <b>$mode->{name} mode</b>: $mode->{desc}.</p>\n";
93 my @pwpurp = ();
94 push @pwpurp, $me->{pwpurp} if $me;
95 push @pwpurp, $pe->{pwpurp} if $pe;
96 my $pwpurp = join(', ', @pwpurp);
98 print <<EOT;
99 <p>You will need the admin password to adjust the project settings later
100 ($pwpurp, project description, ...).
101 Use the project name (without <tt>.git</tt>) as the username when asked by the browser.</p>
104 unless ($name =~ m#/#) {
105 print <<EOT;
106 <p>Note that if your project is a <strong>fork of an existing project</strong>
107 (this does not mean anything socially bad), please instead go to the project's
108 gitweb page and click the 'fork' link in the top bar. This way, all of us
109 will save bandwidth and more importantly, your project will be properly categorized.
111 $me and print <<EOT;
112 If your project is a fork but the existing project is not registered here yet, please
113 consider registering it first; you do not have to be involved in the project
114 in order to register it here as a mirror.</p>
116 } else {
117 my $xname = $name; $xname =~ s#/$#.git#; #
118 my ($pushnote1, $pushnote2);
119 $pushnote1 = " and you will need to push only the data <em>you</em> created, not the whole project" if $pe;
120 $pushnote2 = "(That will be done automagically, you do not need to specify any extra arguments during the push.)" if $pe;
121 print <<EOT;
122 <p>Great, your project will be created as a subproject of the '$xname' project.
123 This means that it will be properly categorized$pushnote1. $pushnote2</p>
127 my $modechooser;
128 my $mirrorentry = 'Repository URL: <input type="text" name="url" />';
129 if ($me and $pe) {
130 $modechooser = <<EOT;
131 <p>Hosting mode:</p><ul>
132 <li><input type="radio" name="mode" value="mirror" />Mirror mode. $mirrorentry</li>
133 <li><input type="radio" name="mode" value="push" />Push mode.</li></ul>
135 } else {
136 $modechooser = '<input type="hidden" name="mode" value="'.($me ? $me->{name} : $pe->{name}).'">';
137 $me and $modechooser .= "<p>$mirrorentry</p>";
140 print <<EOT;
141 <p>By submitting this form, you are confirming that the repository contains only free software
142 and redistributing it does not violate any law of $Girocco::Config::jurisdiction. Read <a href="/about.html">more details</a>
143 about the hosting and terms and conditions.</p>
144 <p>Have fun!</p>
145 <form method="post">
146 <p>Project name (w/o the .git suffix): <input type="text" name="name" value="$name" /></p>
147 <p>Admin password: <input type="password" name="pwd" /></p>
148 <p>Admin password (retype): <input type="password" name="pwd2" /></p>
149 <p>E-mail contact: <input type="text" name="email" /></p>
150 $modechooser
151 <p>Description: <input type="text" name="desc" /></p>
152 <p>Homepage URL: <input type="text" name="hp" /></p>
153 <p>README (HTML, lt 8kb): <textarea name="README" rows="5" cols="80"></textarea></p>
154 <p style="display:none">Anti-captcha (leave empty!): <input type="text" name="mail" /></p>
155 <p><input type="submit" name="y0" value="Register" /></p>
156 </form>