Skip to content

Commit 48ced19

Browse files
committed
Added server plugin for software update function.
1 parent 8065e06 commit 48ced19

File tree

4 files changed

+130
-2
lines changed

4 files changed

+130
-2
lines changed

install/tpl/config.inc.php.master

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ define("DB_PASSWORD",$conf["db_password"]);
108108
$conf["log_file"] = '/var/log/ispconfig/ispconfig.log';
109109
$conf["log_priority"] = {ispconfig_log_priority}; // 0 = Debug, 1 = Warning, 2 = Error
110110

111+
/*
112+
Allow software package installations
113+
*/
114+
115+
$conf['software_updates_enabled'] = false;
116+
117+
111118
/*
112119
Themes
113120
*/

interface/web/admin/software_package_list.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
$tmp = $app->db->queryOneRecord($sql);
7575
$software_update_id = $tmp['software_update_id'];
7676

77-
$insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installing')";
77+
// $insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installing')";
78+
$insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installed')";
7879
$app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id');
7980

8081
}

interface/web/admin/software_update_list.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@
104104
$server_id = intval($_GET['server_id']);
105105
$software_update_id = intval($_GET['id']);
106106

107-
$insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installing')";
107+
// $insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installing')";
108+
$insert_data = "(package_name, server_id, software_update_id, status) VALUES ('$package_name', '$server_id', '$software_update_id','installed')";
108109
$app->db->datalogInsert('software_update_inst', $insert_data, 'software_update_inst_id');
109110

110111
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2008, Till Brehm, projektfarm Gmbh
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
class software_update_plugin {
32+
33+
var $plugin_name = 'software_update_plugin';
34+
var $class_name = 'software_update_plugin';
35+
36+
37+
/*
38+
This function is called when the plugin is loaded
39+
*/
40+
41+
function onLoad() {
42+
global $app;
43+
44+
/*
45+
Register for the events
46+
*/
47+
48+
//* Mailboxes
49+
$app->plugins->registerEvent('software_update_inst_insert',$this->plugin_name,'process');
50+
//$app->plugins->registerEvent('software_update_inst_update',$this->plugin_name,'process');
51+
//$app->plugins->registerEvent('software_update_inst_delete',$this->plugin_name,'process');
52+
53+
54+
}
55+
56+
57+
function process($event_name,$data) {
58+
global $app, $conf;
59+
60+
if(!$conf['software_updates_enabled'] == true) {
61+
$app->log('Software Updates not eanbled on this server. To enable updates, set $conf["software_updates_enabled"] = true; in config.inc.php',LOGLEVEL_ERROR);
62+
return false;
63+
}
64+
65+
//* Get the info of the package:
66+
$software_update_id = intval($data["new"]["software_update_id"]);
67+
$software_update = $app->db->queryOneRecord("SELECT * FROM software_update WHERE software_update_id = '$software_update_id'");
68+
69+
$temp_dir = '/tmp/'.md5 (uniqid (rand()));
70+
$app->log("The temp dir is $temp_dir",LOGLEVEL_DEBUG);
71+
mkdir($temp_dir);
72+
if(!is_dir($temp_dir)) {
73+
$app->log("Unable to create temp directory.",LOGLEVEL_ERROR);
74+
return false;
75+
}
76+
77+
exec("cd $temp_dir && wget ".$software_update["update_url"]);
78+
$app->log("Downloading the update file from: ".$software_update["update_url"],LOGLEVEL_DEBUG);
79+
80+
$url_parts = parse_url($software_update["update_url"]);
81+
$update_filename = basename($url_parts["path"]);
82+
$app->log("The update filename is $update_filename",LOGLEVEL_DEBUG);
83+
84+
if(is_file($temp_dir.'/'.$update_filename)) {
85+
86+
//* Checking the md5sum
87+
if(md5_file($temp_dir.'/'.$update_filename) != $software_update["update_md5"]) {
88+
$app->log("The md5 sum of the downloaded file is incorrect. Update aborted.",LOGLEVEL_ERROR);
89+
exec("rm -rf $temp_dir");
90+
$app->log("Deleting the temp directory $temp_dir",LOGLEVEL_DEBUG);
91+
return false;
92+
}
93+
94+
95+
//* unpacking the update
96+
exec("cd $temp_dir && unzip $update_filename");
97+
98+
if(is_file($temp_dir.'/setup.sh')) {
99+
// Execute the setup script
100+
exec('chmod +x '.$temp_dir.'/setup.sh');
101+
$app->log("Executing setup.sh file in directory $temp_dir",LOGLEVEL_DEBUG);
102+
exec('cd '.$temp_dir.' && ./setup.sh');
103+
$app->db->query("UPDATE software_update_inst SET status = 'installed' WHERE software_update_inst_id = ".$data["new"]["software_update_inst_id"]);
104+
} else {
105+
$app->log("setup.sh file not found",LOGLEVEL_ERROR);
106+
}
107+
} else {
108+
$app->log("Download of the update file failed",LOGLEVEL_ERROR);
109+
}
110+
111+
exec("rm -rf $temp_dir");
112+
$app->log("Deleting the temp directory $temp_dir",LOGLEVEL_DEBUG);
113+
114+
}
115+
116+
117+
} // end class
118+
119+
?>

0 commit comments

Comments
 (0)