Added options 'php-censor.ssh.strength' and 'php-censor.ssh.comment'
for SSH keys generation. Issue #154.
This commit is contained in:
parent
61f512fd22
commit
d28d496264
|
@ -39,6 +39,9 @@ php-censor:
|
|||
log:
|
||||
rotate: true
|
||||
max_files: 10
|
||||
ssh:
|
||||
strength: 4096 # SSH keys strength (default: 2048)
|
||||
comment: admin@php-censor.info # SSH keys comment (default: admin@php-censor)
|
||||
bitbucket:
|
||||
username: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
app_password: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
||||
|
|
|
@ -265,6 +265,10 @@ class InstallCommand extends Command
|
|||
'smtp_password' => null,
|
||||
'smtp_encryption' => false,
|
||||
],
|
||||
'ssh' => [
|
||||
'strength' => 2048,
|
||||
'comment' => 'admin@php-censor',
|
||||
],
|
||||
'bitbucket' => [
|
||||
'username' => null,
|
||||
'app_password' => null,
|
||||
|
|
|
@ -297,17 +297,15 @@ class ProjectController extends PHPCensor\Controller
|
|||
$this->requireAdmin();
|
||||
|
||||
$method = $this->request->getMethod();
|
||||
$pub = null;
|
||||
$values = $this->getParams();
|
||||
$values['branch'] = '';
|
||||
|
||||
if ($method != 'POST') {
|
||||
if ($method !== 'POST') {
|
||||
$sshKey = new SshKey();
|
||||
$key = $sshKey->generate();
|
||||
|
||||
$values['key'] = $key['private_key'];
|
||||
$values['pubkey'] = $key['public_key'];
|
||||
$pub = $key['public_key'];
|
||||
}
|
||||
|
||||
$form = $this->projectForm($values);
|
||||
|
@ -317,7 +315,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
$view->type = 'add';
|
||||
$view->project = null;
|
||||
$view->form = $form;
|
||||
$view->key = $pub;
|
||||
$view->key = $values['pubkey'];
|
||||
|
||||
return $view->render();
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace PHPCensor\Helper;
|
||||
|
||||
use b8\Config;
|
||||
|
||||
/**
|
||||
* Helper class for dealing with SSH keys.
|
||||
*/
|
||||
|
@ -9,6 +11,7 @@ class SshKey
|
|||
{
|
||||
/**
|
||||
* Uses ssh-keygen to generate a public/private key pair.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generate()
|
||||
|
@ -22,7 +25,17 @@ class SshKey
|
|||
|
||||
$return = ['private_key' => '', 'public_key' => ''];
|
||||
|
||||
$output = @shell_exec('ssh-keygen -t rsa -b 2048 -f '.$keyFile.' -N "" -C "deploy@php-censor"');
|
||||
$sshStrength = Config::getInstance()->get('php-censor.ssh.strength', 2048);
|
||||
$sshComment = Config::getInstance()->get('php-censor.ssh.comment', 'admin@php-censor');
|
||||
|
||||
$output = @shell_exec(
|
||||
sprintf(
|
||||
'ssh-keygen -t rsa -b %s -f %s -N "" -C "%s"',
|
||||
$sshStrength,
|
||||
$keyFile,
|
||||
$sshComment
|
||||
)
|
||||
);
|
||||
|
||||
if (!empty($output)) {
|
||||
$pub = file_get_contents($keyFile . '.pub');
|
||||
|
|
|
@ -93,12 +93,12 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface
|
|||
$this->suffixes = ['php'];
|
||||
$this->directory = $this->builder->buildPath;
|
||||
$this->standard = 'PSR2';
|
||||
$this->tabWidth = '';
|
||||
$this->tabWidth = '';
|
||||
$this->encoding = '';
|
||||
$this->path = '';
|
||||
$this->ignore = $this->builder->ignore;
|
||||
$this->allowedWarnings = 0;
|
||||
$this->allowedErrors = 0;
|
||||
$this->allowedWarnings = 0;
|
||||
$this->allowedErrors = 0;
|
||||
|
||||
if (isset($options['zero_config']) && $options['zero_config']) {
|
||||
$this->allowedWarnings = -1;
|
||||
|
@ -133,6 +133,10 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface
|
|||
$this->standard = $options['standard'];
|
||||
}
|
||||
|
||||
if (!empty($options['path'])) {
|
||||
$this->path = $options['path'];
|
||||
}
|
||||
|
||||
if (isset($options['severity']) && is_int($options['severity'])) {
|
||||
$this->severity = $options['severity'];
|
||||
}
|
||||
|
@ -144,10 +148,6 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface
|
|||
if (isset($options['warning_severity']) && is_int($options['warning_severity'])) {
|
||||
$this->warningSeverity = $options['warning_severity'];
|
||||
}
|
||||
|
||||
if (isset($options['path'])) {
|
||||
$this->path = $options['path'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue