Merge branch 'ent-9334-mejorar-seccion-de-administrar-host-para-la-configuracion-remota-del-satellite' into 'develop'

Ent 9334 mejorar seccion de administrar host para la configuracion remota del satellite

See merge request artica/pandorafms!5117
This commit is contained in:
Daniel Rodriguez 2022-09-30 09:41:57 +00:00
commit 74e291696a
2 changed files with 673 additions and 84 deletions

View File

@ -238,6 +238,17 @@ foreach ($servers as $server) {
$data[8] .= '</a>';
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] .= html_print_image(
'images/remote_configuration.png',

View File

@ -56,6 +56,7 @@ class SatelliteAgent extends HTML
'draw',
'addAgent',
'deleteAgent',
'disableAgent',
'loadModal',
];
@ -97,7 +98,6 @@ class SatelliteAgent extends HTML
$this->satellite_name = servers_get_name($this->satellite_server);
$this->satellite_config = (array) config_satellite_get_config_file($this->satellite_name);
}
}
@ -108,27 +108,53 @@ class SatelliteAgent extends HTML
*/
public function run()
{
global $config;
// Javascript.
ui_require_jquery_file('pandora');
// CSS.
ui_require_css_file('wizard');
ui_require_css_file('discovery');
global $config;
$this->createBlock();
// Datatables list.
try {
$checkbox_all = html_print_checkbox(
'all_validate_box',
1,
false,
true
);
$columns = [
[
'text' => 'm',
'extra' => $checkbox_all,
'class' => 'mw60px',
],
'name',
'address',
'actions',
];
$column_names = [
[
'text' => 'm',
'extra' => $checkbox_all,
'class' => 'w20px no-text-imp',
],
__('Agent Name'),
__('IP Adrress'),
__('Actions'),
];
$show_agents = [
0 => __('Everyone'),
1 => __('Only disabled'),
2 => __('Only deleted'),
3 => __('Only added'),
];
$this->tableId = 'satellite_agents';
if (is_metaconsole() === true) {
@ -154,6 +180,7 @@ class SatelliteAgent extends HTML
0,
1,
2,
3,
],
'search_button_class' => 'sub filter float-right',
'form' => [
@ -167,7 +194,15 @@ class SatelliteAgent extends HTML
'name' => 'filter_search',
'size' => 12,
],
[
'label' => __('Show agents'),
'type' => 'select',
'id' => 'filter_agents',
'name' => 'filter_agents',
'fields' => $show_agents,
'return' => true,
'selected' => 0,
],
],
],
]
@ -186,7 +221,34 @@ class SatelliteAgent extends HTML
$msg = '<div id="msg" class="invisible"></div>';
$aux = '<div id="aux" class="invisible"></div>';
echo $modal.$msg.$aux;
echo $modal.$msg.$aux;
echo '<div id="satellite_actions" class="action-buttons" style="width: 100%">';
html_print_select(
[
'0' => 'Disable / Enable selected agents',
'1' => 'Delete / Create selected agents',
],
'satellite_action',
'',
'',
'',
0,
false,
false,
false
);
html_print_submit_button(
__('Execute action'),
'submit_satellite_action',
false,
'class="sub next"'
);
echo '</div>';
echo '</br></br>';
// Create button.
echo '<div class="w100p flex-content-right">';
@ -200,7 +262,6 @@ class SatelliteAgent extends HTML
echo '</div>';
// Load own javascript file.
echo $this->loadJS();
}
@ -212,8 +273,7 @@ class SatelliteAgent extends HTML
public function draw()
{
global $config;
// Initialice filter.
$filter = '1=1';
// Init data.
$data = [];
// Count of total records.
@ -228,8 +288,24 @@ class SatelliteAgent extends HTML
ob_start();
$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, ""),
IF(modo = 1, INSERT("ignore_host", 0 , 0, ""), INSERT("delete_host", 0, 0, ""))) AS type
FROM tagente WHERE `satellite_server` = %d',
$this->satellite_server
)
);
if (empty($agents_db) === false) {
$data = $agents_db;
}
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) {
$agent['address'] = $matches[1][0];
@ -239,17 +315,74 @@ class SatelliteAgent extends HTML
$agent['name'] = $matches[2][0];
}
if (empty($filters['filter_search']) === false) {
if (empty(preg_grep('/'.$filters['filter_search'].'?/mi', array_values($agent))) === true) {
continue;
}
$agent['type'] = 'add_host';
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);
}
}
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,
function ($carry, $item) {
@ -258,14 +391,50 @@ class SatelliteAgent extends HTML
// of objects, making a post-process of certain fields.
$tmp = (object) $item;
$tmp->actions .= html_print_image(
'images/cross.png',
true,
[
'border' => '0',
'class' => 'action_button_img invert_filter',
'onclick' => 'delete_agent(\''.$tmp->address.'\',\''.$tmp->name.'\')',
]
$disable = ($tmp->type === 'ignore_host');
$delete = ($tmp->type === 'delete_host');
if ($disable === true) {
$tmp->name = '<i class="italic_a">'.$tmp->name.'</i>';
}
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.'\')',
]
);
}
$tmp->m = html_print_checkbox(
'check_'.strip_tags($tmp->name),
$tmp->address.','.strip_tags($tmp->name).','.(int) $delete.','.(int) $disable.','.$id_agente,
false,
true
);
$carry[] = $tmp;
@ -274,8 +443,13 @@ class SatelliteAgent extends HTML
);
}
$data = array_slice($data, $start, $length, true);
$total = count($data);
if (empty($data) === true) {
$total = 0;
$data = [];
} else {
$total = count($data);
$data = array_slice($data, $start, $length, false);
}
echo json_encode(
[
@ -333,12 +507,6 @@ class SatelliteAgent extends HTML
$values = [];
}
$return_all_group = false;
if (users_can_manage_group_all('AR') === true) {
$return_all_group = true;
}
$form = [
'action' => '#',
'id' => 'modal_form',
@ -392,6 +560,16 @@ class SatelliteAgent extends HTML
$values['address'] = get_parameter('address');
$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) {
$this->ajaxMsg('error', __('Error saving agent'));
} else {
@ -412,11 +590,82 @@ class SatelliteAgent extends HTML
{
$values['address'] = get_parameter('address', '');
$values['name'] = get_parameter('name', '');
$values['delete'] = get_parameter('delete', '');
$values['id'] = get_parameter('id', 0);
$no_msg = (bool) get_parameter('no_msg', 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) {
$this->ajaxMsg('error', __('Error saving agent'));
if ($no_msg === false) {
$this->ajaxMsg('error', ($values['delete'] === '0') ? __('Error delete agent') : __('Error add agent'));
}
} else {
$this->ajaxMsg('result', _('Host '.$values['addres'].' added.'));
if ($no_msg === false) {
$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);
$no_msg = (bool) get_parameter('no_msg', 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) {
if ($no_msg === false) {
$this->ajaxMsg(
'error',
($values['disable'] === '0') ? __('Error disable agent') : __('Error enable agent')
);
}
} else {
if ($no_msg === false) {
$this->ajaxMsg(
'result',
($values['disable'] === '0')
? _('Host '.$values['address'].' disabled.')
: _('Host '.$values['address'].' enabled.'),
false,
true
);
}
}
exit;
@ -426,38 +675,173 @@ class SatelliteAgent extends HTML
/**
* Parse satellite configuration .
*
* @param string $action Action to perform (save, delete).
* @param array $values.
* @return void
* @param string $action Action to perform (save, delete).
* @param array $values Values.
*
* @return boolean
*/
private function parseSatelliteConf(string $action, array $values)
{
switch ($action) {
case 'save':
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
array_push($this->satellite_config, $string_hosts);
$key_pos = 0;
foreach ($pos as $key => $value) {
$key_pos = $key;
break;
}
// Check config.
if (empty($this->satellite_config)) {
return false;
$array1 = array_slice($this->satellite_config, 0, $key_pos);
$array2 = array_slice($this->satellite_config, $key_pos);
// Add host to conf.
$array_merge = array_merge($array1, [$string_hosts], $array2);
$this->satellite_config = $array_merge;
// Check config.
if (empty($this->satellite_config)) {
return false;
}
$conf = implode('', $this->satellite_config);
}
$conf = implode('', $this->satellite_config);
} else {
return false;
}
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";
$key_pos = 0;
foreach ($pos as $key => $value) {
$key_pos = $key;
break;
}
$array1 = array_slice($this->satellite_config, 0, $key_pos);
$array2 = array_slice($this->satellite_config, $key_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);
$key_pos = 0;
foreach ($pos as $key => $value) {
$key_pos = $key;
break;
}
if (empty($pos) === false) {
unset($this->satellite_config[$key_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";
$key_pos = 0;
foreach ($pos as $key => $value) {
$key_pos = $key;
break;
}
$array1 = array_slice($this->satellite_config, 0, $key_pos);
$array2 = array_slice($this->satellite_config, $key_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);
$key_pos = 0;
foreach ($pos as $key => $value) {
$key_pos = $key;
break;
}
if (empty($pos) === false) {
unset($this->satellite_config[$key_pos]);
}
$conf = implode('', $this->satellite_config);
}
}
break;
case 'delete':
$conf = implode('', $this->satellite_config);
// Find agent to mark for deletion.
$pattern = io_safe_expreg($values['address'].' '.$values['name']);
$re = "/add_host ($pattern)/m";
$subst = 'delete_host $1';
$conf = preg_replace($re, $subst, $conf);
if ((bool) $values['delete'] === true) {
$pos = preg_grep('/^\#INIT ignore_host/', $this->satellite_config);
if (empty($pos) === false) {
$string_hosts = 'add_host '.$values['address'].' '.$values['name']."\n";
$key_pos = 0;
foreach ($pos as $key => $value) {
$key_pos = $key;
break;
}
$array1 = array_slice($this->satellite_config, 0, $key_pos);
$array2 = array_slice($this->satellite_config, $key_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);
$key_pos = 0;
foreach ($pos as $key => $value) {
$key_pos = $key;
break;
}
unset($this->satellite_config[$key_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);
if (empty($pos) === false) {
$key_pos = 0;
foreach ($pos as $key => $value) {
$key_pos = $key;
break;
}
unset($this->satellite_config[$key_pos]);
}
$string_hosts = 'delete_host '.$values['address'].' '.$values['name']."\n";
$pos = preg_grep('/delete_host/', $this->satellite_config);
if (empty($pos) === false) {
$key_pos = array_keys($pos)[(count($pos) - 1)];
$array1 = array_slice($this->satellite_config, 0, ($key_pos + 1));
$array2 = array_slice($this->satellite_config, ($key_pos + 1));
$array_merge = array_merge($array1, [$string_hosts], $array2);
$this->satellite_config = $array_merge;
}
$conf = implode('', $this->satellite_config);
}
break;
default:
@ -469,11 +853,37 @@ class SatelliteAgent extends HTML
}
public function checkAddressExists($address)
{
$pos_address = preg_grep('/.*_host\s('.$address.')\s.*/', $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.
*
* @param array $values
* @return void
* @param string $new_conf Config file.
*
* @return boolean|void
*/
private function saveAgent(string $new_conf)
{
@ -483,13 +893,13 @@ class SatelliteAgent extends HTML
return false;
}
db_pandora_audit(
AUDIT_LOG_SYSTEM,
'Update remote config for server '.$this->satellite_name
);
db_pandora_audit(
AUDIT_LOG_SYSTEM,
'Update remote config for server '.$this->satellite_name
);
// Convert to config file encoding.
$encoding = config_satellite_get_encoding($new_conf);
// Convert to config file encoding.
$encoding = config_satellite_get_encoding($new_conf);
if ($encoding !== false) {
$converted_server_config = mb_convert_encoding($new_conf, $encoding, 'UTF-8');
if ($converted_server_config !== false) {
@ -497,7 +907,7 @@ class SatelliteAgent extends HTML
}
}
// Get filenames.
// Get filenames.
if ($this->satellite_server !== false) {
$files = config_satellite_get_satellite_config_filenames($this->satellite_name);
} else {
@ -506,16 +916,40 @@ class SatelliteAgent extends HTML
$files['md5'] = $config['remote_config'].'/md5/'.md5($this->satellite_name).'.srv.md5';
}
// Save configuration
$result = file_put_contents($files['conf'], $new_conf);
// Save configuration.
$result = file_put_contents($files['conf'], $new_conf);
if ($result === false) {
return false;
}
// Save configuration md5
$result = file_put_contents($files['md5'], md5($new_conf));
// Save configuration md5.
$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);
}
}
@ -532,33 +966,36 @@ class SatelliteAgent extends HTML
}
/**
* Minor function to dump json message as ajax response.
*
* @param string $type Type: result || error.
* @param string $msg Message.
* @param boolean $delete Deletion messages.
*
* @return void
*/
private function ajaxMsg($type, $msg, $delete=false)
/**
* Minor function to dump json message as ajax response.
*
* @param string $type Type: result || error.
* @param string $msg Message.
* @param boolean $delete Deletion messages.
* @param boolean $disable Disable messages.
*
* @return void
*/
private function ajaxMsg($type, $msg, $delete=false, $disable=false)
{
$msg_err = 'Failed while saving: %s';
$msg_ok = 'Successfully saved agent ';
if ($delete) {
if ($delete === true) {
$msg_err = 'Failed while removing: %s';
$msg_ok = 'Successfully deleted ';
}
if ($disable === true) {
$msg_err = 'Failed while disabling: %s';
$msg_ok = 'Successfully disabled';
}
if ($type == 'error') {
echo json_encode(
[
$type => ui_print_error_message(
__(
$msg_err,
$msg
),
__($msg),
'',
true
),
@ -568,10 +1005,7 @@ class SatelliteAgent extends HTML
echo json_encode(
[
$type => ui_print_success_message(
__(
$msg_ok,
$msg
),
__($msg),
'',
true
),
@ -583,6 +1017,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.
*
@ -707,11 +1170,11 @@ class SatelliteAgent extends HTML
/**
* Delete selected agent
*/
function delete_agent(address, name) {
function delete_agent(address, name, deleted, id_agente) {
$('#aux').empty();
$('#aux').text('<?php echo __('Are you sure?'); ?>');
$('#aux').dialog({
title: '<?php echo __('Delete'); ?> ' + address,
title: (deleted == 0) ? '<?php echo __('Delete'); ?> '+address : '<?php echo __('Add'); ?>'+address,
buttons: [
{
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel',
@ -723,7 +1186,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',
click: function(e) {
$.ajax({
@ -734,6 +1197,56 @@ class SatelliteAgent extends HTML
method: 'deleteAgent',
address: address,
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; ?>,
},
datatype: "json",
@ -752,12 +1265,77 @@ class SatelliteAgent extends HTML
$(document).ready(function() {
$("#submit-create").on('click', function(){
$("#submit-create").on('click', function() {
show_form();
});
$("#checkbox-all_validate_box").click(function() {
const check = $("#checkbox-all_validate_box").is(":checked");
$('input[name*=check_]').prop('checked', check);
});
$('#submit-submit_satellite_action').click(function() {
const checks = $('input[name*=check_]:checked');
const action = $('#satellite_action').val();
$.each(checks, function(i, val) {
const params = val.value.split(",");
if (action === '0') {
if (params[2] === '0') {
$.ajax({
method: 'post',
async: false,
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
data: {
page: 'enterprise/godmode/servers/agents_satellite',
method: 'disableAgent',
address: params[0],
disable: params[3],
id: params[4],
name: params[1],
no_msg: 1,
server_remote: <?php echo $this->satellite_server; ?>,
},
datatype: "json",
success: function (data) {
},
error: function(e) {
console.error(e);
}
});
}
} else {
if (params[3] === '0') {
$.ajax({
method: 'post',
async: false,
url: '<?php echo ui_get_full_url('ajax.php', false, false, false); ?>',
data: {
page: 'enterprise/godmode/servers/agents_satellite',
method: 'deleteAgent',
address: params[0],
name: params[1],
id: params[4],
delete: params[2],
no_msg: 1,
server_remote: <?php echo $this->satellite_server; ?>,
},
datatype: "json",
success: function (data) {
},
error: function(e) {
console.error(e);
}
});
}
}
});
var dt_satellite_agents = $("#satellite_agents").DataTable();
dt_satellite_agents.draw();
});
});
</script>
<?php
// EOF Javascript content.