On peut maintenant avoir plusieurs serveurs MySQL pour les utilisateurs sur le même AlternC
This commit is contained in:
parent
cf597f8ee8
commit
770ccb5fb6
|
@ -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
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/*
|
||||
----------------------------------------------------------------------
|
||||
AlternC - Web Hosting System
|
||||
Copyright (C) 2000-2012 by the AlternC Development Team.
|
||||
https://alternc.org/
|
||||
----------------------------------------------------------------------
|
||||
LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License (GPL)
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
||||
----------------------------------------------------------------------
|
||||
Purpose of file: Show a form to edit a member
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
require_once("../class/config.php");
|
||||
|
||||
include("head.php");
|
||||
|
||||
if (!$admin->enabled) {
|
||||
__("This page is restricted to authorized staff");
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
<h3><?php __("List of the databases servers"); ?></h3>
|
||||
<hr/>
|
||||
<?php
|
||||
|
||||
$lst_db_servers = $mysql->list_db_servers();
|
||||
|
||||
echo "<p>";
|
||||
__("Here the list of the available databases servers.");
|
||||
echo "</p>";
|
||||
|
||||
?>
|
||||
|
||||
<table class="tlist">
|
||||
<tr>
|
||||
<th><?php __("ID"); ?></th>
|
||||
<th><?php __("Name"); ?></th>
|
||||
<th><?php __("Hostname"); ?></th>
|
||||
<th><?php __("Login"); ?></th>
|
||||
<th><?php __("Password"); ?></th>
|
||||
<th><?php __("Client"); ?></th>
|
||||
<th><?php __("Users"); ?></th>
|
||||
</tr>
|
||||
<?php
|
||||
$col=2;
|
||||
foreach ( $lst_db_servers as $l) {
|
||||
$col=3-$col;
|
||||
echo "<tr class='lst$col'>"; ?>
|
||||
<td><?php echo $l['id']; ?></td>
|
||||
<td><?php echo $l['name']; ?></td>
|
||||
<td><?php echo $l['host']; ?></td>
|
||||
<td><?php echo $l['login']; ?></td>
|
||||
<td><?php echo $l['password']; ?></td>
|
||||
<td><?php echo $l['client']; ?></td>
|
||||
<td><?php echo $l['nb_users']; ?></td>
|
||||
</tr>
|
||||
<?php } //foreach lst_db_servers ?>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
echo "<p>";
|
||||
__("To add a database server, do an INSERT into the db_servers table");
|
||||
echo "</p>";
|
||||
|
||||
include_once('foot.php');
|
||||
?>
|
|
@ -67,6 +67,7 @@ if (isset($error) && $error) {
|
|||
<li class="lst2"><a href="adm_doms_def_type.php"><?php __("Manage defaults domains type"); ?></a></li>
|
||||
<li class="lst1"><a href="adm_domstype.php"><?php __("Manage domains type"); ?></a></li>
|
||||
<li class="lst2"><a href="adm_dnsweberror.php"><?php __("DNS and website having errors"); ?></a></li>
|
||||
<li class="lst1"><a href="adm_db_servers.php"><?php __("Manage databases servers"); ?></a></li>
|
||||
<!-- <li class="lst2"><a href="stats_members.php"><?php __("Account creation statistics"); ?></a></li> -->
|
||||
|
||||
<?php
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
if (file_exists('/etc/alternc/alternc_display_php_error')) {
|
||||
ini_set('display_errors', true);
|
||||
}
|
||||
|
||||
session_start();
|
||||
|
||||
/*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 : <br>
|
||||
|
|
|
@ -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"
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
// We check that mysql php module is loaded
|
||||
if(!function_exists('mysql_connect')) {
|
||||
if(!dl("mysql.so"))
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// we don't check our AlternC session
|
||||
if(!chdir("/usr/share/alternc/panel"))
|
||||
exit(1);
|
||||
require("/usr/share/alternc/panel/class/config_nochk.php");
|
||||
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// FIRST PART : populate the table db_servers
|
||||
|
||||
$l = $mysql->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
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
?>
|
Loading…
Reference in New Issue