Skip to content

Commit 78af2dd

Browse files
author
Jim Hofer
committed
Added option to use bash to verify the connection instead of netcat.
Netcat verification does not work properly with RHEL/CentOS 7.x
1 parent a24b331 commit 78af2dd

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ in your `bootstrap/app.php` for Lumen services or add it to your `providers` arr
3030
## Configuration
3131
All configuration can and should be done in your `.env` file.
3232
```ini
33+
; Process used to verify connection
34+
; Use bash if your distro uses nmap-ncat (RHEL/CentOS 7.x)
35+
TUNNELER_VERIFY_PROCESS=nc
36+
3337
; Path to the nc executable
3438
TUNNELER_NC_PATH=/usr/bin/nc
39+
; Path to the bash executable
40+
TUNNELER_BASH_PATH=/usr/bin/bash
3541
; Path to the ssh executable
3642
TUNNELER_SSH_PATH=/usr/bin/ssh
3743
; Path to the nohup executable

config/tunneler.php

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22
return [
3+
4+
'verify_process' => env('TUNNELER_VERIFY_PROCESS', 'nc'),
5+
36
'nc_path' => env('TUNNELER_NC_PATH', 'nc'),
7+
'bash_path' => env('TUNNELER_BASH_PATH', 'bash'),
48
'ssh_path' => env('TUNNELER_SSH_PATH', 'ssh'),
59
'nohup_path' => env('TUNNELER_NOHUP_PATH', 'nohup'),
610

@@ -20,4 +24,5 @@
2024
'ssh_verbosity' => env('SSH_VERBOSITY',''),
2125
'ssh_options' => env('TUNNELER_SSH_OPTIONS', ''),
2226
'nohup_log' => env('NOHUP_LOG', '/dev/null'),
27+
2328
];

src/Jobs/CreateTunnel.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ class CreateTunnel
2323

2424
public function __construct()
2525
{
26+
2627
$this->ncCommand = sprintf('%s -z %s %d > /dev/null 2>&1',
2728
config('tunneler.nc_path'),
2829
config('tunneler.local_address'),
2930
config('tunneler.local_port')
3031
);
3132

33+
$this->bashCommand = sprintf('timeout 1 %s -c \'cat < /dev/null > /dev/tcp/%s/%d\' > /dev/null 2>&1',
34+
config('tunneler.bash_path'),
35+
config('tunneler.local_address'),
36+
config('tunneler.local_port')
37+
);
38+
3239
$this->sshCommand = sprintf('%s %s %s -N -i %s -L %d:%s:%d -p %d %s@%s',
3340
config('tunneler.ssh_path'),
3441
config('tunneler.ssh_options'),
@@ -46,13 +53,13 @@ public function __construct()
4653

4754
public function handle(): int
4855
{
49-
if ($this->verifyTunnel()){
56+
if ($this->verifyTunnel()) {
5057
return 1;
5158
}
5259

5360
$this->createTunnel();
5461

55-
if ($this->verifyTunnel()){
62+
if ($this->verifyTunnel()) {
5663
return 2;
5764
}
5865

@@ -81,6 +88,10 @@ protected function createTunnel()
8188
*/
8289
protected function verifyTunnel()
8390
{
91+
if (config('tunneler.verify_process') == 'bash') {
92+
return $this->runCommand($this->bashCommand);
93+
}
94+
8495
return $this->runCommand($this->ncCommand);
8596
}
8697

0 commit comments

Comments
 (0)