Пример #1
0
function restore_container($servername, $path, $instance_id)
{
    $unix = new unix();
    $tmppath = "/var/tmp/" . time();
    $t1 = time();
    if (!is_numeric($instance_id)) {
        $instance_id = 0;
    }
    if (!is_file($path)) {
        writelogs("[{$servername}] fatal {$path} no such file...", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $cp = $unix->find_program("cp");
    $mysql = $unix->find_program("mysql");
    @mkdir($tmppath, 0755, true);
    writelogs("[{$servername}] Uncompress {$path} to {$tmppath}", __FUNCTION__, __FILE__, __LINE__);
    exec("{$tar} -xf {$path} -C {$tmppath}/ 2>&1", $results);
    while (list($num_line, $evenement) = each($results)) {
        if (trim($evenement) != null) {
            writelogs("[{$servername}] {$evenement}", __FUNCTION__, __FILE__, __LINE__);
        }
    }
    $results = array();
    if (!is_file("{$tmppath}/artica.restore")) {
        writelogs("[{$servername}] fatal {$tmppath}/artica.restore no such file...", __FUNCTION__, __FILE__, __LINE__);
        shell_exec("{$rm} -rf {$tmppath}");
        return;
    }
    $CONF = unserialize(base64_decode(@file_get_contents("{$tmppath}/artica.restore")));
    if (!is_array($CONF)) {
        writelogs("[{$servername}] fatal {$tmppath}/artica.restore no such array...", __FUNCTION__, __FILE__, __LINE__);
        shell_exec("{$rm} -rf {$tmppath}");
        return;
    }
    $CONF["mysql_instance_id"] = $instance_id;
    if ($servername == "DEFAULT") {
        $servername = $CONF["servername"];
    } else {
        $CONF["servername"] = $servername;
    }
    while (list($key, $value) = each($CONF)) {
        $fields[] = "`{$key}`";
        $values[] = "'" . addslashes($value) . "'";
        $edit[] = "`{$key}` = '" . addslashes($value) . "'";
    }
    $sqlAdd = "INSERT IGNORE INTO freeweb (" . @implode(",", $fields) . ") VALUES (" . @implode(",", $values) . ")";
    $sqledit = "UPDATE freeweb SET " . @implode(",", $edit) . " WHERE servername='{$servername}'";
    writelogs("[{$servername}] restore settings", __FUNCTION__, __FILE__, __LINE__);
    $sql = "SELECT servername from freeweb WHERE servername='{$servername}'";
    $q = new mysql();
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if ($ligne["servername"] == null) {
        $sql = $sqlAdd;
        writelogs("[{$servername}] Create the new website", __FUNCTION__, __FILE__, __LINE__);
    } else {
        writelogs("[{$servername}] restore the website settings", __FUNCTION__, __FILE__, __LINE__);
        $sql = $sqledit;
    }
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        writelogs("[{$servername}] fatal {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec("{$rm} -rf {$tmppath}");
        return;
    }
    @unlink("{$tmppath}/artica.restore");
    $free = new freeweb($servername);
    if (is_dir("{$tmppath}/MySQL")) {
        $filesArr = $unix->DirRecursiveFiles("{$tmppath}/MySQL", "*.sql");
        $sql_file = $filesArr[0];
    }
    writelogs("[{$servername}] database dump = `{$sql_file}`", __FUNCTION__, __FILE__, __LINE__);
    if (is_file($sql_file)) {
        writelogs("[{$servername}] Restoring database {$free->mysql_database} instance {$free->mysql_instance_id}", __FUNCTION__, __FILE__, __LINE__);
        $host = " --host={$q->mysql_server} --port={$q->mysql_port}";
        if ($instance_id > 0) {
            $q = new mysql_multi($instance_id);
            $host = " --socket={$q->SocketPath}";
        }
        $user = $q->mysql_admin;
        if ($q->mysql_password != null) {
            $adminpassword = $unix->shellEscapeChars($q->mysql_password);
            $adminpassword = str_replace("'", "", $adminpassword);
            $adminpassword = str_replace('$', '\\$', $adminpassword);
            $adminpassword = str_replace("'", '', $adminpassword);
            $adminpassword = "******";
            $adminpassword_text = " --password=*****";
        }
        if ($q->DATABASE_EXISTS($free->mysql_database)) {
            writelogs("[{$servername}] removing old database {$free->mysql_database}...", __FUNCTION__, __FILE__, __LINE__);
            $q->DELETE_DATABASE($free->mysql_database, true);
        }
        if (!$q->DATABASE_EXISTS($free->mysql_database)) {
            writelogs("[{$servername}] Creating database {$free->mysql_database}...", __FUNCTION__, __FILE__, __LINE__);
            $q->CREATE_DATABASE($free->mysql_database, true);
        }
        if (!$q->DATABASE_EXISTS($free->mysql_database)) {
            writelogs("[{$servername}] fatal Creating database {$free->mysql_database} failed...", __FUNCTION__, __FILE__, __LINE__);
            shell_exec("{$rm} -rf {$tmppath}");
            return;
        }
        $cmdline = "{$mysql} --user={$user}{$adminpassword}{$host} \"{$free->mysql_database}\" < {$sql_file} 2>&1";
        $cmdlineVer = "{$mysql} --user={$user}{$adminpassword_text}{$host} \"{$free->mysql_database}\" < {$sql_file} 2>&1";
        writelogs("[{$servername}] {$cmdlineVer}", __FUNCTION__, __FILE__, __LINE__);
        exec($cmdline, $results);
        while (list($num_line, $evenement) = each($results)) {
            if (trim($evenement) != null) {
                writelogs("[{$servername}] {$evenement}", __FUNCTION__, __FILE__, __LINE__);
            }
        }
        $results = array();
        if ($free->mysql_username != "root") {
            writelogs("[{$servername}] Setting privileges for {$free->mysql_username} on {$free->mysql_database}", __FUNCTION__, __FILE__, __LINE__);
            $q->PRIVILEGES($free->mysql_username, $free->mysql_password, $free->mysql_database);
        }
    }
    if (is_dir("{$tmppath}/MySQL")) {
        @unlink($sql_file);
    }
    writelogs("[{$servername}] restoring {$free->WORKING_DIRECTORY}", __FUNCTION__, __FILE__, __LINE__);
    @mkdir($free->WORKING_DIRECTORY, 0755, true);
    if (!is_dir($free->WORKING_DIRECTORY)) {
        writelogs("[{$servername}] fatal {$free->WORKING_DIRECTORY} permission denied...", __FUNCTION__, __FILE__, __LINE__);
        shell_exec("{$rm} -rf {$tmppath}");
        return;
    }
    $cmdline = "{$cp} -rf {$tmppath}/* {$free->WORKING_DIRECTORY}/ 2>&1";
    writelogs("[{$servername}] {$cmdline}", __FUNCTION__, __FILE__, __LINE__);
    exec($cmdline, $results);
    while (list($num_line, $evenement) = each($results)) {
        if (trim($evenement) != null) {
            writelogs("[{$servername}] {$evenement}", __FUNCTION__, __FILE__, __LINE__);
        }
    }
    $results = array();
    writelogs("[{$servername}] Cleaning temporary directory", __FUNCTION__, __FILE__, __LINE__);
    shell_exec("{$rm} -rf {$tmppath}");
    writelogs("[{$servername}] rebuild the website", __FUNCTION__, __FILE__, __LINE__);
    buildHost(null, $servername);
    if (!$GLOBALS["NO_HTTPD_CONF"]) {
        CheckHttpdConf();
    }
    if (!$GLOBALS["NO_HTTPD_RELOAD"]) {
        reload_apache();
    }
    $t2 = time();
    $took = $unix->distanceOfTimeInWords($t1, $t2, true);
    writelogs("[{$servername}] Finish restoring the website took:{$took}", __FUNCTION__, __FILE__, __LINE__);
}
Пример #2
0
function install_groupware_ARTICA_ADM($hostname){
	$sql="SELECT * FROM freeweb WHERE servername='$hostname'";
	$q=new mysql();
	$ligne=@mysql_fetch_array($q->QUERY_SQL($sql,'artica_backup'));	
	echo "Starting......: Apache \"$hostname\" Rebuilding host configuration file\n";
	buildHost($ligne["uid"],$hostname);
	reload_apache();
}
Пример #3
0
function group_office_install($servername, $nobuildHost = false, $rebuild = false)
{
    $sources = "/usr/local/share/artica/group-office";
    $unix = new unix();
    $cp = $unix->find_program("cp");
    $freeweb = new freeweb($servername);
    if (!is_dir($sources)) {
        writelogs("[{$servername}] {$sources} no such directory", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (!is_dir($freeweb->WORKING_DIRECTORY)) {
        writelogs("[{$servername}] {$freeweb->WORKING_DIRECTORY} no such directory", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (!is_file("{$freeweb->WORKING_DIRECTORY}/functions.inc.php")) {
        $mustrebuild = true;
    }
    if (!$mustrebuild) {
        $mustrebuild = $rebuild;
    }
    if ($mustrebuild) {
        writelogs("[{$servername}] copy sources...", __FUNCTION__, __FILE__, __LINE__);
        shell_exec("/bin/cp -rf {$sources}/* {$freeweb->WORKING_DIRECTORY}/");
        @file_put_contents("{$freeweb->WORKING_DIRECTORY}/config.php", "");
    }
    shell_exec("/bin/chmod 666 {$freeweb->WORKING_DIRECTORY}/config.php");
    $apacheusername = $unix->APACHE_SRC_ACCOUNT();
    $apachegroup = $unix->APACHE_SRC_GROUP();
    $freeweb->chown($freeweb->WORKING_DIRECTORY);
    if (!is_dir("/home/{$servername}")) {
        @mkdir("/home/{$servername}");
    }
    include_once dirname(__FILE__) . "/ressources/class.group-office.php";
    $gpoffice = new group_office($servername);
    $gpoffice->www_dir = $freeweb->WORKING_DIRECTORY;
    $gpoffice->rebuildb = $rebuild;
    writelogs("[{$servername}] gpoffice->writeconfigfile() {$freeweb->WORKING_DIRECTORY}", __FUNCTION__, __FILE__, __LINE__);
    $gpoffice->writeconfigfile();
    $freeweb->chown("/home/{$servername}");
    //a la find chmod 644 /var/www/office.touzeau.com/group-office/config.php
    if (!$nobuildHost) {
        buildHost(null, $servername);
    }
}