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