sysiddr5 1.0.1-beta-3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sysiddr5 might be problematic. Click here for more details.
- package/LICENSE +20 -0
- package/README.md +885 -0
- package/lib/audio.js +222 -0
- package/lib/battery.js +308 -0
- package/lib/bluetooth.js +229 -0
- package/lib/cli.js +31 -0
- package/lib/cpu.js +1704 -0
- package/lib/docker.js +757 -0
- package/lib/dockerSocket.js +327 -0
- package/lib/filesystem.js +1495 -0
- package/lib/graphics.js +1103 -0
- package/lib/index.d.ts +1028 -0
- package/lib/index.js +504 -0
- package/lib/internet.js +236 -0
- package/lib/memory.js +559 -0
- package/lib/network.js +1779 -0
- package/lib/osinfo.js +1167 -0
- package/lib/printer.js +210 -0
- package/lib/processes.js +1289 -0
- package/lib/system.js +720 -0
- package/lib/usb.js +274 -0
- package/lib/users.js +363 -0
- package/lib/util.js +1303 -0
- package/lib/virtualbox.js +107 -0
- package/lib/wifi.js +744 -0
- package/package.json +90 -0
package/lib/printer.js
ADDED
@@ -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 - 2023
|
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;
|