topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday April 19, 2024, 10:37 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: See if a user is logged in  (Read 9606 times)

autohost

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 13
    • View Profile
    • Donate to Member
IDEA: See if a user is logged in
« on: April 14, 2009, 10:35 AM »
We have 50 Windows XP patron stations in our university library.  I'd like to create an onscreen map showing which stations are available for use -- no one currently logged into them.  All users log in by a domain username.

I found PSTOOLS: psloggedon.exe  which I can use if I were to create this page on a Windows webserver, but I'd rather use a Linux solution.

IDEA:  I envision a very small app (very small memory footprint) on the patron station that would run when the user logs in (either by the START group, or AD user login script).  This app would respond with a simple string like 'yes' when contacted over the network on a certain port.  When the user logs out, the app would naturally stop running.

Example using port 5432:  http://lib-patron-2:5432

This way, I could easily use wget in PHP in Linux and then parse the results and display a nice floor layout showing which stations were available.

I suppose an alternative is for the app to always run, and return 'no' when a user is not logged in, and 'yes' when one is.

If you know of an already existing app that can do this, which I can call from Linux, please let me know.  Otherwise,  I'd love to have an app like described above.

If you think there is a better way to do it, let's talk about it.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #1 on: April 14, 2009, 11:00 AM »
neat idea.

couple of comments:

there are of course more heavyweight tools for managing and keeping track of or tabs on large numbers of pcs in a setting like this; you should probably make sure there is no other existing bigger tool that you would want to use instead of this custom idea.

instead of a fancy check for being logged in you could just use a check of last activity on keyboard or mouse -- after a minute of non-use i think you could be pretty sure there was no one there.

otherwise, getting back to your original description -- do you mean that the way it's set up, users actually log in and out to the windows pcs using the built-in windows user login system?

autohost

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 13
    • View Profile
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #2 on: April 14, 2009, 11:15 AM »
We're using a logout screensaver that auto logs out the user after 15 minutes of inactivity to help free up stations when users forget to logout.

Yes, all users have to login with their university acct and password.   The only local user on the stations is a local admin user that I occasionally have to use.


autohost

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 13
    • View Profile
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #3 on: April 14, 2009, 11:18 AM »
Yes, using the built-in windows login system.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #4 on: April 14, 2009, 11:23 AM »
so i have one more practical suggestion/idea for you:

a natural way to do this is as you suggested, an app that "would respond with a simple string like 'yes' when contacted over the network on a certain port."

however, a much more low-tech solution also seems like it would be feasible and MUCH easier to implement:

a small application that either ran on login/logout, or in the background constantly, and rather than respond to requests over a port (a process which could be a bit problematic both for security, firewall, and programming reasons), was simply configured to access a lan web page and REPORT IN.

In other words, a tiny program which would simply be configured to open a page like:
https://university.edu/library/reporting.php?stationid=34F&status=userloggedin&password=secretpassword

Seems to me that could have a number of nice benefits in addition to being easier to code.
« Last Edit: April 14, 2009, 11:35 AM by mouser »

autohost

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 13
    • View Profile
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #5 on: April 14, 2009, 11:27 AM »
Ouch!  Sorry, just slapped myself in the head for not seeing that one when I wrote the post.

You're absolutely right, that would be an easier way to do it -- have the app report its own status to a webpage.

autohost

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 13
    • View Profile
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #6 on: April 14, 2009, 02:32 PM »
Looks like its VERY easy as an AHK script, sorry to insult everyone's intelligence by asking for so simple an app  8)

#NoTrayIcon
#SingleInstance ignore
#MaxMem 1
#NoEnv

; This script reports this computer as logged out

UrlDownloadToFile, http://univeristy.ed...A_MyDocuments%status


Something like the above.

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • View Profile
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #7 on: April 14, 2009, 02:55 PM »
Looks like its VERY easy as an AHK script, sorry to insult everyone's intelligence by asking for so simple an app
-autohost

Didn't insult my intelligence (practically impossible to do).
Interested to read the thread and see what transpires.
Airing these kinds of things gives a lot of people the chance to pick up some ideas.


mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #8 on: April 14, 2009, 03:17 PM »
sorry to insult everyone's intelligence by asking for so simple an app

to quote paraphrase the ancient wisdom of the movie War Games: "Sometimes the only way to win is not to play" -- it seems like this request led to one of those very useful discussions where one finds a simpler solution by talking about a problem with others.  so that's a win-win in my book.
« Last Edit: April 14, 2009, 04:16 PM by mouser »

Josh

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Points: 45
  • Posts: 3,411
    • View Profile
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #9 on: April 14, 2009, 03:22 PM »
Mouser, if you are going to quote, DO IT RIGHT.

"A Strange game, the only winning move is not to play?"

autohost

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 13
    • View Profile
    • Donate to Member
Re: IDEA: See if a user is logged in
« Reply #10 on: April 21, 2009, 03:15 PM »
Looks like its VERY easy as an AHK script, sorry to insult everyone's intelligence by asking for so simple an app  8)

#NoTrayIcon
#SingleInstance ignore
#MaxMem 1
#NoEnv

; This script reports this computer as logged out

UrlDownloadToFile, http://univeristy.ed...A_MyDocuments%status


Something like the above.


Ok, it was pretty simple and fun.  Here is the completed app.  Maybe it will be useful to someone.

Here's the background for the code below:
Our library has 3 sets of patron computers named:
LIB-PATRON-1 through LIB-PATRON-16
LIB-PATRON-P1 through LIB-PATRON-P10
LIB-PATRON-U1 through LIB-PATRON-U24

The AHK script below pings the 6 closest stations and reports their status to a PHP program I wrote.  Compiled into an exe file and put into the domain login script.
I took the data reported and created a PHP page that displays the current status of all our patron stations.

#NoTrayIcon
#SingleInstance ignore
#MaxMem 1
#NoEnv

; Written in AutoHotKey by Ron Miller, Apr. 21, 2009

; This script reports this computer as logged in
; it also checks the 6 computers immediately around it and reports if they are up or down.


; %A_ComputerName% contains computer name in all caps
station := A_ComputerName

IfInString, A_UserName, lpac
{
        ; guest user, no password
user := "lpac"
}
else {
user := "university_user"
}

SubPat := ""
if (RegExMatch(station,"LIB-PATRON-(\d+)", SubPat))
{
Max := 16

; The Goto's you see in the following several IF statements prevent clobbering of SubPat1
Goto, Here
}

if (RegExMatch(station,"LIB-PATRON-(P\d+)", SubPat))
{
Max := 10
Goto, Here
}

if (RegExMatch(station,"LIB-PATRON-(U\d+)", SubPat))
{
Max := 24
Goto, Here
}

Here:

Work(Max,SubPat1)

Down_S := ""
if (d_count > 0)
{
Loop, %d_count%
{
Down_S .= Down_A%A_Index% . ":"
}
}
;else
;{
; MsgBox All stations are responding
;}

if (u_count > 0)
{
Loop, %u_count%
{
Up_S .= Up_A%A_Index% . ":"
}
}

UrlDownloadToFile, http://libraryurl/patronstation/report.php?station=%station%&status=yes&user=%user%&down=%Down_S%&up=%Up_S%&pw=reportpassword,%A_MyDocuments%status


Ping(NWA)
{
; MsgBox Pinging %NWA%
RunWait %ComSpec% /C ping -n 1 -w 250 %NWA%,,Hide
If (ErrorLevel)
{
Return 0
}

Return 1
}


Work(Max,SubPat)
{
; Have to set the following global so they can be read outside this function
global Down_A, Down_A1, Down_A2, Down_A3, Down_A4, Down_A5, Down_A6, d_count, Up_A,Up_A1,Up_A2,Up_A3,Up_A4,Up_A5,Up_A6,u_count

extra := "", temp := SubPat

; handle the U series of patron stations
if (InStr(SubPat,"U"))
{
extra := "U"
RegExMatch(SubPat,"U(\d+)",part)
Goto, Here1
}
; handle the P series of patron names
if (InStr(SubPat,"P"))
{
extra := "P"
RegExMatch(SubPat,"P(\d+)",part)
}

Here1:

; Ping 6 stations total, 3 below the current one, and 3 above
Sub := 3, Add := 3


if (extra != "")
{
temp := part1
}

part := temp

; Constrain loop to the number of stations we want to ping
Loop, 6
{
if (part - Sub < 1)
{
Sub--, Add++
}

if (part + Add > Max)
{
Add--, Sub++
}

if ((part - Sub >= 1) && (part + Add <= Max))
{
break
}
}

d_count :=0, u_count :=0

; loop through station names below current one
Loop, %Sub%
{
NWA := "LIB-PATRON-" . extra . (part - Sub)
if (Ping(NWA))
{
u_count++
Up_A%u_count% := NWA
}
else {
d_count++
Down_A%d_count% := NWA
}
Sub--
}

; loop through station names above current one
Loop, %Add%
{
NWA := "LIB-PATRON-" . extra . (part + Add)
if (Ping(NWA))
{
u_count++
Up_A%u_count% := NWA
}
else
{
d_count++
Down_A%d_count% := NWA
}
Add--
}

}