def show(self): pager = os.environ.get('PAGER') if not pager: self.glob.logger.log("KEYDB", "PAGER env must be set") return proc = subprocess.Popen(pager, shell=True, stdin=subprocess.PIPE) pipe = proc.stdin try: with self.lock: for l in sorted(self.lenmap.keys()): for h in self.lenmap[l]: key = self.keys[h] s = "%3d %s:%d\t%s\t%s\t%s\t%s\t%dB\t%s\n" % \ (l, o2on_node.ip2e(key.ip), key.port, key.url, key.title.decode('utf-8'), key.note.decode('utf-8'), str(datetime.datetime.fromtimestamp(int(key.published))), key.size, hexlify(key.hash)) pipe.write(s.encode('utf-8')) pipe.close() proc.wait() except IOError, inst: if inst.errno == errno.EPIPE:pass # Broken pipe else: raise inst
def showmynode(args): if glob.prof.mynode.ip: glob.logger.log("GLOBAL", "my node is %s%s%s" % (hexlify(glob.prof.mynode.id), o2on_node.ip2e(glob.prof.mynode.ip), o2on_node.port2e(glob.prof.mynode.port))) else: glob.logger.log("GLOBAL", "Didn't get global IP")
def showmynode(args): if glob.prof.mynode.ip: glob.logger.log( "GLOBAL", "my node is %s%s%s" % (hexlify(glob.prof.mynode.id), o2on_node.ip2e( glob.prof.mynode.ip), o2on_node.port2e(glob.prof.mynode.port))) else: glob.logger.log("GLOBAL", "Didn't get global IP")
def im_list(self): res = [] with self.lock: for i in self.ims: x = (i.mine, str(datetime.datetime.fromtimestamp(int(i.date))), hexlify(i.id), ip2e(i.ip), i.port, i.name.decode('utf-8'), i.msg.decode('utf-8')) res.append(x) return res
def im_list(self): res = [] with self.lock: for i in self.ims: x = (i.mine, str(datetime.datetime.fromtimestamp(int(i.date))), hexlify(i.id), ip2e(i.ip), i.port, i.name.decode('utf-8'), i.msg.decode('utf-8')) res.append(x) return res
def do_ping(self, node): headers = common_header.copy() headers['Content-Type'] = 'text/plain' headers['Content-Length'] = "8" self.wfile.write("HTTP/1.0 200 OK\r\n") for h in headers: self.wfile.write("%s: %s\r\n" % (h,headers[h])) self.wfile.write("\r\n") self.wfile.write(ip2e(node.ip)) self.wfile.close() self.server.glob.logger.log("P2PSERVER", "respond to ping %s" % hexlify(node.id))
def status(self,args): self.send_common("status", "Status Summary") glob = self.server.glob prof = glob.prof if prof.mynode.ip: ip = "%s (%s)" % (prof.mynode.ip, ip2e(prof.mynode.ip)) else: ip = "未取得" name = prof.mynode.name or "なし" if prof.mynode.ip: nodehash = hexlify(glob.prof.mynode.id)+ip2e(glob.prof.mynode.ip)+\ port2e(glob.prof.mynode.port) else: nodehash = "IP未取得" self.wfile.write("""\ <p class='section'> <h2 class='section_title'>自ノード情報</h2> <div class='section_body'> <table> <tr><th>ID</th><th>IP</th><th>ポート</th><th>ノード名</th><th>UA</th><th>ハッシュ</th></tr> <tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr> </table> </div> </p> """ % (hexlify(prof.mynode.id), ip, prof.mynode.port, name, prof.mynode.ua, nodehash)) self.wfile.write("""\ <p class='section'> <h2 class='section_title'>概要</h2> <div class='section_body'> <table> <tr> <th><a href='/nodes'>ノード数</a></th> <th><a href='/dats'>dat数</a></th> <th><a href='/keys'>datキー数</a></th> <th><a href='/datq'>検索中dat数</a></th></tr> <tr><td>%d</td><td>%d</td><td>%d</td><td>%d</td></tr> </table> </div> </p> """ % (len(glob.nodedb), len(glob.datdb), len(glob.keydb), len(glob.datquery))) self.wfile.write(self.html_footer)
def key_list(self): res = [] with self.lock: for l in sorted(self.lenmap.keys()): for h in self.lenmap[l]: key = self.keys[h] x = (l, o2on_node.ip2e(key.ip), key.port, key.url, key.title.decode('utf-8'), key.note.decode('utf-8'), str(datetime.datetime.fromtimestamp(int(key.published))), key.size, hexlify(key.hash)) res.append(x) return res
def xml(self): if not self.valid(): return "" board_xml = "<key>\r\n" board_xml += "<hash>%s</hash>\r\n" % hexlify(self.hash) board_xml += "<nodeid>%s</nodeid>\r\n" % hexlify(self.nodeid) board_xml += "<ip>%s</ip>\r\n" % o2on_node.ip2e(self.ip) board_xml += "<port>%d</port>\r\n" % (self.port or 0) board_xml += "<size>%d</size>\r\n" % self.size board_xml += "<url>%s</url>\r\n" % self.url title = self.title.decode('utf-8') if len(title)>32: title = title[:31]+"…".decode('utf-8') board_xml += "<title><![CDATA[%s]]></title>\r\n" % title note = self.note.decode('utf-8') if len(note)>32: note = note[:31]+"…".decode('utf-8') board_xml += "<note><![CDATA[%s]]></note>\r\n" % note board_xml += "</key>\r\n" return board_xml
def do_findvalue(self,node): target = self.headers.get('X-O2-Target-Key') if not target: return self.response_400("no target key to findvalue") self.server.glob.logger.log("P2PSERVER", "\tfindvalue from %s for %s" % (hexlify(node.id), target)) target = unhexlify(target) xml_data = None keys = self.server.glob.keydb.get_bydatkey(target) if keys: xml_data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" xml_data += "<keys>\r\n" for key in keys: xml_data += key.xml() xml_data += "</keys>\r\n" else: neighbors = self.server.glob.nodedb.neighbors_nodes(target, True) if len(neighbors)>0: xml_data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" xml_data += "<nodes>\r\n" for node in neighbors: if node.ip and node.port: xml_data += "<node>\r\n" xml_data += "<id>%s</id>\r\n" % hexlify(node.id) xml_data += "<ip>%s</ip>\r\n" % ip2e(node.ip) xml_data += "<port>%s</port>\r\n" % node.port if node.name: xml_data += "<name><![CDATA[%s]]></name>\r\n" % \ node.name.decode('utf-8') if node.pubkey: xml_data += "<pubkey>%s</pubkey>\r\n" % hexlify(node.pubkey) xml_data += "</node>\r\n" xml_data += "</nodes>\r\n" if xml_data: xml_data = xml_data.encode('utf-8') headers = common_header.copy() headers['Content-Type'] = 'text/xml; charset=utf-8' headers['Content-Length'] = str(len(xml_data)) self.wfile.write("HTTP/1.0 200 OK\r\n") for h in headers: self.wfile.write("%s: %s\r\n" % (h,headers[h])) self.wfile.write("\r\n") self.wfile.write(xml_data) self.wfile.close() else: return self.response_404()