-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstenoread.js
executable file
·39 lines (33 loc) · 1014 Bytes
/
stenoread.js
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
#!/usr/bin/env node
var fs = require('fs');
var https = require('https');
const args = process.argv.slice(2);
// Allow Self-Signed Certificates
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
// Read Stenographer configuration
var CONFIG = JSON.parse(fs.readFileSync("/etc/stenographer/config"));
var HOST = CONFIG.Host || '127.0.0.1';
var PORT = CONFIG.Port || '1234';
var CPATH = CONFIG.CertPath || "/etc/stenographer/certs";
// Check for Query
if (!args[0]) { console.error('Missing query!'); process.exit(1); }
var query = args[0];
var options = {
hostname: HOST,
port: PORT,
path: '/query',
method: 'POST',
key: fs.readFileSync( CPATH+'/client_key.pem'),
cert: fs.readFileSync( CPATH+'/client_cert.pem'),
ca: fs.readFileSync( CPATH+'/ca_key.pem')
};
var req = https.request(options, function(res) {
res.on('data', function(data) {
process.stdout.write(data);
});
});
req.write(query);
req.end();
req.on('error', function(e) {
console.error(e);
});