Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cli command to generate and show setup tokens
One is now able to utilize `icingacli setup (show/generate)Token` refs #7163
- Loading branch information
Johannes Meyer
committed
Sep 24, 2014
1 parent
98fbfe6
commit 71ccefa
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
// {{{ICINGA_LICENSE_HEADER}}} | ||
// {{{ICINGA_LICENSE_HEADER}}} | ||
|
||
namespace Icinga\Clicommands; | ||
|
||
use Icinga\Cli\Command; | ||
|
||
/** | ||
* Setup Icinga Web 2 | ||
* | ||
* The setup command allows you to install/configure Icinga Web 2 | ||
* | ||
* Usage: icingacli setup <action> [<argument>] | ||
*/ | ||
class SetupCommand extends Command | ||
{ | ||
/** | ||
* Display the current setup token | ||
* | ||
* Shows you the current setup token used to authenticate when installing Icinga Web 2 using the web-based wizard | ||
* | ||
* USAGE: | ||
* | ||
* icingacli setup showToken | ||
*/ | ||
public function showTokenAction() | ||
{ | ||
$token = @file_get_contents($this->app->getConfigDir() . '/setup.token'); | ||
if (! $token) { | ||
$this->fail( | ||
$this->translate('Nothing to show. Please create a new setup token using the generateToken action.') | ||
); | ||
} | ||
|
||
printf($this->translate("The current setup token is: %s\n"), $token); | ||
} | ||
|
||
/** | ||
* Create a new setup token | ||
* | ||
* Re-generates the setup token used to authenticate when installing Icinga Web 2 using the web-based wizard | ||
* | ||
* USAGE: | ||
* | ||
* icingacli setup generateToken | ||
*/ | ||
public function generateTokenAction() | ||
{ | ||
$token = bin2hex(openssl_random_pseudo_bytes(8)); | ||
$filepath = $this->app->getConfigDir() . '/setup.token'; | ||
|
||
if (false === @file_put_contents($filepath, $token)) { | ||
$this->fail($this->translate('Cannot write setup token to disk.')); | ||
} | ||
|
||
if (false === @chmod($filepath, 0640)) { | ||
$this->fail(sprintf($this->translate('Cannot change access mode of "%s" to %o.'), $filepath, 0640)); | ||
} | ||
|
||
printf($this->translate("The newly generated setup token is: %s\n"), $token); | ||
} | ||
} |