コード例 #1
0
def restore(id):
    """Restore a backup by ID."""
    if "/" not in id:
        raise CLIException("Requires full backup ID with app ID and timestamp")
    id, tsp = id.split("/")
    try:
        b = [x for x in backup.get() if x["id"] == (id + "/" + tsp)][0]
        backup.restore(b)
    except Exception as e:
        raise CLIException(str(e))
コード例 #2
0
def log(name):
    """Get logs since last boot for a particular service"""
    try:
        service = services.get(name)
        if not service:
            raise CLIException("No service found")
        if service.stype == "system":
            data = shell("journalctl -x -b 0 -u {0}".format(service.sfname))
            click.echo_via_pager(data["stdout"].decode())
        else:
            click.echo_via_pager(service.get_log())
    except Exception as e:
        raise CLIException(str(e))
コード例 #3
0
def list_sites():
    """List all websites"""
    try:
        adata = [x.serialized for x in websites.get()]
        _list_websites(adata)
    except Exception as e:
        raise CLIException(str(e))
コード例 #4
0
def info(id):
    """Get information about a certain application."""
    try:
        x = applications.get(id).as_dict
        lines = {
            "Type:": x["type"].capitalize(),
            "By:": x["app_author"],
            "Description:": x["description"]["short"],
            "Website:": x["app_homepage"],
            "Installed:": "Yes" if x["installed"] else "No"
        }
        click.echo(click.style(x["name"], fg="white", bold=True))
        click.echo(click.style(" * Version: ", fg="yellow") + x["version"])
        if x["upgradable"]:
            click.echo(
                click.style(" * Upgradable to: ", fg="green") +
                x["upgradable"])
        for key in sorted(lines.keys()):
            imsg = click.style(lines[key], fg="white")
            click.echo(click.style(" * " + key, fg="yellow") + " " + imsg)
        if [y for y in x["dependencies"] if y["type"] == "app"]:
            deps = [y["name"] for y in x["dependencies"] if y["type"] == "app"]
            click.echo(
                click.style(" * Depends on:", fg="yellow") + " " +
                click.style(", ".join(deps), fg="white"))
    except Exception as e:
        raise CLIException(str(e))
コード例 #5
0
def update():
    """Updates system package index"""
    try:
        pacman.refresh()
        logger.success('ctl:pkg:update', 'Index updated')
    except Exception as e:
        raise CLIException(str(e))
コード例 #6
0
def nslcd():
    """Initialize distribution PAM integration of OpenLDAP."""
    patchfiles = [
        ("/etc/pam.d/system-auth", "001-add-ldap-to-system-auth.patch"),
        ("/etc/pam.d/su", "002-add-ldap-to-su.patch"),
        ("/etc/pam.d/su-l", "003-add-ldap-to-su-l.patch"),
        ("/etc/pam.d/passwd", "004-add-ldap-to-passwd.patch"),
        ("/etc/pam.d/system-login", "005-add-ldap-to-system-login.patch"),
        ("/etc/nsswitch.conf", "006-add-ldap-to-nsswitch.patch"),
        ("/etc/nslcd.conf", "007-add-ldap-to-nslcd.patch")
    ]
    for x in patchfiles:
        if not os.path.exists(os.path.join("/usr/share/arkos/nslcd", x[1])):
            raise CLIException(
                "Patch files could not be found. Your installation may "
                "be corrupted. Please reinstall the `arkos-configs` package.")

    logger.debug('ctl:init:nslcd', 'Stopping daemon: nslcd')
    s = shell("systemctl stop nslcd")
    if s["code"] != 0:
        raise click.ClickException(s["stderr"].decode())

    logger.info('ctl:init:nslcd', 'Patching system files')
    for x in patchfiles:
        shell("patch -N {0} {1}".format(
            x[0], os.path.join("/usr/share/arkos/nslcd", x[1])))

    logger.debug('ctl:init:nslcd', 'Starting daemon: nslcd')
    shell("systemctl enable nslcd")
    shell("systemctl start nslcd")
    logger.success('ctl:init:nslcd', 'Complete')
コード例 #7
0
ファイル: filesystems.py プロジェクト: ns408/core
def list_filesystems():
    """List filesystems"""
    try:
        data = filesystems.get()
        for x in data:
            click.echo(
                click.style(x.id, fg="white", bold=True) +
                click.style(" (" + x.path + ")", fg="green")
            )
            click.echo(
                click.style(" * Type: ", fg="yellow") +
                "{0} {1}".format(
                    "Physical" if isinstance(filesystems.DiskPartition)
                    else "Virtual",
                    x.fstype
                )
            )
            click.echo(
                click.style(" * Size: ", fg="yellow") +
                str_fsize(x.size)
            )
            click.echo(
                click.style(" * Encrypted: ", fg="white") +
                ("Yes" if x.crypt else "No")
            )
            click.echo(
                click.style(" * Mounted: ", fg="yellow") +
                ("At " + x.mountpoint if x.mountpoint else "No")
            )
    except Exception as e:
        raise CLIException(str(e))
コード例 #8
0
def assigns():
    """List all apps/sites that can use certificates."""
    click.echo("Apps/Sites that can use certificates:")
    try:
        assigns = []
        assigns.append({
            "type": "genesis",
            "id": "genesis",
            "name": "arkOS Genesis/API"
        })
        for x in websites.get():
            assigns.append({
                "type": "website",
                "id": x.id,
                "name": x.id if x.app else x.name
            })
        for x in applications.get(installed=True):
            if x.type == "app" and x.uses_ssl:
                for y in x.get_ssl_able():
                    assigns.append(y)
        for x in assigns:
            imsg = click.style("(" + x["type"].capitalize() + ")", fg="green")
            click.echo(
                click.style(x["name"], fg="white", bold=True) + " " + imsg)
    except Exception as e:
        raise CLIException(str(e))
コード例 #9
0
def list_backups():
    """List all backups."""
    try:
        data = backup.get()
        _list_backups(data)
    except Exception as e:
        raise CLIException(str(e))
コード例 #10
0
def upload(name, certfile, keyfile, chainfile):
    """Upload an SSL/TLS certificate."""
    try:
        certificates.upload_certificate(
            name, certfile.read(), keyfile.read(),
            chainfile.read() if chainfile else None)
    except Exception as e:
        raise CLIException(str(e))
コード例 #11
0
def delete_domain(name):
    """Delete an arkOS LDAP domain"""
    try:
        d = domains.get(name)
        d.remove()
        logger.success('ctl:dom:delete', 'Deleted {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))
コード例 #12
0
def add_domain(name):
    """Add a domain to arkOS LDAP"""
    try:
        d = domains.Domain(name=name)
        d.add()
        logger.success('ctl:dom:add', 'Added {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))
コード例 #13
0
def list_domains():
    """List domains"""
    try:
        data = domains.get()
        for x in data:
            click.echo(x.id)
    except Exception as e:
        raise CLIException(str(e))
コード例 #14
0
def delete_group(name):
    """Delete an arkOS LDAP group"""
    try:
        g = groups.get(name=name)
        g.delete()
        logger.success('ctl:grp:delete', 'Deleted {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))
コード例 #15
0
def add_group(name, users):
    """Add a group to arkOS LDAP"""
    try:
        g = groups.Group(name=name, users=users)
        g.add()
        logger.success('ctl:grp:add', 'Added {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))
コード例 #16
0
def chmod(user_name, db_name, grant):
    """Get or set database user permissions."""
    try:
        u = databases.get_user(user_name)
        u.chperm("grant" if grant else "revoke", databases.get(db_name))
        logger.success('ctl:dbusr:chmod', 'Permissions set')
    except Exception as e:
        raise CLIException(str(e))
コード例 #17
0
ファイル: files.py プロジェクト: ns408/core
def update_share(id, expires):
    """Update a fileshare link's expiration."""
    try:
        share = shared_files.get(id)
        share.update_expiry(expires)
        logger.success('ctl:links:update', 'Updated share {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
コード例 #18
0
def delete(id):
    """Delete a network connection"""
    try:
        n = network.get(id)
        n.remove()
        logger.success('ctl:net:delete', 'Deleted {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
コード例 #19
0
def connect(id):
    """Connect to a network"""
    try:
        n = network.get(id)
        n.connect()
        logger.success('ctl:net:connect', 'Connected {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
コード例 #20
0
def create_db(name, type_id):
    """Add a database."""
    try:
        manager = databases.get_managers("db-" + type_id)
        manager.add_db(name)
        logger.success('ctl:db:create', 'Added {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))
コード例 #21
0
def drop_user(name):
    """Delete a database user."""
    try:
        u = databases.get_user(name)
        u.remove()
        logger.success('ctl:dbusr:drop', 'Dropped {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))
コード例 #22
0
def drop(name):
    """Delete a database."""
    try:
        db = databases.get(name)
        db.remove()
        logger.success('ctl:db:drop', 'Dropped {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))
コード例 #23
0
def delete(id):
    """Delete a certificate."""
    try:
        cert = certificates.get(id)
        cert.remove()
        logger.success('ctl:cert:delete', 'Deleted {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
コード例 #24
0
def cli(configfile, secretsfile, policiesfile, v):
    if os.geteuid() != 0:
        raise CLIException(
            "You must run this script as root, or prefixed with `sudo`.")
    config.load(configfile, default=configs.DEFAULT_CONFIG)
    secrets.load(secretsfile, default={})
    policies.load(policiesfile, default={})
    logger.add_stream_logger(st="[{levelname}] {comp}: {message}", debug=v)
コード例 #25
0
def enable(id):
    """Enable connection to a network on boot"""
    try:
        n = network.get(id)
        n.enable()
        logger.success('ctl:net:enable', 'Enabled {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
コード例 #26
0
def add_user(name, type_id):
    """Add a database user."""
    try:
        manager = databases.get_managers("db-" + type_id)
        manager.add_user(name)
        logger.success('ctl:dbusr:add', 'Added user {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))
コード例 #27
0
ファイル: files.py プロジェクト: ns408/core
def remove_share(id):
    """Disable a fileshare link."""
    try:
        share = shared_files.get(id)
        share.delete()
        logger.success('ctl:links:delete', 'Deleted share {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
コード例 #28
0
def delete_user(name):
    """Delete an arkOS LDAP user"""
    try:
        u = users.get(name=name)
        u.delete()
        logger.success('ctl:usr:delete', 'Deleted {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))
コード例 #29
0
def disconnect(id):
    """Disconnect from a network"""
    try:
        n = network.get(id)
        n.disconnect()
        logger.success('ctl:net:disconnect', 'Disconnected {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
コード例 #30
0
def disable(name):
    """Disable a service on boot"""
    try:
        service = services.get(name)
        service.disable()
        logger.success('ctl:svc:disable', 'Disabled {0}'.format(name))
    except Exception as e:
        raise CLIException(str(e))