コード例 #1
0
ファイル: uiMethods.py プロジェクト: AsherBond/cato
    def wmCreateAsset(self):
        args = uiCommon.getAjaxArgs()

        a, sErr = asset.Asset.DBCreateNew(args)
        if sErr:
            return json.dumps({"error": sErr})
        if a is None:
            return json.dumps({"error": "Unable to create Asset."})

        uiCommon.WriteObjectAddLog(catocommon.CatoObjectTypes.Asset, a.ID, a.Name, "Asset Created")

        return a.AsJSON()
コード例 #2
0
ファイル: uiMethods.py プロジェクト: AsherBond/cato
    def wmUpdateCredential(self):
        args = uiCommon.getAjaxArgs()

        c = asset.Credential()
        c.FromID(args["ID"])
        # assuming the attribute names will match ... spin the post data and update the object
        # only where asset attributes are pre-defined.
        for k, v in args.items():
            if hasattr(c, k):
                setattr(c, k, v)

        c.DBUpdate()

        return json.dumps({"result": "success"})
コード例 #3
0
ファイル: uiMethods.py プロジェクト: AsherBond/cato
    def wmCreateCredential(self):
        args = uiCommon.getAjaxArgs()

        # a little different than the others ... credential objects must be instantiated before calling DBCreateNew
        c = asset.Credential()
        c.FromArgs(args["Name"], args["Description"], args["Username"], args["Password"],
                 args["SharedOrLocal"], args["Domain"], args["PrivilegedPassword"], args["PrivateKey"])
        result = c.DBCreateNew()
        if not result:
            json.dumps({"error": "Unable to create Credential."})

        uiCommon.WriteObjectAddLog(catocommon.CatoObjectTypes.Credential, c.ID, c.Name, "Credential Created")

        return c.AsJSON()
コード例 #4
0
ファイル: uiMethods.py プロジェクト: AsherBond/cato
    def wmUpdateUser(self):
        """
            Updates a user.  Will only update the values passed to it.
        """
        user_role = uiCommon.GetSessionUserRole()
        if user_role != "Administrator":
            raise Exception("Only Administrators can edit user accounts.")

        args = uiCommon.getAjaxArgs()

        u = catouser.User()
        u.FromID(args["ID"])

        if u.ID:
            # these changes are done BEFORE we manipulate the user properties for update.

            new_pw = uiCommon.unpackJSON(args.get("Password"))
            random_pw = args.get("NewRandomPassword")

            # if a password was provided, or the random flag was set...exclusively
            if new_pw:
                # if the user requesting the change *IS* the user being changed...
                # set force_change to False
                force = True
                if u.ID == uiCommon.GetSessionUserID():
                    force = False

                u.ChangePassword(new_password=new_pw, force_change=force)
                uiCommon.WriteObjectChangeLog(catocommon.CatoObjectTypes.User, u.ID, u.FullName, "Password changed.")
            elif random_pw:
                u.ChangePassword(generate=random_pw)
                uiCommon.WriteObjectChangeLog(catocommon.CatoObjectTypes.User, u.ID, u.FullName, "Password reset.")

            # now we can change the properties
            u.LoginID = args.get("LoginID")
            u.FullName = args.get("FullName")
            u.Status = args.get("Status")
            u.AuthenticationType = args.get("AuthenticationType")
            u.ForceChange = args.get("ForceChange")
            u.Email = args.get("Email")
            u.Role = args.get("Role")
            u.FailedLoginAttempts = args.get("FailedLoginAttempts")
            u.Expires = args.get("Expires")

            u._Groups = args.get("Groups")

        if u.DBUpdate():
            uiCommon.WriteObjectChangeLog(catocommon.CatoObjectTypes.User, u.ID, u.ID, "User updated.")

        return json.dumps({"result": "success"})
コード例 #5
0
ファイル: uiMethods.py プロジェクト: AsherBond/cato
    def wmCreateUser(self):
        args = uiCommon.getAjaxArgs()

        u = catouser.User.DBCreateNew(username=args["LoginID"],
                                        fullname=args["FullName"],
                                        role=args["Role"],
                                        password=args.get("Password"),
                                        generatepw=args["GeneratePW"],
                                        authtype=args["AuthenticationType"],
                                        forcechange=args.get("ForceChange"),
                                        email=args.get("Email"),
                                        status=args["Status"],
                                        expires=args["Expires"],
                                        groups=args["Groups"])

        uiCommon.WriteObjectAddLog(catocommon.CatoObjectTypes.User, u.ID, u.FullName, "User Created")
        return u.AsJSON()
コード例 #6
0
ファイル: uiMethods.py プロジェクト: AsherBond/cato
    def wmUpdateAsset(self):
        args = uiCommon.getAjaxArgs()

        a = asset.Asset()
        a.FromID(args["ID"])

        if a:
            # assuming the attribute names will match ... spin the post data and update the object
            # only where asset attributes are pre-defined.
            for k, v in args.items():
                if hasattr(a, k):
                    setattr(a, k, v)

            result, msg = a.DBUpdate(tags=args["Tags"], credential_update_mode=args["CredentialMode"], credential=args["Credential"])
            if not result:
                return json.dumps({"error": msg})

        return json.dumps({"result": "success"})