Пример #1
0
	def __findRequest(self, uri):
		"""
			Searches the config resources list to find the correct mapping of URI to Request class

			Arguements:
				uri

			Raises:
				LookupError - no resource/request mapping found in the config file
		"""
		from Common.config import TopHatConfig

		for entry in TopHatConfig.getKey("resources"):
			if entry[0] == uri:
				return entry[1]
	
		if self.uri[-1:] is "/":
			(uri, sep, self.arg) = self.uri[0:-1].rpartition("/")
		else:
			(uri, sep, self.arg) = self.uri.rpartition("/")

		uri += sep

		for entry in TopHatConfig.getKey("resources"):
			if entry[0] == uri:
				return entry[1]

		raise LookupError("No request/resource mappping found in the config file for URI %s" % uri)
Пример #2
0
	def __init__(self,):
		super(Version, self).__init__()

		from Common.config import TopHatConfig

		self._version = TopHatConfig.getKey("Version")
		self._gameVersion = TopHatConfig.getKey("GameVersion")
		self._serverName = TopHatConfig.getKey("ServerTitle")
Пример #3
0
		def __init__(self, _sock, **kwargs):

				super(SSLEncryption, self).__init__(_sock)

				try:
						self._keyfile = kwargs['keyfile']
						self._certfile= kwargs['certfile']
						self._ca_certs= kwargs['ca_certs']

				except KeyError:
					self.config = TopHatConfig.getConfig()
					self._keyfile = self.config.SSLKeyPath
					self._certfile = self.config.SSLCertPath
					self._ca_certs = self.config.SSLCAPath
					
				try:
					self._securesock= wrap_socket(  self,
						keyfile=self._keyfile, 
						ca_certs=self._ca_certs,
						certfile=self._certfile, 
						server_side=True,
						do_handshake_on_connect=True,
						)

				except SSLError:
					self._securesock=None
Пример #4
0
def main():
    from Networking.protocolhandler import ProtocolHandler
    from Common.config import TopHatConfig

    #setup the config
    TopHatConfig(path="/home/specialk/Dev/tophat/config.py")

    # do the other stuff
    from Model.Mapper import gamemapper as GM

    Mapper = GM.GameMapper()
    u = Mapper.find(1)

    from pprint import pprint
    pprint(u.dict(2))
Пример #5
0
def main():
	from Common.config import TopHatConfig

	#setup the config
	kwargs = {"path":"/home/specialk/Dev/tophat/config.py"}
	TopHatConfig(**kwargs)

	# do the other stuff
	from Model.Mapper.gamemapper import GameMapper
	from Model.Mapper.usermapper import UserMapper
	from Model.Mapper.killmapper import KillMapper
	from Model.Mapper.playermapper import PlayerMapper
	from Model.Mapper.apitokenmapper import ApitokenMapper
	from Model.Mapper.objectwatcher import ObjectWatcher

	# Get All the current Users from the database
	UM = UserMapper()
	users = UM.findAll()
	for usr in users:
		print usr

	KM = KillMapper()
	kills = KM.findAll()

	for kill_ in kills:
		print kill_

	PM = PlayerMapper()
	players = PM.findAll()

	for player_ in players:
		print player_

	GM = GameMapper()
	games = GM.findAll()
	for game_ in games:
		print game_

	ATM = ApitokenMapper()
	tokens = ATM.findAll()
	for token in tokens:
		print token

	usr1 = UM.find(1)
Пример #6
0
		def __init__(self, family, host=None, port=443):

				from sys import exit
				dispatcher.__init__(self)
				self.queue = Queue()
				self.port=port
				self.host=host
				self.config = TopHatConfig.getConfig()

				for x in range(0,self.config.Threads):

						x = TopHatThread(self.queue)
						
						self.__workers.append(x)

						x.daemon=True

						x.start()

				if host is not None:
						try:
								inet_aton(host)
						except SocketError:
								if family is not ipv6:
										exit(1)
								else:
										pass
				self.create_socket(family, tcp)

				self.set_reuse_addr()

				if host is None:
						if family is ipv6:
							self.bind(("::", port))

						else:
							self.bind(("0.0.0.0", port))
				else:
						self.bind((host, 443))
				self.listen(5)
				return
Пример #7
0
def TophatMain(config_path):
	global config
	config=TopHatConfig(path=config_path).getConfig()
	printTopHat()

	if config.Port < 1024:

		if getuid() is not 0:
			print "The TopHat-service must be started as root to bind to port %d" % config.Port
			print "[TopHat-Serivce failed to start]"
			exit(1)
		
	

		global network
		network = TopHatNetwork(AF_INET6)
		signal(SIGINT,Shutdown)
		print "Listening on port %d, deadly." % config.Port


		try:
			uidNumber= getpwnam(config.User)[2] 
			print "Dropped privileges to user '%s'. Cool pops." % config.User
		except KeyError:
			print "Failed to drop privileges to user '%s'. Uh-oh." % config.User
			print "Attempting to drop to user 'nobody'"
			try:
				uidNumber= getpwnam('nobody')[2]
				print "Dropped privileges to 'nobody'. Phew!"
			except:
				print "No user 'nobody' on this system, bit mad, I'm outta here so."
				print "[TopHat-Service failed to start]"
				exit(1)
		try:
			gidNumber= getgrnam(config.User)[2] 
			print "Dropped privileges to group '%s'. Nice." % config.User
		except KeyError:
			print "Failed to drop privileges to group '%s'. :-S" % config.User
			print "Attempting to drop to group 'daemon'"
			try:
				gidNumber= getgrnam('daemon')[2]
				
				print "Dropped privileges to group 'daemon'. It seems we're in the clear, for now."
			except:
				print "No group 'nobody' on this system, I'm not going to let you run me as root. Sorry."
				print "[TopHat-Serivce failed to start]"
				exit(1)
	else:
		global network
		network = TopHatNetwork(AF_INET6)
		signal(SIGINT,Shutdown)
		print "Listening on port %d, deadly." % config.Port


	setgid(uidNumber)
	setuid(gidNumber)
	print "[TopHat-Service started successfully]"
	log = LogFile(config.LogFile)
	log.write("TopHat Platform (c) TopHat Software 2012\n%s: Started\n" % Timestamp())
	import asyncore
	asyncore.loop(use_poll=True)
Пример #8
0
		def __init__(self,queue):
				Thread.__init__(self)
				self.queue=queue
				self.config = TopHatConfig.getConfig()
				self.stop=False
				self.transport=None