Пример #1
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))
Пример #2
0
 def get(self, id):
     d = domains.get(id)
     if id and not d:
         abort(404)
     if type(d) == list:
         return jsonify(domains=[x.as_dict() for x in d])
     else:
         return jsonify(domain=d.as_dict())
Пример #3
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))
Пример #4
0
 def get(self, id):
     d = domains.get(id)
     if id and not d:
         abort(404)
     if isinstance(d, domains.Domain):
         return jsonify(domain=d.serialized)
     else:
         return jsonify(domains=[x.serialized for x in d])
Пример #5
0
 def delete(self, id):
     d = domains.get(id)
     if not d:
         abort(404)
     try:
         d.remove()
     except errors.InvalidConfigError as e:
         return jsonify(errors={"msg": str(e)}), 422
     return Response(status=204)
Пример #6
0
 def delete(self, id):
     d = domains.get(id)
     if not d:
         abort(404)
     try:
         d.remove()
     except Exception, e:
         resp = jsonify(message="Domain couldn't be deleted: %s" % str(e))
         resp.status_code = 422
         return resp
Пример #7
0
def on_load(app):
    # Make sure all system domains are registered with XMPP on system start
    if not app.id == "xmpp":
        return
    reload = False
    doms = domains.get()
    for x in doms:
        if not os.path.exists("/etc/prosody/conf.d/%s.cfg.lua" % x.name):
            add_domain(x, False)
            reload = True
    for x in os.listdir("/etc/prosody/conf.d"):
        if x.rstrip(".cfg.lua") not in [y.name for y in doms]:
            os.unlink(os.path.join("/etc/prosody/conf.d", x))
            reload = True
    if reload:
        services.get("prosody").restart()
Пример #8
0
def on_load(app):
    # Make sure all system domains are registered with XMPP on system start
    if not app.id == "xmpp":
        return
    reload = False
    doms = domains.get()
    for x in doms:
        if not os.path.exists("/etc/prosody/conf.d/{0}.cfg.lua".format(
                x.name)):
            add_domain(x, False)
            reload = True
    for x in glob.glob("/etc/prosody/conf.d/*.cfg.lua"):
        basename = os.path.basename(x)
        if basename.split(".cfg.lua")[0] not in [y.name for y in doms]:
            os.unlink(x)
            reload = True
    if reload:
        services.get("prosody").restart()
Пример #9
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}
Пример #10
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/{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)
    }
Пример #11
0
def remove_ssl(name):
    # Removes SSL from an XMPP domain
    dom = domains.get(name)
    add_domain(dom)
Пример #12
0
def remove_ssl(name):
    # Removes SSL from an XMPP domain
    dom = domains.get(name)
    add_domain(dom)
Пример #13
0
 def test_del_domain(self):
     d = domains.Domain("testdomain.xyz")
     d.add()
     d = domains.get("testdomain.xyz")
     d.remove()
     self.assertIsNone(domains.get("testdomain.xyz"))
Пример #14
0
 def test_add_domain(self):
     d = domains.Domain("testdomain.xyz")
     d.add()
     self.assertIsNotNone(domains.get("testdomain.xyz"))