mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
Make use of the new CLI module command namespaces
It's now not `icingacli setup showToken' anymore but `icingacli setup token show' etc. refs #7163
This commit is contained in:
parent
a8e28bfee4
commit
e827e6ddcf
63
modules/setup/application/clicommands/ConfigCommand.php
Normal file
63
modules/setup/application/clicommands/ConfigCommand.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Setup\Clicommands;
|
||||
|
||||
use Icinga\Cli\Command;
|
||||
|
||||
class ConfigCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Create the configuration directory
|
||||
*
|
||||
* This command creates the configuration directory for Icinga Web 2. The `group' argument
|
||||
* is mandatory and should be the groupname of the user your web server is running as.
|
||||
*
|
||||
* USAGE:
|
||||
*
|
||||
* icingacli setup config createDirectory <group> [options]
|
||||
*
|
||||
* OPTIONS:
|
||||
*
|
||||
* --mode The access mode to use. Default is: 2775
|
||||
* --path The path to the configuration directory. If omitted the default is used.
|
||||
*
|
||||
* EXAMPLES:
|
||||
*
|
||||
* icingacli setup config createDirectory apache
|
||||
* icingacli setup config createDirectory apache --mode 2770
|
||||
* icingacli setup config createDirectory apache --path /some/path
|
||||
*/
|
||||
public function createDirectoryAction()
|
||||
{
|
||||
$group = $this->params->getStandalone();
|
||||
if ($group === null) {
|
||||
$this->fail($this->translate('The `group\' argument is mandatory.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$path = $this->params->get('path', $this->app->getConfigDir());
|
||||
if (file_exists($path)) {
|
||||
printf($this->translate("Configuration directory already exists at: %s\n"), $path);
|
||||
return true;
|
||||
}
|
||||
|
||||
$mode = octdec($this->params->get('mode', '2775'));
|
||||
if (false === mkdir($path)) {
|
||||
$this->fail(sprintf($this->translate('Unable to create path: %s'), $path));
|
||||
return false;
|
||||
}
|
||||
|
||||
$old = umask(0); // Prevent $mode from being mangled by the system's umask ($old)
|
||||
chmod($path, $mode);
|
||||
umask($old);
|
||||
|
||||
if (chgrp($path, $group) === false) {
|
||||
$this->fail(sprintf($this->translate('Unable to change the group of "%s" to "%s".'), $path, $group));
|
||||
return false;
|
||||
}
|
||||
|
||||
printf($this->translate("Successfully created configuration directory at: %s\n"), $path);
|
||||
}
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Setup\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 setting up 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 setting up Icinga Web 2 using the web-based wizard.
|
||||
*
|
||||
* USAGE:
|
||||
*
|
||||
* icingacli setup generateToken
|
||||
*/
|
||||
public function generateTokenAction()
|
||||
{
|
||||
if (function_exists('openssl_random_pseudo_bytes')) {
|
||||
$token = bin2hex(openssl_random_pseudo_bytes(8));
|
||||
} else {
|
||||
$token = substr(md5(mt_rand()), 16);
|
||||
}
|
||||
|
||||
$filepath = $this->app->getConfigDir() . '/setup.token';
|
||||
|
||||
if (false === file_put_contents($filepath, $token)) {
|
||||
$this->fail(sprintf($this->translate('Cannot write setup token "%s" to disk.'), $filepath));
|
||||
}
|
||||
|
||||
if (false === chmod($filepath, 0660)) {
|
||||
$this->fail(sprintf($this->translate('Cannot change access mode of "%s" to %o.'), $filepath, 0660));
|
||||
}
|
||||
|
||||
printf($this->translate("The newly generated setup token is: %s\n"), $token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the configuration directory
|
||||
*
|
||||
* This command creates the configuration directory for Icinga Web 2. The `group' argument
|
||||
* is mandatory and should be the groupname of the user your web server is running as.
|
||||
*
|
||||
* USAGE:
|
||||
*
|
||||
* icingacli setup createConfigDirectory <group> [options]
|
||||
*
|
||||
* OPTIONS:
|
||||
*
|
||||
* --mode The access mode to use. Default is: 2775
|
||||
* --path The path to the configuration directory. If omitted the default is used.
|
||||
*
|
||||
* EXAMPLES:
|
||||
*
|
||||
* icingacli setup createConfigDirectory apache
|
||||
* icingacli setup createConfigDirectory apache --mode 2770
|
||||
* icingacli setup createConfigDirectory apache --path /some/path
|
||||
*/
|
||||
public function createConfigDirectoryAction()
|
||||
{
|
||||
$group = $this->params->getStandalone();
|
||||
if ($group === null) {
|
||||
$this->fail($this->translate('The `group\' argument is mandatory.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$path = $this->params->get('path', $this->app->getConfigDir());
|
||||
if (file_exists($path)) {
|
||||
printf($this->translate("Configuration directory already exists at: %s\n"), $path);
|
||||
return true;
|
||||
}
|
||||
|
||||
$mode = octdec($this->params->get('mode', '2775'));
|
||||
if (false === mkdir($path)) {
|
||||
$this->fail(sprintf($this->translate('Unable to create path: %s'), $path));
|
||||
return false;
|
||||
}
|
||||
|
||||
$old = umask(0); // Prevent $mode from being mangled by the system's umask ($old)
|
||||
chmod($path, $mode);
|
||||
umask($old);
|
||||
|
||||
if (chgrp($path, $group) === false) {
|
||||
$this->fail(sprintf($this->translate('Unable to change the group of "%s" to "%s".'), $path, $group));
|
||||
return false;
|
||||
}
|
||||
|
||||
printf($this->translate("Successfully created configuration directory at: %s\n"), $path);
|
||||
}
|
||||
}
|
68
modules/setup/application/clicommands/TokenCommand.php
Normal file
68
modules/setup/application/clicommands/TokenCommand.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Module\Setup\Clicommands;
|
||||
|
||||
use Icinga\Cli\Command;
|
||||
|
||||
/**
|
||||
* Maintain the setup wizard's authentication
|
||||
*
|
||||
* The token command allows you to display the current setup token or to create a new one.
|
||||
*
|
||||
* Usage: icingacli setup token <action>
|
||||
*/
|
||||
class TokenCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Display the current setup token
|
||||
*
|
||||
* Shows you the current setup token used to authenticate when setting up Icinga Web 2 using the web-based wizard.
|
||||
*
|
||||
* USAGE:
|
||||
*
|
||||
* icingacli setup token show
|
||||
*/
|
||||
public function showAction()
|
||||
{
|
||||
$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 setting up Icinga Web 2 using the web-based wizard.
|
||||
*
|
||||
* USAGE:
|
||||
*
|
||||
* icingacli setup token create
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
if (function_exists('openssl_random_pseudo_bytes')) {
|
||||
$token = bin2hex(openssl_random_pseudo_bytes(8));
|
||||
} else {
|
||||
$token = substr(md5(mt_rand()), 16);
|
||||
}
|
||||
|
||||
$filepath = $this->app->getConfigDir() . '/setup.token';
|
||||
|
||||
if (false === file_put_contents($filepath, $token)) {
|
||||
$this->fail(sprintf($this->translate('Cannot write setup token "%s" to disk.'), $filepath));
|
||||
}
|
||||
|
||||
if (false === chmod($filepath, 0660)) {
|
||||
$this->fail(sprintf($this->translate('Cannot change access mode of "%s" to %o.'), $filepath, 0660));
|
||||
}
|
||||
|
||||
printf($this->translate("The newly generated setup token is: %s\n"), $token);
|
||||
}
|
||||
}
|
@ -65,8 +65,8 @@ $setupTokenPath = rtrim(Icinga::app()->getConfigDir(), '/') . '/setup.token';
|
||||
); ?></p>
|
||||
<p><?= t('If you\'ve got the IcingaCLI installed you can do the following:'); ?></p>
|
||||
<div class="code">
|
||||
<span>icingacli setup createConfigDirectory <?= ($user = Platform::getPhpUser()) !== null ? $user : 'your_webserver_group'; ?>;</span>
|
||||
<span>icingacli setup generateToken;</span>
|
||||
<span>icingacli setup config createDirectory <?= ($user = Platform::getPhpUser()) !== null ? $user : 'your_webserver_group'; ?>;</span>
|
||||
<span>icingacli setup token create;</span>
|
||||
</div>
|
||||
<p><?= t('In case the IcingaCLI is missing you can create the token manually:'); ?></p>
|
||||
<div class="code">
|
||||
|
Loading…
x
Reference in New Issue
Block a user