-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconnect-cert.mjs
59 lines (52 loc) · 2.14 KB
/
connect-cert.mjs
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
import {sack} from "sack.vfs"
const enc = new TextDecoder("utf-8"); // convert arraybuffer to string
const priv = enc.decode( sack.Volume.mapFile( "rsa" ) );
//console.log( "Priv?", priv );
const ssh = sack.SSH();
const ssh_alt = new sack.SSH();
ssh.connect( { address:"localhost:2222", port:22, trace:true
, user:"root", password: ""
, privKey: priv
, pubKey:null // pubKey can be gotten from the private key
, trace: false
}
).then( (fingerprint)=>{
console.log( "Connect worked forssh", fingerprint );
console.log( "Make channel1:" );
ssh.Channel( { type:"session", windowSize: 4096, packetSize: 4096 } ).then( (channel)=>{
console.log( "First channel result?", channel );
} );
console.log( "Make channel2:" );
ssh.Channel( ).then( (channel)=>{
console.log( "Generic channel result:", channel );
channel.read( (buf)=>{
console.log( "Channel data:", buf );
} );
channel.readBinary = true;
channel.pty().then( async ()=>{
console.log( "Pty done" );
await channel.setenv( "FOO", "bar" ).then( ()=>{
console.log( "setEnv Done" );
} ).catch( (err)=>{ console.log( "Environment error:", err ) } );
channel.shell().then( ()=>{
console.log( "Shell started..." );
channel.send( "cd /\nls\n" );
//setTimeout( ()=>{ channel.send( "cd /\nls\n" );}, 100 );
} );
} );
} );
} ).catch( (err)=>{
console.log( "Connect error:", err ); }
);
if( false ) {
// test various address connection errors to be thrown.
ssh_alt.connect( { address: "10.173.0.2" } ).catch( (err)=>{
console.log( "Addr error:", err );
ssh_alt.connect( {address:"10.173.0.1:23" } ).catch( (err)=>{
console.log( "port error:", err );
ssh_alt.connect( {address:"1000.1.2.3"} ).catch( (err)=>{
console.log( "number error:", err );
} )
} );
} );
}