ajout classe m_export + script export_account afin de générer un export de compte. Correction de bugs divers.

This commit is contained in:
Steven Mondji-Lerider 2012-02-28 14:48:45 +00:00
parent 7c7f808972
commit 20103063b3
20 changed files with 402 additions and 157 deletions

2
.gitattributes vendored
View File

@ -316,6 +316,7 @@ bureau/class/m_authip.php -text
bureau/class/m_bro.php -text bureau/class/m_bro.php -text
bureau/class/m_dom.php -text bureau/class/m_dom.php -text
bureau/class/m_err.php -text bureau/class/m_err.php -text
bureau/class/m_export.php -text
bureau/class/m_ftp.php -text bureau/class/m_ftp.php -text
bureau/class/m_hooks.php -text bureau/class/m_hooks.php -text
bureau/class/m_hta.php -text bureau/class/m_hta.php -text
@ -465,6 +466,7 @@ src/alternc-dboptimize -text
src/alternc-passwd -text src/alternc-passwd -text
src/alternc_reload -text src/alternc_reload -text
src/du.pl -text src/du.pl -text
src/export_account.php -text
src/fixperms.sh -text src/fixperms.sh -text
src/functions.sh -text src/functions.sh -text
src/functions_dns.sh -text src/functions_dns.sh -text

View File

@ -51,4 +51,4 @@ if ($submit) {
} }
?> ?>

View File

@ -329,16 +329,17 @@ class m_bro {
global $db,$cuid,$err; global $db,$cuid,$err;
$file=ssla($file); $file=ssla($file);
$absolute=$this->convertabsolute($dir."/".$file,0); $absolute=$this->convertabsolute($dir."/".$file,0);
if ($absolute && !file_exists($absolute)) { echo "$absolute";
if (!@mkdir($absolute,00777)) { if ($absolute && (!file_exists($absolute))) {
$err->raise("bro",4); if (!mkdir($absolute,00777)) {
return false; $err->raise("bro",4);
} return false;
$db->query("UPDATE browser SET crff=1 WHERE uid='$cuid';"); }
return true; $db->query("UPDATE browser SET crff=1 WHERE uid='$cuid';");
return true;
} else { } else {
$err->raise("bro",1); $err->raise("bro",1);
return false; return false;
} }
} }
@ -357,6 +358,7 @@ class m_bro {
$err->raise("bro",1); $err->raise("bro",1);
return false; return false;
} }
print_r($absolute);
if (!file_exists($absolute)) { if (!file_exists($absolute)) {
if (!@touch($absolute)) { if (!@touch($absolute)) {
$err->raise("bro",3); $err->raise("bro",3);
@ -918,29 +920,56 @@ class m_bro {
unlink($file); unlink($file);
} }
} }
/*----------------------------------------------------------*/
/** Function d'exportation de configuration appelé par la classe m_export via un hooks
*Produit en sorti un tableau formatté ( pour le moment) en HTML
*
*/
function alternc_export_conf() {
/* ----------------------------------------------------------------- */
/**
* Exporte toutes les informations ftp du compte AlternC
* @access private
* EXPERIMENTAL 'sid' function ;)
*/
function alternc_export() {
global $db,$err; global $db,$err;
$err->log("bro","export"); $err->log("bro","export_conf");
$str="<bro>\n"; $str="<table border=\"1\"><caption> Browser </caption>\n";
$pref=$this->GetPrefs(); $pref=$this->GetPrefs();
$i=1;
foreach ($pref as $k=>$v) { foreach ($pref as $k=>$v) {
$str.=" <pref>\n"; if (($i % 2)==0){
$str.=" <".$k.">".xml_entities($v)."</".$k.">\n"; $str.=" <tr>\n";
$str.=" </pref>\n"; $str.=" <td>".$k."</td><td>".$v."</td>\n";
$str.=" </tr>\n";
}
$i++;
} }
$str.="</bro>\n"; $str.="</table>\n";
return $str; return $str;
} }
/*----------------------------------------------------------*/
/** Function d'exportation des données appelé par la classe m_export via un hooks
*@param : le chemin destination du tarball produit.
*/
function alternc_export_data($dir){
global $mem,$L_ALTERNC_LOC,$err;
$err->log("bro","export_data");
$dir.="html/";
if(!is_dir($dir)){
if(!mkdir($dir))
$err->raise("bro",4);
}
$timestamp=date("H:i:s");
if(exec("/bin/tar cvf - ".$L_ALTERNC_LOC."/html/".substr($mem->user['login'],0,1)."/".$mem->user['login']."/ | gzip -9c > ".$dir."/".$mem->user['login']."_html_".$timestamp.".tar.gz")){
$err->log("bro","export_data_succes");
}else{
$err->log("bro","export_data_failed");
}
}
} /* Classe BROUTEUR */ } /* Classe BROUTEUR */

View File

@ -1279,36 +1279,51 @@ class m_dom {
} else return false; } else return false;
} }
/*---------------------------------------------------------------------*/
/* ----------------------------------------------------------------- */ /**
/** * Returns the global domain(s) configuration(s) of a particular user
* Exporte toutes les informations domaine du compte. * No parameters needed
* @access private *
* EXPERIMENTAL 'sid' function ;) **/
*/ function alternc_export_conf() {
function alternc_export() {
global $db,$err; global $db,$err;
$err->log("dom","export"); $err->log("dom","export");
$this->enum_domains(); $this->enum_domains();
$str="<dom>\n"; $str="<table border=\"1\"><caption>Domaines</caption><tr><th>Domaine</th><th>DNS</th><th>MX</th><th>mail</th></tr> \n";
foreach ($this->domains as $d) { foreach ($this->domains as $d) {
$str.=" <domain>\n <name>".xml_entities($d)."</name>\n"; $str.="<tr>";
$s=$this->get_domain_all($d); $str.="<td>".$d."</td>";
$str.=" <hasdns>".xml_entities($s[dns])."</hasdns>\n"; $this->lock();
$str.=" <hasmx>".xml_entities($s[mx])."</hasmx>\n"; $s=$this->get_domain_all($d);
$str.=" <mx>".xml_entities($s[mail])."</mx>\n"; $this->unlock();
if (is_array($s[sub])) { if(empty($s[dns])){
foreach ($s[sub] as $sub) { $s[dns]="non";
$str.=" <subdomain>";
$str.="<name>".xml_entities($sub[name])."</name>";
$str.="<dest>".xml_entities($sub[dest])."</dest>";
$str.="<type>".xml_entities($sub[type])."</type>";
$str.="</subdomain>\n";
} }
} $str.=" <td>".$s[dns]."</td>\n";
$str.=" </domain>\n";
if(empty($s[mx])){
$s[mx]="non";
}
$str.="<td>".$s[mx]."</td>\n";
if(empty($s[mail])){
$s[mail]="non";
}
$str.="<td>".$s[mail]."</td>\n";
if (is_array($s[sub])) {
$str.="<table border=\"1\"><th>nom sous domaine</th><th>destination</th><th>type</th><tr>";
foreach ($s[sub] as $sub) {
$str.="<tr><td>".$sub["enable"]." </td>";
$str.="<td>".$sub["dest"]." </td>";
$str.="<td>".$sub["type"]." </td></tr>";
}
$str.="</tr>\n";
}
$str.="</table>\n";
} }
$str.="</dom>\n"; $str.="</table>\n";
return $str; return $str;
} }

38
bureau/class/m_export.php Normal file
View File

@ -0,0 +1,38 @@
<?php
/*---------------------------------------------------------------------------*/
/** Constructor
Classe d'export de compte Alternc.
Cette classe ce contente d'invoquer les fonctions d'exportation de configuration et de données d'un compte,
presentes dans les classes concernées.
*/
Class m_export {
function m_export() {
}
function export_conf(){
global $hooks;
$conf = array();
$conf=$hooks->invoke('alternc_export_conf');
return $conf;
}
/** le repertoire de base est passé en paramettre puis en construit une arborescence de la forme
<dir>/<user>/<timestamp/ qui contiendra les dossier de dump html et sql
*/
function export_data($dir){
global $hooks, $mem;
$hooks->invoke('alternc_export_data', Array($dir));
}
}// export Class end
?>

View File

@ -95,7 +95,8 @@ class m_ftp {
$r[]=array( $r[]=array(
"id"=>$db->f("id"), "id"=>$db->f("id"),
"login"=>$db->f("name"), "login"=>$db->f("name"),
"dir"=>$match[1] //"dir"=>$match[1]
"dir"=>$db->f("homedir")
); );
} }
return $r; return $r;
@ -378,19 +379,20 @@ class m_ftp {
* @access private * @access private
* EXPERIMENTAL 'sid' function ;) * EXPERIMENTAL 'sid' function ;)
*/ */
function alternc_export() { function alternc_export_conf() {
global $db,$err; global $db,$err;
$err->log("ftp","export"); $err->log("ftp","export");
$f=$this->get_list(); $f=$this->get_list();
$str="<ftp>\n"; $str="<table border=\"1\"><caption> FTP </caption>\n";
foreach ($f as $d) { foreach ($f as $d=>$v) {
$str.=" <account>\n"; $str.=" <tr>\n";
$str.=" <login>".xml_entities($s[login])."</login>\n"; $str.=" <td>".$v["id"]."</td>\n";
$str.=" <pass>".xml_entities($s[pass])."</pass>\n"; $str.=" <td>".($v["encrypted_password"])."</td>\n";
$str.=" <dir>".xml_entities($s[dir])."</dir>\n"; $str.=" <td>".($v["login"])."</td>\n";
$str.=" </account>\n"; $str.=" <td>".($v["dir"])."<td>\n";
$str.=" </tr>\n";
} }
$str.="</ftp>\n"; $str.="</table>\n";
return $str; return $str;
} }

View File

@ -33,7 +33,8 @@ class m_hooks {
} }
/** /**
* run_hook() * invoke() permet de lancer une fonction donné en parametre dans toute les classes
* connues de alternc, avec les parametres donnés.
* $hname nom de la fonction "hooks" que l'on cherche dans les classes * $hname nom de la fonction "hooks" que l'on cherche dans les classes
* $hparam tableau contenant les parametres * $hparam tableau contenant les parametres
* $hclass tableau contenant les classes spécifique qu'on veux appeler (si on veux pas TOUTE les appeler) * $hclass tableau contenant les classes spécifique qu'on veux appeler (si on veux pas TOUTE les appeler)

View File

@ -751,44 +751,45 @@ class m_mail {
global $db,$err; global $db,$err;
$err->log("mail","export"); $err->log("mail","export");
$domain=$this->enum_domains(); $domain=$this->enum_domains();
$str="<mail>\n"; $str="<table border=\"1\"><caption> Mail</caption>\n";
$tmpfile=$tmpdir."/mail_filelist.txt"; $tmpfile=$tmpdir."/mail_filelist.txt";
$f=fopen($tmpfile,"wb"); $f=fopen($tmpfile,"wb");
$onepop=false; $onepop=false;
foreach ($domain as $d) { foreach ($domain as $d) {
$str.=" <domain>\n <name>".xml_entities($d)."</name>\n"; $str.=" <tr>\n <td>".($d)."</td>\n";
$s=$this->enum_doms_mails($d); $s=$this->enum_doms_mails($d);
unset($s["count"]); unset($s["count"]);
if (count($s)) { if (count($s)) {
foreach($s as $e) { foreach($s as $e) {
$str.=" <address>\n"; $str.=" <table><tr>\n";
$str.=" <mail>".xml_entities($e["mail"])."</mail>\n"; $str.=" <td>".($e["mail"])."</td>\n";
$str.=" <ispop>".xml_entities($e["pop"])."</ispop>\n"; $str.=" <td>".($e["pop"])."</td>\n";
$acc=explode("\n",$e["alias"]); $acc=explode("\n",$e["alias"]);
foreach($acc as $f) { foreach($acc as $f) {
$f=trim($f); $f=trim($f);
if ($f) { $str.="<ul>";
$str.=" <alias>".xml_entities($f)."</alias>\n"; if ($f) {
} $str.=" <li>".($f)."</li>\n</ul>";
} }
if ($e["pop"]) { }
$db->query("SELECT path FROM mail_users WHERE alias='".str_replace("@","_",$e["mail"])."';"); if ($e["pop"]) {
if ($db->next_record()) { $db->query("SELECT path FROM mail_users WHERE alias='".str_replace("@","_",$e["mail"])."';");
fputs($f,$db->Record["path"]."\n"); if ($db->next_record()) {
$onepop=true; fputs($f,$db->Record["path"]."\n");
} $onepop=true;
} }
$str.=" </address>\n"; }
} $str.=" </tr>\n";
}
} }
$str.=" </domain>\n"; $str.=" </tr>\n";
} }
$str.="</mail>\n"; $str.="</table>\n";
fclose($f); fclose($f);
if ($onepop) { /*if ($onepop) {
// Now do the tarball of all pop accounts : // Now do the tarball of all pop accounts :
exec("/bin/tar -czf ".escapeshellarg($tmpdir."/mail.tar.gz")." -T ".escapeshellarg($tmpfile)); exec("/bin/tar -czf ".escapeshellarg($tmpdir."/mail.tar.gz")." -T ".escapeshellarg($tmpfile));
} }*/
@unlink($tmpfile); @unlink($tmpfile);
return $str; return $str;
} }

View File

@ -550,17 +550,23 @@ Cordialement.
/** /**
* Exports all the personnal user related information for an account. * Exports all the personnal user related information for an account.
* @access private * @access private
* EXPERIMENTAL 'sid' function ;)
*/ */
function alternc_export($tmpdir) { function alternc_export_conf() {
global $db,$err; global $db,$err;
$err->log("mem","export"); $err->log("mem","export");
$str="<mem>\n"; $str="<table border=\"1\"><caption > Member </caption>\n";
$users=$this->user;
foreach ($this->user as $k=>$v) { $str.=" <tr> <td>".$users["uid"]."</td></tr>\n";
$str.=" <$k>".xml_entities($v)."</$k>\n"; $str.=" <tr> <td>".$users["login"]."</td></tr>\n";
} $str.=" <tr> <td>".$users["enabled"]."</td></tr>\n";
$str.="</mem>\n"; $str.=" <tr> <td>".$users["su"]."</td></tr>\n";
$str.=" <tr> <td>".$users["pass"]."</td></tr>\n";
$str.=" <tr> <td>".$users["mail"]."</td></tr>\n";
$str.=" <tr> <td>".$users["created"]."</td></tr>\n";
$str.=" <tr> <td>".$users["lastip"]."</td></tr>\n";
$str.=" <tr> <td>".$users["lastlogin"]."</td></tr>\n";
$str.=" <tr> <td>".$users["lastfail"]."</td></tr>\n";
$str.="</table>\n";
return $str; return $str;
} }

View File

@ -35,7 +35,7 @@
*/ */
class DB_users extends DB_Sql { class DB_users extends DB_Sql {
var $Host,$HumanHostname,$User,$Password; var $Host,$HumanHostname,$User,$Password,$client;
/** /**
* Creator * Creator
@ -81,15 +81,16 @@ class DB_users extends DB_Sql {
} }
} }
# Create the object # Create the object
$this->Host = $host; $this->Host = $host;
$this->client = $GLOBALS['L_MYSQL_CLIENT'];
$this->User = $user; $this->User = $user;
$this->Password = $password; $this->Password = $password;
// TODO BUG BUG BUG // TODO BUG BUG BUG
// c'est pas étanche : $db se retrouve avec Database de $sql->dbu . Danger, faut comprendre pourquoi // c'est pas étanche : $db se retrouve avec Database de $sql->dbu . Danger, faut comprendre pourquoi
// Si on veux que ca marche, il faut Database=alternc. // Si on veux que ca marche, il faut Database=alternc.
$this->Database = "mysql"; //$this->Database = "mysql";
$this->Database = "alternc";
$this->HumanHostname = $human_hostname; $this->HumanHostname = $human_hostname;
} }
@ -219,13 +220,15 @@ class m_mysql {
$pa=addslashes($db->f("pass")); $pa=addslashes($db->f("pass"));
} }
if ($this->dbus->query("CREATE DATABASE `$dbname`;")) { if ($this->dbus->query("CREATE DATABASE `$dbname`;")) {
$err->log("mysql","add_db_succes",$dbn);
// Ok, database does not exist, quota is ok and dbname is compliant. Let's proceed // Ok, database does not exist, quota is ok and dbname is compliant. Let's proceed
$db->query("INSERT INTO db (uid,login,pass,db,bck_mode) VALUES ('$cuid','$lo','$pa','$dbname',0);"); $db->query("INSERT INTO db (uid,login,pass,db,bck_mode) VALUES ('$cuid','$lo','$pa','$dbname',0);");
// give everything but GRANT on db.* // give everything but GRANT on db.*
// we assume there's already a user // we assume there's already a user
$this->dbus->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$lo."'@'$this->client'"); $this->dbus->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$lo."'@'$this->dbus->client'");
return true; return true;
} else { } else {
$err->log("mysql","add_db",$dbn);
$err->raise("mysql",3); $err->raise("mysql",3);
return false; return false;
} }
@ -257,7 +260,7 @@ class m_mysql {
$this->dbus->query("DROP DATABASE `$dbname`;"); $this->dbus->query("DROP DATABASE `$dbname`;");
$db->query("SELECT COUNT(*) AS cnt FROM db WHERE uid='$cuid';"); $db->query("SELECT COUNT(*) AS cnt FROM db WHERE uid='$cuid';");
$db->next_record(); $db->next_record();
$this->dbus->query("REVOKE ALL PRIVILEGES ON `".$dbname."`.* FROM '".$login."'@'$this->client'"); $this->dbus->query("REVOKE ALL PRIVILEGES ON `".$dbname."`.* FROM '".$login."'@".$this->dbus->client."");
if ($this->dbus->f("cnt")==0) { if ($this->dbus->f("cnt")==0) {
$this->dbus->query("DELETE FROM mysql.user WHERE User='".$login."';"); $this->dbus->query("DELETE FROM mysql.user WHERE User='".$login."';");
$this->dbus->query("FLUSH PRIVILEGES;"); $this->dbus->query("FLUSH PRIVILEGES;");
@ -344,7 +347,7 @@ class m_mysql {
// Update all the "pass" fields for this user : // Update all the "pass" fields for this user :
$db->query("UPDATE db SET pass='$password' WHERE uid='$cuid';"); $db->query("UPDATE db SET pass='$password' WHERE uid='$cuid';");
$this->dbus->query("SET PASSWORD FOR '$login'@'$this->client' = PASSWORD('$password')"); $this->dbus->query("SET PASSWORD FOR '$login'@'$this->dbus->client' = PASSWORD('$password')");
return true; return true;
} }
@ -389,7 +392,7 @@ class m_mysql {
// OK, creation now... // OK, creation now...
$db->query("INSERT INTO db (uid,login,pass,db) VALUES ('$cuid','".$login."','$password','".$dbname."');"); $db->query("INSERT INTO db (uid,login,pass,db) VALUES ('$cuid','".$login."','$password','".$dbname."');");
// give everything but GRANT on $user.* // give everything but GRANT on $user.*
$this->dbus->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$login."'@'$this->client' IDENTIFIED BY '".addslashes($password)."'"); $this->dbus->query("GRANT ALL PRIVILEGES ON `".$dbname."`.* TO '".$login."'@".$this->dbus->client." IDENTIFIED BY '".addslashes($password)."'");
$this->dbus->query("CREATE DATABASE `".$dbname."`;"); $this->dbus->query("CREATE DATABASE `".$dbname."`;");
return true; return true;
} }
@ -532,7 +535,7 @@ class m_mysql {
} }
// We create the user account (the "file" right is the only one we need globally to be able to use load data into outfile) // We create the user account (the "file" right is the only one we need globally to be able to use load data into outfile)
$this->dbus->query("GRANT file ON *.* TO '$user'@'$this->client' IDENTIFIED BY '$pass';"); $this->dbus->query("GRANT file ON *.* TO '$user'@".$this->dbus->client." IDENTIFIED BY '$pass';");
// We add him to the user table // We add him to the user table
$db->query("INSERT INTO dbusers (uid,name) VALUES($cuid,'$user');"); $db->query("INSERT INTO dbusers (uid,name) VALUES($cuid,'$user');");
return true; return true;
@ -564,8 +567,7 @@ class m_mysql {
return false; // The error has been raised by checkPolicy() return false; // The error has been raised by checkPolicy()
} }
} }
$this->dbus->query("SET PASSWORD FOR ".$user."@".$this->dbus->client." = PASSWORD(".$pass.")");
$this->dbus->query("SET PASSWORD FOR '$user'@'$this->client' = PASSWORD('$pass')");
return true; return true;
} }
@ -593,9 +595,9 @@ class m_mysql {
$login=$db->f("name"); $login=$db->f("name");
// Ok, database exists and dbname is compliant. Let's proceed // Ok, database exists and dbname is compliant. Let's proceed
$this->dbus->query("REVOKE ALL PRIVILEGES ON *.* FROM '".$mem->user["login"]."_$user'@'$this->client';"); $this->dbus->query("REVOKE ALL PRIVILEGES ON *.* FROM '".$mem->user["login"]."_$user'@".$this->dbus->client.";");
$this->dbus->query("DELETE FROM mysql.db WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';"); $this->dbus->query("DELETE FROM mysql.db WHERE User='".$mem->user["login"]."_$user' AND Host=".$this->dbus->client.";");
$this->dbus->query("DELETE FROM mysql.user WHERE User='".$mem->user["login"]."_$user' AND Host='$this->client';"); $this->dbus->query("DELETE FROM mysql.user WHERE User='".$mem->user["login"]."_$user' AND Host=".$this->dbus->client.";");
$this->dbus->query("FLUSH PRIVILEGES"); $this->dbus->query("FLUSH PRIVILEGES");
$this->dbus->query("DELETE FROM dbusers WHERE uid='$cuid' AND name='".$mem->user["login"]."_$user';"); $this->dbus->query("DELETE FROM dbusers WHERE uid='$cuid' AND name='".$mem->user["login"]."_$user';");
return true; return true;
@ -616,7 +618,7 @@ class m_mysql {
$dblist=$this->get_dblist(); $dblist=$this->get_dblist();
for ( $i=0 ; $i<count($dblist) ; $i++ ) { for ( $i=0 ; $i<count($dblist) ; $i++ ) {
$this->dbus->query("SELECT Db, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, References_priv, Index_priv, Alter_priv, Create_tmp_table_priv, Lock_tables_priv FROM mysql.db WHERE User='".$mem->user["login"].($user?"_":"").$user."' AND Host='$this->client' AND Db='".$dblist[$i]["db"]."';"); $this->dbus->query("SELECT Db, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, References_priv, Index_priv, Alter_priv, Create_tmp_table_priv, Lock_tables_priv FROM mysql.db WHERE User='".$mem->user["login"].($user?"_":"").$user."' AND Host=".$this->dbus->client." AND Db='".$dblist[$i]["db"]."';");
if ($this->dbus->next_record()) if ($this->dbus->next_record())
$r[]=array("db"=>$dblist[$i]["name"], "select"=>$this->dbus->f("Select_priv"), "insert"=>$this->dbus->f("Insert_priv"), "update"=>$this->dbus->f("Update_priv"), "delete"=>$this->dbus->f("Delete_priv"), "create"=>$this->dbus->f("Create_priv"), "drop"=>$this->dbus->f("Drop_priv"), "references"=>$this->dbus->f("References_priv"), "index"=>$this->dbus->f("Index_priv"), "alter"=>$this->dbus->f("Alter_priv"), "create_tmp"=>$this->dbus->f("Create_tmp_table_priv"), "lock"=>$this->dbus->f("Lock_tables_priv")); $r[]=array("db"=>$dblist[$i]["name"], "select"=>$this->dbus->f("Select_priv"), "insert"=>$this->dbus->f("Insert_priv"), "update"=>$this->dbus->f("Update_priv"), "delete"=>$this->dbus->f("Delete_priv"), "create"=>$this->dbus->f("Create_priv"), "drop"=>$this->dbus->f("Drop_priv"), "references"=>$this->dbus->f("References_priv"), "index"=>$this->dbus->f("Index_priv"), "alter"=>$this->dbus->f("Alter_priv"), "create_tmp"=>$this->dbus->f("Create_tmp_table_priv"), "lock"=>$this->dbus->f("Lock_tables_priv"));
else else
@ -682,10 +684,10 @@ class m_mysql {
// We reset all user rights on this DB : // We reset all user rights on this DB :
$this->dbus->query("SELECT * FROM mysql.db WHERE User = '$usern' AND Db = '$dbname';"); $this->dbus->query("SELECT * FROM mysql.db WHERE User = '$usern' AND Db = '$dbname';");
if($this->dbus->num_rows()) if($this->dbus->num_rows())
$this->dbus->query("REVOKE ALL PRIVILEGES ON $dbname.* FROM '$usern'@'$this->client';"); $this->dbus->query("REVOKE ALL PRIVILEGES ON $dbname.* FROM '$usern'@'".$this->dbus->client."';");
if( $strrights ){ if( $strrights ){
$strrights=substr($strrights,0,strlen($strrights)-1); $strrights=substr($strrights,0,strlen($strrights)-1);
$this->dbus->query("GRANT $strrights ON $dbname.* TO '$usern'@'$this->client';"); $this->dbus->query("GRANT $strrights ON $dbname.* TO '$usern'@'".$this->dbus->client."';");
} }
$this->dbus->query("FLUSH PRIVILEGES"); $this->dbus->query("FLUSH PRIVILEGES");
return TRUE; return TRUE;
@ -761,36 +763,62 @@ class m_mysql {
* @access private * @access private
* EXPERIMENTAL 'sid' function ;) * EXPERIMENTAL 'sid' function ;)
*/ */
function alternc_export($tmpdir) { function alternc_export_conf() {
//TODO don't work with separated sql server for dbusers //TODO don't work with separated sql server for dbusers
global $db,$err,$cuid; global $db,$err,$cuid;
$err->log("mysql","export"); $err->log("mysql","export");
$db->query("SELECT login, pass, db, bck_mode, bck_dir, bck_history, bck_gzip FROM db WHERE uid='$cuid';"); $db->query("SELECT login, pass, db, bck_mode, bck_dir, bck_history, bck_gzip FROM db WHERE uid='$cuid';");
$str.="<table border=\"1\"><caption>MyQSL</caption><th>login</th><th>pass</th>";
if ($db->next_record()) { if ($db->next_record()) {
$str="<mysql>\n"; $str.="<tr>\n";
$str.=" <login>".xml_entities($db->Record["login"])."</login>"; $str.=" <td>".$db->Record["login"]."</td>";
$str.=" <pass>".xml_entities($db->Record["pass"])."</pass>"; $str.=" <td>".$db->Record["pass"]."</td>";
$str.="</tr>\n";
do { do {
// Do the dump :
$filename=$tmpdir."/mysql.".$db->Record["db"].".sql.gz"; $filename=$tmpdir."/mysql.".$db->Record["db"].".sql.gz";
exec("/usr/bin/mysqldump --add-drop-table --allow-keywords -Q -f -q -a -e -u".escapeshellarg($db->Record["login"])." -p".escapeshellarg($db->Record["pass"])." ".escapeshellarg($db->Record["db"])." |/bin/gzip >".escapeshellarg($filename)); $str.=" <tr>\n";
$str.=" <db>\n"; $str.=" <td>".($db->Record["db"])."</td>\n";
$str.=" <name>".xml_entities($db->Record["db"])."</name>\n"; $str.=" <td>".($db->Record["pass"])."</td>\n";
if ($s["bck_mode"]!=0) { if ($s["bck_mode"]!=0) {
$str.=" <backup>\n"; $str.=" <table>\n";
$str.=" <mode>".xml_entities($db->Record["bck_mode"])."</mode>\n"; $str.=" <td>".($db->Record["bck_mode"])."</td>\n";
$str.=" <dir>".xml_entities($db->Record["bck_dir"])."</dir>\n"; $str.=" <td>".($db->Record["bck_dir"])."</td>\n";
$str.=" <history>".xml_entities($db->Record["bck_history"])."</history>\n"; $str.=" <td>".($db->Record["bck_history"])."</td>\n";
$str.=" <gzip>".xml_entities($db->Record["bck_gzip"])."</gzip>\n"; $str.=" <td>".($db->Record["bck_gzip"])."</td>\n";
$str.=" </backup>\n"; $str.=" </table>\n";
} }
$str.=" </db>\n"; $str.=" </tr>\n";
} while ($db->next_record()); } while ($db->next_record());
$str.="</mysql>\n"; $str.="</table>\n";
} }
return $str; return $str;
} }
/* ----------------------------------------------------------------- */
/**
* Exporte all the mysql databases a of give account to $dir directory
* @access private
* EXPERIMENTAL 'sid' function ;)
*/
function alternc_export_data ($dir){
global $db, $err, $cuid,$mem;
$err->log("mysql","export_data");
$db->query("SELECT db.login, db.pass, db.db, dbusers.name FROM db,dbusers WHERE db.uid='$cuid' AND dbusers.uid=db.uid;");
$dir.="sql/";
if(!is_dir($dir)){
if(!mkdir($dir)){
$err->raise('mysql',4);
}
}
// on exporte toutes les bases utilisateur.
while($db->next_record()){
$filename=$dir."mysql.".$db->Record["db"].".".date("H:i:s").".sql.gz";
exec ("/usr/bin/mysqldump --defaults-file=/etc/alternc/my.cnf --add-drop-table --allow-keywords -Q -f -q -a -e ".escapeshellarg($db->Record["db"])." |/bin/gzip >".escapeshellarg($filename));
}
}
} /* Class m_mysql */ } /* Class m_mysql */

View File

@ -176,9 +176,12 @@ class m_quota {
if (isset($this->disk[$ressource])) { if (isset($this->disk[$ressource])) {
// It's a disk resource, update it with shell command // It's a disk resource, update it with shell command
exec("/usr/lib/alternc/quota_edit $cuid $size"); exec("/usr/lib/alternc/quota_edit $cuid $size");
echo "quota set :::::ciud: $cuid :::: size: $size :::: \n ";
// Now we check that the value has been written properly : // Now we check that the value has been written properly :
exec("/usr/lib/alternc/quota_get ".$cuid,$a); exec("/usr/lib/alternc/quota_get ".$cuid,$a);
if ($size!=$a[1]) { echo "quota get :::::ciud: $cuid :::: size: $size :::: a?: $a ";
print_r($a);
if ($size!=$a[1]) {
$err->raise("quota",1); $err->raise("quota",1);
return false; return false;
} }
@ -362,17 +365,18 @@ class m_quota {
* @access private * @access private
* EXPERIMENTAL 'sid' function ;) * EXPERIMENTAL 'sid' function ;)
*/ */
function alternc_export($tmpdir) { function alternc_export_conf($tmpdir) {
global $db,$err; global $db,$err;
$err->log("quota","export"); $err->log("quota","export");
$str="<quota>\n"; $str="<table border=\"1\" ><caption>QUOTA</caption>\n";
$q=$this->getquota(); $q=$this->getquota();
foreach ($q as $k=>$v) { foreach ($q as $k=>$v) {
$str.=" <service>\n <name>".xml_entities($k)."</name>\n"; $str.=" <tr>\n <td>".($k)."</td>\n";
$str.=" <total>".xml_entities($v)."</total>\n </service>\n"; $str.=" <td>".($v[u])."</td>\n \n";
$str.=" <td>".($v[t])."</td>\n </tr>\n";
} }
$str.="</quota>\n"; $str.="</table>\n";
return $str; return $str;
} }

View File

@ -290,15 +290,15 @@ class m_sta2 {
* @access private * @access private
* EXPERIMENTAL 'sid' function ;) * EXPERIMENTAL 'sid' function ;)
*/ */
function alternc_export($tmpdir) { function alternc_export_conf() {
global $db,$err; global $db,$err;
$err->log("sta2","export"); $err->log("sta2","export");
$this->get_list_raw(); $f=$this->get_list_raw();
$str="<sta2>\n"; $str="<sta2>\n";
foreach ($f as $d) { foreach ($f as $d) {
$str.=" <stats>\n"; $str.=" <stats>\n";
$str.=" <hostname>".xml_entities($s[hostname])."</hostname>\n"; $str.=" <hostname>".($s[hostname])."</hostname>\n";
$str.=" <folder>".xml_entities($s[folder])."</folder>\n"; $str.=" <folder>".($s[folder])."</folder>\n";
$str.=" </stats>\n"; $str.=" </stats>\n";
} }
$str.="</sta2>\n"; $str.="</sta2>\n";
@ -308,4 +308,4 @@ class m_sta2 {
} /* CLASSE m_sta2 */ } /* CLASSE m_sta2 */
?> ?>

11
debian/changelog vendored
View File

@ -1,9 +1,18 @@
alternc (1.1+nmu1) stable; urgency=low
* Dev in progres.
* New class: m_export allowing account exporting given it's iud and a path : http://www.alternc.org/wiki/AlterncExport
* Adding script export_account.php usind the above class to export an account.
* Bugfixes: quota's scripts udpated ( mostly concerning LVM partitions), and lots of others (permissions, browser ...)
-- Lerider Steven <squidly@nnx.com> Tue, 28 Feb 2012 14:57:48 +0100
alternc (1.1) stable; urgency=low alternc (1.1) stable; urgency=low
* Dev in progress * Dev in progress
* New class : access security. Allow to restrict some function to specific IP or subnet * New class : access security. Allow to restrict some function to specific IP or subnet
* Access security management on the ftp account. * Access security management on the ftp account.
-- Alan Garcia <fufroma@mailfr.com> Wed, 25 May 2011 09:24:30 +0200 -- Alan Garcia (nickname) <fufroma@mailfr.com> Wed, 25 May 2011 09:24:30 +0200
alternc (1.0.3) stable; urgency=high alternc (1.0.3) stable; urgency=high
* Bugfix : the 'connect' button in the list of installed domains didn't work, make it work * Bugfix : the 'connect' button in the list of installed domains didn't work, make it work

10
debian/po/fr.po vendored
View File

@ -15,7 +15,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: AlternC 0.9.5\n" "Project-Id-Version: AlternC 0.9.5\n"
"Report-Msgid-Bugs-To: alternc@packages.debian.org\n" "Report-Msgid-Bugs-To: alternc@packages.debian.org\n"
"POT-Creation-Date: 2011-06-04 11:00+0200\n" "POT-Creation-Date: 2012-02-07 17:23+0100\n"
"PO-Revision-Date: 2006-04-26 11:16+0200\n" "PO-Revision-Date: 2006-04-26 11:16+0200\n"
"Last-Translator: Benjamin Sonntag <benjamin@sonntag.fr>\n" "Last-Translator: Benjamin Sonntag <benjamin@sonntag.fr>\n"
"Language-Team: Team AlternC <team@alternc.org>\n" "Language-Team: Team AlternC <team@alternc.org>\n"
@ -33,10 +33,16 @@ msgstr "Etes-vous CERTAIN de vouloir installer AlternC sur cet ordinateur ?"
#. Type: boolean #. Type: boolean
#. Description #. Description
#: ../templates:1001 #: ../templates:1001
#, fuzzy
#| msgid ""
#| "You are currently trying to install AlternC on your computer. Be aware "
#| "that this package will overwrite critical system files, including but not "
#| "limited to the config files of bind, postfix, courier, squirrelmail and "
#| "proftpd."
msgid "" msgid ""
"You are currently trying to install AlternC on your computer. Be aware that " "You are currently trying to install AlternC on your computer. Be aware that "
"this package will overwrite critical system files, including but not limited " "this package will overwrite critical system files, including but not limited "
"to the config files of bind, postfix, courier, squirrelmail and proftpd." "to the config files of bind, postfix, dovecot, squirrelmail and proftpd."
msgstr "" msgstr ""
"Vous tes en train d'installer AlternC sur cet ordinateur. Comprenez que ce " "Vous tes en train d'installer AlternC sur cet ordinateur. Comprenez que ce "
"paquetage va craser plusieurs fichiers de configuration critiques, incluant, " "paquetage va craser plusieurs fichiers de configuration critiques, incluant, "

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: alternc@packages.debian.org\n" "Report-Msgid-Bugs-To: alternc@packages.debian.org\n"
"POT-Creation-Date: 2011-06-04 11:00+0200\n" "POT-Creation-Date: 2012-02-07 17:23+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -29,7 +29,7 @@ msgstr ""
msgid "" msgid ""
"You are currently trying to install AlternC on your computer. Be aware that " "You are currently trying to install AlternC on your computer. Be aware that "
"this package will overwrite critical system files, including but not limited " "this package will overwrite critical system files, including but not limited "
"to the config files of bind, postfix, courier, squirrelmail and proftpd." "to the config files of bind, postfix, dovecot, squirrelmail and proftpd."
msgstr "" msgstr ""
#. Type: boolean #. Type: boolean

View File

@ -26,7 +26,7 @@
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# #
SETUID=mail_add mail_del quota_edit quota_get mem_add mem_del SETUID=mail_add mail_del quota_edit quota_get mem_add mem_del
SCRIPTS=sqlbackup.sh rawstat.daily quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize SCRIPTS=sqlbackup.sh rawstat.daily quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php
LIBS=functions.sh functions_hosting.sh functions_dns.sh LIBS=functions.sh functions_hosting.sh functions_dns.sh
BIN=$(DESTDIR)/usr/lib/alternc/ BIN=$(DESTDIR)/usr/lib/alternc/

92
src/export_account.php Executable file
View File

@ -0,0 +1,92 @@
#!/usr/bin/php -q
<?php
/**
* Script permettant d'exporter la configuration d'un compte Alternc ainsi que les données associé
* A lancer par exemple avant une suppression de compte.
* Les seuls arguments necessaires sont l'iud du compte à exporter, ainsi que le repertoire ou le dump sera effectué.
* l'export ce fait sous l'arborescence <dir>/<login>/date/ ou les dumps de configuration sont déposées.
* Deux sous dossier sont ensuite crée : html ( dump des fichiers web et de la configuration du compte )
* et un dossier sql contenant toutes les bases de données de l'utilisateur.
*/
require("/var/alternc/bureau/class/config_nochk.php");
global $L_VERSION;
if(!chdir("/var/alternc/bureau")){
exit(1);
}
if($argc != 3 ){
echo "usage : export.php <uid> <directory>\n";
exit (1);
}
$my_id=$argv[1];
# TODO here test $my_id is numeric
if((intval($my_id))==0 || (intval($myid)==1)){
echo "bad argument: expecting a 4 digit IUD";
exit (1);
}
$dir=$argv[2];
echo "\n === Export of account $my_id === to $dir\n\n";
# Connect in this user
$admin->enabled=1;
$mem->su($my_id);
if(!is_dir($dir)){
if(!mkdir($dir)){
echo "creating dir : ".$dir." failed";
exit(1);
}
}
$dir.=$mem->user["login"]."/";
if(!is_dir($dir)){
if(!mkdir($dir)){
echo "creating dir : ".$dir." failed";
exit(1);
}
}
$timestamp=date("Y:m:d");
$dir.=$timestamp."/";
if(!is_dir($dir)){
if(!mkdir($dir)){
echo "creating dir : ".$dir." failed";
exit(1);
}
}
# Get the conf
$conf_user=Array();
$conf_user=$export->export_conf();
$file_conf=$dir."dump_conf_".date("H:i:s");
echo $file_conf;
$file=fopen($file_conf."dump","ab");
fputs($file,"dump of ::".$mem->user["login"]."\n");
fputs($file,"alternc version:".$L_VERSION."\n\n");
fputs($file,"<html><body>");
foreach($conf_user as $string){
fputs($file,$string);
}
fputs($file,"</html></body>");
fclose($file);
# Get the data
$export->export_data($dir);
$mem->unsu();
exit(0);
?>

View File

@ -1,5 +1,4 @@
#!/bin/bash -e #!/bin/bash -e
# #
# $Id: fixperms.sh,v 1.1 2005/08/29 19:21:31 benjamin Exp $ # $Id: fixperms.sh,v 1.1 2005/08/29 19:21:31 benjamin Exp $
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
@ -97,8 +96,8 @@ doone() {
# Delete existings ACL # Delete existings ACL
# Set the defaults acl on all the files # Set the defaults acl on all the files
setfacl -b -k -m d:g:alterncpanel:rw- -m d:u:$GID:rw- -m d:g:$GID:rw- \ setfacl -b -k -m d:g:alterncpanel:rwx -m d:u:$GID:rw- -m d:g:$GID:rw- \
-m g:alterncpanel:rw- -m u:$GID:rw- -m g:$GID:rw- \ -m g:alterncpanel:rwx -m u:$GID:rw- -m g:$GID:rw- \
-R "$REP" -R "$REP"
read GID LOGIN read GID LOGIN

View File

@ -1,17 +1,17 @@
#!/bin/bash #!/bin/bash
. /etc/alternc/local.sh . /etc/alternc/local.sh
# Set disk quota to an user # Set disk quota to an user
# Won't work over NFS # Won't work over NFS
MID=$1 MID=$1
SIZE=$2 SIZE=$2
AWK=/usr/bin/awk
QUOTA=/usr/sbin/setquota
if [ $# -ne 2 ] || [[ ! "$MID" =~ ^[0-9]+$ ]] || [[ ! "$SIZE" =~ ^[0-9]+$ ]]; then if [ $# -ne 2 ] || [[ ! "$MID" =~ ^[0-9]+$ ]] || [[ ! "$SIZE" =~ ^[0-9]+$ ]]; then
echo "Usage: quota_edit <uid> <size>" echo "Usage: quota_edit <uid> <size>"
echo "Edit the quota of the AlternC account having uid <uid> the the available space to <size>" echo "Edit the quota of the AlternC account having uid <uid> the the available space to <size>"
exit 1 exit 1
fi fi
DATA_PART=`$DF "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1 }'` DATA_PART=`df "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1; }'`
/usr/sbin/setquota -r -g $MID $SIZE $SIZE 0 0 $DATA_PART 2>/dev/null || echo "Group quota are not enabled on /var/alternc." >&2 `sudo $QUOTA -r -g $MID $SIZE $SIZE 0 0 $DATA_PART 2>/dev/null || echo "Group quota are not enabled on /var/alternc." >&2`

View File

@ -1,6 +1,5 @@
#!/bin/bash #!/bin/bash
. /etc/alternc/local.sh . /etc/alternc/local.sh
AWK=/usr/bin/awk AWK=/usr/bin/awk
DF=/bin/df DF=/bin/df
SED=/bin/sed SED=/bin/sed
@ -8,7 +7,7 @@ MOUNT=/bin/mount
QUOTA=/usr/bin/quota QUOTA=/usr/bin/quota
GREP=/bin/grep GREP=/bin/grep
WC=/usr/bin/wc WC=/usr/bin/wc
BLKID=/sbin/blkid
MID=$1 MID=$1
if [ "x$MID" == "x" ] ; then if [ "x$MID" == "x" ] ; then
@ -21,22 +20,36 @@ fi
# We look precisely on the HTML directory. Why ? because it's surely # We look precisely on the HTML directory. Why ? because it's surely
# the bigger one, and if someone separate it we need to look this one # the bigger one, and if someone separate it we need to look this one
# particulary. It should be interesting to cumulate quota of all mounted directory. # particulary. It should be interesting to cumulate quota of all mounted directory.
DATA_PART=`$DF "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1 }'` DATA_PART=`$DF "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1 }'`
# quota will give over NFS will print the partition using the full NFS name # quota will give over NFS will print the partition using the full NFS name
# (e.g. 10.0.0.1:/var/alternc) so we need to lookup first with mount # (e.g. 10.0.0.1:/var/alternc) so we need to lookup first with mount
# to convert DATA_PART if needed. # to convert DATA_PART if needed.
QUOTA_PART=`$MOUNT | $SED -n -e "s,\([^ ]*\) on ${DATA_PART} type nfs.*,\1,p"` QUOTA_PART=`$MOUNT | $SED -n -e "s,\([^ ]*\) on ${DATA_PART} type nfs.*,\1,p"`
if [ -z "$QUOTA_PART" ]; then if [ -z "$QUOTA_PART" ]; then
QUOTA_PART="$DATA_PART" QUOTA_PART="$DATA_PART"
#if the partition is an LVM one we need to adress the partition by its UUID
UUID=$( $BLKID | grep "$QUOTA_PART" | cut -f2 -s -d" " | sed 's/\(UUID="\)\(.*\)\(\"$\)/\2/')
fi fi
# Now we get the quota
val=$(quota -A -wg "$MID" |grep "$QUOTA_PART" | awk '{ print $2 "\n" $3; }')
# If the quota aren't activated, I return something anyway
# Now we get the quota
#first by testing if the partition is referenced by UUID
val=$(sudo quota -A -wg "$MID" |grep "$UUID" | awk '{ print $2 "\n" $3; }')
if [ -z "$val" ] ; then if [ -z "$val" ] ; then
val=$(sudo quota -A -wg "$MID" |grep "$QUOTA_PART" | awk '{ print $2 "\n" $3; }')
# If the quota aren't activated, I return something anyway
if [ -z "$val" ] ; then
echo -e "0\n0" echo -e "0\n0"
else
echo -e "0\n0"
fi
else else
echo -e "$val" echo -e "$val"
fi fi