-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogtracker.php
More file actions
94 lines (69 loc) · 2.97 KB
/
logtracker.php
File metadata and controls
94 lines (69 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/*
Module Name: Logtracker
Author: Amolood
Author URI: https://amolood.com
Version: 1.0.0
Description: This module provides a centralized interface for managing and accessing log files generated by the Perfex CRM application.
*/
define('LOGTRACKER_MODULE', 'logtracker');
hooks()->add_action('admin_init', 'logtracker_module_init_menu_items');
// active the module
register_activation_hook(LOGTRACKER_MODULE, 'logtracker_module_activate_hook');
get_instance()->load->helper(LOGTRACKER_MODULE . '/logtracker');
// register language files for the module
register_language_files(LOGTRACKER_MODULE, [LOGTRACKER_MODULE]);
hooks()->add_filter('before_settings_updated', function ($data) {
if (isset ($data['settings']['enviornment_mode'])) {
$custom_word = $data['settings']['enviornment_mode'] == 'development' ? 'production' : 'development';
if (file_exists('index.php')) {
$fileContents = file_get_contents('index.php');
$searchString = "define('ENVIRONMENT', '" . $custom_word . "');";
$replacementString = "define('ENVIRONMENT', '" . $data['settings']['enviornment_mode'] . "');";
$fileContents = str_replace($searchString, $replacementString, $fileContents);
file_put_contents('index.php', $fileContents);
}
}
return $data;
});
function logtracker_module_activate_hook()
{
// This function runs when the module is activated.
// Add setup logic here if needed (e.g., create folders, set default options).
}
require_once __DIR__ . '/includes/assets.php';
require_once __DIR__ . '/includes/staff_permissions.php';
require_once __DIR__ . '/includes/sidebar_menu_links.php';
hooks()->add_filter('get_dashboard_widgets', function ($widgets) {
$new_widgets = [];
if (has_permission('logtracker', '', 'view')) {
$new_widgets[] = [
'path' => LOGTRACKER_MODULE . '/widgets/logtracker-widget',
'container' => 'top-12',
];
}
return array_merge($new_widgets, $widgets);
});
register_merge_fields(LOGTRACKER_MODULE . '/merge_fields/logtracker_merge_fields');
// Hook to automatically send Critical errors to Telegram
hooks()->add_action('after_log_message', function($level, $message, $file = '', $line = '') {
$selected_levels = get_option('logtracker_auto_telegram_levels');
if (empty($selected_levels)) {
return;
}
$levels_to_send = explode(',', $selected_levels);
if (in_array($level, $levels_to_send)) {
$telegramMessage = "🚨 *Log Event Detected*\n"
. "*Level:* " . $level . "\n"
. "*Time:* " . date('Y-m-d H:i:s') . "\n"
. "*Message:* " . $message;
if (!empty($file)) {
$telegramMessage .= "\n*File:* " . $file;
}
if (!empty($line)) {
$telegramMessage .= "\n*Line:* " . $line;
}
send_telegram_message($telegramMessage);
}
});