diff --git a/.gitattributes b/.gitattributes
index dfd44599..0096d97b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -47,6 +47,7 @@ bureau/admin/about.php -text
bureau/admin/adm_add.php -text
bureau/admin/adm_authip_whitelist.php -text
bureau/admin/adm_cancel.php -text
+bureau/admin/adm_db_servers.php -text
bureau/admin/adm_deactivate.php -text
bureau/admin/adm_defquotas.php -text
bureau/admin/adm_del.php -text
@@ -453,7 +454,6 @@ debian/rules -text
etc/alternc/alternc-sudoers -text
etc/alternc/alternc.ini -text
etc/alternc/apache2-ssl.conf -text
-etc/alternc/dbusers.cnf.sample -text
etc/alternc/functions_hosting/hosting_massvhost.sh -text
etc/alternc/templates/alternc/apache2.conf -text
etc/alternc/templates/alternc/apache_logformat.conf -text
@@ -521,6 +521,8 @@ install/upgrades/3.0.0~1.sql -text
install/upgrades/3.0.0~2.sh -text
install/upgrades/3.0.0~3.php -text
install/upgrades/3.0.0~4.sh -text
+install/upgrades/3.1.0~a.sql -text
+install/upgrades/3.1.0~b.php -text
install/upgrades/README -text
lang/.svnignore -text
lang/README -text
diff --git a/bureau/admin/adm_db_servers.php b/bureau/admin/adm_db_servers.php
new file mode 100644
index 00000000..8998e382
--- /dev/null
+++ b/bureau/admin/adm_db_servers.php
@@ -0,0 +1,79 @@
+enabled) {
+ __("This page is restricted to authorized staff");
+ exit();
+}
+
+?>
+
+
+list_db_servers();
+
+echo "";
+__("Here the list of the available databases servers.");
+echo "
";
+
+?>
+
+
+
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+
+"; ?>
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+
+
+
+
+";
+__("To add a database server, do an INSERT into the db_servers table");
+echo "";
+
+include_once('foot.php');
+?>
diff --git a/bureau/admin/adm_panel.php b/bureau/admin/adm_panel.php
index d1cdc742..a1364fce 100644
--- a/bureau/admin/adm_panel.php
+++ b/bureau/admin/adm_panel.php
@@ -67,6 +67,7 @@ if (isset($error) && $error) {
+
\ No newline at end of file
+?>
diff --git a/bureau/class/m_mem.php b/bureau/class/m_mem.php
index 2262aa77..1a124ca8 100644
--- a/bureau/class/m_mem.php
+++ b/bureau/class/m_mem.php
@@ -156,7 +156,7 @@ class m_mem {
* @return boolean TRUE if the user has been successfully connected, FALSE else.
*/
function setid($id) {
- global $db,$err,$cuid;
+ global $db,$err,$cuid,$mysql;
$err->log("mem","setid",$id);
$db->query("select * from membres where uid='$id';");
if ($db->num_rows()==0) {
@@ -166,6 +166,9 @@ class m_mem {
$db->next_record();
$this->user=$db->Record;
$cuid=$db->f("uid");
+ // And recreate the $db->dbus
+ $mysql->reload_dbus();
+
$ip=get_remote_ip();
$sess=md5(uniqid(mt_rand()));
$_REQUEST["session"]=$sess;
@@ -276,7 +279,7 @@ class m_mem {
* @return TRUE si la session est correcte, FALSE sinon.
*/
function su($uid) {
- global $cuid,$db,$err;
+ global $cuid,$db,$err,$mysql;
if (!$this->olduid)
$this->olduid=$cuid;
$db->query("select * from membres where uid='$uid';");
@@ -287,6 +290,9 @@ class m_mem {
$db->next_record();
$this->user=$db->Record;
$cuid=$db->f("uid");
+
+ // And recreate the $db->dbus
+ $mysql->reload_dbus();
return true;
}
@@ -300,6 +306,8 @@ class m_mem {
return false;
$this->su($this->olduid);
$this->olduid=0;
+ // And recreate the $db->dbus
+ $mysql->reload_dbus();
return true;
}
diff --git a/bureau/class/m_mysql.php b/bureau/class/m_mysql.php
index 3fbfde28..eb4c78dd 100644
--- a/bureau/class/m_mysql.php
+++ b/bureau/class/m_mysql.php
@@ -41,57 +41,22 @@ class DB_users extends DB_Sql {
* Creator
*/
function DB_users() {
+ global $cuid, $db, $err;
+ $db->query("select db_servers.* from db_servers, membres where membres.uid=$cuid and membres.db_server_id=db_servers.id;");
-# Use the dbusers file if exist, else use default alternc configuration
- if ( is_readable("/etc/alternc/dbusers.cnf") ) {
- $mysqlconf=file_get_contents("/etc/alternc/dbusers.cnf");
- } else {
- $mysqlconf=file_get_contents("/etc/alternc/my.cnf");
- }
- $mysqlconf=explode("\n",$mysqlconf);
-
-# Read the configuration
- foreach ($mysqlconf as $line) {
-# First, read the "standard" configuration
- if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
- switch ($regs[1]) {
- case "user":
- $user = $regs[2];
- break;
- case "password":
- $password = $regs[2];
- break;
- case "host":
- $host = $regs[2];
- break;
- }
- }
-# Then, read specific alternc configuration
- if (preg_match('/^#alternc_var ([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) {
- $$regs[1]=$regs[2];
- }
+ if (!$db->next_record()) {
+ $err->raise('db_user', _("There are no databases in db_servers for this user. Please contact your administrator."));
+ die();
}
-# Set value of human_host if unset
- if (! isset($human_hostname) || empty($human_hostname)) {
- if ( checkip($host) || checkipv6($host) ) {
- $human_hostname = gethostbyaddr($host);
- } else {
- $human_hostname = $host;
- }
- }
+ # Create the object
+ $this->HumanHostname = $db->f('name');
+ $this->Host = $db->f('host');
+ $this->User = $db->f('login');
+ $this->Password = $db->f('password');
+ $this->Client = $db->f('client');
-# Create the object
- $this->Host = $host;
- $this->User = $user;
- $this->Password = $password;
- $this->Client = $GLOBALS['L_MYSQL_CLIENT'];
- // 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"; #if dbus is on a different host the alternc database will not be there and trying to use it might cause an error
- $this->HumanHostname = $human_hostname;
+ $this->Database = "mysql"; # We have to define a dabatase when we connect, and the database must exist.
}
}
@@ -105,9 +70,26 @@ class m_mysql {
* m_mysql([$mid]) Constructeur de la classe m_mysql, initialise le membre concerne
*/
function m_mysql() {
+ global $cuid;
+ if (!empty($cuid)) {
+ $this->dbus = new DB_users();
+ }
+ }
+
+ function reload_dbus() {
$this->dbus = new DB_users();
}
+ function list_db_servers() {
+ global $db;
+ $db->query("select db_servers.*, count(*) as nb_users from db_servers, membres where membres.db_server_id = db_servers.id group by db_server_id order by name,id;");
+ $c=array();
+ while ($db->next_record()) {
+ $c[]=$db->Record;
+ }
+ return $c;
+ }
+
function hook_menu() {
global $quota;
$q = $quota->getquota("mysql");
@@ -151,7 +133,6 @@ class m_mysql {
return array("mysql"=>"MySQL users");
}
-
/*---------------------------------------------------------------------------*/
/** Get the list of the database for the current user.
* @return array returns an associative array as follow :
diff --git a/etc/alternc/dbusers.cnf.sample b/etc/alternc/dbusers.cnf.sample
deleted file mode 100644
index 052fc6d0..00000000
--- a/etc/alternc/dbusers.cnf.sample
+++ /dev/null
@@ -1,8 +0,0 @@
-# If you create a file /etc/alternc/dbusers.cnf
-# His configuration will be used for the storage
-# of the users databases.
-[client]
-host="1.2.3.4"
-#alternc_var human_hostnameee ="human_readable_hostname"
-user="my_user"
-password="my_string_password"
diff --git a/install/alternc.install b/install/alternc.install
index 95e910fb..9ed35221 100644
--- a/install/alternc.install
+++ b/install/alternc.install
@@ -366,6 +366,16 @@ done
OLDDESTINATION=`postconf mydestination | awk -F '=' '{print $2}'`
echo "$OLDDESTINATION" | grep -q -v "$FQDN" && postconf -e "mydestination = $FQDN, $OLDDESTINATION"
+# Configure PHPMyAdmin
+include_str='include("/etc/alternc/phpmyadmin.inc.php")'
+pma_config='/etc/phpmyadmin/config.inc.php'
+
+# Sur une configuration vierge, inclure la configuration alternc
+if ! grep -e "${include_str/\"/\\\"}" $pma_config > /dev/null 2>&1; then
+ echo "$include_str;" >> $pma_config
+fi
+
+
# Reload incron. Useless, but who know?
SERVICES="$SERVICES incron"
diff --git a/install/upgrades/3.1.0~a.sql b/install/upgrades/3.1.0~a.sql
new file mode 100644
index 00000000..c7126be3
--- /dev/null
+++ b/install/upgrades/3.1.0~a.sql
@@ -0,0 +1,14 @@
+-- New table for the MySQL servers
+CREATE TABLE IF NOT EXISTS `db_servers` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `name` varchar(255) NOT NULL,
+ `host` varchar(255) NOT NULL,
+ `login` varchar(255) NOT NULL,
+ `password` varchar(255) NOT NULL,
+ `client` varchar(255) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM COMMENT='List of the databases servers';
+
+-- Alter table membres to add
+ALTER TABLE `membres` ADD db_server_id int(10) DEFAULT NULL;
+
diff --git a/install/upgrades/3.1.0~b.php b/install/upgrades/3.1.0~b.php
new file mode 100644
index 00000000..710b52ca
--- /dev/null
+++ b/install/upgrades/3.1.0~b.php
@@ -0,0 +1,32 @@
+#!/usr/bin/php
+dbus;
+// populate it if there is not entry
+$db->query("select * from db_servers;");
+if ($db->num_rows()==0) {
+ $db->query(" insert into db_servers (name, host, login, password, client) values ('".mysql_escape_string($l->HumanHostname)."','".mysql_escape_string($l->Host)."','".mysql_escape_string($l->User)."','".mysql_escape_string($l->Password)."','".mysql_escape_string($L_MYSQL_CLIENT)."');");
+}
+
+// set the membres.db_server_id
+$db->query(" update membres set db_server_id = (select max(id) from db_servers) where db_server_id is null ;");
+
+// END of db_servers part
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+?>