Skip to content

Commit df8a460

Browse files
committed
Impoved the software update function to enable the installation of apps like phpmyadmin into the apps vhost.
1 parent 423b1d7 commit df8a460

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

install/lib/installer_base.lib.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,9 +1076,9 @@ public function configure_apps_vhost()
10761076

10771077
//* Create the ispconfig apps vhost user and group
10781078

1079-
$apps_vhost_user = $conf['web']['apps_vhost_user'];
1080-
$apps_vhost_group = $conf['web']['apps_vhost_group'];
1081-
$install_dir = $conf['web']['website_basedir'].'/apps';
1079+
$apps_vhost_user = escapeshellcmd($conf['web']['apps_vhost_user']);
1080+
$apps_vhost_group = escapeshellcmd($conf['web']['apps_vhost_group']);
1081+
$install_dir = escapeshellcmd($conf['web']['website_basedir'].'/apps');
10821082

10831083
$command = 'groupadd '.$apps_vhost_user;
10841084
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 @@ public function configure_apps_vhost()
10901090
$command = 'adduser '.$conf['apache']['user'].' '.$apps_vhost_group;
10911091
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
10921092

1093-
exec('mkdir -p '.escapeshellcmd($conf['web']['website_basedir'].'/apps'));
1093+
exec('mkdir -p '.$install_dir);
1094+
exec("chown $apps_vhost_user:$apps_vhost_group $install_dir");
10941095

10951096
//* Copy the apps vhost file
10961097
$vhost_conf_dir = $conf['apache']['vhost_conf_dir'];

install/sql/ispconfig3.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ CREATE TABLE `software_package` (
699699
`package_title` varchar(64) NOT NULL,
700700
`package_description` text,
701701
`package_version` varchar(8) default NULL,
702+
`package_type` enum('ispconfig','app','web') NOT NULL default 'app',
702703
PRIMARY KEY (`package_id`),
703704
UNIQUE KEY `package_name` (`package_name`)
704705
) ENGINE=MyISAM AUTO_INCREMENT=1;
@@ -757,7 +758,7 @@ CREATE TABLE `software_update_inst` (
757758
`software_update_id` int(11) unsigned NOT NULL default '0',
758759
`package_name` varchar(64) NOT NULL,
759760
`server_id` int(11) unsigned NOT NULL,
760-
`status` enum('none','installing','installed','deleting','deleted') NOT NULL default 'none',
761+
`status` enum('none','installing','installed','deleting','deleted','failed') NOT NULL default 'none',
761762
PRIMARY KEY (`software_update_inst_id`),
762763
UNIQUE KEY `software_update_id` (`software_update_id`,`package_name`,`server_id`)
763764
) ENGINE=MyISAM AUTO_INCREMENT=1;

interface/web/admin/software_package_list.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
$package_title = $app->db->quote($p['title']);
5656
$package_description = $app->db->quote($p['description']);
5757
$software_repo_id = intval($repo['software_repo_id']);
58+
$package_type = $app->db->quote($p['type']);
5859

59-
$sql = "INSERT INTO software_package (software_repo_id, package_name, package_title, package_description) VALUES ($software_repo_id, '$package_name', '$package_title', '$package_description')";
60+
$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')";
6061
$app->db->query($sql);
6162
$packages_added++;
6263
}

server/plugins-available/apps_vhost_plugin.inc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ function update($event_name,$data) {
8282
$vhost_conf_enabled_dir = $web_config['vhost_conf_enabled_dir'];
8383
$apps_vhost_servername = ($web_config['apps_vhost_servername'] == '')?'':'ServerName '.$web_config['apps_vhost_servername'];
8484

85+
$web_config['apps_vhost_port'] = (empty($web_config['apps_vhost_port']))?8081:$web_config['apps_vhost_port'];
86+
$web_config['apps_vhost_ip'] = (empty($web_config['apps_vhost_ip']))?'_default_':$web_config['apps_vhost_ip'];
87+
8588
$content = str_replace('{apps_vhost_ip}', $web_config['apps_vhost_ip'], $content);
8689
$content = str_replace('{apps_vhost_port}', $web_config['apps_vhost_port'], $content);
8790
$content = str_replace('{apps_vhost_dir}', $web_config['website_basedir'].'/apps', $content);

server/plugins-available/software_update_plugin.inc.php

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,45 @@ function set_install_status($inst_id, $status) {
7272
function process($event_name,$data) {
7373
global $app, $conf;
7474

75-
if(!$conf['software_updates_enabled'] == true) {
76-
$app->log('Software Updates not enabled on this server. To enable updates, set $conf["software_updates_enabled"] = true; in config.inc.php',LOGLEVEL_ERROR);
75+
//* Get the info of the package:
76+
$software_update_id = intval($data["new"]["software_update_id"]);
77+
$software_update = $app->db->queryOneRecord("SELECT * FROM software_update WHERE software_update_id = '$software_update_id'");
78+
$software_package = $app->db->queryOneRecord("SELECT * FROM software_package WHERE package_name = '".$app->db->quote($software_update['package_name'])."'");
79+
80+
if($software_package['package_type'] == 'ispconfig' && !$conf['software_updates_enabled'] == true) {
81+
$app->log('Software Updates not enabled on this server. To enable updates, set $conf["software_updates_enabled"] = true; in config.inc.php',LOGLEVEL_WARN);
7782
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
7883
return false;
7984
}
8085

81-
//* Get the info of the package:
82-
$software_update_id = intval($data["new"]["software_update_id"]);
83-
$software_update = $app->db->queryOneRecord("SELECT * FROM software_update WHERE software_update_id = '$software_update_id'");
86+
$installuser = '';
87+
if($software_package['package_type'] == 'ispconfig') {
88+
$installuser = '';
89+
} elseif ($software_package['package_type'] == 'app') {
90+
$installuser = 'ispapps';
91+
} else {
92+
$app->log('package_type not supported',LOGLEVEL_WARN);
93+
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
94+
return false;
95+
}
8496

8597
$temp_dir = '/tmp/'.md5 (uniqid (rand()));
8698
$app->log("The temp dir is $temp_dir",LOGLEVEL_DEBUG);
8799
mkdir($temp_dir);
100+
if($installuser != '') exec('chown '.$installuser.' '.$temp_dir);
101+
88102
if(!is_dir($temp_dir)) {
89-
$app->log("Unable to create temp directory.",LOGLEVEL_ERROR);
103+
$app->log("Unable to create temp directory.",LOGLEVEL_WARN);
90104
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
91105
return false;
92106
}
93107

94-
exec("cd $temp_dir && wget ".$software_update["update_url"]);
108+
$cmd = "cd $temp_dir && wget ".$software_update["update_url"];
109+
if($installuser == '') {
110+
exec($cmd);
111+
} else {
112+
exec("su -c ".escapeshellarg($cmd)." $installuser");
113+
}
95114
$app->log("Downloading the update file from: ".$software_update["update_url"],LOGLEVEL_DEBUG);
96115

97116
$url_parts = parse_url($software_update["update_url"]);
@@ -102,7 +121,7 @@ function process($event_name,$data) {
102121

103122
//* Checking the md5sum
104123
if(md5_file($temp_dir.'/'.$update_filename) != $software_update["update_md5"]) {
105-
$app->log("The md5 sum of the downloaded file is incorrect. Update aborted.",LOGLEVEL_ERROR);
124+
$app->log("The md5 sum of the downloaded file is incorrect. Update aborted.",LOGLEVEL_WARN);
106125
exec("rm -rf $temp_dir");
107126
$app->log("Deleting the temp directory $temp_dir",LOGLEVEL_DEBUG);
108127
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
@@ -113,29 +132,39 @@ function process($event_name,$data) {
113132

114133

115134
//* unpacking the update
116-
exec("cd $temp_dir && unzip $update_filename");
135+
$cmd = "cd $temp_dir && unzip $update_filename";
136+
if($installuser == '') {
137+
exec($cmd);
138+
} else {
139+
exec("su -c ".escapeshellarg($cmd)." $installuser");
140+
}
117141

118142
if(is_file($temp_dir.'/setup.sh')) {
119143
// Execute the setup script
120144
exec('chmod +x '.$temp_dir.'/setup.sh');
121145
$app->log("Executing setup.sh file in directory $temp_dir",LOGLEVEL_DEBUG);
122-
exec('cd '.$temp_dir.' && ./setup.sh > package_install.log');
146+
$cmd = 'cd '.$temp_dir.' && ./setup.sh > package_install.log';
147+
if($installuser == '') {
148+
exec($cmd);
149+
} else {
150+
exec("su -c ".escapeshellarg($cmd)." $installuser");
151+
}
123152

124153
$log_data = @file_get_contents("{$temp_dir}/package_install.log");
125154
if(preg_match("'.*\[OK\]\s*$'is", $log_data)) {
126155
$app->log("Installation successful",LOGLEVEL_DEBUG);
127156
$app->log($log_data,LOGLEVEL_DEBUG);
128157
$this->set_install_status($data["new"]["software_update_inst_id"], "installed");
129158
} else {
130-
$app->log("Installation failed:\n\n" . $log_data,LOGLEVEL_ERROR);
159+
$app->log("Installation failed:\n\n" . $log_data,LOGLEVEL_WARN);
131160
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
132161
}
133162
} else {
134163
$app->log("setup.sh file not found",LOGLEVEL_ERROR);
135164
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
136165
}
137166
} else {
138-
$app->log("Download of the update file failed",LOGLEVEL_ERROR);
167+
$app->log("Download of the update file failed",LOGLEVEL_WARN);
139168
$this->set_install_status($data["new"]["software_update_inst_id"], "failed");
140169
}
141170

0 commit comments

Comments
 (0)