Exemplo n.º 1
0
Arquivo: echelon.py Projeto: zumbi/ud
 def handle(self, *args, **options):
     self.options = options
     try:
         load_configuration_file(self.options['config'])
         if settings.config.has_key('username'):
             if settings.config['username'].endswith(DebianUser.base_dn):
                 settings.DATABASES['ldap']['USER'] = settings.config[
                     'username']
             else:
                 settings.DATABASES['ldap']['USER'] = '******' % (
                     settings.config['username'], DebianUser.base_dn)
         else:
             raise CommandError(
                 _('configuration file must specify username parameter'))
         if settings.config.has_key('password'):
             settings.DATABASES['ldap']['PASSWORD'] = settings.config[
                 'password']
         else:
             raise CommandError(
                 _('configuration file must specify password parameter'))
         message = email.message_from_file(sys.stdin)
         user = None
         key = ''
         val = '[%s]' % (time.strftime("%a, %d %b %Y %H:%M:%S",
                                       time.gmtime(time.time())))
         if not key:  # determine user from signature
             try:
                 (fingerprint, content, timestamp) = verify_message(message)
                 user = get_user_from_fingerprint(fingerprint)
                 key = 'activityPGP'
                 val += ' "%s" ' % (fingerprint)
             except:
                 pass
         if not key:  # determine user from headers
             try:
                 user = get_user_from_headers(message)
                 key = 'activityFrom'
                 val += ' "%s" ' % (message.get('From'))
             except:
                 pass
         if user:
             val += ' "%s" "%s"' % (message.get('X-Mailing-List'),
                                    message.get('Message-ID'))
             if self.options['dryrun']:
                 sys.stdout.write('%s: %s\n' % (key, val))
             else:
                 user.do_update(key, val)
                 user.save()
     except Exception as err:
         raise CommandError(err)
Exemplo n.º 2
0
Arquivo: echelon.py Projeto: Debian/ud
 def handle(self, *args, **options):
     self.options = options
     try:
         load_configuration_file(self.options['config'])
         if settings.config.has_key('username'):
             if settings.config['username'].endswith(DebianUser.base_dn):
                 settings.DATABASES['ldap']['USER'] = settings.config['username']
             else:
                 settings.DATABASES['ldap']['USER'] = '******' % (settings.config['username'], DebianUser.base_dn)
         else:
             raise CommandError(_('configuration file must specify username parameter'))
         if settings.config.has_key('password'):
             settings.DATABASES['ldap']['PASSWORD'] = settings.config['password']
         else:
             raise CommandError(_('configuration file must specify password parameter'))
         message = email.message_from_file(sys.stdin)
         user = None
         key = ''
         val = '[%s]' % ( time.strftime("%a, %d %b %Y %H:%M:%S",time.gmtime(time.time())) )
         if not key: # determine user from signature
             try:
                 (fingerprint, content, timestamp) = verify_message(message)
                 user = get_user_from_fingerprint(fingerprint)
                 key = 'activityPGP'
                 val += ' "%s" ' % (fingerprint)
             except:
                 pass
         if not key: # determine user from headers
             try:
                 user = get_user_from_headers(message)
                 key = 'activityFrom'
                 val += ' "%s" ' % (message.get('From'))
             except:
                 pass
         if user:
             val += ' "%s" "%s"' % (message.get('X-Mailing-List'), message.get('Message-ID'))
             if self.options['dryrun']:
                 sys.stdout.write('%s: %s\n' % (key, val))
             else:
                 user.do_update(key, val)
                 user.save()
     except Exception as err:
         raise CommandError(err)
Exemplo n.º 3
0
 def process_message(self, message):
     (fingerprint, content, timestamp) = verify_message(message)
     self.check_replay_cache(fingerprint, content, timestamp)
     user = get_user_from_fingerprint(fingerprint)
     fd = io.StringIO(encoding='utf-8')
     fd.write(u'\n===== start of processing =====\n')
     handler = Handler(fd, user, user)
     for command in content.splitlines():
         if command == '-- ':
             break
         fd.write(u'> %s\n' % (command))
         handler.onecmd(command)
     if self.options['dryrun']:
         fd.write(u'==> dryrun: no changes saved\n')
     else:
         if handler.has_errors:
             fd.write(u'==> errors: no changes saved\n')
         else:
             user.save()
     fd.write(u'===== end of processing =====\n')
     return encrypt_result(fd.getvalue().encode('utf-8'), fingerprint)
Exemplo n.º 4
0
 def process_message(self, message):
     (fingerprint, content, timestamp) = verify_message(message)
     self.check_replay_cache(fingerprint, content, timestamp)
     user = get_user_from_fingerprint(fingerprint)
     fd = io.StringIO()
     fd.write(u'\n===== start of processing =====\n')
     handler = Handler(fd, user, user)
     for command in content.splitlines():
         if command == '-- ':
             break
         fd.write(u'> %s\n' % (command))
         handler.onecmd(command)
     if self.options['dryrun']:
         fd.write(u'==> dryrun: no changes saved\n')
     else:
         if handler.has_errors:
             fd.write(u'==> errors: no changes saved\n')
         else:
             user.save()
     fd.write(u'===== end of processing =====\n')
     fd.write(u'see https://dsa.debian.org/howto/ud/ for help\n')
     return encrypt_result(fd.getvalue().encode('utf-8'), fingerprint)