コード例 #1
0
ファイル: cache.py プロジェクト: Hiroyuki-Nagata/saku
    def build(self, stamp, body, passwd=""):
        target = body.keys()
        bodyary = []
        for key in target:
            bodyary.append(key + ":" + body[key])
            self[key] = body[key]
        bodystr = "<>".join(bodyary)
        if passwd != "":
            (pubkey, prikey) = apollo.key_pair(passwd)
            md = md5.new(bodystr).hexdigest()
            sign = apollo.sign(md, pubkey, prikey)
            self["pubkey"] = pubkey
            self["sign"] = sign
            self["target"] = ",".join(target)

            bodystr += "<>pubkey:" + pubkey + \
                       "<>sign:" + sign + \
                       "<>target:" + ",".join(target)

        id = md5.new(bodystr).hexdigest()
        self.stamp = int(stamp)
        self.recstr = str(stamp) + "<>" + id + "<>" + bodystr
        self.idstr = str(stamp) + "_" + id
        self["stamp"] = str(stamp)
        self["id"] = id
        self.id = id
        self.setpath()
        return id
コード例 #2
0
ファイル: cache.py プロジェクト: hangingman/saku
    def build(self, stamp, body, passwd=""):
        target = body.keys()
        bodyary = []
        for key in target:
            bodyary.append(key + ":" + body[key])
            self[key] = body[key]
        bodystr = "<>".join(bodyary)
        if passwd != "":
            (pubkey, prikey) = apollo.key_pair(passwd)
            md = md5.new(bodystr).hexdigest()
            sign = apollo.sign(md, pubkey, prikey)
            self["pubkey"] = pubkey
            self["sign"] = sign
            self["target"] = ",".join(target)

            bodystr += "<>pubkey:" + pubkey + \
                       "<>sign:" + sign + \
                       "<>target:" + ",".join(target)

        id = md5.new(bodystr).hexdigest()
        self.stamp = int(stamp)
        self.recstr = str(stamp) + "<>" + id + "<>" + bodystr
        self.idstr = str(stamp) + "_" + id
        self["stamp"] = str(stamp)
        self["id"] = id
        self.id = id
        self.setpath()
        return id
コード例 #3
0
ファイル: apollo.py プロジェクト: Hiroyuki-Nagata/saku
def make512pq(keystr):
    seedbuf = md5.new(keystr).digest()
    seedbuf += md5.new(keystr+"pad1").digest()
    seedbuf += md5.new(keystr+"pad2").digest()
    seedbuf += md5.new(keystr+"pad3").digest()
    p = bin_to_int(seedbuf[0:28])
    q = bin_to_int(seedbuf[28:64])
    p |= 2**215
    q |= 2**279
    return (p, q)
コード例 #4
0
ファイル: apollo.py プロジェクト: die4game/saku-ex
def make512pq(keystr):
    seedbuf = md5.new(keystr).digest()
    seedbuf += md5.new(keystr + "pad1").digest()
    seedbuf += md5.new(keystr + "pad2").digest()
    seedbuf += md5.new(keystr + "pad3").digest()
    p = bin_to_int(seedbuf[0:28])
    q = bin_to_int(seedbuf[28:64])
    p |= 2**215
    q |= 2**279
    return (p, q)
コード例 #5
0
ファイル: thread_cgi.py プロジェクト: Hiroyuki-Nagata/saku
 def print_thread(self, path, id='', page=0):
     str_path = self.str_encode(path)
     file_path = self.file_encode('thread', path)
     form = cgi.FieldStorage(environ=self.environ, fp=self.stdin)
     self.archive_uri = '%s%s/' % (config.archive_uri,
                                   md5.new(file_path).hexdigest())
     cache = Cache(file_path)
     if id and form.getfirst('ajax'):
         self.print_thread_ajax(path, id, form)
         return
     if cache.has_record():
         pass
     elif self.check_get_cache():
         if not form.getfirst('search_new_file', ''):
             cache.standby_directories()
             self.unlock()
         else:
             self.get_cache(cache)
     else:
         self.print404(id=id)
         return
     if config.use_cookie and len(cache) and (not id) and (not page):
         access = None
         try:
             cookie = SimpleCookie(self.environ.get('HTTP_COOKIE', ''))
             if 'access' in cookie:
                 access = cookie['access'].value
         except CookieError, err:
             self.stderr.write('%s\n' % err)
         newcookie = self.setcookie(cache, access)
コード例 #6
0
ファイル: thread_cgi.py プロジェクト: hangingman/saku
 def print_thread(self, path, id='', page=0):
     str_path = self.str_encode(path)
     file_path = self.file_encode('thread', path)
     form = cgi.FieldStorage(environ=self.environ, fp=self.stdin)
     self.archive_uri = '%s%s/' % (config.archive_uri,
                                   md5.new(file_path).hexdigest())
     cache = Cache(file_path)
     if id and form.getfirst('ajax'):
         self.print_thread_ajax(path, id, form)
         return
     if cache.has_record():
         pass
     elif self.check_get_cache():
         if not form.getfirst('search_new_file', ''):
             cache.standby_directories()
             self.unlock()
         else:
             self.get_cache(cache)
     else:
         self.print404(id=id)
         return
     if config.use_cookie and len(cache) and (not id) and (not page):
         access = None
         try:
             cookie = SimpleCookie(self.environ.get('HTTP_COOKIE', ''))
             if 'access' in cookie:
                 access = cookie['access'].value
         except CookieError, err:
             self.stderr.write('%s\n' % err)
         newcookie = self.setcookie(cache, access)
コード例 #7
0
ファイル: admin_cgi.py プロジェクト: kuznetz/saku-ex
 def make_sid(self):
     """Make admin sid for security."""
     sidfile = config.admin_sid
     r = ""
     for i in range(4):
         r += str(random())
     sid = md5.new(r).hexdigest()
     try:
         file(sidfile, "wb").write(sid + "\n")
     except IOError, err:
         self.stderr.write("%s: IOError: %s\n" % (sidfile, err))
コード例 #8
0
ファイル: admin_cgi.py プロジェクト: die4game/saku-ex
 def make_sid(self):
     """Make admin sid for security."""
     sidfile = config.admin_sid
     r = ""
     for i in range(4):
         r += str(random())
     sid = md5.new(r).hexdigest()
     try:
         file(sidfile, "wb").write(sid + "\n")
     except IOError, err:
         self.stderr.write("%s: IOError: %s\n" % (sidfile, err))
コード例 #9
0
ファイル: mobile_cgi.py プロジェクト: Hiroyuki-Nagata/saku
 def print_thread(self, path, id='', page=0):
     str_path = self.str_encode(path)
     file_path = self.file_encode('thread', path)
     self.archive_uri = '%s%s/' % (config.archive_uri,
                                   md5.new(file_path).hexdigest())
     cache = Cache(file_path)
     if cache.has_record():
         pass
     elif self.check_get_cache():
         self.get_cache(cache)
     else:
         self.print404(id=id)
         return
     ids = cache.keys()
     self.header(path)
     form = self.form
     self.stdout.write('<p id="pagenavi">\n')
     self.stdout.write('<a href="%s" accesskey="0">[0]%s</a> | ' %
                       (self.mobile_cgi, self.message['top']))
     self.stdout.write(
         '  <a href="#bottom" id="top" accesskey="8">[8]%s</a>\n' %
         self.message['bottom_of_page'])
     self.print_page_navi(page, cache, path, str_path, id)
     self.stdout.write('</p>\n<div id="records">\n')
     page_size = config.mobile_page_size
     if id:
         inrange = ids
     elif page:
         inrange = ids[-page_size*(page+1):-page_size*page]
     else:
         inrange = ids[-page_size*(page+1):]
     printed = False
     for k in inrange:
         rec = cache[k]
         if ((not id) or (rec.id[:8] == id)) and rec.load_body():
             self.print_record(cache, rec, path, str_path, id)
             printed = True
         rec.free()
     self.stdout.write("</div>\n")
     if id and (not printed) and config.archive_uri:
         self.print_jump('%s%s.html' % (self.archive_uri, id))
     escaped_path = cgi.escape(path)
     escaped_path = re.sub(r'  ', '&nbsp;&nbsp;', escaped_path)
     var = {
         'cache': cache,
     }
     self.stdout.write(self.template('mobile_thread_top', var))
     if len(cache):
         self.print_page_navi(page, cache, path, str_path, id)
         self.stdout.write('</p>\n')
     self.print_post_form(cache, id=id)
     self.remove_file_form(cache, escaped_path)
     self.footer()
コード例 #10
0
 def print_thread(self, path, id='', page=0):
     str_path = self.str_encode(path)
     file_path = self.file_encode('thread', path)
     self.archive_uri = '%s%s/' % (config.archive_uri,
                                   md5.new(file_path).hexdigest())
     cache = Cache(file_path)
     if cache.has_record():
         pass
     elif self.check_get_cache():
         self.get_cache(cache)
     else:
         self.print404(id=id)
         return
     ids = cache.keys()
     self.header(path)
     form = self.form
     self.stdout.write('<p id="pagenavi">\n')
     self.stdout.write('<a href="%s" accesskey="0">[0]%s</a> | ' %
                       (self.mobile_cgi, self.message['top']))
     self.stdout.write(
         '  <a href="#bottom" id="top" accesskey="8">[8]%s</a>\n' %
         self.message['bottom_of_page'])
     self.print_page_navi(page, cache, path, str_path, id)
     self.stdout.write('</p>\n<div id="records">\n')
     page_size = config.mobile_page_size
     if id:
         inrange = ids
     elif page:
         inrange = ids[-page_size * (page + 1):-page_size * page]
     else:
         inrange = ids[-page_size * (page + 1):]
     printed = False
     for k in inrange:
         rec = cache[k]
         if ((not id) or (rec.id[:8] == id)) and rec.load_body():
             self.print_record(cache, rec, path, str_path, id)
             printed = True
         rec.free()
     self.stdout.write("</div>\n")
     if id and (not printed) and config.archive_uri:
         self.print_jump('%s%s.html' % (self.archive_uri, id))
     escaped_path = cgi.escape(path)
     escaped_path = re.sub(r'  ', '&nbsp;&nbsp;', escaped_path)
     var = {
         'cache': cache,
     }
     self.stdout.write(self.template('mobile_thread_top', var))
     if len(cache):
         self.print_page_navi(page, cache, path, str_path, id)
         self.stdout.write('</p>\n')
     self.print_post_form(cache, id=id)
     self.remove_file_form(cache, escaped_path)
     self.footer()
コード例 #11
0
 def update(self):
     now = int(time())
     tmp = []
     changed = False
     for addr, stamp in self.available:
         if now < stamp + config.tmpaddr_span:
             tmp.append((addr, stamp))
         else:
             changed = True
     if len(tmp) < config.tmpaddr_size:
         r = ''
         for i in range(4):
             r += str(random())
         addr = md5.new(r).hexdigest()[:config.tmpaddr_length]
         tmp.append((addr, now))
         changed = True
     if changed:
         self.available = tmp
         self.sync()
コード例 #12
0
ファイル: tmpaddr.py プロジェクト: Hiroyuki-Nagata/saku
 def update(self):
     now = int(time())
     tmp = []
     changed = False
     for addr, stamp in self.available:
         if now < stamp + config.tmpaddr_span:
             tmp.append((addr, stamp))
         else:
             changed = True
     if len(tmp) < config.tmpaddr_size:
         r = ''
         for i in range(4):
             r += str(random())
         addr = md5.new(r).hexdigest()[:config.tmpaddr_length]
         tmp.append((addr, now))
         changed = True
     if changed:
         self.available = tmp
         self.sync()
コード例 #13
0
ファイル: cache.py プロジェクト: hangingman/saku
    def check_sign(self):
        """Check sigunature."""
        for k in ("pubkey", "sign", "target"):
            if k not in self:
                return False
        target = ""
        for t in self["target"].split(","):
            try:
                target += "<>" + t + ":" + self[t]
            except KeyError:
                return False
            except ValueError:
                return False
        target = target[2:]  # remove ^<>

        md = md5.new(target).hexdigest()
        if apollo.verify(md, self["sign"], self["pubkey"]):
            return True
        else:
            return False
コード例 #14
0
ファイル: cache.py プロジェクト: Hiroyuki-Nagata/saku
    def check_sign(self):
        """Check sigunature."""
        for k in ("pubkey", "sign", "target"):
            if k not in self:
                return False
        target = ""
        for t in self["target"].split(","):
            try:
                target += "<>" + t + ":" + self[t]
            except KeyError:
                return False
            except ValueError:
                return False
        target = target[2:]         # remove ^<>

        md = md5.new(target).hexdigest()
        if apollo.verify(md, self["sign"], self["pubkey"]):
            return True
        else:
            return False
コード例 #15
0
ファイル: cache.py プロジェクト: hangingman/saku
 def md5check(self):
     buf = str(self).split("<>", 2)
     if (len(buf) > 2):
         return md5.new(buf[2]).hexdigest() == self["id"]
     else:
         return False
コード例 #16
0
ファイル: cache.py プロジェクト: Hiroyuki-Nagata/saku
 def md5check(self):
     buf = str(self).split("<>", 2)
     if (len(buf) > 2):
         return md5.new(buf[2]).hexdigest() == self["id"]
     else:
         return False
コード例 #17
0
ファイル: apollo.py プロジェクト: die4game/saku-ex
def cut_key(key):
    """Cut KeyStr to 11words."""
    short_key = base64.encodestring(md5.new(key[:512]).digest())[:11]
    return short_key
コード例 #18
0
ファイル: apollo.py プロジェクト: Hiroyuki-Nagata/saku
def cut_key(key):
    """Cut KeyStr to 11words."""
    short_key = base64.encodestring(md5.new(key[:512]).digest())[:11]
    return short_key