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
::does_exist
($name,1) && !Girocco
::Project
::valid_name
($name)) {
25 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
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";
34 my $proj = Girocco
::Project
->load($name);
36 print "<p>not found project $name, that's really weird!</p>\n";
40 $escname =~ s/[+]/%2B/g;
41 $proj->{cpwd
} = $cgi->param('cpwd');
42 my $isempty = !$proj->{mirror
} && $proj->is_empty;
44 if ($proj->has_forks()) {
45 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";
49 my $y0 = $cgi->param('y0') || '';
50 if ($y0 && $cgi->request_method eq 'POST' && $proj->authenticate($gcgi)) {
52 if (!$proj->{mirror
} && !$isempty && !$cgi->param('auth')) {
53 if ($y0 ne 'Send authorization code') {
54 print "<p>Invalid data. Go away, sorcerer.</p>\n";
58 my $auth = $proj->gen_auth('DEL');
61 defined(my $MAIL = mailer_pipe
'-s', "[$Girocco::Config::name] Project removal authorization", $proj->{email
}) or
62 die "Sorry, could not send authorization code: $!";
66 Somebody requested a project removal authorization code to be sent for
67 project $name on $Girocco::Config::name. Since you are the project admin,
68 you receive the authorization code. If you don't want to actually remove
69 project $name, just ignore this e-mail. Otherwise, use this code
74 In case you did not request the removal authorization code, we apologize.
76 Should you run into any problems, please let us know.
83 <p>The project admin should shortly receive an e-mail containing a project
84 removal authorization code. Please enter this code below to remove project
85 $name from $Girocco::Config::name. The code will expire in 24 hours or after
87 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
88 <input type="hidden" name="name" value="$name" />
89 <input type="hidden" name="cpwd" value="$proj->{cpwd}" />
90 <p>Authorization code: <input name="auth" size="50" /></p>
91 <p><input type="submit" name="y0" value="Remove" /></p>
96 if ($y0 ne "Remove") {
97 print "<p>Invalid data. Go away, sorcerer.</p>\n";
100 if (!$proj->{mirror
} && !$isempty) {
101 $proj->{auth
} && $proj->{authtype
} && $proj->{authtype
} eq 'DEL' or do {
103 <p>There currently isn't any project removal authorization code on file for
104 project $name. Please <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname"
105 >generate one</a>.</p>
109 my $auth = $gcgi->wparam('auth');
110 if ($auth ne $proj->{auth
}) {
112 <p>Invalid authorization code, please re-enter or
113 <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname"
114 >generate a new one</a>.</p>
115 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
116 <input type="hidden" name="name" value="$name" />
117 <input type="hidden" name="cpwd" value="$proj->{cpwd}" />
118 <p>Authorization code: <input name="auth" size="50" /></p>
119 <p><input type="submit" name="y0" value="Remove" /></p>
126 if (!$proj->{mirror
} && !$isempty) {
127 # archive the non-empty, non-mirror project before calling delete
129 my $destdir = $proj->{base_path
};
130 $destdir =~ s
,(?
<=[^/])/+$,,;
131 $destdir .= "-recyclebin/";
132 $destdir .= $1 if $proj->{name
} =~ m
,^(.*/)[^/]+$,;
133 my $destbase = $proj->{name
};
134 $destbase = $1 if $destbase =~ m
,^.*/([^/]+)$,;
135 system('mkdir', '-p', $destdir) == 0 && -d
$destdir
136 or die "mkdir -p $destdir failed: $?";
138 if (-e
"$destdir$destbase.git") {
140 while (-e
"$destdir$destbase~$suffix.git") {
142 last if $suffix >= 10000; # don't get too carried away
144 $suffix = '~'.$suffix;
146 not -e
"$destdir$destbase$suffix.git"
147 or die "Unable to compute suitable archive path";
148 system('mv', $proj->{path
}, "$destdir$destbase$suffix.git") == 0
149 or die "mv $proj->{path} $destdir$destbase$suffix.git failed: $?";
152 print "<p>Project successfully removed. Have a nice day.</p>\n";
156 my $fetchy = $Girocco::Config
::gitpullurl
|| $Girocco::Config
::httppullurl
||
157 $Girocco::Config
::pushurl
|| $Girocco::Config
::httpspushurl
|| $Girocco::Config
::gitweburl
;
158 my $url = $proj->{mirror
} ?
$proj->{url
} : "$fetchy/$name.git";
159 my $type = $proj->{mirror
} ?
"mirrored " : ($isempty ?
"empty " : "");
160 my $label = ($proj->{mirror
} || $isempty) ?
"Remove" : "Send authorization code";
163 <p>Please confirm that you are going to remove ${type}project
164 $name ($url) from the site.</p>
165 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
166 <input type="hidden" name="name" value="$name" />
168 if ($Girocco::Config
::project_passwords
) {
170 <p>Admin password: <input type="password" name="cpwd" /> <sup><a
171 href="@{[url_path($Girocco::Config::webadmurl)]}/pwproj.cgi?name=$escname">(forgot password?)</a></sup></p>
175 <p><input type="submit" name="y0" value="$label" /></p>