def remove_share(id): """Disable a fileshare link.""" try: client().files.remove_share(id) logger.success('ctl:links:delete', 'Deleted share {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def add(name, type_id): """Add a database.""" try: client().databases.add(name, "db-" + type_id) logger.success('ctl:db:create', 'Added {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def delete(id): """Delete a network connection""" try: client().networks.delete(id) logger.success('ctl:net:delete', 'Deleted {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def add_user(name, type_id): """Add a database user.""" try: client().databases.add_user(name, type_id) logger.success('ctl:dbusr:add', 'Added user {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def add_domain(name): """Add a domain to arkOS LDAP""" try: client().roles.add_domain(name) logger.success('ctl:dom:add', 'Added {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def delete_domain(name): """Delete an arkOS LDAP domain""" try: client().roles.delete_domain(name) logger.success('ctl:dom:delete', 'Deleted {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def update_share(id, expires): """Update a fileshare link's expiration.""" try: client().files.update_share(id, expires) logger.success('ctl:links:update', 'Updated share {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def disable(id): """Disable mounting a filesystem on boot""" try: client().filesystems.disable(id) logger.success('ctl:fs:disable', 'Disabled {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def local(id): """Allow local network access only to service""" try: client().security.update_policy(id, "local") logger.success('ctl:sec:local', 'Access to {0} restricted'.format(id)) except Exception as e: raise CLIException(str(e))
def block(id): """Block all network access to service""" try: client().security.update_policy(id, "block") logger.success('ctl:sec:block', 'Access to {0} blocked'.format(id)) except Exception as e: raise CLIException(str(e))
def allow(id): """Allow all access to service""" try: client().security.update_policy(id, "allow") logger.success('ctl:sec:allow', 'Access to {0} allowed'.format(id)) except Exception as e: raise CLIException(str(e))
def update(): """Updates system package index""" try: client().packages.get(refresh=True) logger.success('ctl:pkg:update', 'Index updated') except Exception as e: raise CLIException(str(e))
def edit(id, address, port, new_name): """Edit a website""" try: client().websites.edit(id, new_name, address, port) logger.success('ctl:site:edit', 'Edited {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def update(id): """Update a website""" try: client().websites.update(id) logger.success('ctl:site:update', 'Updated {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def delete(id): """Delete a certificate.""" try: client().certificates.delete(id=id) logger.success('ctl:cert:delete', 'Deleted {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def drop_user(name): """Delete a database user.""" try: client().databases.delete_user(name) logger.success('ctl:dbusr:drop', 'Dropped {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def connect(id): """Connect to a network""" try: client().networks.connect(id) logger.success('ctl:net:connect', 'Connected {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def enable(id): """Mount a filesystem on boot""" try: client().filesystems.enable(id) logger.success('ctl:fs:enable', 'Enabled {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def delete(id): """Delete a virtual disk""" try: client().filesystems.delete(id) logger.success('ctl:fs:delete', 'Deleted {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def add_group(name, users): """Add a group to arkOS LDAP""" try: client().roles.add_group(name, users) logger.success('ctl:grp:add', 'Added {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def enable(id): """Enable connection to a network on boot""" try: client().networks.enable(id) logger.success('ctl:net:enable', 'Enabled {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def disconnect(id): """Disconnect from a network""" try: client().networks.disconnect(id) logger.success('ctl:net:disconnect', 'Disconnected {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def umount(id): """Unmount a filesystem""" try: client().filesystems.umount(id) logger.success('ctl:fs:umount', 'Unmounted {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def disable(id): """Disable a website""" try: client().websites.disable(id) logger.success('ctl:site:disable', 'Disabled {0}'.format(id)) except Exception as e: raise CLIException(str(e))
def disable(name): """Disable a service on boot""" try: client().services.disable(name) logger.success('ctl:svc:disable', 'Disabled {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def stop(name): """Stop a service""" try: client().services.stop(name) logger.success('ctl:svc:stop', 'Stopped {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def dump(name, path): """Export database to SQL file.""" try: data = client().databases.dump(name) path.write(data) logger.success('ctl:db:dump', 'Database dumped to {0}'.format(path)) except Exception as e: raise CLIException(str(e))
def add_user(name, password, domain, first_name, last_name, admin, sudo): """Add a user to arkOS LDAP""" try: client().roles.add_user( name, password, domain, first_name, last_name, admin, sudo) logger.success('ctl:usr:add', 'Added {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def chmod(user_name, db_name, grant): """Get or set database user permissions.""" try: cmd = client().databases.user_chmod cmd(user_name, "grant" if grant else "revoke") logger.success('ctl:dbusr:chmod', 'Permissions set') except Exception as e: raise CLIException(str(e))
def add_user(name, password, domain, first_name, last_name, admin, sudo): """Add a user to arkOS LDAP""" try: client().roles.add_user(name, password, domain, first_name, last_name, admin, sudo) logger.success('ctl:usr:add', 'Added {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def add_share(path, expires): """Create a fileshare link.""" try: data = client().files.share(path, expires) logger.success('ctl:links:create', 'Created link') smsg = "Link is your external server address, plus: /shared/{0}" logger.info('ctl:links:create', smsg.format(data["id"])) except Exception as e: raise CLIException(str(e))
def delete_user(name): """Delete an arkOS LDAP user""" try: users = client().roles.get_users() uid = [y["id"] for y in users if y["name"] == name] if not uid: raise CLIException("No such user") uid = uid[0] client().roles.delete_user(uid) logger.success('ctl:usr:delete', 'Deleted {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def delete_group(name): """Delete an arkOS LDAP group""" try: groups = client().roles.get_groups() gid = [y["id"] for y in groups if y["name"] == name] if not gid: raise CLIException("No such group") gid = gid[0] client().roles.delete_group(gid) logger.success('ctl:grp:delete', 'Deleted {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def start(name): """Start a service""" try: client().services.start(name) svc = client().services.get(id=name) state = svc["state"] if state == "running": logger.success('ctl:svc:start', 'Started {0}'.format(name)) else: logger.error('ctl:svc:start', 'Failed to start {0}'.format(name)) except Exception as e: raise CLIException(str(e))
def mount(id, password): """Mount a filesystem""" try: fs = client().filesystems.get(id=id) if fs["crypt"] and not password: password = click.prompt( "Please enter your password to mount this filesystem", hide_input=True) client().filesystems.mount(id, password or "") logger.success('ctl:fs:mount', 'Mounted {0}'.format(id)) except Exception as e: raise CLIException(str(e))