-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSSHTunnel.ahk
More file actions
executable file
·65 lines (52 loc) · 1.47 KB
/
SSHTunnel.ahk
File metadata and controls
executable file
·65 lines (52 loc) · 1.47 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
#Persistent
; TODO: Add storing configuration in ini file
; TODO: Add autoconnect on start
; TODO: Add autoreconnect on connection error
SendMode Input
SetWorkingDir, %A_ScriptDir%
SSHCommand := "ssh ubuntu@144.21.32.19 -D 127.0.0.1:1080 -CnNT"
SSHProcessPID := -1
IconConnected := A_ScriptDir . "\icons\connection_green.ico"
IconDisconnected := A_ScriptDir . "\icons\connection.ico"
Menu, Connection, Add, Start, ConnectionStart
Menu, Connection, Add, Stop, ConnectionStop
Menu, Connection, Add, Restart, ConnectionRestart
Menu, Tray, Add
Menu, Tray, Add, Connection, :Connection
Menu, Tray, Icon, %IconDisconnected%
OnExit, ScriptExit
SetTimer, CheckConnectionStatus, 3000
Return
ConnectionStart:
if (SSHProcessPID <= 0){
Run, %SSHCommand%, %A_ScriptDir%, Hide, SSHProcessPID
}
Return
ConnectionStop:
if (SSHProcessPID > 0){
Process, Close, %SSHProcessPID%
SSHProcessPID := -1
}
Return
ConnectionRestart:
Gosub, ConnectionStop
Sleep, 3000
Gosub, ConnectionStart
Return
CheckConnectionStatus:
If (SSHProcessPID <= 0){
Menu, Tray, Icon, %IconDisconnected%
} Else {
Process, Exist, %SSHProcessPID%
If (ErrorLevel > 0 ){
Menu, Tray, Icon, %IconConnected%
} Else {
SSHProcessPID := -1
Menu, Tray, Icon, %IconDisconnected%
}
}
Return
ScriptExit:
Gosub, ConnectionStop
ExitApp, 0
Return