def doSetUp(self, arg): """ Action method. """ self.hostname = settings.getIdServerHost() if self.hostname == '': self.hostname = strng.to_bin(misc.readExternalIP()) # bpio.ReadTextFile(settings.ExternalIPFilename()) if self.hostname == '': self.hostname = net_misc.getLocalIp() lg.out(4, 'id_server.doSetUp hostname=%s' % strng.to_text(self.hostname)) if not os.path.isdir(settings.IdentityServerDir()): os.makedirs(settings.IdentityServerDir()) lg.out(4, ' created a folder %s' % settings.IdentityServerDir()) root = WebRoot() root.putChild(b'', WebMainPage()) try: self.tcp_listener = reactor.listenTCP(self.tcp_port, IdServerFactory()) lg.out(4, " identity server listen on TCP port %d started" % (self.tcp_port)) except: lg.out(4, "id_server.set_up ERROR exception trying to listen on port " + str(self.tcp_port)) lg.exc() try: self.web_listener = reactor.listenTCP(self.web_port, server.Site(root)) lg.out(4, " have started web server at http://%s:%d " % (strng.to_text(self.hostname), self.web_port)) except: lg.out(4, "id_server.set_up ERROR exception trying to listen on port " + str(self.web_port)) lg.exc()
def getChild(self, path, request): if path == '': return self filepath = os.path.join(settings.IdentityServerDir(), path) if os.path.isfile(filepath): return static.File(filepath) return resource.NoResource('Not found')
def getChild(self, path, request): if not path: return self filepath = os.path.join(settings.IdentityServerDir(), strng.to_text(path)) if os.path.isfile(filepath): return static.File(filepath) return resource.NoResource('Not found')
def render(self, request): src = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Identities on %(hostname)s</title> <style> body{margin: 0 auto; padding: 0;} #content {margin: 0 auto; padding: 0; text-align: justify; line-height: 1.7; min-height: 500px; width: 960px; font-size: 18px; text-decoration: none; font-family: "Tw Cen MT", "Century Gothic", Futura, Arial, sans-serif;} </style> </head> <body> <div id="content"> <h1 align=center>Identities on %(hostname)s</h1> ''' % { 'hostname': strng.to_text(A().hostname) } src += '<table cellspacing=0 width=100% border=0><tr valign=top>\n' src += '<td width=152px nowrap>\n' HTDOCS_DIR = settings.IdentityServerDir() files = [] if os.path.isdir(HTDOCS_DIR): for filename in os.listdir(HTDOCS_DIR): filepath = os.path.join(HTDOCS_DIR, filename) if os.path.isdir(filepath): continue if not filename.endswith('.xml'): continue files.append(filename) files.sort() currentChar = '' charIndex = 0 for filename in files: if filename[0] != currentChar: currentChar = filename[0] if charIndex % 4 == 3: src += '\n</td>\n<td width=152px nowrap>\n' charIndex += 1 src += '\n<br>\n<h3>%s</h3>\n' % str(currentChar).upper() url = '/' + filename name = filename[:-4] src += '<p><a href="%s"><nobr>%s</nobr></a></p>\n' % ( strng.to_text(url), strng.to_text(name)) src += '</td>\n</tr>\n</table>\n</td>\n</tr>\n<tr><td align=left>' src += '<br><br><p>Total identities on "%s": %d</p><br><br>\n' % ( strng.to_text(A().hostname), len(files)) src += '<p>Other known identity servers:\n' for idhost in sorted(known_servers.by_host().keys()): idport = known_servers.by_host()[idhost][0] if idport != 80: idhost += b':%d' % idport src += '<a href="http://%s/"><nobr>%s</nobr></a> \n' % ( strng.to_text(idhost), strng.to_text(idhost)) src += '</p>' src += '<!--CLIENT_HOST=%s:%s-->\n' % (request.client.host, request.client.port) src += '</body>\n</html>' del files return strng.to_bin(src)
def _save_identity(self, inputfilename): """ """ lg.out(6, "id_server._save_identity " + inputfilename) if os.path.getsize(inputfilename) > 50000: lg.warn("input file too big - ignoring ") tmpfile.erase('idsrv', inputfilename, 'input file too big') # os.remove(inputfilename) return newxml = bpio.ReadTextFile(inputfilename) if len(newxml.strip()) < 500: lg.warn("input file too small - ignoring ") tmpfile.erase('idsrv', inputfilename, 'input file too small') # os.remove(inputfilename) return try: newidentity = identity.identity(xmlsrc=newxml) except: lg.warn("input file is wrong - ignoring ") tmpfile.erase('idsrv', inputfilename, 'input file is wrong') # os.remove(inputfilename) return tmpfile.erase('idsrv', inputfilename, 'id received') if not newidentity.isCorrect(): lg.warn("has non-Correct identity") return if not newidentity.Valid(): lg.warn("has non-Valid identity") return matchid = "" for idurl in newidentity.sources: protocol, host, port, filename = nameurl.UrlParse(idurl) if host == self.hostname: lg.out(4, "id_server._save_identity found match for us") matchid = idurl break if matchid == "": lg.warn("identity is not for this nameserver") return protocol, host, port, filename = nameurl.UrlParse(matchid) name, justxml = filename.split(".") # SECURITY check that name is simple if justxml != "xml": lg.warn("identity name " + filename) return if len(name) > settings.MaximumUsernameLength(): lg.warn("identity name " + filename) return if len(name) < settings.MinimumUsernameLength(): lg.warn("identity name " + filename) return for c in name: if c not in settings.LegalUsernameChars(): lg.warn("identity name " + filename) return localfilename = os.path.join(settings.IdentityServerDir(), filename) # lg.out(8,"id_server.SaveIdentity with filename " + localfilename) oldxml = '' # need to make sure id was not already used by different key - which would mean someone trying to steal identity if os.path.exists(localfilename): lg.out( 6, "id_server._save_identity was already an identity with this name " + localfilename) oldxml = bpio.ReadTextFile(localfilename) oldidentity = identity.identity(xmlsrc=oldxml) if oldidentity.publickey != newidentity.publickey: lg.warn("new public key does not match old " + localfilename) return if newxml != oldxml: if not os.path.exists(localfilename): lg.out( 6, "id_server._save_identity will save NEW Identity: " + filename) bpio.WriteFile(localfilename, newxml)