'''
webq.py - An service for sagator's quarantine over HTTP.

(c) 2005 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

'''

import re,db
from aglib import *
from av.basic import const

__all__=['webq_apache']

class webq_apache(service):
  '''
  Virtual service for sagator's quaratine access via HTTP. [obsolete]
  
  This service can be used to access email collected by sagator via
  web interface. You need to configure mod_python in apache to run
  this service.
  
  Usage: webq_apache(...)

  Where: rootdir is a string, which defines where are HTML templates
         scanner is a scanner to use for checking (only one scanner
           can be used here!)
         userconv is an array, which defines regular expression
           and substitution strings. Usernames from login prompt
           are marched against this regular expression and substitued
           by substitution string.
         admin is an array of webqueue admins.
         perms is an array of strings, which defines access permissions
           for subpages.
         db is a database connection. For description see Databases.txt.
  
  Example: see default config file for example

  This scanner is obsolete since 0.8.0. There is no replacement now,
  please wait for new webq() service in any new versions. This service
  has been marked as obsolete because it's installation is too complicated.
  '''
  name='webq_apache()'
  WEB_ROOT='/usr/lib/sagator/srv/web'
  SCANNER=const(0)
  USERCONV=['^(.*)$','\\1']
  ADMINS=[]
  ALL_PERMS=['','index','action','search',
             'view','download','recheck','deliver',
             'webscan','settings','stats','reg']
  def __init__(self,**args):
      self.PERMS=self.ALL_PERMS
      self.DB=db.dbconn(args)
      for key,value in args.items():
        if key=='rootdir':
          self.WEB_ROOT=value
        elif key=='scanner':
          self.SCANNER=value
        elif key=='userconv':
          self.USERCONV=value
        elif key=='admin':
          self.ADMINS=value
        elif key=='perms':
          self.PERMS=self.PERMS[:4]+value
        elif key in self.DB.params:
          pass # parameter used later
        elif key=='db':
          if type(value)==type(""):
            try:
              self.DB=eval('db.%s(args)' % value)
            except NameError:
              raise NameError,'%s: Database type %s not supported!' % (self.name,value)
          else:
            self.DB=value
        else:
          raise TypeError,'%s got an unexpected argument %s' % (self.name,key)
  def start(self):
      return []
