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