From d5a0f240289c78b3c066af7c5fc0086d4850004c Mon Sep 17 00:00:00 2001 From: Jesse Norell Date: Thu, 22 Oct 2020 12:03:41 -0600 Subject: [PATCH 1/2] check for conf-custom templates during update --- install/lib/update.lib.php | 47 ++++++++++++++++++++++++++++++++++++++ install/update.php | 10 ++++---- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/install/lib/update.lib.php b/install/lib/update.lib.php index 4dcb31cff1..a28de0b798 100644 --- a/install/lib/update.lib.php +++ b/install/lib/update.lib.php @@ -459,4 +459,51 @@ function check_service_config_state($servicename, $detected_value) { } else return $current_state; } +/** + * Check for existing conf-custom templates and offer to rename them. + */ +function checkAndRenameCustomTemplates($default_prompt='no') { + global $inst; + $ret = true; + + $default_prompt = ($default_prompt == 'yes') ? 'yes' : 'no'; + + $template_directories = array( + '/usr/local/ispconfig/server/conf-custom', + '/usr/local/ispconfig/server/conf-custom/install', + ); + + $found_templates = array(); + foreach ($template_directories as $dir) { + if (!is_dir($dir)) { continue; } + $output = array(); + exec("find $dir -maxdepth 1 -name \*.master", $output); + foreach ($output as $f) { + if (is_file(trim($f))) { + $found_templates[] = trim($f); + } + } + } + + if (count($found_templates) > 0) { + echo "The following custom templates were found:\n\n"; + echo implode("\n", $found_templates) . "\n\n"; + + $answer = $inst->simple_query('Do you want to rename these conf-custom templates now so the default templates are used?', array('yes', 'no'), $default_prompt, 'rename_custom_templates'); + if (strtolower($answer) == 'yes') { + $date=date('-Y-m-d_H-i'); + foreach ($found_templates as $f) { + if (!rename($f, $f.$date)) { + echo "Error renaming template $f\n"; + $ret = false; + } + } + } else { + $ret = null; + } + } + + return $ret; +} + ?> diff --git a/install/update.php b/install/update.php index 685d52892f..c15678486f 100644 --- a/install/update.php +++ b/install/update.php @@ -370,6 +370,8 @@ $reconfigure_services_answer = $inst->simple_query('Reconfigure Services?', arra if($reconfigure_services_answer == 'yes' || $reconfigure_services_answer == 'selected') { + checkAndRenameCustomTemplates(); + if($conf['services']['mail']) { //** Configure postfix @@ -483,10 +485,10 @@ if($reconfigure_services_answer == 'yes' || $reconfigure_services_answer == 'sel } - if($conf['services']['xmpp'] && $inst->reconfigure_app('XMPP', $reconfigure_services_answer)) { - //** Configure Metronome XMPP - $inst->configure_xmpp('dont-create-certs'); - } + if($conf['services']['xmpp'] && $inst->reconfigure_app('XMPP', $reconfigure_services_answer)) { + //** Configure Metronome XMPP + $inst->configure_xmpp('dont-create-certs'); + } if($conf['services']['firewall'] && $inst->reconfigure_app('Firewall', $reconfigure_services_answer)) { if($conf['ufw']['installed'] == true) { -- GitLab From ab74ee2f66d4403bf3bb35bc9271c3e240719791 Mon Sep 17 00:00:00 2001 From: Jesse Norell Date: Thu, 22 Oct 2020 14:44:55 -0600 Subject: [PATCH 2/2] filenames via glob() --- install/lib/update.lib.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/install/lib/update.lib.php b/install/lib/update.lib.php index a28de0b798..6d67472fdd 100644 --- a/install/lib/update.lib.php +++ b/install/lib/update.lib.php @@ -476,11 +476,9 @@ function checkAndRenameCustomTemplates($default_prompt='no') { $found_templates = array(); foreach ($template_directories as $dir) { if (!is_dir($dir)) { continue; } - $output = array(); - exec("find $dir -maxdepth 1 -name \*.master", $output); - foreach ($output as $f) { - if (is_file(trim($f))) { - $found_templates[] = trim($f); + foreach (glob("$dir/*.master") as $f) { + if (is_file($f)) { + $found_templates[] = $f; } } } -- GitLab