@@ -24,13 +24,9 @@ public static function serverSshConfiguration(Server $server)
24
24
public static function ensureMultiplexedConnection (Server $ server )
25
25
{
26
26
if (! self ::isMultiplexingEnabled ()) {
27
- ray ('SSH Multiplexing: DISABLED ' )->red ();
28
27
return ;
29
28
}
30
29
31
- ray ('SSH Multiplexing: ENABLED ' )->green ();
32
- ray ('Ensuring multiplexed connection for server: ' , $ server );
33
-
34
30
$ sshConfig = self ::serverSshConfiguration ($ server );
35
31
$ muxSocket = $ sshConfig ['muxFilename ' ];
36
32
$ sshKeyLocation = $ sshConfig ['sshKeyLocation ' ];
@@ -41,15 +37,10 @@ public static function ensureMultiplexedConnection(Server $server)
41
37
if (data_get ($ server , 'settings.is_cloudflare_tunnel ' )) {
42
38
$ checkCommand = 'cloudflared access ssh --hostname %h -O check -o ControlPath= ' . $ muxSocket . ' ' . $ server ->user . '@ ' . $ server ->ip ;
43
39
}
44
- ray ('Check Command: ' , $ checkCommand );
45
40
$ process = Process::run ($ checkCommand );
46
41
47
42
if ($ process ->exitCode () !== 0 ) {
48
- ray ('SSH Multiplexing: Existing connection check failed or not found ' )->orange ();
49
- ray ('Establishing new connection ' );
50
43
self ::establishNewMultiplexedConnection ($ server );
51
- } else {
52
- ray ('SSH Multiplexing: Existing connection is valid ' )->green ();
53
44
}
54
45
}
55
46
@@ -59,10 +50,6 @@ public static function establishNewMultiplexedConnection(Server $server)
59
50
$ sshKeyLocation = $ sshConfig ['sshKeyLocation ' ];
60
51
$ muxSocket = $ sshConfig ['muxFilename ' ];
61
52
62
- ray ('Establishing new multiplexed connection ' )->blue ();
63
- ray ('SSH Key Location: ' , $ sshKeyLocation );
64
- ray ('Mux Socket: ' , $ muxSocket );
65
-
66
53
$ connectionTimeout = config ('constants.ssh.connection_timeout ' );
67
54
$ serverInterval = config ('constants.ssh.server_interval ' );
68
55
$ muxPersistTime = config ('constants.ssh.mux_persist_time ' );
@@ -75,25 +62,11 @@ public static function establishNewMultiplexedConnection(Server $server)
75
62
$ establishCommand = 'cloudflared access ssh --hostname %h -fNM -o ControlMaster=auto -o ControlPath= ' . $ muxSocket . ' -o ControlPersist= ' . $ muxPersistTime . ' ' . self ::getCommonSshOptions ($ server , $ sshKeyLocation , $ connectionTimeout , $ serverInterval ) . $ server ->user . '@ ' . $ server ->ip ;
76
63
}
77
64
78
- ray ('Establish Command: ' , $ establishCommand );
79
-
80
65
$ establishProcess = Process::run ($ establishCommand );
81
66
82
- ray ('Establish Process Exit Code: ' , $ establishProcess ->exitCode ());
83
- ray ('Establish Process Output: ' , $ establishProcess ->output ());
84
- ray ('Establish Process Error Output: ' , $ establishProcess ->errorOutput ());
85
-
86
67
if ($ establishProcess ->exitCode () !== 0 ) {
87
- ray ('Failed to establish multiplexed connection ' )->red ();
88
68
throw new \RuntimeException ('Failed to establish multiplexed connection: ' .$ establishProcess ->errorOutput ());
89
69
}
90
-
91
- ray ('Successfully established multiplexed connection ' )->green ();
92
-
93
- // Check if the mux socket file was created
94
- if (! file_exists ($ muxSocket )) {
95
- ray ('Mux socket file not found after connection establishment ' )->orange ();
96
- }
97
70
}
98
71
99
72
public static function removeMuxFile (Server $ server )
@@ -105,19 +78,7 @@ public static function removeMuxFile(Server $server)
105
78
if (data_get ($ server , 'settings.is_cloudflare_tunnel ' )) {
106
79
$ closeCommand = 'cloudflared access ssh --hostname %h -O exit -o ControlPath= ' . $ muxSocket . ' ' . $ server ->user . '@ ' . $ server ->ip ;
107
80
}
108
- $ process = Process::run ($ closeCommand );
109
-
110
- ray ('Closing multiplexed connection ' )->blue ();
111
- ray ('Close command: ' , $ closeCommand );
112
- ray ('Close process exit code: ' , $ process ->exitCode ());
113
- ray ('Close process output: ' , $ process ->output ());
114
- ray ('Close process error output: ' , $ process ->errorOutput ());
115
-
116
- if ($ process ->exitCode () !== 0 ) {
117
- ray ('Failed to close multiplexed connection ' )->orange ();
118
- } else {
119
- ray ('Successfully closed multiplexed connection ' )->green ();
120
- }
81
+ Process::run ($ closeCommand );
121
82
}
122
83
123
84
public static function generateScpCommand (Server $ server , string $ source , string $ dest )
@@ -143,8 +104,6 @@ public static function generateScpCommand(Server $server, string $source, string
143
104
$ scp_command .= self ::getCommonSshOptions ($ server , $ sshKeyLocation , config ('constants.ssh.connection_timeout ' ), config ('constants.ssh.server_interval ' ), isScp: true );
144
105
$ scp_command .= "{$ source } {$ server ->user }@ {$ server ->ip }: {$ dest }" ;
145
106
146
- ray ('SCP Command: ' , $ scp_command );
147
-
148
107
return $ scp_command ;
149
108
}
150
109
@@ -182,8 +141,6 @@ public static function generateSshCommand(Server $server, string $command)
182
141
.$ command .PHP_EOL
183
142
.$ delimiter ;
184
143
185
- ray ('SSH Command: ' , $ ssh_command );
186
-
187
144
return $ ssh_command ;
188
145
}
189
146
0 commit comments