Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/tunneler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
return [

'verify_process' => 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'),

Expand All @@ -20,4 +24,5 @@
'ssh_verbosity' => env('SSH_VERBOSITY',''),
'ssh_options' => env('TUNNELER_SSH_OPTIONS', ''),
'nohup_log' => env('NOHUP_LOG', '/dev/null'),

];
15 changes: 13 additions & 2 deletions src/Jobs/CreateTunnel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down