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') && $proj->authenticate($gcgi)) {
46 if (!$proj->{mirror
} && !$isempty && !$cgi->param('auth')) {
47 my $auth = $proj->gen_auth;
50 open(MAIL
, '|-', '/usr/bin/mail', '-s', "[$Girocco::Config::name] Project removal authorization", $proj->{email
}) or
51 die "Sorry, could not send authorization code: $!";
55 somebody requested a project removal authorization code to be sent for
56 project $name on $Girocco::Config::name. Since you are the project admin,
57 you receive the authorization code. If you don't want to actually remove
58 project $name, just ignore this e-mail. Otherwise, use this code
63 In case you did not request the removal authorization code, we apologize.
65 Should you run into any problems, please let us know.
72 <p>The project admin should shortly receive an e-mail containing a project
73 removal authorization code. Please enter this code below to remove project
74 $name from $Girocco::Config::name. The code will expire in 24 hours or after
76 <form method="post" action="delproj.cgi">
77 <input type="hidden" name="name" value="$name" />
78 <input type="hidden" name="cpwd" value="$proj->{cpwd}" />
79 <p>Authorization code: <input name="auth" size="40" /></p>
80 <p><input type="submit" name="y0" value="Remove" /></p>
85 if (!$proj->{mirror
} && !$isempty) {
88 <p>There currently isn't any project removal authorization code on file for
89 project $name. Please <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$name"
90 >generate one</a>.</p>
94 my $auth = $gcgi->wparam('auth');
95 if ($auth ne $proj->{auth
}) {
97 <p>Invalid authorization code, please re-enter or
98 <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$name"
99 >generate a new one</a>.</p>
100 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi">
101 <input type="hidden" name="name" value="$name" />
102 <input type="hidden" name="cpwd" value="$proj->{cpwd}" />
103 <p>Authorization code: <input name="auth" size="40" /></p>
104 <p><input type="submit" name="y0" value="Remove" /></p>
111 if (!$proj->{mirror
} && !$isempty) {
112 # archive the non-empty, non-mirror project before calling delete
114 my $destdir = $proj->{base_path
};
115 $destdir =~ s
,(?
<=[^/])/+$,,;
116 $destdir .= "-recyclebin/";
117 $destdir .= $1 if $proj->{name
} =~ m
,^(.*/)[^/]+$,;
118 my $destbase = $proj->{name
};
119 $destbase = $1 if $destbase =~ m
,^.*/([^/]+)$,;
120 system('mkdir', '-p', $destdir) == 0 && -d
$destdir
121 or die "mkdir -p $destdir failed: $?";
123 if (-e
"$destdir$destbase.git") {
125 while (-e
"$destdir$destbase~$suffix.git") {
127 last if $suffix >= 10000; # don't get too carried away
129 $suffix = '~'.$suffix;
131 not -e
"$destdir$destbase$suffix.git"
132 or die "Unable to compute suitable archive path";
133 system('mv', $proj->{path
}, "$destdir$destbase$suffix.git") == 0
134 or die "mv $proj->{path} $destdir$destbase$suffix.git failed: $?";
137 print "<p>Project successfully removed. Have a nice day.</p>\n";
141 my $fetchy = $Girocco::Config
::gitpullurl
|| $Girocco::Config
::httppullurl
||
142 $Girocco::Config
::pushurl
|| $Girocco::Config
::httpspushurl
|| $Girocco::Config
::gitweburl
;
143 my $url = $proj->{mirror
} ?
$proj->{url
} : "$fetchy/$name.git";
144 my $type = $proj->{mirror
} ?
"mirrored " : ($isempty ?
"empty " : "");
145 my $label = ($proj->{mirror
} || $isempty) ?
"Remove" : "Send authorization code";
148 <p>Please confirm that you are going to remove ${type}project
149 $name ($url) from the site.</p>
150 <form method="post" action="delproj.cgi">
151 <input type="hidden" name="name" value="$name" />
153 if ($Girocco::Config
::project_passwords
) {
155 <p>Admin password: <input type="password" name="cpwd" /> <sup><a
156 href="@{[url_path($Girocco::Config::webadmurl)]}/pwproj.cgi?name=$name">(forgot password?)</a></sup></p>
160 <p><input type="submit" name="y0" value="$label" /></p>