mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 07:44:05 +02:00
Util: new helper class
This commit is contained in:
parent
2dcd1c2d78
commit
676acf0740
@ -3,12 +3,13 @@
|
|||||||
use Icinga\Module\Director\ActionController;
|
use Icinga\Module\Director\ActionController;
|
||||||
|
|
||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||||
|
use Icinga\Module\Director\Util;
|
||||||
|
|
||||||
class Director_ConfigController extends ActionController
|
class Director_ConfigController extends ActionController
|
||||||
{
|
{
|
||||||
public function showAction()
|
public function showAction()
|
||||||
{
|
{
|
||||||
$this->view->config = IcingaConfig::fromDb(pack('H*', $this->params->get('checksum')), $this->db());
|
$this->view->config = IcingaConfig::fromDb(Util::hex2binary($this->params->get('checksum')), $this->db());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function storeAction()
|
public function storeAction()
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use Icinga\Module\Director\ActionController;
|
use Icinga\Module\Director\ActionController;
|
||||||
|
|
||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||||
|
use Icinga\Module\Director\Util;
|
||||||
|
|
||||||
class Director_ShowController extends ActionController
|
class Director_ShowController extends ActionController
|
||||||
{
|
{
|
||||||
@ -11,7 +12,7 @@ class Director_ShowController extends ActionController
|
|||||||
if ($id = $this->params->get('id')) {
|
if ($id = $this->params->get('id')) {
|
||||||
$this->view->entry = $this->db()->fetchActivityLogEntryById($id);
|
$this->view->entry = $this->db()->fetchActivityLogEntryById($id);
|
||||||
} elseif ($checksum = $this->params->get('checksum')) {
|
} elseif ($checksum = $this->params->get('checksum')) {
|
||||||
$this->view->entry = $this->db()->fetchActivityLogEntry(pack('H*', $checksum));
|
$this->view->entry = $this->db()->fetchActivityLogEntry(Util::hex2binary($checksum));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view->title = $this->translate('Activity');
|
$this->view->title = $this->translate('Activity');
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
namespace Icinga\Module\Director\Data\Db;
|
namespace Icinga\Module\Director\Data\Db;
|
||||||
|
|
||||||
use Icinga\Data\Db\DbConnection;
|
use Icinga\Data\Db\DbConnection;
|
||||||
|
use Icinga\Module\Director\Util;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -557,7 +559,7 @@ abstract class DbObject
|
|||||||
if ($this->connection->getDbType() === 'pgsql') {
|
if ($this->connection->getDbType() === 'pgsql') {
|
||||||
foreach ($properties as $key => $value) {
|
foreach ($properties as $key => $value) {
|
||||||
if (preg_match('/checksum$/', $key)) {
|
if (preg_match('/checksum$/', $key)) {
|
||||||
$properties[$key] = new \Zend_Db_Expr("'" . pg_escape_bytea($value) . "'");
|
$properties[$key] = Util::pgBinEscape($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Icinga\Module\Director\IcingaConfig;
|
namespace Icinga\Module\Director\IcingaConfig;
|
||||||
|
|
||||||
use Icinga\Data\Db\DbConnection;
|
use Icinga\Data\Db\DbConnection;
|
||||||
|
use Icinga\Module\Director\Util;
|
||||||
use Icinga\Module\Director\Objects\IcingaCommand;
|
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ class IcingaConfig
|
|||||||
|
|
||||||
public function getHexChecksum()
|
public function getHexChecksum()
|
||||||
{
|
{
|
||||||
return current(unpack('H*', $this->checksum));
|
return Util::binary2hex($this->checksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFiles()
|
public function getFiles()
|
||||||
@ -243,7 +244,7 @@ class IcingaConfig
|
|||||||
|
|
||||||
public function getLastActivityHexChecksum()
|
public function getLastActivityHexChecksum()
|
||||||
{
|
{
|
||||||
return current(unpack('H*', $this->getLastActivityChecksum()));
|
return Util::binary2hex($this->getLastActivityChecksum());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Icinga\Module\Director\IcingaConfig;
|
namespace Icinga\Module\Director\IcingaConfig;
|
||||||
|
|
||||||
use Icinga\Module\Director\Objects\IcingaObject;
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
|
use Icinga\Module\Director\Util;
|
||||||
|
|
||||||
class IcingaConfigFile
|
class IcingaConfigFile
|
||||||
{
|
{
|
||||||
@ -35,7 +36,7 @@ class IcingaConfigFile
|
|||||||
|
|
||||||
public function getHexChecksum()
|
public function getHexChecksum()
|
||||||
{
|
{
|
||||||
return current(unpack('H*', $this->getChecksum()));
|
return Util::binary2hex($this->getChecksum());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getChecksum()
|
public function getChecksum()
|
||||||
|
@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Objects;
|
|||||||
|
|
||||||
use Icinga\Module\Director\Data\Db\DbObject;
|
use Icinga\Module\Director\Data\Db\DbObject;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
|
use Icinga\Module\Director\Util;
|
||||||
use Icinga\Authentication\Manager as Auth;
|
use Icinga\Authentication\Manager as Auth;
|
||||||
|
|
||||||
class DirectorActivityLog extends DbObject
|
class DirectorActivityLog extends DbObject
|
||||||
@ -51,7 +52,7 @@ class DirectorActivityLog extends DbObject
|
|||||||
);
|
);
|
||||||
|
|
||||||
$data['checksum'] = sha1(json_encode($data), true);
|
$data['checksum'] = sha1(json_encode($data), true);
|
||||||
$data['parent_checksum'] = pack('H*', $data['parent_checksum']);
|
$data['parent_checksum'] = Util::hex2binary($data['parent_checksum']);
|
||||||
return self::create($data)->store($db);
|
return self::create($data)->store($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ class DirectorActivityLog extends DbObject
|
|||||||
);
|
);
|
||||||
|
|
||||||
$data['checksum'] = sha1(json_encode($data), true);
|
$data['checksum'] = sha1(json_encode($data), true);
|
||||||
$data['parent_checksum'] = pack('H*', $data['parent_checksum']);
|
$data['parent_checksum'] = Util::hex2binary($data['parent_checksum']);
|
||||||
return self::create($data)->store($db);
|
return self::create($data)->store($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ class DirectorActivityLog extends DbObject
|
|||||||
);
|
);
|
||||||
|
|
||||||
$data['checksum'] = sha1(json_encode($data), true);
|
$data['checksum'] = sha1(json_encode($data), true);
|
||||||
$data['parent_checksum'] = pack('H*', $data['parent_checksum']);
|
$data['parent_checksum'] = Util::hex2binary($data['parent_checksum']);
|
||||||
return self::create($data)->store($db);
|
return self::create($data)->store($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
library/Director/Util.php
Normal file
23
library/Director/Util.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director;
|
||||||
|
|
||||||
|
use Zend_Db_Expr;
|
||||||
|
|
||||||
|
class Util
|
||||||
|
{
|
||||||
|
public static function pgBinEscape($binary)
|
||||||
|
{
|
||||||
|
return new Zend_Db_Expr("'" . pg_escape_bytea($binary) . "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function hex2binary($bin)
|
||||||
|
{
|
||||||
|
return pack('H*', $bin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function binary2hex($hex)
|
||||||
|
{
|
||||||
|
return end(unpack('H*', $hex));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user