ftimme
2012-11-12 8e38755040c6c2073f92f0ffb087da530d0e7a0a
server/lib/classes/aps_installer.inc.php
@@ -77,7 +77,7 @@
        }
        catch(Exception $e)
        {
            $app->log('Aborting execution because '.$e->getMessage());
            $app->log('Aborting execution because '.$e->getMessage(), 1);
            return false;
        }
    }
@@ -252,12 +252,12 @@
        $this->domain = $main_domain['value'];
        
        // Get the document root
        $domain_res = $app->db->queryOneRecord("SELECT document_root FROM web_domain
        $domain_res = $app->db->queryOneRecord("SELECT document_root, web_folder, type FROM web_domain
            WHERE domain = '".$app->db->quote($this->domain)."';");
        $this->document_root = $domain_res['document_root'];
        
        // Get the sub location
        $location_res = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings
        $location_res = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings
            WHERE name = 'main_location' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
        $this->sublocation = $location_res['value'];
        
@@ -265,7 +265,8 @@
        if(substr($this->document_root, -1) != '/') $this->document_root .= '/';
        
        // Attention: ISPConfig Special: web files are in subfolder 'web' -> append it:
        $this->document_root .= 'web/';
        if($domain_res['type'] == 'vhostsubdomain') $this->document_root .= $domain_res['web_folder'] . '/';
        else $this->document_root .= 'web/';
        // If a subfolder is given, make sure it's path doesn't begin with / i.e. /phpbb
        if(substr($this->sublocation, 0, 1) == '/') $this->sublocation = substr($this->sublocation, 1);
@@ -312,14 +313,14 @@
        
        $this->newdb_name = $dbname_prefix.$task['CustomerID'].'aps'.$task['InstanceID'];
        $this->newdb_user = $dbuser_prefix.$task['CustomerID'].'aps'.$task['InstanceID'];
        $dbpw_res = $app->dbmaster->queryOneRecord("SELECT Value FROM aps_instances_settings
        $dbpw_res = $app->db->queryOneRecord("SELECT Value FROM aps_instances_settings
            WHERE Name = 'main_database_password' AND InstanceID = '".$app->db->quote($task['InstanceID'])."';");
        $newdb_pw = $dbpw_res['Value'];
 
        // In any case delete an existing database (install and removal procedure)
        $app->db->query('DROP DATABASE IF EXISTS `'.$app->db->quote($this->newdb_name).'`;');
        // Delete an already existing database with this name
        $app->dbmaster->query("DELETE FROM web_database WHERE database_name = '".$app->db->quote($this->newdb_name)."';");
        $app->db->query("DELETE FROM web_database WHERE database_name = '".$app->db->quote($this->newdb_name)."';");
        
        
        // Create the new database and assign it to a user
@@ -332,7 +333,7 @@
        
            // Add the new database to the customer databases
            // Assumes: charset = utf8
            $app->dbmaster->query('INSERT INTO web_database (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id,
            $app->db->query('INSERT INTO web_database (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id,
                type, database_name, database_user, database_password, database_charset, remote_access, remote_ips, active) 
                VALUES ('.$task['sys_userid'].', '.$task['sys_groupid'].', "'.$task['sys_perm_user'].'", "'.$task['sys_perm_group'].'", 
                "'.$task['sys_perm_other'].'", '.$app->db->quote($serverid).', "mysql", "'.$app->db->quote($this->newdb_name).'", 
@@ -343,16 +344,16 @@
        $mysqlver_res = $app->db->queryOneRecord('SELECT VERSION() as ver;');
        $mysqlver = $mysqlver_res['ver'];
      
      $tmp = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_password' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
      $tmp = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_password' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
        $newdb_pw = $tmp['value'];
      
      $tmp = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_host' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
      $tmp = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_host' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
        $newdb_host = $tmp['value'];
      
      $tmp = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_name' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
      $tmp = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_name' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
        $newdb_name = $tmp['value'];
      
      $tmp = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_login' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
      $tmp = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_login' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
        $newdb_login = $tmp['value'];
        
        $this->putenv[] = 'DB_'.$db_id.'_TYPE=mysql';
@@ -429,7 +430,7 @@
        {
            $app->dbmaster->query('UPDATE aps_instances SET instance_status = "'.INSTANCE_ERROR.'" 
                WHERE id = "'.$app->db->quote($task['instance_id']).'";');
            $app->log($e->getMessage());
            $app->log($e->getMessage(), 1);
            return false;
        }
        
@@ -445,7 +446,7 @@
    {
        global $app;
        
        $userdata = $app->dbmaster->queryAllRecords("SELECT name, value FROM aps_instances_settings
        $userdata = $app->db->queryAllRecords("SELECT name, value FROM aps_instances_settings
            WHERE instance_id = '".$app->db->quote($task['instance_id'])."';");
        if(empty($userdata)) return false;
        
@@ -565,7 +566,7 @@
        {
            $app->dbmaster->query('UPDATE aps_instances SET instance_status = "'.INSTANCE_ERROR.'" 
                WHERE id = "'.$app->db->quote($task['instance_id']).'";');
            $app->log($e->getMessage());
            $app->log($e->getMessage(), 1);
            return false;
        }
        
@@ -622,7 +623,7 @@
         curl_setopt($ch, CURLOPT_TIMEOUT, 0);
         curl_setopt($ch, CURLOPT_FAILONERROR, 1);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);     
         if(curl_exec($ch) === false) $app->log(curl_error ($ch),LOGLEVEL_DEBUG);
         if(curl_exec($ch) === false) $app->log(curl_error ($ch),1);
         fclose($fh);
         curl_close($ch);
      }
@@ -646,7 +647,7 @@
        {
            $app->dbmaster->query('UPDATE aps_instances SET instance_status = "'.INSTANCE_ERROR.'" 
                WHERE id = "'.$app->db->quote($task['instance_id']).'";');
            $app->log('Unable to find the meta data file of package '.$task['path']);
            $app->log('Unable to find the meta data file of package '.$task['path'], 1);
            return false;
        }
        
@@ -678,8 +679,8 @@
        // Finally delete the instance entry + settings
        if($this->handle_type == 'delete')
        {
            $app->dbmaster->query('DELETE FROM aps_instances WHERE id = "'.$app->db->quote($task['instance_id']).'";');
            $app->dbmaster->query('DELETE FROM aps_instances_settings WHERE instance_id = "'.$app->db->quote($task['instance_id']).'";');
            $app->db->query('DELETE FROM aps_instances WHERE id = "'.$app->db->quote($task['instance_id']).'";');
            $app->db->query('DELETE FROM aps_instances_settings WHERE instance_id = "'.$app->db->quote($task['instance_id']).'";');
        }
        
        unset($sxe);