From 20103063b328515e5fcc975428cee6f23197ba7f Mon Sep 17 00:00:00 2001 From: Steven Mondji-Lerider Date: Tue, 28 Feb 2012 14:48:45 +0000 Subject: [PATCH] =?UTF-8?q?ajout=20classe=20m=5Fexport=20+=20script=20expo?= =?UTF-8?q?rt=5Faccount=20afin=20de=20g=C3=A9n=C3=A9rer=20un=20export=20de?= =?UTF-8?q?=20compte.=20Correction=20de=20bugs=20divers.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 2 + bureau/admin/adm_quotadoedit.php | 2 +- bureau/class/m_bro.php | 75 ++++++++++++++++++-------- bureau/class/m_dom.php | 63 +++++++++++++--------- bureau/class/m_export.php | 38 +++++++++++++ bureau/class/m_ftp.php | 22 ++++---- bureau/class/m_hooks.php | 3 +- bureau/class/m_mail.php | 59 ++++++++++---------- bureau/class/m_mem.php | 22 +++++--- bureau/class/m_mysql.php | 92 +++++++++++++++++++++----------- bureau/class/m_quota.php | 16 +++--- bureau/class/m_sta2.php | 10 ++-- debian/changelog | 11 +++- debian/po/fr.po | 10 +++- debian/po/templates.pot | 4 +- src/Makefile | 2 +- src/export_account.php | 92 ++++++++++++++++++++++++++++++++ src/fixperms.sh | 5 +- src/quota_edit | 8 +-- src/quota_get | 23 ++++++-- 20 files changed, 402 insertions(+), 157 deletions(-) create mode 100644 bureau/class/m_export.php create mode 100755 src/export_account.php diff --git a/.gitattributes b/.gitattributes index 370d7003..da063ecc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -316,6 +316,7 @@ bureau/class/m_authip.php -text bureau/class/m_bro.php -text bureau/class/m_dom.php -text bureau/class/m_err.php -text +bureau/class/m_export.php -text bureau/class/m_ftp.php -text bureau/class/m_hooks.php -text bureau/class/m_hta.php -text @@ -465,6 +466,7 @@ src/alternc-dboptimize -text src/alternc-passwd -text src/alternc_reload -text src/du.pl -text +src/export_account.php -text src/fixperms.sh -text src/functions.sh -text src/functions_dns.sh -text diff --git a/bureau/admin/adm_quotadoedit.php b/bureau/admin/adm_quotadoedit.php index 2cf940b7..ab79372d 100644 --- a/bureau/admin/adm_quotadoedit.php +++ b/bureau/admin/adm_quotadoedit.php @@ -51,4 +51,4 @@ if ($submit) { } -?> \ No newline at end of file +?> diff --git a/bureau/class/m_bro.php b/bureau/class/m_bro.php index 04fb1c27..5e337877 100644 --- a/bureau/class/m_bro.php +++ b/bureau/class/m_bro.php @@ -329,16 +329,17 @@ class m_bro { global $db,$cuid,$err; $file=ssla($file); $absolute=$this->convertabsolute($dir."/".$file,0); - if ($absolute && !file_exists($absolute)) { - if (!@mkdir($absolute,00777)) { - $err->raise("bro",4); - return false; - } - $db->query("UPDATE browser SET crff=1 WHERE uid='$cuid';"); - return true; + echo "$absolute"; + if ($absolute && (!file_exists($absolute))) { + if (!mkdir($absolute,00777)) { + $err->raise("bro",4); + return false; + } + $db->query("UPDATE browser SET crff=1 WHERE uid='$cuid';"); + return true; } else { - $err->raise("bro",1); - return false; + $err->raise("bro",1); + return false; } } @@ -357,6 +358,7 @@ class m_bro { $err->raise("bro",1); return false; } + print_r($absolute); if (!file_exists($absolute)) { if (!@touch($absolute)) { $err->raise("bro",3); @@ -918,29 +920,56 @@ class m_bro { 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 +* +*/ - - /* ----------------------------------------------------------------- */ - /** - * Exporte toutes les informations ftp du compte AlternC - * @access private - * EXPERIMENTAL 'sid' function ;) - */ - function alternc_export() { +function alternc_export_conf() { global $db,$err; - $err->log("bro","export"); - $str="\n"; + $err->log("bro","export_conf"); + $str="\n"; $pref=$this->GetPrefs(); + + $i=1; foreach ($pref as $k=>$v) { - $str.=" \n"; - $str.=" <".$k.">".xml_entities($v)."\n"; - $str.=" \n"; + if (($i % 2)==0){ + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + } + $i++; } - $str.="\n"; + $str.="
Browser
".$k."".$v."
\n"; 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 */ diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index 17a3dd83..5a33ab82 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -1279,36 +1279,51 @@ class m_dom { } else return false; } - - /* ----------------------------------------------------------------- */ - /** - * Exporte toutes les informations domaine du compte. - * @access private - * EXPERIMENTAL 'sid' function ;) - */ - function alternc_export() { +/*---------------------------------------------------------------------*/ +/** + * Returns the global domain(s) configuration(s) of a particular user + * No parameters needed + * +**/ + function alternc_export_conf() { global $db,$err; $err->log("dom","export"); $this->enum_domains(); - $str="\n"; + $str=" \n"; foreach ($this->domains as $d) { - $str.=" \n ".xml_entities($d)."\n"; - $s=$this->get_domain_all($d); - $str.=" ".xml_entities($s[dns])."\n"; - $str.=" ".xml_entities($s[mx])."\n"; - $str.=" ".xml_entities($s[mail])."\n"; - if (is_array($s[sub])) { - foreach ($s[sub] as $sub) { - $str.=" "; - $str.="".xml_entities($sub[name]).""; - $str.="".xml_entities($sub[dest]).""; - $str.="".xml_entities($sub[type]).""; - $str.="\n"; + $str.=""; + $str.=""; + $this->lock(); + $s=$this->get_domain_all($d); + $this->unlock(); + if(empty($s[dns])){ + $s[dns]="non"; } - } - $str.=" \n"; + $str.=" \n"; + + if(empty($s[mx])){ + $s[mx]="non"; + } + $str.="\n"; + + if(empty($s[mail])){ + $s[mail]="non"; + } + $str.="\n"; + if (is_array($s[sub])) { + $str.="
Domaines
DomaineDNSMXmail
".$d."".$s[dns]."".$s[mx]."".$s[mail]."
"; + + foreach ($s[sub] as $sub) { + $str.=""; + $str.=""; + $str.=""; + } + + $str.="\n"; + } + $str.="
nom sous domainedestinationtype
".$sub["enable"]." ".$sub["dest"]." ".$sub["type"]."
\n"; } - $str.="
\n"; + $str.="\n"; return $str; } diff --git a/bureau/class/m_export.php b/bureau/class/m_export.php new file mode 100644 index 00000000..81694784 --- /dev/null +++ b/bureau/class/m_export.php @@ -0,0 +1,38 @@ +invoke('alternc_export_conf'); + return $conf; + } + +/** le repertoire de base est passé en paramettre puis en construit une arborescence de la forme +//invoke('alternc_export_data', Array($dir)); + } + +}// export Class end +?> + + + + + + + + diff --git a/bureau/class/m_ftp.php b/bureau/class/m_ftp.php index 063371c4..a85ba53d 100644 --- a/bureau/class/m_ftp.php +++ b/bureau/class/m_ftp.php @@ -95,7 +95,8 @@ class m_ftp { $r[]=array( "id"=>$db->f("id"), "login"=>$db->f("name"), - "dir"=>$match[1] + //"dir"=>$match[1] + "dir"=>$db->f("homedir") ); } return $r; @@ -378,19 +379,20 @@ class m_ftp { * @access private * EXPERIMENTAL 'sid' function ;) */ - function alternc_export() { + function alternc_export_conf() { global $db,$err; $err->log("ftp","export"); $f=$this->get_list(); - $str="\n"; - foreach ($f as $d) { - $str.=" \n"; - $str.=" ".xml_entities($s[login])."\n"; - $str.=" ".xml_entities($s[pass])."\n"; - $str.=" ".xml_entities($s[dir])."\n"; - $str.=" \n"; + $str="\n"; + foreach ($f as $d=>$v) { + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; } - $str.="\n"; + $str.="
FTP
".$v["id"]."".($v["encrypted_password"])."".($v["login"])."".($v["dir"])."\n"; + $str.="
\n"; return $str; } diff --git a/bureau/class/m_hooks.php b/bureau/class/m_hooks.php index 84648a2c..d9287bd8 100644 --- a/bureau/class/m_hooks.php +++ b/bureau/class/m_hooks.php @@ -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 * $hparam tableau contenant les parametres * $hclass tableau contenant les classes spécifique qu'on veux appeler (si on veux pas TOUTE les appeler) diff --git a/bureau/class/m_mail.php b/bureau/class/m_mail.php index 633593cc..20db0c3f 100644 --- a/bureau/class/m_mail.php +++ b/bureau/class/m_mail.php @@ -751,44 +751,45 @@ class m_mail { global $db,$err; $err->log("mail","export"); $domain=$this->enum_domains(); - $str="\n"; + $str="\n"; $tmpfile=$tmpdir."/mail_filelist.txt"; $f=fopen($tmpfile,"wb"); $onepop=false; foreach ($domain as $d) { - $str.=" \n ".xml_entities($d)."\n"; - $s=$this->enum_doms_mails($d); - unset($s["count"]); - if (count($s)) { - foreach($s as $e) { - $str.="
\n"; - $str.=" ".xml_entities($e["mail"])."\n"; - $str.=" ".xml_entities($e["pop"])."\n"; - $acc=explode("\n",$e["alias"]); - foreach($acc as $f) { - $f=trim($f); - if ($f) { - $str.=" ".xml_entities($f)."\n"; - } - } - if ($e["pop"]) { - $db->query("SELECT path FROM mail_users WHERE alias='".str_replace("@","_",$e["mail"])."';"); - if ($db->next_record()) { - fputs($f,$db->Record["path"]."\n"); - $onepop=true; - } - } - $str.="
\n"; - } + $str.="
\n \n"; + $s=$this->enum_doms_mails($d); + unset($s["count"]); + if (count($s)) { + foreach($s as $e) { + $str.="
Mail
".($d)."
\n"; + $str.=" \n"; + $str.=" \n"; + $acc=explode("\n",$e["alias"]); + foreach($acc as $f) { + $f=trim($f); + $str.="
    "; + if ($f) { + $str.="
  • ".($f)."
  • \n
"; + } + } + if ($e["pop"]) { + $db->query("SELECT path FROM mail_users WHERE alias='".str_replace("@","_",$e["mail"])."';"); + if ($db->next_record()) { + fputs($f,$db->Record["path"]."\n"); + $onepop=true; + } + } + $str.=" \n"; + } } - $str.=" \n"; + $str.=" \n"; } - $str.="\n"; + $str.="
".($e["mail"])."".($e["pop"])."
\n"; fclose($f); - if ($onepop) { + /*if ($onepop) { // Now do the tarball of all pop accounts : exec("/bin/tar -czf ".escapeshellarg($tmpdir."/mail.tar.gz")." -T ".escapeshellarg($tmpfile)); - } + }*/ @unlink($tmpfile); return $str; } diff --git a/bureau/class/m_mem.php b/bureau/class/m_mem.php index d7f78aaa..fb25bebf 100644 --- a/bureau/class/m_mem.php +++ b/bureau/class/m_mem.php @@ -550,17 +550,23 @@ Cordialement. /** * Exports all the personnal user related information for an account. * @access private - * EXPERIMENTAL 'sid' function ;) */ - function alternc_export($tmpdir) { + function alternc_export_conf() { global $db,$err; $err->log("mem","export"); - $str="\n"; - - foreach ($this->user as $k=>$v) { - $str.=" <$k>".xml_entities($v)."\n"; - } - $str.="\n"; + $str="\n"; + $users=$this->user; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.="
Member
".$users["uid"]."
".$users["login"]."
".$users["enabled"]."
".$users["su"]."
".$users["pass"]."
".$users["mail"]."
".$users["created"]."
".$users["lastip"]."
".$users["lastlogin"]."
".$users["lastfail"]."
\n"; return $str; } diff --git a/bureau/class/m_mysql.php b/bureau/class/m_mysql.php index b4ff09e4..465f166f 100644 --- a/bureau/class/m_mysql.php +++ b/bureau/class/m_mysql.php @@ -35,7 +35,7 @@ */ class DB_users extends DB_Sql { - var $Host,$HumanHostname,$User,$Password; + var $Host,$HumanHostname,$User,$Password,$client; /** * Creator @@ -81,15 +81,16 @@ class DB_users extends DB_Sql { } } - # Create the object $this->Host = $host; + $this->client = $GLOBALS['L_MYSQL_CLIENT']; $this->User = $user; $this->Password = $password; // TODO BUG BUG BUG // 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. - $this->Database = "mysql"; + //$this->Database = "mysql"; + $this->Database = "alternc"; $this->HumanHostname = $human_hostname; } @@ -219,13 +220,15 @@ class m_mysql { $pa=addslashes($db->f("pass")); } 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 $db->query("INSERT INTO db (uid,login,pass,db,bck_mode) VALUES ('$cuid','$lo','$pa','$dbname',0);"); // give everything but GRANT on db.* // 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; } else { + $err->log("mysql","add_db",$dbn); $err->raise("mysql",3); return false; } @@ -257,7 +260,7 @@ class m_mysql { $this->dbus->query("DROP DATABASE `$dbname`;"); $db->query("SELECT COUNT(*) AS cnt FROM db WHERE uid='$cuid';"); $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) { $this->dbus->query("DELETE FROM mysql.user WHERE User='".$login."';"); $this->dbus->query("FLUSH PRIVILEGES;"); @@ -344,7 +347,7 @@ class m_mysql { // Update all the "pass" fields for this user : $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; } @@ -389,7 +392,7 @@ class m_mysql { // OK, creation now... $db->query("INSERT INTO db (uid,login,pass,db) VALUES ('$cuid','".$login."','$password','".$dbname."');"); // 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."`;"); 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) - $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 $db->query("INSERT INTO dbusers (uid,name) VALUES($cuid,'$user');"); return true; @@ -564,8 +567,7 @@ class m_mysql { return false; // The error has been raised by checkPolicy() } } - - $this->dbus->query("SET PASSWORD FOR '$user'@'$this->client' = PASSWORD('$pass')"); + $this->dbus->query("SET PASSWORD FOR ".$user."@".$this->dbus->client." = PASSWORD(".$pass.")"); return true; } @@ -593,9 +595,9 @@ class m_mysql { $login=$db->f("name"); // 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("DELETE FROM mysql.db 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->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->dbus->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("DELETE FROM dbusers WHERE uid='$cuid' AND name='".$mem->user["login"]."_$user';"); return true; @@ -616,7 +618,7 @@ class m_mysql { $dblist=$this->get_dblist(); for ( $i=0 ; $idbus->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()) $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 @@ -682,10 +684,10 @@ class m_mysql { // We reset all user rights on this DB : $this->dbus->query("SELECT * FROM mysql.db WHERE User = '$usern' AND Db = '$dbname';"); 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 ){ $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"); return TRUE; @@ -761,36 +763,62 @@ class m_mysql { * @access private * EXPERIMENTAL 'sid' function ;) */ - function alternc_export($tmpdir) { + function alternc_export_conf() { //TODO don't work with separated sql server for dbusers global $db,$err,$cuid; $err->log("mysql","export"); $db->query("SELECT login, pass, db, bck_mode, bck_dir, bck_history, bck_gzip FROM db WHERE uid='$cuid';"); + $str.=""; if ($db->next_record()) { - $str="\n"; - $str.=" ".xml_entities($db->Record["login"]).""; - $str.=" ".xml_entities($db->Record["pass"]).""; + $str.="\n"; + $str.=" "; + $str.=" "; + $str.="\n"; do { - // Do the dump : $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.=" \n"; - $str.=" ".xml_entities($db->Record["db"])."\n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; if ($s["bck_mode"]!=0) { - $str.=" \n"; - $str.=" ".xml_entities($db->Record["bck_mode"])."\n"; - $str.=" ".xml_entities($db->Record["bck_dir"])."\n"; - $str.=" ".xml_entities($db->Record["bck_history"])."\n"; - $str.=" ".xml_entities($db->Record["bck_gzip"])."\n"; - $str.=" \n"; + $str.="
MyQSL
loginpass
".$db->Record["login"]."".$db->Record["pass"]."
".($db->Record["db"])."".($db->Record["pass"])."
\n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.=" \n"; + $str.="
".($db->Record["bck_mode"])."".($db->Record["bck_dir"])."".($db->Record["bck_history"])."".($db->Record["bck_gzip"])."
\n"; } - $str.=" \n"; + $str.=" \n"; } while ($db->next_record()); - $str.="\n"; + $str.="\n"; } 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 */ diff --git a/bureau/class/m_quota.php b/bureau/class/m_quota.php index 3c51eef4..80ce96f5 100644 --- a/bureau/class/m_quota.php +++ b/bureau/class/m_quota.php @@ -176,9 +176,12 @@ class m_quota { if (isset($this->disk[$ressource])) { // It's a disk resource, update it with shell command 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 : 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); return false; } @@ -362,17 +365,18 @@ class m_quota { * @access private * EXPERIMENTAL 'sid' function ;) */ - function alternc_export($tmpdir) { + function alternc_export_conf($tmpdir) { global $db,$err; $err->log("quota","export"); - $str="\n"; + $str="\n"; $q=$this->getquota(); foreach ($q as $k=>$v) { - $str.=" \n ".xml_entities($k)."\n"; - $str.=" ".xml_entities($v)."\n \n"; + $str.=" \n \n"; + $str.=" \n \n"; + $str.=" \n \n"; } - $str.="\n"; + $str.="
QUOTA
".($k)."".($v[u])."".($v[t])."
\n"; return $str; } diff --git a/bureau/class/m_sta2.php b/bureau/class/m_sta2.php index df26cd42..fa680587 100644 --- a/bureau/class/m_sta2.php +++ b/bureau/class/m_sta2.php @@ -290,15 +290,15 @@ class m_sta2 { * @access private * EXPERIMENTAL 'sid' function ;) */ - function alternc_export($tmpdir) { + function alternc_export_conf() { global $db,$err; $err->log("sta2","export"); - $this->get_list_raw(); + $f=$this->get_list_raw(); $str="\n"; foreach ($f as $d) { $str.=" \n"; - $str.=" ".xml_entities($s[hostname])."\n"; - $str.=" ".xml_entities($s[folder])."\n"; + $str.=" ".($s[hostname])."\n"; + $str.=" ".($s[folder])."\n"; $str.=" \n"; } $str.="\n"; @@ -308,4 +308,4 @@ class m_sta2 { } /* CLASSE m_sta2 */ -?> \ No newline at end of file +?> diff --git a/debian/changelog b/debian/changelog index 6767d808..4fda4a11 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Tue, 28 Feb 2012 14:57:48 +0100 + alternc (1.1) stable; urgency=low * Dev in progress * New class : access security. Allow to restrict some function to specific IP or subnet * Access security management on the ftp account. - -- Alan Garcia Wed, 25 May 2011 09:24:30 +0200 + -- Alan Garcia (nickname) Wed, 25 May 2011 09:24:30 +0200 alternc (1.0.3) stable; urgency=high * Bugfix : the 'connect' button in the list of installed domains didn't work, make it work diff --git a/debian/po/fr.po b/debian/po/fr.po index 82d11fc2..2edc86e6 100644 --- a/debian/po/fr.po +++ b/debian/po/fr.po @@ -15,7 +15,7 @@ msgid "" msgstr "" "Project-Id-Version: AlternC 0.9.5\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" "Last-Translator: Benjamin Sonntag \n" "Language-Team: Team AlternC \n" @@ -33,10 +33,16 @@ msgstr "Etes-vous CERTAIN de vouloir installer AlternC sur cet ordinateur ?" #. Type: boolean #. Description #: ../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 "" "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." +"to the config files of bind, postfix, dovecot, squirrelmail and proftpd." msgstr "" "Vous tes en train d'installer AlternC sur cet ordinateur. Comprenez que ce " "paquetage va craser plusieurs fichiers de configuration critiques, incluant, " diff --git a/debian/po/templates.pot b/debian/po/templates.pot index c9ca01c5..136cf221 100644 --- a/debian/po/templates.pot +++ b/debian/po/templates.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -29,7 +29,7 @@ msgstr "" 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." +"to the config files of bind, postfix, dovecot, squirrelmail and proftpd." msgstr "" #. Type: boolean diff --git a/src/Makefile b/src/Makefile index 3035ad3e..51196621 100644 --- a/src/Makefile +++ b/src/Makefile @@ -26,7 +26,7 @@ # ---------------------------------------------------------------------- # 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 BIN=$(DESTDIR)/usr/lib/alternc/ diff --git a/src/export_account.php b/src/export_account.php new file mode 100755 index 00000000..19d08ad7 --- /dev/null +++ b/src/export_account.php @@ -0,0 +1,92 @@ +#!/usr/bin/php -q +//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 \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,""); +foreach($conf_user as $string){ + fputs($file,$string); +} +fputs($file,""); +fclose($file); + + + +# Get the data +$export->export_data($dir); +$mem->unsu(); +exit(0); + +?> diff --git a/src/fixperms.sh b/src/fixperms.sh index 6932c2d7..6a71aa48 100755 --- a/src/fixperms.sh +++ b/src/fixperms.sh @@ -1,5 +1,4 @@ #!/bin/bash -e - # # $Id: fixperms.sh,v 1.1 2005/08/29 19:21:31 benjamin Exp $ # ---------------------------------------------------------------------- @@ -97,8 +96,8 @@ doone() { # Delete existings ACL # 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- \ - -m g:alterncpanel:rw- -m u:$GID:rw- -m g:$GID:rw- \ + setfacl -b -k -m d:g:alterncpanel:rwx -m d:u:$GID:rw- -m d:g:$GID:rw- \ + -m g:alterncpanel:rwx -m u:$GID:rw- -m g:$GID:rw- \ -R "$REP" read GID LOGIN diff --git a/src/quota_edit b/src/quota_edit index d0a39a52..7e36d4d5 100755 --- a/src/quota_edit +++ b/src/quota_edit @@ -1,17 +1,17 @@ #!/bin/bash . /etc/alternc/local.sh - # Set disk quota to an user # Won't work over NFS MID=$1 SIZE=$2 - +AWK=/usr/bin/awk +QUOTA=/usr/sbin/setquota if [ $# -ne 2 ] || [[ ! "$MID" =~ ^[0-9]+$ ]] || [[ ! "$SIZE" =~ ^[0-9]+$ ]]; then echo "Usage: quota_edit " echo "Edit the quota of the AlternC account having uid the the available space to " exit 1 fi -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 +DATA_PART=`df "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1; }'` +`sudo $QUOTA -r -g $MID $SIZE $SIZE 0 0 $DATA_PART 2>/dev/null || echo "Group quota are not enabled on /var/alternc." >&2` diff --git a/src/quota_get b/src/quota_get index 50e3fac8..372dcd90 100755 --- a/src/quota_get +++ b/src/quota_get @@ -1,6 +1,5 @@ #!/bin/bash . /etc/alternc/local.sh - AWK=/usr/bin/awk DF=/bin/df SED=/bin/sed @@ -8,7 +7,7 @@ MOUNT=/bin/mount QUOTA=/usr/bin/quota GREP=/bin/grep WC=/usr/bin/wc - +BLKID=/sbin/blkid MID=$1 if [ "x$MID" == "x" ] ; then @@ -21,22 +20,36 @@ fi # 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 # 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 }'` # 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 # to convert DATA_PART if needed. + QUOTA_PART=`$MOUNT | $SED -n -e "s,\([^ ]*\) on ${DATA_PART} type nfs.*,\1,p"` + if [ -z "$QUOTA_PART" ]; then 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 -# 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 + 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" + else + echo -e "0\n0" + fi + else echo -e "$val" fi