mirror of https://github.com/MISP/MISP
chg: [internal] Move GPG initialization to GpgTool
parent
6fc8e4d119
commit
ee4de160e8
|
@ -1,6 +1,34 @@
|
|||
<?php
|
||||
class GpgTool
|
||||
{
|
||||
/**
|
||||
* @return Crypt_GPG
|
||||
* @throws Exception
|
||||
*/
|
||||
public function initializeGpg()
|
||||
{
|
||||
if (!class_exists('Crypt_GPG')) {
|
||||
// 'Crypt_GPG' class cannot be autoloaded, try to require from include_path.
|
||||
if (!stream_resolve_include_path('Crypt/GPG.php')) {
|
||||
throw new Exception("Crypt_GPG is not installed.");
|
||||
}
|
||||
require_once 'Crypt/GPG.php';
|
||||
}
|
||||
|
||||
$homedir = Configure::read('GnuPG.homedir');
|
||||
if ($homedir === null) {
|
||||
throw new Exception("Configuration option 'GnuPG.homedir' is not set, Crypt_GPG cannot be initialized.");
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'homedir' => $homedir,
|
||||
'gpgconf' => Configure::read('GnuPG.gpgconf'),
|
||||
'binary' => Configure::read('GnuPG.binary') ?: '/usr/bin/gpg',
|
||||
);
|
||||
|
||||
return new Crypt_GPG($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $search
|
||||
* @return array
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
App::uses('AppModel', 'Model');
|
||||
App::uses('GpgTool', 'Tools');
|
||||
|
||||
class Server extends AppModel
|
||||
{
|
||||
|
@ -5059,18 +5060,9 @@ class Server extends AppModel
|
|||
$gpgStatus = 0;
|
||||
if (Configure::read('GnuPG.email') && Configure::read('GnuPG.homedir')) {
|
||||
$continue = true;
|
||||
$gpgTool = new GpgTool();
|
||||
try {
|
||||
if (!class_exists('Crypt_GPG')) {
|
||||
if (!stream_resolve_include_path('Crypt/GPG.php')) {
|
||||
throw new Exception("Crypt_GPG is not installed");
|
||||
}
|
||||
require_once 'Crypt/GPG.php';
|
||||
}
|
||||
$gpg = new Crypt_GPG(array(
|
||||
'homedir' => Configure::read('GnuPG.homedir'),
|
||||
'gpgconf' => Configure::read('GnuPG.gpgconf'),
|
||||
'binary' => Configure::read('GnuPG.binary') ?: '/usr/bin/gpg'
|
||||
));
|
||||
$gpg = $gpgTool->initializeGpg();
|
||||
} catch (Exception $e) {
|
||||
$this->logException("Error during initializing GPG.", $e, LOG_NOTICE);
|
||||
$gpgStatus = 2;
|
||||
|
|
|
@ -1151,26 +1151,8 @@ class User extends AppModel
|
|||
*/
|
||||
private function initializeGpg()
|
||||
{
|
||||
if (!class_exists('Crypt_GPG')) {
|
||||
// 'Crypt_GPG' class cannot be autoloaded, try to require from include_path.
|
||||
if (!stream_resolve_include_path('Crypt/GPG.php')) {
|
||||
throw new Exception("Crypt_GPG is not installed.");
|
||||
}
|
||||
require_once 'Crypt/GPG.php';
|
||||
}
|
||||
|
||||
$homedir = Configure::read('GnuPG.homedir');
|
||||
if ($homedir === null) {
|
||||
throw new Exception("Configuration option 'GnuPG.homedir' is not set, Crypt_GPG cannot be initialized.");
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'homedir' => $homedir,
|
||||
'gpgconf' => Configure::read('GnuPG.gpgconf'),
|
||||
'binary' => Configure::read('GnuPG.binary') ?: '/usr/bin/gpg',
|
||||
);
|
||||
|
||||
return new Crypt_GPG($options);
|
||||
$gpgTool = new GpgTool();
|
||||
return $gpgTool->initializeGpg();
|
||||
}
|
||||
|
||||
public function getOrgActivity($orgId, $params=array())
|
||||
|
|
Loading…
Reference in New Issue