@@ -243,12 +243,61 @@ function update($event_name, $data) {
243243
244244 } else {
245245 if ($ data ['mirrored ' ] == true ) {
246- $ app ->log ('Skipping network config request. IP addresses from amster are not configured on the mirror. ' , LOGLEVEL_DEBUG );
246+ $ app ->log ('Skipping network config request. IP addresses from master are not configured on the mirror. ' , LOGLEVEL_DEBUG );
247247 }
248248 if ($ server_config ['auto_network_configuration ' ] == 'n ' ) {
249249 $ app ->log ('Network configuration disabled in server settings. ' , LOGLEVEL_DEBUG );
250250 }
251251 }
252+
253+ //* Configure hostname
254+ if ($ event_name == 'server_update ' && $ data ['mirrored ' ] == false ) {
255+
256+ //* get old server config
257+ $ tmp = $ app ->ini_parser ->parse_ini_string (stripslashes ($ data ['old ' ]['config ' ]));
258+ $ old_server_config = $ tmp ['server ' ];
259+ unset($ tmp );
260+
261+ $ new_hostname = trim ($ server_config ['hostname ' ]);
262+ $ old_hostname = trim ($ old_server_config ['hostname ' ]);
263+
264+ if ($ new_hostname != '' && $ old_hostname != $ new_hostname ) {
265+
266+ if (is_file ('/etc/hostname ' )) {
267+ $ app ->system ->file_put_contents ('/etc/hostname ' ,$ new_hostname );
268+ $ app ->log ('Changed /etc/hostname to ' .$ new_hostname , LOGLEVEL_DEBUG );
269+ }
270+
271+ if (is_file ('/etc/mailname ' )) {
272+ $ app ->system ->file_put_contents ('/etc/mailname ' ,$ new_hostname );
273+ $ app ->log ('Changed /etc/mailname to ' .$ new_hostname , LOGLEVEL_DEBUG );
274+ }
275+
276+ $ postconf_commands = array (
277+ 'myhostname = ' .$ new_hostname ,
278+ 'mydestination = ' .$ new_hostname .', localhost, localhost.localdomain '
279+ );
280+
281+ //* Executing the postconf commands
282+ foreach ($ postconf_commands as $ cmd ) {
283+ $ command = "postconf -e ' $ cmd' " ;
284+ exec ($ command );
285+ }
286+
287+ $ app ->log ('Changed changed myhostname and mydestination in postfix main.cf to ' .$ new_hostname , LOGLEVEL_DEBUG );
288+
289+ //* change /etc/hosts
290+ $ hosts = file_get_contents ('/etc/hosts ' );
291+ $ hosts = str_replace ($ old_hostname ,$ new_hostname ,$ hosts );
292+ $ app ->system ->file_put_contents ('/etc/hosts ' ,$ hosts );
293+
294+ exec ($ app ->system ->getinitcommand ('postfix ' , 'restart ' ).' 2>&1 ' );
295+ exec ($ app ->system ->getinitcommand ('networking ' , 'restart ' ).' 2>&1 ' );
296+
297+ }
298+
299+ }
300+
252301
253302 }
254303
0 commit comments