rlb3 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I have a problem with user tracking, but I'm not
really sure where to begin.

I need to track users by username on every page on our
student information site. The problem is that the web
application doesn't support this and is closed source. I was
wondering if there is any way to grab the information that I
want in perl, log it and then pass that information on to
the next web page. Just so you know, it is a Red Hat Linux box
running apache. The student information system software is Web
Advisor.
Like I said, this one has got me stumped, and the
company that supports web advisor isn't much help at all. I
would appreciate any help you could give.

Thanks,
rlb3
  • Comment on User Tracking in closed source application.

Replies are listed 'Best First'.
Re: User Tracking in closed source application.
by tachyon (Chancellor) on Oct 21, 2003 at 01:06 UTC

    Maintaining state is really something you need to build into the app, pesumbably Web Advisor. It seems to me probably the only way to do it effectively would be to make a wrapper app for Web Advisor. What you then do is insert your app between the end users and Web Advisor. You do what you want in your app then redirect to Web Advisor to do the actual work.

    There are two ways to get this happening. Assuming WebAdvisor is a single.cgi you could just rename it WebAdvisor2.cgi and call your script WebAdvisor.cgi. A call to WebAdvisor.cgi will now go to you where you could in the first instance request the login and fire up a session cookie. Then you track the user via this cookie, logging as you want, and redirect to WebAdvisor to do the work.

    That is the most simplistic model. You can also use the Apache mod_rewrite module to seamlessly direct request to your wrapper script. Need to aviod generating an infinite loop here but that is easy enough. Remember each request will now effectively be two part (first rewrites request to WebAdvisor to your script, you do stuff, then redirect to say dont-loop.cgi (does not even have to exist) because you get mod_rewrite to rewrite this to the real WebAdvisor.

    The practical mechanics depend on the details but it is quite possible to insert your script into the chain of events. One gotcha is POST data. The usual login will probably be by POST. If you read this in your wrapper STDIN will be empty when the request gets to WebAdvisor. You could try passing the data in a query string or do a pipe open to WebAdvisor and pass the data you stole from STDIN to it that way. There are other ways within Apache to do it as well.

    There are other possibilities such as using a proxy server but they are far more convoluted.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: User Tracking in closed source application.
by cees (Curate) on Oct 21, 2003 at 05:58 UTC

    You could write a simple mod_perl handler that looks at the URL being called, and the variables being POSTed or GETed. The easiest place to stick it would probably be at the FixupHandler stage. This gets executed right before the content is generated. In your case just before the CGI is called.

    If you need to know what is being served up by the software as well (ie need to look at the resulting HTML from the CGI call), then you could look at the new Filter support in mod_perl2 (needs Apache 2.0.x). With that you can write a filter in perl that will recieve the HTML that was generated by the content handler (the CGI script in this case), and you can do what you like with it. You would probably want to parse it for any pertinant info, and pass it on unchanged...

    If none of this helps, then maybe you could give us some more info, like what user info are you trying to track? And how is a user defined in the app (cookie, basic auth, url rewriting, hidden vars)? If the user is already being tracked by a cookie through the app, and you just want to know which users visit which URLs, then you could look at just adding a custom log rule to apache to track the URL and the cookie to a log file (see how the mod_usertrack module logs cookie values).

    - Cees

Re: User Tracking in closed source application.
by Roger (Parson) on Oct 21, 2003 at 00:39 UTC
    Yes, there are many ways to do this.

    Method 1 - you can use the hidden form fields to store student information when you generate the HTML pages. It would be something like this -
    use CGI; $q = new CGI; print $q->header, $q->hidden('variable', 'value'), .... ;
    Method 2 - When you generate the link on the page, append ?name=xxxx after link.pl script, so your link.pl script knows about the name variable when it gets activated.

    Method 3 - Set a cookie with encrypted student name in it, and use this cookie to track the student.

    The above are a few commonly used techniques in Web CGI programming to pass variables between pages.

Re: User Tracking in closed source application.
by PodMaster (Abbot) on Oct 21, 2003 at 00:42 UTC
    *yuck*
    How does "Web Advisor" keep track of sessions?
    A user has to go through a form to get authenticated (i know this), so simply get in between (be the middle man).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.