code-poltergeist-system-monitor 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of code-poltergeist-system-monitor might be problematic. Click here for more details.

Files changed (33) hide show
  1. package/index.js +74 -0
  2. package/package.json +21 -0
  3. package/te/node_modules/.package-lock.json +44 -0
  4. package/te/node_modules/code-poltergeist-system-monitor/index.js +74 -0
  5. package/te/node_modules/code-poltergeist-system-monitor/package.json +21 -0
  6. package/te/node_modules/systeminformation/LICENSE +20 -0
  7. package/te/node_modules/systeminformation/README.md +1116 -0
  8. package/te/node_modules/systeminformation/lib/audio.js +222 -0
  9. package/te/node_modules/systeminformation/lib/battery.js +311 -0
  10. package/te/node_modules/systeminformation/lib/bluetooth.js +231 -0
  11. package/te/node_modules/systeminformation/lib/cli.js +91 -0
  12. package/te/node_modules/systeminformation/lib/cpu.js +1834 -0
  13. package/te/node_modules/systeminformation/lib/docker.js +758 -0
  14. package/te/node_modules/systeminformation/lib/dockerSocket.js +327 -0
  15. package/te/node_modules/systeminformation/lib/filesystem.js +1510 -0
  16. package/te/node_modules/systeminformation/lib/graphics.js +1125 -0
  17. package/te/node_modules/systeminformation/lib/index.d.ts +1041 -0
  18. package/te/node_modules/systeminformation/lib/index.js +504 -0
  19. package/te/node_modules/systeminformation/lib/internet.js +237 -0
  20. package/te/node_modules/systeminformation/lib/memory.js +575 -0
  21. package/te/node_modules/systeminformation/lib/network.js +1783 -0
  22. package/te/node_modules/systeminformation/lib/osinfo.js +1179 -0
  23. package/te/node_modules/systeminformation/lib/printer.js +210 -0
  24. package/te/node_modules/systeminformation/lib/processes.js +1296 -0
  25. package/te/node_modules/systeminformation/lib/system.js +742 -0
  26. package/te/node_modules/systeminformation/lib/usb.js +279 -0
  27. package/te/node_modules/systeminformation/lib/users.js +363 -0
  28. package/te/node_modules/systeminformation/lib/util.js +1373 -0
  29. package/te/node_modules/systeminformation/lib/virtualbox.js +107 -0
  30. package/te/node_modules/systeminformation/lib/wifi.js +834 -0
  31. package/te/node_modules/systeminformation/package.json +99 -0
  32. package/te/package-lock.json +52 -0
  33. package/te/package.json +15 -0
@@ -0,0 +1,210 @@
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // printers.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2024
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 15. printers
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const exec = require('child_process').exec;
17
+ const util = require('./util');
18
+
19
+ let _platform = process.platform;
20
+
21
+ const _linux = (_platform === 'linux' || _platform === 'android');
22
+ const _darwin = (_platform === 'darwin');
23
+ const _windows = (_platform === 'win32');
24
+ const _freebsd = (_platform === 'freebsd');
25
+ const _openbsd = (_platform === 'openbsd');
26
+ const _netbsd = (_platform === 'netbsd');
27
+ const _sunos = (_platform === 'sunos');
28
+
29
+ const winPrinterStatus = {
30
+ 1: 'Other',
31
+ 2: 'Unknown',
32
+ 3: 'Idle',
33
+ 4: 'Printing',
34
+ 5: 'Warmup',
35
+ 6: 'Stopped Printing',
36
+ 7: 'Offline',
37
+ };
38
+
39
+ function parseLinuxCupsHeader(lines) {
40
+ const result = {};
41
+ if (lines && lines.length) {
42
+ if (lines[0].indexOf(' CUPS v') > 0) {
43
+ const parts = lines[0].split(' CUPS v');
44
+ result.cupsVersion = parts[1];
45
+ }
46
+ }
47
+ return result;
48
+ }
49
+
50
+ function parseLinuxCupsPrinter(lines) {
51
+ const result = {};
52
+ const printerId = util.getValue(lines, 'PrinterId', ' ');
53
+ result.id = printerId ? parseInt(printerId, 10) : null;
54
+ result.name = util.getValue(lines, 'Info', ' ');
55
+ result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : '';
56
+ result.uri = util.getValue(lines, 'DeviceURI', ' ');
57
+ result.uuid = util.getValue(lines, 'UUID', ' ');
58
+ result.status = util.getValue(lines, 'State', ' ');
59
+ result.local = util.getValue(lines, 'Location', ' ').toLowerCase().startsWith('local');
60
+ result.default = null;
61
+ result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes');
62
+
63
+ return result;
64
+ }
65
+
66
+ function parseLinuxLpstatPrinter(lines, id) {
67
+ const result = {};
68
+ result.id = id;
69
+ result.name = util.getValue(lines, 'Description', ':', true);
70
+ result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : '';
71
+ result.uri = null;
72
+ result.uuid = null;
73
+ result.status = lines.length > 0 && lines[0] ? (lines[0].indexOf(' idle') > 0 ? 'idle' : (lines[0].indexOf(' printing') > 0 ? 'printing' : 'unknown')) : null;
74
+ result.local = util.getValue(lines, 'Location', ':', true).toLowerCase().startsWith('local');
75
+ result.default = null;
76
+ result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes');
77
+
78
+ return result;
79
+ }
80
+
81
+ function parseDarwinPrinters(printerObject, id) {
82
+ const result = {};
83
+ const uriParts = printerObject.uri.split('/');
84
+ result.id = id;
85
+ result.name = printerObject._name;
86
+ result.model = uriParts.length ? uriParts[uriParts.length - 1] : '';
87
+ result.uri = printerObject.uri;
88
+ result.uuid = null;
89
+ result.status = printerObject.status;
90
+ result.local = printerObject.printserver === 'local';
91
+ result.default = printerObject.default === 'yes';
92
+ result.shared = printerObject.shared === 'yes';
93
+
94
+ return result;
95
+ }
96
+
97
+ function parseWindowsPrinters(lines, id) {
98
+ const result = {};
99
+ const status = parseInt(util.getValue(lines, 'PrinterStatus', ':'), 10);
100
+
101
+ result.id = id;
102
+ result.name = util.getValue(lines, 'name', ':');
103
+ result.model = util.getValue(lines, 'DriverName', ':');
104
+ result.uri = null;
105
+ result.uuid = null;
106
+ result.status = winPrinterStatus[status] ? winPrinterStatus[status] : null;
107
+ result.local = util.getValue(lines, 'Local', ':').toUpperCase() === 'TRUE';
108
+ result.default = util.getValue(lines, 'Default', ':').toUpperCase() === 'TRUE';
109
+ result.shared = util.getValue(lines, 'Shared', ':').toUpperCase() === 'TRUE';
110
+
111
+ return result;
112
+ }
113
+
114
+ function printer(callback) {
115
+
116
+ return new Promise((resolve) => {
117
+ process.nextTick(() => {
118
+ let result = [];
119
+ if (_linux || _freebsd || _openbsd || _netbsd) {
120
+ let cmd = 'cat /etc/cups/printers.conf 2>/dev/null';
121
+ exec(cmd, function (error, stdout) {
122
+ // printers.conf
123
+ if (!error) {
124
+ const parts = stdout.toString().split('<Printer ');
125
+ const printerHeader = parseLinuxCupsHeader(parts[0]);
126
+ for (let i = 1; i < parts.length; i++) {
127
+ const printers = parseLinuxCupsPrinter(parts[i].split('\n'));
128
+ if (printers.name) {
129
+ printers.engine = 'CUPS';
130
+ printers.engineVersion = printerHeader.cupsVersion;
131
+ result.push(printers);
132
+ }
133
+ }
134
+ }
135
+ if (result.length === 0) {
136
+ if (_linux) {
137
+ cmd = 'export LC_ALL=C; lpstat -lp 2>/dev/null; unset LC_ALL';
138
+ // lpstat
139
+ exec(cmd, function (error, stdout) {
140
+ const parts = ('\n' + stdout.toString()).split('\nprinter ');
141
+ for (let i = 1; i < parts.length; i++) {
142
+ const printers = parseLinuxLpstatPrinter(parts[i].split('\n'), i);
143
+ result.push(printers);
144
+ }
145
+ });
146
+ if (callback) {
147
+ callback(result);
148
+ }
149
+ resolve(result);
150
+ } else {
151
+ if (callback) {
152
+ callback(result);
153
+ }
154
+ resolve(result);
155
+ }
156
+ } else {
157
+ if (callback) {
158
+ callback(result);
159
+ }
160
+ resolve(result);
161
+ }
162
+ });
163
+ }
164
+ if (_darwin) {
165
+ let cmd = 'system_profiler SPPrintersDataType -json';
166
+ exec(cmd, function (error, stdout) {
167
+ if (!error) {
168
+ try {
169
+ const outObj = JSON.parse(stdout.toString());
170
+ if (outObj.SPPrintersDataType && outObj.SPPrintersDataType.length) {
171
+ for (let i = 0; i < outObj.SPPrintersDataType.length; i++) {
172
+ const printer = parseDarwinPrinters(outObj.SPPrintersDataType[i], i);
173
+ result.push(printer);
174
+ }
175
+ }
176
+ } catch (e) {
177
+ util.noop();
178
+ }
179
+ }
180
+ if (callback) {
181
+ callback(result);
182
+ }
183
+ resolve(result);
184
+ });
185
+ }
186
+ if (_windows) {
187
+ util.powerShell('Get-CimInstance Win32_Printer | select PrinterStatus,Name,DriverName,Local,Default,Shared | fl').then((stdout, error) => {
188
+ if (!error) {
189
+ const parts = stdout.toString().split(/\n\s*\n/);
190
+ for (let i = 0; i < parts.length; i++) {
191
+ const printer = parseWindowsPrinters(parts[i].split('\n'), i);
192
+ if (printer.name || printer.model) {
193
+ result.push(printer);
194
+ }
195
+ }
196
+ }
197
+ if (callback) {
198
+ callback(result);
199
+ }
200
+ resolve(result);
201
+ });
202
+ }
203
+ if (_sunos) {
204
+ resolve(null);
205
+ }
206
+ });
207
+ });
208
+ }
209
+
210
+ exports.printer = printer;