1
|
|
|
/* |
2
|
|
|
* MikoPBX - free phone system for small business |
3
|
|
|
* Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov |
4
|
|
|
* |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
16
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/* global sessionStorage, PbxApi, archivePackingCheckWorker */ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Represents the system diagnostic capture object. |
23
|
|
|
*/ |
24
|
|
|
const systemDiagnosticCapture = { |
25
|
|
|
/** |
26
|
|
|
* jQuery element for the start button. |
27
|
|
|
* @type {jQuery} |
28
|
|
|
*/ |
29
|
|
|
$startBtn: $('#start-capture-button'), |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* jQuery element for the download button. |
33
|
|
|
* @type {jQuery} |
34
|
|
|
*/ |
35
|
|
|
$downloadBtn: $('#download-logs-button'), |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* jQuery element for the stop button. |
39
|
|
|
* @type {jQuery} |
40
|
|
|
*/ |
41
|
|
|
$stopBtn: $('#stop-capture-button'), |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* jQuery element for the show button. |
45
|
|
|
* @type {jQuery} |
46
|
|
|
*/ |
47
|
|
|
$showBtn: $('#show-last-log'), |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* jQuery element for the dimmer. |
51
|
|
|
* @type {jQuery} |
52
|
|
|
*/ |
53
|
|
|
$dimmer: $('#capture-log-dimmer'), |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Initializes the system diagnostic capture. |
57
|
|
|
*/ |
58
|
|
|
initialize() { |
59
|
|
|
const segmentHeight = window.innerHeight - 300; |
60
|
|
|
$(window).load(function () { |
61
|
|
|
systemDiagnosticCapture.$dimmer.closest('div').css('min-height', `${segmentHeight}px`); |
62
|
|
|
}); |
63
|
|
|
if (sessionStorage.getItem('PCAPCaptureStatus') === 'started') { |
64
|
|
|
systemDiagnosticCapture.$startBtn.addClass('disabled loading'); |
65
|
|
|
systemDiagnosticCapture.$stopBtn.removeClass('disabled'); |
66
|
|
|
} else { |
67
|
|
|
systemDiagnosticCapture.$startBtn.removeClass('disabled loading'); |
68
|
|
|
systemDiagnosticCapture.$stopBtn.addClass('disabled'); |
69
|
|
|
} |
70
|
|
|
systemDiagnosticCapture.$startBtn.on('click', (e) => { |
71
|
|
|
e.preventDefault(); |
72
|
|
|
systemDiagnosticCapture.$startBtn.addClass('disabled loading'); |
73
|
|
|
systemDiagnosticCapture.$stopBtn.removeClass('disabled'); |
74
|
|
|
PbxApi.SyslogStartLogsCapture(systemDiagnosticCapture.cbAfterStartCapture); |
75
|
|
|
}); |
76
|
|
|
systemDiagnosticCapture.$stopBtn.on('click', (e) => { |
77
|
|
|
e.preventDefault(); |
78
|
|
|
systemDiagnosticCapture.$startBtn.removeClass('loading'); |
79
|
|
|
systemDiagnosticCapture.$stopBtn.addClass('loading'); |
80
|
|
|
systemDiagnosticCapture.$dimmer.addClass('active'); |
81
|
|
|
PbxApi.SyslogStopLogsCapture(systemDiagnosticCapture.cbAfterStopCapture); |
82
|
|
|
|
83
|
|
|
}); |
84
|
|
|
systemDiagnosticCapture.$downloadBtn.on('click', (e) => { |
85
|
|
|
e.preventDefault(); |
86
|
|
|
systemDiagnosticCapture.$downloadBtn.addClass('disabled loading'); |
87
|
|
|
systemDiagnosticCapture.$dimmer.addClass('active'); |
88
|
|
|
PbxApi.SyslogPrepareLog(systemDiagnosticCapture.cbAfterDownloadCapture); |
89
|
|
|
}); |
90
|
|
|
}, |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Callback after pushing the start logs collect button. |
94
|
|
|
* @param {object} response - The response object. |
95
|
|
|
*/ |
96
|
|
|
cbAfterStartCapture(response) { |
97
|
|
|
if (response !== false) { |
98
|
|
|
sessionStorage.setItem('PCAPCaptureStatus', 'started'); |
99
|
|
|
setTimeout(() => { |
100
|
|
|
sessionStorage.setItem('PCAPCaptureStatus', 'stopped'); |
101
|
|
|
}, 300000); |
102
|
|
|
} |
103
|
|
|
}, |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Callback after pushing the start logs collect button. |
108
|
|
|
* @param {object} response - The response object. |
109
|
|
|
*/ |
110
|
|
|
cbAfterDownloadCapture(response) { |
111
|
|
|
if (response !== false) { |
112
|
|
|
archivePackingCheckWorker.initialize(response.filename); |
113
|
|
|
} |
114
|
|
|
}, |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Callback after pushing the stop logs collect button. |
118
|
|
|
* @param {object} response - The response object. |
119
|
|
|
*/ |
120
|
|
|
cbAfterStopCapture(response) { |
121
|
|
|
if (response !== false) { |
122
|
|
|
archivePackingCheckWorker.initialize(response.filename); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
}; |
126
|
|
|
|
127
|
|
|
// When the document is ready, initialize the system diagnostic management console |
128
|
|
|
$(document).ready(() => { |
129
|
|
|
systemDiagnosticCapture.initialize(); |
130
|
|
|
}); |
131
|
|
|
|
132
|
|
|
|