- Timestamp:
- 07/21/06 02:14:17 (6 years ago)
- Location:
- branches/version_2
- Files:
-
- 1 added
- 13 modified
-
HelpIM/baseconfig.py (modified) (3 diffs)
-
HelpIM/bot/bot.py (modified) (6 diffs)
-
HelpIM/chatdb.py (modified) (1 diff)
-
HelpIM/database.py (modified) (3 diffs)
-
HelpIM/intranet/handler.py (modified) (2 diffs)
-
HelpIM/intranet/lib/startstop.py (modified) (6 diffs)
-
HelpIM/intranet/scripts/admin.py (modified) (9 diffs)
-
HelpIM/intranet/scripts/login.py (modified) (1 diff)
-
HelpIM/sharedvars.py (added)
-
HelpIM/status.py (modified) (2 diffs)
-
HelpIM/webchat/handler.py (modified) (1 diff)
-
settings/config.example (modified) (1 diff)
-
settings/settings_all_example.py (modified) (1 diff)
-
settings/settings_intranet_example.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/version_2/HelpIM/baseconfig.py
r353 r354 1 1 import ConfigParser 2 2 import os 3 import HelpIM.sharedvars 3 4 4 5 default = ['/etc/HelpIM/config'] … … 14 15 15 16 2) 16 Location pointed to by the environment variable "H elpIMconfig"17 Location pointed to by the environment variable "HELPIMCONFIG" 17 18 18 19 3) … … 21 22 """ 22 23 # default location for configfile 23 configfiles = default 24 cached = HelpIM.sharedvars.get("baseconfig"+section) 25 if cached: 26 return cached 27 else: 28 configfiles = default 24 29 25 env = os.environ.get("HelpIMconfig")26 if env:27 configfiles.append(env)30 env = os.environ.get("HELPIMCONFIG") 31 if env: 32 configfiles.append(env) 28 33 29 try: 30 # To-Do: dit gaat niet werken, de variabelen komen uit de request 31 # dus moet de handler via global hier een variable zetten die hier 32 # opgevangen kan worden. (Hmmm, dit kan op meer plaatsen gebruikt 33 # worden). 34 opts = apache.get_options() 35 configfiles.append(opts['HelpIMconfig']) 36 except (ImportError, KeyError, AttributeError): 37 pass 34 HelpIMconfig = HelpIM.sharedvars.get('HelpIMconfig') 35 if HelpIMconfig and not HelpIMconfig in configfiles: 36 configfiles.append(HelpIMconfig) 38 37 39 # read configfiles and get parameters 40 config = ConfigParser.SafeConfigParser() 41 config.read(configfiles) 42 parms = {} 43 items = config.options(section) 44 for item in items: 45 parms[item] = config.get(section, item) 46 return parms 38 # from mod_python import apache 39 # apache.log_error("baseconfig: " + str(configfiles)) 40 41 # read configfiles and get parameters 42 config = ConfigParser.SafeConfigParser() 43 config.read(configfiles) 44 parms = {} 45 try: 46 items = config.options(section) 47 except ConfigParser.NoSectionError: 48 raise Exception ("Configfile not found") 49 for item in items: 50 parms[item] = config.get(section, item) 51 HelpIM.sharedvars.set("baseconfig"+section, parms) 52 return parms -
branches/version_2/HelpIM/bot/bot.py
r353 r354 8 8 import os 9 9 10 # hack for local testing 11 sys.path.append("/home/wt/werk/HelpIM/svn/branches/version_2") 12 10 13 from pyxmpp.all import * 11 14 from pyxmpp.jabber.client import JabberClient … … 13 16 from pyxmpp.streambase import FatalStreamError 14 17 15 import HelpIM.settings 16 import HelpIM.bot.handlers 17 import HelpIM.users 18 19 import HelpIM.logger 20 import logging 21 22 log = logging.getLogger('HelpIM.chatbot') 23 logger = log # make logger object for pyxmpp 24 25 # temporary for testing 26 pidfile = '/tmp/HelpIMbot.pid' 18 import HelpIM.sharedvars 19 import HelpIM.baseconfig 20 21 pidfile = '' 27 22 28 23 class Exit(Exception): … … 170 165 171 166 def start(): 167 global log 168 global logger 169 import HelpIM.settings 170 import HelpIM.bot.handlers 171 import HelpIM.users 172 173 import HelpIM.logger 174 import logging 175 176 log = logging.getLogger('HelpIM.chatbot') 177 logger = log # make logger object for pyxmpp 172 178 173 179 def cleanup(): … … 252 258 253 259 def startdeamon(): 260 global pidfile 261 pidfile = HelpIM.baseconfig.get('bot')['pidfile'] 254 262 # read pidfile 255 263 try: … … 285 293 # Whe are now detachted, make ourselves proces leader and 286 294 # make shure no pipes are left open: 295 if (os.sysconf_names.has_key("SC_OPEN_MAX")): 296 maxfd = os.sysconf("SC_OPEN_MAX") 297 else: 298 maxfd = 1024 299 for fd in range(0, maxfd): 300 try: 301 os.close(fd) 302 except OSError: # ERROR, fd wasn't open to begin with (ignored) 303 pass 304 287 305 os.setpgrp() 288 306 sys.stdin.close() … … 302 320 303 321 if __name__ == '__main__': 322 try: 323 HelpIM.sharedvars.set('HelpIMconfig', sys.argv[1]) 324 except IndexError: 325 pass 304 326 startdeamon() -
branches/version_2/HelpIM/chatdb.py
r347 r354 320 320 session[prop['property']] = prop['valuetimestamp'] 321 321 else: 322 session[prop['property']] = prop['valuetext'] 322 if prop['valuetext']: 323 session[prop['property']] = prop['valuetext'] 324 else: 325 session[prop['property']] = prop['valueid'] 323 326 if prop['property'] in ['staff', 'division']: 324 327 session[prop['property']+'_id'] = int(prop['valueid']) -
branches/version_2/HelpIM/database.py
r353 r354 104 104 return 'param(%r)' % (self.value,) 105 105 106 107 # then get the database settings and module108 dbparms=HelpIM.baseconfig.get('database')109 110 111 # get dbmodule112 dbmod = __import__(dbparms['dbmodule'])113 paramstyle = getattr(dbmod, 'paramstyle')114 converter = globals()['to_' + paramstyle]115 116 if getattr(dbmod, 'threadsafety') == 0:117 raise DBModuleNotCompatibleError118 119 106 class cursor: 120 107 """Class to mimic DB-Api 2.0 cursor functions. Does not implement not … … 126 113 def __init__(self, dict = False): 127 114 """create an cursor object""" 115 # get the database settings 116 dbparms=HelpIM.baseconfig.get('database') 117 118 # get dbmodule 119 dbmod = __import__(dbparms['dbmodule']) 120 paramstyle = getattr(dbmod, 'paramstyle') 121 self.converter = globals()['to_' + paramstyle] 122 if getattr(dbmod, 'threadsafety') == 0: 123 raise DBModuleNotCompatibleError 124 128 125 # connect to dbmodule and create an cursor 129 126 wait = 0 … … 188 185 param('%value%')) 189 186 """ 190 query, params = converter(chunked_query)187 query, params = self.converter(chunked_query) 191 188 wait = 0 192 189 while 1: -
branches/version_2/HelpIM/intranet/handler.py
r352 r354 3 3 """ 4 4 5 from mod_python import apache6 import logging7 import HelpIM.settings8 import HelpIM.logger9 import HelpIM.intranet.dispatch10 import HelpIM.intranet.response11 12 log = logging.getLogger('HelpIM.intranet')13 14 log.info('Loading settings')15 config = HelpIM.settings.get('settings', 'intranet')16 config['texts'] = HelpIM.settings.get()['texts']17 5 18 6 def handlereq(request): … … 20 8 Handles an incoming apache request. 21 9 """ 10 from mod_python import apache 11 import logging 12 import HelpIM.settings 13 import HelpIM.intranet.response 14 import HelpIM.sharedvars 15 16 # Try to get value of "PythonOption HelpIMconfig [path]" 17 # from apache configuration and make it a shared variable. 18 opts = request.get_options() 19 if opts.has_key('HelpIMconfig'): 20 HelpIM.sharedvars.set('HelpIMconfig', opts['HelpIMconfig']) 21 22 # setup with need the HelpIMconfig 23 import HelpIM.logger 24 import HelpIM.intranet.dispatch 25 log = logging.getLogger('HelpIM.intranet') 26 config = HelpIM.settings.get('settings', 'intranet') 27 config['texts'] = HelpIM.settings.get()['texts'] 28 29 # Get varibles from the apache configuration, 30 # use them for HelpIM too 22 31 apacheConfig = request.get_config() 23 32 # Don't use try / except here, it leaks memory in mod_python 3.0 24 33 if apacheConfig.has_key('PythonDebug'): 25 log = logging.getLogger('HelpIM.intranet')26 log.info('Reloading settings')27 config = HelpIM.settings.get('settings', 'intranet')28 config['texts'] = HelpIM.settings.get()['texts']29 34 config['PythonDebug'] = apacheConfig['PythonDebug'] 30 35 else: 31 try: 32 config['PythonDebug'] = None 33 except UnboundLocalError: 34 # Note: mod_python does not initialise the handler 35 # so we have to do it here 36 log = logging.getLogger('HelpIM.intranet') 37 log.info('Loading settings') 38 config = HelpIM.settings.get('settings', 'intranet') 39 config['texts'] = HelpIM.settings.get()['texts'] 40 config['PythonDebug'] = None 36 config['PythonDebug'] = None 41 37 42 38 if apacheConfig.has_key('PythonAutoReload'): -
branches/version_2/HelpIM/intranet/lib/startstop.py
r340 r354 2 2 3 3 import os 4 import sys 4 5 import string 5 6 import socket … … 7 8 import time 8 9 9 import HelpIM.settings 10 import HelpIM.baseconfig 11 import HelpIM.sharedvars 10 12 11 settings = HelpIM.settings.get() 12 pidfile = settings['pidfile'] 13 command = settings['command'] 13 pidfile = HelpIM.baseconfig.get('bot')['pidfile'] 14 14 15 def getrunning(pid): 16 try: 17 os.kill(pid, 0) 18 return True 19 except OSError, err: 20 return False 15 21 16 22 def getpid(): … … 18 24 pid_file=open(pidfile, 'r') 19 25 pid=pid_file.read() 26 pid_file.close() 20 27 else: 21 pid= None28 pid=0 22 29 return pid 23 30 … … 25 32 pid=getpid() 26 33 if pid: 27 status_message="The chatserver is running ok (pid: "+pid+")." 28 status=pid 34 if getrunning(int(pid)): 35 status_message="The chatserver is running ok (pid: "+pid+")." 36 status=pid 37 else: 38 status_message="The chatserver is not running, but pid-file exist (pid: "+pid+") Please try to stop the chatserver first" 39 status=pid 29 40 else: 30 41 status_message="The chatserver is not running." … … 41 52 return("Can't start server: ") 42 53 else: 43 os.spawnlp(os.P_NOWAIT, "python", "python", command) 44 return("The chatserver is starting: ") 54 #Find the path of the bot: 55 for path in sys.path: 56 bot = os.path.join(path, 'HelpIM/bot/bot.py') 57 if os.path.isfile(bot): 58 os.spawnl(os.P_NOWAIT, bot, 'bot.py', HelpIM.sharedvars.get('HelpIMconfig')) 59 return("The chatserver is starting: ") 60 return("Can't find server... ") 45 61 46 62 def stop(): … … 62 78 else: 63 79 return("Can't stop the chatserver: ") 64 65 def restart():66 return(stop()+" "+start())67 -
branches/version_2/HelpIM/intranet/scripts/admin.py
r340 r354 3 3 import time 4 4 import HelpIM.intranet.lib.servletbase 5 import HelpIM.intranet.lib.startstop 6 5 7 #from lib import kindertelefoon 6 8 #from lib import getsettings … … 27 29 if section in ['', 'prefs', 'shifts', 'blocked', 'users']: 28 30 # valid section, handle it 29 reloadServer = False30 31 31 32 if section == '': … … 35 36 action = self.requestVars.get('action') 36 37 if action == 'startchat': 37 namespace['status'] = startstop.start()38 namespace['status'] = HelpIM.intranet.lib.startstop.start() 38 39 elif action == 'stopchat': 39 namespace['status'] = startstop.stop()40 namespace['status'] = HelpIM.intranet.lib.startstop.stop() 40 41 if str(action).startswith('start') or str(action).startswith('stop'): 41 42 time.sleep(2) 42 43 43 44 # get status 44 namespace['status'] = namespace['status'] + startstop.status()45 namespace['status'] = namespace['status'] + HelpIM.intranet.lib.startstop.status() 45 46 elif section == 'prefs': 46 47 # preferences section … … 55 56 prefs['max-queue-length'] = str(maxQueueLength) 56 57 getsettings.store('prefs', prefs, 'prefs') 57 reloadServer = True58 58 else: 59 59 namespace['errors'].append('invalid_max-queue-length') … … 92 92 int(form['length_hour'])*60+int(form['length_minute']) 93 93 )) 94 reloadServer = True95 94 for remove in removes: 96 95 try: … … 99 98 except KeyError: 100 99 pass 101 reloadServer = True102 100 getsettings.store('shifts', shifts, 'shifts') 103 101 namespace['shifts'] = shifts … … 131 129 pass 132 130 getsettings.store('blocked', blocked, 'blocked') 133 reloadServer = True134 131 namespace['blocked'] = blocked 135 132 … … 179 176 namespace['mode'] = mode 180 177 181 # reload the server if nessecary182 if reloadServer:183 try:184 if getsettings.reloadServer():185 namespace['message'] = 'server_reloaded'186 else:187 namespace['message'] = 'cannot_reload_server'188 except IOError:189 namespace['message'] = 'server_not_running'190 191 178 template = 'admin.tpl' 192 179 else: … … 197 184 template = 'nopermission.tpl' 198 185 199 tpl = inpy.fileCacheTpl( 200 template, 201 self.config['path']['templates'], 202 self.config['path']['templates_c'], 203 encoding='iso-8859-1' 204 ) 205 #tpl.clearCache(self.config['path']['templates_c']) 206 self.response.write(tpl.fetch(namespace).encode('iso-8859-1','ignore')) 186 self.writeTemplate(template, namespace) -
branches/version_2/HelpIM/intranet/scripts/login.py
r328 r354 23 23 self.log.warn('failed login attempt: ' + form.get('username')) 24 24 else: 25 cookieHeader = "%s=%s; path=%s; domain=%s;" % ('sessid', \ 26 self.session.getSessionId(), self.config['path']['base'], \ 27 self.request.hostname) 25 if self.request.hostname in ['localhost', '127.0.0.1']: 26 cookieHeader = "%s=%s; path=%s;" % ('sessid', \ 27 self.session.getSessionId(), self.config['path']['base']) 28 else: 29 cookieHeader = "%s=%s; path=%s; domain=%s;" % ('sessid', \ 30 self.session.getSessionId(), self.config['path']['base'], \ 31 self.request.hostname) 28 32 self.response.addHeader('Set-Cookie', cookieHeader) 29 33 self.log.info('login: ' + form.get('username')) -
branches/version_2/HelpIM/status.py
r348 r354 1 """Functions for getting and setting the status of HelpIM """1 """Functions for getting and setting the status of HelpIM clients and staff""" 2 2 3 3 import logging 4 4 import HelpIM.database 5 5 import HelpIM.settings 6 import HelpIM.logger7 8 log = logging.getLogger('HelpIM')9 6 10 7 def get(jid=None, hash=None, bot=None): … … 63 60 to place clients fallen out of the waiting-queue back in the same 64 61 position if they reconnect.""" 62 63 # Don't initialize logging earlier: it needs the global HelpIMconfig 64 65 import HelpIM.logger 66 log = logging.getLogger('HelpIM') 67 65 68 if not ((jid and bot) or hash): 66 69 raise TypeError, 'jid and bot or hash needed' -
branches/version_2/HelpIM/webchat/handler.py
r317 r354 1 import logging 2 import random 3 import time 4 from mod_python import apache 5 from Crypto.Hash import SHA256 6 import HelpIM.logger 7 import HelpIM.settings 8 import HelpIM.status 9 import HelpIM.webchat.servletbase 1 def handlereq(req): 2 import logging 3 import random 4 import time 5 from mod_python import apache 6 from Crypto.Hash import SHA256 7 import HelpIM.status 8 import HelpIM.webchat.servletbase 9 import HelpIM.settings 10 import HelpIM.sharedvars 10 11 11 log = logging.getLogger('HelpIM.webchat')12 logger = log # make logger object for pyxmpp 12 rangen = random.Random() 13 rangen.seed() 13 14 14 rangen = random.Random() 15 rangen.seed() 15 ERROR_HEADER = """<html> 16 <head> 17 <title>Error</title> 18 <style> 19 p 20 { 21 border: 1px solid #ff6600; 22 background: #ffcc00; 23 padding: 1em; 24 } 25 </style> 26 </head> 27 <body> 28 <p> 29 """ 16 30 17 ERROR_HEADER = """<html> 18 <head> 19 <title>Error</title> 20 <style> 21 p 22 { 23 border: 1px solid #ff6600; 24 background: #ffcc00; 25 padding: 1em; 26 } 27 </style> 28 </head> 29 <body> 30 <p> 31 """ 31 ERROR_FOOTER = """ 32 </p> 33 </body> 34 </html> 35 """ 36 def newhash(): 37 # Generate from time and a random number a string to generate the 38 # hash from. This makes sure the hash is unique and not guessable: 39 string = str(time.time())+str(rangen.random()) 40 hash = SHA256.new(string).hexdigest() 41 return hash 32 42 33 ERROR_FOOTER = """34 </p>35 </body>36 </html> 37 """ 43 # Try to get value of "PythonOption HelpIMconfig [path]" 44 # from apache configuration and make it a shared variable. 45 opts = req.get_options() 46 if opts.has_key('HelpIMconfig'): 47 HelpIM.sharedvars.set('HelpIMconfig', opts['HelpIMconfig']) 38 48 49 # initiate logging, it needs the shared variable HelpIMconfig 50 import HelpIM.logger 51 log = logging.getLogger('HelpIM.webchat') 52 logger = log # make logger object for pyxmpp 39 53 40 def newhash(): 41 # Generate from time and a random number a string to generate the 42 # hash from. This makes sure the hash is unique and not guessable: 43 string = str(time.time())+str(rangen.random()) 44 hash = SHA256.new(string).hexdigest() 45 return hash 46 47 def handlereq(req): 54 # Get varibles from the apache configuration, 55 # use them for HelpIM too 48 56 apacheConfig = req.get_config() 49 57 # Don't use try / except here, it leaks memory in mod_python 3.0 -
branches/version_2/settings/config.example
r353 r354 19 19 20 20 [bot] 21 pidfile=/ var/run/HelpIMbot21 pidfile=/home/wt/werk/HelpIM/svn/branches/version_2/test/HelpIMbot 22 22 [database] 23 23 dbmodule=MySQLdb -
branches/version_2/settings/settings_all_example.py
r353 r354 16 16 17 17 settings = { 18 'command': '/home/wt/werk/HelpIM/svn/branches/version_2/settings/start_chat2.sh',19 'pidfile': '/home/wt/werk/HelpIM/svn/branches/version_2/test/chatbot.pid',20 18 'logging': { 21 19 # Valid levels are (from verbose to less verbose): DEBUG, INFO, WARN, ERROR, CRITICAL -
branches/version_2/settings/settings_intranet_example.py
r326 r354 17 17 settings = { 18 18 u'path': { 19 u'templates': u'/ disk/web/oefenchat.soshulp.nl/HelpIM/templates',20 u'templates_c': u'/ disk/web/oefenchat.soshulp.nl/HelpIM/templates_c',21 u'base': u' ',19 u'templates': u'/home/wt/werk/HelpIM/svn/branches/version_2/settings/templates', 20 u'templates_c': u'/home/wt/werk/HelpIM/svn/branches/version_2/test/templates_c', 21 u'base': u'/intranet', 22 22 u'protocol': u'http' 23 23 }, … … 33 33 'volunteer': 'vrijwilliger', 34 34 'coordinator': 'coordinator', 35 'administrator': 'beheerder'}, 35 'administrator': 'beheerder', 36 'testgroup': 'tester'}, 36 37 u'pages': { 37 38 # for each callable script ( baseuri+'/'+script ) the script it links to, the following … … 49 50 u'script': u'HelpIM.intranet.scripts.admin', 50 51 u'name': u'Beheer', 51 u'navigation': ['administrator' ],52 u'view': ['administrator' ]52 u'navigation': ['administrator', 'testgroup'], 53 u'view': ['administrator', 'testgroup'] 53 54 }, 54 55 u'chatsession': { … … 56 57 u'name': u'Gesprek', 57 58 u'navigation': [], 58 u'view': ['administrator', ' coordinator', 'volunteer'],59 u'view_all': ['administrator' ],59 u'view': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 60 u'view_all': ['administrator', 'testgroup'], 60 61 u'view_division': ['coordinator'], 61 62 u'view_own': ['volunteer'], … … 79 80 u'script': u'HelpIM.intranet.scripts.stats', 80 81 u'name': u'Stats', 81 u'navigation': ['administrator' ],82 u'view': ['administrator' ]82 u'navigation': ['administrator', 'testgroup'], 83 u'view': ['administrator', 'testgroup'] 83 84 }, 84 85 u'': { 85 86 u'script': u'HelpIM.intranet.scripts.page', 86 87 u'name': u'Nieuws', 87 u'navigation': ['administrator', ' coordinator', 'volunteer'],88 u'view': ['administrator', ' coordinator', 'volunteer'],89 u'edit': ['administrator' ],88 u'navigation': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 89 u'view': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 90 u'edit': ['administrator', 'testgroup'], 90 91 u'subnav': [['', 'landelijk nieuws'], ['divisionnews', 'regionaal nieuws']], 91 92 u'division': False … … 95 96 u'name': u'Nieuws', 96 97 u'navigation': [], 97 u'view': ['administrator', ' coordinator', 'volunteer'],98 u'view': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 98 99 u'edit': ['coordinator'], 99 100 u'subnav': [['', 'landelijk nieuws'], ['divisionnews', 'regionaal nieuws']], … … 103 104 u'script': u'HelpIM.intranet.scripts.chatsessions', 104 105 u'name': u'Gesprekken', 105 u'navigation': ['administrator', ' coordinator', 'volunteer'],106 u'view': ['administrator', ' coordinator', 'volunteer'],107 u'view_all': ['administrator' ],106 u'navigation': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 107 u'view': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 108 u'view_all': ['administrator', 'testgroup'], 108 109 u'view_division': ['coordinator'], 109 110 u'view_own': ['volunteer'], … … 113 114 u'script': u'HelpIM.intranet.scripts.page', 114 115 u'name': u'Handleiding', 115 u'navigation': ['administrator', ' coordinator', 'volunteer'],116 u'view': ['administrator', ' coordinator', 'volunteer'],117 u'edit': ['administrator' ],116 u'navigation': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 117 u'view': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 118 u'edit': ['administrator', 'testgroup'], 118 119 u'division': False 119 120 }, … … 121 122 u'script': u'HelpIM.intranet.scripts.files', 122 123 u'name': u'Rooster', 123 u'navigation': ['administrator', ' coordinator', 'volunteer'],124 u'view': ['administrator', ' coordinator', 'volunteer'],124 u'navigation': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 125 u'view': ['administrator', 'testgroup', 'coordinator', 'volunteer'], 125 126 u'edit': ['coordinator', 'coordinator'], 126 127 u'division': True … … 136 137 u'name': u'Gebruikersgegevens', 137 138 u'navigation': [], 138 u'view': ['administrator' ]139 u'view': ['administrator', 'testgroup'] 139 140 }, 140 141 },
