示例#1
0
def umount_storage(name):
    if ".." in name or "/" in name:
        return error("invalid name")

    mount_target = f"/media/{name}"

    if mount_target not in partitions.mounted:
        return error("not mounted")

    if partitions.umount_partition(mount_target):
        return success("Unmounting successful")
    else:
        return error("Failed unmount, check logs...")
示例#2
0
def restore_start():
    src_path = request.form.get("src_path")

    if not backup_restore.check_backup(src_path):
        msg = "Invalid backup, cannot restore"
        log.error(msg)
        return error(msg)

    log.info(f"Initiating restore from: {src_path}")

    job_kwargs = {"tar_path": src_path, "mode": "restore"}
    job_queue.put(("BackupRestore", job_kwargs))

    return success("restore started")
示例#3
0
def mount_storage(device, name=None):
    devs = partitions.block_devices
    mounted = partitions.mounted

    found = False
    for dev in devs.values():
        for part in dev["parts"].values():
            if part["name"] == device:
                found = True
                if part["mounted"]:
                    return error("device already mounted")
                if part["special"]:
                    return error("cannot mount special device")

    if not found:
        return error("Could not find device!")

    if name is None:
        for idx in range(1, 11):
            _name = f"extra-{idx}"
            mount_target = f"/media/{_name}"
            if mount_target not in mounted:
                name = _name
                break

        if name is None:
            return error("cannot determine mount target, too many mounts?")

    if ".." in device or "/" in device:
        return error("invalid device")
    if ".." in name or "/" in name:
        return error("invalid name")

    mount_target = f"/media/{name}"
    mount_device = f"/dev/{device}"

    if not os.path.exists(mount_target):
        os.makedirs(mount_target)

    if partitions.mount_partition(mount_device, mount_target):
        return success("Mounting successful")
    else:
        return error("Failed mounting, check logs...")
示例#4
0
def backup_start():
    tar_path = request.form.get("tar_path")
    found = False
    for dev in partitions.backup_devices:
        if tar_path.startswith(dev["path"]):
            found = dev
            break

    if not found:
        msg = "Invalid backup location provided"
        log.error(msg)
        return error(msg)

    log.info(
        f"Initiating backup onto: {dev['friendly_name']} @ {dev['path']} with target: {tar_path}"
    )

    job_kwargs = {"tar_path": tar_path, "mode": "backup"}
    job_queue.put(("BackupRestore", job_kwargs))

    return success("backup started")
示例#5
0
def show_log(num_lines=50):
    ret = tail(LOG_FILENAME, num_lines)
    return error(f"could not read log: {LOG_FILENAME}") if ret is None \
        else success(data=ret[:-1])
示例#6
0
def service_operation(name, operation):
    if not services.check(name, operation):
        return error("not allowed")

    dct = services.exec(name, operation)
    return success(data=dct)
示例#7
0
def poweroff():
    log.info("POWER-OFF - by /poweroff request")
    cr = CommandRunner("poweroff")
    if cr.returncode != 0:
        return error("failed executing: 'poweroff'")
    return success(data={})
示例#8
0
def reboot():
    log.info("REBOOTING NOW - by /reboot request")
    cr = CommandRunner("reboot")
    if cr.returncode != 0:
        return error("failed executing: 'reboot'")
    return success(data={})