Exemplo n.º 1
0
def supply(request):
    """
    If the HTTP Verb is GET: Provide a form for adding a new spam email message.
    
    If the HTTP Verb is POST: Save and process a new email message, and view
    the resulting message.
    
    :param HttpRequest request: A web request.
    :rtype: An HttpResponse object.
    """
    user = users.get_current_user()

    if user is None:
        return redirect(users.create_login_url('/supply'))

    usetting = UserSetting.gql('WHERE userid = :1', user.user_id())
    if usetting.count() != 1 or not usetting.get().is_contrib:
        return HttpResponseForbidden('<h1>Authorization Required</h1>')

    if request.method == 'GET':
        ctx = RequestContext(request, {})
        return render_to_response('input_form.html', context_instance=ctx)

    title = request.POST['title']
    input = request.POST['input'].lstrip('\t\n\r ')
    date = datetime.now()

    email = Email(title=title, body=input, date=date, views=0, rating=0)
    email.put()

    _process_new(email)

    return redirect('/view/%s' % email.key())
Exemplo n.º 2
0
    def parseRequest(self, urlpart):
        self.customRules = self.request.get_all('c')
        self.customRules += (urlsafe_b64decode(r.encode('ascii'))
                             for r in self.request.get_all('e'))

        match = self.userPacRegxp.match(unquote(urlpart).strip())
        if match:
            setting = UserSetting.gql('WHERE pacName=:1',
                                      match.group(1).lower()).get()
            if setting is None: return

            urlpart = match.group(2) or setting.defaultProxy
            self.customRules += setting.customRules
            self.settingTime = setting.lastModified
        else:
            self.settingTime = datetime.min

        match = self.proxyRegxp.match(urlpart.lower())
        if match is None: return
        self.proxyDict = match.groupdict()

        if self.proxyDict['name']:
            if self.proxyDict['name'] not in PRESET_PROXIES: return
            self.proxyString = PRESET_PROXIES[self.proxyDict['name']][1]
        elif self.proxyDict['type']:
            self.proxyDict['type'] = 'SOCKS' if self.proxyDict[
                'type'] == 'socks' else 'PROXY'
            self.proxyString = '%(type)s %(host)s:%(port)s' % self.proxyDict

        # Chrome expects 'SOCKS5' instead of 'SOCKS', see http://j.mp/pac-test
        if useragent.family() == 'Chrome':
            self.proxyString = self.proxyString.replace('SOCKS ', 'SOCKS5 ')

        return True
Exemplo n.º 3
0
    def parseRequest(self, urlpart):
        self.customRules = self.request.get_all('c')
        self.customRules += (urlsafe_b64decode(r.encode('ascii')) for r in self.request.get_all('e'))

        match = self.userPacRegxp.match(unquote(urlpart).strip())
        if match:
            setting = UserSetting.gql('WHERE pacName=:1', match.group(1).lower()).get()
            if setting is None: return

            urlpart = match.group(2) or setting.defaultProxy
            self.customRules += setting.customRules
            self.settingTime = setting.lastModified
        else:
            self.settingTime = datetime.min

        match = self.proxyRegxp.match(urlpart.lower())
        if match is None: return
        self.proxyDict = match.groupdict()

        if self.proxyDict['name']:
            if self.proxyDict['name'] not in PRESET_PROXIES: return
            self.proxyString = PRESET_PROXIES[self.proxyDict['name']][1]
        elif self.proxyDict['type']:
            self.proxyDict['type'] = 'SOCKS' if self.proxyDict['type'] == 'socks' else 'PROXY'
            self.proxyString = '%(type)s %(host)s:%(port)s' % self.proxyDict

        # Chrome expects 'SOCKS5' instead of 'SOCKS', see http://j.mp/pac-test
        if useragent.family() == 'Chrome':
            self.proxyString = self.proxyString.replace('SOCKS ', 'SOCKS5 ')

        return True
Exemplo n.º 4
0
def supply(request):
    """
    If the HTTP Verb is GET: Provide a form for adding a new spam email message.
    
    If the HTTP Verb is POST: Save and process a new email message, and view
    the resulting message.
    
    :param HttpRequest request: A web request.
    :rtype: An HttpResponse object.
    """
    user = users.get_current_user()
    
    if user is None:
        return redirect(users.create_login_url('/supply'))
        
    usetting = UserSetting.gql('WHERE userid = :1', user.user_id())
    if usetting.count() != 1 or not usetting.get().is_contrib:
        return HttpResponseForbidden('<h1>Authorization Required</h1>')
        
    if request.method == 'GET':
        ctx = RequestContext(request, {})
        return render_to_response('input_form.html', context_instance=ctx)
        
    title = request.POST['title']
    input = request.POST['input'].lstrip('\t\n\r ')
    date = datetime.now()
    
    email = Email(title=title, body=input, date=date, views=0, rating=0)
    email.put()

    _process_new(email)
    
    return redirect('/view/%s' % email.key())
Exemplo n.º 5
0
def incoming(request):
    """
    Accept a new email message directly via the AppEngine email facility. The
    entire email message is contained in the POST body of *email*.
    
    :param HttpRequest request: A web request.
    :rtype: An HttpResponse object.
    """
    logging.info('Incoming email received.')
    
    try:
        msg = InboundEmailMessage(request.raw_post_data)
        
        usetting = UserSetting.gql('WHERE email = :1', msg.sender)
        if usetting.count() == 0:
            logging.warn('Received email from an unrecognized sender: ' + msg.sender)
            
            return render_to_response('msg_receipt.email', mimetype='text/plain')
            
        if not usetting.get().is_contrib:
            logging.warn('Received email from an unauthorized contributor: ' + msg.sender)
            
            return render_to_response('msg_receipt.email', mimetype='text/plain')
            
        content = ''
        for content_type, body in msg.bodies('text/plain'):
            headers = True
            date = False
            for line in str(body).split('\n'):
                if not date:
                    parts = line.split(' ')
                    line = ' '.join(parts[len(parts)-5:])
                    date = datetime.strptime(line, '%a %b %d %H:%M:%S %Y')
                    logging.debug(str(date))
                    
                if headers and line == '':
                    headers = False
                elif not headers:
                    content += '%s\n' % line
        
        if content == '':
            logging.warn('Received an email, but no text/plain bodies.')
        else:
            logging.info('Compiled plain-text email: body length=%d' % len(content))
            
            newtitle = msg.subject.replace('\n','').replace('\r','')
            content = content.lstrip('\t\n\r ')
            email = Email(title=newtitle, body=content, date=date, views=0, rating=0)
            email.put()
            
            logging.info('Processing new data for tokens & tags')
            
            _process_new(email)
            
    except Exception, ex:
        logging.error('Error processing new email. %s' % ex)
Exemplo n.º 6
0
def user(request):
    user = users.get_current_user()
    
    if user:
        usetting = UserSetting.gql('WHERE userid = :1', user.user_id())
        if usetting.count() == 0:
            usetting = UserSetting(userid=user.user_id(), email=db.Email(user.email()), is_contrib=False)
            usetting.put()
        userurl = users.create_logout_url(request.get_full_path())
    else:
        userurl = users.create_login_url(request.get_full_path())
        
    return {
        "user": user,
        "userurl": userurl
    }
Exemplo n.º 7
0
def incoming(request):
    """
    Accept a new email message directly via the AppEngine email facility. The
    entire email message is contained in the POST body of *email*.
    
    :param HttpRequest request: A web request.
    :rtype: An HttpResponse object.
    """
    logging.info('Incoming email received.')

    try:
        msg = InboundEmailMessage(request.raw_post_data)

        usetting = UserSetting.gql('WHERE email = :1', msg.sender)
        if usetting.count() == 0:
            logging.warn('Received email from an unrecognized sender: ' +
                         msg.sender)

            return render_to_response('msg_receipt.email',
                                      mimetype='text/plain')

        if not usetting.get().is_contrib:
            logging.warn('Received email from an unauthorized contributor: ' +
                         msg.sender)

            return render_to_response('msg_receipt.email',
                                      mimetype='text/plain')

        content = ''
        for content_type, body in msg.bodies('text/plain'):
            headers = True
            date = False
            for line in str(body).split('\n'):
                if not date:
                    parts = line.split(' ')
                    line = ' '.join(parts[len(parts) - 5:])
                    date = datetime.strptime(line, '%a %b %d %H:%M:%S %Y')
                    logging.debug(str(date))

                if headers and line == '':
                    headers = False
                elif not headers:
                    content += '%s\n' % line

        if content == '':
            logging.warn('Received an email, but no text/plain bodies.')
        else:
            logging.info('Compiled plain-text email: body length=%d' %
                         len(content))

            newtitle = msg.subject.replace('\n', '').replace('\r', '')
            content = content.lstrip('\t\n\r ')
            email = Email(title=newtitle,
                          body=content,
                          date=date,
                          views=0,
                          rating=0)
            email.put()

            logging.info('Processing new data for tokens & tags')

            _process_new(email)

    except Exception, ex:
        logging.error('Error processing new email. %s' % ex)