Exemple #1
0
function setMysqlOptimize($select, $database = null)
{
    global $gbl, $sgbl, $login, $ghtml;
    log_cleanup("Mysql Optimization");
    $database = $database ? $database : "_all_";
    $pass = slave_get_db_pass();
    if ($select === 'repair') {
        log_cleanup("- Repairing database");
        if ($database === '_all_') {
            system("mysqlcheck --user=root --password=\"{$pass}\" --repair --all-databases");
        } else {
            system("mysqlcheck --user=root --password=\"{$pass}\" --repair --databases {$dbname}");
        }
    } else {
        if ($select === 'optimize') {
            log_cleanup("- Compacting database");
            if ($database === '_all_') {
                system("mysqlcheck --user=root --password=\"{$pass}\" --optimize --all-databases");
            } else {
                system("mysqlcheck --user=root --password=\"{$pass}\" --optimize --databases {$dbname}");
            }
        }
    }
    log_cleanup("- MySQL Service restart");
    $ret = lxshell_return("service", "mysqld", "restart");
    if ($ret) {
        throw new lxexception('mysqld_restart_failed', 'parent');
    }
}
Exemple #2
0
function remove_test_root()
{
    $pass = slave_get_db_pass();
    $__tr = mysql_connect("localhost", "root", $pass);
    mysql_select_db("mysql", $__tr);
    mysql_query("delete from user where Host = 'test.lxlabs.com' and User = '******'", $__tr);
}
function setupsecondary_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    global $argv;
    $dbf = $sgbl->__var_dbf;
    $prgm = $sgbl->__var_program_name;
    $list = parse_opt($argv);
    if (!isset($list['primary-master'])) {
        print "need --primary-master=\n";
        exit;
    }
    if (!isset($list['sshport'])) {
        print "need --sshport=\n";
        exit;
    }
    $master = $list['primary-master'];
    $sshport = $list['sshport'];
    print "Taking backup of the current database anyway...\n";
    lxshell_php("../bin/common/mebackup.php");
    $slavepass = randomString(7);
    print "Setting up mysql to receive data from master\n";
    add_line_to_secondary_mycnf($master, $slavepass);
    $pass = slave_get_db_pass();
    // TODO: REPLACE MYSQL_CONNECT
    $dblink = mysqli_connect("localhost", "root", $pass, $dbf);
    mysqli_query($dblink, "STOP SLAVE");
    print "Getting initial data from the master\n";
    system("ssh -p {$sshport} {$master} \"(cd /usr/local/lxlabs/{$prgm}/httpdocs ; lphp.exe ../bin/common/setupprimarymaster.php --slavepass={$slavepass})\" | mysql -u root -p{$pass} {$dbf}");
    print "starting mysql data getting process\n";
    mysqli_query($dblink, "CHANGE MASTER TO master_host='{$master}', master_password='******'");
    mysqli_query($dblink, "START SLAVE");
    lxfile_touch("../etc/secondary_master");
    lxfile_touch("../etc/running_secondary");
}
function pmaster_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    global $argv;
    ob_start();
    $pass = slave_get_db_pass();
    $tfile = ltempnam("/tmp", "mastertmp");
    $dbf = $sgbl->__var_dbf;
    $list = parse_opt($argv);
    $slavepass = $list['slavepass'];
    add_line_to_master_mycnf();
    mysql_connect("localhost", "root", $pass);
    mysql_query("grant replication slave on *.* to lxlabsslave@'%' identified by '{$slavepass}'");
    system("mysqldump --master-data -u root '-p{$pass}' {$dbf} > {$tfile}");
    ob_clean();
    readfile($tfile);
    ob_start();
    unlink($tfile);
    ob_clean();
}
function pmaster_main()
{
    global $gbl, $sgbl, $login, $ghtml;
    global $argv;
    ob_start();
    $pass = slave_get_db_pass();
    $tfile = ltempnam("/tmp", "mastertmp");
    $dbf = $sgbl->__var_dbf;
    $list = parse_opt($argv);
    $slavepass = $list['slavepass'];
    add_line_to_master_mycnf();
    // TODO: REPLACE MYSQL_CONNECT
    $dblink = mysqli_connect("localhost", "root", $pass, $dbf);
    mysqli_query($dblink, "GRANT REPLICATION SLAVE ON *.* TO lxlabsslave@'%' IDENTIFIED BY '{$slavepass}'");
    system("mysqldump --master-data -u root '-p{$pass}' {$dbf} > {$tfile}");
    ob_clean();
    readfile($tfile);
    ob_start();
    unlink($tfile);
    ob_clean();
}
Exemple #6
0
<?php

include_once "htmllib/lib/include.php";
chdir("/usr/local/lxlabs/lxadmin/httpdocs/");
$pass = slave_get_db_pass();
$res = mysql_connect("localhost", "root", $pass);
$dbadminpass = trim(file_get_contents("/usr/local/lxlabs/lxadmin/etc/conf/lxadmin.pass"));
print $dbadminpass;
print "\n";
mysql_query("grant all on kloxo.* to 'kloxo'@'localhost' identified by '{$dbadminpass}';");
mysql_query("flush privileges");
Exemple #7
0
function PrepareRoundCubeDb()
{
    global $gbl, $sgbl, $login, $ghtml;
    $pass = slave_get_db_pass();
    //system("yum -y install lxroundcube");
    $pstring = null;
    if ($pass) {
        $pstring = "-p\"{$pass}\"";
    }
    //$cmd = "echo \"drop database roundcubemail \" | mysql -u root $pstring 2>/dev/null";
    //system($cmd);
    $cmd = " echo \"create database roundcubemail ; grant all on roundcubemail.* to roundcube@localhost identified by 'pass' \" | mysql -u root {$pstring} 2>/dev/null";
    system($cmd);
    system("mysql -u roundcube -ppass roundcubemail < /home/kloxo/httpd/webmail/roundcube/SQL/mysql.initial.sql 2>/dev/null");
}
Exemple #8
0
function setMysqlConvert($engine, $database, $table, $config)
{
    global $gbl, $sgbl, $login, $ghtml;
    log_cleanup("Convert of MySQL engine");
    $engine = strtolower($engine);
    $database = $database ? $database : '_all_';
    $table = $table ? $table : '_all_';
    $config = $config ? $config : 'yes';
    $pass = slave_get_db_pass();
    //--- the first - to 'disable' skip- and restart mysql
    system("sed -i 's/skip/\\;###123###skip/g' /etc/my.cnf");
    $ret = lxshell_return("service", "mysqld", "restart");
    if ($ret) {
        throw new lxexception('mysqld_restart_failed', 'parent');
    }
    mysql_connect('localhost', 'root', $pass);
    log_cleanup("- Converting to " . $engine . " engine");
    if ($database === '_all_') {
        $dbs = mysql_query('SHOW databases');
        while ($db = mysql_fetch_array($dbs)) {
            log_cleanup("-- " . $db[0] . " database converted");
            if ($db[0] === 'mysql') {
            } else {
                if ($db[0] === 'information_schema') {
                } else {
                    mysql_select_db($db[0]);
                    if ($table === '_all_') {
                        $tbls = mysql_query('SHOW tables');
                        while ($tbl = mysql_fetch_array($tbls)) {
                            log_cleanup("--- " . $tbl[0] . " table converted");
                            mysql_query("ALTER TABLE {$tbl[0]} ENGINE={$engine}");
                        }
                    } else {
                        mysql_query("ALTER TABLE {$table} ENGINE={$engine}");
                        log_cleanup("--- " . $table . " table converted");
                    }
                }
            }
        }
    } else {
        mysql_select_db($database);
        log_cleanup("-- " . $database . " database converted");
        if ($table === '_all_') {
            $tbls = mysql_query('SHOW tables');
            while ($tbl = mysql_fetch_array($tbls)) {
                log_cleanup("--- " . $tbl[0] . " table converted");
                mysql_query("ALTER TABLE {$tbl[0]} ENGINE={$engine}");
            }
        } else {
            mysql_query("ALTER TABLE {$table} ENGINE={$engine}");
            log_cleanup("--- " . $table . " table");
        }
    }
    //--- the second - back to 'original' config and restart mysql
    system("sed -i 's/\\;###123###skip/skip/g' /etc/my.cnf");
    $ret = lxshell_return("service", "mysqld", "restart");
    if ($ret) {
        throw new lxexception('mysqld_restart_failed', 'parent');
    }
    if ($config === 'yes') {
        if ($database === '_all_') {
            $string = implode("", file("/etc/my.cnf"));
            $file = fopen("/etc/my.cnf", "w");
            $string_array = explode("\n", $string);
            $string_collect = null;
            foreach ($string_array as $sa) {
                if (stristr($sa, 'skip-innodb') !== FALSE) {
                    $string_collect .= "";
                    continue;
                }
                if (stristr($sa, 'default-storage-engine') !== FALSE) {
                    $string_collect .= "";
                    continue;
                }
                $string_collect .= $sa . "\n";
            }
            if ($engine === 'myisam') {
                $string_source = "[mysqld]\n";
                $string_replace = "[mysqld]\nskip-innodb\ndefault-storage-engine=myisam\n";
                log_cleanup("- Added \"skip-innodb and default-storage-engine=" . $engine . "\" in /etc/my.cnf");
            } else {
                $string_source = "[mysqld]\n";
                $string_replace = "[mysqld]\ndefault-storage-engine={$engine}\n";
                log_cleanup("- Added \"default-storage-engine=" . $engine . "\" in /etc/my.cnf");
            }
            $string_collect = str_replace($string_source, $string_replace, $string_collect);
            fwrite($file, $string_collect, strlen($string_collect));
        }
    }
    log_cleanup("- Convert of MySQL to " . $engine . " engine finished");
    log_cleanup("- MySQL Service restarted");
    $ret = lxshell_return("service", "mysqld", "restart");
    if ($ret) {
        throw new lxexception('mysqld_restart_failed', 'parent');
    }
}
Exemple #9
0
<?php

include_once "htmllib/lib/include.php";
print slave_get_db_pass();
Exemple #10
0
function PrepareHordeDb()
{
    global $gbl, $sgbl, $login, $ghtml;
    log_cleanup("Preparing Horde database");
    $pass = slave_get_db_pass();
    $user = "******";
    $host = "localhost";
    $link = mysql_connect($host, $user, $pass);
    if (!$link) {
        log_cleanup("- Mysql root password incorrect");
        exit;
    }
    $pstring = null;
    if ($pass) {
        $pstring = "-p\"{$pass}\"";
    }
    $result = mysql_select_db('horde_groupware', $link);
    log_cleanup("- Fix MySQL commands in import files of Horde");
    $hordefile = "/home/kloxo/httpd/webmail/horde/scripts/sql/groupware.mysql.sql";
    $content = lfile_get_contents($hordefile);
    $content = str_replace("USE horde;", "USE horde_groupware;", $content);
    $content = str_replace(") ENGINE = InnoDB;", ");", $content);
    // --- better create table logic --> also see updateDatabaseProperly()
    $content = str_replace(" IF NOT EXISTS", "", $content);
    $content = str_replace("CREATE TABLE", "CREATE TABLE IF NOT EXISTS", $content);
    $content = str_replace("CREATE DATABASE horde;", "CREATE DATABASE IF NOT EXISTS horde_groupware;", $content);
    $content = str_replace("CREATE DATABASE horde_groupware;", "CREATE DATABASE IF NOT EXISTS horde_groupware;", $content);
    // no need 'IF NOT EXISTS' for INDEX
    //	$content = str_replace("CREATE INDEX", "CREATE INDEX IF NOT EXISTS", $content);
    lfile_put_contents($hordefile, $content);
    $result = mysql_query("CREATE DATABASE IF NOT EXISTS horde_groupware", $link);
    if (!$result) {
        log_cleanup("- ***** There is something REALLY wrong... Go to http://forum.lxcenter.org and report to the team *****");
        exit;
    }
    system("mysql -f -u root {$pstring} < /home/kloxo/httpd/webmail/horde/scripts/sql/groupware.mysql.sql >/dev/null 2>&1");
    $cfgfile = "/home/kloxo/httpd/webmail/horde/config/conf.php";
    lxfile_cp("/usr/local/lxlabs/kloxo/file/horde.config.phps", $cfgfile);
    system("chattr -i {$cfgfile}");
    log_cleanup("- Generating password");
    $pass = randomString(8);
    log_cleanup("- Add password to configuration file");
    $content = lfile_get_contents($cfgfile);
    $content = str_replace("__lx_horde_pass", $pass, $content);
    lfile_put_contents($cfgfile, $content);
    $result = mysql_query("GRANT ALL ON horde_groupware.* TO horde_groupware@localhost IDENTIFIED BY '{$pass}'", $link);
    mysql_query("flush privileges", $link);
    if (!$result) {
        log_cleanup("Could not grant privileges. Script Aborted");
        exit;
    }
    log_cleanup("- Database installed");
    $pass = null;
    $pstring = null;
    //--- to make sure always 644
    system("chmod 644 /home/kloxo/httpd/webmail/horde/config/conf.php");
}
<?php

include_once "htmllib/lib/include.php";
if ($argv[1]) {
    $mysqlpass = $argv[1];
} else {
    $mysqlpass = slave_get_db_pass();
}
$db = $sgbl->__var_dbf;
$username = $sgbl->__var_program_name;
$program = $username;
$newpass = randomString(9);
$newpass = client::createDbPass($newpass);
mysql_connect("localhost", "root", $mysqlpass);
$cmd = "grant all on {$db}.* to {$username}@localhost identified by '{$newpass}'";
print "{$cmd}\n";
mysql_query($cmd);
lfile_put_contents("../etc/conf/{$program}.pass", $newpass);