Monthly Archives: February 2009

SSH proxy – Running SSH over blocked ports, SSH on mobile phones, SSH over HTTP

Imagine yourself in a scenario where you’re a behind a firewall and cannot access the SSH, or you’re controlling your servers via your mobile. Here’s a quick way to manage your servers through HTTP via command line. You can fire scripts, run shell commands etc.

Be careful, it will not ask you any username/password and runs with username Apache/SYSTEM.

The script is tested over linux and windows servers!

ssh-over-http1

ssh-over-http2

All you need is an Apache server with PHP installed. Just create a PHP file and insert the following code.

Put in a comment if this really helped you!

//— BEGIN OF CODE—-

<html>
<head>
<title>HussuLinux SSH over HTTP…</title>
</head>
<body>
<form id=”form1″ name=”form1″ method=”post” action=””>
<label>Enter Command
<input type=”text” name=”cmd” />
</label>
<input type=”submit” name=”Submit” value=”Submit” />
</form>

Output :
<textarea cols=”100″ rows=”30″>
<?php
$cmd = $_POST[‘cmd’];
if ($cmd==””)
{
//Do Nothing!
}
else
{
echo htmlspecialchars((shell_exec($cmd)));
}
?>
</textarea>
</body>
</html>

//— END OF CODE—–

Webmethods running linux commands as a java service

Recently a friend asked me how in webmethods, she could fire linux specific utility tasks. She wanted to find out if the disk space is full on linux. This can be done very easily by the “df- kh” command. But how to invoke this through webmethods?

Solution: Follow the steps below.

Step 1: Create a Java Service with the following input and output

webmethods-java-service-1

Step 2: Paste in the following code:

//—- BEGIN OF CODE
//Author: Hussain Fakhruddin
//Date: 20090203
IDataCursor cursor = pipeline.getCursor();
//Return if no command is specified…
if (!cursor.first(“command”)) return;
String output = “”;
try {
String command = (String)cursor.getValue();
String line=””;

//Creating a Process Instance and executing the command..
Process p = Runtime.getRuntime().exec(command);

// Capturing the output.
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output = output + line + “\n”;
}
input.close();
}
catch (Exception err) {
// Do something on error… may be throw a ServiceException
}
// setting the outputMsg for whatever output the command has given.
cursor.insertAfter(“outputMsg”, output);

//—–END OF CODE————

webmethods-run-external-command-or-programs

Step 3: Run the program and pass the unix/linux command

Note: DO NOT use commands which are not exiting after giving an output. For example “tail -f” . This service is only for commands like “df -hk” or “cp file1 file2” or “pwd” or “ls -lrt“.

If you face some issues, do feel free to write back.