38 $db->query(
"select db_servers.* from db_servers, membres where membres.uid= ? and membres.db_server_id=db_servers.id;", array(
$cuid));
39 if (!
$db->next_record()) {
40 $msg->raise(
"ERROR",
'db_user', _(
"There are no databases in db_servers for this user. Please contact your administrator."));
45 $this->HumanHostname =
$db->f(
'name');
46 $this->Host =
$db->f(
'host');
47 $this->User =
$db->f(
'login');
48 $this->Password =
$db->f(
'password');
49 $this->Client =
$db->f(
'client');
50 $this->Database =
"mysql";
52 parent::__construct(
"mysql",
$db->f(
'host'),
$db->f(
'login'),
$db->f(
'password') );
72 variable_get(
'sql_allow_users_backups', 1,
'Set 1 to allow users to configure backup of their databases, 0 if you want do disable this feature. Warning: it will not stop configured backup made by sqlbackup.sh');
83 $db->query(
"select d.*, IFNULL(count(m.uid),0) as nb_users from db_servers d left join membres m on d.id = m.db_server_id group by d.id,m.db_server_id order by d.name,d.id;");
85 while (
$db->next_record()) {
94 $q = $quota->getquota(
"mysql");
97 'title' => _(
"MySQL"),
98 'ico' =>
'images/mysql.png',
104 $obj[
'links'][] = array(
105 'txt' => _(
"Databases"),
106 'url' =>
"sql_list.php",
108 $obj[
'links'][] = array(
109 'txt' => _(
"MySQL Users"),
110 'url' =>
"sql_users_list.php",
113 $obj[
'links'][] = array(
114 'txt' => _(
"PhpMyAdmin"),
115 'url' =>
"sql_pma_sso.php",
116 'target' =>
'_blank',
127 return array(
"mysql" =>
"MySQL users");
140 $msg->debug(
"mysql",
"get_dblist");
142 $db->query(
"SELECT login,pass,db, bck_mode, bck_dir FROM db WHERE uid= ? ORDER BY db;", array(
$cuid));
144 while (
$db->next_record()) {
146 $c[] = array(
"db" =>
$db->f(
"db"),
"name" =>
$db->f(
'db'),
"bck" =>
$db->f(
"bck_mode"),
"dir" =>
$db->f(
"bck_dir"),
"login" =>
$db->f(
"login"),
"pass" =>
$db->f(
"pass"));
159 $msg->log(
"mysql",
"php_myadmin_connect");
160 $db->query(
"SELECT count(0) as count from db where uid = ?;", array(
$cuid));
162 if (
$db->f(
'count') == 0) {
163 $msg->raise(
"ERROR",
"mysql", _(
"Cannot connect to PhpMyAdmin, no databases for user {$cuid}"));
166 $db->query(
"SELECT dbu.name,dbu.password, dbs.host FROM dbusers dbu, db_servers dbs, membres m WHERE dbu.uid= ? and enable='ADMIN' and dbs.id=m.db_server_id and m.uid= ? ;", array(
$cuid,
$cuid));
167 if (!
$db->num_rows()) {
168 $msg->raise(
"ERROR",
"mysql", _(
"Cannot connect to PhpMyAdmin, no admin user for uid {$cuid}"));
173 "login" =>
$db->f(
"name"),
174 "pass" =>
$db->f(
"password"),
175 "host" =>
$db->f(
"host")
197 $msg->debug(
"mysql",
"get_mysql_details");
198 $pos = strpos($dbn,
'_');
199 if ($pos ===
false) {
202 $dbncomp = explode(
'_', $dbn);
207 $db->query(
"SELECT login,pass,db, bck_mode, bck_gzip, bck_dir, bck_history FROM db WHERE uid= ? AND db= ?;", array(
$cuid, $dbname));
208 if (!
$db->num_rows()) {
209 $msg->raise(
"ERROR",
"mysql", _(
"Database %s not found"), $dbn);
210 return array(
"enabled" =>
false);
214 return array(
"enabled" =>
true,
"login" =>
$db->f(
"login"),
"db" =>
$db->f(
"db"),
"name" => $dbn,
"bck" =>
$db->f(
"bck_mode"),
"dir" => substr(
$db->f(
"bck_dir"), strlen(
$root)),
"size" => $size,
"pass" =>
$db->f(
"pass"),
"history" =>
$db->f(
"bck_history"),
"gzip" =>
$db->f(
"bck_gzip"));
226 $msg->log(
"mysql",
"add_db", $dbn);
228 if (!$quota->cancreate(
"mysql")) {
229 $msg->raise(
"ERROR",
"mysql", _(
"Your databases quota is over. You cannot create more databases"));
232 $pos = strpos($dbn,
'_');
233 if ($pos ===
false) {
236 $dbncomp = explode(
'_', $dbn);
240 $msg->raise(
"ERROR",
"mysql", _(
"Database can't have empty suffix"));
244 if (!preg_match(
"#^[0-9a-z]*$#", $dbn)) {
245 $msg->raise(
"ERROR",
"mysql", _(
"Database name can contain only letters and numbers"));
250 if (strlen($dbname) >
$len) {
251 $msg->raise(
"ERROR",
"mysql", _(
"Database name cannot exceed %d characters"),
$len);
254 $db->query(
"SELECT * FROM db WHERE db= ? ;", array($dbname));
255 if (
$db->num_rows()) {
256 $msg->raise(
"ERROR",
"mysql", _(
"Database %s already exists"), $dbn);
262 if (strlen($dbname) <=
$len) {
263 $db->query(
"SELECT name from dbusers where name= ? and enable='ACTIVATED' ;", array($dbname));
264 if (!
$db->num_rows()) {
266 $c=$admin->listPasswordPolicies();
270 if ($this->
add_user($dbn, $password_user, $password_user)) {
271 $msg->raise(
"INFO",
"mysql",
"L'utilisateur '$dbname' a été créé et les droits sur cette base de données lui ont été attribué.");
273 $msg->raise(
"ALERT",
"mysql",
"L'utilisateur '$dbname' n'a pas pu être créé.<br>Allez à la page 'Utilisateurs Mysql' pour en créer manuellement.<br>Et n'oubliez pas de lui donner les droits sur la base de données.");
277 $msg->raise(
"ALERT",
"mysql",
"L'utilisateur '$dbname' n'a pas été automatiquement créé car il dépasse la limite de taille pour les utilisateurs qui est à $len<br>Allez à la page 'Utilisateurs Mysql' pour en créer un avec le nom que vous voulez.<br>Et n'oubliez pas de lui donner les droits sur la base de données.");
281 $db->query(
"SELECT * FROM dbusers WHERE uid= ? AND enable='ADMIN';", array(
$cuid));
282 if (
$db->num_rows()) {
284 $myadm =
$db->f(
"name");
287 $msg->raise(
"ERROR",
"mysql", _(
"There is a problem with the special PhpMyAdmin user. Contact the administrator"));
292 if ($this->dbus->exec(
"CREATE DATABASE $dbname;")) {
293 $msg->log(
"mysql",
"add_db",
"Success: ".$dbn);
295 $db->query(
"INSERT INTO db (uid,login,pass,db,bck_mode) VALUES (?, ?, ?, ? ,0)", array(
$cuid, $myadm,
$password, $dbname));
297 $dbname = str_replace(
'_',
'\_', $dbname);
299 if (!empty($password_user)) {
300 $this->
grant($dbname, $dbuser,
"ALL PRIVILEGES", $password_user);
302 $this->dbus->query(
"FLUSH PRIVILEGES;");
305 $msg->log(
"mysql",
"add_db",
"Error: ".$dbn);
306 $msg->raise(
"ERROR",
"mysql", _(
"An error occured. The database could not be created"));
320 $msg->log(
"mysql",
"del_db", $dbname);
321 $db->query(
"SELECT uid FROM db WHERE db= ?;", array($dbname));
322 if (!
$db->next_record()) {
323 $msg->raise(
"ERROR",
"mysql", _(
"The database was not found. I can't delete it"));
328 $db->query(
"DELETE FROM size_db WHERE db= ?;", array($dbname));
329 $db->query(
"DELETE FROM db WHERE uid= ? AND db= ? ;", array(
$cuid, $dbname));
330 $this->dbus->query(
"DROP DATABASE $dbname;");
332 $db_esc = str_replace(
'_',
'\_', $dbname);
333 $this->dbus->query(
"DELETE FROM mysql.db WHERE Db= ? ;", array($db_esc));
336 $this->dbus->query(
"select User from mysql.db where User= ? ;", array($dbname));
337 if (($this->dbus->num_rows()) == 0) {
339 $this->
del_user($dbname,
false,
true );
356 $msg->log(
"mysql",
"put_mysql_backup");
359 $msg->raise(
"ERROR",
"mysql", _(
"User aren't allowed to configure their backups"));
363 $pos = strpos($dbn,
'_');
364 if ($pos ===
false) {
367 $dbncomp = explode(
'_', $dbn);
371 if (!preg_match(
"#^[0-9a-z]*$#", $dbn)) {
372 $msg->raise(
"ERROR",
"mysql", _(
"Database name can contain only letters and numbers"));
375 $db->query(
"SELECT * FROM db WHERE uid= ? AND db= ? ;", array(
$cuid, $dbname));
376 if (!
$db->num_rows()) {
377 $msg->raise(
"ERROR",
"mysql", _(
"Database %s not found"), $dbn);
381 $bck_mode = intval($bck_mode);
382 $bck_history = intval($bck_history);
392 $msg->raise(
"ALERT",
"mysql", _(
"You have to choose how many backups you want to keep"));
395 if (($bck_dir =
$bro->convertabsolute($bck_dir, 0)) ===
false) {
396 $msg->raise(
"ERROR",
"mysql", _(
"Directory does not exist"));
399 $db->query(
"UPDATE db SET bck_mode= ? , bck_history= ?, bck_gzip= ?, bck_dir= ? WHERE uid= ? AND db= ? ;", array($bck_mode, $bck_history, $bck_gzip, $bck_dir,
$cuid, $dbname));
411 $msg->log(
"mysql",
"put_mysql_details");
412 $db->query(
"SELECT * FROM db WHERE uid= ?;", array(
$cuid));
413 if (!
$db->num_rows()) {
414 $msg->raise(
"ERROR",
"mysql", _(
"Database not found"));
421 $msg->raise(
"ERROR",
"mysql", _(
"The password is mandatory"));
427 $msg->raise(
"ERROR",
"mysql", _(
"MySQL password cannot exceed %d characters"),
$len);
432 if (is_callable(array($admin,
"checkPolicy"))) {
440 $this->dbus->query(
"SET PASSWORD FOR " .
$login .
"@" . $this->dbus->Client .
" = PASSWORD(?);", array(
$password));
453 function grant($base,
$user, $rights =
null, $pass =
null, $table =
'*') {
455 $msg->log(
"mysql",
"grant", $base .
"-" . $rights .
"-" .
$user);
457 if (!preg_match(
"#^[0-9a-z_\\*\\\\]*$#", $base)) {
458 $msg->raise(
"ERROR",
"mysql", _(
"Database name can contain only letters and numbers"));
460 }
elseif (!$this->dbus->query(
"select db from db where db= ?;", array($base))) {
461 $msg->raise(
"ERROR",
"mysql", _(
"Database not found"));
465 if ($rights ==
null) {
466 $rights =
'ALL PRIVILEGES';
467 }
elseif (!preg_match(
"#^[a-zA-Z,\s]*$#", $rights)) {
468 $msg->raise(
"ERROR",
"mysql", _(
"Databases rights are not correct"));
472 if (!preg_match(
"#^[0-9a-z]#",
$user)) {
473 $msg->raise(
"ERROR",
"mysql", _(
"The username can contain only letters and numbers."));
476 $db->query(
"select name from dbusers where name= ? ;", array(
$user));
478 if (!
$db->num_rows()) {
479 $msg->raise(
"ERROR",
"mysql", _(
"Database user not found"));
483 $grant =
"grant " . $rights .
" on `" . $base .
"`." . $table .
" to " .
$db->quote(
$user) .
"@" .
$db->quote($this->dbus->Client);
486 $grant .=
" identified by " .
$db->quote($pass) .
";";
491 if (!$this->dbus->query($grant)) {
492 $msg->raise(
"ERROR",
"mysql", _(
"Could not grant rights"));
509 $msg->raise(
"ERROR",
"mysql", _(
"No file specified"));
515 if (!($fi =
$bro->convertabsolute($file, 0))) {
516 $msg->raise(
"ERROR",
"mysql", _(
"File not found"));
519 if (!file_exists($fi)) {
520 $msg->raise(
"ERROR",
"mysql", _(
"File not found"));
524 if (substr($fi, -3) ==
".gz") {
525 $exe =
"/bin/gzip -d -c <" . escapeshellarg($fi) .
" | /usr/bin/mysql -h" . escapeshellarg($this->dbus->Host) .
" -u" . escapeshellarg(
$r[
"login"]) .
" -p" . escapeshellarg(
$r[
"pass"]) .
" " . escapeshellarg(
$r[
"db"]);
526 }
elseif (substr($fi, -4) ==
".bz2") {
527 $exe =
"/usr/bin/bunzip2 -d -c <" . escapeshellarg($fi) .
" | /usr/bin/mysql -h" . escapeshellarg($this->dbus->Host) .
" -u" . escapeshellarg(
$r[
"login"]) .
" -p" . escapeshellarg(
$r[
"pass"]) .
" " . escapeshellarg(
$r[
"db"]);
529 $exe =
"/usr/bin/mysql -h" . escapeshellarg($this->dbus->Host) .
" -u" . escapeshellarg(
$r[
"login"]) .
" -p" . escapeshellarg(
$r[
"pass"]) .
" " . escapeshellarg(
$r[
"db"]) .
" <" . escapeshellarg($fi);
536 passthru($exe, $ret);
540 echo
"</pre></code>";
556 $this->dbus->query(
"SHOW TABLE STATUS FROM $dbname;");
558 while ($this->dbus->next_record()) {
559 $size += $this->dbus->f(
'Data_length') + $this->dbus->f(
'Index_length');
560 if ($this->dbus->f(
'Engine') !=
'InnoDB') {
561 $size += $this->dbus->f(
'Data_free');
573 $msg->debug(
"mysql",
"get_userslist");
576 $db->query(
"SELECT name FROM dbusers WHERE uid= ? and enable not in ('ADMIN','HIDDEN') ORDER BY name;", array(
$cuid));
578 $db->query(
"SELECT name FROM dbusers WHERE uid= ? ORDER BY name;", array(
$cuid));
580 while (
$db->next_record()) {
581 $pos = strpos(
$db->f(
"name"),
"_");
582 if ($pos ===
false) {
583 $c[] = array(
"name" => (
$db->f(
"name")));
585 $c[] = array(
"name" => (
$db->f(
"name")));
596 $msg->debug(
"mysql",
"getdefaults");
600 $dbn = str_replace(
'_',
'\_', $dbn);
601 $this->dbus->query(
"Select * from mysql.db where Db= ? and User!= ? ;", array($dbn,
$cuid.
"_myadm"));
603 if (!$this->dbus->num_rows()) {
604 $msg->raise(
"ERROR",
"mysql",_(
"Database not found"));
608 $listRights = array(
'Select',
'Insert',
'Update',
'Delete',
'Create',
'Drop',
'References',
'Index',
'Alter',
'Create_tmp_table',
'Lock_tables',
'Create_view',
'Show_view',
'Create_routine',
'Alter_routine',
'Execute',
'Event',
'Trigger');
609 while ($this->dbus->next_record()) {
612 $variable = $this->dbus->Record;
614 $dbu = $variable[
'User'];
616 $rTmp[
'Host'] = $this->dbus->f(
'Host');
617 $rTmp[
'Rights']=
'All';
619 foreach ($listRights as $v) {
621 if ($this->dbus->f($right) !==
"Y") {
622 $rTmp[
'Rights'] =
'NotAll';
627 if (!
$db->query(
"SELECT name,password from dbusers where name= ? ;", array($dbu))) {
628 $msg->raise(
"ERROR",
"mysql",_(
"Database not found").
" (3)");
632 if (!
$db->num_rows()) {
633 $msg->raise(
"ERROR",
"mysql",_(
"Database not found").
" (4)");
638 $rTmp[
'user'] =
$db->f(
'name');
639 $rTmp[
'password'] =
$db->f(
'password');
657 $msg->log(
"mysql",
"add_user", $usern);
659 $usern = trim($usern);
667 $msg->raise(
"ALERT",
"mysql", _(
"The username is mandatory"));
671 $msg->raise(
"ALERT",
"mysql", _(
"The password is mandatory"));
674 if (!preg_match(
"#^[0-9a-z]#", $usern)) {
675 $msg->raise(
"ERROR",
"mysql", _(
"The username can contain only letters and numbers"));
682 $msg->raise(
"ERROR",
"mysql", _(
"MySQL username cannot exceed %d characters"),
$len);
685 $db->query(
"SELECT * FROM dbusers WHERE name= ? ;", array(
$user));
686 if (
$db->num_rows()) {
687 $msg->raise(
"ERROR",
"mysql", _(
"The database user already exists"));
691 $msg->raise(
"ERROR",
"mysql", _(
"The passwords do not match"));
696 if (is_callable(array($admin,
"checkPolicy"))) {
703 $db->query(
"INSERT INTO dbusers (uid,name,password,enable) VALUES( ?, ?, ?, 'ACTIVATED');", array(
$cuid,
$user,
$password));
719 $msg->log(
"mysql",
"change_user_pass", $usern);
721 $usern = trim($usern);
723 $msg->raise(
"ERROR",
"mysql", _(
"The passwords do not match"));
728 if (is_callable(array($admin,
"checkPolicy"))) {
729 if (!$admin->checkPolicy(
"mysql", $usern,
$password)) {
733 $this->dbus->query(
"SET PASSWORD FOR " .
$db->quote($usern) .
"@" .
$db->quote($this->dbus->Client) .
" = PASSWORD(?);", array(
$password));
734 $db->query(
"UPDATE dbusers set password= ? where name= ? and uid= ? ;", array(
$password, $usern,
$cuid));
748 if (!preg_match(
"#^[0-9a-z]#",
$user)) {
749 $msg->raise(
"ERROR",
"mysql", _(
"The username can contain only letters and numbers"));
753 $db->query(
"SELECT name FROM dbusers WHERE name= ? and enable not in ('ADMIN','HIDDEN');", array(
$user));
755 $db->query(
"SELECT name FROM dbusers WHERE uid= ? ;", array(
$cuid));
758 if (!
$db->num_rows()) {
759 if (! $caller_is_deldb )
760 $msg->raise(
"ERROR",
"mysql", _(
"The username was not found"));
768 $this->dbus->query(
"REVOKE ALL PRIVILEGES ON *.* FROM " .
$db->quote(
$user) .
"@" .
$db->quote($this->dbus->Client) .
";");
769 $this->dbus->query(
"DELETE FROM mysql.db WHERE User= ? AND Host= ? ;", array(
$user, $this->dbus->Client));
770 $this->dbus->query(
"DELETE FROM mysql.user WHERE User= ? AND Host= ? ;", array(
$user, $this->dbus->Client));
771 $this->dbus->query(
"FLUSH PRIVILEGES");
773 $db->query(
"DELETE FROM dbusers WHERE uid= ? AND name= ? ;", array(
$cuid,
$user));
775 if ( $caller_is_deldb )
776 $msg->raise(
"INFO",
"mysql", _(
"The user '%s' has been successfully deleted"),
$user);
790 $this->dbus->query(
"SELECT * FROM mysql.user WHERE User= ? AND Host= ? ;", array(
$user, $this->dbus->Client));
791 if (!$this->dbus->next_record()) {
792 $msg->raise(
"ERROR",
'mysql', _(
"This user does not exist in the MySQL/User database"));
799 foreach ($dblist as
$tab) {
800 $dbname = str_replace(
'_',
'\_',
$tab[
"db"]);
801 $this->dbus->query(
"SELECT * FROM mysql.db WHERE User= ? AND Host= ? AND Db= ? ;", array(
$user, $this->dbus->Client, $dbname));
802 if ($this->dbus->next_record()) {
803 $r[] = array(
"db" =>
$tab[
"db"],
"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"),
804 "create_view" => $this->dbus->f(
"Create_view_priv"),
805 "show_view" => $this->dbus->f(
"Show_view_priv"),
806 "create_routine" => $this->dbus->f(
"Create_routine_priv"),
807 "alter_routine" => $this->dbus->f(
"Alter_routine_priv"),
808 "execute" => $this->dbus->f(
"Execute_priv"),
809 "event" => $this->dbus->f(
"Event_priv"),
810 "trigger" => $this->dbus->f(
"Trigger_priv")
813 $r[] = array(
"db" =>
$tab[
'db'],
"select" =>
"N",
"insert" =>
"N",
"update" =>
"N",
"delete" =>
"N",
"create" =>
"N",
"drop" =>
"N",
"references" =>
"N",
"index" =>
"N",
"alter" =>
"N",
"create_tmp" =>
"N",
"lock" =>
"N",
"create_view" =>
"N",
"show_view" =>
"N",
"create_routine" =>
"N",
"alter_routine" =>
"N",
"execute" =>
"N",
"event" =>
"N",
"trigger" =>
"N");
829 $msg->log(
"mysql",
"set_user_rights");
833 for (
$i = 0;
$i < count($rights);
$i++) {
834 switch ($rights[
$i]) {
836 $strrights.=
"SELECT,";
839 $strrights.=
"INSERT,";
842 $strrights.=
"UPDATE,";
845 $strrights.=
"DELETE,";
848 $strrights.=
"CREATE,";
854 $strrights.=
"REFERENCES,";
857 $strrights.=
"INDEX,";
860 $strrights.=
"ALTER,";
863 $strrights.=
"CREATE TEMPORARY TABLES,";
866 $strrights.=
"LOCK TABLES,";
869 $strrights.=
"CREATE VIEW,";
872 $strrights.=
"SHOW VIEW,";
874 case "create_routine":
875 $strrights.=
"CREATE ROUTINE,";
877 case "alter_routine":
878 $strrights.=
"ALTER ROUTINE,";
881 $strrights.=
"EXECUTE,";
884 $strrights.=
"EVENT,";
887 $strrights.=
"TRIGGER,";
893 $dbname = str_replace(
'_',
'\_', $dbn);
894 $this->dbus->query(
"SELECT * FROM mysql.db WHERE User = ? AND Db = ?;", array(
$user, $dbname));
896 if ($this->dbus->num_rows()) {
897 $this->dbus->query(
"REVOKE ALL PRIVILEGES ON `".$dbname.
"`.* FROM ".$this->dbus->quote(
$user).
"@" . $this->dbus->quote($this->dbus->Client) .
";");
900 $strrights = substr($strrights, 0, strlen($strrights) - 1);
903 $this->dbus->query(
"FLUSH PRIVILEGES");
911 return Array(
'select',
'insert',
'update',
'delete',
'create',
'drop',
'references',
'index',
'alter',
'create_tmp',
'lock',
'create_view',
'show_view',
'create_routine',
'alter_routine',
'execute',
'event',
'trigger');
922 $msg->log(
"mysql",
"alternc_get_quota");
924 if (isset($this->dbus[
"Host"]) && $this->dbus[
"Host"] !=
"") {
925 $p[
"mysql_host"] = $this->dbus[
"Host"];
926 $p[
"mysql_port"] = 3306;
941 $msg->debug(
"mysql",
"alternc_get_quota");
942 $q = Array(
"name" =>
"mysql",
"description" => _(
"MySQL Databases"),
"used" => 0);
945 $q[
'used'] = count(
$c);
946 $q[
'sizeondisk'] = $quota->get_size_db_sum_user(
$mem->user[
"login"])/1024;
959 $msg->log(
"mysql",
"alternc_add_member");
961 $db->query(
"SELECT name,password FROM dbusers WHERE uid= ? AND enable='ADMIN';", array(
$cuid));
962 if (
$db->num_rows()) {
963 $myadm =
$db->f(
"name");
966 $myadm =
$cuid .
"_myadm";
970 $db->query(
"INSERT INTO dbusers (uid,name,password,enable) VALUES (?, ?, ?, 'ADMIN');", array(
$cuid, $myadm,
$password));
983 $msg->log(
"mysql",
"alternc_del_member");
986 for (
$i = 0;
$i < count(
$c);
$i++) {
992 for (
$i = 0;
$i < count(
$d);
$i++) {
1006 $_SESSION[
'PMA_single_signon_user'] =
'';
1007 $_SESSION[
'PMA_single_signon_password'] =
'';
1008 $_SESSION[
'PMA_single_signon_host'] =
'';
1020 $msg->log(
"mysql",
"export");
1021 $db->query(
"SELECT login, pass, db, bck_mode, bck_dir, bck_history, bck_gzip FROM db WHERE uid= ? ;", array(
$cuid));
1023 if (
$db->next_record()) {
1025 $str.=
" <login>" .
$db->Record[
"login"] .
"</login>\n";
1026 $str.=
" <pass>" .
$db->Record[
"pass"] .
"</pass>\n";
1028 $filename = $tmpdir .
"/mysql." .
$db->Record[
"db"] .
".sql.gz";
1029 $str.=
" <database>" . (
$db->Record[
"db"]) .
"</database>\n";
1030 $str.=
" <password>" . (
$db->Record[
"pass"]) .
"</password>\n";
1031 if ($s[
"bck_mode"] != 0) {
1032 $str.=
" <backup-mode>" . (
$db->Record[
"bck_mode"]) .
"</backup-mode>\n";
1033 $str.=
" <backup-dir>" . (
$db->Record[
"bck_dir"]) .
"</backup-dir>\n";
1034 $str.=
" <backup-history>" . (
$db->Record[
"bck_history"]) .
"</backup-history>\n";
1035 $str.=
" <backup-gzip>" . (
$db->Record[
"bck_gzip"]) .
"</backup-gzip>\n";
1037 }
while (
$db->next_record());
1051 $msg->log(
"mysql",
"export_data");
1052 $db->query(
"SELECT db.login, db.pass, db.db, dbusers.name FROM db,dbusers WHERE db.uid= ? AND dbusers.uid=db.uid;", array(
$cuid));
1054 if (!is_dir($dir)) {
1056 $msg->raise(
"ERROR",
'mysql', _(
"The directory could not be created"));
1060 while (
$db->next_record()) {
1061 $filename = $dir .
"mysql." .
$db->Record[
"db"] .
"." . date(
"H:i:s") .
".sql.gz";
1062 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));
1076 function get_dbus_size($db_name, $db_host, $db_login, $db_password, $db_client) {
1078 $msg->debug(
"mysql",
"get_dbus_size", $db_host);
1080 $this->dbus =
new DB_Sql(
"mysql",$db_host,$db_login,$db_password);
1082 $this->dbus->query(
"SHOW DATABASES;");
1084 while ($this->dbus->next_record()) {
1085 $alldb[] = $this->dbus->f(
"Database");
1089 foreach($alldb as $dbname) {
1090 $c = $this->dbus->query(
"SHOW TABLE STATUS FROM $dbname;");
1092 while ($this->dbus->next_record()) {
1093 $size+=$this->dbus->f(
"Data_length") + $this->dbus->f(
"Index_length");
1095 $res[
"$dbname"] =
"$size";
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
MySQL user database management for AlternC.
get_dbus_size($db_name, $db_host, $db_login, $db_password, $db_client)
Return the size of each databases in a SQL Host given in parameter.
alternc_password_policy()
Password kind used in this class (hook for admin class)
grant($base, $user, $rights=null, $pass=null, $table=' *')
Function used to grant SQL rights to users: @base :database @user : database user @rights : rights to...
change_user_password($usern, $password, $passconf)
Change a user's MySQL password.
get_dblist()
Get the list of the database for the current user.
__construct()
Constructor m_mysql([$mid]) Constructeur de la classe m_mysql, initialise le membre concerne.
del_user($user, $all=false, $caller_is_deldb=false)
Delete a user in MySQL rights tables.
add_db($dbn)
Create a new database for the current user.
php_myadmin_connect()
Get the login and password of the special user able to connect to phpmyadmin.
add_user($usern, $password, $passconf)
Create a new user in MySQL rights tables.
get_mysql_details($dbn)
Returns the details of a user's database.
put_mysql_details($password)
Change the password of the user in MySQL.
del_db($dbname)
Delete a database for the current user.
set_user_rights($user, $dbn, $rights)
Set the access rights of user $user to database $dbn to be rights $rights.
alternc_del_member()
Hook function called when a user is deleted.
get_userslist($all=null)
Returns the list of database users of an account.
hook_quota_get()
Hook function called by the quota class to compute user used quota Returns the used quota for the $na...
put_mysql_backup($dbn, $bck_mode, $bck_history, $bck_gzip, $bck_dir)
Set the backup parameters for the database $db.
get_db_size($dbname)
Get the size of a database.
hook_lxc_params($params)
Hook function called by the lxc class to set mysql_host and port parameters @access private.
alternc_del_session()
Hook function called when a user is logged out.
alternc_add_member()
Hook function called when a user is created.
get_user_dblist($user)
Return the list of the database rights of user $user.
restore($file, $stdout, $id)
Restore a sql database.
alternc_export_conf()
Exports all the mysql information of an account @access private EXPERIMENTAL 'sid' function ;)
available_sql_rights()
list of all possible SQL rights
alternc_export_data($dir)
Exports all the mysql databases a of give account to $dir directory @access private EXPERIMENTAL 'sid...
split_mysql_database_name($dbname)
split mysql database name between username and custom database name
create_pass($length=10, $classcount=3)
Create a password compatible with the password policy.
getuserpath($user=null)
get the home of the user
if(empty($site_name)) elseif($piwik->site_add( $site_name, $site_urls))
if(!isset($is_include)) if(! $key &&! $crt) $id