Exemple #1
0
    def __init__(self, *servers, verbose=False, enable_ssl=False):
        if enable_ssl:
            self.context = ssl.create_default_context(
                ssl.Purpose.CLIENT_AUTH, )
            BaseTCPServer.__init__(self, '', 853, SSLHandler)
        else:
            BaseTCPServer.__init__(self, '', 53, TCPHandler)

        BaseDNSServer.__init__(self, *servers, verbose=verbose)
Exemple #2
0
    def __init__(self, ip: str, public=False, req_pass=True, root_dir: str = path.curdir):
        BaseTCPServer.__init__(self, ip, 21, TCPHandler)
        self.ip = ip  # Server IP address.
        self.active = 0  # Active number of clients communicating.

        self.shutingdown = False  # Flag for if server needs to shutdown.
        self.public = public  # Flag for if the server is public. (IE: Allow anonymous log ins)
        self.req_pass = req_pass  # Flag for if the server requires a password to sign in.

        self.root = root_dir  # Root directory where files are stored for the server and clients.
        if not path.exists(f'{root_dir}{sep}users'):
            mkdir(f'{root_dir}{sep}users')  # Directory where all user directories will be saved to.
        if not path.exists(f'{root_dir}{sep}logs'):
            mkdir(f'{root_dir}{sep}logs')  # Directory where all logs will be saved to.
        if not path.exists(f'{root_dir}{sep}userdata'):
            # Directory where user data (IE usernames and passwords) will be stored
            mkdir(f'{root_dir}{sep}userdata')

        # Dictionary containing all user data
        # Gets loaded with saved data from disk if any.
        self.userdata = dict()
        self.load()

        # Logger for the server. Stores things like what users sign in with.
        self.logging = logging.getLogger('FTP Server')
        # Logger will save to disk.
        fh = logging.FileHandler(f'{self.root}{path.sep}logs{path.sep}server.log')
        fh.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
        self.logging.addHandler(fh)

        if public:
            # If this is a public server, create an anonymous account with no password info.
            public_dir = fr'{self.root}{sep}users{sep}public'
            self.userdata['anonymous'] = (None, None, public_dir)
            if not path.exists(public_dir):
                # Creates the directory for the anonymous user.
                mkdir(public_dir)
Exemple #3
0
 def __init__(self, ip, data: str = printable, width: int = 72):
     BaseTCPServer.__init__(self, ip, 19, TCPHandler)
     self.data = data
     self.size = len(data)
     self.width = width
Exemple #4
0
 def __init__(self, ip, message: bytes = b''):
     BaseTCPServer.__init__(self, ip, 17, TCPHandler)
     # Message to send to clients
     self.message = message
Exemple #5
0
 def __init__(self, ip):
     BaseTCPServer.__init__(self, ip, 7, TCPHandler)
Exemple #6
0
 def __init__(self, ip, format='%d %b %y %H:%M:%S %Z'):
     BaseTCPServer.__init__(self, ip, 13, TCPHandler)
     # String format for server to respond with
     self.format = format