FAQ
I have situation where I need to be able to get the current active
user, and catch user switching eg user1 locks screen, leaves computer,
user2 comes, and logs on.
basically, when there is any type of user switch my script needs to
know.

Search Discussions

  • Tim Harig at Nov 30, 2010 at 10:54 pm

    On 2010-11-30, mpnordland wrote:
    I have situation where I need to be able to get the current active
    user, and catch user switching eg user1 locks screen, leaves computer,
    user2 comes, and logs on.
    basically, when there is any type of user switch my script needs to
    know.
    Well you could use inotify to trigger on any changes to /var/log/wtmp.
    When a change is detected, you could check of deltas in the output of "who
    -a" to figure out what has changed since the last time wtmp triggered.
  • James Mills at Nov 30, 2010 at 11:04 pm

    On Wed, Dec 1, 2010 at 8:54 AM, Tim Harig wrote:
    Well you could use inotify to trigger on any changes to /var/log/wtmp.
    When a change is detected, you could check of deltas in the output of "who
    -a" to figure out what has changed since the last time wtmp triggered.
    This is a good idea and you could also
    make use of the following library:

    http://pypi.python.org/pypi?:action=search&term=utmp&submit=search

    cheers
    James

    --
    -- James Mills
    --
    -- "Problems are solved by method"
  • Tim Golden at Dec 1, 2010 at 8:48 am

    On 30/11/2010 22:47, mpnordland wrote:
    I have situation where I need to be able to get the current active
    user, and catch user switching eg user1 locks screen, leaves computer,
    user2 comes, and logs on.
    basically, when there is any type of user switch my script needs to
    know.
    If it's Windows you're on, have a look at this:

    http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html

    TJG
  • Grant Edwards at Dec 1, 2010 at 3:23 pm

    On 2010-11-30, mpnordland wrote:

    I have situation where I need to be able to get the current active
    user,
    How do you define "current active user"?
    and catch user switching eg user1 locks screen, leaves computer,
    user2 comes, and logs on. basically, when there is any type of user
    switch my script needs to know.
    What do you do when there are multiple users logged in?

    --
    Grant Edwards grant.b.edwards Yow! How's the wife?
    at Is she at home enjoying
    gmail.com capitalism?
  • Mark Wooding at Dec 1, 2010 at 6:19 pm

    Grant Edwards <invalid at invalid.invalid> writes:
    On 2010-11-30, mpnordland wrote:
    and catch user switching eg user1 locks screen, leaves computer,
    user2 comes, and logs on. basically, when there is any type of user
    switch my script needs to know.
    What do you do when there are multiple users logged in?
    In case it's not clear: this situation doesn't just occur on `exotic'
    systems like Unix servers. Even Windows systems can have several people
    logged into the console (with one active, using `fast user switching')
    and another one or two connected using terminal services.

    -- [mdw]
  • Mpnordland at Dec 11, 2010 at 7:43 pm
    sorry, I've been busy, it's on linux, and current active user is the
    user currently using the computer. My program needs to switch log
    files when a different user starts using the computer.
  • Mpnordland at Dec 11, 2010 at 7:51 pm
    about the pyutmp, is the most recent entry at the top or bottom of the
    file?
  • Tim Chase at Dec 11, 2010 at 9:01 pm

    On 12/11/2010 01:43 PM, mpnordland wrote:
    it's on linux, and current active user is the user currently
    using the computer. My program needs to switch log files when
    a different user starts using the computer.
    The problem is that multiple users can be logged on at the same
    time. You might be able to come up with a solution that works
    for a small set of use-cases, but I admin several Linux boxes
    where multiple people can be logged-in at the same time. There
    are also some multi-head arrangements (multiple
    keyboards/mice/monitors and sometimes even sound-cards attached
    to the same motherboard) and people can log into each "terminal"
    (if you will) concurrently, all on the same box. So if I'm using
    the computer, and a co-worker logs in, I'm still using it at the
    same time you might catch the "new user logged in" event.

    Watching wtmp (or possibly /var/log/auth) can capture the "hey,
    somebody logged in" event, but that doesn't mean that other
    previous users are done with their sessions.


    -tkc
  • Tim Harig at Dec 11, 2010 at 10:32 pm
    Mr. Chase, I really wouldn't even bother wasting my time on this one.
    He asked an incomplete question to start with; so, the replies that
    he received were insufficient to solve his problem. He still has not
    provided enough information to know how to answer his question propery.
    He doesn't understand a sacastic reply when he hears one, he doesn't
    understand the concept of a multi-user operating system, and he doesn't
    understand the concept of how usenet threads work. Until he demonstrates
    some intelligence, I would say that he has flunked the Turing test.
  • Steven D'Aprano at Dec 12, 2010 at 12:04 am

    On Sat, 11 Dec 2010 11:43:13 -0800, mpnordland wrote:

    sorry, I've been busy, it's on linux, and current active user is the
    user currently using the computer. My program needs to switch log files
    when a different user starts using the computer.
    I think you have missed what people are trying to tell you: if you're
    running Linux, you may have more than one human being logged into and
    using the computer AT THE SAME TIME. You can also have a single human
    being logged into the computer as more than one user, and one user being
    used by multiple human beings.

    As we speak, I am logged into my Linux computer eight times, five times
    as myself (two GUI sessions, just to prove I can do it, plus three
    terminals), two times as root, and one time as another user; my wife's
    computer has two people logged in simultaneously (me and her); I'm also
    logged into a server at work, which currently lists eight people logged
    in twenty-one times between them.

    Perhaps you should explain what problem you are trying to solve, rather
    than how you think you should solve it ("catch the user switching").



    --
    Steven
  • Mpnordland at Dec 13, 2010 at 11:04 pm
    I think I do understand multiuser systems, although I'm sorry I did
    not make my self clear. Yes, I understand that there can be multiple
    people logged in, and yes if you really wanted to, you could login as
    yourself as many times as you want. This is not a server based
    program, it is intended for use in a normal environment. The people
    using it will probably not be logging in multiple times as themselves,
    or someone else. The problem I have is I want monitor what sites the
    user visits, I need to know what sites were accessed by which user.
    So, a way to find which user is requesting what url is what I want.
    Have I passed the Turing test?
  • Carl Banks at Dec 13, 2010 at 11:40 pm

    On Dec 13, 3:04?pm, mpnordland wrote:
    I think I do understand multiuser systems, although I'm sorry I did
    not make my self clear. Yes, I understand that there can be multiple
    people logged in, and yes if you really wanted to, you could login as
    yourself as many times as you want. This is not a server based
    program, it is intended for use in a normal environment. The people
    using it will probably not be logging in multiple times as themselves,
    or someone else. The problem I have is I want monitor what sites the
    user visits, I need to know what sites were accessed by which user.
    So, a way to find which user is requesting what url is what I want.
    Have I passed the Turing test?
    Install a web proxy.

    In a pinch you can stat /dev/console to see who the owner is, which I
    think was what they did last time I looked.

    If you're ambitious there's some stuff you can do with netfilter to
    attach user ids to network packets which you might be able to read
    with your logging software. How are you logging web site accesses
    anyway? That would be helpful to know.


    Carl Banks
  • Tim Harig at Dec 14, 2010 at 2:53 am

    On 2010-12-13, mpnordland wrote:
    I think I do understand multiuser systems, although I'm sorry I did
    not make my self clear. Yes, I understand that there can be multiple
    people logged in, and yes if you really wanted to, you could login as
    Apparantly you do not. There is nothing that prevents me from downloading
    from the web when I am not even at the computer. The point people are
    making is that there is no such thing as a single active user. Any user
    that has a running process is active. Somebody is not going to appreciate
    getting fired because somebody else scheduled a porn download at a time
    when they happened to be flagged as the current user.
    yourself as many times as you want. This is not a server based
    program, it is intended for use in a normal environment. The people
    There is nothing definitive about a so-called "normal" enviroment and
    since you didn't really specify anything, we had go make assumtpions
    for ourselves.

    Note also that a server is a piece of software, it need not be running
    on server class hardware. There are probably several local servers
    running on your system right now.

    As is commonly the case, the reason that you are having trouble with this
    problem is that you are trying to solve it wrong in the first place.
    You told us how you thought you should solve it which meant that we
    couldn't help you because we didn't know what problem you were trying to
    solve in the first place. For future reference, always give a 10,000ft
    explanation of the problem that you are actually trying to solve rather
    then just the microcosm of the problem that you feel is relevant.
    or someone else. The problem I have is I want monitor what sites the
    user visits, I need to know what sites were accessed by which user.
    So, a way to find which user is requesting what url is what I want.
    As Carl has already pointed out, an authenticated proxy is the proper
    way to get the individualized logging that you are looking for.
    It is capable of logging each connection (including software from
    which you might not have anticipated) with its own identified user of
    origin. Even when several users are accessing the network at once, the
    network connections can be tied directly to the person who initated
    the connection. Users cannot use somebody elses connection without
    their authentication credentials.

    With a little bit of scripting, the browser can be configured to
    automatically use the user's credentials whenever the user account is
    created so that the user never needs to enter their credentials manually
    after logging in to their account. All connections that attempt to
    bypass the proxy should be firewalled.
    Have I passed the Turing test?
    You still don't seem to understand how to use threads. Heres a clue:
    find a decent usenet client that actually displays them by default. Or,
    if you can't manage to get rid of that junky interface that is Google
    Groups, at least select the option to view as a tree. Then you might
    be able to actually post your replies in the proper thread rather then
    just appending on the the person who last posted.
  • Mpnordland at Dec 20, 2010 at 5:54 pm
    I give up, I will never try to use a usenet group again. For the ones of you who tried to help thank you. You helped to identify some of my troubles, as for you @usernet, you are a troll
  • Steve Holden at Dec 21, 2010 at 1:35 am

    On 12/20/2010 12:54 PM, mpnordland wrote:
    I give up, I will never try to use a usenet group again. For the ones
    of you who tried to help thank you. You helped to identify some of my
    troubles, as for you @usernet, you are a troll
    Don't give up after one experience. Usenet can be really useful as long
    as you know who to listen to and who to ignore ...

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    PyCon 2011 Atlanta March 9-17 http://us.pycon.org/
    See Python Video! http://python.mirocommunity.org/
    Holden Web LLC http://www.holdenweb.com/
  • Mpnordland at Dec 22, 2010 at 7:28 pm
    ok, I'll give one more chance.
    First, to pacify those who hate google groups: What is a good usenet
    client?
    second, How should I set up this proxy so that when a connection is
    made, it request's authentication, and then log's the request, if
    authentication is not gotten, how do I have it block (or firewall) the
    request? Furthermore, I would like for the proxy to be squid. So all
    of the nitty gritty should have to do with squid.
  • Emile van Sebille at Dec 22, 2010 at 9:06 pm
    On 12/22/2010 11:28 AM mpnordland said...
    ok, I'll give one more chance.
    ... which probably won't be enough -- this is potentially a huge
    question you're asking with lots of little bits to put together. I have
    an installation where I did somthing similar seven-ish years ago using
    squid, squidguard, blacklists from Universit? Toulouse in France,
    python, iptables, sql, php, zope, bash, and who knows what else. It
    authenticates, logs, tracks, blocks, unblocks, reports activity on an
    automated In and Out board by user, provides historical stats, automates
    new user setup and invalidation, and probably more. I put maybe a week
    or two into it initially, and about the same again over the years adding
    to it.
    First, to pacify those who hate google groups: What is a good usenet
    client?
    I use thunderbird to access gmane groups.
    second, How should I set up this proxy so that when a connection is
    made, it request's authentication, and then log's the request, if
    authentication is not gotten, how do I have it block (or firewall) the
    request? Furthermore, I would like for the proxy to be squid. So all
    of the nitty gritty should have to do with squid.
    ... and that's where I'd start looking. Check out the current status of
    Squid to see how much of what you want can be done out of the box. When
    you hit the limits of what it'll do for you, start writing glue to fill
    in the puzzle.

    HTH,

    Emile
  • Steve Holden at Dec 22, 2010 at 9:20 pm

    On 12/22/2010 2:28 PM, mpnordland wrote:
    ok, I'll give one more chance.
    First, to pacify those who hate google groups: What is a good usenet
    client?
    Thunderbird is OK for me (I follow about three groups normally). I
    access the comp.lang.python group vie the Gmane ("Main") service, where
    for some strange resaon best known to the gmane admins it is called
    gmane.comp.python.general. Ho, hum.

    I seem to remember Outlook Express was a fairly decent NNTP client as
    well, and Tim Peters says I'm not just blowing smoke up your ass.
    second, How should I set up this proxy so that when a connection is
    made, it request's authentication, and then log's the request, if
    authentication is not gotten, how do I have it block (or firewall) the
    request? Furthermore, I would like for the proxy to be squid. So all
    of the nitty gritty should have to do with squid.
    I would recommend you take a look at the Spambayes code, which does all
    that sort of stuff apparently quite reliably.

    If you aren't yet proficient enough with Python to understand the code
    on your own look for a Python Meetup or a local or regional conference
    to meet people who will helpyou answer your questions.

    Increasingly there are workspaces like HacDC springing up to give people
    access to advanced technologies at everyday prices. You could look for
    such a group locally. There's lots of energy from people once they
    realise that what gets built can help them.

    Squid is a different matter. For that, probably if you go on an IRC
    channel (freenode.net is what I use, but others have their favorites).
    Maybe #squid?

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    PyCon 2011 Atlanta March 9-17 http://us.pycon.org/
    See Python Video! http://python.mirocommunity.org/
    Holden Web LLC http://www.holdenweb.com/
  • Stefan Sonnenberg-Carstens at Dec 22, 2010 at 10:29 pm

    Am 22.12.2010 20:28, schrieb mpnordland:
    ok, I'll give one more chance.
    First, to pacify those who hate google groups: What is a good usenet
    client?
    second, How should I set up this proxy so that when a connection is
    made, it request's authentication, and then log's the request, if
    authentication is not gotten, how do I have it block (or firewall) the
    request? Furthermore, I would like for the proxy to be squid. So all
    of the nitty gritty should have to do with squid.
    Just install Squid, enable user authentication and grant access only to
    authenticated people.
    Now, configure logrotated and tell to rotate logs every day/week/month
    (your mileage will vary).
    After rotating run a program such as webalizer to get stats (even on a
    per user basis).
    If you have smart guys under your users, set up a) a transparent proxy
    intercepting http/https requests
    or b) set up a iptables firewall with redirection to the squid port.

    There are many, many, many how-to documents on the net describing
    exactly what you want to do.

    A first starting point could be
    http://www.comfsm.fm/computing/squid/FAQ.html

    And your problems are solved a long time ago:

    http://www.faqs.org/docs/Linux-mini/TransparentProxy.html

    And, the most important thing:

    Check your local laws for this intention.
    Some, like our german law, require these things to be under clear rules.

    Cheers
  • Aahz at Dec 31, 2010 at 12:59 am
    In article <ff3a2b89-2586-43d2-ae5a-490384687e61 at 32g2000yqz.googlegroups.com>,
    mpnordland wrote:
    First, to pacify those who hate google groups: What is a good usenet
    client?
    trn3.6 ;-)
    --
    Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/

    "Think of it as evolution in action." --Tony Rand
  • Steven D'Aprano at Dec 22, 2010 at 10:05 pm

    On Mon, 20 Dec 2010 20:35:54 -0500, Steve Holden wrote:
    On 12/20/2010 12:54 PM, mpnordland wrote:
    I give up, I will never try to use a usenet group again. For the ones
    of you who tried to help thank you. You helped to identify some of my
    troubles, as for you @usernet, you are a troll
    Don't give up after one experience. Usenet can be really useful as long
    as you know who to listen to and who to ignore ...

    More importantly, Usenet can be very useful so long as you know how to
    ask smart questions. If you insist on asking stupid questions, you will
    rapidly get disillusioned: people will either ignore you, abuse you, or
    give you helpful advice that you don't want to hear.




    --
    Steven
  • Stefan Sonnenberg-Carstens at Dec 22, 2010 at 10:34 pm
    Sorry, this one is cross post.
    I posted my question below some time ago to then jython ml, because this
    hit me first with jython.
    Anyway, time passed, problem not solved.

    So, I'd like to know if some of you know where my error lies:


    Hi all,

    I've played around with some code-kata of mine from the past.
    It's a toy http server:

    import socket
    import select
    import sys
    import time
    srv = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    srv.setblocking(0)
    srv.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,True) # Not sure if
    this is needed. I only remember I've started once for some reason.
    Commenting out does no change
    if srv:
    srv.bind(('',8080))
    srv.setblocking(0)
    srv.listen(5)
    conns = [srv]
    buffers = {}
    while True:
    reader,writer,failed = select.select(conns,conns,[],1)
    if failed:
    sys.exit(1)

    if srv in reader:
    client,(ip,port) = srv.accept()
    client.setblocking(False)
    conns += [client]
    for r in reader:
    if r is not srv:
    data = r.recv(1024)
    if not data:
    conns.remove(r)
    else:
    if r in buffers:
    buffers[r] += data
    else:
    buffers[r] = data
    for w in writer:
    if w is not srv:
    if w in buffers and buffers[w][-2:] == '\r\n':
    msg = 'HTTP/1.0 200 OK\r\nServer:
    Jython/2.5\r\nContent-type: text/plain\r\n\r\nThe answer is: 42\r\n'
    w.send(msg)
    w.close() # THIS ONLY WORKS WHEN THIS LINE IS PRESENT
    conns.remove(w) # AND THEN THIS IS MUST
    buffers[w] = ''

    But today I was asking myself why I should always close the socket, and
    if wouldn't be more efficient if
    I let it open.
    To make a long story short: it does not work.
    If I comment out the lines with the comment all upper case,
    jython consumes one core in my laptop completely and ab.exe from apache
    bails out after a while.

    Changing send() to sendall() did not do the trick.

    I've searched the web and did not find anything meaningful.

    Perhaps someone here can switch the light on.
  • MRAB at Dec 23, 2010 at 1:54 am

    On 22/12/2010 22:34, Stefan Sonnenberg-Carstens wrote:
    Sorry, this one is cross post.
    I posted my question below some time ago to then jython ml, because this
    hit me first with jython.
    Anyway, time passed, problem not solved.

    So, I'd like to know if some of you know where my error lies:
    [snip]
    What happens if the conns list contains a writer that's ready?

    The select function returns immediately with that writer in the writer
    list. If it's not srv then nothing is done with it, so execution just
    loops back to the select function with that writer still in the conns
    list, and the select function then returns immediately with that writer
    in the writer list again.

    Infinite loop!
  • Mpnordland at Dec 23, 2010 at 11:07 pm
    Ok, thank you. I will go look at the resources mentioned.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 30, '10 at 10:47p
activeDec 31, '10 at 12:59a
posts25
users14
websitepython.org

People

Translate

site design / logo © 2022 Grokbase