From 86495b0b14c82dfd509ec27b85782dbfc3653602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=C4=9Bzslav=20Dvo=C5=99=C3=A1k?= Date: Wed, 17 Aug 2016 14:59:55 +0200 Subject: [PATCH] Deploy script for Windows now use PowerShell Automatic icinga reload after successfull Configuration files generation Deploying new script C:\Program Files\NSClient++\refresh.ps1 Main page switched to English language --- debian/changelog | 5 +- debian/conf/composer.json | 2 +- debian/install | 2 +- debian/revison | 2 +- src/apply.php | 34 ++--- src/cfgconfirm.php | 15 +- src/classes/ExternalCommand.php | 11 +- src/classes/NSCPConfigPS1Generator.php | 163 +++++++++++++++------- src/classes/UI/ConfigurationsOverview.php | 43 +++--- src/downtime.php | 6 +- src/index.php | 5 +- src/login.php | 2 +- src/main.php | 7 +- src/nscpcfggen.php | 14 +- src/regenall.php | 46 +++--- 15 files changed, 222 insertions(+), 135 deletions(-) diff --git a/debian/changelog b/debian/changelog index 895303f..7788939 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -icinga-editor (1.1.2-24) UNRELEASED; urgency=medium +icinga-editor (1.1.2-25) UNRELEASED; urgency=medium [ dvorak ] * Initial release. (Closes: #XXXXXX) @@ -118,5 +118,6 @@ icinga-editor (1.1.2-24) UNRELEASED; urgency=medium * Fixed Scripts Edit/Upload Switching strings to English * Fixed Scripts Edit/Upload Switching strings to English * Fixed Scripts Edit/Upload Switching strings to English + * Support for ShutDown & Up scripts to start/stop icinga - -- vitex Fri, 12 Aug 2016 19:27:30 +0200 + -- vitex Tue, 16 Aug 2016 19:03:04 +0200 diff --git a/debian/conf/composer.json b/debian/conf/composer.json index 4340c7f..e62f8d9 100644 --- a/debian/conf/composer.json +++ b/debian/conf/composer.json @@ -1,7 +1,7 @@ { "name": "vitexsoftware/icinga-editor", "description": "Editor of Icinga Configuration files (debianized)", - "version": "1.1.2.24", + "version": "1.1.2.25", "license": "GPL-2.0", "authors": [ { diff --git a/debian/install b/debian/install index 6633813..d16bb46 100644 --- a/debian/install +++ b/debian/install @@ -22,4 +22,4 @@ bin/iecfgimporter.php usr/bin bin/toicmdfile.sh usr/bin locale/cs_CZ/LC_MESSAGES/*.mo usr/share/locale/cs_CZ/LC_MESSAGES -locale/en_US/LC_MESSAGES/*.mo usr/share/locale/cs_CZ/LC_MESSAGES +locale/en_US/LC_MESSAGES/*.mo usr/share/locale/en_US/LC_MESSAGES diff --git a/debian/revison b/debian/revison index a45fd52..7273c0f 100644 --- a/debian/revison +++ b/debian/revison @@ -1 +1 @@ -24 +25 diff --git a/src/apply.php b/src/apply.php index 4233b43..b9a71f8 100644 --- a/src/apply.php +++ b/src/apply.php @@ -3,12 +3,11 @@ namespace Icinga\Editor; /** - * Icinga Editor - generování konfigurace + * Icinga Editor - Configuration Generating * * @package IcingaEditor - * @subpackage WebUI * @author Vitex - * @copyright 2012 Vitex@hippy.cz (G) + * @copyright 2012-2016 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; @@ -56,9 +55,9 @@ if (($line === false) && ($line_num == 1)) { $errorLine = $oPage->container->addItem(new \Ease\Html\Div(''._('Chyba:').'', ['class' => 'alert alert-danger'])); - $oUser->addStatusMessage(_('Kontrola konfigurace nevrátila výsledek.'), + $oUser->addStatusMessage(_('Configuration control empty result'), 'error'); - $errorLine->addItem(_('Zkontroluj prosím zdlali nechybí potřebný fragment v /etc/sudoers:')); + $errorLine->addItem(_('Please check if /etc/sudoers contains:')); $errorLine->addItem(new \Ease\Html\Div('User_Alias APACHE = www-data')); $errorLine->addItem(new \Ease\Html\Div('Cmnd_Alias ICINGA = /usr/sbin/icinga, /etc/init.d/icinga')); $errorLine->addItem(new \Ease\Html\Div('APACHE ALL = (ALL) NOPASSWD: ICINGA')); @@ -67,18 +66,18 @@ if (strstr($line, 'Error:')) { $line = str_replace('Error:', '', $line); - $errorLine = $oPage->container->addItem(new \Ease\Html\Div(''._('Chyba:').'', + $errorLine = $oPage->container->addItem(new \Ease\Html\Div(''._('Error:').'', ['class' => 'alert alert-danger'])); $keywords = preg_split("/['(.*)']+/", $line); switch (trim($keywords[0])) { case 'Service notification period': - $errorLine->addItem(' '._('Notifikační perioda').' služeb '); + $errorLine->addItem(' '._('Notification period').' of services '); $errorLine->addItem(new \Ease\Html\ATag('timeperiod.php?timeperiod_name='.$keywords[1], $keywords[1])); break; case 'Host notification period': - $errorLine->addItem(' '._('Notifikační perioda').' hostů'); + $errorLine->addItem(' '._('Notification period').' of hosts'); $errorLine->addItem(new \Ease\Html\ATag('timeperiod.php?timeperiod_name='.$keywords[1], $keywords[1])); break; @@ -91,7 +90,7 @@ if (isset($keywords[2])) { switch (trim($keywords[2])) { case 'specified for contact': - $errorLine->addItem(' specifikovaná pro kontakt '); + $errorLine->addItem(' specified for contact '); $contact = new Engine\Contact($keywords[3]); $errorLine->addItem(new \Ease\Html\ATag('contact.php?contact_id='.$contact->getMyKey(), $keywords[3])); @@ -104,11 +103,10 @@ if (isset($keywords[4])) { switch (trim($keywords[4])) { case 'is not defined anywhere!': - $errorLine->addItem(' není nikde definován/a '); + $errorLine->addItem(''._('is not defined anywhere')); break; } } - //$OPage->addItem('
' . EaseBrick::printPreBasic($keywords) . '
'); } if (strstr($line, 'Error in configuration file')) { @@ -145,20 +143,21 @@ if (strstr($line, 'Total Warnings')) { list($msg, $WarningCount) = explode(':', $line); if (intval(trim($WarningCount))) { - $oUser->addStatusMessage(sprintf(_('celkem %s varování'), + $oUser->addStatusMessage(sprintf(_('total %s warnings'), $WarningCount), 'warning'); } else { - $oUser->addStatusMessage(_('test proběhl bez varování'), + $oUser->addStatusMessage(_('test successfully done without warnings'), 'success'); } } if (strstr($line, 'Total Errors')) { list($msg, $errorCount) = explode(':', $line); if (intval(trim($errorCount))) { - $oUser->addStatusMessage(sprintf(_('celkem %s chyb'), + $oUser->addStatusMessage(sprintf(_('total %s errors'), $errorCount), 'warning'); } else { - $oUser->addStatusMessage(_('test proběhl bez chyb'), 'success'); + $oUser->addStatusMessage(_('test successfully done without errors'), + 'success'); } } } @@ -166,9 +165,10 @@ if (!intval($errorCount) && !is_null($WarningCount)) { if (Engine\Configurator::reloadIcinga()) { - $oPage->container->addItem(_('Všechny vaše konfigurační soubory byly přegenerovány')); + $oPage->container->addItem(_('All your configuration files was regenerated')); + $oPage->container->addItem(new \Ease\TWB\LinkButton('main.php', - _('Hotovo').' '.\Ease\TWB\Part::GlyphIcon('ok-sign'), 'success')); + _('Done').' '.\Ease\TWB\Part::GlyphIcon('ok-sign'), 'success')); \Ease\Shared::user()->setSettingValue('unsaved', false); } } diff --git a/src/cfgconfirm.php b/src/cfgconfirm.php index 167b87b..1ab6b1b 100644 --- a/src/cfgconfirm.php +++ b/src/cfgconfirm.php @@ -6,9 +6,8 @@ * Icinga Editor - potvrzení nasazení konfigurace * * @package IcingaEditor - * @subpackage WebUI * @author Vitex - * @copyright 2012 Vitex@hippy.cz (G) + * @copyright 2012-2016 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; @@ -16,14 +15,18 @@ $hash = $oPage->getRequestValue('hash'); if ($host_id && $hash) { - $host = new Engine\Host($host_id); + $host = new Engine\Host($host_id); + $oUser = new \Icinga\Editor\User($host->getOwnerID()); $host->setDataValue('config_hash', $hash); if ($host->saveToSQL()) { - echo sprintf(_('Konfigurace %s potvrzena'), $host->getName()); + echo sprintf(_('Configuration Confirmed'), $host->getName()); + $extCmd = new ExternalCommand(); + $extCmd->addCommand('ADD_HOST_COMMENT;'.$host->getName().';1;'.$oUser->getUserLogin().';'._('Sensor Configuration Confirmed')); + $extCmd->executeAll(); } else { - echo sprintf(_('Chyba potvrzení konfigurace'), $host->getName()); + echo sprintf(_('Configuration Confirmation Error'), $host->getName()); } - echo "\n
"._('Sledovat cestu k hostu').":\n"; + echo "\n
"._('Watch route to host').":\n"; if (isset($_SERVER['REQUEST_SCHEME'])) { $scheme = $_SERVER['REQUEST_SCHEME']; diff --git a/src/classes/ExternalCommand.php b/src/classes/ExternalCommand.php index e6575d8..8391ad7 100644 --- a/src/classes/ExternalCommand.php +++ b/src/classes/ExternalCommand.php @@ -36,11 +36,15 @@ public function addCommand($command) */ public function executeAll() { + $results = []; foreach ($this->commands as $id => $command) { - if ($this->execute($command) !== false) { + $result = $this->execute($command); + if ($result !== false) { unset($this->commands[$id]); + $results[$command] = $result; } } + return $results; } /** @@ -52,7 +56,10 @@ public function executeAll() public function execute($command) { $this->addStatusMessage('External command: '.$command); - return system('sudo /usr/bin/toicmdfile.sh "['.time().'] '.$command.'"'); + ob_start(); + $result = system('sudo /usr/bin/toicmdfile.sh "['.time().'] '.$command.'"'); + ob_end_clean(); + return $result; } /** diff --git a/src/classes/NSCPConfigPS1Generator.php b/src/classes/NSCPConfigPS1Generator.php index d5d425a..276dae7 100644 --- a/src/classes/NSCPConfigPS1Generator.php +++ b/src/classes/NSCPConfigPS1Generator.php @@ -96,38 +96,45 @@ public function cfgEnding() } switch ($this->platform) { case 'windows': - $this->nscConfArray[] = "\n".'echo "

'._('Konfigurace hosta').' '.$this->host->getName().'

" | Out-File $ICIEDIT_HTML -Append'; + $this->nscConfArray[] = "\n".'echo "

'._('Host Configuration').' '.$this->host->getName().'

" | Out-File $ICIEDIT_HTML -Append'; $this->nscConfArray[] = "\n".'echo "
'._('Host Configuration').'" | Out-File $ICIEDIT_HTML -Append'; - $this->nscConfArray[] = "\n".'echo "
'._('Refresh sensor installation').' '.$this->host->getName().'_nscp.ps1'.'" | Out-File $ICIEDIT_HTML -Append'; + $this->nscConfArray[] = "\n".'echo "
'._('Refresh sensor installation').' '.$this->host->getName().'_nscp.ps1'.'" | Out-File $ICIEDIT_HTML -Append'; if ($this->host->getDataValue('host_is_server') == 0) { $dtUrl = Engine\Configurator::getBaseURL().'downtime.php?host_id='.$this->host->getId(); - $this->nscConfArray[] = "\n"."echo '
"._('Start host downtime')."' | Out-File \$ICIEDIT_HTML -Append"; - $this->nscConfArray[] = "\n"."echo '
"._('End host downtime')."' | Out-File \$ICIEDIT_HTML -Append"; + $this->nscConfArray[] = "\n"."echo '
"._('Start host downtime')."' | Out-File \$ICIEDIT_HTML -Append"; + $this->nscConfArray[] = "\n"."echo '
"._('End host downtime')."' | Out-File \$ICIEDIT_HTML -Append"; } - $this->nscConfArray[] = "\n"."echo '
getCfgConfirmUrl()."\">"._('Potvrzení konfigurace')."' | Out-File \$ICIEDIT_HTML -Append"; + $this->nscConfArray[] = "\n"."echo '
getCfgConfirmUrl()."\">"._('Confirm Configuration')."' | Out-File \$ICIEDIT_HTML -Append"; $this->nscConfArray[] = "\n".'echo "" | Out-File $ICIEDIT_HTML -Append'; $this->nscConfArray[] = "\n".'echo "" | Out-File $ICIEDIT_HTML -Append '; if ($this->host->getDataValue('host_is_server') == 0) { $this->nscConfArray[] = "\n".$this->registryUpdaterCode(); + + $gpspath = 'C:\\Windows\\System32\\GroupPolicy\\Machine\\Scripts\\'; - $upfile = 'C:\\Windows\\System32\\GroupPolicy\\Machine\\Scripts\\Startup\\hostup.ps1'; - $this->nscConfArray[] = "\n"."echo '(New-Object System.Net.WebClient).DownloadFile(\"$dtUrl\"&\"state=stop\",\"C:\\WINDOWS\\TEMP\\UP.TXT\")' | Out-File $upfile"; + $this->nscConfArray[] = "\n"."if(!(Test-Path -Path $gpspath )){ New-Item -ItemType directory -Path $gpspath }"; + $this->nscConfArray[] = "\n"."if(!(Test-Path -Path ".$gpspath."Startup )){ New-Item -ItemType directory -Path ".$gpspath."Startup }"; + $this->nscConfArray[] = "\n"."if(!(Test-Path -Path ".$gpspath."Shutdown )){ New-Item -ItemType directory -Path ".$gpspath."Shutdown }"; - $downfile = 'C:\\Windows\\System32\\GroupPolicy\\Machine\\Scripts\\Shutdown\\hostdown.ps1'; - $this->nscConfArray[] = "\n"."echo '(New-Object System.Net.WebClient).DownloadFile(\"$dtUrl\"&\"state=start\",\"C:\\WINDOWS\\TEMP\\DOWN.TXT\")' | Out-File $downfile"; + $upfile = $gpspath.'Startup\\hostup.ps1'; + $this->nscConfArray[] = "\n"."echo '(New-Object System.Net.WebClient).DownloadFile(\"$dtUrl&state=stop\",\"C:\\WINDOWS\\TEMP\\UP.TXT\")' | Out-File $upfile"; + + $downfile = $gpspath.'Shutdown\\hostdown.ps1'; + $this->nscConfArray[] = "\n"."echo '(New-Object System.Net.WebClient).DownloadFile(\"$dtUrl&state=start\",\"C:\\WINDOWS\\TEMP\\DOWN.TXT\")' | Out-File $downfile"; } + + $this->nscConfArray[] = "\n".' '.$this->nscvar.' service --start (New-Object System.Net.WebClient).DownloadFile("'.parent::getCfgConfirmUrl().'", $NSCDIR + "\\CONFIRM.HTM") '; $this->nscConfArray[] = "\n". - "echo '(New-Object System.Net.WebClient).DownloadFile(\"".Engine\Configurator::getBaseURL().'nscpcfggen.php?host_id='.$this->host->getId().'&format=ps1&user='.\Ease\Shared::user()->getUserLogin().'","'.$this->host->getName().'_nscp.ps1")\' | Out-File $NSCDIR + \"\\refresh.ps1"'; + "echo '(New-Object System.Net.WebClient).DownloadFile(\"".Engine\Configurator::getBaseURL().'nscpcfggen.php?host_id='.$this->host->getId().'&format=ps1&user='.\Ease\Shared::user()->getUserLogin().'", ${Env:ProgramFiles} + "\\NSCLient++\\'.$this->host->getName().'_nscp.ps1")\' | Out-File $NSCDIR"\\refresh.ps1"'; $this->nscConfArray[] = "\n". - "echo '& ".$this->host->getName().'_nscp.ps1 | Out-File $NSCDIR + \"\\refresh.ps1" -Append'; - + "echo '& \${Env:ProgramFiles}\"\\NSCLient++\\".$this->host->getName().'_nscp.ps1"\' | Out-File $NSCDIR"\\refresh.ps1" -Append'; break; case 'linux': $this->nscConfArray[] = "\n".' @@ -150,7 +157,7 @@ public function deployScripts() if (count($this->scriptsToDeploy)) { switch ($this->platform) { case 'windows': - $this->nscConfArray[] = "\n".'echo "

'._('Skripty').'

" | Out-File $ICIEDIT_HTML -Append + $this->nscConfArray[] = "\n".'echo "

'._('Scripts').'

" | Out-File $ICIEDIT_HTML -Append '; break; } @@ -190,34 +197,56 @@ function getCfgConfirmUrl() public static function registryUpdaterCode() { - return '$reg = "0" + return ' +# UPDATE REGISTRY + +$reg = "0" $PathGP = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\" $ScriptPathShutdown = "$PathGP"+"Scripts\Shutdown\0\" $PathScriptShutdown = "$ScriptPathShutdown"+"$reg" +$StatePathShutdown = "$PathGP"+"State\Machine\Scripts\Shutdown\0\" +$PathStateShutdown = "$StatePathShutdown"+"$reg" $ScriptPathStartup = "$PathGP"+"Scripts\Startup\0\" $PathScriptStartup = "$ScriptPathStartup"+"$reg" +$StatePathStartup = "$PathGP"+"State\Machine\Scripts\Startup\0\" +$PathStateStartup = "$StatePathStartup"+"$reg" $ScriptShutdown = "hostdown.ps1" $ScriptStartup = "hostup.ps1" -IF { + +IF(Test-Path $PathScriptShutdown) { $PatternShutdown = Get-ItemPropertyValue -Path "$PathScriptShutdown" -Name "Script" -IF { -New-Item -Path $ScriptPathShutdown -Name $reg -Force -New-ItemProperty -Path "$PathScriptShutdown" -Name "Script" -Value $ScriptShutdown -Force -New-ItemProperty -Path "$PathScriptShutdown" -Name "Parameters" -Value "" -Force -New-ItemProperty -Path "$PathScriptShutdown" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD -New-ItemProperty -Path "$PathScriptShutdown" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD + IF($PatternShutdown -ne "hostdown.ps1") { + New-Item -Path $ScriptPathShutdown -Name $reg -Force + New-ItemProperty -Path "$PathScriptShutdown" -Name "Script" -Value $ScriptShutdown -Force + New-ItemProperty -Path "$PathScriptShutdown" -Name "Parameters" -Value "" -Force + New-ItemProperty -Path "$PathScriptShutdown" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD + New-ItemProperty -Path "$PathScriptShutdown" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD -New-ItemProperty -Path $ScriptPathShutdown -Name "DisplayName" -Value "Místní zásady skupiny" -New-ItemProperty -Path $ScriptPathShutdown -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" -New-ItemProperty -Path $ScriptPathShutdown -Name "GPO-ID" -Value "LocalGPO" -New-ItemProperty -Path $ScriptPathShutdown -Name "GPOName" -Value "Místní zásady skupiny" -New-ItemProperty -Path $ScriptPathShutdown -Name "PSScriptOrder" -Value "1" -PropertyType DWORD -New-ItemProperty -Path $ScriptPathShutdown -Name "SOM-ID" -Value "Local" -} + New-ItemProperty -Path $ScriptPathShutdown -Name "DisplayName" -Value "Local Group Policy" + New-ItemProperty -Path $ScriptPathShutdown -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" + New-ItemProperty -Path $ScriptPathShutdown -Name "GPO-ID" -Value "LocalGPO" + New-ItemProperty -Path $ScriptPathShutdown -Name "GPOName" -Value "Local Group Policy" + New-ItemProperty -Path $ScriptPathShutdown -Name "PSScriptOrder" -Value "1" -PropertyType DWORD + New-ItemProperty -Path $ScriptPathShutdown -Name "SOM-ID" -Value "Local" + + + New-Item -Path $StatePathShutdown -Name $reg -Force + New-ItemProperty -Path "$PathStateShutdown" -Name "Script" -Value $ScriptShutdown -Force + New-ItemProperty -Path "$PathStateShutdown" -Name "Parameters" -Value "" -Force + New-ItemProperty -Path "$PathStateShutdown" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD + New-ItemProperty -Path "$PathStateShutdown" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD + + New-ItemProperty -Path $StatePathShutdown -Name "DisplayName" -Value "Local Group Policy" + New-ItemProperty -Path $StatePathShutdown -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" + New-ItemProperty -Path $StatePathShutdown -Name "GPO-ID" -Value "LocalGPO" + New-ItemProperty -Path $StatePathShutdown -Name "GPOName" -Value "Local Group Policy" + New-ItemProperty -Path $StatePathShutdown -Name "PSScriptOrder" -Value "1" -PropertyType DWORD + New-ItemProperty -Path $StatePathShutdown -Name "SOM-ID" -Value "Local" + } } ELSE { New-Item -Path $ScriptPathShutdown -Name $reg -Force @@ -226,30 +255,57 @@ public static function registryUpdaterCode() New-ItemProperty -Path "$PathScriptShutdown" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD New-ItemProperty -Path "$PathScriptShutdown" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD -New-ItemProperty -Path $ScriptPathShutdown -Name "DisplayName" -Value "Místní zásady skupiny" +New-ItemProperty -Path $ScriptPathShutdown -Name "DisplayName" -Value "Local Group Policy" New-ItemProperty -Path $ScriptPathShutdown -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" New-ItemProperty -Path $ScriptPathShutdown -Name "GPO-ID" -Value "LocalGPO" -New-ItemProperty -Path $ScriptPathShutdown -Name "GPOName" -Value "Místní zásady skupiny" +New-ItemProperty -Path $ScriptPathShutdown -Name "GPOName" -Value "Local Group Policy" New-ItemProperty -Path $ScriptPathShutdown -Name "PSScriptOrder" -Value "1" -PropertyType DWORD New-ItemProperty -Path $ScriptPathShutdown -Name "SOM-ID" -Value "Local" + +New-Item -Path $StatePathShutdown -Name $reg -Force +New-ItemProperty -Path "$PathStateShutdown" -Name "Script" -Value $ScriptShutdown -Force +New-ItemProperty -Path "$PathStateShutdown" -Name "Parameters" -Value "" -Force +New-ItemProperty -Path "$PathStateShutdown" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD +New-ItemProperty -Path "$PathStateShutdown" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD + +New-ItemProperty -Path $StatePathShutdown -Name "DisplayName" -Value "Local Group Policy" +New-ItemProperty -Path $StatePathShutdown -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" +New-ItemProperty -Path $StatePathShutdown -Name "GPO-ID" -Value "LocalGPO" +New-ItemProperty -Path $StatePathShutdown -Name "GPOName" -Value "Local Group Policy" +New-ItemProperty -Path $StatePathShutdown -Name "PSScriptOrder" -Value "1" -PropertyType DWORD +New-ItemProperty -Path $StatePathShutdown -Name "SOM-ID" -Value "Local" } -IF { +IF(Test-Path $PathScriptStartup) { $PatternStartup = Get-ItemPropertyValue -Path "$PathScriptStartup" -Name "Script" -IF { -New-Item -Path $ScriptPathStartup -Name $reg -Force -New-ItemProperty -Path "$PathScriptStartup" -Name "Script" -Value $ScriptStartup -Force -New-ItemProperty -Path "$PathScriptStartup" -Name "Parameters" -Value "" -Force -New-ItemProperty -Path "$PathScriptStartup" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD -New-ItemProperty -Path "$PathScriptStartup" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD + IF($PatternStartup -ne "hostup.ps1") { + New-Item -Path $ScriptPathStartup -Name $reg -Force + New-ItemProperty -Path "$PathScriptStartup" -Name "Script" -Value $ScriptStartup -Force + New-ItemProperty -Path "$PathScriptStartup" -Name "Parameters" -Value "" -Force + New-ItemProperty -Path "$PathScriptStartup" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD + New-ItemProperty -Path "$PathScriptStartup" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD -New-ItemProperty -Path $ScriptPathStartup -Name "DisplayName" -Value "Místní zásady skupiny" -New-ItemProperty -Path $ScriptPathStartup -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" -New-ItemProperty -Path $ScriptPathStartup -Name "GPO-ID" -Value "LocalGPO" -New-ItemProperty -Path $ScriptPathStartup -Name "GPOName" -Value "Místní zásady skupiny" -New-ItemProperty -Path $ScriptPathStartup -Name "PSScriptOrder" -Value "1" -PropertyType DWORD -New-ItemProperty -Path $ScriptPathStartup -Name "SOM-ID" -Value "Local" -} + New-ItemProperty -Path $ScriptPathStartup -Name "DisplayName" -Value "Local Group Policy" + New-ItemProperty -Path $ScriptPathStartup -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" + New-ItemProperty -Path $ScriptPathStartup -Name "GPO-ID" -Value "LocalGPO" + New-ItemProperty -Path $ScriptPathStartup -Name "GPOName" -Value "Local Group Policy" + New-ItemProperty -Path $ScriptPathStartup -Name "PSScriptOrder" -Value "1" -PropertyType DWORD + New-ItemProperty -Path $ScriptPathStartup -Name "SOM-ID" -Value "Local" + + + New-Item -Path $StatePathStartup -Name $reg -Force + New-ItemProperty -Path "$PathStateStartup" -Name "Script" -Value $ScriptStartup -Force + New-ItemProperty -Path "$PathStateStartup" -Name "Parameters" -Value "" -Force + New-ItemProperty -Path "$PathStateStartup" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD + New-ItemProperty -Path "$PathStateStartup" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD + + New-ItemProperty -Path $StatePathStartup -Name "DisplayName" -Value "Local Group Policy" + New-ItemProperty -Path $StatePathStartup -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" + New-ItemProperty -Path $StatePathStartup -Name "GPO-ID" -Value "LocalGPO" + New-ItemProperty -Path $StatePathStartup -Name "GPOName" -Value "Local Group Policy" + New-ItemProperty -Path $StatePathStartup -Name "PSScriptOrder" -Value "1" -PropertyType DWORD + New-ItemProperty -Path $StatePathStartup -Name "SOM-ID" -Value "Local" + } } ELSE { New-Item -Path $ScriptPathStartup -Name $reg -Force @@ -258,14 +314,27 @@ public static function registryUpdaterCode() New-ItemProperty -Path "$PathScriptStartup" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD New-ItemProperty -Path "$PathScriptStartup" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD -New-ItemProperty -Path $ScriptPathStartup -Name "DisplayName" -Value "Místní zásady skupiny" +New-ItemProperty -Path $ScriptPathStartup -Name "DisplayName" -Value "Local Group Policy" New-ItemProperty -Path $ScriptPathStartup -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" New-ItemProperty -Path $ScriptPathStartup -Name "GPO-ID" -Value "LocalGPO" -New-ItemProperty -Path $ScriptPathStartup -Name "GPOName" -Value "Místní zásady skupiny" +New-ItemProperty -Path $ScriptPathStartup -Name "GPOName" -Value "Local Group Policy" New-ItemProperty -Path $ScriptPathStartup -Name "PSScriptOrder" -Value "1" -PropertyType DWORD New-ItemProperty -Path $ScriptPathStartup -Name "SOM-ID" -Value "Local" + +New-Item -Path $StatePathStartup -Name $reg -Force +New-ItemProperty -Path "$PathStateStartup" -Name "Script" -Value $ScriptStartup -Force +New-ItemProperty -Path "$PathStateStartup" -Name "Parameters" -Value "" -Force +New-ItemProperty -Path "$PathStateStartup" -Name "IsPowershell" -Value "1" -Force -PropertyType DWORD +New-ItemProperty -Path "$PathStateStartup" -Name "ExecTime" -Value "0" -Force -PropertyType QWORD + +New-ItemProperty -Path $StatePathStartup -Name "DisplayName" -Value "Local Group Policy" +New-ItemProperty -Path $StatePathStartup -Name "FileSysPath" -Value "C:\WINDOWS\System32\GroupPolicy\Machine" +New-ItemProperty -Path $StatePathStartup -Name "GPO-ID" -Value "LocalGPO" +New-ItemProperty -Path $StatePathStartup -Name "GPOName" -Value "Local Group Policy" +New-ItemProperty -Path $StatePathStartup -Name "PSScriptOrder" -Value "1" -PropertyType DWORD +New-ItemProperty -Path $StatePathStartup -Name "SOM-ID" -Value "Local" } - '; +'; } } diff --git a/src/classes/UI/ConfigurationsOverview.php b/src/classes/UI/ConfigurationsOverview.php index 064e0d6..94a0cee 100644 --- a/src/classes/UI/ConfigurationsOverview.php +++ b/src/classes/UI/ConfigurationsOverview.php @@ -3,18 +3,17 @@ namespace Icinga\Editor\UI; /** - * Přehled hostů bez potvrzeného senzoru, nebo se zastaralou konf. senzoru. + * Hosts without confirmerd configuration or sensor deployed overview * * @package IcingaEditor - * @subpackage WebUI * @author Vitex - * @copyright 2012 Vitex@hippy.cz (G) + * @copyright 2012-2016 Vitex@hippy.cz (G) */ class ConfigurationsOverview extends \Ease\TWB\Panel { /** - * Přehled hostů bez potvrzeného senzoru, nebo se zastaralou konf. senzoru. + * Hosts without confirmerd configuration or sensor deployed overview * * @param array $hosts */ @@ -43,28 +42,28 @@ public function __construct($hosts) unset($hosts[$host_id]); $ok++; } else { - //Zastaralá konfigurace + //Obsoleted configuration $oldSensor[$host_id] = $host_info; } } else { $noSensor[$host_id] = $host_info; - //senzor neregistrován + //sensor undeployed yet } if (!isset($host_info['parents']) || !count($host_info['parents'])) { $noParents[$host_id] = $host_info; - //Host bez rodičů + //Host without parents } if (!isset($host_info['icon_image']) || !strlen(trim($host_info['icon_image']))) { $noIcon[$host_id] = $host_info; - //Host bez ikony + //Host without icon } if ((!isset($host_info['contacts']) || !count($host_info['contacts'])) || (!isset($host_info['contact_groups']) || !count($host_info['contact_groups']))) { $noContacts[$host_id] = $host_info; - //Host bez kontaktů + //Host without contact } } @@ -74,10 +73,10 @@ public function __construct($hosts) foreach ($oldSensor as $host_id => $host_info) { $row = $oldHostsTable->addRowColumns([new \Ease\Html\ATag('host.php?host_id='.$host_id, $host_info['host_name']), new \Ease\TWB\LinkButton('sensor.php?host_id='.$host_id, - _('aktualizovat senzor'))]); + _('Actualise Sensor'))]); $row->setTagClass('warning'); } - $hostsTabs->addTab(sprintf(_('Neakt. Senzor %s'), + $hostsTabs->addTab(sprintf(_('Outdated Sensor %s'), count($oldSensor)), $oldHostsTable); } @@ -86,10 +85,10 @@ public function __construct($hosts) foreach ($noSensor as $host_id => $host_info) { $row = $noSensorTable->addRowColumns([new \Ease\Html\ATag('host.php?host_id='.$host_id, $host_info['host_name']), new \Ease\TWB\LinkButton('sensor.php?host_id='.$host_id, - _('nasadit senzor'))]); + _('Sensor Deploy'))]); $row->setTagClass('danger'); } - $hostsTabs->addTab(sprintf(_('Bez senzoru %s'), + $hostsTabs->addTab(sprintf(_('Without sensor %s'), count($noSensor)), $noSensorTable); } @@ -101,9 +100,9 @@ public function __construct($hosts) new \Ease\Html\ATag('host.php?host_id='.$host_id, $host_info['host_name']), new \Ease\TWB\LinkButton('host.php?action=parent&host_id='.$host_id, - _('přiřadit rodiče')), + _('Assign parents')), new \Ease\TWB\LinkButton('watchroute.php?action=parent&host_id='.$host_id, - _('sledovat celou cestu'), 'warning', + _('Watch hosts on route'), 'warning', ['onClick' => "$('#preload').css('visibility', 'visible');"]) ] ); @@ -111,7 +110,7 @@ public function __construct($hosts) $row->setTagClass('info'); } - $hostsTabs->addTab(sprintf(_('Bez rodičů %s'), + $hostsTabs->addTab(sprintf(_('Without parents %s'), count($noParents)), $noParentsTable); } @@ -120,10 +119,10 @@ public function __construct($hosts) foreach ($noIcon as $host_id => $host_info) { $row = $noIconTable->addRowColumns([new \Ease\Html\ATag('host.php?host_id='.$host_id, $host_info['host_name']), new \Ease\TWB\LinkButton('host.php?action=icon&host_id='.$host_id, - _('přiřadit ikonu'))]); + _('Assign icon'))]); $row->setTagClass('default'); } - $hostsTabs->addTab(sprintf(_('Bez ikony %s'), + $hostsTabs->addTab(sprintf(_('Without icon %s'), count($noIcon)), $noIconTable); } @@ -133,16 +132,16 @@ public function __construct($hosts) foreach ($noContacts as $host_id => $host_info) { $row = $noContactsTable->addRowColumns([new \Ease\Html\ATag('host.php?host_id='.$host_id, $host_info['host_name']), new \Ease\TWB\LinkButton('host.php?host_id='.$host_id, - _('přiřadit kontakty'))]); + _('Assign Contact'))]); $row->setTagClass('default'); } - $hostsTabs->addTab(sprintf(_('Bez kontaktů %s'), + $hostsTabs->addTab(sprintf(_('Without contacts %s'), count($noContacts)), $noContactsTable); } - parent::__construct(_('Hosty dle stavu konfigurace'), 'info', + parent::__construct(_('Hosts by configuration state'), 'info', $hostsTabs, - sprintf(_('Celkem %s hostů bez aktuální konfigurace. (%s aktuální)'), + sprintf(_('Overall %s hosts without actual configuration. (%s actual)'), count($hosts), $ok)); } diff --git a/src/downtime.php b/src/downtime.php index a894854..c74f465 100644 --- a/src/downtime.php +++ b/src/downtime.php @@ -28,16 +28,18 @@ $oneYear = 31556926; //In seconds $extCmd->addCommand('SCHEDULE_HOST_DOWNTIME;'.$host->getName().';'.$now.';'.($now + $oneYear).';0;0;'.$oneYear.';'.$owner->getUserLogin().';remote downtime invoke'); - $extCmd->addCommand(' PROCESS_HOST_CHECK_RESULT;'.$host->getName().';1;Host go Down'); + $extCmd->addCommand('DISABLE_HOST_NOTIFICATIONS;'.$host->getName()); + $extCmd->addCommand('PROCESS_HOST_CHECK_RESULT;'.$host->getName().';1;Host go Down'); break; case 'stop': $extCmd->addCommand('PROCESS_HOST_CHECK_RESULT;'.$host->getName().';0;Host go Up'); $extCmd->addCommand('DEL_DOWNTIME_BY_HOST_NAME;'.$host->getName()); + $extCmd->addCommand('ENABLE_HOST_NOTIFICATIONS;'.$host->getName()); break; default : $oPage->addStatusMessage(sprintf(_('Unknown state %s.'), $state)); die(_('State can be only start or stop')); break; } - $extCmd->executeAll(); + echo implode("\n", $extCmd->executeAll()); } \ No newline at end of file diff --git a/src/index.php b/src/index.php index e7fecc7..da26de6 100644 --- a/src/index.php +++ b/src/index.php @@ -3,12 +3,11 @@ namespace Icinga\Editor; /** - * Icinga Editor - hlavní strana + * Icinga Editor - index page * * @package IcingaEditor - * @subpackage WebUI * @author Vitex - * @copyright 2012 Vitex@hippy.cz (G) + * @copyright 2012-2016 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; diff --git a/src/login.php b/src/login.php index 5e511d5..0d782dd 100644 --- a/src/login.php +++ b/src/login.php @@ -3,7 +3,7 @@ namespace Icinga\Editor; /** - * Přihlašovací stránka + * Sign in page * * @author Vitex * @copyright Vitex@hippy.cz (G) 2009,2011 diff --git a/src/main.php b/src/main.php index 82ccc3d..f95b030 100644 --- a/src/main.php +++ b/src/main.php @@ -3,12 +3,11 @@ namespace Icinga\Editor; /** - * Icinga Editor - titulní strana + * Icinga Editor - main page * * @package IcingaEditor - * @subpackage WebUI * @author Vitex - * @copyright 2012 Vitex@hippy.cz (G) + * @copyright 2012-2016 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; @@ -25,7 +24,7 @@ $oPage->container->addItem(new UI\ConfigurationsOverview($hosts)); } else { $oPage->container->addItem(new \Ease\TWB\LinkButton('wizard-host.php', - _('Založte si první sledovaný host'), 'success')); + _('Create first watched host'), 'success')); $oUser->addStatusMessage(_('It is not yet registered any monitored host'), 'warning'); } diff --git a/src/nscpcfggen.php b/src/nscpcfggen.php index 20f955b..c956439 100644 --- a/src/nscpcfggen.php +++ b/src/nscpcfggen.php @@ -3,20 +3,24 @@ namespace Icinga\Editor; /** - * Icinga Editor - titulní strana + * Icinga Editor - Obtain configuration script for NSClient ++ deploy * * @package IcingaEditor - * @subpackage WebUI * @author Vitex - * @copyright 2012 Vitex@hippy.cz (G) + * @copyright 2012-2016 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; -$oPage->onlyForLogged(); - $hostId = $oPage->getRequestValue('host_id', 'int'); $host = new Engine\Host($hostId); +$forceUsername = $oPage->getRequestValue('user'); +if (!is_null($forceUsername)) { + \Ease\Shared::user(new \Icinga\Editor\User($forceUsername)); +} else { + \Ease\Shared::user(new \Icinga\Editor\User($host->getOwnerID())); +} + if ($oPage->getRequestValue('format') == 'ps1') { $generator = new NSCPConfigPS1Generator($host); } else { diff --git a/src/regenall.php b/src/regenall.php index 9bd6871..9a3e8f7 100644 --- a/src/regenall.php +++ b/src/regenall.php @@ -3,18 +3,17 @@ namespace Icinga\Editor; /** - * Icinga Editor - generování konfigurace + * Icinga Editor - Configuration Generating * * @package IcingaEditor - * @subpackage WebUI * @author Vitex - * @copyright 2012 Vitex@hippy.cz (G) + * @copyright 2012-2016 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; $oPage->onlyForAdmin(); -$oPage->container->addItem(new UI\PageTop(_('Přegenerování veškeré konfigurace'))); +$oPage->container->addItem(new UI\PageTop(_('Regenerate all configuration files'))); system('rm '.constant('CFG_GENERATED').'/*'); @@ -34,10 +33,10 @@ $cfg = fopen(constant('CFG_GENERATED').'/'.$fileName, 'w'); if ($cfg) { fclose($cfg); - $oUser->addStatusMessage(sprintf(_('konfigurační soubor %s byl znovu vytvořen'), + $oUser->addStatusMessage(sprintf(_('Configuration file %s was created'), $fileName), 'success'); } else { - $oUser->addStatusMessage(sprintf(_('konfigurační soubor %s nebyl znovu vytvořen'), + $oUser->addStatusMessage(sprintf(_('Configuration file %s was not created'), $fileName), 'warning'); } @@ -63,9 +62,9 @@ if (($line === false) && ($line_num == 1)) { $errorLine = $oPage->container->addItem(new \Ease\Html\Div(''._('Chyba:').'', ['class' => 'alert alert-danger'])); - $oUser->addStatusMessage(_('Kontrola konfigurace nevrátila výsledek.'), + $oUser->addStatusMessage(_('Configuration control empty result'), 'error'); - $errorLine->addItem(_('Zkontroluj prosím zdali nechybí potřebný fragment v /etc/sudoers:')); + $errorLine->addItem(_('Please check if /etc/sudoers contains:')); $errorLine->addItem(new \Ease\Html\Div('User_Alias APACHE = www-data')); $errorLine->addItem(new \Ease\Html\Div('Cmnd_Alias ICINGA = /usr/sbin/icinga, /etc/init.d/icinga')); $errorLine->addItem(new \Ease\Html\Div('APACHE ALL = (ALL) NOPASSWD: ICINGA')); @@ -74,18 +73,18 @@ if (strstr($line, 'Error:')) { $line = str_replace('Error:', '', $line); - $errorLine = $oPage->container->addItem(new \Ease\Html\Div(''._('Chyba:').'', + $errorLine = $oPage->container->addItem(new \Ease\Html\Div(''._('Error:').'', ['class' => 'alert alert-danger'])); $keywords = preg_split("/['(.*)']+/", $line); switch (trim($keywords[0])) { case 'Service notification period': - $errorLine->addItem(' '._('Notifikační perioda').' služeb '); + $errorLine->addItem(' '._('Notification period').' of services '); $errorLine->addItem(new \Ease\Html\ATag('timeperiod.php?timeperiod_name='.$keywords[1], $keywords[1])); break; case 'Host notification period': - $errorLine->addItem(' '._('Notifikační perioda').' hostů'); + $errorLine->addItem(' '._('Notification period').' of hosts'); $errorLine->addItem(new \Ease\Html\ATag('timeperiod.php?timeperiod_name='.$keywords[1], $keywords[1])); break; @@ -98,7 +97,7 @@ if (isset($keywords[2])) { switch (trim($keywords[2])) { case 'specified for contact': - $errorLine->addItem(' specifikovaná pro kontakt '); + $errorLine->addItem(' specified for contact '); $contact = new Engine\Contact($keywords[3]); $errorLine->addItem(new \Ease\Html\ATag('contact.php?contact_id='.$contact->getMyKey(), $keywords[3])); @@ -111,11 +110,10 @@ if (isset($keywords[4])) { switch (trim($keywords[4])) { case 'is not defined anywhere!': - $errorLine->addItem(' není nikde definován/a '); + $errorLine->addItem(''._('is not defined anywhere')); break; } } - //$OPage->addItem('
' . EaseBrick::printPreBasic($keywords) . '
'); } if (strstr($line, 'Error in configuration file')) { @@ -151,30 +149,36 @@ if (strstr($line, 'Total Warnings')) { list($msg, $WarningCount) = explode(':', $line); if (intval(trim($WarningCount))) { - $oUser->addStatusMessage(sprintf(_('celkem %s varování'), + $oUser->addStatusMessage(sprintf(_('total %s warnings'), $WarningCount), 'warning'); } else { - $oUser->addStatusMessage(_('test proběhl bez varování'), + $oUser->addStatusMessage(_('test successfully done without warnings'), 'success'); } } if (strstr($line, 'Total Errors')) { list($msg, $errorCount) = explode(':', $line); if (intval(trim($errorCount))) { - $oUser->addStatusMessage(sprintf(_('celkem %s chyb'), + $oUser->addStatusMessage(sprintf(_('total %s errors'), $errorCount), 'warning'); } else { - $oUser->addStatusMessage(_('test proběhl bez chyb'), 'success'); + $oUser->addStatusMessage(_('test successfully done without errors'), + 'success'); } } } fclose($testing); if (!intval($errorCount) && !is_null($WarningCount)) { - $oPage->container->addItem(new \Ease\TWB\LinkButton('reload.php', - _('Reload icingy').' ')); - } else { + $extCmd = new ExternalCommand(); + $extCmd->addCommand('RESTART_PROCESS'); + $extCmd->executeAll(); + $oPage->container->addItem(new \Ease\TWB\LinkButton('main.php', + _('Done').' '.\Ease\TWB\Part::GlyphIcon('ok-sign'), 'success')); + \Ease\Shared::user()->setSettingValue('unsaved', false); + } else { + } }