1+ <?php
2+
3+ /*
4+ Copyright (c) 2007-2011, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
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 webserver_plugin {
32+
33+ var $ plugin_name = 'webserver_plugin ' ;
34+ var $ class_name = 'webserver_plugin ' ;
35+
36+ /**
37+ * This function is called during ispconfig installation to determine
38+ * if a symlink shall be created for this plugin.
39+ */
40+ public function onInstall () {
41+ global $ conf ;
42+
43+ if ($ conf ['services ' ]['web ' ] == true ) {
44+ return true ;
45+ } else {
46+ return false ;
47+ }
48+ }
49+
50+ /**
51+ * This function is called when the module is loaded
52+ */
53+ public function onLoad () {
54+ global $ app ;
55+
56+ $ app ->plugins ->registerAction ('server_plugins_loaded ' , $ this ->plugin_name , 'check_phpini_changes ' );
57+ }
58+
59+ /**
60+ * This function is called when a change in one of the registered tables is detected.
61+ * The function then raises the events for the plugins.
62+ */
63+ public function process ($ tablename , $ action , $ data ) {
64+ // not needed
65+ }
66+
67+ /**
68+ * The method checks for a change of a php.ini file
69+ */
70+ public function check_phpini_changes () {
71+ global $ app , $ conf ;
72+
73+ //** check if the main php.ini of the system changed so we need to regenerate all custom php.inis
74+ $ app ->uses ('getconf ' );
75+
76+ //** files to check
77+ $ check_files = array ();
78+
79+ $ web_config = $ app ->getconf ->get_server_config ($ conf ['server_id ' ], 'web ' );
80+ $ fastcgi_config = $ app ->getconf ->get_server_config ($ conf ['server_id ' ], 'fastcgi ' );
81+
82+ //** add default php.ini files to check
83+ $ check_files [] = array ('file ' => $ web_config ['php_ini_path_apache ' ],
84+ 'mode ' => 'mod ' ,
85+ 'php_version ' => '' ); // default;
86+
87+ $ check_files [] = array ('file ' => $ web_config ['php_ini_path_cgi ' ],
88+ 'mode ' => '' , // all but 'mod' and 'fast-cgi'
89+ 'php_version ' => '' ); // default;
90+
91+ if ($ fastcgi_config ["fastcgi_phpini_path " ] && $ fastcgi_config ["fastcgi_phpini_path " ] != $ web_config ['php_ini_path_cgi ' ]) {
92+ $ check_files [] = array ('file ' => $ fastcgi_config ["fastcgi_phpini_path " ],
93+ 'mode ' => 'fast-cgi ' ,
94+ 'php_version ' => '' ); // default;
95+ } else {
96+ $ check_files [] = array ('file ' => $ web_config ['php_ini_path_cgi ' ],
97+ 'mode ' => 'fast-cgi ' , // all but 'mod'
98+ 'php_version ' => '' ); // default;
99+ }
100+
101+
102+ //** read additional php versions of this server
103+ $ php_versions = $ app ->db ->queryAllRecords ('SELECT server_php_id, php_fastcgi_ini_dir, php_fpm_ini_dir FROM server_php WHERE server_id = ' . intval ($ conf ['server_id ' ]));
104+ foreach ($ php_versions as $ php ) {
105+ if ($ php ['php_fastcgi_ini_dir ' ] && $ php ['php_fastcgi_ini_dir ' ] . '/php.ini ' != $ web_config ['php_ini_path_cgi ' ]) {
106+ $ check_files [] = array ('file ' => $ php ['php_fastcgi_ini_dir ' ] . '/php.ini ' ,
107+ 'mode ' => 'fast-cgi ' ,
108+ 'php_version ' => $ php ['php_fastcgi_ini_dir ' ]);
109+ } elseif ($ php ['php_fpm_ini_dir ' ] && $ php ['php_fpm_ini_dir ' ] . '/php.ini ' != $ web_config ['php_ini_path_cgi ' ]) {
110+ $ check_files [] = array ('file ' => $ php ['php_fpm_ini_dir ' ] . '/php.ini ' ,
111+ 'mode ' => 'php-fpm ' ,
112+ 'php_version ' => $ php ['php_fpm_ini_dir ' ]);
113+ }
114+ }
115+ unset($ php_versions );
116+
117+ //** read md5sum status file
118+ $ new_php_ini_md5 = array ();
119+ $ php_ini_md5 = array ();
120+ $ php_ini_changed = false ;
121+ if (file_exists (SCRIPT_PATH . '/php.ini.md5sum ' )) $ php_ini_md5 = unserialize (base64_decode (trim ($ app ->system ->file_get_contents (SCRIPT_PATH . '/php.ini.md5sum ' ))));
122+ if (!is_array ($ php_ini_md5 )) $ php_ini_md5 = array ();
123+
124+ $ processed = array ();
125+ foreach ($ check_files as $ file ) {
126+ $ file_path = $ file ['file ' ];
127+ if (substr ($ file_path , -8 ) !== '/php.ini ' ) $ file_path .= (substr ($ file_path , -1 ) !== '/ ' ? '/ ' : '' ) . 'php.ini ' ;
128+ if (!file_exists ($ file_path )) continue ;
129+
130+ //** check if this php.ini file was already processed (if additional php version uses same php.ini)
131+ $ ident = $ file_path . ':: ' . $ file ['mode ' ] . ':: ' . $ file ['php_version ' ];
132+ if (in_array ($ ident , $ processed ) == true ) continue ;
133+ $ processed [] = $ ident ;
134+
135+ //** check if md5sum of file changed
136+ $ file_md5 = md5_file ($ file_path );
137+ if (array_key_exists ($ file_path , $ php_ini_md5 ) == false || $ php_ini_md5 [$ file_path ] != $ file_md5 ) {
138+ $ php_ini_changed = true ;
139+
140+ $ app ->log ('Info: PHP.ini changed: ' . $ file_path . ', mode ' . $ file ['mode ' ] . ' vers ' . $ file ['php_version ' ] . '. ' ,LOGLEVEL_DEBUG );
141+ // raise action for this file
142+ $ app ->plugins ->raiseAction ('php_ini_changed ' , $ file );
143+ }
144+
145+ $ new_php_ini_md5 [$ file_path ] = $ file_md5 ;
146+ }
147+
148+ //** write new md5 sums if something changed
149+ if ($ php_ini_changed == true ) $ app ->system ->file_put_contents (SCRIPT_PATH . '/php.ini.md5sum ' , base64_encode (serialize ($ new_php_ini_md5 )));
150+ unset($ new_php_ini_md5 );
151+ unset($ php_ini_md5 );
152+ unset($ processed );
153+ }
154+ }
155+
156+ ?>
0 commit comments