Exemplo n.º 1
0
    def LogWarn(self, *args, **keywords):
        argsList = self.ArrangeArguments(*args, **keywords)
        if self.isLogWarning and self.logChannel.IsLogChannelOpen(log.LGWARN) or charsession and not boot.role == 'client':
            try:
                if len(argsList) == 1:
                    s = strx(argsList[0])
                else:
                    s = ' '.join(map(strx, argsList))
                if self.logChannel.IsOpen(log.LGWARN):
                    self.logChannel.Log(s, log.LGWARN, 1, force=True)
                for x in util.LineWrap(s, 10):
                    if charsession and not boot.role == 'client':
                        charsession.LogSessionHistory(x, None, 1)

            except TypeError:
                sys.exc_clear()
                x = '[X]'.join(map(strx, argsList)).replace('\x00', '\\0')
                if self.logChannel.IsOpen(log.LGWARN):
                    self.logChannel.Log(x, log.LGWARN, 1, force=True)
                if charsession and not boot.role == 'client':
                    charsession.LogSessionHistory(x, None, 1)
            except UnicodeEncodeError:
                sys.exc_clear()
                x = '[U]'.join(map(lambda x: x.encode('ascii', 'replace'), map(unicode, argsList)))
                if self.logChannel.IsOpen(log.LGWARN):
                    self.logChannel.Log(x, log.LGWARN, 1, force=True)
                if charsession and not boot.role == 'client':
                    charsession.LogSessionHistory(x, None, 1)
Exemplo n.º 2
0
    def Flush(self):
        if self.done:
            return
        self.done = 1
        self.buff.seek(0, 2)
        self.header['Content-Length'] = self.buff.tell()
        if 'Content-Type' not in self.header:
            self.header['Content-Type'] = self.contentType
        self.header['Server'] = 'CCP-SP/%s' % boot.version
        if 'Keep-Alive' not in self.header:
            self.header['Keep-Alive'] = 'timeout=15, max=98'
        if 'Connection' not in self.header:
            self.header['Connection'] = 'Keep-Alive'
        if self.authenticate:
            self.header['WWW-Authenticate'] = 'Basic realm="CCP SERVER PAGES"'
            for k, v in self.httpService.GetStaticHeader().iteritems():
                if k not in self.header:
                    self.header[k] = v

        if self.cookie:
            s = ''.join([ '%s=%s; ' % (k, v) for k, v in self.cookie.iteritems() ])
            self.header['Set-Cookie'] = s + 'path=/'
        s = cStringIO.StringIO()
        s.write('HTTP/1.1 ')
        s.write(str(self.status))
        s.write('\r\n')
        for k, v in self.header.iteritems():
            s.write(k)
            s.write(': ')
            s.write(str(v))
            s.write('\r\n')

        s.write('\r\n')
        e = self.buff.getvalue()
        s.write(e)
        out = s.getvalue()
        service = self.httpService
        if service.httpLog:
            if service.logChannel.IsOpen(1):
                for y in out.split('\n'):
                    for l in util.LineWrap(y.replace('\r', ''), maxlines=0, maxlen=80, pfx=''):
                        service.LogMethodCall('HTTP OUTPUT: ', strx(l))

        self.ep.Write(out)
Exemplo n.º 3
0
    def ParseHeader(self):
        self.Init()
        request, self.header, head, body = self.ReadRequest()
        self.raw = ''.join((head, body))
        line = request
        sp = line.find(' ')
        self.method = line[:sp]
        self.proto = line[-9:].strip()
        if self.proto not in ('HTTP/1.0', 'HTTP/1.1'):
            raise UserError('Unknown protocol', self.proto)
        if self.method not in ('GET', 'POST', 'HEAD', 'OPTIONS'):
            raise UserError('Unknown command', self.method)
        self.path = line[sp + 1:-9]
        argidx = self.path.find('?')
        if argidx != -1:
            self.args = self.path[argidx + 1:]
            self.path = self.path[:argidx]
            htmlwriter.SplitArgs(self.args, self.query)
        else:
            import urllib
            self.path = urllib.unquote_plus(self.path)
        if self.path.startswith('/'):
            self.paths = self.path[1:].split('/')
        else:
            self.paths = []
        if self.header.has_key('Cookie'):
            cookies = self.header['Cookie']
            for cookie in cookies.split(';'):
                kv = cookie.split('=', 1)
                if len(kv) == 2:
                    self.cookie[kv[0].strip()] = kv[1].strip()

        service = self.httpService
        if service.httpLog:
            if service.logChannel.IsOpen(1):
                for y in strx(self.buff[:-4]).split('\n'):
                    for l in util.LineWrap(y.replace('\r', ''), maxlines=0, maxlen=80, pfx=''):
                        service.LogMethodCall('HTTP INPUT: ', l)

        if 'Expect' in self.header and self.header['Expect'].lower().strip().find('100-continue') >= 0:
            self.ep.Write('HTTP/1.1 100 Continue\r\n\r\n')
            if service.httpLog:
                service.LogMethodCall('HTTP OUTPUT: HTTP/1.1 100 Continue')
                service.LogMethodCall('HTTP OUTPUT: ')
        if self.method == 'POST':
            form = body
            if form:
                if service.httpLog:
                    if service.logChannel.IsOpen(1):
                        for y in strx(form).split('\n'):
                            for l in util.LineWrap(y.replace('\r', ''), maxlines=0, maxlen=80, pfx=''):
                                service.LogMethodCall('HTTP INPUT: ', l)

                if self.header['Content-Type'].find('multipart/form-data') == -1:
                    htmlwriter.SplitArgs(form, self.form)
                else:
                    hd, body = head, body
                    req, hd = hd.split('\r\n', 1)
                    headers = hd.split('\r\n')
                    headers = [ header.split(': ', 1) for header in headers ]
                    headers = [ header for header in headers if len(header) > 1 ]
                    headers = dict([ (k.lower(), v) for k, v in headers ])
                    method = req.split(' ', 1)[0]
                    fields = cgi.FieldStorage(StringIO.StringIO(body), headers=headers, strict_parsing=1, environ={'REQUEST_METHOD': method})
                    self.formfields = fields
                    htmlwriter.SplitMIMEArgs(fields, self.form)
                if 'action' in self.form and 'action' not in self.query:
                    action = self.form['action']
                    if action != 'ActionTakenFromQuery':
                        self.query['action'] = action
Exemplo n.º 4
0
 def DoPaste(self, *args):
     text = blue.pyos.GetClipboardData()
     for chunk in util.LineWrap(text, maxlines=-1, maxlen=1500, pfx=''):
         self.wnd.sr.input.Paste(chunk)