HostController: simplify code

This commit is contained in:
Thomas Gelf 2017-01-18 15:11:14 +01:00
parent a1ed3f4be5
commit 0506bf2b64
1 changed files with 20 additions and 15 deletions

View File

@ -335,23 +335,28 @@ class HostController extends ObjectController
public function agentAction()
{
switch ($this->params->get('download')) {
case 'windows-kickstart':
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=icinga2-agent-kickstart.ps1');
if ($os = $this->params->get('download')) {
$wizard = $this->view->wizard = new AgentWizard($this->object);
$wizard->setTicketSalt($this->api()->getTicketSalt());
echo preg_replace('/\n/', "\r\n", $wizard->renderWindowsInstaller());
exit;
case 'linux':
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=icinga2-agent-kickstart.bash');
$wizard = new AgentWizard($this->object);
$wizard->setTicketSalt($this->api()->getTicketSalt());
$wizard = $this->view->wizard = new AgentWizard($this->object);
$wizard->setTicketSalt($this->api()->getTicketSalt());
echo $wizard->renderLinuxInstaller();
exit;
switch ($os) {
case 'windows-kickstart':
$ext = 'ps1';
$script = preg_replace('/\n/', "\r\n", $wizard->renderWindowsInstaller());
break;
case 'linux':
$ext = 'bash';
$script = $wizard->renderLinuxInstaller();
break;
default:
throw new NotFoundError('There is no kickstart helper for %s', $os);
}
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=icinga2-agent-kickstart.' . $ext);
echo $script;
exit;
}
$this->gracefullyActivateTab('agent');