#!/usr/bin/perl

do '../web-lib.pl';
$|=1;
&init_config();
%access = &get_module_acl();

&ReadParse();

&error ("Le module de gestion de mysql n'est pas utilisable") unless &foreign_check("mysql");
&foreign_require("mysql","mysql-lib.pl");

$serveur = &get_system_hostname();

$domaine=$in{domaine};
&error ("Quel domaine ?") if (!$domaine);

use DB_File;
tie %LIST,'DB_File',"/etc/ovhm.db";
$login = $LIST{"$domaine"};
untie(%LIST);


if (!$in{oui}) {
#	&error ("oui, non ?");
&header("Effacer ?", "", undef, 0, 1, 1, "Written by<BR><A HREF=mailto:hardware\@ovh.net>OVH</A><BR><A HREF=http://sd.ovh.fr>http://sd.ovh.fr</A>");
	print <<EOF;
<p>Etes vous sur de vouloir effacer la base de donnée $login ($domaine) ainsi que toutes les données qu'elle contient ?
<form action=effacer_bdd.cgi>
<input type=hidden name=domaine value="$domaine">
<br><input type=radio name=oui value=oui>Oui
<br><input type=radio name=oui value=non checked>Non
<p><input type=submit value=Go>
</form>
</body></html>
EOF
	exit;
}
if ($in{oui} eq "oui") {
	foreign_call("mysql","execute_sql_logged","mysql", "REVOKE ALL PRIVILEGES ON $login.* from $login\@localhost");
	foreign_call("mysql","execute_sql_logged","mysql", "REVOKE ALL PRIVILEGES ON $login.* from $login\@$serveur");
	foreign_call("mysql","execute_sql_logged","mysql", "drop database $login");
	foreign_call("mysql","execute_sql_logged","mysql", "delete from user where User = \'$login\'");
	foreign_call("mysql","execute_sql_logged","mysql","FLUSH PRIVILEGES");
	system ("rm -rf /home/$login/www/phpmyadmin");
}

&redirect("modifier.cgi?domaine=$domaine");

