hak5 / pineapple-modules

The Official WiFi Pineapple Module Repository for the WiFi Pineapple Mark VII
https://wifipineapple.com
368 stars 157 forks source link

Library and module refactors #19

Closed frozenjava closed 4 years ago

frozenjava commented 4 years ago

Action handlers are no longer required to return a Tuple. If a handler just returns data, it is assumed that the data returned is a successful response. If the function returns in error, then the function should return a Tuple with the data first and boolean second.

Old Way:

def list_files(request: Request):
    dir = request.dir

    if not os.path.exists(dir):
        return False, 'No such file or directory'
    else:
        return True, 'Here are your files!'

New Way:

def list_files(request: Request):
    dir = request.dir

    if not os.path.exist(dir):
        return 'No such file or directory', False
    else:
        return 'Here are your files!'

======

Module developers can now register functions to be called on start and shutdown lifecycle events. This can be done manually by calling register_startup_handler(func) and register_shutdown_handler or by using the @on_start() and @on_shutdown() decorators.

Manual Examples:

...

def create_directory():
    os.path.mkdir('/tmp/module_logs/')

def delete_directory():
    os.unlink('/tmp/module_logs/')

module.register_startup_handler(create_directory)
module.register_shutdown_handler(delete_directory)
...

Decorator Examples:

...

@module.on_start()
def create_directory():
    os.path.mkdir('/tmp/module_logs/')

@module.on_shutdown()
def delete_directory():
    os.unlink('/tmp/module_logs/')
...

=====

Refactored existing modules to follow the new conventions.