diff --git a/README.md b/README.md index 3c7f27f..4415dec 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,14 @@ in your `bootstrap/app.php` for Lumen services or add it to your `providers` arr ## Configuration All configuration can and should be done in your `.env` file. ```ini +; Process used to verify connection +; Use bash if your distro uses nmap-ncat (RHEL/CentOS 7.x) +TUNNELER_VERIFY_PROCESS=nc + ; Path to the nc executable TUNNELER_NC_PATH=/usr/bin/nc +; Path to the bash executable +TUNNELER_BASH_PATH=/usr/bin/bash ; Path to the ssh executable TUNNELER_SSH_PATH=/usr/bin/ssh ; Path to the nohup executable diff --git a/config/tunneler.php b/config/tunneler.php index d46072e..0ab9865 100644 --- a/config/tunneler.php +++ b/config/tunneler.php @@ -1,6 +1,10 @@ env('TUNNELER_VERIFY_PROCESS', 'nc'), + 'nc_path' => env('TUNNELER_NC_PATH', 'nc'), + 'bash_path' => env('TUNNELER_BASH_PATH', 'bash'), 'ssh_path' => env('TUNNELER_SSH_PATH', 'ssh'), 'nohup_path' => env('TUNNELER_NOHUP_PATH', 'nohup'), @@ -20,4 +24,5 @@ 'ssh_verbosity' => env('SSH_VERBOSITY',''), 'ssh_options' => env('TUNNELER_SSH_OPTIONS', ''), 'nohup_log' => env('NOHUP_LOG', '/dev/null'), + ]; diff --git a/src/Jobs/CreateTunnel.php b/src/Jobs/CreateTunnel.php index da49352..911a3d6 100644 --- a/src/Jobs/CreateTunnel.php +++ b/src/Jobs/CreateTunnel.php @@ -23,12 +23,19 @@ class CreateTunnel public function __construct() { + $this->ncCommand = sprintf('%s -z %s %d > /dev/null 2>&1', config('tunneler.nc_path'), config('tunneler.local_address'), config('tunneler.local_port') ); + $this->bashCommand = sprintf('timeout 1 %s -c \'cat < /dev/null > /dev/tcp/%s/%d\' > /dev/null 2>&1', + config('tunneler.bash_path'), + config('tunneler.local_address'), + config('tunneler.local_port') + ); + $this->sshCommand = sprintf('%s %s %s -N -i %s -L %d:%s:%d -p %d %s@%s', config('tunneler.ssh_path'), config('tunneler.ssh_options'), @@ -46,13 +53,13 @@ public function __construct() public function handle(): int { - if ($this->verifyTunnel()){ + if ($this->verifyTunnel()) { return 1; } $this->createTunnel(); - if ($this->verifyTunnel()){ + if ($this->verifyTunnel()) { return 2; } @@ -81,6 +88,10 @@ protected function createTunnel() */ protected function verifyTunnel() { + if (config('tunneler.verify_process') == 'bash') { + return $this->runCommand($this->bashCommand); + } + return $this->runCommand($this->ncCommand); }