View Poll Results: Can this be done
- 7. You may not vote on this poll
Results 1 to 6 of 6
Is it possible to make gnuplot-like graphs with Perl and/or CGI? Forum: CGI Perl ForumReplies: 1
Help with my perl script Forum: CGI Perl ForumReplies: 1
Please Help me (Perl Script) Forum: CGI Perl ForumReplies: 1
How to make a nms by Perl? Forum: CGI Perl ForumReplies: 2
cgi script/perl problem Forum: CGI Perl ForumReplies: 4
02-14-2004, 07:12 AM #1
Make a perl script log into a site
Here is my problem. I sometimes help program alarm panels for my employer. The process just to login requires me to use a web browser to log into a website. Once I am logged in it gives me a port number. Then I log into a server via ssh and enter this port number. I was trying to make a shell script that uses lynx to automate this process a bit. Lynx will not work and I believe this is because the website is in jsp. I asked around and a buddy told me to try a perl script. I did some research and found this perl module "HTML::FillInForm" but i do not know how to make it work. I have never written a perl script.
Here is the form in question. I notice that the sessionid changes each time as I presume it should.
<form name="loginForm" method="POST" action="/portsecure/do/login;jsessionid=C4A9F9B5048491A7F0F85CE9D4F05DF4">
<td><input type="text" name="id" value=""></td>
<td><input type="password" name="password" value=""></td>
<td><input type="submit" name="submit" value="Submit"></td>
So how do I make a perl script to login to this site enter the username and pass and neatly echo the port number to me on my console? It would be nice to automate this becasue the next step is to make a shell script "once I have the port" to automatically spawn ssh and enter it all by itself. Can it be done? Any help would be greatly appreciated. Thanks
03-17-2004, 09:27 AM #2
Wow. Wicked question!
Hmm. I am not a Perl programmer, so I cannot give you code examples, but I think I can point you in the right direction.
This will be a two-step process, mainly because we need to get the sessionid before we attempt login.
What your going to have to code is a mini-browser, in effect. First, it makes a HTTP GET request to the correct address. This should return, basically, the header information, which we can ignore, and the HTML of the page itself. All we want from this output is the session ID. You will need to parse this from the output.
Once we have the session ID, we can then do a HTTP POST request to
Again, this should return HTML Including the port you need. This can then be parsed out and you can go onto the next step.
Good luck with it, please let us know of progress as this is a very interesting little project.
10-07-2004, 07:34 AM #3
Hehehe... this actually looks like a fun project. Then again, I'm a geek. Please forgive a bit of rusty coding... I don't have a unix box around to try this on as I type.
Here's something you could try. Since you're running Lynx; I'm 'assuming' you're on a *nix-based platform and running Bash.
A. Capturing your session ID:
Lynx output can be dumped to the console (or piped) using the --dump command.
lynx --dump http://myurl.com
lynx --dump http://myurl.com | grep jsessionid
lynx --dump http://myurl.com | grep jsession > jsession.tmp
var_jession=lynx --dump http://myurl.com | grep jsession
B. Plugging in the user name and password.
This is going to be kinda tricky.. and any of you Bash programmers, jump in.
You could create the HTML in a preset file, e.g.:
cat jsession.tmp > login.htm cat htmllogin1.tmp >> login.htm lynx --dump http://login.htm
Hmm, in any case; that'd be a possible starting point. Let me know where and what breaks and I'll load up a quick VM with Gentoo or something and see if I can give you cleaner, more stable code. I'm sure I have an O'Reilly Bash Programming book around here somewhere.... now to find it!
Edited note: One thing to consider is the security of that password and username. You'll have it in plain text somewhere on your machine--weight the pros and cons.
11-22-2004, 11:34 PM #4
this is kickass and close to something I need too.
I don't need the session ID that was in this example, so I just hardcoded the html (for now... later, I'll write an awk script to generate the .html based on incoming information)
how else can I kickoff a HTTP form POST without using a web browser?
11-22-2004, 11:39 PM #5
Last edited by HTML; 03-09-2012 at 09:42 PM.
11-22-2004, 11:41 PM #6
Haha, I forgot. You can also telnet port 80 and type in the HTTP commands manually. Good for testing if nothing else.