def delete(self):
        username = self.get_current_user().encode('utf-8')
        customer_name = (get_user_property(username, UserKeys.CurrentCustomer))
        uri = self.request.uri
        method = self.request.method
        try:
            #app_ids = self.arguments.get('app_ids') The UI needs to past the options as the body not as arguments
            app_ids = self.get_arguments('app_ids')
            appids_deleted = 0
            appids_failed = 0
            for appid in app_ids:
                deleted = (delete_app_from_vfense(
                    appid, CustomAppsCollection, CustomAppsPerAgentCollection))
                if deleted:
                    appids_deleted += 1
                else:
                    appids_failed += 1

            results = (PackageResults(username, uri, method).packages_deleted(
                app_ids, appids_deleted, appids_failed))

            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))

        except Exception as e:
            logger.exception(e)
            results = (GenericResults(username, uri, method).something_broke(
                app_ids, 'failed to delete custom_apps', e))

            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))
Пример #2
0
    def filter_by_status(self, pkg_status, conn=None):
        try:
            if pkg_status in CommonAppKeys.ValidPackageStatuses:
                base = (
                    r
                    .table(self.CurrentAppsPerAgentCollection, use_outdated=True)
                    .get_all(
                        [pkg_status, self.customer_name],
                        index=self.CurrentAppsPerAgentIndexes.StatusAndCustomer)
                    .eq_join(self.CurrentAppsKey.AppId, r.table(self.CurrentAppsCollection))
                    .map(self.joined_map_hash)
                )

                if self.show_hidden == CommonKeys.NO:
                    base = base.filter(
                        {self.CurrentAppsKey.Hidden: CommonKeys.NO}
                    )

                packages = list(
                    base
                    .distinct()
                    .order_by(self.sort(self.sort_key))
                    .skip(self.offset)
                    .limit(self.count)
                    .run(conn)
                )

                pkg_count = (
                    base
                    .pluck(self.CurrentAppsKey.AppId)
                    .distinct()
                    .count()
                    .run(conn)
                )

                return_status = (
                    GenericResults(
                        self.username, self.uri, self.method
                    ).information_retrieved(packages, pkg_count)
                )

            else:
                return_status = (
                    PackageResults(
                        self.username, self.uri, self.method
                    ).invalid_global_status(pkg_status)
                )

        except Exception as e:
            return_status = (
                GenericResults(
                    self.username, self.uri, self.method
                ).something_broke(
                    "Package Searching went haywire",
                    'os_updates', e
                    )
            )
            logger.exception(e)

        return(return_status)
Пример #3
0
    def post(self, app_id):
        username = self.get_current_user().encode('utf-8')
        customer_name = (get_user_property(username, UserKeys.CurrentCustomer))
        uri = self.request.uri
        method = self.request.method
        try:
            severity = self.arguments.get('severity').capitalize()

            if severity in CommonSeverityKeys.ValidRvSeverities:
                sev_data = {AppsKey.RvSeverity: severity}
                update_app_data_by_app_id(app_id, sev_data,
                                          AppCollections.vFenseApps)

                results = GenericResults(username, uri, method).object_updated(
                    app_id, 'app severity', [sev_data])

                self.set_status(results['http_status'])
                self.set_header('Content-Type', 'application/json')
                self.write(json.dumps(results, indent=4))

            else:
                results = (PackageResults(username, uri,
                                          method).invalid_severity(severity))
                self.set_status(results['http_status'])
                self.set_header('Content-Type', 'application/json')
                self.write(json.dumps(results, indent=4))

        except Exception as e:
            results = (GenericResults(username, uri, method).something_broke(
                app_id, 'update_severity', e))
            logger.exception(e)
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))
Пример #4
0
    def filter_by_severity(self, sev, conn=None):
        try:
            if sev in CommonSeverityKeys.ValidRvSeverities:
                base = (
                    r
                    .table(self.CurrentAppsCollection)
                    .get_all(self.customer_name, sev, index=self.CurrentAppsIndexes.CustomerAndRvSeverity)
                )

                if self.show_hidden == CommonKeys.NO:
                    base = base.filter({self.CurrentAppsKey.Hidden: CommonKeys.NO})

                packages = list(
                    base
                    .map(self.map_hash)
                    .order_by(self.sort(self.sort_key))
                    .skip(self.offset)
                    .limit(self.count)
                    .run(conn)
                )

                pkg_count = (
                    base
                    .pluck(self.pluck_list)
                    .count()
                    .run(conn)
                )

                return_status = (
                    GenericResults(
                        self.username, self.uri, self.method
                    ).information_retrieved(packages, pkg_count)
                )

            else:
                return_status = (
                    PackageResults(
                        self.username, self.uri, self.method
                    ).invalid_severity(sev)
                )

        except Exception as e:
            return_status = (
                GenericResults(
                    self.username, self.uri, self.method
                ).something_broke(
                    "Package Searching went haywire",
                    'os_updates', e
                    )
            )
            logger.exception(e)

        return(return_status)
Пример #5
0
    def filter_by_status_and_sev(self, pkg_status, sev, conn=None):

        try:
            pkg = (
                r
                .table(self.CurrentAppsCollection, use_outdated=True)
                .get(self.app_id)
                .run(conn)
            )
            if pkg:
                if pkg_status in CommonAppKeys.ValidPackageStatuses:
                    if sev in CommonSeverityKeys.ValidRvSeverities:
                        agents = list(
                            r
                            .table(self.CurrentAppsPerAgentCollection)
                            .get_all(
                                [self.app_id, pkg_status],
                                index=self.CurrentAppsPerAgentIndexes.AppIdAndStatus
                            )
                            .eq_join(
                                self.CurrentAppsPerAgentKey.AppId,
                                r.table(self.CurrentAppsCollection)
                            )
                            .zip()
                            .eq_join(
                                self.CurrentAppsPerAgentKey.AgentId,
                                r.table(AgentsCollection)
                            )
                            .zip()
                            .filter(r.row[self.CurrentAppsKey.RvSeverity] == sev)
                            .order_by(r.asc(self.CurrentAppsKey.Name))
                            .skip(self.offset)
                            .limit(self.count)
                            .map(self.map_hash)
                            .run(conn)
                        )

                        agent_count = (
                            r
                            .table(self.CurrentAppsPerAgentCollection)
                            .get_all(
                                [self.app_id, pkg_status],
                                index=self.CurrentAppsPerAgentIndexes.AppIdAndStatus
                            )
                            .eq_join(
                                self.CurrentAppsPerAgentKey.AppId,
                                r.table(self.CurrentAppsCollection)
                            )
                            .zip()
                            .filter(r.row[self.CurrentAppsKey.RvSeverity] == sev)
                            .count()
                            .run(conn)
                        )

                        return_status = (
                            GenericResults(
                                self.username, self.uri, self.method
                            ).information_retrieved(agents, agent_count)
                        )

                    else:
                        return_status = (
                            PackageResults(
                                self.username, self.uri, self.method
                            ).invalid_severity(sev)
                        )

                else:
                    return_status = (
                        PackageResults(
                            self.username, self.uri, self.method
                        ).invalid_status(self.app_id, pkg_status)
                    )

            else:
                return_status = (
                    GenericResults(
                        self.username, self.uri, self.method
                    ).invalid_id(self.app_id, 'os_apps')
                )

        except Exception as e:
            return_status = (
                GenericResults(
                    self.username, self.uri, self.method
                ).something_broke(
                    "Package Searching went haywire",
                    'os_updates', e
                    )
            )
            logger.exception(e)

        return(return_status)
Пример #6
0
    def query_by_name(self, name, conn=None):
        try:
            pkg = (
                r
                .table(self.CurrentAppsCollection, use_outdated=True)
                .get(self.app_id)
                .run(conn)
            )
            if pkg:
                agents = list(
                    r
                    .table(self.CurrentAppsPerAgentCollection)
                    .get_all(self.app_id, index=self.CurrentAppsPerAgentIndexes.AppId)
                    .eq_join(
                        self.CurrentAppsPerAgentKey.AgentId,
                        r.table(AgentsCollection)
                    )
                    .zip()
                    .filter(
                        r.row[AgentKey.ComputerName].match("(?i)"+name)
                        |
                        r.row[AgentKey.DisplayName].match("(?i)"+name)
                    )
                    .order_by(r.asc('computer_name'))
                    .skip(self.offset)
                    .limit(self.count)
                    .map(self.map_hash)
                    .run(conn)
                )

                agent_count = (
                    r
                    .table(self.CurrentAppsPerAgentCollection, use_outdated=True)
                    .get_all(self.app_id, index=self.CurrentAppsPerAgentIndexes.AppId)
                    .eq_join(
                        self.CurrentAppsPerAgentKey.AgentId,
                        r.table(AgentsCollection)
                    )
                    .zip()
                    .filter(
                        r.row[AgentKey.ComputerName].match("(?i)"+name)
                        |
                        r.row[AgentKey.DisplayName].match("(?i)"+name)
                    )
                    .count()
                    .run(conn)
                )

                return_status = (
                    GenericResults(
                        self.username, self.uri, self.method
                    ).information_retrieved(agents, agent_count)
                )

            else:
                return_status = (
                    PackageResults(
                        self.username, self.uri, self.method
                    ).invalid_package_id(self.app_id)
                )

        except Exception as e:
            return_status = (
                GenericResults(
                    self.username, self.uri, self.method
                ).something_broke(
                    "Package Searching went haywire",
                    'os_updates', e
                    )
            )
            logger.exception(e)

        return(return_status)
Пример #7
0
    def filter_by_status_and_sev(self, pkg_status, sev, conn=None):

        try:
            agent = get_agent_info(self.agent_id)
            if agent:
                if pkg_status in CommonAppKeys.ValidPackageStatuses:
                    if sev in CommonSeverityKeys.ValidRvSeverities:
                        base = (
                            r
                            .table(self.CurrentAppsPerAgentCollection)
                            .get_all(
                                [pkg_status, self.agent_id],
                                index=self.CurrentAppsPerAgentIndexes.StatusAndAgentId
                            )
                            .eq_join(
                                self.CurrentAppsPerAgentKey.AppId,
                                r.table(self.CurrentAppsCollection)
                            )
                            .zip()
                        )
                        if self.show_hidden == CommonKeys.NO:
                            base = base.filter({self.CurrentAppsKey.Hidden: CommonKeys.NO})

                        packages = list(
                            base
                            .filter(r.row[self.CurrentAppsKey.RvSeverity] == sev)
                            .map(self.map_hash)
                            .order_by(self.sort(self.sort_key))
                            .skip(self.offset)
                            .limit(self.count)
                            .run(conn)
                        )

                        pkg_count = (
                            base
                            .filter(r.row[self.CurrentAppsKey.RvSeverity] == sev)
                            .count()
                            .run(conn)
                        )

                        return_status = (
                            GenericResults(
                                self.username, self.uri, self.method
                            ).information_retrieved(packages, pkg_count)
                        )

                    else:
                        return_status = (
                            PackageResults(
                                self.username, self.uri, self.method
                            ).invalid_severity(sev)
                        )

                else:
                    return_status = (
                        PackageResults(
                            self.username, self.uri, self.method
                        ).invalid_status(self.agent_id, pkg_status)
                    )

            else:
                return_status = (
                    GenericResults(
                        self.username, self.uri, self.method
                    ).invalid_id(self.agent_id, 'agents')
                )

        except Exception as e:
            return_status = (
                GenericResults(
                    self.username, self.uri, self.method
                ).something_broke(
                    "Package Searching went haywire",
                    'os_updates', e
                    )
            )
            logger.exception(e)

        return(return_status)
Пример #8
0
    def filter_by_status(self, pkg_status, conn=None):
        try:
            tag = tag_exists(self.tag_id)
            if tag:
                if pkg_status in CommonAppKeys.ValidPackageStatuses:
                    base = (
                        r
                        .table(TagsPerAgentCollection, use_outdated=True)
                        .get_all(self.tag_id, index=TagsPerAgentIndexes.TagId)
                        .pluck(TagsPerAgentKey.AgentId)
                        .eq_join(
                            lambda x: [
                                pkg_status,
                                x[self.CurrentAppsPerAgentKey.AgentId]
                            ],
                            r.table(self.CurrentAppsPerAgentCollection),
                            index=self.CurrentAppsPerAgentIndexes.StatusAndAgentId
                        )
                        .eq_join(
                            lambda y:
                            y['right'][self.CurrentAppsKey.AppId],
                            r.table(self.CurrentAppsCollection)
                        )
                        .map(self.map_hash)
                    )
                    if self.show_hidden == CommonKeys.NO:
                        base = base.filter({self.CurrentAppsKey.Hidden: CommonKeys.NO})

                    packages = list(
                        base
                        .distinct()
                        .order_by(self.sort(self.sort_key))
                        .skip(self.offset)
                        .limit(self.count)
                        .run(conn)
                    )
                    pkg_count = (
                        base
                        .pluck(self.CurrentAppsKey.AppId)
                        .distinct()
                        .count()
                        .run(conn)
                    )

                    return_status = (
                        GenericResults(
                            self.username, self.uri, self.method
                        ).information_retrieved(packages, pkg_count)
                    )

                else:
                    return_status = (
                        PackageResults(
                            self.username, self.uri, self.method
                        ).invalid_status(self.tag_id, pkg_status)
                    )

            else:
                return_status = (
                    GenericResults(
                        self.username, self.uri, self.method
                    ).invalid_id(self.tag_id, 'tags')
                )

        except Exception as e:
            return_status = (
                GenericResults(
                    self.username, self.uri, self.method
                ).something_broke(
                    "Package Searching went haywire",
                    'os_updates', e
                    )
            )
            logger.exception(e)

        return(return_status)