Update of /cvsroot/mailman/mailman/Mailman/Cgi
In directory usw-pr-cvs1:/tmp/cvs-serv21133

Modified Files:
        private.py 
Log Message:
Updates for the new authentication scheme.  Note that there are other
cleanups we could do to this file, but there are other priorities at
the moment.

Cleaned up the imports.  Removed login_attemped and _list unused
module globals.  i18n setup.

main(): Set the i18n language, first to the server default, then to
the list preferred, once we have a valid list, and to the user's
preferred language once we know that.  Updates for new string methods.
Removed a call to IsListInitialized() and use return instead of
sys.exit(0).  Better cgidata style.  Use new WebAuthenticate()
mechanisms to authenticate the user.


Index: private.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Cgi/private.py,v
retrieving revision 2.8
retrieving revision 2.9
diff -C2 -r2.8 -r2.9
*** private.py  2001/05/31 16:34:54     2.8
--- private.py  2001/06/01 17:11:40     2.9
***************
*** 16,22 ****
  
  """Provide a password-interface wrapper around private archives.
- 
- Currently this is organized to obtain passwords for Mailman mailing list
- subscribers.
  """
  
--- 16,19 ----
***************
*** 25,40 ****
  import cgi
  
- from Mailman import Utils, MailList, Errors
- from Mailman.htmlformat import *
- from Mailman.Logging.Utils import LogStdErr
  from Mailman import mm_cfg
  from Mailman.Logging.Syslog import syslog
- from Mailman.i18n import _
  
! LogStdErr("error", "private")
  
- login_attempted = 0
- _list = None
  
  def true_path(path):
      "Ensure that the path is safe by removing .."
--- 22,41 ----
  import cgi
  
  from Mailman import mm_cfg
+ from Mailman import Utils
+ from Mailman import MailList
+ from Mailman import Errors
+ from Mailman import i18n
+ from Mailman import Cookie
+ from Mailman.htmlformat import *
  from Mailman.Logging.Syslog import syslog
  
! # Set up i18n.  Until we know which list is being requested, we use the
! # server's default.
! _ = i18n._
! i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
  
  
+ 
  def true_path(path):
      "Ensure that the path is safe by removing .."
***************
*** 52,57 ****
--- 53,61 ----
  
  
+ 
  def main():
      doc = Document()
+     doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
+ 
      parts = Utils.GetPathPieces()
      if not parts:
***************
*** 59,63 ****
          doc.AddItem(Header(3, _("You must specify a list.")))
          print doc.Format()
!         sys.exit(0)
  
      path = os.environ.get('PATH_INFO')
--- 63,67 ----
          doc.AddItem(Header(3, _("You must specify a list.")))
          print doc.Format()
!         return
  
      path = os.environ.get('PATH_INFO')
***************
*** 72,76 ****
  
      # See if it's the list's mbox file is being requested
!     if listname[-5:] == '.mbox' and mboxfile[-5:] == '.mbox' and \
             listname[:-5] == mboxfile[:-5]:
          listname = listname[:-5]
--- 76,80 ----
  
      # See if it's the list's mbox file is being requested
!     if listname.endswith('.mbox') and mboxfile.endswith('.mbox') and \
             listname[:-5] == mboxfile[:-5]:
          listname = listname[:-5]
***************
*** 84,94 ****
          true_filename = true_filename + '/index.html'
      if not os.path.exists(true_filename) and \
!        os.path.exists(true_filename + '.gz'):
!         # then
          true_filename = true_filename + '.gz'
  
      try:
          mlist = MailList.MailList(listname, lock=0)
-         mlist.IsListInitialized()
      except Errors.MMListError, e:
          msg = _('No such list <em>%(listname)s</em>')
--- 88,96 ----
          true_filename = true_filename + '/index.html'
      if not os.path.exists(true_filename) and \
!            os.path.exists(true_filename + '.gz'):
          true_filename = true_filename + '.gz'
  
      try:
          mlist = MailList.MailList(listname, lock=0)
      except Errors.MMListError, e:
          msg = _('No such list <em>%(listname)s</em>')
***************
*** 97,134 ****
          print doc.Format()
          syslog('error', 'No such list "%s": %s\n' % (listname, e))
!         sys.exit(0)
  
!     form = cgi.FieldStorage()
!     user = password = None
!     if form.has_key('username'):
!         user = form['username']
!         if type(user) == type([]): user = user[0]
!         user = user.value
!     if form.has_key('password'): 
!         password = form['password']
!         if type(password) == type([]): password = password[0]
!         password = password.value
  
      is_auth = 0
      realname = mlist.real_name
!     message = (_("Please enter your %(realname)s subscription email address "
!                "and password."))
!     try:
!         is_auth = mlist.WebAuthenticate(user=user,
!                                           password=password,
!                                           cookie='archive')
!     except (Errors.MMBadUserError, Errors.MMBadPasswordError,
!             Errors.MMNotAMemberError): 
!         message = (_('Your email address or password were incorrect. '
!                    'Please try again.'))
!     except Errors.MMExpiredCookieError:
!         message = _('Your cookie has gone stale, ' \
!                   'enter password to get a new one.'),
!     except Errors.MMInvalidCookieError:
!         message = _('Error decoding authorization cookie.')
!     except Errors.MMAuthenticationError:
!         message = _('Authentication error.')
!     
!     if not is_auth:
          # Output the password form
          charset = Utils.GetCharSet(mlist.preferred_language)
--- 99,123 ----
          print doc.Format()
          syslog('error', 'No such list "%s": %s\n' % (listname, e))
!         return
  
!     i18n.set_language(mlist.preferred_language)
!     doc.set_language(mlist.preferred_language)
  
+     cgidata = cgi.FieldStorage()
+     username = cgidata.getvalue('username', '')
+     password = cgidata.getvalue('password', '')
+ 
      is_auth = 0
      realname = mlist.real_name
!     message = ''
! 
!     if not mlist.WebAuthenticate((mm_cfg.AuthUser,
!                                   mm_cfg.AuthListModerator,
!                                   mm_cfg.AuthListAdmin,
!                                   mm_cfg.AuthSiteAdmin),
!                                  password, username):
!         if cgidata.has_key('submit'):
!             # This is a re-authorization attempt
!             message = Bold(FontSize('+1', _('Authorization failed.'))).Format()
          # Output the password form
          charset = Utils.GetCharSet(mlist.preferred_language)
***************
*** 144,147 ****
--- 133,140 ----
          return
  
+     lang = mlist.GetPreferredLanguage(username)
+     i18n.set_language(lang)
+     doc.set_language(lang)
+ 
      # Authorization confirmed... output the desired file
      try:
***************
*** 157,161 ****
              f = open(true_filename, 'r')
      except IOError:
!         print 'Content-type: text/html; charset=' + Utils.GetCharSet() + '\n\n'
  
          print "<H3>" + _("Archive File Not Found") + "</H3>"
--- 150,155 ----
              f = open(true_filename, 'r')
      except IOError:
!         charset = Utils.GetCharSet(lang)
!         print 'Content-type: text/html; charset=' + charset + '\n\n'
  
          print "<H3>" + _("Archive File Not Found") + "</H3>"


_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/mailman-checkins

Reply via email to