HostController: simplify code

This commit is contained in:
Thomas Gelf 2017-01-18 15:11:14 +01:00
parent a1ed3f4be5
commit 0506bf2b64

View File

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