Log on to we page via script or batch file

Posted on 2013-10-02
Medium Priority
Last Modified: 2013-11-19
We have a process controller in our shop which stores records sent by our shop equipment...
It is web page accessible on the LAN and has a simple JavaScript logon. I need to be able to log on to this site (I have the username and password) via a script or batch file, as I have been tasked with pulling the text records it stores automatically. Since all the records resolve the HTML addresses this is simple, once logged on... However I can't seem to find a good way to do this. The old http://user:password@somesite.com/URL doesn't work. Anyone know how to go about this? Thanks.
Question by:JP_TechGroup
  • 4
  • 3
LVL 45

Expert Comment

by:Chris Stanyon
ID: 39541665
Don't really have enough to go on here.

You say your records are 'stored' but don't say how. If they're stored in a database, then you can probably skip the web page completely and just access the records directly using something like PHP.

If your system uses Javascript for a login then it probably isn't very secure. Normally, your login details are sent to the server using POST. If that's the case, then you could use a cURL request, again using something like PHP to POST the credentials and pull back your data.

The old user:password@somedomain.com only ever worked for htpasswd protected folders.

Probably need more info to give you a specific answer.

Author Comment

ID: 39546525
No question the page is not very secure... It's what the client system runs on however, so there isn't much I can do about that.

ok, here is the script I am trying to make work... it runs correctly except the authentication does not work. The resulting file download winds up being the html for the start page rather than the file to be downloaded... obviously the script is not properly authenticating.

 strLink = "http://ourURL/StorageCardMMC/LOG_P1/LOG_P10.txt"
 	 ' Get file name from URL.

 	 strSaveName = Mid(strLink, InStrRev(strLink,"/") + 1, Len(strLink))
 	 strSaveTo = "C:\temp\" & strSaveName
     ' Create an HTTP object
     Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
     ' Download the specified URL
     objHTTP.Open "GET", strLink, False
     objHTTP.SetCredentials "username", "password", HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
          Set objFSO = CreateObject("Scripting.FileSystemObject")
	  If objFSO.FileExists(strSaveTo) Then
	  End If
      If objHTTP.Status = 200 Then
    	Dim objStream
	    Set objStream = CreateObject("ADODB.Stream")
	    With objStream
		    .Type = 1 'adTypeBinary
		    .Write objHTTP.ResponseBody
		    .SaveToFile strSaveTo
	    End With
	    set objStream = Nothing
	  End If
	  If objFSO.FileExists(strSaveTo) Then
	  End If 

Open in new window

LVL 45

Expert Comment

by:Chris Stanyon
ID: 39546679
Hi JP,

My point was that if your security is JavaScript-based then it can probably be bypassed altogether. Javascript security is usually ineffective because it's browser based so can be turned off (or avoided completely). If you try to access that txt file without logging in first, and you end up on a different page, then I'm guessing there is more to your logon system than just Javascript.

What happens if you disable javascript in your browser and try accessing the file?

If you're able to run PHP scripts, then a simple cURL request may do the job for you:

$remoteFile  = 'http://ourURL/StorageCardMMC/LOG_P1/LOG_P10.txt';
$newFile = 'LOG_P10.txt';
$fp = fopen($newFile, 'w');
$ch = curl_init($remoteFile);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);

Open in new window

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.


Author Comment

ID: 39605992
Thank you and apologies for taking so long to respond. The PHP script yields the same result. Think this one is over my head!
LVL 45

Accepted Solution

Chris Stanyon earned 2000 total points
ID: 39606232
Hmmm. It sounds like your security model is more than just Javascript (which is a good thing), but in order to log in remotely, you'll need to understand a little more about how it's implemented.

If your security is server-side controlled, and relies on a user to fill in and POST a form, for example, then you may be able to do this using cURL. Before you try moving further on this though, I would suggest you get a good handle on the authentication model used. Without that, it will just be trial and error
LVL 45

Expert Comment

by:Chris Stanyon
ID: 39642332

Author Comment

ID: 39651358
This was an oops on my part Chris. I have notified the mod and asked to have the solution upgraded to A.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

These seven tips can help you create an extraordinary website, one that captivates audiences and has them wanting to return regularly for more. Keep reading to find out what your site is missing and what you need to add!
I recently worked on a Wordpress site that utilized the popular ContactForm7 (https://contactform7.com/) plug-in that only sends an email and does not save data. The client wanted the data saved to a custom CRM database. This is my solution.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question