Skip to content

Commit d5a0f24

Browse files
committed
check for conf-custom templates during update
1 parent f4547c1 commit d5a0f24

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

install/lib/update.lib.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,51 @@ function check_service_config_state($servicename, $detected_value) {
459459
} else return $current_state;
460460
}
461461

462+
/**
463+
* Check for existing conf-custom templates and offer to rename them.
464+
*/
465+
function checkAndRenameCustomTemplates($default_prompt='no') {
466+
global $inst;
467+
$ret = true;
468+
469+
$default_prompt = ($default_prompt == 'yes') ? 'yes' : 'no';
470+
471+
$template_directories = array(
472+
'/usr/local/ispconfig/server/conf-custom',
473+
'/usr/local/ispconfig/server/conf-custom/install',
474+
);
475+
476+
$found_templates = array();
477+
foreach ($template_directories as $dir) {
478+
if (!is_dir($dir)) { continue; }
479+
$output = array();
480+
exec("find $dir -maxdepth 1 -name \*.master", $output);
481+
foreach ($output as $f) {
482+
if (is_file(trim($f))) {
483+
$found_templates[] = trim($f);
484+
}
485+
}
486+
}
487+
488+
if (count($found_templates) > 0) {
489+
echo "The following custom templates were found:\n\n";
490+
echo implode("\n", $found_templates) . "\n\n";
491+
492+
$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');
493+
if (strtolower($answer) == 'yes') {
494+
$date=date('-Y-m-d_H-i');
495+
foreach ($found_templates as $f) {
496+
if (!rename($f, $f.$date)) {
497+
echo "Error renaming template $f\n";
498+
$ret = false;
499+
}
500+
}
501+
} else {
502+
$ret = null;
503+
}
504+
}
505+
506+
return $ret;
507+
}
508+
462509
?>

install/update.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@
370370

371371
if($reconfigure_services_answer == 'yes' || $reconfigure_services_answer == 'selected') {
372372

373+
checkAndRenameCustomTemplates();
374+
373375
if($conf['services']['mail']) {
374376

375377
//** Configure postfix
@@ -483,10 +485,10 @@
483485

484486
}
485487

486-
if($conf['services']['xmpp'] && $inst->reconfigure_app('XMPP', $reconfigure_services_answer)) {
487-
//** Configure Metronome XMPP
488-
$inst->configure_xmpp('dont-create-certs');
489-
}
488+
if($conf['services']['xmpp'] && $inst->reconfigure_app('XMPP', $reconfigure_services_answer)) {
489+
//** Configure Metronome XMPP
490+
$inst->configure_xmpp('dont-create-certs');
491+
}
490492

491493
if($conf['services']['firewall'] && $inst->reconfigure_app('Firewall', $reconfigure_services_answer)) {
492494
if($conf['ufw']['installed'] == true) {

0 commit comments

Comments
 (0)