Category Archives: code

gettinig PDF form field names

If you have a PDF and want to fill the pdf programmatic-ally, You can but you need those pdf’s form fields.

Here’s a simple Java Class which can help you. I am using iText as my PDF library.

import java.util.HashMap;
import java.util.Iterator;
import com.lowagie.text.pdf.*;

public class iTextSample {
public static void main(String[] args) throws Exception{
PdfReader reader = new PdfReader(“/Users/Admin/Public/jars/a.pdf”);
boolean test = reader.isEncrypted();


AcroFields form = reader.getAcroFields();
HashMap fields = form.getFields();
System.out.println(“Total Fields: ” + fields.size());
String key;
for (Iterator i = fields.keySet().iterator(); i.hasNext(); ) {
key = (String);
switch(form.getFieldType(key)) {

case AcroFields.FIELD_TYPE_TEXT:
System.out.print(key + “: “);
System.out.print(“, At Page:” + form.getFieldItem(key).getPage(0));
System.out.println(“, at tab:” + form.getFieldItem(key).getTabOrder(0));


Stop using rediff

I have reasons to believe that rediff’s code quality has become really pathetic day by day. Delivery managers aren’t paying attention to the feedbacks. They keep putting bad code and pile up stacks of powerful servers to hide their bad programming practices!

Its high time Rediff ! WAKE UP!

After my initial post on a full quality analysis of rediff which can be found here I thought they would improve the quality but they went worse. Neither did they improve the quality but they left out loop holes for themselves for hackers to hack in.

The below screenshots would explain:

rediff_bad_coding Click to enlarge

rediff_code_horror Click to enlarge

I did email the product manager, but he asked me to wait and I’m still waiting!!

Picture 3 Click to enlarge.

So now I’ve decided that I will stop using Rediff, and go to other news sites which are good for my browser.

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!



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!


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

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


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


Step 2: Paste in the following 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”;
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————


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. Coding Standards: An Analysis

By Hussain Fakhruddin

Rediff has a lot of portals within its main portal.

This is how they organize their re-usable code.

The first thing I did is logged on to:

I opened my Fire Fox’s Error Console and found this:

The next thing I did was to open up the source code:

I was shocked. I could really figure out that this type of code was

1) Written by just “Jugard” of code from their own paces here and there!

2) Not at all reviewed!

3) Done in haste to meet the deadlines!

I will put some screenshots to prove my point:(Please enlarge them as needed)

  1. Are these written by the same programmer?

Subsequent lines of code, but one in caps and other in small.

– Seems like they have just copied it from some previous page.

  1. Dirty CSS to look good? : Reuse of CSS codes, but not at all arranged in a proper manner. They are probably using the code which is lying here and there.

  1. Code lying here and there + insert what is needed and get the things done!

  1. JavaScript in the middle of an external CSS.

    Why not place it together along with the code above!

  1. Just Wow: Internal JS > CSS > External JS > Internal JS

    CSS surrounded between JavaScript and JavaScript surrounded between CSS!

  1. Where are your code conventions Mr. Rediff?

    See the CSS classname ‘Naming standards’

  1. Rediff’s way of importing external JS!

They are using JavaScript to import another JavaScript code!

Look carefully!

  1. Debugging debris remains…

  1. Reuse the code, but not in the same page man!

    I saw this CSS defined AGAIN somewhere below the code!
  2. What a waste of memory!

    Everything commented inside the function, what does this function do then?!

  1. Agreed we all use broadband, but what a waste of Bandwidth?

Why so many wide spaces!

Don’t you guys know browser ignores them but bandwidth network doesn’t!

  1. Broken Link

Wanna report?

  1. Total time over 512KBPS

    No comments!

  1. 19 Requests to the server! Woah!

    Thank you that I have an advance browser to do these for me!

  1. So many DNS resolutions

    My ISP might think I am doing a DNS attack!

16. Best of all:

Around 8 MB of Memory occupied by just 41KB of HTML code!

Single line of HTML crashes IE 6

A Japanese blogger who goes by the name Hamachiya2 has discovered a single line of HTML and CSS that crashes IE 6. The line is:


If you’re brave, you can click here to try it out. The code is rendered correctly in Firefox, Safari and Opera (didn’t get a chance to try any other browsers, but presumably they work too). But in IE 6 it raises a fatal error in mshtml.dll.

Deep Linking How to avoid

A deep link is a direct link to a web site’s resource without accessing the main page of the site. For example your site is and your contact page is at If a user types the 2nd link without going though the main page, he is called as The Deep Linker.

It becomes a problem for many of the sites which display ads on their first page(the index page). The HTTP protocol doesn’t bother if the user is asking for a resource via a deep link or via a normal link. After all, the request which goes to the server is something like this :

GET /contactus/contact.html

for both cases 1. When you access it through a deep link or 2. When you access it normally via first page’s link.

So, how to avoid people from linking deep?
Here’s a small trick:

1. Check for a cookie at each deep link. If it doesn’t exist, redirect to index page.
2. On the index page insert a cookie which gets killed when the browser is closed.

Anyone knowing a non cookie based solution to this problem do post it in the comments

VB6 and IE7 problem

One may no longer be able to use the ieframe.dll when using IE7 with VB6’s Web Browser Control

Here’s a quick tip:
On your component selection dialog box, Point the Microsoft Internet Controls to SHDOCVW.dll instead of ieframe.dll and bingo!