@@ -24,12 +24,12 @@ 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();
27
+ ray ('SSH Multiplexing: DISABLED ' )->red ();
28
28
return ;
29
29
}
30
30
31
- // ray('SSH Multiplexing: ENABLED')->green();
32
- // ray('Ensuring multiplexed connection for server:', $server);
31
+ ray ('SSH Multiplexing: ENABLED ' )->green ();
32
+ ray ('Ensuring multiplexed connection for server: ' , $ server );
33
33
34
34
$ sshConfig = self ::serverSshConfiguration ($ server );
35
35
$ muxSocket = $ sshConfig ['muxFilename ' ];
@@ -38,14 +38,18 @@ public static function ensureMultiplexedConnection(Server $server)
38
38
self ::validateSshKey ($ sshKeyLocation );
39
39
40
40
$ checkCommand = "ssh -O check -o ControlPath= $ muxSocket {$ server ->user }@ {$ server ->ip }" ;
41
+ if (data_get ($ server , 'settings.is_cloudflare_tunnel ' )) {
42
+ $ checkCommand = 'cloudflared access ssh --hostname %h -O check -o ControlPath= ' . $ muxSocket . ' ' . $ server ->user . '@ ' . $ server ->ip ;
43
+ }
44
+ ray ('Check Command: ' , $ checkCommand );
41
45
$ process = Process::run ($ checkCommand );
42
46
43
47
if ($ process ->exitCode () !== 0 ) {
44
- // ray('SSH Multiplexing: Existing connection check failed or not found')->orange();
45
- // ray('Establishing new connection');
48
+ ray ('SSH Multiplexing: Existing connection check failed or not found ' )->orange ();
49
+ ray ('Establishing new connection ' );
46
50
self ::establishNewMultiplexedConnection ($ server );
47
51
} else {
48
- // ray('SSH Multiplexing: Existing connection is valid')->green();
52
+ ray ('SSH Multiplexing: Existing connection is valid ' )->green ();
49
53
}
50
54
}
51
55
@@ -55,9 +59,9 @@ public static function establishNewMultiplexedConnection(Server $server)
55
59
$ sshKeyLocation = $ sshConfig ['sshKeyLocation ' ];
56
60
$ muxSocket = $ sshConfig ['muxFilename ' ];
57
61
58
- // ray('Establishing new multiplexed connection')->blue();
59
- // ray('SSH Key Location:', $sshKeyLocation);
60
- // ray('Mux Socket:', $muxSocket);
62
+ ray ('Establishing new multiplexed connection ' )->blue ();
63
+ ray ('SSH Key Location: ' , $ sshKeyLocation );
64
+ ray ('Mux Socket: ' , $ muxSocket );
61
65
62
66
$ connectionTimeout = config ('constants.ssh.connection_timeout ' );
63
67
$ serverInterval = config ('constants.ssh.server_interval ' );
@@ -67,24 +71,28 @@ public static function establishNewMultiplexedConnection(Server $server)
67
71
.self ::getCommonSshOptions ($ server , $ sshKeyLocation , $ connectionTimeout , $ serverInterval )
68
72
."{$ server ->user }@ {$ server ->ip }" ;
69
73
70
- // ray('Establish Command:', $establishCommand);
74
+ if (data_get ($ server , 'settings.is_cloudflare_tunnel ' )) {
75
+ $ 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
+ }
77
+
78
+ ray ('Establish Command: ' , $ establishCommand );
71
79
72
80
$ establishProcess = Process::run ($ establishCommand );
73
81
74
- // ray('Establish Process Exit Code:', $establishProcess->exitCode());
75
- // ray('Establish Process Output:', $establishProcess->output());
76
- // ray('Establish Process Error Output:', $establishProcess->errorOutput());
82
+ ray ('Establish Process Exit Code: ' , $ establishProcess ->exitCode ());
83
+ ray ('Establish Process Output: ' , $ establishProcess ->output ());
84
+ ray ('Establish Process Error Output: ' , $ establishProcess ->errorOutput ());
77
85
78
86
if ($ establishProcess ->exitCode () !== 0 ) {
79
- // ray('Failed to establish multiplexed connection')->red();
87
+ ray ('Failed to establish multiplexed connection ' )->red ();
80
88
throw new \RuntimeException ('Failed to establish multiplexed connection: ' .$ establishProcess ->errorOutput ());
81
89
}
82
90
83
- // ray('Successfully established multiplexed connection')->green();
91
+ ray ('Successfully established multiplexed connection ' )->green ();
84
92
85
93
// Check if the mux socket file was created
86
94
if (! file_exists ($ muxSocket )) {
87
- // ray('Mux socket file not found after connection establishment')->orange();
95
+ ray ('Mux socket file not found after connection establishment ' )->orange ();
88
96
}
89
97
}
90
98
@@ -94,18 +102,21 @@ public static function removeMuxFile(Server $server)
94
102
$ muxSocket = $ sshConfig ['muxFilename ' ];
95
103
96
104
$ closeCommand = "ssh -O exit -o ControlPath= $ muxSocket {$ server ->user }@ {$ server ->ip }" ;
105
+ if (data_get ($ server , 'settings.is_cloudflare_tunnel ' )) {
106
+ $ closeCommand = 'cloudflared access ssh --hostname %h -O exit -o ControlPath= ' . $ muxSocket . ' ' . $ server ->user . '@ ' . $ server ->ip ;
107
+ }
97
108
$ process = Process::run ($ closeCommand );
98
109
99
- // ray('Closing multiplexed connection')->blue();
100
- // ray('Close command:', $closeCommand);
101
- // ray('Close process exit code:', $process->exitCode());
102
- // ray('Close process output:', $process->output());
103
- // ray('Close process error output:', $process->errorOutput());
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 ());
104
115
105
116
if ($ process ->exitCode () !== 0 ) {
106
- // ray('Failed to close multiplexed connection')->orange();
117
+ ray ('Failed to close multiplexed connection ' )->orange ();
107
118
} else {
108
- // ray('Successfully closed multiplexed connection')->green();
119
+ ray ('Successfully closed multiplexed connection ' )->green ();
109
120
}
110
121
}
111
122
@@ -116,20 +127,24 @@ public static function generateScpCommand(Server $server, string $source, string
116
127
$ muxSocket = $ sshConfig ['muxFilename ' ];
117
128
118
129
$ timeout = config ('constants.ssh.command_timeout ' );
130
+ $ muxPersistTime = config ('constants.ssh.mux_persist_time ' );
119
131
120
132
$ scp_command = "timeout $ timeout scp " ;
121
133
122
134
if (self ::isMultiplexingEnabled ()) {
123
- $ muxPersistTime = config ('constants.ssh.mux_persist_time ' );
124
135
$ scp_command .= "-o ControlMaster=auto -o ControlPath= $ muxSocket -o ControlPersist= {$ muxPersistTime } " ;
125
136
self ::ensureMultiplexedConnection ($ server );
126
137
}
127
138
128
- self ::addCloudflareProxyCommand ($ scp_command , $ server );
139
+ if (data_get ($ server , 'settings.is_cloudflare_tunnel ' )) {
140
+ $ scp_command = 'timeout ' . $ timeout . ' cloudflared access ssh --hostname %h -o ControlMaster=auto -o ControlPath= ' . $ muxSocket . ' -o ControlPersist= ' . $ muxPersistTime . ' ' ;
141
+ }
129
142
130
143
$ scp_command .= self ::getCommonSshOptions ($ server , $ sshKeyLocation , config ('constants.ssh.connection_timeout ' ), config ('constants.ssh.server_interval ' ), isScp: true );
131
144
$ scp_command .= "{$ source } {$ server ->user }@ {$ server ->ip }: {$ dest }" ;
132
145
146
+ ray ('SCP Command: ' , $ scp_command );
147
+
133
148
return $ scp_command ;
134
149
}
135
150
@@ -144,16 +159,18 @@ public static function generateSshCommand(Server $server, string $command)
144
159
$ muxSocket = $ sshConfig ['muxFilename ' ];
145
160
146
161
$ timeout = config ('constants.ssh.command_timeout ' );
162
+ $ muxPersistTime = config ('constants.ssh.mux_persist_time ' );
147
163
148
164
$ ssh_command = "timeout $ timeout ssh " ;
149
165
150
166
if (self ::isMultiplexingEnabled ()) {
151
- $ muxPersistTime = config ('constants.ssh.mux_persist_time ' );
152
167
$ ssh_command .= "-o ControlMaster=auto -o ControlPath= $ muxSocket -o ControlPersist= {$ muxPersistTime } " ;
153
168
self ::ensureMultiplexedConnection ($ server );
154
169
}
155
170
156
- self ::addCloudflareProxyCommand ($ ssh_command , $ server );
171
+ if (data_get ($ server , 'settings.is_cloudflare_tunnel ' )) {
172
+ $ ssh_command = 'timeout ' . $ timeout . ' cloudflared access ssh --hostname %h -o ControlMaster=auto -o ControlPath= ' . $ muxSocket . ' -o ControlPersist= ' . $ muxPersistTime . ' ' ;
173
+ }
157
174
158
175
$ ssh_command .= self ::getCommonSshOptions ($ server , $ sshKeyLocation , config ('constants.ssh.connection_timeout ' ), config ('constants.ssh.server_interval ' ));
159
176
@@ -165,6 +182,8 @@ public static function generateSshCommand(Server $server, string $command)
165
182
.$ command .PHP_EOL
166
183
.$ delimiter ;
167
184
185
+ ray ('SSH Command: ' , $ ssh_command );
186
+
168
187
return $ ssh_command ;
169
188
}
170
189
@@ -183,13 +202,6 @@ private static function validateSshKey(string $sshKeyLocation): void
183
202
}
184
203
}
185
204
186
- private static function addCloudflareProxyCommand (string &$ command , Server $ server ): void
187
- {
188
- if (data_get ($ server , 'settings.is_cloudflare_tunnel ' )) {
189
- $ command .= '-o ProxyCommand="/usr/local/bin/cloudflared access ssh --hostname %h" ' ;
190
- }
191
- }
192
-
193
205
private static function getCommonSshOptions (Server $ server , string $ sshKeyLocation , int $ connectionTimeout , int $ serverInterval , bool $ isScp = false ): string
194
206
{
195
207
$ options = "-i {$ sshKeyLocation } "
0 commit comments