Commit df8a460c authored by tbrehm's avatar tbrehm
Browse files

Impoved the software update function to enable the installation of apps like...

Impoved the software update function to enable the installation of apps like phpmyadmin into the apps vhost.
parent 423b1d75
......@@ -1076,9 +1076,9 @@ class installer_base {
//* Create the ispconfig apps vhost user and group
$apps_vhost_user = $conf['web']['apps_vhost_user'];
$apps_vhost_group = $conf['web']['apps_vhost_group'];
$install_dir = $conf['web']['website_basedir'].'/apps';
$apps_vhost_user = escapeshellcmd($conf['web']['apps_vhost_user']);
$apps_vhost_group = escapeshellcmd($conf['web']['apps_vhost_group']);
$install_dir = escapeshellcmd($conf['web']['website_basedir'].'/apps');
$command = 'groupadd '.$apps_vhost_user;
if(!is_group($apps_vhost_group)) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
......@@ -1090,7 +1090,8 @@ class installer_base {
$command = 'adduser '.$conf['apache']['user'].' '.$apps_vhost_group;
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
exec('mkdir -p '.escapeshellcmd($conf['web']['website_basedir'].'/apps'));
exec('mkdir -p '.$install_dir);
exec("chown $apps_vhost_user:$apps_vhost_group $install_dir");
//* Copy the apps vhost file
$vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
......
......@@ -699,6 +699,7 @@ CREATE TABLE `software_package` (
`package_title` varchar(64) NOT NULL,
`package_description` text,
`package_version` varchar(8) default NULL,
`package_type` enum('ispconfig','app','web') NOT NULL default 'app',
PRIMARY KEY (`package_id`),
UNIQUE KEY `package_name` (`package_name`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
......@@ -757,7 +758,7 @@ CREATE TABLE `software_update_inst` (
`software_update_id` int(11) unsigned NOT NULL default '0',
`package_name` varchar(64) NOT NULL,
`server_id` int(11) unsigned NOT NULL,
`status` enum('none','installing','installed','deleting','deleted') NOT NULL default 'none',
`status` enum('none','installing','installed','deleting','deleted','failed') NOT NULL default 'none',
PRIMARY KEY (`software_update_inst_id`),
UNIQUE KEY `software_update_id` (`software_update_id`,`package_name`,`server_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1;
......
......@@ -55,8 +55,9 @@ if(is_array($repos)) {
$package_title = $app->db->quote($p['title']);
$package_description = $app->db->quote($p['description']);
$software_repo_id = intval($repo['software_repo_id']);
$package_type = $app->db->quote($p['type']);
$sql = "INSERT INTO software_package (software_repo_id, package_name, package_title, package_description) VALUES ($software_repo_id, '$package_name', '$package_title', '$package_description')";
$sql = "INSERT INTO software_package (software_repo_id, package_name, package_title, package_description,package_type) VALUES ($software_repo_id, '$package_name', '$package_title', '$package_description','$package_type')";
$app->db->query($sql);
$packages_added++;
}
......
......@@ -82,6 +82,9 @@ class apps_vhost_plugin {
$vhost_conf_enabled_dir = $web_config['vhost_conf_enabled_dir'];
$apps_vhost_servername = ($web_config['apps_vhost_servername'] == '')?'':'ServerName '.$web_config['apps_vhost_servername'];
$web_config['apps_vhost_port'] = (empty($web_config['apps_vhost_port']))?8081:$web_config['apps_vhost_port'];
$web_config['apps_vhost_ip'] = (empty($web_config['apps_vhost_ip']))?'_default_':$web_config['apps_vhost_ip'];
$content = str_replace('{apps_vhost_ip}', $web_config['apps_vhost_ip'], $content);
$content = str_replace('{apps_vhost_port}', $web_config['apps_vhost_port'], $content);
$content = str_replace('{apps_vhost_dir}', $web_config['website_basedir'].'/apps', $content);
......
......@@ -72,26 +72,45 @@ class software_update_plugin {
function process($event_name,$data) {
global $app, $conf;
if(!$conf['software_updates_enabled'] == true) {
$app->log('Software Updates not enabled on this server. To enable updates, set $conf["software_updates_enabled"] = true; in config.inc.php',LOGLEVEL_ERROR);
//* Get the info of the package:
$software_update_id = intval($data["new"]["software_update_id"]);
$software_update = $app->db->queryOneRecord("SELECT * FROM software_update WHERE software_update_id = '$software_update_id'");
$software_package = $app->db->queryOneRecord("SELECT * FROM software_package WHERE package_name = '".$app->db->quote($software_update['package_name'])."'");
if($software_package['package_type'] == 'ispconfig' && !$conf['software_updates_enabled'] == true) {
$app->log('Software Updates not enabled on this server. To enable updates, set $conf["software_updates_enabled"] = true; in config.inc.php',LOGLEVEL_WARN);
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
return false;
}
//* Get the info of the package:
$software_update_id = intval($data["new"]["software_update_id"]);
$software_update = $app->db->queryOneRecord("SELECT * FROM software_update WHERE software_update_id = '$software_update_id'");
$installuser = '';
if($software_package['package_type'] == 'ispconfig') {
$installuser = '';
} elseif ($software_package['package_type'] == 'app') {
$installuser = 'ispapps';
} else {
$app->log('package_type not supported',LOGLEVEL_WARN);
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
return false;
}
$temp_dir = '/tmp/'.md5 (uniqid (rand()));
$app->log("The temp dir is $temp_dir",LOGLEVEL_DEBUG);
mkdir($temp_dir);
if($installuser != '') exec('chown '.$installuser.' '.$temp_dir);
if(!is_dir($temp_dir)) {
$app->log("Unable to create temp directory.",LOGLEVEL_ERROR);
$app->log("Unable to create temp directory.",LOGLEVEL_WARN);
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
return false;
}
exec("cd $temp_dir && wget ".$software_update["update_url"]);
$cmd = "cd $temp_dir && wget ".$software_update["update_url"];
if($installuser == '') {
exec($cmd);
} else {
exec("su -c ".escapeshellarg($cmd)." $installuser");
}
$app->log("Downloading the update file from: ".$software_update["update_url"],LOGLEVEL_DEBUG);
$url_parts = parse_url($software_update["update_url"]);
......@@ -102,7 +121,7 @@ class software_update_plugin {
//* Checking the md5sum
if(md5_file($temp_dir.'/'.$update_filename) != $software_update["update_md5"]) {
$app->log("The md5 sum of the downloaded file is incorrect. Update aborted.",LOGLEVEL_ERROR);
$app->log("The md5 sum of the downloaded file is incorrect. Update aborted.",LOGLEVEL_WARN);
exec("rm -rf $temp_dir");
$app->log("Deleting the temp directory $temp_dir",LOGLEVEL_DEBUG);
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
......@@ -113,13 +132,23 @@ class software_update_plugin {
//* unpacking the update
exec("cd $temp_dir && unzip $update_filename");
$cmd = "cd $temp_dir && unzip $update_filename";
if($installuser == '') {
exec($cmd);
} else {
exec("su -c ".escapeshellarg($cmd)." $installuser");
}
if(is_file($temp_dir.'/setup.sh')) {
// Execute the setup script
exec('chmod +x '.$temp_dir.'/setup.sh');
$app->log("Executing setup.sh file in directory $temp_dir",LOGLEVEL_DEBUG);
exec('cd '.$temp_dir.' && ./setup.sh > package_install.log');
$cmd = 'cd '.$temp_dir.' && ./setup.sh > package_install.log';
if($installuser == '') {
exec($cmd);
} else {
exec("su -c ".escapeshellarg($cmd)." $installuser");
}
$log_data = @file_get_contents("{$temp_dir}/package_install.log");
if(preg_match("'.*\[OK\]\s*$'is", $log_data)) {
......@@ -127,7 +156,7 @@ class software_update_plugin {
$app->log($log_data,LOGLEVEL_DEBUG);
$this->set_install_status($data["new"]["software_update_inst_id"], "installed");
} else {
$app->log("Installation failed:\n\n" . $log_data,LOGLEVEL_ERROR);
$app->log("Installation failed:\n\n" . $log_data,LOGLEVEL_WARN);
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
}
} else {
......@@ -135,7 +164,7 @@ class software_update_plugin {
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
}
} else {
$app->log("Download of the update file failed",LOGLEVEL_ERROR);
$app->log("Download of the update file failed",LOGLEVEL_WARN);
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment