server

Reverse SSH Tunnel

Have you ever wanted to ssh to your Linux box that sits behind NAT? Now you can with reverse SSH tunneling. This document will show you step by step how to set up reverse SSH tunneling. The reverse SSH tunneling should work fine with Unix like systems.

Let’s assume that Destination’s IP is 192.168.20.83 (Linux host that you want to access).

You want to access from Linux client with IP 8.7.6.5

Destination (192.168.20.83) <- |NAT| <- Source (8.7.6.5)

  1. SSH from the destination to the source (with public ip/fqdn) using command below:
    ssh -R 1339:localhost:22 sourceuser@8.7.6.5

    * port 1339 can be any unused port.

  2. Now you can SSH from source to destination through SSH tuneling:
    ssh destinationuser@localhost -p 1339
  3. 3rd party servers can also access 192.168.20.83 through Destination (8.7.6.5).

    Destination (192.168.20.83) <- |NAT| <- Source (8.7.6.5) <- 3rd party server

  4. From 3rd party server:
    ssh sourceuser@8.7.6.5
  5. After the sucessful login to Source:
    ssh destinationuser@localhost -p 1339

    * the connection between destination and source must be alive at all time.

Tip: you may run a command (e.g. watch, top) on Destination to keep the connection active.

How to set up a dynamic SSH Tunnel (with PuTTY)

Strict requirement: a remote linux server with an openssh-server active daemon.

Let’s open PuTTY and start:

  • Insert your server fqdn/ip
  • Go to Connection Tab -> SSH -> Tunnels
  • Into Destination field, choose Dynamic
  • Choose a TCP port number that is free to use locally on your windows computer (usually any number above 1024 is ok, let’s assume 1339) and insert it into Source field
  • Click Add
  • Click Open button, connect to your server via ssh with username and password and leave the session open and active

Now the tunnel is set up to localhost on the tcp port 1339 that you specified as source port.

Now you could setup you progrma to use a SOCKS5 proxy to use the tunnel.

Conquest Dicom Server Mysql on Debian (dgate)

This is a quick guide to install ConQuest DICOM server on Debian 8 (Jessie) using MySQL as ConQuest database.

BEFORE PROCEEDING
I assume that you’re logged in as “root” and the image files will be stored into the directory “/data” and you’ve already installed your debian server with a standard configuration.
I’m used with “nano” to edit files, if you’re not familiar with “nano”, please use another editor (eg: “vim”).

If you’re updating your ConQuest version, backup these files before proceeding:

/etc/conquest-dicom-server/acrnema.map
/etc/conquest-dicom-server/dicom.ini

Don’t restore the above files to your new version of ConQuest. Use them just to check the information you need to change at the new files. Overwriting files from a newer version of ConQuest with files from an older version may cause ConQuest malfunctioning.

INSTALLING
First of all, we want to install the latest version of each needed package, so we call:
# apt-get update

And then install the recommended packages:
# apt-get install apache2 mysql-server openssh-server conquest-mysql

Optionally i install too:
#phpmyadmin dcmtk apache2-mpm-itk

Now we create the database that ConQuest will use:
# mysql -u root -p
create database conquest;
quit;

The directory for ConQuest files is:
# /etc/conquest-dicom-server

Enter the ConQuest directory:
# cd /etc/conquest-dicom-server

Edit the file dicom.ini to set up your server, now you define the server Application Entity Title (AET), its communication port, the user and the password that ConQuest will use to connect to MySQL
The lines that aren’t listed here are the lines that I don’t make any changes, so leave them alone:
# nano dicom.ini
MyACRNema = SERVER_AET
TCPPort = 104 # the server communication port
Password =
FixPhilips = 1 # avoids problems with Patient ID from some Philips systems
FixKodak = 1 # avoids problems with Patient ID from some Kodak/Carestream systems
IgnoreOutOfMemoryErrors = 1 # avoids ConQuest interruptions when out of memory errors occurs
FileNameSyntax = 8 # determines the name of stored files (see page 52 of windowsmanual.pdf)
DroppedFileCompression = jk # store dropped files using Lossless JPEG2000
IncomingCompression = jk # store image files through DICOM communication using Lossless JPEG2000
PACSName = # for banner and debug information
MAGDevice0 /data/ # where the images will be stored

Create the directory to store the images:
# mkdir /data

Edit the the file that contain associated remote DICOM nodes that will communicate with this server:
# nano acrnema.map

(Re)build the database verbosely:
# dgate -v -r

SCRIPTS
I’ve developed some simple scripts to make my life easier. Here they are:

(Re)start Conquest
(Re)start script for ConQuest saving logs into “serverstatus.log” file:
# nano /usr/local/bin/start

#!/bin/bash
pkill -9 dgate
dgate -^logfilename.log &

Keep Server Alive
This script checks if “dgate” proccess is running, if not (server crashed), the script restarts it:
# nano /usr/local/bin/keepalive

#!/bin/bash
pgrep dgate
if [ $? -ne 0 ]
then /usr/local/bin/start
fi

Send Yesterday’s Studies To Another Server
This script sends every yesterday’s studies to another server
# nano /usr/local/bin/dgateyesterday

#!/bin/bash
DATE=$(date -d 'yesterday' + %Y%m%d)
dgate --movestudies:SRC_AET,DEST_AET,$DATE
wait

Make all scripts executables:
# chmod a+x /usr/local/bin/*

Schedule the execution of scripts:
# crontab -e

Reload cron to activate the new entries at “/etc/crontab”:
# /etc/init.d/cron restart

Some Useful Commands

Load new DICOM nodes after editing acrnema.map:
# dgate –read_amap:
List of loaded DICOM nodes:
# dgate –get_amaps:
Transferring studies from one server to another:
# dgate –movestudy:patientID:studyuid