Exemple #1
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))
Exemple #2
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))
 def put(self, id):
     data = json.loads(request.data)["database_user"]
     u = databases.get_user(id)
     if not id or not u:
         abort(404)
     elif not data.get("operation"):
         abort(400)
     u.chperm(data["operation"], databases.get(data["database"]))
     push_record("database_users", u.as_dict())
     return Response(status=201)
 def get(self, id):
     if request.args.get("rescan", None):
         databases.scan_users()
     u = databases.get_user(id)
     if id and not u:
         abort(404)
     if type(u) == list:
         return jsonify(database_users=[x.as_dict() for x in u])
     else:
         return jsonify(database_user=u.as_dict())
 def delete(self, id):
     u = databases.get_user(id)
     if not id or not u:
         abort(404)
     try:
         u.remove()
     except Exception, e:
         resp = jsonify(message="Database user couldn't be deleted: %s" % str(e))
         resp.status_code = 422
         return resp
Exemple #6
0
    def remove(self, message=DefaultMessage()):
        # Call site type's pre-removal hook
        message.update("info", "Running pre-removal...", head="Removing website")
        self.pre_remove()

        # Remove source directories
        message.update("info", "Removing website...", head="Removing website")
        if self.path.endswith("_site"):
            shutil.rmtree(self.path.split("/_site")[0])
        elif self.path.endswith("htdocs"):
            shutil.rmtree(self.path.split("/htdocs")[0])
        elif os.path.islink(self.path):
            os.unlink(self.path)
        else:
            shutil.rmtree(self.path)

        # If there's a database, get rid of that too
        if self.db:
            message.update("info", "Removing database...", head="Removing website")
            if self.db.manager.meta.database_multiuser:
                db_user = databases.get_user(self.db.id)
                if db_user:
                    db_user.remove()
            self.db.remove()

        self.nginx_disable(reload=True)
        try:
            os.unlink(os.path.join("/etc/nginx/sites-available", self.id))
        except:
            pass

        # Call site type's post-removal hook
        message.update("info", "Running post-removal...", head="Removing website")
        self.post_remove()
        storage.sites.remove("sites", self)
        signals.emit("websites", "site_removed", self)
Exemple #7
0
        meta.set("website", "dbengine", "")
        if hasattr(self.meta, "selected_dbengine"):
            meta.set("website", "dbengine", self.meta.selected_dbengine or "")
        with open(os.path.join(self.path, ".arkos"), "w") as f:
            meta.write(f)

        # Call site type's post-installation hook
        message.update("info", "Running post-installation. This may take a few minutes...",
            head="Installing website")
        try:
            specialmsg = self.post_install(extra_vars, dbpasswd)
        except Exception, e:
            shutil.rmtree(self.path, True)
            if self.db:
                self.db.remove()
                db_user = databases.get_user(self.id)
                if db_user:
                    db_user.remove()
            os.unlink(os.path.join("/etc/nginx/sites-available", self.id))
            raise Exception("Error during website config - "+str(e))

        # Cleanup and reload daemons
        message.update("info", "Finishing...", head="Installing website")
        self.installed = True
        storage.sites.add("sites", self)
        signals.emit("websites", "site_installed", self)
        if enable:
            self.nginx_enable()
        if enable and self.php:
            php_reload()
        if specialmsg: