From df8a460cfd4a21e35441bd1e0c4cefe6739463ea Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Fri, 26 Feb 2010 07:09:42 -0500
Subject: [PATCH] Impoved the software update function to enable the installation of apps like phpmyadmin into the apps vhost.
---
install/lib/installer_base.lib.php | 9 ++--
install/sql/ispconfig3.sql | 3 +
interface/web/admin/software_package_list.php | 3 +
server/plugins-available/apps_vhost_plugin.inc.php | 3 +
server/plugins-available/software_update_plugin.inc.php | 53 ++++++++++++++++++++------
5 files changed, 53 insertions(+), 18 deletions(-)
diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index bf14ca4..2b6c055 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -1076,9 +1076,9 @@
//* 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 @@
$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'];
diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql
index 78dbd3b..1b4ea37 100644
--- a/install/sql/ispconfig3.sql
+++ b/install/sql/ispconfig3.sql
@@ -699,6 +699,7 @@
`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 @@
`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;
diff --git a/interface/web/admin/software_package_list.php b/interface/web/admin/software_package_list.php
index 24c53ec..789a71e 100644
--- a/interface/web/admin/software_package_list.php
+++ b/interface/web/admin/software_package_list.php
@@ -55,8 +55,9 @@
$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++;
}
diff --git a/server/plugins-available/apps_vhost_plugin.inc.php b/server/plugins-available/apps_vhost_plugin.inc.php
index a87ef5e..47107b0 100644
--- a/server/plugins-available/apps_vhost_plugin.inc.php
+++ b/server/plugins-available/apps_vhost_plugin.inc.php
@@ -82,6 +82,9 @@
$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);
diff --git a/server/plugins-available/software_update_plugin.inc.php b/server/plugins-available/software_update_plugin.inc.php
index f3b0c32..71fbccc 100644
--- a/server/plugins-available/software_update_plugin.inc.php
+++ b/server/plugins-available/software_update_plugin.inc.php
@@ -72,26 +72,45 @@
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 @@
//* 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 @@
//* 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 @@
$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 @@
$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");
}
--
Gitblit v1.9.1