예제 #1
0
파일: backup.py 프로젝트: ns408/core
    if not backup_location:
        backup_location = config.get("backups", "location")
    backups = get()
    for x in backups:
        if x["id"] == id+"/"+time:
            os.unlink(x["path"])
            try:
                os.unlink(x["path"].split(".")[0]+".meta")
            except:
                pass


def site_load(site):
    """
    Create a BackupController when a Website is first created/loaded.

    :param Website site: Site to create controller for
    """
    if site.__class__.__name__ != "ReverseProxy":
        logger.debug(
            "Back", "Registering backupcontroller for {0}".format(site.id))
        controller = site.app.get_module("backup") or BackupController
        site.backup = controller(site.id, site.app.icon, site,
                                 site.app.version)
    else:
        site.backup = None


signals.add("backup", "websites", "site_loaded", site_load)
signals.add("backup", "websites", "site_installed", site_load)
예제 #2
0
    return device

def edit_node(name, newname, addr):
    config = pull_config()
    device = next((dev for dev in config["devices"] if dev["name"] == name), None)
    config["devices"].remove(device)
    device["name"] = newname
    device["addressing"] = addr
    config["devices"].append(device)
    save_config(config)
    device["id"] = device["name"]
    return device

def del_node(name):
    config = pull_config()
    device = next((dev for dev in config["devices"] if dev["name"] == name), None)
    config["devices"].remove(device)
    save_config(config)

def get_nodes(id=None):
    config = pull_config()
    for x in config["devices"]:
        x["id"] = x["name"]
        x["is_main_device"] = x["deviceID"] == my_id
    if id:
        return next((dev for dev in config["devices"] if dev["id"] == id), None)
    return config["devices"]


signals.add("syncthing", "apps", "post_load", on_load)
예제 #3
0
def get_open_port(ignore_common=False):
    data = get()
    ports = []
    for x in data:
        for y in x.ports:
            ports.append(int(y[1]))
    if not ignore_common: ports = ports + COMMON_PORTS
    r = random.randint(8001, 65534)
    return r if not r in ports else get_open_port()

def initialize():
    policy = policies.get("arkos", "arkos", 2)
    storage.policies.add("policies", SecurityPolicy("arkos", "arkos",
        "System Management (Genesis/APIs)", "fa fa-desktop",
        [("tcp", int(config.get("genesis", "port")))], policy))
    for x in policies.get_all("custom"):
        storage.policies.add("policies", SecurityPolicy("custom", x["id"],
            x["name"], x["icon"], x["ports"], x["policy"]))

def register_website(site):
    register("website", site.id, site.name if hasattr(site, "name") and site.name else site.id,
        site.meta.icon if site.meta else "fa fa-globe", [("tcp", site.port)], site.addr)

def deregister_website(site):
    deregister("website", site.id)

signals.add("tracked_services", "websites", "site_loaded", register_website)
signals.add("tracked_services", "websites", "site_installed", register_website)
signals.add("tracked_services", "websites", "site_removed", deregister_website)
예제 #4
0
            controller = app._backup(backup["pid"], backup["icon"], True)
    else:
        app = applications.get(backup["pid"])
        controller = app._backup()
    if not controller:
        raise Exception("No backup controller found")
    b = controller.restore(backup)
    return b

def remove(id, time, backup_location=""):
    if not backup_location:
        backup_location = config.get("backups", "location", "/var/lib/arkos/backups")
    backups = get()
    for x in backups:
        if x["id"] == id+"/"+time:
            os.unlink(x["path"])
            try:
                os.unlink(x["path"].split(".")[1]+".meta")
            except:
                pass

def site_load(site):
    if site.__class__.__name__ != "ReverseProxy":
        controller = site.meta.get_module("backup") or BackupController
        site.backup = controller(site.id, site.meta.icon, site, site.meta.version)
    else:
        site.backup = None

signals.add("backup", "websites", "site_loaded", site_load)
signals.add("backup", "websites", "site_installed", site_load)
예제 #5
0
def add_ssl(name, cert, key):
    # Add an SSL certificate to an XMPP domain
    domain = domains.get(name)
    with open("/etc/prosody/conf.d/%s.cfg.lua" % name, "w") as f:
        data = [
            'VirtualHost "%s"\n' % name,
            '\tssl = {\n',
            '\t\tkey = "%s";\n' % cert,
            '\t\tcertificate = "%s";\n' % key,
            '\t}\n'
        ]
        data.append(DEFAULT_CONFIG % domain.name)
        f.writelines(data)
    try:
        services.get("prosody").restart()
    except:
        pass
    return {"type": "app", "id": "xmpp_%s" % name, "aid": "xmpp",
        "sid": name, "name": "Chat Server (%s)" % name}

def remove_ssl(name):
    # Removes SSL from an XMPP domain
    dom = domains.get(name)
    add_domain(dom)


signals.add("xmpp", "apps", "post_load", on_load)
signals.add("xmpp", "domains", "post_add", add_domain)
signals.add("xmpp", "domains", "post_remove", remove_domain)
예제 #6
0
    with open("/etc/prosody/conf.d/{0}.cfg.lua".format(name), "w") as f:
        data = [
            'VirtualHost "{0}"\n'.format(name), '\tssl = {{\n',
            '\t\tkey = "{0}";\n'.format(cert),
            '\t\tcertificate = "{0}";\n'.format(key), '\t}}\n'
        ]
        data.append(DEFAULT_CONFIG.format(domain.name))
        f.writelines(data)
    try:
        services.get("prosody").restart()
    except:
        pass
    return {
        "type": "app",
        "id": "xmpp_{0}".format(name),
        "aid": "xmpp",
        "sid": name,
        "name": "Chat Server ({0})".format(name)
    }


def remove_ssl(name):
    # Removes SSL from an XMPP domain
    dom = domains.get(name)
    add_domain(dom)


signals.add("xmpp", "apps", "post_load", on_load)
signals.add("xmpp", "domains", "post_add", add_domain)
signals.add("xmpp", "domains", "post_remove", remove_domain)
예제 #7
0

def open_upnp_site(site):
    """Convenience function to register a website with uPnP."""
    if config.get("general", "enable_upnp"):
        open_upnp(("tcp", site.port))
    domain = site.domain
    if domain == "localhost" or domain.endswith(".local"):
        domain = None
    try:
        test_port(config.get("general", "repo_server"), site.port, domain)
    except:
        msg = ("Port {0} and/or domain {1} could not be tested."
               " Make sure your ports are properly forwarded and"
               " that your domain is properly set up.")\
               .format(site.port, site.domain)
        Notification("error", "TrSv", msg).send()


def close_upnp_site(site):
    """Convenience function to deregister a website with uPnP."""
    if config.get("general", "enable_upnp"):
        close_upnp(("tcp", site.port))


signals.add("tracked_services", "websites", "site_loaded", register_website)
signals.add("tracked_services", "websites", "site_installed", register_website)
signals.add("tracked_services", "websites", "site_installed", open_upnp_site)
signals.add("tracked_services", "websites", "site_removed", deregister_website)
signals.add("tracked_services", "websites", "site_removed", close_upnp_site)
예제 #8
0
    device["name"] = newname
    device["addressing"] = addr
    config["devices"].append(device)
    save_config(config)
    device["id"] = device["name"]
    device["is_ready"] = True
    return device


def del_node(name):
    config = pull_config()
    device = next((dev for dev in config["devices"] if dev["name"] == name),
                  None)
    config["devices"].remove(device)
    save_config(config)


def get_nodes(id=None):
    config = pull_config()
    for x in config["devices"]:
        x["id"] = x["deviceID"]
        x["is_main_device"] = x["deviceID"] == get_myid()
        x["is_ready"] = True
    if id:
        return next(
            (dev for dev in config["devices"] if dev["deviceID"] == id), None)
    return config["devices"]


signals.add("syncthing", "apps", "post_load", on_load)