2 # (c) Petr Baudis <pasky@suse.cz>
14 my $gcgi = Girocco
::CGI
->new('Project Removal');
17 my $name = $cgi->param('name');
19 unless (defined $name) {
20 print "<p>I need the project name as an argument now.</p>\n";
24 if (!Girocco
::Project
::valid_name
($name)) {
25 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
29 if (!Girocco
::Project
::does_exist
($name)) {
30 print "<p>Sorry but this project does not exist. Now, how did you <em>get</em> here?!</p>\n";
34 my $proj = Girocco
::Project
->load($name);
35 $proj or die "not found project $name, that's really weird!";
36 $proj->{cpwd
} = $cgi->param('cpwd');
37 my $isempty = !$proj->{mirror
} && $proj->is_empty;
39 if ($proj->has_forks()) {
40 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";
44 if ($cgi->param('y0') && $cgi->request_method eq 'POST' && $proj->authenticate($gcgi)) {
46 if (!$proj->{mirror
} && !$isempty && !$cgi->param('auth')) {
47 if ($cgi->param('y0') ne 'Send authorization code') {
48 print "<p>Invalid data. Go away, sorcerer.</p>\n";
52 my $auth = $proj->gen_auth;
55 open(MAIL
, '|-', '/usr/bin/mail', '-s', "[$Girocco::Config::name] Project removal authorization", $proj->{email
}) or
56 die "Sorry, could not send authorization code: $!";
60 somebody requested a project removal authorization code to be sent for
61 project $name on $Girocco::Config::name. Since you are the project admin,
62 you receive the authorization code. If you don't want to actually remove
63 project $name, just ignore this e-mail. Otherwise, use this code
68 In case you did not request the removal authorization code, we apologize.
70 Should you run into any problems, please let us know.
77 <p>The project admin should shortly receive an e-mail containing a project
78 removal authorization code. Please enter this code below to remove project
79 $name from $Girocco::Config::name. The code will expire in 24 hours or after
81 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
82 <input type="hidden" name="name" value="$name" />
83 <input type="hidden" name="cpwd" value="$proj->{cpwd}" />
84 <p>Authorization code: <input name="auth" size="50" /></p>
85 <p><input type="submit" name="y0" value="Remove" /></p>
90 if ($cgi->param('y0') ne "Remove") {
91 print "<p>Invalid data. Go away, sorcerer.</p>\n";
94 if (!$proj->{mirror
} && !$isempty) {
97 <p>There currently isn't any project removal authorization code on file for
98 project $name. Please <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$name"
99 >generate one</a>.</p>
103 my $auth = $gcgi->wparam('auth');
104 if ($auth ne $proj->{auth
}) {
106 <p>Invalid authorization code, please re-enter or
107 <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$name"
108 >generate a new one</a>.</p>
109 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
110 <input type="hidden" name="name" value="$name" />
111 <input type="hidden" name="cpwd" value="$proj->{cpwd}" />
112 <p>Authorization code: <input name="auth" size="50" /></p>
113 <p><input type="submit" name="y0" value="Remove" /></p>
120 if (!$proj->{mirror
} && !$isempty) {
121 # archive the non-empty, non-mirror project before calling delete
123 my $destdir = $proj->{base_path
};
124 $destdir =~ s
,(?
<=[^/])/+$,,;
125 $destdir .= "-recyclebin/";
126 $destdir .= $1 if $proj->{name
} =~ m
,^(.*/)[^/]+$,;
127 my $destbase = $proj->{name
};
128 $destbase = $1 if $destbase =~ m
,^.*/([^/]+)$,;
129 system('mkdir', '-p', $destdir) == 0 && -d
$destdir
130 or die "mkdir -p $destdir failed: $?";
132 if (-e
"$destdir$destbase.git") {
134 while (-e
"$destdir$destbase~$suffix.git") {
136 last if $suffix >= 10000; # don't get too carried away
138 $suffix = '~'.$suffix;
140 not -e
"$destdir$destbase$suffix.git"
141 or die "Unable to compute suitable archive path";
142 system('mv', $proj->{path
}, "$destdir$destbase$suffix.git") == 0
143 or die "mv $proj->{path} $destdir$destbase$suffix.git failed: $?";
146 print "<p>Project successfully removed. Have a nice day.</p>\n";
150 my $fetchy = $Girocco::Config
::gitpullurl
|| $Girocco::Config
::httppullurl
||
151 $Girocco::Config
::pushurl
|| $Girocco::Config
::httpspushurl
|| $Girocco::Config
::gitweburl
;
152 my $url = $proj->{mirror
} ?
$proj->{url
} : "$fetchy/$name.git";
153 my $type = $proj->{mirror
} ?
"mirrored " : ($isempty ?
"empty " : "");
154 my $label = ($proj->{mirror
} || $isempty) ?
"Remove" : "Send authorization code";
157 <p>Please confirm that you are going to remove ${type}project
158 $name ($url) from the site.</p>
159 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
160 <input type="hidden" name="name" value="$name" />
162 if ($Girocco::Config
::project_passwords
) {
164 <p>Admin password: <input type="password" name="cpwd" /> <sup><a
165 href="@{[url_path($Girocco::Config::webadmurl)]}/pwproj.cgi?name=$name">(forgot password?)</a></sup></p>
169 <p><input type="submit" name="y0" value="$label" /></p>