#9819 New section configuration sound event
This commit is contained in:
parent
3f000f403a
commit
34fede2ce1
|
@ -0,0 +1,10 @@
|
|||
START TRANSACTION;
|
||||
|
||||
CREATE TABLE `tevent_sound` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`name` TEXT NULL,
|
||||
`sound` TEXT NULL,
|
||||
`active` TINYINT NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
COMMIT;
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Audit log View.
|
||||
*
|
||||
* @category Audit log
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2022 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Begin.
|
||||
global $config;
|
||||
|
||||
require_once $config['homedir'].'/include/class/EventSound.class.php';
|
||||
|
||||
$ajaxPage = 'godmode/events/configuration_sounds';
|
||||
|
||||
// Control call flow.
|
||||
try {
|
||||
// User access and validation is being processed on class constructor.
|
||||
$controller = new EventSound($ajaxPage);
|
||||
} catch (Exception $e) {
|
||||
if ((bool) is_ajax() === true) {
|
||||
echo json_encode(['error' => '[EventSound]'.$e->getMessage() ]);
|
||||
exit;
|
||||
} else {
|
||||
echo '[EventSound]'.$e->getMessage();
|
||||
}
|
||||
|
||||
// Stop this execution, but continue 'globally'.
|
||||
return;
|
||||
}
|
||||
|
||||
// AJAX controller.
|
||||
if ((bool) is_ajax() === true) {
|
||||
$method = get_parameter('method');
|
||||
|
||||
if (method_exists($controller, $method) === true) {
|
||||
if ($controller->ajaxMethod($method) === true) {
|
||||
$controller->{$method}();
|
||||
} else {
|
||||
$controller->error('Unavailable method.');
|
||||
}
|
||||
} else {
|
||||
$controller->error('Method not found. ['.$method.']');
|
||||
}
|
||||
|
||||
// Stop any execution.
|
||||
exit;
|
||||
} else {
|
||||
// Run.
|
||||
$controller->run();
|
||||
}
|
|
@ -2348,6 +2348,11 @@ if ($drawConsoleSound === true) {
|
|||
'Star_Trek_emergency_simulation.wav' => 'StarTrek emergency simulation',
|
||||
];
|
||||
|
||||
$eventsounds = mysql_db_get_all_rows_sql('SELECT * FROM tevent_sound WHERE active = 1');
|
||||
foreach ($eventsounds as $key => $row) {
|
||||
$sounds[$row['sound']] = $row['name'];
|
||||
}
|
||||
|
||||
$inputs[] = [
|
||||
'class' => 'test-sounds',
|
||||
'direct' => 1,
|
||||
|
|
|
@ -0,0 +1,495 @@
|
|||
<?php
|
||||
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
/**
|
||||
* Controller for Audit Logs
|
||||
*
|
||||
* @category Controller
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2022 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
// Begin.
|
||||
global $config;
|
||||
|
||||
// Necessary classes for extends.
|
||||
require_once $config['homedir'].'/include/class/HTML.class.php';
|
||||
enterprise_include_once('godmode/admin_access_logs.php');
|
||||
|
||||
/**
|
||||
* Class EventSound
|
||||
*/
|
||||
class EventSound extends HTML
|
||||
{
|
||||
|
||||
/**
|
||||
* Allowed methods to be called using AJAX request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $AJAXMethods = ['draw'];
|
||||
|
||||
/**
|
||||
* Ajax page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $ajaxController;
|
||||
|
||||
/**
|
||||
* Table id.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $tableId;
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $ajaxController Ajax controller.
|
||||
*/
|
||||
public function __construct(string $ajaxController)
|
||||
{
|
||||
global $config;
|
||||
|
||||
check_login();
|
||||
|
||||
if (check_acl($config['id_user'], 0, 'PM') === false
|
||||
&& is_user_admin($config['id_user']) === true
|
||||
) {
|
||||
db_pandora_audit(
|
||||
AUDIT_LOG_ACL_VIOLATION,
|
||||
'Trying to access Event Sound'
|
||||
);
|
||||
include 'general/noaccess.php';
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the ajax controller.
|
||||
$this->ajaxController = $ajaxController;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
global $config;
|
||||
$tab = get_parameter('tab', '');
|
||||
$action = get_parameter('action', '');
|
||||
$message_ok = 0;
|
||||
$error_msg = __('Name already exist');
|
||||
$ok_msg = __('Successfully created');
|
||||
|
||||
if ($action == 'create') {
|
||||
$name = get_parameter('name', '');
|
||||
$sound = get_parameter('file', '');
|
||||
|
||||
$exist = db_get_all_rows_sql(sprintf('SELECT * FROM tevent_sound WHERE name = "%s"', $name));
|
||||
|
||||
if ($exist === false) {
|
||||
$uploadMaxFilesize = config_return_in_bytes(ini_get('upload_max_filesize'));
|
||||
|
||||
$upload_status = get_file_upload_status('file');
|
||||
$upload_result = translate_file_upload_status($upload_status);
|
||||
if ($uploadMaxFilesize < $sound['size']) {
|
||||
$error_msg = __('File is too large to upload. Check the configuration in php.ini.');
|
||||
} else {
|
||||
$pathname = $config['homedir'].'/include/sounds/';
|
||||
$nameSound = str_replace(' ', '_', $_FILES['file']['name']);
|
||||
$target_file = $pathname.basename($nameSound);
|
||||
|
||||
if (file_exists($target_file)) {
|
||||
$error_msg = __('Sound already are exists.');
|
||||
} else {
|
||||
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file)) {
|
||||
$insert = db_process_sql_insert(
|
||||
'tevent_sound',
|
||||
[
|
||||
'name' => $name,
|
||||
'sound' => $nameSound,
|
||||
]
|
||||
);
|
||||
$ok_msg = __('Successfully created');
|
||||
} else {
|
||||
$error_msg = __('Fail uploading the sound');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($insert > 0) {
|
||||
$tab = '';
|
||||
$message_ok = 1;
|
||||
}
|
||||
} else {
|
||||
$error_msg = __('Sound already are exists');
|
||||
}
|
||||
} else if ($action == 'change_action') {
|
||||
$id = get_parameter('id', '');
|
||||
$new_action = (int) get_parameter('set_action', '1');
|
||||
|
||||
$exist = db_get_all_rows_sql(sprintf('SELECT * FROM tevent_sound WHERE id = "%s"', $id));
|
||||
|
||||
if ($exist !== false) {
|
||||
$result = db_process_sql_update(
|
||||
'tevent_sound',
|
||||
['active' => $new_action],
|
||||
['id' => $id]
|
||||
);
|
||||
if (false === (bool) $result) {
|
||||
$error_msg = __('Error on update status');
|
||||
} else {
|
||||
$message_ok = 1;
|
||||
}
|
||||
} else {
|
||||
$error_msg = __('Sound not exist');
|
||||
}
|
||||
}
|
||||
|
||||
if ($action) {
|
||||
ui_print_result_message(
|
||||
$message_ok,
|
||||
$ok_msg,
|
||||
$error_msg,
|
||||
'',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
$base_url = 'index.php?sec=eventos&sec2=godmode/events/configuration_sounds';
|
||||
$setup_url = $base_url.'&tab=add';
|
||||
$tabs = [
|
||||
'list' => [
|
||||
'text' => '<a href="'.$base_url.'">'.html_print_image(
|
||||
'images/eye_show.png',
|
||||
true,
|
||||
[
|
||||
'title' => __('Sounds'),
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
).'</a>',
|
||||
'active' => (bool) ($tab != 'add'),
|
||||
],
|
||||
'options' => [
|
||||
'text' => '<a href="'.$setup_url.'">'.html_print_image(
|
||||
'images/pen.png',
|
||||
true,
|
||||
[
|
||||
'title' => __('Create'),
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
).'</a>',
|
||||
'active' => (bool) ($tab == 'add'),
|
||||
],
|
||||
];
|
||||
|
||||
if ($tab === 'add') {
|
||||
$helpHeader = '';
|
||||
$titleHeader = __('Add new sound');
|
||||
} else {
|
||||
$helpHeader = 'servers_ha_clusters_tab';
|
||||
$titleHeader = __('Events sound list');
|
||||
}
|
||||
|
||||
// Header.
|
||||
ui_print_standard_header(
|
||||
$titleHeader,
|
||||
'images/gm_servers.png',
|
||||
false,
|
||||
$helpHeader,
|
||||
false,
|
||||
$tabs,
|
||||
[
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('Events'),
|
||||
],
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('Configuration Sounds'),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// Javascript.
|
||||
ui_require_jquery_file('pandora');
|
||||
// CSS.
|
||||
ui_require_css_file('wizard');
|
||||
ui_require_css_file('discovery');
|
||||
|
||||
if ($tab === 'add') {
|
||||
echo '<form method="post" enctype="multipart/form-data" action="index.php?sec=eventos&sec2=godmode/events/configuration_sounds&tab=add&action=create">';
|
||||
$table = new stdClass();
|
||||
$table->width = '100%';
|
||||
|
||||
$table->class = 'databox filters';
|
||||
$table->data = [];
|
||||
$table->data[0][0] = __('Name:');
|
||||
|
||||
$table->data[0][1] = html_print_input_text(
|
||||
'name',
|
||||
'',
|
||||
'',
|
||||
80,
|
||||
100,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$table->data[1][0] = __('WAV Sound');
|
||||
$table->data[1][1] = html_print_input_file('file', true, ['required' => true]);
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
echo '<div class="action-buttons" style="width: '.$table->width.'">';
|
||||
html_print_submit_button(
|
||||
__('Create'),
|
||||
'save_sound',
|
||||
false,
|
||||
'class="sub wand"'
|
||||
);
|
||||
echo '</div>';
|
||||
echo '</form>';
|
||||
|
||||
// Load own javascript file.
|
||||
echo $this->loadJS();
|
||||
} else {
|
||||
// Datatables list.
|
||||
try {
|
||||
$columns = [
|
||||
'name',
|
||||
'sound',
|
||||
[
|
||||
'text' => 'options',
|
||||
'class' => 'action_buttons mw120px',
|
||||
],
|
||||
];
|
||||
|
||||
$column_names = [
|
||||
__('Name'),
|
||||
__('Sound'),
|
||||
__('Options'),
|
||||
];
|
||||
|
||||
$this->tableId = 'event_sounds';
|
||||
|
||||
if (is_metaconsole() === true) {
|
||||
// Only in case of Metaconsole, format the frame.
|
||||
open_meta_frame();
|
||||
}
|
||||
|
||||
// Load datatables user interface.
|
||||
ui_print_datatable(
|
||||
[
|
||||
'id' => $this->tableId,
|
||||
'class' => 'info_table',
|
||||
'style' => 'width: 100%',
|
||||
'columns' => $columns,
|
||||
'column_names' => $column_names,
|
||||
'ajax_url' => $this->ajaxController,
|
||||
'ajax_data' => ['method' => 'draw'],
|
||||
'no_sortable_columns' => [-1],
|
||||
'order' => [
|
||||
'field' => 'id',
|
||||
'direction' => 'asc',
|
||||
],
|
||||
'search_button_class' => 'sub filter',
|
||||
'form' => [
|
||||
'inputs' => [
|
||||
[
|
||||
'label' => __('Free search').ui_print_help_tip(__('Search filter by Name or Sound fields content'), true),
|
||||
'type' => 'text',
|
||||
'class' => 'w200px',
|
||||
'id' => 'filter_text',
|
||||
'name' => 'filter_text',
|
||||
],
|
||||
[
|
||||
'label' => __('Active'),
|
||||
'type' => 'select',
|
||||
'fields' => [
|
||||
'' => __('All'),
|
||||
'0' => __('No'),
|
||||
'1' => __('Yes'),
|
||||
],
|
||||
'class' => 'w100px',
|
||||
'id' => 'active',
|
||||
'name' => 'active',
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
if (is_metaconsole() === true) {
|
||||
// Close the frame.
|
||||
close_meta_frame();
|
||||
}
|
||||
|
||||
// Load own javascript file.
|
||||
echo $this->loadJS();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the data for draw the table.
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
public function draw()
|
||||
{
|
||||
global $config;
|
||||
// Initialice filter.
|
||||
$filter = '1=1';
|
||||
// Init data.
|
||||
$data = [];
|
||||
// Count of total records.
|
||||
$count = 0;
|
||||
// Catch post parameters.
|
||||
$start = get_parameter('start', 0);
|
||||
$length = get_parameter('length', $config['block_size']);
|
||||
// There is a limit of (2^32)^2 (18446744073709551615) rows in a MyISAM table, show for show all use max nrows.
|
||||
$length = ($length != '-1') ? $length : '18446744073709551615';
|
||||
$order = get_datatable_order();
|
||||
$filters = get_parameter('filter', []);
|
||||
$filterText = $filters['filter_text'];
|
||||
$filterActive = $filters['active'];
|
||||
|
||||
if (empty($filterText) === false) {
|
||||
$filter .= sprintf(
|
||||
" AND (name LIKE '%%%s%%' OR sound LIKE '%%%s%%')",
|
||||
$filterText,
|
||||
$filterText
|
||||
);
|
||||
}
|
||||
|
||||
if (in_array($filterActive, [0, 1])) {
|
||||
$filter .= sprintf(
|
||||
' AND active = %s',
|
||||
$filterActive,
|
||||
);
|
||||
}
|
||||
|
||||
$count = (int) db_get_value_sql(sprintf('SELECT COUNT(*) as "total" FROM tevent_sound WHERE %s', $filter));
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT *
|
||||
FROM tevent_sound
|
||||
WHERE %s
|
||||
ORDER BY %s
|
||||
LIMIT %d, %d',
|
||||
$filter,
|
||||
$order,
|
||||
$start,
|
||||
$length
|
||||
);
|
||||
$data = db_get_all_rows_sql($sql);
|
||||
|
||||
foreach ($data as $key => $row) {
|
||||
if ($row['active'] === '1') {
|
||||
$img = 'images/lightbulb.png';
|
||||
$action = __('Disable sound');
|
||||
$new_action = 0;
|
||||
} else {
|
||||
$img = 'images/lightbulb_off.png';
|
||||
$action = __('Enable sound');
|
||||
$new_action = 1;
|
||||
}
|
||||
|
||||
$options = '<a href="index.php?sec=eventos&sec2=godmode/events/configuration_sounds';
|
||||
$options .= '&action=change_action&id='.$row['id'].'&set_action='.$new_action.'">';
|
||||
$options .= html_print_image(
|
||||
$img,
|
||||
true,
|
||||
[
|
||||
'title' => $action,
|
||||
'class' => 'invert_filter',
|
||||
]
|
||||
);
|
||||
$options .= '</a>';
|
||||
|
||||
$data[$key]['options'] = $options;
|
||||
}
|
||||
|
||||
echo json_encode(
|
||||
[
|
||||
'data' => $data,
|
||||
'recordsTotal' => $count,
|
||||
'recordsFiltered' => $count,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if target method is available to be called using AJAX.
|
||||
*
|
||||
* @param string $method Target method.
|
||||
*
|
||||
* @return boolean True allowed, false not.
|
||||
*/
|
||||
public function ajaxMethod(string $method)
|
||||
{
|
||||
return in_array($method, $this->AJAXMethods);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load Javascript code.
|
||||
*
|
||||
* @return string.
|
||||
*/
|
||||
public function loadJS()
|
||||
{
|
||||
// Nothing for this moment.
|
||||
ob_start();
|
||||
|
||||
// Javascript content.
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('#file-sound').change(function(){
|
||||
var ext = $('#file-sound').val().split('.').pop().toLowerCase();
|
||||
if($.inArray(ext, ['wav']) == -1) {
|
||||
alert('<?php __('invalid extension'); ?>');
|
||||
$('#file-sound').val('');
|
||||
}
|
||||
});
|
||||
|
||||
$('#submit-save_sound').click(function(){
|
||||
console.log("a");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
// EOF Javascript content.
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -252,6 +252,11 @@ $sounds = [
|
|||
'Star_Trek_emergency_simulation.wav' => 'StarTrek emergency simulation',
|
||||
];
|
||||
|
||||
$eventsounds = mysql_db_get_row_sql('SELECT * FROM tevent_sound WHERE active = 1');
|
||||
foreach ($eventsounds as $key => $row) {
|
||||
$sounds[$row['sound']] = $row['name'];
|
||||
}
|
||||
|
||||
$inputs[] = [
|
||||
'label' => \__('Sounds'),
|
||||
'class' => 'flex-row',
|
||||
|
|
|
@ -477,6 +477,10 @@ if ($access_console_node === true) {
|
|||
}
|
||||
</script>
|
||||
<?php
|
||||
$sub['godmode/events/configuration_sounds']['text'] = __('Configuration Sounds');
|
||||
$sub['godmode/events/configuration_sounds']['id'] = 'Configuration Sounds';
|
||||
$sub['godmode/events/configuration_sounds']['pages'] = ['godmode/events/configuration_sounds'];
|
||||
|
||||
$menu_operation['eventos']['sub'] = $sub;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue