Merge branch 'wip/doc-migration' into rorcz
[girocco.git] / cgi / delproj.cgi
blobccfc0ce72782cbf0d1bf2b8e1f3126f23f16ddcd
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib "__BASEDIR__";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Project;
12 use Girocco::Util;
14 my $gcgi = Girocco::CGI->new('Project Removal');
15 my $cgi = $gcgi->cgi;
17 my $name = $cgi->param('name');
19 unless (defined $name) {
20 print "<p>I need the project name as an argument now.</p>\n";
21 exit;
24 if (!Girocco::Project::does_exist($name,1) && !Girocco::Project::valid_name($name)) {
25 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
26 exit;
29 if (!Girocco::Project::does_exist($name,1)) {
30 print "<p>Sorry but this project does not exist. Now, how did you <em>get</em> here?!</p>\n";
31 exit;
34 if (my $romsg=check_readonly(1)) {
35 print "<p>$romsg</p>\n";
36 exit;
39 my $proj = Girocco::Project->load($name);
40 if (!$proj) {
41 print "<p>not found project $name, that's really weird!</p>\n";
42 exit;
44 my $escname = $name;
45 $escname =~ s/[+]/%2B/g;
46 $proj->{cpwd} = $cgi->param('cpwd');
47 my $isempty = !$proj->{mirror} && $proj->is_empty;
49 if ($proj->has_forks()) {
50 print "<p>Sorry but this project has forks associated. Such projects cannot be removed. Please tell the administrator if you really want to.</p>\n";
51 exit;
54 my $y0 = $cgi->param('y0') || '';
55 if ($y0 && $cgi->request_method eq 'POST' && $proj->authenticate($gcgi)) {
56 # submitted
57 if (!$proj->{mirror} && !$isempty && !$cgi->param('auth')) {
58 if ($y0 ne 'Send authorization code') {
59 print "<p>Invalid data. Go away, sorcerer.</p>\n";
60 exit;
63 valid_email($proj->{email}) or die "Sorry, this project cannot be removed.";
65 my $auth = $proj->gen_auth('DEL');
67 # Send auth mail
68 defined(my $MAIL = mailer_pipe '-s', "[$Girocco::Config::name] Project removal authorization", $proj->{email}) or
69 die "Sorry, could not send authorization code: $!";
70 print $MAIL <<EOT;
71 Hello,
73 Somebody requested a project removal authorization code to be sent for
74 project $name on $Girocco::Config::name. Since you are the project admin,
75 you receive the authorization code. If you don't want to actually remove
76 project $name, just ignore this e-mail. Otherwise, use this code
77 within 24 hours:
79 $auth
81 In case you did not request the removal authorization code, we apologize.
83 Should you run into any problems, please let us know.
85 Have fun!
86 EOT
87 close $MAIL;
89 print <<EOT;
90 <p>The project admin should shortly receive an e-mail containing a project
91 removal authorization code. Please enter this code below to remove project
92 $name from $Girocco::Config::name. The code will expire in 24 hours or after
93 you have used it.</p>
94 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
95 <input type="hidden" name="name" value="$name" />
96 <input type="hidden" name="cpwd" value="$proj->{cpwd}" />
97 <p>Authorization code: <input name="auth" size="50" /></p>
98 <p><input type="submit" name="y0" value="Remove" /></p>
99 </form>
101 exit;
103 if ($y0 ne "Remove") {
104 print "<p>Invalid data. Go away, sorcerer.</p>\n";
105 exit;
107 if (!$proj->{mirror} && !$isempty) {
108 $proj->{auth} && $proj->{authtype} && $proj->{authtype} eq 'DEL' or do {
109 print <<EOT;
110 <p>There currently isn't any project removal authorization code on file for
111 project $name. Please <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname"
112 >generate one</a>.</p>
114 exit;
116 my $auth = $gcgi->wparam('auth');
117 if ($auth ne $proj->{auth}) {
118 print <<EOT;
119 <p>Invalid authorization code, please re-enter or
120 <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname"
121 >generate a new one</a>.</p>
122 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
123 <input type="hidden" name="name" value="$name" />
124 <input type="hidden" name="cpwd" value="$proj->{cpwd}" />
125 <p>Authorization code: <input name="auth" size="50" /></p>
126 <p><input type="submit" name="y0" value="Remove" /></p>
127 </form>
129 exit;
131 $proj->del_auth;
133 if (!$proj->{mirror} && !$isempty) {
134 # archive the non-empty, non-mirror project before calling delete
135 $proj->archive_and_delete;
136 } else {
137 $proj->delete;
139 print "<p>Project successfully removed. Have a nice day.</p>\n";
140 exit;
143 my $fetchy = $Girocco::Config::gitpullurl || $Girocco::Config::httppullurl ||
144 $Girocco::Config::pushurl || $Girocco::Config::httpspushurl || $Girocco::Config::gitweburl;
145 my $url = $proj->{mirror} ? $proj->{url} : "$fetchy/$name.git";
146 my $type = $proj->{mirror} ? "mirrored " : ($isempty ? "empty " : "");
147 my $label = ($proj->{mirror} || $isempty) ? "Remove" : "Send authorization code";
149 print <<EOT;
150 <p>Please confirm that you are going to remove ${type}project
151 $name ($url) from the site.</p>
152 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
153 <input type="hidden" name="name" value="$name" />
155 if ($Girocco::Config::project_passwords) {
156 print <<EOT;
157 <p>Admin password: <input type="password" name="cpwd" /> <sup class="sup"><span><a
158 href="@{[url_path($Girocco::Config::webadmurl)]}/pwproj.cgi?name=$escname">(forgot password?)</a></span></sup></p>
161 print <<EOT;
162 <p><input type="submit" name="y0" value="$label" /></p>
163 </form>