ssh port forwarding notes

mySQL access using ssh:

  1. open terminal
  2. ssh -L 3306:[username]@[database system]:3306 [username]@[ssh gateway]

Tunneling to an internal system using ssh:

  1. open terminal
  2. ssh -L 7777:[username]@[internal system]:22 [username]@[ssh gateway]
  3. open a second terminal
  4. ssh -p 7777 [username]@localhost

Tunneling to an internal IMAP server through ssh when away from the office:

  1. open terminal
  2. update your /etc/hosts file to override the DNS entry for your internal server with localhost:
    1. 127.0.0.1 imap.example.com
  3. open terminal and execute the following:
  4. sudo ssh -i ~/.ssh/id_dsa -L 993:[internal imap server address]:993 [username]@[ssh gateway]
  5. once logged into the ssh gateway server you may need to keep the connection from timing out by issuing a command such as this:
  6. vmstat 30

Notice that the command is issued as root, this is to allow the forwarding of a privileged port (993 if the connection is SSL encrypted or 143 if not). By forwarding the privileged port there is no need to change any of the settings in you email program since the /etc/hosts file overrides the DNS lookup of your mail server.

delete folders

To delete all of the subversion (.svn), CVS (.cvs) or hidden MAC .DS_Store folders from a directory tree use one of the following commands from the console:

rm -rf `find . -type d -name .svn`
rm -rf `find . -type d -name .cvs`
rm -rf `find . -type d -name .DS_Store`

for files use:

rm `find . -name ‘*.tmp’`

rolling directory backup using cron and tar

First lets create a gzip compressed tar file of the directory to be backed up:

tar --create --gzip --absolute-names --preserve-permissions --file=/backups/etc-`date +"%b_%d_%Y"`.tar.gz /etc

this will create a file called etc-Apr_15_2007.tar.gz in your /backups folder. To create a 7 day rolling backup you can use the following:

tar --create --gzip --absolute-names --preserve-permissions --file=/backups/etc-`date +"%A"`.tar.gz /etc

this will create a backup file called etc-Sunday.tar.gz.
To schedule the backup with cron add the following to your crontab file (crontab -e):

0 1 * * * tar --create --gzip --absolute-names --preserve-permissions --file=/backups/etc-`date +"\%A"`.tar.gz /etc

This will run the backup at 1 am every day. Note the use of \% to escape the % symbol in the crontab file.

 

HTTPit Web Server

HTTPit is a tiny multi-threaded executable java based HTTP server (under 10kb). It was built as a simple challenge to myself, how much functionality could be coded into a .jar file under 10Kb in size. It supports SSI and CGI (to the point that PHP applications function correctly) and supports both GET and POST request, 52 document types, virtual hosting ….

:. System Requirements

This server uses the regular expressions support added in JDK1.4.x and therefore requires that version as a minimum.

:. Download

Click here to download:
HTTPit.zip (182 KB)

:. Features

• Very small executable (under 10kb).
• Virtual hosting support.
• Can deal with multiple requests at the same time.
• Support for 52 content-types (images, videos, HTML, etc).
• Directory browsing features.
• Index page retrieval without specifying full path.
• Request logging.
• Support for both GET and POST requests.
• Support for If-Modified-Since caching.
• Limited support for Server Side Includes.
• Support for CGI scripts (including /cgi-bin directory support).

:. Usage

java -jar HTTPit.jar [options]

Options include:

• port=8080 - the port the server will listen on
• timeout=10000 - the server socket timeout
• webroot=./webroot - the default root web directory
• webroot.[host_name]=./webroot - the root web directory for a virtual host
• index.files=index.html - comma separated list of default index files used when no file is passed
• dir.browsing=true - allow directory browsing
• admin=root@localhost - SERVER_ADMIN value passed as an env variable to CGI scripts
• cgi.[file_ext]=[executable] - file extensions that should be processed as CGI, followed by the executable that should be used to execute the file
• mime.[file_ext]=[mime type] - file extension followed by its mime type, if no mime type is found application/octet-stream will be used
• response.[code]=[reason phrase] - response code followed by its reason phrase
• response.[code].alt=[/path/to/err_page.html] - send alternate error page for 4xx and 5xx response codes

:. Example usages

java -jar HTTPit.jar mime.tar=application/x-tar

Launch with additional support for files of type .tar

java -jar HTTPit.jar cgi.php=/usr/local/bin/php index.files=index.html,index.php

Launch with support for .php files using CGI and include index.php as a valid index file.

java -jar HTTPit.jar webroot.www.foo.com=./webroot2

Virtual host www.foo.com using the ./webroot2 folder as its root directory.

:. Static Page Load Test

The static page load test results for this server detailed below involved testing 10 concurrent users against a simple html page (using the openload tool, http://openwebload.sourceforge.net/ ).

openload http://192.168.0.100:8000/index.html 10

  • Total TPS: 36.08 
  • Avg. Response time: 0.277 sec. 
  • Max Response time: 1.442 sec 
  • Total Requests: 68988 
  • Total Errors: 0

:. CGI Load Test

The CGI load test results for this server detailed below involved testing 10 concurrent users against a simple perl based CGI script (using the openload tool).

openload http://192.168.0.100:8000/cgi-bin/counter.cgi 10

  • Total TPS: 29.87 
  • Avg. Response time: 0.335 sec.
  • Max Response time: 1.760 sec
  • Total Requests: 57403
  • Total Errors: 0