evol4
This commit is contained in:
@@ -14,12 +14,14 @@ from pyftpdlib.handlers import FTPHandler
|
||||
from pyftpdlib.servers import FTPServer
|
||||
from pyftpdlib.authorizers import DummyAuthorizer, AuthenticationFailed
|
||||
|
||||
# Configure logging (moved inside main function)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class DummySha256Authorizer(DummyAuthorizer):
|
||||
"""Custom authorizer that uses SHA256 for password hashing and manages users from a database."""
|
||||
|
||||
def __init__(self, cfg):
|
||||
def __init__(self: object, cfg: object) -> None:
|
||||
"""Initializes the authorizer, adds the admin user, and loads users from the database.
|
||||
|
||||
Args:
|
||||
@@ -47,7 +49,7 @@ class DummySha256Authorizer(DummyAuthorizer):
|
||||
except Exception as e:
|
||||
self.responde(f'551 Error in create virtual user path: {e}')
|
||||
|
||||
def validate_authentication(self, username, password, handler):
|
||||
def validate_authentication(self: object, username: str, password: str, handler: object) -> None:
|
||||
# Validate the user's password against the stored hash
|
||||
hash = sha256(password.encode("UTF-8")).hexdigest()
|
||||
try:
|
||||
@@ -59,7 +61,7 @@ class DummySha256Authorizer(DummyAuthorizer):
|
||||
class ASEHandler(FTPHandler):
|
||||
"""Custom FTP handler that extends FTPHandler with custom commands and file handling."""
|
||||
|
||||
def __init__(self, conn, server, ioloop=None):
|
||||
def __init__(self: object, conn: object, server: object, ioloop=None) -> None:
|
||||
"""Initializes the handler, adds custom commands, and sets up command permissions.
|
||||
|
||||
Args:
|
||||
@@ -87,26 +89,26 @@ class ASEHandler(FTPHandler):
|
||||
help='Syntax: SITE <SP> LSTU (list virtual users).')}
|
||||
)
|
||||
|
||||
def on_file_received(self, file):
|
||||
def on_file_received(self: object, file: str) -> None:
|
||||
return file_management.on_file_received(self, file)
|
||||
|
||||
def on_incomplete_file_received(self, file):
|
||||
def on_incomplete_file_received(self: object, file: str) -> None:
|
||||
"""Removes partially uploaded files.
|
||||
Args:
|
||||
file: The path to the incomplete file.
|
||||
"""
|
||||
os.remove(file)
|
||||
|
||||
def ftp_SITE_ADDU(self, line):
|
||||
def ftp_SITE_ADDU(self: object, line: str) -> None:
|
||||
return user_admin.ftp_SITE_ADDU(self, line)
|
||||
|
||||
def ftp_SITE_DISU(self, line):
|
||||
def ftp_SITE_DISU(self: object, line: str) -> None:
|
||||
return user_admin.ftp_SITE_DISU(self, line)
|
||||
|
||||
def ftp_SITE_ENAU(self, line):
|
||||
def ftp_SITE_ENAU(self: object, line: str) -> None:
|
||||
return user_admin.ftp_SITE_ENAU(self, line)
|
||||
|
||||
def ftp_SITE_LSTU(self, line):
|
||||
def ftp_SITE_LSTU(self: object, line: str) -> None:
|
||||
return user_admin.ftp_SITE_LSTU(self, line)
|
||||
|
||||
def main():
|
||||
@@ -128,6 +130,7 @@ def main():
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
format="%(asctime)s - PID: %(process)d.%(name)s.%(levelname)s: %(message)s ",
|
||||
# Use cfg.logfilename directly without checking its existence
|
||||
filename=cfg.logfilename,
|
||||
level=logging.INFO,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user