#9334 Added improve in satellite hosts
This commit is contained in:
parent
ffc51471d0
commit
cd199e233d
|
@ -238,6 +238,17 @@ foreach ($servers as $server) {
|
||||||
$data[8] .= '</a>';
|
$data[8] .= '</a>';
|
||||||
|
|
||||||
if (($names_servers[$safe_server_name] === true) && ($server['type'] === 'data' || $server['type'] === 'enterprise satellite')) {
|
if (($names_servers[$safe_server_name] === true) && ($server['type'] === 'data' || $server['type'] === 'enterprise satellite')) {
|
||||||
|
$data[8] .= '<a href="'.ui_get_full_url('index.php?sec=gservers&sec2=godmode/servers/modificar_server&server_remote='.$server['id_server'].'&ext='.$ext.'&tab=agent_editor').'">';
|
||||||
|
$data[8] .= html_print_image(
|
||||||
|
'images/agent.png',
|
||||||
|
true,
|
||||||
|
[
|
||||||
|
'title' => __('Manage satellite hosts'),
|
||||||
|
'class' => 'invert_filter',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$data[8] .= '</a>';
|
||||||
|
|
||||||
$data[8] .= '<a href="'.ui_get_full_url('index.php?sec=gservers&sec2=godmode/servers/modificar_server&server_remote='.$server['id_server'].'&ext='.$ext).'">';
|
$data[8] .= '<a href="'.ui_get_full_url('index.php?sec=gservers&sec2=godmode/servers/modificar_server&server_remote='.$server['id_server'].'&ext='.$ext).'">';
|
||||||
$data[8] .= html_print_image(
|
$data[8] .= html_print_image(
|
||||||
'images/remote_configuration.png',
|
'images/remote_configuration.png',
|
||||||
|
|
|
@ -56,6 +56,7 @@ class SatelliteAgent extends HTML
|
||||||
'draw',
|
'draw',
|
||||||
'addAgent',
|
'addAgent',
|
||||||
'deleteAgent',
|
'deleteAgent',
|
||||||
|
'disableAgent',
|
||||||
'loadModal',
|
'loadModal',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -97,7 +98,6 @@ class SatelliteAgent extends HTML
|
||||||
$this->satellite_name = servers_get_name($this->satellite_server);
|
$this->satellite_name = servers_get_name($this->satellite_server);
|
||||||
$this->satellite_config = (array) config_satellite_get_config_file($this->satellite_name);
|
$this->satellite_config = (array) config_satellite_get_config_file($this->satellite_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,13 +108,15 @@ class SatelliteAgent extends HTML
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
global $config;
|
||||||
// Javascript.
|
// Javascript.
|
||||||
ui_require_jquery_file('pandora');
|
ui_require_jquery_file('pandora');
|
||||||
// CSS.
|
// CSS.
|
||||||
ui_require_css_file('wizard');
|
ui_require_css_file('wizard');
|
||||||
ui_require_css_file('discovery');
|
ui_require_css_file('discovery');
|
||||||
|
|
||||||
global $config;
|
$this->createBlock();
|
||||||
|
|
||||||
// Datatables list.
|
// Datatables list.
|
||||||
try {
|
try {
|
||||||
$columns = [
|
$columns = [
|
||||||
|
@ -129,6 +131,13 @@ class SatelliteAgent extends HTML
|
||||||
__('Actions'),
|
__('Actions'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$show_agents = [
|
||||||
|
0 => __('Everyone'),
|
||||||
|
1 => __('Only disabled'),
|
||||||
|
2 => __('Only deleted'),
|
||||||
|
3 => __('Only added'),
|
||||||
|
];
|
||||||
|
|
||||||
$this->tableId = 'satellite_agents';
|
$this->tableId = 'satellite_agents';
|
||||||
|
|
||||||
if (is_metaconsole() === true) {
|
if (is_metaconsole() === true) {
|
||||||
|
@ -167,7 +176,15 @@ class SatelliteAgent extends HTML
|
||||||
'name' => 'filter_search',
|
'name' => 'filter_search',
|
||||||
'size' => 12,
|
'size' => 12,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'label' => __('Show agents'),
|
||||||
|
'type' => 'select',
|
||||||
|
'id' => 'filter_agents',
|
||||||
|
'name' => 'filter_agents',
|
||||||
|
'fields' => $show_agents,
|
||||||
|
'return' => true,
|
||||||
|
'selected' => 0,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
@ -200,7 +217,6 @@ class SatelliteAgent extends HTML
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
// Load own javascript file.
|
// Load own javascript file.
|
||||||
echo $this->loadJS();
|
echo $this->loadJS();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,8 +228,7 @@ class SatelliteAgent extends HTML
|
||||||
public function draw()
|
public function draw()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
// Initialice filter.
|
|
||||||
$filter = '1=1';
|
|
||||||
// Init data.
|
// Init data.
|
||||||
$data = [];
|
$data = [];
|
||||||
// Count of total records.
|
// Count of total records.
|
||||||
|
@ -228,8 +243,23 @@ class SatelliteAgent extends HTML
|
||||||
ob_start();
|
ob_start();
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
|
$agents_db = db_get_all_rows_sql(
|
||||||
|
sprintf(
|
||||||
|
'SELECT id_agente, alias AS name, direccion AS address,
|
||||||
|
IF(disabled = 0, INSERT("add_host", 0 , 0, ""), INSERT("ignore_host", 0 , 0, "")) AS type
|
||||||
|
FROM tagente WHERE `satellite_server` = %d AND modo = 1',
|
||||||
|
$this->satellite_server
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (empty($agents_db) === false) {
|
||||||
|
$data = $agents_db;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($this->satellite_config as $line) {
|
foreach ($this->satellite_config as $line) {
|
||||||
$re = '/^#*add_host \b(\S+) (\S*)$/m';
|
$re = '/^#*add_host \b(\S+) (\S*)/m';
|
||||||
|
$re_disable = '/^ignore_host \b(\S+) (\S*)/m';
|
||||||
|
$re_delete = '/^delete_host \b(\S+) (\S*)/m';
|
||||||
|
|
||||||
if (preg_match($re, $line, $matches, PREG_OFFSET_CAPTURE, 0) > 0) {
|
if (preg_match($re, $line, $matches, PREG_OFFSET_CAPTURE, 0) > 0) {
|
||||||
$agent['address'] = $matches[1][0];
|
$agent['address'] = $matches[1][0];
|
||||||
|
@ -239,17 +269,74 @@ class SatelliteAgent extends HTML
|
||||||
$agent['name'] = $matches[2][0];
|
$agent['name'] = $matches[2][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($filters['filter_search']) === false) {
|
$agent['type'] = 'add_host';
|
||||||
if (empty(preg_grep('/'.$filters['filter_search'].'?/mi', array_values($agent))) === true) {
|
|
||||||
continue;
|
array_push($data, $agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preg_match($re_disable, $line, $matches, PREG_OFFSET_CAPTURE, 0) > 0) {
|
||||||
|
$agent['address'] = $matches[1][0];
|
||||||
|
if (isset($matches[2][0]) === false || empty($matches[2][0]) === true) {
|
||||||
|
$agent['name'] = '';
|
||||||
|
} else {
|
||||||
|
$agent['name'] = $matches[2][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$agent['type'] = 'ignore_host';
|
||||||
|
|
||||||
|
array_push($data, $agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match($re_delete, $line, $matches, PREG_OFFSET_CAPTURE, 0) > 0) {
|
||||||
|
$agent['address'] = $matches[1][0];
|
||||||
|
if (isset($matches[2][0]) === false || empty($matches[2][0]) === true) {
|
||||||
|
$agent['name'] = '';
|
||||||
|
} else {
|
||||||
|
$agent['name'] = $matches[2][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$agent['type'] = 'delete_host';
|
||||||
|
|
||||||
array_push($data, $agent);
|
array_push($data, $agent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($data) === false) {
|
if (empty($data) === false) {
|
||||||
|
$data = $this->uniqueMultidimArray($data, ['name', 'address']);
|
||||||
|
if (empty($filters['filter_agents']) === false || empty($filters['filter_search']) === false) {
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
switch ($filters['filter_agents']) {
|
||||||
|
case 1:
|
||||||
|
if ($value['type'] !== 'ignore_host') {
|
||||||
|
unset($data[$key]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
if ($value['type'] !== 'delete_host') {
|
||||||
|
unset($data[$key]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
if ($value['type'] !== 'add_host') {
|
||||||
|
unset($data[$key]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Everyone.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($filters['filter_search']) === false) {
|
||||||
|
if (empty(preg_grep('/'.$filters['filter_search'].'?/mi', array_values($value))) === true) {
|
||||||
|
unset($data[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$data = array_reduce(
|
$data = array_reduce(
|
||||||
$data,
|
$data,
|
||||||
function ($carry, $item) {
|
function ($carry, $item) {
|
||||||
|
@ -258,15 +345,44 @@ class SatelliteAgent extends HTML
|
||||||
// of objects, making a post-process of certain fields.
|
// of objects, making a post-process of certain fields.
|
||||||
$tmp = (object) $item;
|
$tmp = (object) $item;
|
||||||
|
|
||||||
$tmp->actions .= html_print_image(
|
$disable = ($tmp->type === 'ignore_host');
|
||||||
'images/cross.png',
|
$delete = ($tmp->type === 'delete_host');
|
||||||
true,
|
|
||||||
[
|
if ($disable === true) {
|
||||||
'border' => '0',
|
$tmp->name = '<i>'.$tmp->name.'</i>';
|
||||||
'class' => 'action_button_img invert_filter',
|
}
|
||||||
'onclick' => 'delete_agent(\''.$tmp->address.'\',\''.$tmp->name.'\')',
|
|
||||||
]
|
if ($delete === true) {
|
||||||
);
|
$tmp->name = '<del>'.$tmp->name.'</del>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$id_agente = (isset($tmp->id_agente) === true) ? $tmp->id_agente : 0;
|
||||||
|
|
||||||
|
$tmp->actions = '';
|
||||||
|
|
||||||
|
if ($delete === false) {
|
||||||
|
$tmp->actions .= html_print_image(
|
||||||
|
($disable === true) ? 'images/lightbulb_off.png' : 'images/lightbulb.png',
|
||||||
|
true,
|
||||||
|
[
|
||||||
|
'border' => '0',
|
||||||
|
'class' => 'action_button_img mrgn_lft_05em invert_filter',
|
||||||
|
'onclick' => 'disable_agent(\''.$tmp->address.'\',\''.strip_tags($tmp->name).'\',\''.(int) $disable.'\',\''.$id_agente.'\')',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($disable === false) {
|
||||||
|
$tmp->actions .= html_print_image(
|
||||||
|
($delete === true) ? 'images/add.png' : 'images/cross.png',
|
||||||
|
true,
|
||||||
|
[
|
||||||
|
'border' => '0',
|
||||||
|
'class' => 'action_button_img mrgn_lft_05em invert_filter',
|
||||||
|
'onclick' => 'delete_agent(\''.$tmp->address.'\',\''.strip_tags($tmp->name).'\',\''.(int) $delete.'\',\''.$id_agente.'\')',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$carry[] = $tmp;
|
$carry[] = $tmp;
|
||||||
return $carry;
|
return $carry;
|
||||||
|
@ -274,8 +390,13 @@ class SatelliteAgent extends HTML
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array_slice($data, $start, $length, true);
|
if (empty($data) === true) {
|
||||||
$total = count($data);
|
$total = 0;
|
||||||
|
$data = [];
|
||||||
|
} else {
|
||||||
|
$total = count($data);
|
||||||
|
$data = array_slice($data, $start, $length, false);
|
||||||
|
}
|
||||||
|
|
||||||
echo json_encode(
|
echo json_encode(
|
||||||
[
|
[
|
||||||
|
@ -392,6 +513,16 @@ class SatelliteAgent extends HTML
|
||||||
$values['address'] = get_parameter('address');
|
$values['address'] = get_parameter('address');
|
||||||
$values['name'] = get_parameter('name');
|
$values['name'] = get_parameter('name');
|
||||||
|
|
||||||
|
if ($this->checkAddressExists($values['address']) === true) {
|
||||||
|
$this->ajaxMsg('error', __('Error saving agent. The address already exists'));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->checkNameExists($values['name']) === true) {
|
||||||
|
$this->ajaxMsg('error', __('Error saving agent. The Name already exists'));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->parseSatelliteConf('save', $values) === false) {
|
if ($this->parseSatelliteConf('save', $values) === false) {
|
||||||
$this->ajaxMsg('error', __('Error saving agent'));
|
$this->ajaxMsg('error', __('Error saving agent'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -412,11 +543,70 @@ class SatelliteAgent extends HTML
|
||||||
{
|
{
|
||||||
$values['address'] = get_parameter('address', '');
|
$values['address'] = get_parameter('address', '');
|
||||||
$values['name'] = get_parameter('name', '');
|
$values['name'] = get_parameter('name', '');
|
||||||
|
$values['delete'] = get_parameter('delete', '');
|
||||||
|
$values['id'] = get_parameter('id', 0);
|
||||||
|
|
||||||
|
if ((bool) $values['id'] === true) {
|
||||||
|
db_process_sql_update(
|
||||||
|
'tagente',
|
||||||
|
[
|
||||||
|
'disabled' => ($values['delete'] === '0') ? 1 : 0,
|
||||||
|
'modo' => ($values['delete'] === '0') ? 2 : 1,
|
||||||
|
],
|
||||||
|
['id_agente' => (int) $values['id']]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->parseSatelliteConf('delete', $values) === false) {
|
if ($this->parseSatelliteConf('delete', $values) === false) {
|
||||||
$this->ajaxMsg('error', __('Error saving agent'));
|
$this->ajaxMsg('error', ($values['delete'] === '0') ? __('Error delete agent') : __('Error add agent'));
|
||||||
} else {
|
} else {
|
||||||
$this->ajaxMsg('result', _('Host '.$values['addres'].' added.'));
|
$this->ajaxMsg(
|
||||||
|
'result',
|
||||||
|
($values['delete'] === '0')
|
||||||
|
? _('Host '.$values['address'].' deleted.')
|
||||||
|
: _('Host '.$values['address'].' added.'),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable agent from satellite conf.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function disableAgent()
|
||||||
|
{
|
||||||
|
$values['address'] = get_parameter('address', '');
|
||||||
|
$values['name'] = get_parameter('name', '');
|
||||||
|
$values['disable'] = get_parameter('disable', '');
|
||||||
|
$values['id'] = get_parameter('id', 0);
|
||||||
|
|
||||||
|
if ((bool) $values['id'] === true) {
|
||||||
|
db_process_sql_update(
|
||||||
|
'tagente',
|
||||||
|
['disabled' => ($values['disable'] === '0') ? 1 : 0],
|
||||||
|
['id_agente' => (int) $values['id']]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->parseSatelliteConf('disable', $values) === false) {
|
||||||
|
$this->ajaxMsg(
|
||||||
|
'error',
|
||||||
|
($values['disable'] === '0') ? __('Error disable agent') : __('Error enable agent')
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->ajaxMsg(
|
||||||
|
'result',
|
||||||
|
($values['disable'] === '0')
|
||||||
|
? _('Host '.$values['address'].' disabled.')
|
||||||
|
: _('Host '.$values['address'].' enabled.'),
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
@ -435,29 +625,106 @@ class SatelliteAgent extends HTML
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'save':
|
case 'save':
|
||||||
if (isset($values['address']) === true && empty($values['address']) === false) {
|
if (isset($values['address']) === true && empty($values['address']) === false) {
|
||||||
$string_hosts = 'add_host '.$values['address'].' '.$values['name']."\n";
|
$pos = preg_grep('/^\#INIT ignore_host/', $this->satellite_config);
|
||||||
|
if (empty($pos) === false) {
|
||||||
|
$string_hosts = 'add_host '.$values['address'].' '.$values['name']."\n";
|
||||||
|
|
||||||
// Add host to conf
|
$array1 = array_slice($this->satellite_config, 0, array_key_first($pos));
|
||||||
array_push($this->satellite_config, $string_hosts);
|
$array2 = array_slice($this->satellite_config, array_key_first($pos));
|
||||||
|
// Add host to conf.
|
||||||
|
$array_merge = array_merge($array1, [$string_hosts], $array2);
|
||||||
|
$this->satellite_config = $array_merge;
|
||||||
|
|
||||||
// Check config.
|
// Check config.
|
||||||
if (empty($this->satellite_config)) {
|
if (empty($this->satellite_config)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$conf = implode('', $this->satellite_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
$conf = implode('', $this->satellite_config);
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'disable':
|
||||||
|
if ((bool) $values['disable'] === true) {
|
||||||
|
$pos = preg_grep('/^\#INIT ignore_host/', $this->satellite_config);
|
||||||
|
if (empty($pos) === false) {
|
||||||
|
$string_hosts = 'add_host '.$values['address'].' '.$values['name']."\n";
|
||||||
|
|
||||||
|
$array1 = array_slice($this->satellite_config, 0, array_key_first($pos));
|
||||||
|
$array2 = array_slice($this->satellite_config, array_key_first($pos));
|
||||||
|
// Add host to conf.
|
||||||
|
$array_merge = array_merge($array1, [$string_hosts], $array2);
|
||||||
|
$this->satellite_config = $array_merge;
|
||||||
|
|
||||||
|
// Remove ignore_host.
|
||||||
|
$pattern = io_safe_expreg('ignore_host '.$values['address'].' '.$values['name']);
|
||||||
|
$pos = preg_grep('/'.$pattern.'/', $this->satellite_config);
|
||||||
|
if (empty($pos) === false) {
|
||||||
|
unset($this->satellite_config[array_key_first($pos)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conf = implode('', $this->satellite_config);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$pos = preg_grep('/^\#INIT delete_host/', $this->satellite_config);
|
||||||
|
if (empty($pos) === false) {
|
||||||
|
$string_hosts = 'ignore_host '.$values['address'].' '.$values['name']."\n";
|
||||||
|
|
||||||
|
$array1 = array_slice($this->satellite_config, 0, array_key_first($pos));
|
||||||
|
$array2 = array_slice($this->satellite_config, array_key_first($pos));
|
||||||
|
// Add host to conf.
|
||||||
|
$array_merge = array_merge($array1, [$string_hosts], $array2);
|
||||||
|
$this->satellite_config = $array_merge;
|
||||||
|
|
||||||
|
// Remove add_host.
|
||||||
|
$pattern = io_safe_expreg('add_host '.$values['address'].' '.$values['name']);
|
||||||
|
$pos = preg_grep('/'.$pattern.'/', $this->satellite_config);
|
||||||
|
if (empty($pos) === false) {
|
||||||
|
unset($this->satellite_config[array_key_first($pos)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conf = implode('', $this->satellite_config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'delete':
|
case 'delete':
|
||||||
$conf = implode('', $this->satellite_config);
|
if ((bool) $values['delete'] === true) {
|
||||||
// Find agent to mark for deletion.
|
$pos = preg_grep('/^\#INIT ignore_host/', $this->satellite_config);
|
||||||
$pattern = io_safe_expreg($values['address'].' '.$values['name']);
|
if (empty($pos) === false) {
|
||||||
$re = "/add_host ($pattern)/m";
|
$string_hosts = 'add_host '.$values['address'].' '.$values['name']."\n";
|
||||||
$subst = 'delete_host $1';
|
|
||||||
$conf = preg_replace($re, $subst, $conf);
|
$array1 = array_slice($this->satellite_config, 0, array_key_first($pos));
|
||||||
|
$array2 = array_slice($this->satellite_config, array_key_first($pos));
|
||||||
|
// Add host to conf.
|
||||||
|
$array_merge = array_merge($array1, [$string_hosts], $array2);
|
||||||
|
$this->satellite_config = $array_merge;
|
||||||
|
|
||||||
|
// Remove delete_host.
|
||||||
|
$pattern = io_safe_expreg('delete_host '.$values['address'].' '.$values['name']);
|
||||||
|
$pos = preg_grep('/'.$pattern.'/', $this->satellite_config);
|
||||||
|
unset($this->satellite_config[array_key_first($pos)]);
|
||||||
|
|
||||||
|
$conf = implode('', $this->satellite_config);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Find agent to mark for deletion.
|
||||||
|
$pattern = io_safe_expreg('add_host '.$values['address'].' '.$values['name']);
|
||||||
|
$pos = preg_grep('/'.$pattern.'/', $this->satellite_config);
|
||||||
|
unset($this->satellite_config[array_key_first($pos)]);
|
||||||
|
|
||||||
|
$string_hosts = 'delete_host '.$values['address'].' '.$values['name']."\n";
|
||||||
|
$pos = preg_grep('/delete_host/', $this->satellite_config);
|
||||||
|
$array1 = array_slice($this->satellite_config, 0, array_key_last($pos));
|
||||||
|
$array2 = array_slice($this->satellite_config, (array_key_last($pos) + 1));
|
||||||
|
$array_merge = array_merge($array1, [$string_hosts], $array2);
|
||||||
|
$this->satellite_config = $array_merge;
|
||||||
|
|
||||||
|
$conf = implode('', $this->satellite_config);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -469,11 +736,37 @@ class SatelliteAgent extends HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function checkAddressExists($address)
|
||||||
|
{
|
||||||
|
$pos_address = preg_grep('/.*_host\s('.$address.').*/', $this->satellite_config);
|
||||||
|
|
||||||
|
if (empty($pos_address) === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function checkNameExists($name)
|
||||||
|
{
|
||||||
|
$pos_name = preg_grep('/.*_host.*('.$name.')$/', $this->satellite_config);
|
||||||
|
|
||||||
|
if (empty($pos_name) === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves agent to satellite cofiguration file.
|
* Saves agent to satellite cofiguration file.
|
||||||
*
|
*
|
||||||
* @param array $values
|
* @param string $new_conf Config file.
|
||||||
* @return void
|
*
|
||||||
|
* @return boolean|void
|
||||||
*/
|
*/
|
||||||
private function saveAgent(string $new_conf)
|
private function saveAgent(string $new_conf)
|
||||||
{
|
{
|
||||||
|
@ -483,13 +776,13 @@ class SatelliteAgent extends HTML
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
db_pandora_audit(
|
db_pandora_audit(
|
||||||
AUDIT_LOG_SYSTEM,
|
AUDIT_LOG_SYSTEM,
|
||||||
'Update remote config for server '.$this->satellite_name
|
'Update remote config for server '.$this->satellite_name
|
||||||
);
|
);
|
||||||
|
|
||||||
// Convert to config file encoding.
|
// Convert to config file encoding.
|
||||||
$encoding = config_satellite_get_encoding($new_conf);
|
$encoding = config_satellite_get_encoding($new_conf);
|
||||||
if ($encoding !== false) {
|
if ($encoding !== false) {
|
||||||
$converted_server_config = mb_convert_encoding($new_conf, $encoding, 'UTF-8');
|
$converted_server_config = mb_convert_encoding($new_conf, $encoding, 'UTF-8');
|
||||||
if ($converted_server_config !== false) {
|
if ($converted_server_config !== false) {
|
||||||
|
@ -497,7 +790,7 @@ class SatelliteAgent extends HTML
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get filenames.
|
// Get filenames.
|
||||||
if ($this->satellite_server !== false) {
|
if ($this->satellite_server !== false) {
|
||||||
$files = config_satellite_get_satellite_config_filenames($this->satellite_name);
|
$files = config_satellite_get_satellite_config_filenames($this->satellite_name);
|
||||||
} else {
|
} else {
|
||||||
|
@ -506,16 +799,40 @@ class SatelliteAgent extends HTML
|
||||||
$files['md5'] = $config['remote_config'].'/md5/'.md5($this->satellite_name).'.srv.md5';
|
$files['md5'] = $config['remote_config'].'/md5/'.md5($this->satellite_name).'.srv.md5';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save configuration
|
// Save configuration.
|
||||||
$result = file_put_contents($files['conf'], $new_conf);
|
$result = file_put_contents($files['conf'], $new_conf);
|
||||||
|
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save configuration md5
|
// Save configuration md5.
|
||||||
$result = file_put_contents($files['md5'], md5($new_conf));
|
$result = file_put_contents($files['md5'], md5($new_conf));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates add_host, ignore_host and delete_host blocks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function createBlock()
|
||||||
|
{
|
||||||
|
$init = preg_grep('/^\#INIT/', $this->satellite_config);
|
||||||
|
|
||||||
|
if (empty($init) === true) {
|
||||||
|
$add_host = "#INIT add_host\n";
|
||||||
|
$ignore_host = "#INIT ignore_host\n";
|
||||||
|
$delete_host = "#INIT delete_host\n";
|
||||||
|
|
||||||
|
array_push($this->satellite_config, "\n");
|
||||||
|
array_push($this->satellite_config, $add_host);
|
||||||
|
array_push($this->satellite_config, $ignore_host);
|
||||||
|
array_push($this->satellite_config, $delete_host);
|
||||||
|
|
||||||
|
$conf = implode('', $this->satellite_config);
|
||||||
|
$this->saveAgent($conf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -541,24 +858,26 @@ class SatelliteAgent extends HTML
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function ajaxMsg($type, $msg, $delete=false)
|
private function ajaxMsg($type, $msg, $delete=false, $disable=false)
|
||||||
{
|
{
|
||||||
$msg_err = 'Failed while saving: %s';
|
$msg_err = 'Failed while saving: %s';
|
||||||
$msg_ok = 'Successfully saved agent ';
|
$msg_ok = 'Successfully saved agent ';
|
||||||
|
|
||||||
if ($delete) {
|
if ($delete === true) {
|
||||||
$msg_err = 'Failed while removing: %s';
|
$msg_err = 'Failed while removing: %s';
|
||||||
$msg_ok = 'Successfully deleted ';
|
$msg_ok = 'Successfully deleted ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($disable === true) {
|
||||||
|
$msg_err = 'Failed while disabling: %s';
|
||||||
|
$msg_ok = 'Successfully disabled';
|
||||||
|
}
|
||||||
|
|
||||||
if ($type == 'error') {
|
if ($type == 'error') {
|
||||||
echo json_encode(
|
echo json_encode(
|
||||||
[
|
[
|
||||||
$type => ui_print_error_message(
|
$type => ui_print_error_message(
|
||||||
__(
|
__($msg),
|
||||||
$msg_err,
|
|
||||||
$msg
|
|
||||||
),
|
|
||||||
'',
|
'',
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
|
@ -568,10 +887,7 @@ class SatelliteAgent extends HTML
|
||||||
echo json_encode(
|
echo json_encode(
|
||||||
[
|
[
|
||||||
$type => ui_print_success_message(
|
$type => ui_print_success_message(
|
||||||
__(
|
__($msg),
|
||||||
$msg_ok,
|
|
||||||
$msg
|
|
||||||
),
|
|
||||||
'',
|
'',
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
|
@ -583,6 +899,35 @@ class SatelliteAgent extends HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes duplicate values from a multidimensional array
|
||||||
|
*
|
||||||
|
* @param array $array Input array.
|
||||||
|
* @param array $key Keys.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function uniqueMultidimArray($array, $key)
|
||||||
|
{
|
||||||
|
$temp_array = [];
|
||||||
|
$i = 0;
|
||||||
|
$key_array_name = [];
|
||||||
|
$key_array_address = [];
|
||||||
|
|
||||||
|
foreach ($array as $val) {
|
||||||
|
if (!in_array($val[$key[0]], $key_array_name) && !in_array($val[$key[1]], $key_array_address)) {
|
||||||
|
$key_array_name[$i] = $val[$key[0]];
|
||||||
|
$key_array_address[$i] = $val[$key[1]];
|
||||||
|
$temp_array[$i] = $val;
|
||||||
|
}
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $temp_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load Javascript code.
|
* Load Javascript code.
|
||||||
*
|
*
|
||||||
|
@ -707,11 +1052,11 @@ class SatelliteAgent extends HTML
|
||||||
/**
|
/**
|
||||||
* Delete selected agent
|
* Delete selected agent
|
||||||
*/
|
*/
|
||||||
function delete_agent(address, name) {
|
function delete_agent(address, name, deleted, id_agente) {
|
||||||
$('#aux').empty();
|
$('#aux').empty();
|
||||||
$('#aux').text('<?php echo __('Are you sure?'); ?>');
|
$('#aux').text('<?php echo __('Are you sure?'); ?>');
|
||||||
$('#aux').dialog({
|
$('#aux').dialog({
|
||||||
title: '<?php echo __('Delete'); ?> ' + address,
|
title: (deleted == 0) ? '<?php echo __('Delete'); ?> '+address : '<?php echo __('Add'); ?>'+address,
|
||||||
buttons: [
|
buttons: [
|
||||||
{
|
{
|
||||||
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel',
|
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel',
|
||||||
|
@ -723,7 +1068,7 @@ class SatelliteAgent extends HTML
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'Delete',
|
text: (deleted == 0) ? 'Delete' : 'Add',
|
||||||
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next',
|
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next',
|
||||||
click: function(e) {
|
click: function(e) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -734,6 +1079,56 @@ class SatelliteAgent extends HTML
|
||||||
method: 'deleteAgent',
|
method: 'deleteAgent',
|
||||||
address: address,
|
address: address,
|
||||||
name: name,
|
name: name,
|
||||||
|
id: id_agente,
|
||||||
|
delete: deleted,
|
||||||
|
server_remote: <?php echo $this->satellite_server; ?>,
|
||||||
|
},
|
||||||
|
datatype: "json",
|
||||||
|
success: function (data) {
|
||||||
|
showMsg(data);
|
||||||
|
},
|
||||||
|
error: function(e) {
|
||||||
|
showMsg(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable selected agent
|
||||||
|
*/
|
||||||
|
function disable_agent(address, name, disabled, id_agente) {
|
||||||
|
$('#aux').empty();
|
||||||
|
$('#aux').text('<?php echo __('Are you sure?'); ?>');
|
||||||
|
$('#aux').dialog({
|
||||||
|
title: (disabled == 0) ? '<?php echo __('Disable'); ?>'+address : '<?php echo __('Enable'); ?>'+address,
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel',
|
||||||
|
text: '<?php echo __('Cancel'); ?>',
|
||||||
|
click: function(e) {
|
||||||
|
$(this).dialog('close');
|
||||||
|
cleanupDOM();
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: (disabled == 0) ? 'Disable' : 'Enable',
|
||||||
|
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next',
|
||||||
|
click: function(e) {
|
||||||
|
$.ajax({
|
||||||
|
method: 'post',
|
||||||
|
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
|
||||||
|
data: {
|
||||||
|
page: 'enterprise/godmode/servers/agents_satellite',
|
||||||
|
method: 'disableAgent',
|
||||||
|
address: address,
|
||||||
|
disable: disabled,
|
||||||
|
id: id_agente,
|
||||||
|
name: name,
|
||||||
server_remote: <?php echo $this->satellite_server; ?>,
|
server_remote: <?php echo $this->satellite_server; ?>,
|
||||||
},
|
},
|
||||||
datatype: "json",
|
datatype: "json",
|
||||||
|
|
Loading…
Reference in New Issue