Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

I'm going to start work on a quick and simple PHP/Windows logging script that will log every time a user logs in and out of a PC as well as tie the events together so I can see whether or not a student logged off from a particular session.

 

Anyhoo the PHP wont be an issue, the problem is simply getting that login event to the PHP receiver. There are two obvious solutions I see each with drawbacks. Option one is to make a publicly writeable CSV file on the LAMP server and have the batch file echo straight into it. It's the simplest option by far but the drawback is that to make the data "live" in PHP I would need to read directly from the CSV with a database used for archives, the problems with that are two fold. It's a massive security risk opening the whole server to a clever (albeit it VERY clever) user and files are single access so if the login script runs twice at the same time (IE two users log in) one of the sessions will lock the CSV meaning I get no data from the second session or a corrupted CSV.

 

The second option which is by far the best is to have my login script hit a PHP page similar to "log.php?user=auser&machine=XYZ" the php will then error check and make the data safe and insert it into a database safely. This gives me safe, accurate data, multiuser/session support and error checking as well as live data when I view the log. The problem being I can't make a script to hit a remote PHP page.

 

Under linux I could use "wget", I know wget exists for windows but it requires me to deploy wget to all the machines in the school then risk incomplete data if I miss a machine etc... so I am looking for a built in, windows standard for calling a remote webpage without triggering user response or a browser window. I don't need any feedback from the PHP script it will all be silent.

 

Any ideas?

Posted
I think your best bet would be to try and create a HTTP request from your script. I don't use vbs but maybe look around for MSXML2.XMLHTTP, which I think vbs can create an object of and perform get requests on websites from.
  • Thanks 1
Posted
Long shot and not even sure if it will work but what about putting or placing wget into the netlogon share on a server that all machines can access and in the script you just need to use a unc path to the netlogon share ?
  • Thanks 1
Posted
I think your best bet would be to try and create a HTTP request from your script. I don't use vbs but maybe look around for MSXML2.XMLHTTP, which I think vbs can create an object of and perform get requests on websites from.

 

That is pretty much exactly what I want to do, just trigger a http request, will do some googling on that library/function, thanks!

 

Long shot and not even sure if it will work but what about putting or placing wget into the netlogon share on a server that all machines can access and in the script you just need to use a unc path to the netlogon share ?

 

Genius, didn't even think of that... If wget works like we both (now) expect I can simply call it as an external exe and pass it the URL as an argument and bob's your uncle!

 

Thanks to both, will have a google if I get a chance in between cable pulling :D

  • Thanks 1
Posted
I think your best bet would be to try and create a HTTP request from your script. I don't use vbs but maybe look around for MSXML2.XMLHTTP, which I think vbs can create an object of and perform get requests on websites from.

 

You sir are a genius.

 

The documentation for windows commands is crap! If you google a PHP function you get the PHP manual showing all the expected and optional parameters and examples. Google windows stuff and all you get is people showing off the fact they have microsoft certifications! Got there in the end and got this little bit of code for anyone else who is interested in doing something similar:

Dim info

Dim connection

 

Set info = CreateObject("Wscript.Network")

computer = info.ComputerName

user = info.UserName

 

Set connection = CreateObject("MSXML2.XMLHTTP")

connection.open "GET", "http://172.16.0.20/logging/test.php?pc="&computer&"&user="&user, FALSE

connection.send

WScript.Echo "!!DEBUG!! Status is: " & connection.Status

 

Firstly define the variables, gotta love VBS... -.-

Use the info variable to get the logged in user and computer name

Set up the http connection object, give it the URL to hit and the method (in this case GET, as all we need to do is request the data rather than POST data to the server) and include the USER and COMPUTER variables in the url for PHP to process

Send the connection

Then for debugging echo out the HTTP status code.

 

Works a charm for me, so now the fun bit, I get to do some more PHP coding :D

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...