2009-02-19 22:34:27 +01:00
< ? php
2009-06-08 20:26:14 +02:00
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
2009-02-19 22:34:27 +01:00
// This program is free software; you can redistribute it and/or
2009-06-08 20:26:14 +02:00
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
2009-02-19 22:34:27 +01:00
// 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.
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/dev.php,
include/auth/ldap.php, include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/FusionCharts/FusionCharts_Gen.php,
include/FusionCharts/FusionCharts.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/help/en/help_plugin_parameters.php,
include/help/en/help_snmpcommunity.php, include/help/en/help_wmiquery.php,
include/help/en/help_postprocess.php,
include/help/en/help_prediction_source_module.php,
include/help/en/help_date_format.php, include/help/en/help_recontask.php,
include/help/en/help_alert-matches.php, include/help/en/help_tcp_send.php,
include/help/en/help_wmifield.php, include/help/en/help_duplicateconfig.php,
include/help/en/help_agent_status.php,
include/help/en/help_manage_alerts.php, include/help/en/help_wmikey.php,
include/help/en/help_alert_type.php,
include/help/en/help_network_component.php,
include/help/en/help_time_stamp-comparation.php,
include/help/en/help_eventview.php, include/help/en/help_timesource.php,
include/help/en/help_alert_validation.php,
include/help/en/help_map_builder.php,
include/help/en/help_alert_recovery.php,
include/help/en/help_module_type.php,
include/help/en/help_planned_downtime.php,
include/help/en/help_serverlag.php, include/help/en/help_alerts.php,
include/help/en/help_snmpwalk.php,
include/help/en/help_module_definition.php,
include/help/en/help_plugin_definition.php,
include/help/en/help_wminamespace.php, include/help/en/help_snmpoid.php
include/help/en/help_manageconfig.php,
include/help/es/help_alert_validation.php,
include/help/es/help_plugin_parameters.php,
include/help/es/help_snmpcommunity.php, include/help/es/help_wmiquery.php,
include/help/es/help_map_builder.php, include/help/es/help_postprocess.php,
include/help/es/help_date_format.php,
include/help/es/help_alert_recovery.php,
include/help/es/help_prediction_source_module.php,
include/help/es/help_module_type.php,
include/help/es/help_planned_downtime.php,
include/help/es/help_alert-matches.php, include/help/es/help_recontask.php,
include/help/es/help_alerts.php, include/help/es/help_serverlag.php,
include/help/es/help_snmpwalk.php,
include/help/es/help_module_definition.php,
include/help/es/help_tcp_send.php, include/help/es/help_duplicateconfig.php,
include/help/es/help_wmifield.php, include/help/es/help_manage_alerts.php,
include/help/es/help_wmikey.php, include/help/es/help_plugin_definition.php,
include/help/es/help_alert_type.php, include/help/es/help_snmpoid.php,
include/help/es/help_wminamespace.php,
include/help/es/help_network_component.php,
include/help/es/help_time_stamp-comparation.php,
include/help/es/help_manageconfig.php, include/help/es/help_timesource.php,
include/config_process.php, include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change comments blocks for delete the
warnings to construct phpDoc Files, give a struct and order in the
phpDoc files.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1881 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-25 19:39:28 +02:00
/**
* @ package Include
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/ldap.php,
include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/config_process.php,
include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change or add the subpackage in phpdoc
comment blocks for to organize more the result phpdoc files. Start to
document undocument functions.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1882 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-26 17:37:47 +02:00
* @ subpackage Messages
2009-08-24 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_menu.php, include/functions_html.php,
include/functions_events.php, include/functions_messages.php,
include/functions_modules.php, include/functions_exportserver.php,
include/functions_reporting.php, include/functions_filemanager.php,
include/pchart_graph.php, include/pandora_graph.php, include/auth/dev.php,
include/auth/ldap.php, include/auth/mysql.php, include/config.inc.php,
include/functions_networkmap.php, include/functions_servers.php,
include/FusionCharts/FusionCharts_Gen.php,
include/FusionCharts/FusionCharts.php,
include/functions_network_profiles.php, include/gettext.php,
include/functions_network_components.php, include/functions_visual_map.php,
include/fgraph2.php, include/Image/image_functions.php,
include/functions_config.php, include/help/en/help_plugin_parameters.php,
include/help/en/help_snmpcommunity.php, include/help/en/help_wmiquery.php,
include/help/en/help_postprocess.php,
include/help/en/help_prediction_source_module.php,
include/help/en/help_date_format.php, include/help/en/help_recontask.php,
include/help/en/help_alert-matches.php, include/help/en/help_tcp_send.php,
include/help/en/help_wmifield.php, include/help/en/help_duplicateconfig.php,
include/help/en/help_agent_status.php,
include/help/en/help_manage_alerts.php, include/help/en/help_wmikey.php,
include/help/en/help_alert_type.php,
include/help/en/help_network_component.php,
include/help/en/help_time_stamp-comparation.php,
include/help/en/help_eventview.php, include/help/en/help_timesource.php,
include/help/en/help_alert_validation.php,
include/help/en/help_map_builder.php,
include/help/en/help_alert_recovery.php,
include/help/en/help_module_type.php,
include/help/en/help_planned_downtime.php,
include/help/en/help_serverlag.php, include/help/en/help_alerts.php,
include/help/en/help_snmpwalk.php,
include/help/en/help_module_definition.php,
include/help/en/help_plugin_definition.php,
include/help/en/help_wminamespace.php, include/help/en/help_snmpoid.php
include/help/en/help_manageconfig.php,
include/help/es/help_alert_validation.php,
include/help/es/help_plugin_parameters.php,
include/help/es/help_snmpcommunity.php, include/help/es/help_wmiquery.php,
include/help/es/help_map_builder.php, include/help/es/help_postprocess.php,
include/help/es/help_date_format.php,
include/help/es/help_alert_recovery.php,
include/help/es/help_prediction_source_module.php,
include/help/es/help_module_type.php,
include/help/es/help_planned_downtime.php,
include/help/es/help_alert-matches.php, include/help/es/help_recontask.php,
include/help/es/help_alerts.php, include/help/es/help_serverlag.php,
include/help/es/help_snmpwalk.php,
include/help/es/help_module_definition.php,
include/help/es/help_tcp_send.php, include/help/es/help_duplicateconfig.php,
include/help/es/help_wmifield.php, include/help/es/help_manage_alerts.php,
include/help/es/help_wmikey.php, include/help/es/help_plugin_definition.php,
include/help/es/help_alert_type.php, include/help/es/help_snmpoid.php,
include/help/es/help_wminamespace.php,
include/help/es/help_network_component.php,
include/help/es/help_time_stamp-comparation.php,
include/help/es/help_manageconfig.php, include/help/es/help_timesource.php,
include/config_process.php, include/functions_ui.php, include/htmlawed.php,
include/functions_custom_graphs.php, include/fgraph.php,
include/functions_incidents.php, include/functions.php,
include/functions_agents.php, include/functions_db.php,
include/functions_themes.php, include/streams.php,
include/functions_fsgraph.php, include/functions_alerts.php,
include/functions_reports.php, include/functions_extensions.php,
include/functions_ui_renders.php: change comments blocks for delete the
warnings to construct phpDoc Files, give a struct and order in the
phpDoc files.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1881 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-08-25 19:39:28 +02:00
*/
2009-02-19 22:34:27 +01:00
/**
* Creates a private message to be forwarded to other people
*
* @ param string $usuario_origen The sender of the message
* @ param string $usuario_destino The receiver of the message
* @ param string $subject Subject of the message ( much like E - Mail )
* @ param string $mensaje The actual message . This message will be cleaned by safe_input
* ( html is allowed but loose html chars will be translated )
*
* @ return bool true when delivered , false in case of error
*/
function create_message ( $usuario_origen , $usuario_destino , $subject , $mensaje ) {
$users = get_users_info ();
if ( ! array_key_exists ( $usuario_origen , $users ) || ! array_key_exists ( $usuario_destino , $users )) {
return false ; //Users don't exist so don't send to them
}
2009-02-24 12:20:34 +01:00
$values = array ();
$values [ " id_usuario_origen " ] = $usuario_origen ;
$values [ " id_usuario_destino " ] = $usuario_destino ;
2009-11-27 Sancho lerena <slerena@artica.es>
* operation/menu.php: User section has no ACL check, always can be seen.
* index.php: Added suppor for user-defined custom language (this code was
on my disk for 3 months, pending to be commited!).
* include/functions_db.php,
* include/functions_agents.php,
* godmode/alerts/alert_list.php,
* godmode/agentes/modificar_agente.php,
* godmode/agentes/configurar_agente.php: Added audit calls to several
management operations who don't have or have insufficient audit info.
* godmode/users/configure_user.php: Fixed several annoyings bugs. Added
custom language support, and added more audit info on management operations.
* godmode/users/user_list.php: More audit info.
* include/config_process.php: Add new debug option to render error log to
/pandora_console.log. Also set timezone if not defined (this makes warnings
on several PHP 5.x setups). Added user custom language support.
* include/functions_events.php: More audit info. Fixed problems with HTML
encoding render.
* functions_io.php: Some cleaning.
* include/functions_messages.php: Fixed problems with HTML
encoding render.
* functions_ui.php: Fixed problems with HTML encoding render in
print_string_substr() function.
* auth/mysql.php: is_user_admin() functions seems to be broken ¿?¿!. Fixed.
* styles/pandora.css: removed green colored left border in default style.
* message.php, incident*: Fixed problems with HTML encoding render.
* user.php: Better ACL check before let user to view/edit another user.
* user_edit: Removed some un-used form fields, some arrangements in layout,
and FIXED forever problems with password change (new code written).
* users/user_statistics.php: Now user can see its own audit records.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2139 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-27 21:02:12 +01:00
$values [ " subject " ] = $subject ;
$values [ " mensaje " ] = $mensaje ;
2009-02-24 12:20:34 +01:00
$values [ " timestamp " ] = get_system_time ();
2009-02-19 22:34:27 +01:00
$return = process_sql_insert ( " tmensajes " , $values );
if ( $return === false ) {
return false ;
} else {
return true ;
}
}
/**
* Creates private messages to be forwarded to groups
*
2009-02-24 12:20:34 +01:00
* @ param string The sender of the message
* @ param string The receivers ( group ) of the message
* @ param string Subject of the message ( much like E - Mail )
* @ param string The actual message . This message will be cleaned by safe_input
2009-02-19 22:34:27 +01:00
* ( html is allowed but loose html chars will be translated )
*
* @ return bool true when delivered , false in case of error
*/
function create_message_group ( $usuario_origen , $dest_group , $subject , $mensaje ) {
$users = get_users_info ();
$group_users = get_group_users ( $dest_group );
2009-02-24 12:20:34 +01:00
if ( ! array_key_exists ( $usuario_origen , $users )) {
//Users don't exist in the system
return false ;
2009-02-19 22:34:27 +01:00
} elseif ( empty ( $group_users )) {
2009-02-24 12:20:34 +01:00
//There are no users in the group, so it hasn't failed although it hasn't done anything.
return true ;
2009-02-19 22:34:27 +01:00
}
//Start transaction so that if it fails somewhere along the way, we roll back
2009-05-04 Esteban Sánchez <estebans@artica.es>
* include/functions_agents.php: Added create_agent(),
* include/functions_db.php: Renamed dame_agente_id() to get_agent_id ().
Added process_sql_begin(), process_sql_rollback() and process_sql_commit()
and use MySQL functions directly because the Pandora cache was avoiding
more than one execution.
* include/functions_incidents.php, include/functions_messages.php,
godmode/agentes/massive_delete_agents.php,
godmode/agentes/massive_delete_alerts.php,
godmode/agentes/massive_delete_modules.php,
godmode/agentes/massive_edit_modules.php,
godmode/db/db_purge.php,
include/functions_events.php: Use new transaction functions.
* include/functions_modules.php: Sanitize some values. Added
create_agent_module_from_network_component(), create_agent_module()
and get_network_component().
* godmode/agentes/configurar_agente.php: Use get_agent_id() and transaction
functions.
* reporting/fgraph.php, operation/reporting/reporting_viewer.php: Use
get_agent_id().
* godmode/setup/file_manager.php: Removed unnecesary variable.
* operation/agentes/ver_agente.php: Replaced exit with return on ajax
operation.
* include/config_process.php: Updated build number.
* include/functions_network_profiles.php: Fixed documentation.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1672 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-04 12:10:19 +02:00
process_sql_begin ();
2009-02-19 22:34:27 +01:00
foreach ( $group_users as $user ) {
2009-02-24 12:20:34 +01:00
$return = create_message ( $usuario_origen , get_user_id ( $user ), $subject , $mensaje );
2009-02-19 22:34:27 +01:00
if ( $return === false ) {
//Error sending message, rollback and return false
2009-05-04 Esteban Sánchez <estebans@artica.es>
* include/functions_agents.php: Added create_agent(),
* include/functions_db.php: Renamed dame_agente_id() to get_agent_id ().
Added process_sql_begin(), process_sql_rollback() and process_sql_commit()
and use MySQL functions directly because the Pandora cache was avoiding
more than one execution.
* include/functions_incidents.php, include/functions_messages.php,
godmode/agentes/massive_delete_agents.php,
godmode/agentes/massive_delete_alerts.php,
godmode/agentes/massive_delete_modules.php,
godmode/agentes/massive_edit_modules.php,
godmode/db/db_purge.php,
include/functions_events.php: Use new transaction functions.
* include/functions_modules.php: Sanitize some values. Added
create_agent_module_from_network_component(), create_agent_module()
and get_network_component().
* godmode/agentes/configurar_agente.php: Use get_agent_id() and transaction
functions.
* reporting/fgraph.php, operation/reporting/reporting_viewer.php: Use
get_agent_id().
* godmode/setup/file_manager.php: Removed unnecesary variable.
* operation/agentes/ver_agente.php: Replaced exit with return on ajax
operation.
* include/config_process.php: Updated build number.
* include/functions_network_profiles.php: Fixed documentation.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1672 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-04 12:10:19 +02:00
process_sql_rollback ();
2009-02-19 22:34:27 +01:00
return false ;
}
}
//We got here, so we can commit - if this function gets extended, make sure to do SQL above these lines
2009-05-04 Esteban Sánchez <estebans@artica.es>
* include/functions_agents.php: Added create_agent(),
* include/functions_db.php: Renamed dame_agente_id() to get_agent_id ().
Added process_sql_begin(), process_sql_rollback() and process_sql_commit()
and use MySQL functions directly because the Pandora cache was avoiding
more than one execution.
* include/functions_incidents.php, include/functions_messages.php,
godmode/agentes/massive_delete_agents.php,
godmode/agentes/massive_delete_alerts.php,
godmode/agentes/massive_delete_modules.php,
godmode/agentes/massive_edit_modules.php,
godmode/db/db_purge.php,
include/functions_events.php: Use new transaction functions.
* include/functions_modules.php: Sanitize some values. Added
create_agent_module_from_network_component(), create_agent_module()
and get_network_component().
* godmode/agentes/configurar_agente.php: Use get_agent_id() and transaction
functions.
* reporting/fgraph.php, operation/reporting/reporting_viewer.php: Use
get_agent_id().
* godmode/setup/file_manager.php: Removed unnecesary variable.
* operation/agentes/ver_agente.php: Replaced exit with return on ajax
operation.
* include/config_process.php: Updated build number.
* include/functions_network_profiles.php: Fixed documentation.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1672 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-05-04 12:10:19 +02:00
process_sql_commit ();
2009-02-19 22:34:27 +01:00
return true ;
}
/**
* Deletes a private message
*
* @ param int $id_message
*
* @ return bool true when deleted , false in case of error
*/
function delete_message ( $id_message ) {
global $config ;
$sql = sprintf ( " DELETE FROM tmensajes WHERE id_usuario_destino='%s' AND id_mensaje=%d " , $config [ " id_user " ], $id_message );
return ( bool ) process_sql ( $sql );
}
/**
* Marks a private message as read / unread
*
* @ param int $message_id The message to modify
* @ param bool $read To set unread pass 0 , false or empty value
*
* @ return bool true when marked , false in case of error
*/
function process_message_read ( $message_id , $read = true ) {
if ( empty ( $read )) {
$read = 0 ;
} else {
$read = 1 ;
}
return ( bool ) process_sql ( " UPDATE tmensajes SET estado = " . $read . " WHERE id_mensaje = " . $message_id );
}
/**
* Gets a private message
*
* This function abstracts the database backend so it can simply be replaced with another system
*
* @ param int $message_id
*
* @ return mixed False if it doesn ' t exist or a filled array otherwise
*/
function get_message ( $message_id ) {
global $config ;
$sql = sprintf ( " SELECT id_usuario_origen, subject, mensaje, timestamp FROM tmensajes WHERE id_usuario_destino='%s' AND id_mensaje=%d " , $config [ " id_user " ], $message_id );
$row = get_db_row_sql ( $sql );
if ( empty ( $row )) {
return false ;
}
$return [ " sender " ] = $row [ " id_usuario_origen " ];
2009-11-27 Sancho lerena <slerena@artica.es>
* operation/menu.php: User section has no ACL check, always can be seen.
* index.php: Added suppor for user-defined custom language (this code was
on my disk for 3 months, pending to be commited!).
* include/functions_db.php,
* include/functions_agents.php,
* godmode/alerts/alert_list.php,
* godmode/agentes/modificar_agente.php,
* godmode/agentes/configurar_agente.php: Added audit calls to several
management operations who don't have or have insufficient audit info.
* godmode/users/configure_user.php: Fixed several annoyings bugs. Added
custom language support, and added more audit info on management operations.
* godmode/users/user_list.php: More audit info.
* include/config_process.php: Add new debug option to render error log to
/pandora_console.log. Also set timezone if not defined (this makes warnings
on several PHP 5.x setups). Added user custom language support.
* include/functions_events.php: More audit info. Fixed problems with HTML
encoding render.
* functions_io.php: Some cleaning.
* include/functions_messages.php: Fixed problems with HTML
encoding render.
* functions_ui.php: Fixed problems with HTML encoding render in
print_string_substr() function.
* auth/mysql.php: is_user_admin() functions seems to be broken ¿?¿!. Fixed.
* styles/pandora.css: removed green colored left border in default style.
* message.php, incident*: Fixed problems with HTML encoding render.
* user.php: Better ACL check before let user to view/edit another user.
* user_edit: Removed some un-used form fields, some arrangements in layout,
and FIXED forever problems with password change (new code written).
* users/user_statistics.php: Now user can see its own audit records.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2139 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-11-27 21:02:12 +01:00
$return [ " subject " ] = $row [ " subject " ];
$return [ " message " ] = $row [ " mensaje " ];
2009-02-19 22:34:27 +01:00
$return [ " timestamp " ] = $row [ " timestamp " ];
return $return ;
}
/**
* Counts private messages
*
* @ param string $user
* @ param bool $incl_read Whether or not to include read messages
*
* @ return int The number of messages this user has
*/
function get_message_count ( $user = false , $incl_read = false ) {
if ( empty ( $user )) {
global $config ;
$user = $config [ " id_user " ];
}
if ( empty ( $incl_read )) {
$filter = " AND estado = 0 " ;
} else {
$filter = " " ;
}
$sql = sprintf ( " SELECT COUNT(*) FROM tmensajes WHERE id_usuario_destino='%s' %s " , $user , $filter );
return ( int ) get_db_sql ( $sql );
}
/**
* Get message overview in array
*
* @ param string $order How to order them valid :
* ( status ( default ), subject , timestamp , sender )
* @ param string $order_dir Direction of order ( ASC = Ascending , DESC = Descending )
*
* @ return int The number of messages this user has
*/
function get_message_overview ( $order = " status " , $order_dir = " ASC " ) {
global $config ;
switch ( $order ) {
case " timestamp " :
case " sender " :
case " subject " :
break ;
case " status " :
default :
$order = " estado " ;
}
if ( $order_dir != " ASC " ) {
$order .= " DESC " ;
}
$result = array ();
$return = get_db_all_rows_field_filter ( 'tmensajes' , 'id_usuario_destino' , $config [ " id_user " ], $order );
if ( $return === false ) {
return $result ;
}
foreach ( $return as $message ) {
$result [ $message [ " id_mensaje " ]][ " sender " ] = $message [ " id_usuario_origen " ];
$result [ $message [ " id_mensaje " ]][ " subject " ] = $message [ " subject " ];
$result [ $message [ " id_mensaje " ]][ " timestamp " ] = $message [ " timestamp " ];
$result [ $message [ " id_mensaje " ]][ " status " ] = $message [ " estado " ];
}
return $result ;
}
2009-02-24 12:20:34 +01:00
?>