From 0506bf2b6469c9736bb24ac83d507ecc2bd810d7 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 18 Jan 2017 15:11:14 +0100 Subject: [PATCH] HostController: simplify code --- application/controllers/HostController.php | 35 ++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 0b84bc51..8ac5e93b 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -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');