replace config-template-variables also in commands to be executed, e.g. used in proftpd ssl-cert generation command

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2016-05-29 09:41:38 +02:00
parent 08563e9298
commit e5c16439e1

View File

@@ -20,198 +20,198 @@ require './lib/init.php';
if ($userinfo['change_serversettings'] == '1') { if ($userinfo['change_serversettings'] == '1') {
$replace_arr = Array( $replace_arr = Array(
'<SQL_UNPRIVILEGED_USER>' => $sql['user'], '<SQL_UNPRIVILEGED_USER>' => $sql['user'],
'<SQL_UNPRIVILEGED_PASSWORD>' => 'MYSQL_PASSWORD', '<SQL_UNPRIVILEGED_PASSWORD>' => 'MYSQL_PASSWORD',
'<SQL_DB>' => $sql['db'], '<SQL_DB>' => $sql['db'],
'<SQL_HOST>' => $sql['host'], '<SQL_HOST>' => $sql['host'],
'<SQL_SOCKET>' => isset($sql['socket']) ? $sql['socket'] : null, '<SQL_SOCKET>' => isset($sql['socket']) ? $sql['socket'] : null,
'<SERVERNAME>' => Settings::Get('system.hostname'), '<SERVERNAME>' => Settings::Get('system.hostname'),
'<SERVERIP>' => Settings::Get('system.ipaddress'), '<SERVERIP>' => Settings::Get('system.ipaddress'),
'<NAMESERVERS>' => Settings::Get('system.nameservers'), '<NAMESERVERS>' => Settings::Get('system.nameservers'),
'<VIRTUAL_MAILBOX_BASE>' => Settings::Get('system.vmail_homedir'), '<VIRTUAL_MAILBOX_BASE>' => Settings::Get('system.vmail_homedir'),
'<VIRTUAL_UID_MAPS>' => Settings::Get('system.vmail_uid'), '<VIRTUAL_UID_MAPS>' => Settings::Get('system.vmail_uid'),
'<VIRTUAL_GID_MAPS>' => Settings::Get('system.vmail_gid'), '<VIRTUAL_GID_MAPS>' => Settings::Get('system.vmail_gid'),
'<SSLPROTOCOLS>' => (Settings::Get('system.use_ssl') == '1') ? 'imaps pop3s' : '', '<SSLPROTOCOLS>' => (Settings::Get('system.use_ssl') == '1') ? 'imaps pop3s' : '',
'<CUSTOMER_TMP>' => (Settings::Get('system.mod_fcgid_tmpdir') != '') ? makeCorrectDir(Settings::Get('system.mod_fcgid_tmpdir')) : '/tmp/', '<CUSTOMER_TMP>' => (Settings::Get('system.mod_fcgid_tmpdir') != '') ? makeCorrectDir(Settings::Get('system.mod_fcgid_tmpdir')) : '/tmp/',
'<BASE_PATH>' => makeCorrectDir(FROXLOR_INSTALL_DIR), '<BASE_PATH>' => makeCorrectDir(FROXLOR_INSTALL_DIR),
'<BIND_CONFIG_PATH>' => makeCorrectDir(Settings::Get('system.bindconf_directory')), '<BIND_CONFIG_PATH>' => makeCorrectDir(Settings::Get('system.bindconf_directory')),
'<WEBSERVER_RELOAD_CMD>' => Settings::Get('system.apachereload_command'), '<WEBSERVER_RELOAD_CMD>' => Settings::Get('system.apachereload_command'),
'<CUSTOMER_LOGS>' => makeCorrectDir(Settings::Get('system.logfiles_directory')), '<CUSTOMER_LOGS>' => makeCorrectDir(Settings::Get('system.logfiles_directory')),
'<FPM_IPCDIR>' => makeCorrectDir(Settings::Get('phpfpm.fastcgi_ipcdir')), '<FPM_IPCDIR>' => makeCorrectDir(Settings::Get('phpfpm.fastcgi_ipcdir')),
'<WEBSERVER_GROUP>' => Settings::Get('system.httpgroup') '<WEBSERVER_GROUP>' => Settings::Get('system.httpgroup')
); );
// get distro from URL param // get distro from URL param
$distribution = (isset($_GET['distribution']) && $_GET['distribution'] != 'choose') ? $_GET['distribution'] : ""; $distribution = (isset($_GET['distribution']) && $_GET['distribution'] != 'choose') ? $_GET['distribution'] : "";
$service = (isset($_GET['service']) && $_GET['service'] != 'choose') ? $_GET['service'] : ""; $service = (isset($_GET['service']) && $_GET['service'] != 'choose') ? $_GET['service'] : "";
$daemon = (isset($_GET['daemon']) && $_GET['daemon'] != 'choose') ? $_GET['daemon'] : ""; $daemon = (isset($_GET['daemon']) && $_GET['daemon'] != 'choose') ? $_GET['daemon'] : "";
$distributions_select = ""; $distributions_select = "";
$services_select = ""; $services_select = "";
$daemons_select = ""; $daemons_select = "";
$configfiles = ""; $configfiles = "";
$services = ""; $services = "";
$daemons = ""; $daemons = "";
$config_dir = makeCorrectDir(FROXLOR_INSTALL_DIR . '/lib/configfiles/'); $config_dir = makeCorrectDir(FROXLOR_INSTALL_DIR . '/lib/configfiles/');
if ($distribution != "") { if ($distribution != "") {
// create configparser object // create configparser object
$configfiles = new ConfigParser($config_dir . '/' . $distribution . ".xml"); $configfiles = new ConfigParser($config_dir . '/' . $distribution . ".xml");
// get distro-info // get distro-info
$dist_display = getCompleteDistroName($configfiles); $dist_display = getCompleteDistroName($configfiles);
// get all the services from the distro // get all the services from the distro
$services = $configfiles->getServices(); $services = $configfiles->getServices();
if ($service != "") { if ($service != "") {
$daemons = $services[$service]->getDaemons(); $daemons = $services[$service]->getDaemons();
if ($daemon == "") { if ($daemon == "") {
foreach ($daemons as $di => $dd) { foreach ($daemons as $di => $dd) {
$title = $dd->title; $title = $dd->title;
if ($dd->default) { if ($dd->default) {
$title = $title." (".strtolower($lng['panel']['default']).")"; $title = $title . " (" . strtolower($lng['panel']['default']) . ")";
} }
$daemons_select .= makeoption($title, $di); $daemons_select .= makeoption($title, $di);
} }
} }
} else { } else {
foreach ($services as $si => $sd) { foreach ($services as $si => $sd) {
$services_select .= makeoption($sd->title, $si); $services_select .= makeoption($sd->title, $si);
} }
} }
} else { } else {
// show list of available distro's // show list of available distro's
$distros = glob($config_dir . '*.xml'); $distros = glob($config_dir . '*.xml');
// tmp array // tmp array
$distributions_select_data = array(); $distributions_select_data = array();
// read in all the distros // read in all the distros
foreach ($distros as $_distribution) { foreach ($distros as $_distribution) {
// get configparser object // get configparser object
$dist = new ConfigParser($_distribution); $dist = new ConfigParser($_distribution);
// get distro-info // get distro-info
$dist_display = getCompleteDistroName($dist); $dist_display = getCompleteDistroName($dist);
// store in tmp array // store in tmp array
$distributions_select_data[$dist_display] = str_replace(".xml", "", strtolower(basename($_distribution))); $distributions_select_data[$dist_display] = str_replace(".xml", "", strtolower(basename($_distribution)));
} }
// sort by distribution name // sort by distribution name
ksort($distributions_select_data); ksort($distributions_select_data);
foreach ($distributions_select_data as $dist_display => $dist_index) { foreach ($distributions_select_data as $dist_display => $dist_index) {
// create select-box-option // create select-box-option
$distributions_select .= makeoption($dist_display, $dist_index); $distributions_select .= makeoption($dist_display, $dist_index);
} }
} }
if ($distribution != "" && $service != "" && $daemon != "") { if ($distribution != "" && $service != "" && $daemon != "") {
$confarr = $daemons[$daemon]->getConfig(); $confarr = $daemons[$daemon]->getConfig();
$configpage = ''; $configpage = '';
$distro_editor = $configfiles->distributionEditor; $distro_editor = $configfiles->distributionEditor;
$commands_pre = ""; $commands_pre = "";
$commands_file = ""; $commands_file = "";
$commands_post = ""; $commands_post = "";
$lasttype = ''; $lasttype = '';
$commands = ''; $commands = '';
foreach ($confarr as $idx => $action) { foreach ($confarr as $idx => $action) {
if ($lasttype != '' && $lasttype != $action['type']) { if ($lasttype != '' && $lasttype != $action['type']) {
$commands = trim($commands); $commands = trim($commands);
$numbrows = count(explode("\n", $commands)); $numbrows = count(explode("\n", $commands));
eval("\$configpage.=\"" . getTemplate("configfiles/configfiles_commands") . "\";"); eval("\$configpage.=\"" . getTemplate("configfiles/configfiles_commands") . "\";");
$lasttype = ''; $lasttype = '';
$commands = ''; $commands = '';
} }
switch ($action['type']) { switch ($action['type']) {
case "install": case "install":
$commands .= $action['content'] . "\n"; $commands .= strtr($action['content'], $replace_arr) . "\n";
$lasttype = "install"; $lasttype = "install";
break; break;
case "command": case "command":
$commands .= $action['content'] . "\n"; $commands .= strtr($action['content'], $replace_arr) . "\n";
$lasttype = "command"; $lasttype = "command";
break; break;
case "file": case "file":
if (array_key_exists('content', $action)) { if (array_key_exists('content', $action)) {
$commands_file = getFileContentContainer($action['content'], $replace_arr, $action['name'], $distro_editor); $commands_file = getFileContentContainer($action['content'], $replace_arr, $action['name'], $distro_editor);
} elseif (array_key_exists('subcommands', $action)) { } elseif (array_key_exists('subcommands', $action)) {
foreach ($action['subcommands'] as $fileaction) { foreach ($action['subcommands'] as $fileaction) {
if (array_key_exists('execute', $fileaction) && $fileaction['execute'] == "pre") { if (array_key_exists('execute', $fileaction) && $fileaction['execute'] == "pre") {
$commands_pre .= $fileaction['content'] . "\n"; $commands_pre .= $fileaction['content'] . "\n";
} elseif (array_key_exists('execute', $fileaction) && $fileaction['execute'] == "post") { } elseif (array_key_exists('execute', $fileaction) && $fileaction['execute'] == "post") {
$commands_post .= $fileaction['content'] . "\n"; $commands_post .= $fileaction['content'] . "\n";
} elseif ($fileaction['type'] == 'file') { } elseif ($fileaction['type'] == 'file') {
$commands_file = getFileContentContainer($fileaction['content'], $replace_arr, $action['name'], $distro_editor); $commands_file = getFileContentContainer($fileaction['content'], $replace_arr, $action['name'], $distro_editor);
} }
} }
} }
$realname = $action['name']; $realname = $action['name'];
$commands = trim($commands_pre); $commands = trim($commands_pre);
if ($commands != "") { if ($commands != "") {
$numbrows = count(explode("\n", $commands)); $numbrows = count(explode("\n", $commands));
eval("\$commands_pre=\"" . getTemplate("configfiles/configfiles_commands") . "\";"); eval("\$commands_pre=\"" . getTemplate("configfiles/configfiles_commands") . "\";");
} }
$commands = trim($commands_post); $commands = trim($commands_post);
if ($commands != "") { if ($commands != "") {
$numbrows = count(explode("\n", $commands)); $numbrows = count(explode("\n", $commands));
eval("\$commands_post=\"" . getTemplate("configfiles/configfiles_commands") . "\";"); eval("\$commands_post=\"" . getTemplate("configfiles/configfiles_commands") . "\";");
} }
eval("\$configpage.=\"" . getTemplate("configfiles/configfiles_subfileblock") . "\";"); eval("\$configpage.=\"" . getTemplate("configfiles/configfiles_subfileblock") . "\";");
$commands = ''; $commands = '';
$commands_pre = ''; $commands_pre = '';
$commands_post = ''; $commands_post = '';
break; break;
} }
} }
$commands = trim($commands); $commands = trim($commands);
if ($commands != '') { if ($commands != '') {
$numbrows = count(explode("\n", $commands)); $numbrows = count(explode("\n", $commands));
eval("\$configpage.=\"" . getTemplate("configfiles/configfiles_commands") . "\";"); eval("\$configpage.=\"" . getTemplate("configfiles/configfiles_commands") . "\";");
} }
eval("echo \"" . getTemplate("configfiles/configfiles") . "\";"); eval("echo \"" . getTemplate("configfiles/configfiles") . "\";");
} else { } else {
eval("echo \"" . getTemplate("configfiles/wizard") . "\";"); eval("echo \"" . getTemplate("configfiles/wizard") . "\";");
} }
} else { } else {
die('not allowed to see this page'); die('not allowed to see this page');
// redirect or similar here // redirect or similar here
} }
// helper functions // helper functions
function getFileContentContainer($file_content, &$replace_arr, $realname, $distro_editor) function getFileContentContainer($file_content, &$replace_arr, $realname, $distro_editor)
{ {
$files = ""; $files = "";
$file_content = trim($file_content); $file_content = trim($file_content);
if ($file_content != '') { if ($file_content != '') {
$file_content = strtr($file_content, $replace_arr); $file_content = strtr($file_content, $replace_arr);
$file_content = htmlspecialchars($file_content); $file_content = htmlspecialchars($file_content);
$numbrows = count(explode("\n", $file_content)); $numbrows = count(explode("\n", $file_content));
eval("\$files=\"" . getTemplate("configfiles/configfiles_file") . "\";"); eval("\$files=\"" . getTemplate("configfiles/configfiles_file") . "\";");
} }
return $files; return $files;
} }
function getCompleteDistroName($cparser) function getCompleteDistroName($cparser)
{ {
// get distro-info // get distro-info
$dist_display = $cparser->distributionName; $dist_display = $cparser->distributionName;
if ($cparser->distributionCodename != '') { if ($cparser->distributionCodename != '') {
$dist_display .= " ".$cparser->distributionCodename; $dist_display .= " " . $cparser->distributionCodename;
} }
if ($cparser->distributionVersion != '') { if ($cparser->distributionVersion != '') {
$dist_display .= " (" . $cparser->distributionVersion . ")"; $dist_display .= " (" . $cparser->distributionVersion . ")";
} }
if ($cparser->deprecated) { if ($cparser->deprecated) {
$dist_display .= " [deprecated]"; $dist_display .= " [deprecated]";
} }
return $dist_display; return $dist_display;
} }