Util: drop bin2hex/hex2bin helpers
We dropped support for PHP 5.3, this is no longer required
This commit is contained in:
parent
e7d5b4a40a
commit
cf6e4536ea
|
@ -94,7 +94,7 @@ class ConfigCommand extends Command
|
||||||
|
|
||||||
$checksum = $this->params->get('checksum');
|
$checksum = $this->params->get('checksum');
|
||||||
if ($checksum) {
|
if ($checksum) {
|
||||||
$config = IcingaConfig::load(Util::hex2binary($checksum), $db);
|
$config = IcingaConfig::load(hex2bin($checksum), $db);
|
||||||
} else {
|
} else {
|
||||||
$config = IcingaConfig::generate($db);
|
$config = IcingaConfig::generate($db);
|
||||||
$checksum = $config->getHexChecksum();
|
$checksum = $config->getHexChecksum();
|
||||||
|
|
|
@ -107,7 +107,7 @@ class ConfigController extends ActionController
|
||||||
// TODO: require POST
|
// TODO: require POST
|
||||||
$checksum = $this->params->get('checksum');
|
$checksum = $this->params->get('checksum');
|
||||||
if ($checksum) {
|
if ($checksum) {
|
||||||
$config = IcingaConfig::load(Util::hex2binary($checksum), $this->db());
|
$config = IcingaConfig::load(hex2bin($checksum), $this->db());
|
||||||
} else {
|
} else {
|
||||||
$config = IcingaConfig::generate($this->db());
|
$config = IcingaConfig::generate($this->db());
|
||||||
$checksum = $config->getHexChecksum();
|
$checksum = $config->getHexChecksum();
|
||||||
|
@ -237,7 +237,7 @@ class ConfigController extends ActionController
|
||||||
}
|
}
|
||||||
$this->assertPermission('director/showconfig');
|
$this->assertPermission('director/showconfig');
|
||||||
$config = IcingaConfig::load(
|
$config = IcingaConfig::load(
|
||||||
Util::hex2binary($this->params->getRequired('checksum')),
|
hex2bin($this->params->getRequired('checksum')),
|
||||||
$this->db()
|
$this->db()
|
||||||
);
|
);
|
||||||
$deploymentId = $this->params->get('deployment_id');
|
$deploymentId = $this->params->get('deployment_id');
|
||||||
|
@ -296,7 +296,7 @@ class ConfigController extends ActionController
|
||||||
$this->addBackLink('director/config/files', $params);
|
$this->addBackLink('director/config/files', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = IcingaConfig::load(Util::hex2binary($this->params->get('config_checksum')), $this->db());
|
$config = IcingaConfig::load(hex2bin($this->params->get('config_checksum')), $this->db());
|
||||||
$this->addTitle($this->translate('Config file "%s"'), $filename);
|
$this->addTitle($this->translate('Config file "%s"'), $filename);
|
||||||
$this->content()->add(new ShowConfigFile(
|
$this->content()->add(new ShowConfigFile(
|
||||||
$config->getFile($filename),
|
$config->getFile($filename),
|
||||||
|
@ -389,8 +389,8 @@ class ConfigController extends ActionController
|
||||||
$rightSum = $p->getRequired('right');
|
$rightSum = $p->getRequired('right');
|
||||||
$filename = $p->getRequired('file_path');
|
$filename = $p->getRequired('file_path');
|
||||||
|
|
||||||
$left = IcingaConfig::load(Util::hex2binary($leftSum), $db);
|
$left = IcingaConfig::load(hex2bin($leftSum), $db);
|
||||||
$right = IcingaConfig::load(Util::hex2binary($rightSum), $db);
|
$right = IcingaConfig::load(hex2bin($rightSum), $db);
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->addTitle($this->translate('Config file "%s"'), $filename)
|
->addTitle($this->translate('Config file "%s"'), $filename)
|
||||||
|
|
|
@ -77,7 +77,7 @@ class DeployConfigForm extends DirectorForm
|
||||||
|
|
||||||
$isApiRequest = $this->getRequest()->isApiRequest();
|
$isApiRequest = $this->getRequest()->isApiRequest();
|
||||||
if ($this->checksum) {
|
if ($this->checksum) {
|
||||||
$config = IcingaConfig::load(Util::hex2binary($this->checksum), $db);
|
$config = IcingaConfig::load(hex2bin($this->checksum), $db);
|
||||||
} else {
|
} else {
|
||||||
$config = IcingaConfig::generate($db);
|
$config = IcingaConfig::generate($db);
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,7 +301,7 @@ class Db extends DbConnection
|
||||||
$result = $this->db()->fetchOne($sql);
|
$result = $this->db()->fetchOne($sql);
|
||||||
|
|
||||||
if ($binary) {
|
if ($binary) {
|
||||||
return Util::hex2binary($result);
|
return hex2bin($result);
|
||||||
} else {
|
} else {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -332,7 +332,7 @@ class Db extends DbConnection
|
||||||
);
|
);
|
||||||
|
|
||||||
return $db->fetchRow(
|
return $db->fetchRow(
|
||||||
$db->quoteInto($sql, $this->quoteBinary(Util::hex2binary($checksum)))
|
$db->quoteInto($sql, $this->quoteBinary(hex2bin($checksum)))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ class IcingaConfig
|
||||||
|
|
||||||
public function getHexChecksum()
|
public function getHexChecksum()
|
||||||
{
|
{
|
||||||
return Util::binary2hex($this->checksum);
|
return bin2hex($this->checksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -204,7 +204,7 @@ class IcingaConfig
|
||||||
array('checksum' => $connection->dbHexFunc('c.checksum'))
|
array('checksum' => $connection->dbHexFunc('c.checksum'))
|
||||||
)->where(
|
)->where(
|
||||||
'checksum = ?',
|
'checksum = ?',
|
||||||
$connection->quoteBinary(Util::hex2binary($checksum))
|
$connection->quoteBinary(hex2bin($checksum))
|
||||||
);
|
);
|
||||||
|
|
||||||
return $db->fetchOne($query) === $checksum;
|
return $db->fetchOne($query) === $checksum;
|
||||||
|
@ -222,7 +222,7 @@ class IcingaConfig
|
||||||
array()
|
array()
|
||||||
)->where(
|
)->where(
|
||||||
'last_activity_checksum = ?',
|
'last_activity_checksum = ?',
|
||||||
$connection->quoteBinary(Util::hex2binary($checksum))
|
$connection->quoteBinary(hex2bin($checksum))
|
||||||
)->order('l.id DESC')->limit(1);
|
)->order('l.id DESC')->limit(1);
|
||||||
|
|
||||||
return self::load($db->fetchOne($query), $connection);
|
return self::load($db->fetchOne($query), $connection);
|
||||||
|
@ -240,7 +240,7 @@ class IcingaConfig
|
||||||
array()
|
array()
|
||||||
)->where(
|
)->where(
|
||||||
'last_activity_checksum = ?',
|
'last_activity_checksum = ?',
|
||||||
$connection->quoteBinary(Util::hex2binary($checksum))
|
$connection->quoteBinary(hex2bin($checksum))
|
||||||
)->order('l.id DESC')->limit(1);
|
)->order('l.id DESC')->limit(1);
|
||||||
|
|
||||||
return $db->fetchOne($query) === $checksum;
|
return $db->fetchOne($query) === $checksum;
|
||||||
|
@ -648,7 +648,7 @@ apply Service for (title => params in host.vars["%s"]) {
|
||||||
$result = $this->db->fetchRow($query);
|
$result = $this->db->fetchRow($query);
|
||||||
|
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
throw new NotFoundError('Got no config for %s', Util::binary2hex($checksum));
|
throw new NotFoundError('Got no config for %s', bin2hex($checksum));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checksum = $this->binFromDb($result->checksum);
|
$this->checksum = $this->binFromDb($result->checksum);
|
||||||
|
@ -785,7 +785,7 @@ apply Service for (title => params in host.vars["%s"]) {
|
||||||
|
|
||||||
public function getLastActivityHexChecksum()
|
public function getLastActivityHexChecksum()
|
||||||
{
|
{
|
||||||
return Util::binary2hex($this->getLastActivityChecksum());
|
return bin2hex($this->getLastActivityChecksum());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -96,7 +96,7 @@ class IcingaConfigFile
|
||||||
|
|
||||||
public function getHexChecksum()
|
public function getHexChecksum()
|
||||||
{
|
{
|
||||||
return Util::binary2hex($this->getChecksum());
|
return bin2hex($this->getChecksum());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getChecksum()
|
public function getChecksum()
|
||||||
|
|
|
@ -339,7 +339,7 @@ class Import
|
||||||
protected function lastRowsetIs($checksum)
|
protected function lastRowsetIs($checksum)
|
||||||
{
|
{
|
||||||
return $this->connection->getLatestImportedChecksum($this->source->get('id'))
|
return $this->connection->getLatestImportedChecksum($this->source->get('id'))
|
||||||
=== Util::binary2hex($checksum);
|
=== bin2hex($checksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -391,7 +391,7 @@ class Import
|
||||||
// ...
|
// ...
|
||||||
// return array_diff($checksums, $existing);
|
// return array_diff($checksums, $existing);
|
||||||
|
|
||||||
$hexed = array_map('Icinga\Module\Director\Util::binary2hex', $checksums);
|
$hexed = array_map('bin2hex', $checksums);
|
||||||
|
|
||||||
$conn = $this->connection;
|
$conn = $this->connection;
|
||||||
$query = $db
|
$query = $db
|
||||||
|
@ -407,7 +407,7 @@ class Import
|
||||||
$existing = $db->fetchCol($query);
|
$existing = $db->fetchCol($query);
|
||||||
$new = array_diff($hexed, $existing);
|
$new = array_diff($hexed, $existing);
|
||||||
|
|
||||||
return array_map('Icinga\Module\Director\Util::hex2binary', $new);
|
return array_map('hex2bin', $new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -739,7 +739,7 @@ class Sync
|
||||||
$object = null;
|
$object = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$formerActivityChecksum = Util::hex2binary(
|
$formerActivityChecksum = hex2bin(
|
||||||
$db->getLastActivityChecksum()
|
$db->getLastActivityChecksum()
|
||||||
);
|
);
|
||||||
$created = 0;
|
$created = 0;
|
||||||
|
@ -775,7 +775,7 @@ class Sync
|
||||||
if ($created + $deleted + $modified > 0) {
|
if ($created + $deleted + $modified > 0) {
|
||||||
// TODO: What if this has been the very first activity?
|
// TODO: What if this has been the very first activity?
|
||||||
$runProperties['last_former_activity'] = $db->quoteBinary($formerActivityChecksum);
|
$runProperties['last_former_activity'] = $db->quoteBinary($formerActivityChecksum);
|
||||||
$runProperties['last_related_activity'] = $db->quoteBinary(Util::hex2binary(
|
$runProperties['last_related_activity'] = $db->quoteBinary(hex2bin(
|
||||||
$db->getLastActivityChecksum()
|
$db->getLastActivityChecksum()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ class ConfigJob extends JobHook
|
||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
|
|
||||||
return IcingaConfig::existsForActivityChecksum(
|
return IcingaConfig::existsForActivityChecksum(
|
||||||
Util::binary2hex(DirectorActivityLog::loadLatest($db)->checksum),
|
bin2hex(DirectorActivityLog::loadLatest($db)->checksum),
|
||||||
$db
|
$db
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ class DirectorActivityLog extends DbObject
|
||||||
);
|
);
|
||||||
|
|
||||||
$data['checksum'] = sha1(json_encode($data), true);
|
$data['checksum'] = sha1(json_encode($data), true);
|
||||||
$data['parent_checksum'] = Util::hex2binary($data['parent_checksum']);
|
$data['parent_checksum'] = hex2bin($data['parent_checksum']);
|
||||||
|
|
||||||
static::audit($db, array(
|
static::audit($db, array(
|
||||||
'action' => 'create',
|
'action' => 'create',
|
||||||
|
@ -136,7 +136,7 @@ class DirectorActivityLog extends DbObject
|
||||||
);
|
);
|
||||||
|
|
||||||
$data['checksum'] = sha1(json_encode($data), true);
|
$data['checksum'] = sha1(json_encode($data), true);
|
||||||
$data['parent_checksum'] = Util::hex2binary($data['parent_checksum']);
|
$data['parent_checksum'] = hex2bin($data['parent_checksum']);
|
||||||
|
|
||||||
static::audit($db, array(
|
static::audit($db, array(
|
||||||
'action' => 'modify',
|
'action' => 'modify',
|
||||||
|
@ -166,7 +166,7 @@ class DirectorActivityLog extends DbObject
|
||||||
);
|
);
|
||||||
|
|
||||||
$data['checksum'] = sha1(json_encode($data), true);
|
$data['checksum'] = sha1(json_encode($data), true);
|
||||||
$data['parent_checksum'] = Util::hex2binary($data['parent_checksum']);
|
$data['parent_checksum'] = hex2bin($data['parent_checksum']);
|
||||||
|
|
||||||
static::audit($db, array(
|
static::audit($db, array(
|
||||||
'action' => 'remove',
|
'action' => 'remove',
|
||||||
|
|
|
@ -42,7 +42,7 @@ class DirectorDeploymentLog extends DbObject
|
||||||
|
|
||||||
public function getConfigHexChecksum()
|
public function getConfigHexChecksum()
|
||||||
{
|
{
|
||||||
return Util::binary2hex($this->config_checksum);
|
return bin2hex($this->config_checksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConfig()
|
public function getConfig()
|
||||||
|
|
|
@ -22,16 +22,6 @@ class Util
|
||||||
return new Zend_Db_Expr("'\\x" . bin2hex($binary) . "'");
|
return new Zend_Db_Expr("'\\x" . bin2hex($binary) . "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function hex2binary($bin)
|
|
||||||
{
|
|
||||||
return pack('H*', $bin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function binary2hex($hex)
|
|
||||||
{
|
|
||||||
return current(unpack('H*', $hex));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PBKDF2 - Password-Based Cryptography Specification (RFC2898)
|
* PBKDF2 - Password-Based Cryptography Specification (RFC2898)
|
||||||
*
|
*
|
||||||
|
|
|
@ -104,12 +104,12 @@ class ConfigFileDiffTable extends ZfQueryBasedTable
|
||||||
array('cfr' => 'director_generated_config_file'),
|
array('cfr' => 'director_generated_config_file'),
|
||||||
$db->quoteInto(
|
$db->quoteInto(
|
||||||
'cfl.file_path = cfr.file_path AND cfr.config_checksum = ?',
|
'cfl.file_path = cfr.file_path AND cfr.config_checksum = ?',
|
||||||
$this->quoteBinary(Util::hex2binary($this->rightChecksum))
|
$this->quoteBinary(hex2bin($this->rightChecksum))
|
||||||
),
|
),
|
||||||
array()
|
array()
|
||||||
)->where(
|
)->where(
|
||||||
'cfl.config_checksum = ?',
|
'cfl.config_checksum = ?',
|
||||||
$this->quoteBinary(Util::hex2binary($this->leftChecksum))
|
$this->quoteBinary(hex2bin($this->leftChecksum))
|
||||||
);
|
);
|
||||||
|
|
||||||
$right = $db->select()
|
$right = $db->select()
|
||||||
|
@ -127,12 +127,12 @@ class ConfigFileDiffTable extends ZfQueryBasedTable
|
||||||
array('cfr' => 'director_generated_config_file'),
|
array('cfr' => 'director_generated_config_file'),
|
||||||
$db->quoteInto(
|
$db->quoteInto(
|
||||||
'cfl.file_path = cfr.file_path AND cfl.config_checksum = ?',
|
'cfl.file_path = cfr.file_path AND cfl.config_checksum = ?',
|
||||||
$this->quoteBinary(Util::hex2binary($this->leftChecksum))
|
$this->quoteBinary(hex2bin($this->leftChecksum))
|
||||||
),
|
),
|
||||||
array()
|
array()
|
||||||
)->where(
|
)->where(
|
||||||
'cfr.config_checksum = ?',
|
'cfr.config_checksum = ?',
|
||||||
$this->quoteBinary(Util::hex2binary($this->rightChecksum))
|
$this->quoteBinary(hex2bin($this->rightChecksum))
|
||||||
)->where('cfl.file_checksum IS NULL');
|
)->where('cfl.file_checksum IS NULL');
|
||||||
|
|
||||||
return $db->select()->union(array($left, $right))->order('file_path');
|
return $db->select()->union(array($left, $right))->order('file_path');
|
||||||
|
|
Loading…
Reference in New Issue