Ejemplo n.º 1
0
def zipbkp(directoryToZip):
    """
    Zips the duplicate Dumpfolder in the Temp Directory
    7zip has to be installed to use this function.
    """
    zipFileName = directoryToZip + ".zip"

    appPath = "C:\Program Files\\7-Zip"
    zApp = "7z.exe"
    zAction = 'a'
    zPass = '******'.format(param.ZIPW)
    zAnswer = '-y'
    zDir = directoryToZip
    progDir = os.path.join(appPath, zApp)

    if not os.path.isfile(progDir):
        clr.red("[X] Cannot Create .zip since 7zip is not installed!")
        sleep(3)
        return menu()

    print("[*] Trying to create .zip File, please wait...")
    cmd = [zApp, zAction, zipFileName, zPass, zAnswer, zDir]
    zipper = subprocess.Popen(cmd,
                              executable=progDir,
                              stderr=subprocess.STDOUT,
                              stdout=subprocess.PIPE)
    zipper.wait()
    clr.green("[*] Successfully created .zip File")
    return zipFileName
Ejemplo n.º 2
0
def fm_upload():
    """
    This is a Function to upload a file to the ftp server
    """
    print("[*] Please Input the Full Path to the File (or drag it here)")
    filepath = input("   -> ")
    if is_file(filepath):
        filesize = os.path.getsize(filepath)
        with open(filepath, 'rb') as f:
            with tqdm(unit='blocks',
                      unit_scale=True,
                      leave=False,
                      miniters=1,
                      desc='[*] Uploading',
                      total=filesize) as tqdm_instance:
                ftp.storbinary(
                    'STOR ' + os.path.basename(filepath),
                    f,
                    2048,
                    callback=lambda block: tqdm_instance.update(len(block)))
        clr.green("[*] Upload Successful")
        sleep(2)
        items = getitems()
        return filemenu(items)
    else:
        clr.red("\n[X] Given Path is not a File")
        sleep(2)
        items = getitems()
        return filemenu(items)
Ejemplo n.º 3
0
def mm_rotate():
    """
    This Checks if there are more than 15 Dumps in the Dumps Folder
    if so, deletes the oldest till there are 15 Dumps.
    """
    if status != colored("{0:12}".format("Connected"), "green"):
        clr.red("[X] Not Connected to a Server")
        return menu()
    else:
        ftp.cwd("Dumps")
        items = getitems()
        items_n = len(items)
        maxdumps = 15
        if items_n > maxdumps:
            clr.red("More than {0} Dumps! [{1}]".format(maxdumps, items_n))
            todel_n = items_n - maxdumps
            # print(items[0:todel_n])
            print("\n[*] Are you sure you want to rotate the Dumps? (Y/N)")
            inp = input("	-> ")
            print("")
            if inp == "Y" or inp == "y":
                for item in items[0:todel_n]:
                    print("[*] Deleting: {0}".format(item))
                    ftp.delete(item)
                clr.green("\n[*] Deleted the {0} oldest Dumps".format(todel_n))
                sleep(5)
            else:
                clr.red("\n[X] Aborted")
        else:
            clr.green("[*] Less then {0} Dumps [{1}]! We Gucci!".format(
                maxdumps, items_n))
            sleep(3)

    return menu()
Ejemplo n.º 4
0
async def on_ready():
    print(clr.green("Bot is Ready"))
    print(clr.blue(f"Serving:{len(client.guilds)} guilds."))
    nep = (client.user.name)
    print(clr.green("Logged in as", nep))
    print('-------------------------')
    await client.change_presence(status=discord.Status.online,
                                 activity=discord.Game(name="Active!"))
Ejemplo n.º 5
0
def cleanup(bkp_path, zipfile):
    """
    Cleans the Temp Directory from the Duplicate and the .zip File
    """
    print("[*] Trying to clean up, please wait...")
    try:
        shutil.rmtree(bkp_path)
        os.remove(zipfile)
    except PermissionError:
        clr.red(
            "[X] Error: Guess there's a Thumbs.db, try to manually Clean Up the Temp Directory."
        )
        pass
    clr.green("[*] Successfully Cleaned")
Ejemplo n.º 6
0
def mm_connect():
    """
    Connects to a FTP-Server using the Info given in the param file
    USRN and PSWD can be None to interactively get the Info.
    THIS IS NOT SECURE and should be replaced with SFTP in the next Versions
    """
    """ monkeypatch https://stackoverflow.com/questions/44057732/connecting-to-explicit-ftp-over-tls-in-python """
    _old_makepasv = FTP.makepasv

    def _new_makepasv(self):
        host, port = _old_makepasv(self)
        host = self.sock.getpeername()[0]
        return host, port

    FTP.makepasv = _new_makepasv
    """ monkeypatch """

    global ftp
    ftp = FTP()
    ftp.connect(param.HOST, param.PORT)
    print("[*] Successfully established a Connection to [" + param.HOST +
          "] on PORT [" + str(param.PORT) + "]")
    if param.USRN is None:
        param.USRN = input("    Username: "******"    Password: "******"[*] Trying to Authenticate as [" + param.USRN + "]")
    try:
        ftp.login(user=param.USRN, passwd=param.PSWD)
        ftp.getwelcome()
    except Exception as e:
        errorcode = e.args[0][:3]
        # print('Errorcode: {}'.format(errorcode))
        if errorcode == "530":
            clr.red("[X] Error: Wrong Login credentials ||| Errorcode: " +
                    errorcode)
            return menu()
        else:
            clr.red(
                "[X] Error: undefined error, check the errorcode. ||| Errorcode: "
                + errorcode)
            return menu()
    clr.green("[*] Successfully authenticated")

    global status
    status = colored("{0:12}".format("Connected"), "green")

    if not qu and not qd:
        return menu()
Ejemplo n.º 7
0
def mm_disconnect():
    """
    Disconnects you from a currently connected FTP-Server
    """
    global status
    if status != colored("{0:12}".format("Connected"), "green"):
        clr.red("[X] Not Connected to a Server")
        return menu()
    clr.yellow("[#] Disconnecting...")
    ftp.quit()
    clr.green("[*] Successfully disconnected")
    status = colored("{0:12}".format("Disconnected"), "red")
    sleep(1)
    if not qu and not qd:
        return menu()
Ejemplo n.º 8
0
def createbkp(root):
    """
    Creates a duplicate of the Dump folder in the Temp Directory
    Throws errors when there is a Thumbs.db blocking...
    """
    temp_dir = tempfile.gettempdir()
    date = datetime.datetime.now()
    ext = date.strftime("%Y-%m-%d")
    src = root + '\\Dump'
    dst = temp_dir + '\\' + ext + "_" + "Dump"
    print("[*] Trying to create a Duplicate, please wait...")
    try:
        monkey.copy(src, dst)
    except FileExistsError:
        try:
            shutil.rmtree(dst)
        except PermissionError:
            clr.red("[X] Error: Guess there's a Thumbs.db")
    clr.green("[*] Successfully created Duplicate")
    return dst
Ejemplo n.º 9
0
    def print(classname, commands):
        command_list = []
        for command, description in commands.items():
            command_list.append(
                [' ' + clr.green(command), ' ' + clr.yellow(description)])

        usage = columnar(command_list,
                         headers=[
                             clr.green.bold(' Command'),
                             clr.yellow.bold(' Description')
                         ])

        return f"{classname} Usage:\n" + usage
Ejemplo n.º 10
0
def fm_download(qd=False):
    """
    Downloads a File from the remote server to the current working Directory
    tqdm is used to show the download progress.
    """

    global selected
    if qd:
        ftp.cwd("Dumps")
        items = getitems()
        selected = items[-1]

    if is_file(selected):
        filesize = ftp.size(selected)
        with open(selected, 'wb') as f:
            with tqdm(unit='blocks',
                      unit_scale=True,
                      leave=False,
                      miniters=1,
                      desc='[*] Downloading',
                      total=filesize) as tqdm_instance:
                ftp.retrbinary(
                    'RETR ' + selected,
                    lambda block: download_handle(block, f, tqdm_instance),
                    2048)
        clr.green("[*] Download Successful")
        sleep(2)
        items = getitems()

        if not qd:
            return filemenu(items)
    else:
        clr.red("\n[X] Can only download files")
        sleep(2)
        items = getitems()
        if not qd:
            return filemenu(items)
Ejemplo n.º 11
0
def mm_upload():
    """
    Uploads a Dump Folder which lies next to the FTPhub pathwise.
    tqdm is used to show the upload progress.
    This function is based on functions wrote in savedum.py
    """
    if status != colored("{0:12}".format("Connected"), "green"):
        clr.red("[X] Not Connected to a Server")
        return menu()
    else:
        root = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
        bkp_path = createbkp(root)
        zipfile = zipbkp(bkp_path)

        filesize = os.path.getsize(zipfile)
        filename = os.path.basename(zipfile)
        ftp.cwd("Dumps")
        print("[*] Trying to transfer the Backup, please wait...")
        with open(zipfile, 'rb') as f:
            with tqdm(unit='blocks',
                      unit_scale=True,
                      leave=False,
                      miniters=1,
                      desc='[*] Uploading',
                      total=filesize) as tqdm_instance:
                ftp.storbinary(
                    'STOR ' + filename,
                    f,
                    2048,
                    callback=lambda sent: tqdm_instance.update(len(sent)))
        clr.green("[*] Successfully transfered the Backup")
        cleanup(bkp_path, zipfile)
        clr.magenta("[*] Upload-Function Successful")
        sleep(3)

        if not qu:
            return menu()