Short description

Sometimes I forgot to logout, sometimes I am asked to kill someone else' session on the server.

The scripts shown below kill all sessions of a user - maybe we you don't want that. What is needed to select the session files to kill?

The scripts could be added to script/account. or "script/session"? latter is better, script will be named destroy.

(!) A similar script was added to moin 1.9 (will be in moin 1.9.1) as moin maint cleansessions.

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3 MoinMoin - destroysession script
   4 
   5 @copyright: 2009 MoinMoin:ReimarBauer
   6 @license: GNU GPL, see COPYING for details.
   7 """
   8 import os
   9 from MoinMoin import caching, user
  10 from MoinMoin.script import MoinScript
  11 
  12 
  13 class PluginScript(MoinScript):
  14     """\
  15 Purpose:
  16 ========
  17 This script allows you to delete all session cookies from a user in
  18 data/cache/__common__/session
  19 
  20 You will usually do this after a user request.
  21 
  22 Detailed Instructions:
  23 ======================
  24 General syntax: moin [options] account destroysession
  25 
  26 [options] usually should be:
  27     --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
  28 
  29 [destroysession-options] see below:
  30     1. To remove JohnSmith's session cookies. (He has to login at next request):
  31        moin ... account destroysession --name JohnSmith
  32 """
  33 
  34     def __init__(self, argv, def_values):
  35         MoinScript.__init__(self, argv, def_values)
  36 
  37         self.parser.add_option(
  38             "--name", metavar="NAME", dest="uname",
  39             help="Destroy Sessions for the user with user name NAME."
  40         )
  41 
  42     def mainloop(self):
  43         if not self.options.uname:
  44             self.parser.error("no name given")
  45             self.parser.print_help()
  46             import sys
  47             sys.exit(1)
  48 
  49         self.init_request()
  50         request = self.request
  51         if self.options.uname:
  52             u = user.User(request, None, self.options.uname)
  53             if not u.exists():
  54                 print 'This user "%s" does not exists!' % u.name
  55                 return
  56 
  57             cachelist = caching.get_cache_list(request, 'session', 'farm')
  58             for sid in cachelist:
  59                 session = caching.CacheEntry(request, 'session', sid, 'farm',
  60                                            use_pickle=True).content()
  61                 if session["user.id"] == u.id:
  62                     caching.CacheEntry(request, 'session', sid, 'farm').remove()
  63                     print 'Session file "%s" deleted!' % sid

moin-1.8_destroysession.py


CategoryFeatureRequest

MoinMoin: FeatureRequests/OnDemandDestroySession (last edited 2010-01-13 09:17:12 by ThomasWaldmann)