Category Archives: php

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—–

Creating sequences in MySQL an alternative to AUTO_INCREMENT

MySQL doesn’t doesn’t have sequences and Auto_Increment does not suffice the need for a text based sequence generator. Or say you want to reset AUTO_INCREMENT’s value?

So here’s a workaround for a generating a sequence in MySQL which can be reset later.

Step 1: Create a Table

CREATE TABLE IF NOT EXISTS `seqgen` (
`seqno` int(4) unsigned NOT NULL,
`application_id` varchar(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Step 2: Add your application in the sequence
INSERT INTO `seqgen` (`seqno`, `application_id`) VALUES (0, ‘myappname’);
Now when inserting I have set the seqno = 0 , because I want my sequence to start with 0;

Step 3:  You can create a Stored Proc or a Function to get the value and increment it by 1
<Remember to add this Proc/Function through command line with delimiter, else it will not work>

delimiter //
CREATE PROCEDURE seq_gen( OUT nextval INT , IN applicationid text)
BEGIN
select seqno into nextval from seqgen where application_id = applicationid;
update seqgen SET seqno = seqno + 1 where application_id = applicationid;
commit;
END;
//

—OR Function —- If you use function note that you’ll have to commit it by your program, MySQL doesn’t allow implicit or explicit commit in a Stored Function. So better use Procedure..

delimiter //
CREATE FUNCTION f_seq_gen(applicationid text)
RETURNS INT
BEGIN
DECLARE
nextval INT;
select seqno into nextval from seqgen where application_id = applicationid;
update seqgen SET seqno = seqno + 1 where application_id = applicationid;
RETURN nextva;
END;
//

Step 4: Access your sequence by

select f_seq_gen(‘myappname”);

Now you can use many such applications as Sequences in MySQL

Most popular windows – linux equivalent softwares

0) Windows – Linux

1) uTorrent  – rTorrent

If you like uTorrent, you will definitely like rTorrent. Its much simpler and easier to use!

2) Remote Desktop – rDesktop/VNC

If you want to share desktops, use VNC. If you want to Remote desktop to a windows machine from a linux system, use rDesktop

3) Yahoo/MSN – Pidgin

Your all in one instant messenger. Gives you better features: Major one being, you can login with multiple accounts on the same system! Isn’t that cool?!

4) IE – Firefox

Ok, we all know how good firefox is!

5) Outlook – Thunderbird

DONT USE OUTLOOK unless you want to screw your system up with hackers around! Use Thunderbird for windows and linux both!

6) Photoshop – Gimp

Gimp is quite matured now! It gives  you better brushes than photoshop..

7) Dreamweaver – Quanta Plus

Used dreamweaver since long and cant use it in linux? Try Quanta..

8 ) MS Office – OpenOffice.org

I’ve personally stopped using MS Office on windows too ( Ok, Ive stopped using windows too)

9) VMWare – Virtual Box

Virtual box is still a bit buggy, but you’ll not get to know unless you’re a hacker.

10) Notepad – GEdit/VI

We all know this!

11) Media Player – VLC Player

VLC is not in looks, but neither is Media Player.

12) WSFTP – Filezilla

Use filezilla for both , windows and Linux

Some Javascript Tips

I have been doing a lot of JavaScript these days. Each day I learn newer things and each day I am starting to like it more and more.

I am going to compile a few queries where I broke my head.

Q) If I do window.open(‘anotherPage.html’), How can I change the DOM of the parent window.
This problem arrived when I was trying to add more rows to a table from another window itself.
Problem: Firefox allows it. But IE doesn’t allow.
Solution: Use cloneNode() for FF. For IE , create the row again by attachRow()
Now for each cell, loop through it and do insertCells() and then copy the innerHTML to it.
All this is done in a simple loop through the table.

Q I have 3 frames on a page, I want to submit requests to page 2 and 3 at the same time
Do: document.forms[2].functionName();
yes, its as easy as this…
in your functionName(), you can add code to submit the form.submit();

Q Recursive Ajax calls.
Problem: To keep refreshing content of a page through Ajax.
One might typically use setInterval() but what if setInterval fires while a request from your ajax is coming back?
Solution: Use a global variable called “lock”. Everytime you make a request set this lock, the call back function should release the lock.
When setInterval fires your ajax request function it should exit if its locked.

Q. getElementById(‘idname’). Don’t use it too often, Try to traverse though the DOM by your code.

Q. Always give IDs to your form. Someday you’ll find that this is very useful. You can submit a form from anywhere if you do this by getting the refrence of the form and then yourform.submit()

Q. Try to avoid excess IDs, This will occupy more browser memory interms of DOM parsing.
For example, If you have a table, don’t give ID to each row. instead give the id to the table and then traverse the table.

Q. Do overuse Ajax and submit multiple requests simultaneously. Browser might allow this, but your database will not. Specially when you’re doing connection pooling. In connection pooling , you have the same connection object and multiple execution of sql queries on the same object from different clients will result in failed transactions.

Q. attaching events is a good idea , but beware, IE and FF behaves differently. The API is completely different.

Q. Always use a common Javascript Browser detection Module. Make the detected browser global and then customize your scripts that way.

Q. Often while debugging we use alert(“debug msg here..”); and waste time in commenting and uncommenting it. Instead use a global variable called “debug=true”. And use if (debug) alert(“”);
You wont have to comment or uncomment it all the time.

Q. There are some good Javascript debuggers. Use them. The simplest one is FF error console. But what about IE? Yes, now you can use FF error console to debug IE related Errors too.. Install the FF IE tab plugin and have fun.

Q. Another great FF extension is Firebug. MUST MUST have for all you JS guys….

Barcamp Pune 4

“Barcamp Pune 4: Love for technology” took place today at Thoughtworks Pune.
I gave a workshop on PHP & Ajax along with Priyank. This time I didn’t develop any website but rather a Proxy server using PHP!
We also conducted a BOF session on PHP and Ajax Security and Meta Trader the online forex platform.

Get some pics here:

Barcamp Pune 4 Logo


PHP & Ajax workshop


Barcamp schedule.


Preparing for workshop

Slides and Video to come next..

WebOSS ’07 : The Web Technology Conference

WebOSS 07

The first of its kind Web Technology Conference on Open Source Technologies, WEBOSS ‘07 is being organised in Kolkata on Saturday 13th October, 2007.

I am the organizer and speaker.
The conference is going to be held at West Bengal University of Technology Main Campus.
Topics include: RIA, AJAX, ROR, PHP VS PERL, speeding up your websites. I’m going to speak on RIA and RoR.
There is also going to be a panel discussion on Web 1.0, Web 2.0 and Web 3.0.

Hope to catch some action!