-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh.js
More file actions
66 lines (54 loc) · 1.52 KB
/
ssh.js
File metadata and controls
66 lines (54 loc) · 1.52 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
import { Client } from 'ssh2';
import Config from './config.js';
import fs from 'fs';
export default class BitlairBank
{
pay3DPrint(weight, username)
{
try {
const conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.shell((err, stream) => {
if (err) throw err;
stream.on('close', () => {
console.log('Stream :: close');
conn.end();
});
stream.on('data', (data) => {
console.log('OUTPUT: ' + data.toString());
// You can conditionally respond to prompts here
// For example:
// if (data.toString().includes('Username:')) stream.write('your_username\n');
});
stream.stderr.on('data', (data) => {
console.error('STDERR: ' + data.toString());
});
// Initial command that expects interactive input
stream.write('3dprint\n');
// You can chain writes like:
stream.write(weight + '\n');
stream.write(username + '\n');
});
}).connect({
host: Config.BANK_HOST,
username: Config.BANK_USERNAME,
privateKey: fs.readFileSync(Config.BANK_PRIVATE_KEY_PATH), // path to your private key
passphrase: Config.BANK_PASSPHRASE,
//password: Config.BANK_PASSWORD
});
}
catch(exception)
{
console.log('SSH failed for print with weight:', weight, ', username: ', username, ' with exception ', exception);
}
}
}
console.log('BITLAIRBANK INIT');
/*
let test = new BitlairBank();
setTimeout(() => {
console.log('TESTING PAYING ');
test.pay3DPrint(1, 'djo');
}, 5000);
*/