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...")
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")
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...")
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")
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])
def service_operation(name, operation): if not services.check(name, operation): return error("not allowed") dct = services.exec(name, operation) return success(data=dct)
def poweroff(): log.info("POWER-OFF - by /poweroff request") cr = CommandRunner("poweroff") if cr.returncode != 0: return error("failed executing: 'poweroff'") return success(data={})
def reboot(): log.info("REBOOTING NOW - by /reboot request") cr = CommandRunner("reboot") if cr.returncode != 0: return error("failed executing: 'reboot'") return success(data={})