#!/usr/bin/perl

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

&ReadParse();

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

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

$domaine=$in{domaine};

&error ("Quel domaine ?") if (!$domaine);

&header("", "", "modification", 0, 0, undef,"Written by<BR><A HREF=mailto:hardware\@ovh.net>OVH</A><BR><A HREF=http://sd.ovh.fr>http://sd.ovh.fr</A>");

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

@quota_user = &foreign_call("quota","user_quota",$login,"/home");
$quota = $quota_user[2] / 1000 ;

$serveur = &get_system_hostname();

$lock = `/usr/bin/passwd -S $login`;
$shell = `cat /etc/passwd | grep "^$login:" | sed s/^.*://`;
chop $shell;

$mysql = "";
$mysql = foreign_call("mysql","execute_sql_logged","mysql","select * from user where User=\'$login\'");

print <<EOF;

<hr>
<form action=save_modifier.cgi>
<input type=hidden name=domaine value="$domaine">
<table border>
  <tr $tb><td>Modification du domaine <b>$domaine</b> <i>utilisateur (ftp, mysql...) : <b>$login</b></i></td></tr>
  <tr $cb><td>
  <table>
    <tr><td>
    Quotas</td><td>
    <input name=quota value=$quota size=10> mo

    </td></tr><tr><td>
    Changer le mot de passe ftp
    </td><td>
    <input type=password size=10 name=mdpftp1>
    <br><input type=password size=10 name=mdpftp2>

    </td></tr><tr><td>
    Changer le mot de passe mail
    </td><td>
    <input type=password size=10 name=mdpmail1>
    <br><input type=password size=10 name=mdpmail2>

EOF

if ($mysql) {
print <<EOF;
    </td></tr><tr><td>
    Changer le mot de passe mysql
    </td><td>
    <input type=password size=10 name=mdpsql1>
    <br><input type=password size=10 name=mdpsql2>
EOF
}

print <<EOF;
    </td></tr><tr><td>
    Suspendre le site
    </td><td>

EOF

if ($lock =~ /Locked password./) {
	print "<input type=radio value=\"oui\" name=suspendre checked>Oui <input type=radio value=\"non\" name=suspendre>Non";
} else {
	print "<input type=radio value=\"oui\" name=suspendre>Oui <input type=radio value=\"non\" name=suspendre checked>Non";
}


print <<EOF;    
    </td></tr><tr><td>
    Accès telnet / ssh
    </td><td>
EOF

if ($shell eq "/bin/false") {
	print "<input type=radio value=oui name=telnet>Oui <input type=radio value=non name=telnet checked>Non";
} else {
        print "<input type=radio value=oui name=telnet checked>Oui <input type=radio value=non name=telnet>Non"; 
}


print <<EOF;
    </td></tr><tr><td>
    </td><td>
    <input type=submit value="Modifier">
    </form>
EOF

if (!$mysql) {

print <<EOF;
	</td></tr><tr><td>
	<hr>
	<form action=creer_bdd.cgi>
	<b>Créer une base de données:</b>
	</td><td>

        </td></tr><tr><td>
	Mot de passe:
	</td><td>
	<input type=hidden name=domaine value=$domaine>
	<input type=password size=10 name=mdpsql1>
	<br><input type=password size=10 name=mdpsql2>

	</td></tr><tr><td>
	</td><td>
	<input type=submit value="Créer">
	</form>
EOF

} else {
print <<EOF;
        </td></tr><tr><td>
        <hr>
	Effacer la base de données
        </td><td>
	<br><br>
        <form action=effacer_bdd.cgi>
        <input type=hidden name=domaine value=$domaine>
        <input type=submit value="Effacer">
        </form>
EOF
}

print <<EOF;
    </td></tr><tr><td>
    <hr>
    Ajouter un sous domaine (en cours)

    </td></tr><tr><td>
    <a href="alias.cgi?domaine=$domaine">Alias de nom de domaine</a>

    </td></tr>
  </table>
  </td></tr>
</table>

<hr>
<a href=effacer_domaine.cgi?domaine=$domaine>Effacer le domaine</a>
<hr>
<table border=0>
<tr><td><center><a href="http://www.$domaine">http://www.$domaine</a>&nbsp;</center></td>
<td><center>&nbsp;<a href="http://$serveur/~$login">http://$serveur/~$login</a></center></td></tr>

<tr><td><center><a href="http://www.$domaine/stats/">statistiques</a></center>
</td><td><center><a href="http://$serveur/~$login/stats/">statistiques</a></center></td></tr>
EOF

if ($mysql) {
print <<EOF;
<tr><td><center><a href="http://www.$domaine/phpmyadmin/">phpmyadmin</a></center></td>
<td><center><a href="http://$serveur/~$login/phpmyadmin/">phpmyadmin</a></center></td></tr>
EOF
}

print <<EOF;
</table>
<hr>
EOF

&footer("/ovhm/",ovh);
