示例#1
0
def execute(paramsDictionary, message):
	logger.logInfo(NAME + "wewnatrz modulu rozglaszania nowej wersji ")

	homePath = paramsDictionary["HOME_PATH"]

	lock = paramsDictionary["LOCK"]
	if lock.is_locked == False:
		return
	try:
		addressesfile = FileProcessor(paramsDictionary["HOME_PATH"]+"ServerSide/config/addresses.conf")
		addressesfile.lockFile()
		addresses = addressesfile.readFile()
		addressesfile.unlockFile()

		versionsFile = FileProcessor(homePath+"ServerSide/config/database_config/data_version.dat")
		versionsFile.lockFile()
		dataVersions = versionsFile.readFile()
		versionsFile.unlockFile()

		myVersion = dataVersions[LOCALHOST_NAME]
		logger.logInfo(NAME + "Moja wersja danych " + myVersion)
		for address in addresses:
			if addresses[address] == "T":
				logger.logInfo(NAME + "wysylanie wersji do " + address)
				connection = Connection(homePath + "ServerSide/config/connection_config.conf" )
				if connection.connect(address, 80, RESOURCE) == OK_FLAG:
					connection.send_message(myVersion)
					connection._do_closing_handshake()
				else:
					logger.logError(NAME + "Nie moge polaczyc sie z serwerem o adresie " + address)
	except Exception, e:
		logger.logError(NAME + e.message)
		lock.release
示例#2
0
def execute(paramsDictionary, message):
	remoteAddress = paramsDictionary["CLIENT_ADDRESS"]

	logger.logImportant(NAME+ "Wykryto probe nawiazania polaczenia od " + remoteAddress)
	file = FileProcessor(paramsDictionary["HOME_PATH"]+"ServerSide/config/addresses.conf")
	paramsDictionary["CONNECTION_MODE"] = False
	try:
		file.lockFile()
		addresses = file.readFile()
		for key in addresses:
			logger.logInfo(NAME+ "klucz %s", key)
			logger.logInfo(NAME+ "adres serwera zdalnego %s", remoteAddress)
			logger.logInfo(NAME+ "addresses[key] %s", addresses[key])
			if key == remoteAddress:
				logger.logInfo(NAME+ "znalazl dopasowanie")
				if( addresses[key] != 'T' ):
					logger.logInfo(NAME+ "proba nawiazania polaczenia z nowododanym serwerem")
					paramsDictionary["CONNECTION"] = Connection(paramsDictionary["HOME_PATH"]+"ServerSide/config/ping_config.conf")
					if paramsDictionary["CONNECTION"].connect(remoteAddress, 80, RESOURCE) != ERROR:
						paramsDictionary["SOCKET"] = paramsDictionary["CONNECTION"]._stream
						paramsDictionary["SOCKET"].send_message(PING)
						paramsDictionary["SOCKET"].receive_message()
						logger.logImportant(NAME+ "Polaczenie z " + remoteAddress + " nawiazane")
						addresses[key] = 'T'
						file.writeToFile(addresses)
						paramsDictionary["CONNECTION_MODE"] = True
				break
	except Exception, e:
		logger.logError(NAME + e.message)
		file.unlockFile()
示例#3
0
def web_socket_transfer_data(request):

	logger.logInfo(NAME+ "Server dostal zgloszenie")

	paramsDictionary = {}
	paramsDictionary["REQUEST"] = request
	paramsDictionary["CLIENT_ADDRESS"]= request.connection.remote_ip
	paramsDictionary["SOCKET"] = request.ws_stream
	paramsDictionary["HOME_PATH"] = request.get_options()["PROJECT_LOCATION"]

	configReader = ConfigurationReader(paramsDictionary["HOME_PATH"]+"ServerSide/config/runParams.conf")
	paramsDictionary["CONFIG_PARAMS"] = configReader.readConfigFile()

	paramsDictionary["SOCKET"].receive_message()

	if paramsDictionary["CLIENT_ADDRESS"] == PARENT_MACHINE_ADDRESS:
		paramsDictionary["SOCKET"].send_message(EXIT)
		return apache.HTTP_OK

	logger.logImportant(NAME+ "Serwer " + paramsDictionary["CLIENT_ADDRESS"] + " probuje nawiazac polaczenie")

	remoteAddress = paramsDictionary["CLIENT_ADDRESS"]

	file = FileProcessor(paramsDictionary["HOME_PATH"]+"ServerSide/config/addresses.conf")
	paramsDictionary["CONNECTION_MODE"] = True
	try:
		file.lockFile()
		addresses = file.readFile()

		for key in addresses:
			logger.logInfo(NAME+ "klucz %s " + key)
			logger.logInfo(NAME+ "adres zdalnej maszyny %s " + remoteAddress)
			logger.logInfo(NAME+ "addresses[key] %s " + addresses[key])
			if key == remoteAddress:
				if addresses[key] == 'F':
					logger.logInfo(NAME+ "znalazl dopasowanie")
					paramsDictionary["SOCKET"].send_message(PONG)
					logger.logInfo(NAME+ "Server odpowiedzial PONG do " + paramsDictionary["CLIENT_ADDRESS"])
					logger.logInfo(NAME+ "proba nawiazania polaczenia z nowododanym serwerem")
					paramsDictionary["CONNECTION"] = Connection(paramsDictionary["HOME_PATH"]+"ServerSide/config/connection_config.conf")
					if paramsDictionary["CONNECTION"].connect(remoteAddress, 80, RESOURCE) != ERROR:
						paramsDictionary["SOCKET"] = paramsDictionary["CONNECTION"]._stream
						paramsDictionary["SOCKET"].send_message(PING)
						paramsDictionary["SOCKET"].receive_message()
						logger.logInfo(NAME+ "nawiazywanie polaczenia z nowododanym serwerem")
						addresses[key] = 'T'
						file.writeToFile(addresses)
						break
				else:
					paramsDictionary["SOCKET"].send_message(EXIT)
					logger.logInfo(NAME+ "Server odpowiedzial EXIT do " + paramsDictionary["CLIENT_ADDRESS"])
					file.unlockFile()
					return apache.HTTP_OK
		file.unlockFile()
	except Exception, e:
		logger.logError(NAME + e.message)
		file.unlockFile()
		return apache.HTTP_OK
示例#4
0
def execute(paramsDictionary, message):
    logger.logInfo(NAME + "Resetuje stan serwera")
    file = FileProcessor(paramsDictionary["HOME_PATH"] + "ServerSide/config/addresses.conf")
    file.lockFile()
    addresses = file.readFile()
    for key in addresses:
        addresses[key] = "F"
    file.writeToFile(addresses)
    file.unlockFile()
示例#5
0
文件: log_wsh.py 项目: Dur/Inzynierka
def web_socket_transfer_data(request):
	path = request.get_options()["PROJECT_LOCATION"]
	message = request.ws_stream.receive_message()
	level = request.ws_stream.receive_message()
	processor = FileProcessor(path + map[level])
	processor.lockFile()
	toLog = time.strftime('%x %X') + " " + mapIpOnServerName(request.connection.remote_ip) + " " + message + '\n'
	processor.appendToFile(toLog)
	processor.unlockFile()
	return apache.HTTP_OK
示例#6
0
def web_socket_transfer_data(request):
	logger.logInfo(NAME + "Zgloszenie po bilet od " + str(request.connection.remote_ip))

	homePath = request.get_options()["PROJECT_LOCATION"]
	processor = FileProcessor(homePath + "ServerSide/config/database_config/ticketNumber.dat")
	processor.lockFile()
	number = processor.readFirstLine()
	nextNumber = int(number) + 1
	processor.writeSingleLine(str(nextNumber))
	processor.unlockFile()
	request.ws_stream.send_message(str(nextNumber))
	logger.logInfo(NAME + request.connection.remote_ip + " otrzymal bilet " + str(nextNumber))
	return apache.HTTP_OK
示例#7
0
def acknowlage(paramsDictionary, argument):
	remoteAddress = paramsDictionary["CLIENT_ADDRESS"]
	homePath = paramsDictionary["HOME_PATH"]

	logger.logInfo(NAME + "dostalem potwierdzenie zmiany hasla od " + remoteAddress)
	file = FileProcessor(homePath+"ServerSide/config/pass/all_to_me.pass")
	file.lockFile()
	passwords = file.readFile()
	passwords[remoteAddress] = generatedPass
	file.writeToFile(passwords)
	file.unlockFile()
	logger.logInfo(NAME + "Haslo zostalo zmienione")
	global expectedMessage
	expectedMessage = OLD
	global generatedPass
	generatedPass = None
def setNewPassword(paramsDictionary, newPass):
	socket = paramsDictionary["SOCKET"]
	remoteAddress = paramsDictionary["CLIENT_ADDRESS"]
	homePath = paramsDictionary["HOME_PATH"]

	logger.logInfo(NAME + "Otrzymalem nowe haslo")
	processor = FileProcessor(homePath+"ServerSide/config/pass/me_to_all.pass")
	processor.lockFile()
	passwords = processor.readFile()
	passwords[remoteAddress] = newPass
	processor.writeToFile(passwords)
	processor.unlockFile()
	logger.logInfo(NAME + "zapisalem nowe haslo")
	socket.send_message(RES_MODULE+ACK)
	logger.logInfo(NAME + "Wyslalem potwierdzenie do " + remoteAddress)
	global expectedMessage
	expectedMessage = NEW_PASS
示例#9
0
def skip(paramsDictionary, ticket):
	tempProcessor = FileProcessor(paramsDictionary["HOME_PATH"] + "ServerSide/config/tempParams.conf")
	tempProcessor.lockFile()
	params = tempProcessor.readFile()
	currentTicket = params[EXPECTED_TICKET]
	if int(currentTicket) == int(ticket):
		params[EXPECTED_TICKET] = str(int(ticket) + 1)
	else:
		toSkip = params[SKIP_TICKETS]
		toRet = ""
		if(toSkip != None and len(toSkip) != 0):
			for single in toSkip.split(","):
				if int(single)>int(currentTicket):
					toRet= toRet + single + ","
		toRet = toRet + str(ticket)
		params[SKIP_TICKETS] = toRet
	tempProcessor.writeToFile(params)
	tempProcessor.unlockFile()
示例#10
0
def web_socket_transfer_data(request):
	logger.logInfo(NAME + "Server dostal zgloszenie")
	clientAddress = request.connection.remote_ip
	socket = request.ws_stream
	homePath = request.get_options()["PROJECT_LOCATION"]
	try:
		versionsFile = FileProcessor(homePath+"ServerSide/config/database_config/data_version.dat")
		versionsFile.lockFile()
		dataVersions = versionsFile.readFile()
		version = socket.receive_message()
		logger.logInfo(NAME + "Otrzymano nowa wersje klienta " + version)
		dataVersions[clientAddress] = version
		versionsFile.writeToFile(dataVersions)
		versionsFile.unlockFile()
	except Exception, e:
		logger.logEerror(NAME + e.message)
		versionsFile.unlockFile()
		return apache.HTTP_OK
示例#11
0
def skipTicket(ticket):
	tempProcessor = FileProcessor("/home/dur/Projects/ServerSide/config/tempParams.conf")
	tempProcessor.lockFile()
	params = tempProcessor.readFile()
	currentTicket = params[EXPECTED_TICKET]
	if int(currentTicket) == int(ticket):
		params[EXPECTED_TICKET] = setNextExpectedTicket(ticket)
	else:
		toSkip = params[SKIP_TICKETS]
		toRet = ""
		if(toSkip != None and len(toSkip) != 0):
			array = toSkip.split(",")
			array.append(ticket)
			for single in sortStringsByIntValue(array):
				toRet= toRet + str(single) + ","
			toRet = toRet[:-1]
		else:
			toRet += str(ticket)
		params[SKIP_TICKETS] = toRet
	tempProcessor.writeToFile(params)
	tempProcessor.unlockFile()
示例#12
0
def insertNewDataVersions(serversList, paramsDictionary):
    try:
        homePath = paramsDictionary["HOME_PATH"]
        logger.logInfo(NAME + "Metoda wstawiajaca wiersz do tabeli z wierszami")
        versionProcessor = FileProcessor(homePath + "ServerSide/config/database_config/data_version.dat")
        versionProcessor.lockFile()
        logger.logInfo(NAME + "Plik z wersjami zablokowany")
        logger.logInfo(NAME + "Zapisywanie do pliku z wersjami")
        versions = versionProcessor.readFile()
        newVersion = str(int(versions[LOCALHOST_NAME]) + 1)
        for address in serversList:
            logger.logInfo(NAME + "Dla adresu: " + address)
            if address in versions:
                versions[address] = newVersion
                logger.logInfo(NAME + "Zapisano " + address)
        versions[LOCALHOST_NAME] = newVersion
        versionProcessor.writeToFile(versions)
        versionProcessor.unlockFile()
    except Exception, e:
        logger.logError(NAME + e.message)
        versionProcessor.unlockFile()
示例#13
0
def execute(paramsDictionary, message):
	remoteAddress = paramsDictionary["CLIENT_ADDRESS"]
	logger.logImportant(NAME+ "Wykryto odlaczenie serwera " + remoteAddress)
	file = FileProcessor(paramsDictionary["HOME_PATH"]+"ServerSide/config/addresses.conf")
	if( paramsDictionary["CONNECTION_MODE"] == True ):
		paramsDictionary["CONNECTION"]._socket.close()
	logger.logInfo(NAME+ "Proba zapisu do pliku adresowego")
	writeOk = False
	while writeOk != True:
		try:
			file.lockFile()
			logger.logInfo(NAME + "Plik adresowy zablokowany")
			writeOk = True
			addresses = file.readFile()
			addresses[paramsDictionary["CLIENT_ADDRESS"]] = 'F'
			file.writeToFile(addresses)
			file.unlockFile()
			logger.logInfo(NAME+ "Plik adresowy zaktualizowany")
			if file.lock.is_locked:
				file.unlockFile()
		except Exception, e:
			logger.logError(NAME + "Nie mozna zablokowac pliku adresowego, czekanie bedzie wznowione")
示例#14
0
def dataVersionRequestMode(paramsDictionary):

	socket = paramsDictionary["SOCKET"]
	remoteAddress = paramsDictionary["CLIENT_ADDRESS"]
	homePath = paramsDictionary["HOME_PATH"]

	if socket.receive_message() == GET_DATA_VERSION:
		logger.logInfo(NAME + "Otrzymano zapytanie o wersje danych")
		processor = FileProcessor(homePath+"ServerSide/config/database_config/data_version.dat")
		dataVersions = processor.readFile()
		socket.send_message(dataVersions[LOCALHOST])
		logger.logInfo(NAME + "Wysylano wersji danych " + dataVersions[LOCALHOST])

		socket.send_message(GET_DATA_VERSION)

		clientVersion = socket.receive_message()
		dataVersions[remoteAddress] = clientVersion
		logger.logInfo(NAME + "Otrzymano wersje danych klienta " + clientVersion)

		processor.lockFile()
		temp = processor.readFile()
		temp[remoteAddress] = dataVersions[remoteAddress]
		processor.writeToFile(temp)
		processor.unlockFile()
示例#15
0
def setNextExpectedTicket(currentTicket):
	logger.logInfo(NAME + "Otrzymalem aktualny bilet " + str(currentTicket))
	tempProcessor = FileProcessor("/home/dur/Projects/ServerSide/config/tempParams.conf")
	tempProcessor.lockFile()
	params = tempProcessor.readFile()
	if params[SKIP_TICKETS] != '':
		skipped = params[SKIP_TICKETS].split(",")
	else:
		skipped = None
	newTicket = int(currentTicket) + 1
	skipped = removeAllSkippedLowerThen(skipped, newTicket)
	while skipped.__contains__(str(newTicket)):
		skipped.remove(str(newTicket))
		newTicket = int(newTicket) + 1
	toRet = ""
	for single in skipped:
		toRet= toRet + str(single) + ","
	toRet = toRet[:-1]
	params[EXPECTED_TICKET] = str(newTicket)
	params[SKIP_TICKETS] = toRet
	tempProcessor.writeToFile(params)
	tempProcessor.unlockFile()
	logger.logInfo(NAME + "Zwracam kolejny oczekiwany bilet: " + str(newTicket))
	return newTicket
示例#16
0
		lock = FileLock(lockFilePath,2,.05)
		paramsDictionary["LOCK"] = lock

	try:
		lock.acquire()
	except Exception, e:
		logger.logError(NAME + e.message)
		if lock.is_locked:
			lock.release()
		return

	if lock.is_locked == False:
		return

	versionsFile = FileProcessor(homePath+"ServerSide/config/database_config/data_version.dat")
	versionsFile.lockFile()
	dataVersions = versionsFile.readFile()
	versionsFile.unlockFile()

	if checkIfServerIsUpToDate(dataVersions) == True:
		logger.logInfo(NAME + "Dane na serwerze sa aktualne")
		lock.release()
		return

	addressesfile = FileProcessor(paramsDictionary["HOME_PATH"]+"ServerSide/config/addresses.conf")
	addressesfile.lockFile()
	addresses = addressesfile.readFile()
	addressesfile.unlockFile()

	addressesToConnect = findActiveUpToDateServer(addresses, dataVersions)
	try:
示例#17
0
def web_socket_transfer_data(request):
	paramsDictionary = {}
	paramsDictionary["REQUEST"] = request
	paramsDictionary["SOCKET"] = request.ws_stream
	paramsDictionary["HOME_PATH"] = request.get_options()["PROJECT_LOCATION"]

	loader = ModulesLoader()
	modules = loader.loadModules(paramsDictionary["HOME_PATH"]+"ServerSide/config/modules.ext")
	paramsDictionary["MODULES"] = modules
	logger.logInfo(NAME+ "Serwer wczytal moduly")

	configReader = ConfigurationReader(paramsDictionary["HOME_PATH"]+"ServerSide/config/runParams.conf")
	runParams = configReader.readConfigFile()

	if modules.has_key("BEFORE_CONNECT"):
		for singleModule in modules["BEFORE_CONNECT"]:
			singleModule.execute(paramsDictionary, None)

	firstTimeIteration = True
	file = FileProcessor(paramsDictionary["HOME_PATH"]+"ServerSide/config/addresses.conf")

	while True:
		if modules.has_key("BEFORE_CONNECT_PERIODIC"):
			for singleModule in modules["BEFORE_CONNECT_PERIODIC"]:
				singleModule.execute(paramsDictionary, None)
		try:
			file.lockFile()
			addresses = file.readFile()
			file.unlockFile()
			for key in addresses:
				try:
					file.lockFile()
					tempAddresses = file.readFile()
					if( tempAddresses[key] == 'F' ):
						connection = Connection(request.get_options()["PROJECT_LOCATION"]+"ServerSide/config/connection_config.conf")
						if( connection.connect(key,80, RESOURCE) != ERROR ):
							logger.logInfo(NAME+ "Polaczenie z " + key + " nawiazane")
							connection.send_message(PING)
							logger.logInfo(NAME+ "Wysylanie pingu z metody startowej")
							expectedPong = connection.get_message()
							logger.logInfo(NAME + "Oczekiwano PONG, Otrzymano " + expectedPong)
							if expectedPong == PONG:
								logger.logInfo(NAME+ "Metoda startowa otrzymala odpowiedz, zamykanie polaczenia")
								connection._do_closing_handshake()
								logger.logInfo(NAME + "########### polaczenie zakonczone, zapisywanie pliku adresowego")
								tempAddresses[key] = 'T'
								file.writeToFile(tempAddresses)
								logger.logInfo(NAME + "Zapisano zmiany do pliku adresowego")
							else:
								logger.logError(NAME+ "Serwer " + key + " nie odpowiedzial na PING, zrywanie polaczenia")
						else:
							logger.logError(NAME+ "Nie moge polaczyc sie z " + key)
					file.unlockFile()
				except Exception, e:
					logger.logError(NAME + e.message)
					file.unlockFile()
		except Exception, e:
			logger.logError(NAME + e.message)
			file.unlockFile()
			continue
		file.unlockFile()

		if firstTimeIteration == True:
			firstTimeIteration = False
			if modules.has_key("AFTER_CONNECT"):
				for singleModule in modules["AFTER_CONNECT"]:
					singleModule.execute(paramsDictionary, None)

		if modules.has_key("AFTER_CONNECT_PERIODIC"):
			for singleModule in modules["AFTER_CONNECT_PERIODIC"]:
				singleModule.execute(paramsDictionary, None)

		logger.logInfo(NAME+ "Serwer rozpoczyna czeanie na kolejna ture sprawdzania")
		time.sleep(int(runParams["ConnectionCheckPeriod"]))
		logger.logInfo(NAME+ "Serwer wznawia sprawdzanie")
示例#18
0
文件: Logger.py 项目: Dur/Inzynierka
def _getLoggerAddress():
	tempProcessor = FileProcessor(HOME_PATH + "ServerSide/config/tempParams.conf")
	tempProcessor.lockFile()
	params = tempProcessor.readFile()
	tempProcessor.unlockFile()
	return params[LOGGER]
示例#19
0
from utils.FileProcessors import FileProcessor

__author__ = 'dur'

file = FileProcessor("/home/dur/Projects/ServerSide/config/addresses.conf")
file.lockFile()
addresses = file.readFile()
for key in addresses:
	addresses[key] = 'F'
file.writeToFile(addresses)
file.unlockFile()
示例#20
0
def readTempVars():
	tempProcessor = FileProcessor("/home/dur/Projects/ServerSide/config/tempParams.conf")
	tempProcessor.lockFile()
	params = tempProcessor.readFile()
	tempProcessor.unlockFile()
	return params