Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --redirect.sh
- #!/bin/bash
- #$1 = "internal" port
- #$2 = IP
- #$3 = port
- fifoname = "revprox" + $1 #unique backpipe
- nc -l $1 0<$fifoname | nc $2 $3 1>$fifoname #redirect doublepipe
- --newredir.sh
- #!/bin/bash
- #$1 "internal" port
- #$2 IP
- #$3 port
- #$4 lifetime (seconds)
- ./redirect.sh $1 $2 $3 & #run in background
- pid=$! #process ID in $!
- sleep $4
- kill -9 $pid #kill it (-9 = extra hard)
- --form.php
- <form action="newredirect.php" method="POST">
- The IP to forward to: <input type="text" name="IP" /><br/>
- The port to forward to: <input type="text" name="port" /><br/>
- <input type="submit" name="Forward" />
- </form>
- --newredirect.php
- if( ! preg_match( '/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $_POST['IP'] ) )
- die( "Invalid IP" );
- if( ! preg_match( '/[0-9]*/', $_POST['port'] ) )
- die( "Invalid port" );
- if( $_POST['IP'] == "MY OWN IP" )
- die( "Not forwarding to myself" ); //dont know why, but I guess this could end "bad"
- mysql_connect( ... );
- mysql_select_db( "reverse_proxy" );
- $res = mysql_query( "SELECT * FROM ports WHERE expires <= NOW() LIMIT 1" );
- $port = mysql_fetch_object( $res );
- if ( $port == null )
- die( "Sorry, no free ports. Please try again later." );
- exec( "./newredir.sh " . $port->port . " " . $_POST['IP'] . " " . $_POST['port'] . "1800 &" );
- mysql_query( "UPDATE ports SET expires=DATE_ADD(NOW(), INTERVAL 30 MINUTE) WHERE port = " . $port->port );
- echo( "Hooray, you are now reachable at " . $_SERVER['HTTP_HOST'] . ":" . $port->port . "!" );
- --ports_table.sql
- CREATE TABLE IF NOT EXISTS `ports` (
- `port` int(11) NOT NULL,
- `expires` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`port`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Add Comment
Please, Sign In to add comment