Skip to content
Snippets Groups Projects
Commit 1d5f9b75 authored by Marius Burkard's avatar Marius Burkard
Browse files

Merge branch '4917-hosts-file-mirror' into 'develop'

Don't change /etc/hosts on mirrors (#4917)

Closes #4917

See merge request ispconfig/ispconfig3!1282
parents f5f9885a 25f19294
No related branches found
No related tags found
No related merge requests found
...@@ -249,55 +249,55 @@ class network_settings_plugin { ...@@ -249,55 +249,55 @@ class network_settings_plugin {
$app->log('Network configuration disabled in server settings.', LOGLEVEL_DEBUG); $app->log('Network configuration disabled in server settings.', LOGLEVEL_DEBUG);
} }
} }
//* Configure hostname //* Configure hostname
if($event_name == 'server_update' && $data['mirrored'] == false) { if($event_name == 'server_update' && $conf['mirror_server_id'] == 0) {
//* get old server config //* get old server config
$tmp = $app->ini_parser->parse_ini_string(stripslashes($data['old']['config'])); $tmp = $app->ini_parser->parse_ini_string(stripslashes($data['old']['config']));
$old_server_config = $tmp['server']; $old_server_config = $tmp['server'];
unset($tmp); unset($tmp);
$new_hostname = trim($server_config['hostname']); $new_hostname = trim($server_config['hostname']);
$old_hostname = trim($old_server_config['hostname']); $old_hostname = trim($old_server_config['hostname']);
if($new_hostname != '' && $old_hostname != $new_hostname) { if($new_hostname != '' && $old_hostname != $new_hostname) {
if(is_file('/etc/hostname')) { if(is_file('/etc/hostname')) {
$app->system->file_put_contents('/etc/hostname',$new_hostname); $app->system->file_put_contents('/etc/hostname',$new_hostname);
$app->log('Changed /etc/hostname to '.$new_hostname, LOGLEVEL_DEBUG); $app->log('Changed /etc/hostname to '.$new_hostname, LOGLEVEL_DEBUG);
} }
if(is_file('/etc/mailname')) { if(is_file('/etc/mailname')) {
$app->system->file_put_contents('/etc/mailname',$new_hostname); $app->system->file_put_contents('/etc/mailname',$new_hostname);
$app->log('Changed /etc/mailname to '.$new_hostname, LOGLEVEL_DEBUG); $app->log('Changed /etc/mailname to '.$new_hostname, LOGLEVEL_DEBUG);
} }
$postconf_commands = array( $postconf_commands = array(
'myhostname = '.$new_hostname, 'myhostname = '.$new_hostname,
'mydestination = '.$new_hostname.', localhost, localhost.localdomain' 'mydestination = '.$new_hostname.', localhost, localhost.localdomain'
); );
//* Executing the postconf commands //* Executing the postconf commands
foreach($postconf_commands as $cmd) { foreach($postconf_commands as $cmd) {
$command = "postconf -e ?"; $command = "postconf -e ?";
$app->system->exec_safe($command, $cmd); $app->system->exec_safe($command, $cmd);
} }
$app->log('Changed changed myhostname and mydestination in postfix main.cf to '.$new_hostname, LOGLEVEL_DEBUG); $app->log('Changed changed myhostname and mydestination in postfix main.cf to '.$new_hostname, LOGLEVEL_DEBUG);
//* change /etc/hosts //* change /etc/hosts
$hosts = file_get_contents('/etc/hosts'); $hosts = file_get_contents('/etc/hosts');
$hosts = str_replace($old_hostname,$new_hostname,$hosts); $hosts = str_replace($old_hostname,$new_hostname,$hosts);
$app->system->file_put_contents('/etc/hosts',$hosts); $app->system->file_put_contents('/etc/hosts',$hosts);
exec($app->system->getinitcommand('postfix', 'restart').' 2>&1'); exec($app->system->getinitcommand('postfix', 'restart').' 2>&1');
exec($app->system->getinitcommand('networking', 'restart').' 2>&1'); exec($app->system->getinitcommand('networking', 'restart').' 2>&1');
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment