- show aps-databases also customer-mysql overview, fixes #272

- aps-databases are now increasing the customers mysql-contingent, refs #278
- customers viewing the aps-list are now notified if a package requires a database but the contingent is used up
- the update will add all web[X]aps[Y] databases to the according customer regardless of contingent
- fix tiny issue in preconfig
- setting version to 0.9.10-svn2


refs #272,278
This commit is contained in:
Michael Kaufmann (d00p) 2010-06-17 09:21:14 +00:00
parent 794c4d3b55
commit 9851ac53cc
12 changed files with 133 additions and 43 deletions

View File

@ -52,7 +52,7 @@ elseif($page == 'mysqls')
'description' => $lng['mysql']['databasedescription']
);
$paging = new paging($userinfo, $db, TABLE_PANEL_DATABASES, $fields, $settings['panel']['paging'], $settings['panel']['natsorting']);
$result = $db->query("SELECT `id`, `databasename`, `description`, `dbserver` FROM `" . TABLE_PANEL_DATABASES . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' " . $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit());
$result = $db->query("SELECT * FROM `" . TABLE_PANEL_DATABASES . "` WHERE `customerid`='" . (int)$userinfo['customerid'] . "' " . $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit());
$paging->setEntries($db->num_rows($result));
$sortcode = $paging->getHtmlSortCode($lng);
$arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s);

View File

@ -248,6 +248,7 @@ CREATE TABLE `panel_databases` (
`databasename` varchar(255) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`dbserver` int(11) unsigned NOT NULL default '0',
`apsdb` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `customerid` (`customerid`)
) TYPE=MyISAM ;
@ -451,7 +452,7 @@ INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) V
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (18, 'system', 'vmail_homedir', '/var/customers/mail/');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (19, 'system', 'bindconf_directory', '/etc/bind/');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (20, 'system', 'bindreload_command', '/etc/init.d/bind9 reload');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (22, 'panel', 'version', '0.9.10-svn1');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (22, 'panel', 'version', '0.9.10-svn2');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (23, 'system', 'hostname', 'SERVERNAME');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (24, 'login', 'maxloginattempts', '3');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (25, 'login', 'deactivatetime', '900');

View File

@ -837,3 +837,37 @@ if(isFroxlorVersion('0.9.9'))
updateToVersion('0.9.10-svn1');
}
if(isFroxlorVersion('0.9.10-svn1'))
{
showUpdateStep("Updating from 0.9.10-svn1 to 0.9.10-svn2", false);
showUpdateStep("Updating database table definition for panel_databases");
$db->query("ALTER TABLE `" . TABLE_PANEL_DATABASES . "` ADD `apsdb` tinyint(1) NOT NULL default '0' AFTER `dbserver`;");
lastStepStatus(0);
showUpdateStep("Adding APS databases to customers overview");
$count_dbupdates = 0;
$db_root = null;
openRootDB();
$result = $db_root->query("SHOW DATABASES;");
while($row = $db_root->fetch_array($result))
{
if(preg_match('/^web([0-9]+)aps([0-9]+)$/', $row['Database']))
{
$cid = substr($row['Database'], 3, strpos($row['Database'], 'aps')- 3);
$databasedescription = 'APS DB';
$result = $db->query('INSERT INTO `' . TABLE_PANEL_DATABASES . '` (`customerid`, `databasename`, `description`, `dbserver`, `apsdb`) VALUES ("' . (int)$cid . '", "' . $db->escape($row['Database']) . '", "' . $db->escape($databasedescription) . '", "0", "1")');
$result = $db->query('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` SET `mysqls_used`=`mysqls_used`+1 WHERE `customerid`="' . (int)$cid . '"');
$count_dbupdates++;
}
}
closeRootDB();
if($count_dbupdates > 0) {
lastStepStatus(0, "Found ".$count_dbupdates." customer APS databases");
} else {
lastStepStatus(0, "None found");
}
updateToVersion('0.9.10-svn2');
}

View File

@ -192,20 +192,23 @@ function parseAndOutputPreconfig(&$has_preconfig, &$return, $current_version)
}
}
$description = 'Please enter the correct username/groupname of the webserver on your system We\'re guessing the user but it might not be correct, so please check.';
if($has_nouser)
if($has_nouser || $has_nogroup)
{
$question = '<strong>Please enter the webservers username:</strong>&nbsp;<input type="text" class="text" name="update_httpuser" value="'.$guessed_user.'" />';
}
elseif($has_nogroup)
{
$question2 = '<strong>Please enter the webservers groupname:</strong>&nbsp;<input type="text" class="text" name="update_httpgroup" value="'.$guessed_group.'" />';
if($has_nouser) {
$question .= '<br /><br />'.$question2;
} else {
$question = $question2;
$description = 'Please enter the correct username/groupname of the webserver on your system We\'re guessing the user but it might not be correct, so please check.';
if($has_nouser)
{
$question = '<strong>Please enter the webservers username:</strong>&nbsp;<input type="text" class="text" name="update_httpuser" value="'.$guessed_user.'" />';
}
elseif($has_nogroup)
{
$question2 = '<strong>Please enter the webservers groupname:</strong>&nbsp;<input type="text" class="text" name="update_httpgroup" value="'.$guessed_group.'" />';
if($has_nouser) {
$question .= '<br /><br />'.$question2;
} else {
$question = $question2;
}
}
eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
}
eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
}
}

View File

@ -252,6 +252,12 @@ class ApsInstaller extends ApsParser
$this->db_root->query('DROP DATABASE IF EXISTS `' . $this->db->escape($Database) . '`');
$this->db_root->query('FLUSH PRIVILEGES');
/*
* remove database from customer-mysql overview, #272
*/
$this->db->query('DELETE FROM `' . TABLE_PANEL_DATABASES . '` WHERE `customerid`="' . (int)$Row['CustomerID'] . '" AND `databasename`="' . $this->db->escape($Database) . '" AND `apsdb`="1"');
$result = $this->db->query('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` SET `mysqls_used`=`mysqls_used`-1 WHERE `customerid`="' . (int)$Row['CustomerID'] . '"');
}
//remove task & delete package instance + settings
@ -259,20 +265,6 @@ class ApsInstaller extends ApsParser
$this->db->query('DELETE FROM `' . TABLE_APS_TASKS . '` WHERE `Task` = ' . TASK_REMOVE . ' AND `InstanceID` = ' . $this->db->escape($Row['InstanceID']));
$this->db->query('DELETE FROM `' . TABLE_APS_INSTANCES . '` WHERE `ID` = ' . $this->db->escape($Row['InstanceID']));
$this->db->query('DELETE FROM `' . TABLE_APS_SETTINGS . '` WHERE `InstanceID` = ' . $this->db->escape($Row['InstanceID']));
// decrease customer-counter
/*
* @TODO this is for 0.9.11 or so
*
$aps_userinfo = $db->query_first("SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid` = '" . (int)$Row['CustomerID'] . "'");
if($aps_userinfo['mysqls_used'] == '1')
{
$resetaccnumber = " , `mysql_lastaccountnumber`='0' ";
}
$result = $db->query('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` SET `mysqls_used`=`mysqls_used`-1 ' . $resetaccnumber . 'WHERE `customerid`="' . (int)$Row['CustomerID'] . '"');
*/
}
}
@ -487,8 +479,6 @@ class ApsInstaller extends ApsParser
private function PrepareDatabase($Xml, $Row, $Task)
{
global $db_root;
$XmlDb = $Xml->requirements->children('http://apstandard.com/ns/1/db');
if ($this->aps_version == '1.0')
@ -525,6 +515,13 @@ class ApsInstaller extends ApsParser
}
$this->db_root->query('FLUSH PRIVILEGES');
/*
* add database to customers databases, #272
*/
$databasedescription = $Xml->name.' '.$Xml->version.' (Release ' . $Xml->release . ')';
$result = $this->db->query('INSERT INTO `' . TABLE_PANEL_DATABASES . '` (`customerid`, `databasename`, `description`, `dbserver`, `apsdb`) VALUES ("' . (int)$Row['CustomerID'] . '", "' . $this->db->escape($NewDatabase) . '", "' . $this->db->escape($databasedescription) . '", "0", "1")');
$result = $this->db->query('UPDATE `' . TABLE_PANEL_CUSTOMERS . '` SET `mysqls_used`=`mysqls_used`+1 WHERE `customerid`="' . (int)$Row['CustomerID'] . '"');
}
//get first mysql access host

View File

@ -1351,7 +1351,7 @@ class ApsParser
private function InstallNewPackage($Filename)
{
global $lng;
global $lng, $userinfo;
if(file_exists($Filename)
&& $Xml = self::GetXmlFromZip($Filename))
@ -1831,7 +1831,7 @@ class ApsParser
public function MainHandler($Action)
{
global $lng, $filename, $s, $page, $action, $Id;
global $lng, $filename, $s, $page, $action, $Id, $userinfo;
//check for basic functions, classes and permissions
@ -2183,8 +2183,9 @@ class ApsParser
}
// no more contingent, #278
if($userinfo['aps_packages'] == $userinfo['aps_packages_used'])
{
if($userinfo['aps_packages'] == $userinfo['aps_packages_used']
&& $userinfo['aps_packages'] != '-1'
){
self::InfoBox($lng['aps']['nocontingent']);
}
@ -3494,6 +3495,41 @@ class ApsParser
}
}
/*
* check if packages needs a database
* and if the customer has contingent for that, #272
*/
if ($this->aps_version == '1.0')
{
// the good ole way
$XmlDb = $Xml->requirements->children('http://apstandard.com/ns/1/db');
}
else
{
// since 1.1
$Xml->registerXPathNamespace('db', 'http://apstandard.com/ns/1/db');
$XmlDb = new DynamicProperties;
$XmlDb->db->id = getXPathValue($Xml, '//db:id');
}
if($XmlDb->db->id)
{
if($userinfo['mysqls_used'] < $userinfo['mysqls']
|| $userinfo['mysqls'] == '-1'
){
$can_use_db = true;
} else {
$can_use_db = false;
}
} else { $can_use_db = true; }
$db_info = '';
if(!$can_use_db)
{
$db_info = $lng['aps']['packageneedsdb'];
}
eval("echo \"" . getTemplate("aps/package") . "\";");
unset($Xml);
}

View File

@ -26,7 +26,7 @@
*
* @return null
*/
function openRootDB($debugHandler, $lockfile)
function openRootDB($debugHandler = false, $lockfile = false)
{
global $db_root;
@ -47,14 +47,22 @@ function openRootDB($debugHandler, $lockfile)
/**
* Do not proceed further if no database connection could be established
*/
fclose($debugHandler);
unlink($lockfile);
if(isset($debugHandler) && $debugHandler !== false)
{
fclose($debugHandler);
}
if(isset($lockfile) && $lockfile !== false)
{
unlink($lockfile);
}
die('root can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
}
unset($db_root->password);
fwrite($debugHandler, 'Database-rootconnection established' . "\n");
if(isset($debugHandler) && $debugHandler !== false)
{
fwrite($debugHandler, 'Database-rootconnection established' . "\n");
}
unset($sql);
}

View File

@ -72,7 +72,7 @@ define('PACKAGE_ENABLED', 2);
// VERSION INFO
$version = '0.9.10-svn1';
$version = '0.9.10-svn2';
$dbversion = '2';
$branding = '';

View File

@ -1429,5 +1429,7 @@ $lng['serversettings']['mail_also_with_mxservers'] = 'Create mail-, imap-, pop3-
// ADDED IN FROXLOR 0.9.10-svn1
$lng['aps']['nocontingent'] = 'Your APS contingent is insufficient. You cannot install any package.';
$lng['aps']['packageneedsdb'] = 'This package needs a database but your contingent is used up';
$lng['aps']['cannoteditordeleteapsdb'] = 'APS databases cannot be edited or removed here';
?>

View File

@ -1412,5 +1412,7 @@ $lng['serversettings']['mail_also_with_mxservers'] = 'Erstelle mail-, imap-, pop
// ADDED IN FROXLOR 0.9.10-svn1
$lng['aps']['nocontingent'] = 'Sie haben kein ausreichendes APS-Kontingent und k&ouml;nnen daher keine Pakete installieren.';
$lng['aps']['packageneedsdb'] = 'Dieses Paket ben&ouml;tigt eine Datenbank, Sie haben allerdings keine mehr frei';
$lng['aps']['cannoteditordeleteapsdb'] = 'APS-Datenbanken k&ouml;nnen hier nicht bearbeitet oder gel&ouml;scht werden';
?>

View File

@ -29,7 +29,7 @@
<input class="bottom" type="submit" value="{$lng['aps']['back']}" />
</form>
</if>
<if $action != 'customerstatus' && ( $userinfo['aps_packages'] != $userinfo['aps_packages_used'] )>
<if $action != 'customerstatus' && ( $userinfo['aps_packages'] != $userinfo['aps_packages_used'] ) && $db_info == ''>
<form method="get" action="$filename" style="float:left; padding-left: 5px;">
<input type="hidden" name="s" value="$s" />
<input type="hidden" name="page" value="$page" />
@ -38,6 +38,9 @@
<input class="bottom" type="submit" value="{$lng['aps']['install']}" />
</form>
</if>
<if $db_info != ''>
<span style="padding-left: 5px;">{$db_info}</span>
</if>
<if ($action == 'customerstatus') && ($Row['Status'] == 2 || $Row['Status'] == 3)>
<form method="get" action="$filename" style="float:left;">
<input type="hidden" name="s" value="$s" />

View File

@ -2,6 +2,10 @@
<td class="field_name_border_left">{$row['databasename']}</td>
<td class="field_name">{$row['description']}</td>
<if 1 < count($sql_root)><td class="field_name">{$sql_root[$row['dbserver']]['caption']}</td></if>
<td class="field_name"><a href="$filename?page=mysqls&amp;action=edit&amp;id={$row['id']}&amp;s=$s">{$lng['panel']['edit']}</a></td>
<td class="field_name"><a href="$filename?page=mysqls&amp;action=delete&amp;id={$row['id']}&amp;s=$s">{$lng['panel']['delete']}</a></td>
<if $row['apsdb'] != '1'>
<td class="field_name"><a href="$filename?page=mysqls&amp;action=edit&amp;id={$row['id']}&amp;s=$s">{$lng['panel']['edit']}</a></td>
<td class="field_name"><a href="$filename?page=mysqls&amp;action=delete&amp;id={$row['id']}&amp;s=$s">{$lng['panel']['delete']}</a></td>
<else>
<td class="field_name" colspan="2">{$lng['aps']['cannoteditordeleteapsdb']}</td>
</if>
</tr>