Repository navigation
Expand file tree
/
Copy pathARMSDebugQuery.js
More file actions
212 lines (164 loc) · 6.2 KB
/
Copy pathARMSDebugQuery.js
File metadata and controls
212 lines (164 loc) · 6.2 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// ==UserScript==
// @name ARMS Debug Query
// @namespace https://github.com/LeightonSolo/IsensixScripts
// @version 3.1
// @description Creates a button on ARMS servers that will open, autofill query, and copy from debug_query.php along with server information. Also creates link to generate calibration report
// @author Leighton Solomon
// @match https://*/arms/admin/
// @match https://*/arms/debug/debug.php
// @match https://*/arms/debug/debug_query.php
// @downloadURL https://raw.githubusercontent.com/LeightonSolo/IsensixScripts/main/ARMSDebugQuery.js
// @updateURL https://raw.githubusercontent.com/LeightonSolo/IsensixScripts/main/ARMSDebugQuery.js
// @icon https://www.google.com/s2/favicons?sz=64&domain=isensix.com
// @grant none
// ==/UserScript==
// .--. .--. .--. .--. .--. .--. .--. .--.
//:::::.\::::::::.\::::::::.\ Leighton's Tools \::::::::.\::::::::.\::::::::.\
//' `--' `--' `--' `--' `--' `--' `--' `
const query = `SELECT
s.sensor_id AS id, s.addr,
s.name AS sensor,
s.sensor_sn as serial,
s.offset,
a.name AS ap,
CASE l.qual
WHEN 0 THEN 'LINK'
WHEN 1 THEN 'GOOD'
WHEN 2 THEN 'SENSOR'
WHEN 3 THEN 'NETWORK'
WHEN 4 THEN 'BATTERY'
WHEN 7 THEN 'WIRE'
WHEN 8 THEN 'WIRE'
WHEN 99 THEN 'INIT'
ELSE IF(s.enable=0, '','UNKNOWN')
END as Qual,
IF (s.enable=1, "ENABLED","DISABLED") AS status,
st.name AS type,
z.name AS zone,
from_unixtime(MAX(c.ts)) as calibrated
FROM sensor s
LEFT JOIN stypes st ON st.id = s.stype
LEFT JOIN zone z ON z.zone_id = s.owner LEFT JOIN callog c ON c.sid = s.sensor_id
LEFT JOIN slog_now l ON l.sensor_id = s.sensor_id
LEFT JOIN ap a on a.ap_id = s.ap
GROUP BY s.name, c.sid`;
let arms = 0;
try { //determine if the system is ARMS or Guardian
if(document.getElementsByClassName("headline2")[0].innerHTML == "(Advanced Remote Monitoring System)"){
arms = 1;
}
}
catch(err){}
let match = window.location.href.match(/:(\d{3,5})/); // match like :7888
let serverId = match ? match[1].slice(-3) : "UNKNOWN"; // get last 3 digits
function selectElementContents(el) {
var body = document.body, range, sel;
if (document.createRange && window.getSelection) {
range = document.createRange();
sel = window.getSelection();
sel.removeAllRanges();
try {
range.selectNodeContents(el);
sel.addRange(range);
} catch (e) {
range.selectNode(el);
sel.addRange(range);
}
} else if (body.createTextRange) {
range = body.createTextRange();
range.moveToElementText(el);
range.select();
}
}
function removeEmptyLastColumn(table) {
let lastColumnEmpty = true;
const rows = table.rows;
const lastCellIndex = rows[0].cells.length - 1;
for (let i = 0; i < rows.length; i++) {
const cell = rows[i].cells[lastCellIndex];
if (cell && cell.textContent.trim() !== "") {
lastColumnEmpty = false;
break;
}
}
if (lastColumnEmpty) {
for (let i = 0; i < rows.length; i++) {
rows[i].deleteCell(lastCellIndex);
}
}
}
function copyTable(copyBtn){
var table = document.getElementsByTagName("table")[0];
// Remove the last column if it is empty
removeEmptyLastColumn(table);
let rows = Array.from(table.rows);
let newRows = [];
let version = "ARMS";
for (let row of rows) {
let cells = Array.from(row.cells).map(cell => cell.textContent.trim());
cells.push(serverId, version); // Add the two new columns
newRows.push(cells.join("\t"));
}
const finalText = newRows.join("\n");
navigator.clipboard.writeText(finalText).then(
() => {
copyBtn.textContent = 'Copied to your clipboard!';
copyBtn.style.background = '#5beb34';
window.getSelection().removeAllRanges();
},
(message) => {
alert("Could not copy! Error: " + message);
},
);
}
(function() {
'use strict';
if(arms == 1){//ensure we are on older arms server
let div = document.getElementById("arms_menu_1");
let btn2 = document.createElement("BUTTON");
btn2.style.margin = '5px';
btn2.textContent = 'Generate Calibration Report';
btn2.title = "Type the SID, check don't send mail, and then click submit to generate the full server calibration report";
div.prepend(btn2);
btn2.onclick = () => {
openCalReport();
}
let btn = document.createElement("BUTTON");
btn.textContent = 'Copy Calibration Query';
btn.title = "Generate a Calibration Summary to be pasted onto a Visualizer";
let cell = document.createElement("td");
cell.appendChild(btn);
div.prepend(cell);
const url = document.URL;
let debugUrl = "";
debugUrl = url.slice(0, 38) + "debug/debug_query.php";
btn.onclick = () => {
window.open(debugUrl); //opens the debug_query.php in a new tab
}
}
else{ //should only run on debug_query.php url
try {
document.getElementsByName("query")[0].textContent = query;
let btn = document.getElementsByName("submit")[0];
var table = document.querySelector('table');
if(table){
// The table element exists.
let copyBtn = document.createElement("BUTTON");
copyBtn.textContent = 'Copy Query Results';
copyBtn.style.background='#00e1ff';
btn.parentNode.appendChild(copyBtn);
copyBtn.addEventListener('click', function(event) {
// Prevent the default behavior of the button.
event.preventDefault();
});
copyBtn.onclick = () => {
copyTable(copyBtn);
}
}
}
catch(err) {}
}
})();
function openCalReport() {
window.open("https://172.16.64.2/sshto/cal.php", "_blank");
}