def search(server_id, username = None): log_debug(3, server_id, username) s = Server(None) if not s.reload(server_id) == 0: log_error("Reloading server id %d failed" % server_id) # we can't say that the server is not really found raise rhnFault(20) # now that it is reloaded, fix up the s.user field if username: s.user = rhnUser.search(username) return s
def search(server_id, username=None): """ search for a server in the database and return the Server object """ log_debug(3, server_id, username) s = Server(None) if not s.reload(server_id) == 0: log_error("Reloading server id %d failed" % server_id) # we can't say that the server is not really found raise rhnFault(20) # now that it is reloaded, fix up the s.user field if username: s.user = rhnUser.search(username) return s
def main(): if os.path.isdir(CONFIG_STORAGE_PATH) and not debug_mode: shutil.rmtree(CONFIG_STORAGE_PATH) if not debug_mode: os.makedirs(CONFIG_STORAGE_PATH) for path in CONFIGURATION_PATHS: path_segments = path.split('/') output_path = os.path.join(CONFIG_STORAGE_PATH, path_segments[len(path_segments) - 1]) if not debug_mode: shutil.copyfile(path, output_path) with open(output_path, 'r') as config_file: global server_name lines = config_file.readlines() for line_number in range(0, len(lines)): line = lines[line_number].rstrip() if 'server' in line and '{' in line: # The begining of the definition of a server start_line = line_number while not line.startswith('}'): line_number += 1 line = lines[line_number].rstrip() end_line = line_number configured_servers.append(Server(start_line, end_line, lines))
def get(system_id, load_user = 1): log_debug(3, "load_user = %s" % load_user) # This has to be a string if not type(system_id) == type(""): return None # Try to initialize the certificate object cert = Certificate() if not cert.reload(system_id) == 0: return None # if invalid, stop here if not cert.valid(): return None # this looks like a real server server = Server(None) # and load it up if not server.loadcert(cert, load_user) == 0: return None # okay, it is a valid certificate return server
def get(system_id, load_user=1): """ retrieve the server with matching certificate from the database """ log_debug(3, "load_user = %s" % load_user) # This has to be a string if not isinstance(system_id, (StringType, UnicodeType)): return None # Try to initialize the certificate object cert = Certificate() if not cert.reload(system_id) == 0: return None # if invalid, stop here if not cert.valid(): return None # this looks like a real server server = Server(None) # and load it up if not server.loadcert(cert, load_user) == 0: return None # okay, it is a valid certificate return server
async def handle_echo(reader, writer): """ Server-client connections are handled in this function""" addr = writer.get_extra_info('peername') message = f"{addr} is connected !!!!" CLIENT_DICTIONARY[addr[1]] = Server() print(message) while True: data = await reader.read(10000) message = data.decode().strip() if message == 'quit': break print(f"Received {message} from {addr}") reply = CLIENT_DICTIONARY[addr[1]].split(message) print(f"Send: {reply}") #hello = 'successful' if reply != '' or reply != 'None': writer.write(reply.encode()) else: reply = '.' writer.write(reply.encode()) await writer.drain() print("Close the connection") writer.close()
# Imports from bot_class import Bot from channel_class import Channel from chat_class import Chat # Classes from server_class import Server from socket_class import Socket from user_class import User from viewers_class import Viewers # Setup Classes server = "irc.twitch.tv" port = 6667 svr = Server(server, port) # Channel to Join Here channel = "" chn = Channel(channel) # Channels User Here user = "" usr = User(user) # Bot Details Here bot = "" oath = "" bot = Bot(bot, oath) vws = Viewers(chn)
def connection_thread(connectionSocket): sentence = connectionSocket.recv(1024).decode() server = Server() response = server.send_http_response(sentence, connectionSocket) connectionSocket.close()
def __init__(self,s_name,s_login): Server.__init__(self,s_name,s_login) self.vars = {"CHOWN":None,"MV":None,"CHMOD":None,"TAR":None,"CAT":None,"AWK":None,"DU":None,"FIND":None,"IPTABLES":None,"CP":None,"DBROOT":None,"SITE_DIR":None}
def __init__(self, count): Thread.__init__(self) self.s = Server()
from client_class import Client from server_class import Server from threading import Thread if __name__ == "__main__": c = None s = None try: client_port = 9001 # this is the other server's port server_port = 9001 # this is the port that you are hosting ## Server Setup s = Server("", server_port) s.bindSetup() x = Thread(target=s.serverLoop) x.start() ## Client Setup c = Client("", client_port) c.connect() y = Thread(target=c.clientLoop) y.start() x.join() y.join() except KeyboardInterrupt: print("Pressed CTL+C") finally: if s:
server.store(key) else: if state == '1111': encrypted = server.recv(encoding=False) decrypted = decrypt(encrypted) write(decrypted) else: server.store(state) if __name__ == '__main__': if len(argv) != 3: print(colored("Correct Usage: script host port", 'red')) exit() host, port = argv[1], int(argv[2]) server = Server(host, port) t1 = Thread(target=send, args=(server, )) t2 = Thread(target=recv, args=(server, )) t1.start() t2.start() t2.join() print(0) server.close() exit()