| | |
| | | parent::__construct($app); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Removes www from Domains name |
| | | * |
| | | * @param $filename the file to read |
| | | * @return $sxe a SimpleXMLElement handle |
| | | */ |
| | | public function getMainDomain($domain) { |
| | | if (substr($domain, 0, 4) == 'www.') $domain = substr($domain, 4); |
| | | return $domain; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Reads in a package metadata file and registers it's namespaces |
| | |
| | | //* Create the mysql database user if not existing |
| | | $tmp = $app->db->queryOneRecord("SELECT database_user_id FROM web_database_user WHERE database_user = ?", $settings['main_database_login']); |
| | | if(!$tmp) { |
| | | $tmppw = $app->db->queryOneRecord("SELECT PASSWORD(?) as `crypted`", $settings['main_database_password']); |
| | | $insert_data = array("sys_userid" => $websrv['sys_userid'], |
| | | "sys_groupid" => $websrv['sys_groupid'], |
| | | "sys_perm_user" => 'riud', |
| | |
| | | "server_id" => 0, |
| | | "database_user" => $settings['main_database_login'], |
| | | "database_user_prefix" => $dbuser_prefix, |
| | | "database_password" => "PASSWORD('" . $settings['main_database_password'] . "')" |
| | | "database_password" => $tmppw['crypted'] |
| | | ); |
| | | $mysql_db_user_id = $app->db->datalogInsert('web_database_user', $insert_data, 'database_user_id'); |
| | | } |
| | |
| | | $app->uses('tools_sites'); |
| | | |
| | | $webserver_id = 0; |
| | | $websrv = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = ?", $settings['main_domain']); |
| | | $websrv = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = ?", $this->getMainDomain($settings['main_domain'])); |
| | | if(!empty($websrv)) $webserver_id = $websrv['server_id']; |
| | | $customerid = $this->getCustomerIDFromDomain($settings['main_domain']); |
| | | $customerid = $this->getCustomerIDFromDomain($this->getMainDomain($settings['main_domain'])); |
| | | |
| | | if(empty($settings) || empty($webserver_id)) return false; |
| | | |
| | |
| | | //* Set PHP mode to php-fcgi and enable suexec in website on apache servers / set PHP mode to PHP-FPM on nginx servers |
| | | if($web_config['server_type'] == 'apache') { |
| | | if(($websrv['php'] != 'fast-cgi' || $websrv['suexec'] != 'y') && $websrv['php'] != 'php-fpm') { |
| | | $app->db->datalogUpdate('web_domain', "php = 'fast-cgi', suexec = 'y'", 'domain_id', $websrv['domain_id']); |
| | | $app->db->datalogUpdate('web_domain', array("php" => 'fast-cgi', "suexec" => 'y'), 'domain_id', $websrv['domain_id']); |
| | | } |
| | | } else { |
| | | // nginx |
| | | if($websrv['php'] != 'php-fpm' && $websrv['php'] != 'fast-cgi') { |
| | | $app->db->datalogUpdate('web_domain', "php = 'php-fpm'", 'domain_id', $websrv['domain_id']); |
| | | $app->db->datalogUpdate('web_domain', array("php" => 'php-fpm'), 'domain_id', $websrv['domain_id']); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | //* Insert new package instance |
| | | $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `customer_id`, `package_id`, `instance_status`) VALUES (".$app->functions->intval($websrv['sys_userid']).", ".$app->functions->intval($websrv['sys_groupid']).", 'riud', '".$app->db->quote($websrv['sys_perm_group'])."', '', ".$app->db->quote($webserver_id).",".$app->db->quote($customerid).", ".$app->db->quote($packageid).", ".INSTANCE_PENDING.")"; |
| | | $insert_data = array( |
| | | "sys_userid" => $websrv['sys_userid'], |
| | | "sys_groupid" => $websrv['sys_groupid'], |
| | | "sys_perm_user" => 'riud', |
| | | "sys_perm_group" => $websrv['sys_perm_group'], |
| | | "sys_perm_other" => '', |
| | | "server_id" => $webserver_id, |
| | | "customer_id" => $customerid, |
| | | "package_id" => $packageid, |
| | | "instance_status" => INSTANCE_PENDING |
| | | ); |
| | | $InstanceID = $app->db->datalogInsert('aps_instances', $insert_data, 'id'); |
| | | |
| | | //* Insert all package settings |
| | | if(is_array($settings)) { |
| | | foreach($settings as $key => $value) { |
| | | $insert_data = "(server_id, instance_id, name, value) VALUES (".$app->db->quote($webserver_id).",".$app->db->quote($InstanceID).", '".$app->db->quote($key)."', '".$app->db->quote($value)."')"; |
| | | $insert_data = array( |
| | | "server_id" => $webserver_id, |
| | | "instance_id" => $InstanceID, |
| | | "name" => $key, |
| | | "value" => $value |
| | | ); |
| | | $app->db->datalogInsert('aps_instances_settings', $insert_data, 'id'); |
| | | } |
| | | } |
| | | |
| | | //* Set package status to install afetr we inserted the settings |
| | | $app->db->datalogUpdate('aps_instances', "instance_status = ".INSTANCE_INSTALL, 'id', $InstanceID); |
| | | $app->db->datalogUpdate('aps_instances', array("instance_status" => INSTANCE_INSTALL), 'id', $InstanceID); |
| | | } |
| | | |
| | | /** |
| | |
| | | if($tmp['cnt'] < 1) $app->db->datalogDelete('web_database_user', 'database_user_id', $database_user); |
| | | } |
| | | |
| | | $app->db->datalogUpdate('aps_instances', "instance_status = ".INSTANCE_REMOVE, 'id', $instanceid); |
| | | $app->db->datalogUpdate('aps_instances', array("instance_status" => INSTANCE_REMOVE), 'id', $instanceid); |
| | | |
| | | } |
| | | |
| | |
| | | if(in_array($postinput['main_domain'], $domains)) |
| | | { |
| | | $docroot = $app->db->queryOneRecord("SELECT document_root FROM web_domain |
| | | WHERE domain = ?", $postinput['main_domain']); |
| | | WHERE domain = ?", $this->getMainDomain($postinput['main_domain'])); |
| | | $new_path = $docroot['document_root']; |
| | | if(substr($new_path, -1) != '/') $new_path .= '/'; |
| | | $new_path .= $main_location; |
| | | |
| | | // Get the $customerid which belongs to the selected domain |
| | | $customerid = $this->getCustomerIDFromDomain($postinput['main_domain']); |
| | | $customerid = $this->getCustomerIDFromDomain($this->getMainDomain($postinput['main_domain'])); |
| | | |
| | | // First get all domains used for an install, then their loop them |
| | | // and get the corresponding document roots as well as the defined |