ported maintain.php to lib2

This commit is contained in:
following
2013-07-17 18:21:16 +02:00
parent 22e98f5e00
commit 30f0448465
13 changed files with 70 additions and 145 deletions

View File

@ -47,6 +47,15 @@
$opt['db']['password'] = '';
$opt['db']['pconnect'] = false;
/**
* user for manual maintenance functions
* needs all privileges except for GRANT
*
* Set the password ONLY ON DEVELOPER SYSTEMS !!
*/
$opt['db']['maintenance_user'] = '';
$opt['db']['maintenance_password'] = '';
// begin throotling when more than 80%
// of max_connections is reached on db server
$opt['db']['throttle_connection_count'] = 240;

View File

@ -9,7 +9,6 @@
* .dist files at the following places:
*
* lib
* util/mysql_root
* util/notifications
* util/publish_caches
* util/watchlist
@ -27,9 +26,10 @@
/* database settings
*/
$opt['db']['servername'] = 'localhost';
$opt['db']['username'] = '<db>';
$opt['db']['username'] = '<user>';
$opt['db']['password'] = '<pw>';
$opt['db']['pconnect'] = false;
$opt['db']['maintenance_user'] = '<priviledged_user>';
// ... how long a query can take without warning (0 <= disabled)
$opt['db']['warn']['time'] = 1;

View File

@ -1,29 +0,0 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* Unicode Reminder メモ
*
* !!! IMPORTANT !!!
*
* Only use this file on development systems!
* NOT for productive use!
*
* !!! IMPORTANT !!!
*
* Default settings for all options in sqlroot.inc.php
* Do not modify this file - use settings.inc.php!
*
* This is currently needed only for 'reset IDs' function in translate.php
* (via sql_connect_root in lib2/db.inc.php).
***************************************************************************/
if ($opt['debug'] == DEBUG_NO)
die('sqlroot.inc.php cannot be included on productive systems, set $opt[\'debug\'] != DEBUG_NO');
/* creditials for db-root
* needs all privileges to all oc-databases
*/
$opt['sqlroot']['username'] = 'root';
$opt['sqlroot']['password'] = 'secret';
?>

View File

@ -0,0 +1,13 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* Unicode Reminder メモ
***************************************************************************/
if (($opt['db']['maintenance_password'] != '') && ($opt['debug'] && DEBUG_NO))
{
die("ERROR: db maintenance password must not be used in production enviroment!\n");
}
?>

View File

@ -35,7 +35,7 @@
{
$proc = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
// if (sql_connect_root() == false)
// if (sql_connect_maintenance() == false)
// $tpl->error(ERROR_DB_NO_ROOT);
$bError = false;

View File

@ -1559,10 +1559,9 @@
// Update trigger version function.
// Keep this at the end of this file.
sql_dropFunction('dbsvTriggerVersion');
$db_version = sqlValue("SELECT `value` FROM `sysconfig` WHERE `name`='db_version'", 0);
sql("
CREATE FUNCTION `dbsvTriggerVersion` () RETURNS INT
RETURN '&1'",
$db_version);
current_triggerversion());
?>

View File

@ -9,35 +9,39 @@
***************************************************************************/
$opt['rootpath'] = dirname(__FILE__) . '/../../../';
require_once($opt['rootpath'] . 'lib/clicompatbase.inc.php');
require_once($opt['rootpath'] . 'util/mysql_root/sql_root.inc.php');
require_once($opt['rootpath'] . 'lib2/cli.inc.php');
if ($opt['db']['maintenance_user'] == '')
die("ERROR: \$opt['db']['maintenance_user'] is not set in config2/settings.inc.php\n");
// retrieve DB password
if ($db_root_password == '')
if ($opt['db']['maintenance_password'] == '')
{
if (in_array('--flush',$argv))
{
echo "\nenter DB $db_root_username password:\n";
echo "\nenter DB ".$opt['db']['maintenance_user']." password:\n";
flush();
}
else
echo "enter DB $db_root_username password: ";
echo "enter DB ".$opt['db']['maintenance_user']." password: ";
$fh = fopen('php://stdin', 'r');
$db_root_password = trim(fgets($fh, 1024));
$opt['db']['maintenance_password'] = trim(fgets($fh, 1024));
fclose($fh);
if ($db_root_password == '')
if ($opt['db']['maintenance_password'] == '')
die("no DB password - aborting.\n");
}
// connect to database
db_root_connect();
if ($dblink === false)
if (!sql_connect_maintenance())
{
echo 'Unable to connect to database';
exit;
}
// set variables used by old maintenance scripts
$lang = $opt['template']['locale'];
// include the requested maintain version file
$dbsv = in_array('--dbsv',$argv);
if ($dbsv)
@ -47,9 +51,15 @@
die($versionfile." not found\n");
else
require $versionfile;
unlink($opt['rootpath'] . 'cache2/dbsv-running');
@unlink($opt['rootpath'] . 'cache2/dbsv-running');
}
else
require 'maintain-current.inc.php';
function current_triggerversion()
{
return sql_value("SELECT `value` FROM `sysconfig` WHERE `name`='db_version'", 0);
}
?>

View File

@ -48,6 +48,7 @@ function __autoload($class_name)
// set options
require_once($opt['rootpath'] . 'config2/settings-dist.inc.php');
require_once($opt['rootpath'] . 'config2/settings.inc.php');
require_once($opt['rootpath'] . 'config2/verify-settings.inc.php');
set_domain();

View File

@ -29,11 +29,9 @@
sql_affected_rows() ... mysql_affected_rows
sql_insert_id() ... mysql_insert_id
sql_num_rows($rs) ... mysql_num_rows
sql_connect_root() ... connect the database with all privileges
sql_export_recordset($f, $rs) ... export recordset to file
sql_export_table($f, $table) ... export table to file
sql_export_table_to_file($filename, $table)
sql_dropFunction ... drops stored procedure or trigger
sql_table_exists ... tests if a table exists
sql_field_exists ... tests if a table and a field in this table exist
@ -67,6 +65,12 @@
sql_error() ... report an error and stop processing
sql_warn($warnmessage) ... report a warning and resume processing
// for maintenance functions
sql_connect_maintenance() ... connect the database with more privileges
sql_dropFunction ... drops stored function
sql_dropProcedure ... drops stored procedure
sql_dropTrigger ... drops stored trigger
***************************************************************************/
$db['connected'] = false;
@ -803,17 +807,11 @@
sql_error();
}
function sql_connect_root()
function sql_connect_maintenance()
{
global $tpl, $db, $opt;
if (file_exists($opt['rootpath'] . 'config2/sqlroot.inc.php'))
require($opt['rootpath'] . 'config2/sqlroot.inc.php');
else
return false;
sql_disconnect();
sql_connect($opt['sqlroot']['username'], $opt['sqlroot']['password'], false);
sql_connect($opt['db']['maintenance_user'], $opt['db']['maintenance_password'], false);
if ($db['dblink'] === false)
{
sql_disconnect();
@ -1183,4 +1181,18 @@
sql('DROP PROCEDURE IF EXISTS `&1`', $name);
}
function sql_dropTrigger($triggername)
{
$rs = sql("SHOW TRIGGERS");
while ($r = sql_fetch_assoc($rs))
{
if ($r['Trigger'] == $triggername)
{
sql('DROP TRIGGER `&1`', $triggername);
return;
}
}
sql_free_result($rs);
}
?>

View File

@ -282,7 +282,7 @@ function resetIds()
{
global $translang, $tpl;
if (sql_connect_root() == false)
if (sql_connect_maintenance() == false)
$tpl->error(ERROR_DB_NO_ROOT);
// clean up dead refs

View File

@ -1,4 +0,0 @@
<FilesMatch "*">
Order Deny,Allow
Deny from All
</FilesMatch>

View File

@ -1,8 +0,0 @@
<?php
// Unicode Reminder メモ
$db_root_username = 'root';
$db_root_password = 'geheim';
?>

View File

@ -1,78 +0,0 @@
<?php
/***************************************************************************
For license information see doc/license.txt
Unicode Reminder メモ
Ggf. muss die Location des php-Binaries angepasst werden.
SQL-Funktionen für DB-Verwaltung
***************************************************************************/
require_once($opt['rootpath'] . 'lib/clicompatbase.inc.php');
require_once($opt['rootpath'] . 'util/mysql_root/settings.inc.php');
function db_root_connect()
{
global $dbusername, $dbpasswd;
global $db_root_username, $db_root_password;
$sOldUsername = $dbusername;
$sOldPassword = $dbpasswd;
$dbusername = $db_root_username;
$dbpasswd = $db_root_password;
db_connect();
$dbusername = $sOldUsername;
$dbpasswd = $sOldPassword;
}
function sql_dropTrigger($triggername)
{
$rs = sql("SHOW TRIGGERS");
while ($r = sql_fetch_assoc($rs))
{
if ($r['Trigger'] == $triggername)
{
sql('DROP TRIGGER `&1`', $triggername);
return;
}
}
sql_free_result($rs);
}
function sql_dropFunction($name)
{
global $dbname;
$rs = sql("SHOW FUNCTION STATUS LIKE '&1'", $name);
while ($r = sql_fetch_assoc($rs))
{
if ($r['Db'] == $dbname && $r['Name'] == $name && $r['Type'] == 'FUNCTION')
{
sql('DROP FUNCTION `&1`', $name);
return;
}
}
sql_free_result($rs);
}
function sql_dropProcedure($name)
{
global $dbname;
$rs = sql("SHOW PROCEDURE STATUS LIKE '&1'", $name);
while ($r = sql_fetch_assoc($rs))
{
if ($r['Db'] == $dbname && $r['Name'] == $name && $r['Type'] == 'PROCEDURE')
{
sql('DROP PROCEDURE `&1`', $name);
return;
}
}
sql_free_result($rs);
}
?>