Thomas Sampson


Leave a comment

SSH Port Redirection

This is a really useful technique I recently discovered which allows you to bind a port on your local machine to the local port on a remote machine. Why would you want to do this?

Well in my case I was working on a remote web server via ssh, setting up some web aplications on various different ports. The hosting company had yet to open these ports to the outside world. However, this technique allowed me to bind the local ports on the remote machine (running the web applications) to my local machine. This allowed me to test and configure each application as if it was installed on my local machine, simply by accessing localhost:xx in my browser. The port numbers don’t even have to match! I ended up binding remote port 8080 to port 80 on my local machine.

This can be achieved¬†by issuing the following command on the local machine…

ssh $REMOTE_IP -L $REMOTE_PORT:localhost:$LOCAL_PORT

Example binding remote 8080 to local 80:

ssh myhost.com -L 8080:localhost:80


Leave a comment

Very good basic AJAX tutorial

simple AJAX tutorial, goes through sending a request to the server (as a querystring) and getting the response text, and applying it to a div tag

http://rajshekhar.net/blog/archives/85-Rasmus-30-second-AJAX-Tutorial.html

Notes

Create a new XMLHTTP request object named “http”


function createRequestObject() {

var ro;
var browser = navigator.appName;
if(browser == “Microsoft Internet Explorer”){
ro = new ActiveXObject(“Microsoft.XMLHTTP”);
}else{
ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

Create a request sender poining it to an aspx page with the querystring “number” and tell it which function to use to handle the request (“handleResponse”)

function sndReq(thenumber) { http.open(‘get’, ‘example1service.aspx?number=’+thenumber);
http.onreadystatechange = handleResponse;
http.send(null);
}

above; the “example1service.aspx” page simply takes the querystring and Response.Write ‘s it* 10 (for example) , also a try/catch for if the data sent was not an integer.

NOTE: the example1service.aspx page has ContentType=”Text” in the header

Create the request handler “handleResponse”, returnpanel is a div tag to recieve the contents of the request.

function handleResponse() {

if(http.readyState == 4){
var response = http.responseText;

document.getElementById(‘returnpanel’).innerHTML = response;

}

}

THE HTML

The HTML is simple a text input field which fires the sndReq() function on the keyup event, sending its own value as an argument , example

onkeyup=”sndReq(form.inputtextbox.value)”

The html also contains the div tag to display the response with id=”returnpanel”