コード例 #1
0
ファイル: db_calls.py プロジェクト: akaasjager/vFense
def add_supported_app_to_agents(username, customer_name, uri, method, agent_id=None):

    if agent_id:
        agent_info = get_agent_info(agent_id)
        apps_info = (
            fetch_apps_data_by_os_code(
                agent_info[AgentKey.OsCode],
                customer_name,
                collection=AppCollections.SupportedApps,
            )
        )
        if len(apps_info) > 0:
            for app_info in apps_info:
                app_id = app_info.get(SupportedAppsKey.AppId)
                file_data = fetch_file_data(app_id)
                add_file_data(
                    app_id, file_data, agent_id
                )
                agent_info_to_insert = (
                    {
                        SupportedAppsPerAgentKey.AgentId: agent_id,
                        SupportedAppsPerAgentKey.AppId: app_id,
                        SupportedAppsPerAgentKey.Status: AVAILABLE,
                        SupportedAppsPerAgentKey.CustomerName: customer_name,
                        SupportedAppsPerAgentKey.InstallDate: r.epoch_time(0.0)
                    }
                )
                insert_app_data(
                    agent_info_to_insert,
                    collection=AppCollections.SupportedAppsPerAgent
                )
コード例 #2
0
ファイル: db_calls.py プロジェクト: vFense/vFense
def add_supported_app_to_agents(username,
                                customer_name,
                                uri,
                                method,
                                agent_id=None):

    if agent_id:
        agent_info = get_agent_info(agent_id)
        apps_info = (fetch_apps_data_by_os_code(
            agent_info[AgentKey.OsCode],
            customer_name,
            collection=AppCollections.SupportedApps,
        ))
        if len(apps_info) > 0:
            for app_info in apps_info:
                app_id = app_info.get(SupportedAppsKey.AppId)
                file_data = fetch_file_data(app_id)
                add_file_data(app_id, file_data, agent_id)
                agent_info_to_insert = ({
                    SupportedAppsPerAgentKey.AgentId:
                    agent_id,
                    SupportedAppsPerAgentKey.AppId:
                    app_id,
                    SupportedAppsPerAgentKey.Status:
                    AVAILABLE,
                    SupportedAppsPerAgentKey.CustomerName:
                    customer_name,
                    SupportedAppsPerAgentKey.InstallDate:
                    r.epoch_time(0.0)
                })
                insert_app_data(
                    agent_info_to_insert,
                    collection=AppCollections.SupportedAppsPerAgent)
コード例 #3
0
ファイル: syncer.py プロジェクト: ttysteale/vFense
def update_supported_apps(json_data):

    try:
        rv_q = Queue("downloader", connection=RQ_PKG_POOL)
        conn = db_connect()

        inserted_count = 0
        all_customers = list(r.table(Collection.Customers).map(lambda x: x[CustomerKey.CustomerName]).run(conn))

        for i in range(len(json_data)):
            json_data[i][SupportedAppsKey.Customers] = all_customers
            json_data[i][SupportedAppsKey.ReleaseDate] = r.epoch_time(json_data[i][SupportedAppsKey.ReleaseDate])
            json_data[i][SupportedAppsKey.FilesDownloadStatus] = PackageCodes.FilePendingDownload
            json_data[i][SupportedAppsKey.Hidden] = "no"
            json_data[i][SupportedAppsKey.VulnerabilityId] = ""

            insert_app_data(json_data[i], DownloadCollections.LatestDownloadedSupported)
            file_data = json_data[i].get(SupportedAppsKey.FileData)
            add_file_data(json_data[i][SupportedAppsKey.AppId], file_data)
            data_to_update = {SupportedAppsKey.Customers: all_customers}
            exists = r.table(AppCollections.SupportedApps).get(json_data[i][SupportedAppsKey.AppId]).run(conn)

            if exists:
                updated = (
                    r.table(AppCollections.SupportedApps)
                    .get(json_data[i][SupportedAppsKey.AppId])
                    .update(data_to_update)
                    .run(conn)
                )

            else:
                updated = r.table(AppCollections.SupportedApps).insert(json_data[i]).run(conn)

            rv_q.enqueue_call(
                func=download_all_files_in_app,
                args=(
                    json_data[i][SupportedAppsKey.AppId],
                    json_data[i][SupportedAppsKey.OsCode],
                    None,
                    file_data,
                    0,
                    AppCollections.SupportedApps,
                ),
                timeout=86400,
            )

            inserted_count += updated["inserted"]

        conn.close()

        update_apps = IncomingSupportedApps()
        update_apps.sync_supported_updates_to_all_agents(json_data)

    except Exception as e:
        logger.exception(e)
コード例 #4
0
def add_custom_app_to_agents(username,
                             customer_name,
                             uri,
                             method,
                             file_data,
                             agent_id=None,
                             app_id=None):

    if app_id and not agent_id:
        app_info = (fetch_app_data(app_id,
                                   collection=AppCollections.CustomApps))

        agent_ids = get_all_agent_ids(customer_name,
                                      agent_os=app_info[AgentKey.OsCode])
        if len(agent_ids) > 0:
            for agentid in agent_ids:
                add_file_data(app_id, file_data, agent_id)
                agent_info_to_insert = ({
                    CustomAppsPerAgentKey.AgentId:
                    agentid,
                    CustomAppsPerAgentKey.AppId:
                    app_id,
                    CustomAppsPerAgentKey.Status:
                    CommonAppKeys.AVAILABLE,
                    CustomAppsPerAgentKey.CustomerName:
                    customer_name,
                    CustomAppsPerAgentKey.InstallDate:
                    r.epoch_time(0.0)
                })
                insert_app_data(agent_info_to_insert,
                                collection=AppCollections.CustomAppsPerAgent)

    if agent_id and not app_id:
        agent_info = get_agent_info(agent_id)
        apps_info = fetch_apps_data_by_os_code(
            agent_info[AgentKey.OsCode],
            customer_name,
            collection=AppCollections.CustomApps)

        for app_info in apps_info:
            app_id = app_info.get(CustomAppsKey.AppId)
            file_data = fetch_file_data(app_id)
            add_file_data(app_id, file_data, agent_id)

            agent_info_to_insert = {
                CustomAppsPerAgentKey.AgentId: agent_id,
                CustomAppsPerAgentKey.AppId: app_id,
                CustomAppsPerAgentKey.Status: CommonAppKeys.AVAILABLE,
                CustomAppsPerAgentKey.CustomerName: customer_name,
                CustomAppsPerAgentKey.InstallDate: r.epoch_time(0.0)
            }

            insert_app_data(agent_info_to_insert,
                            collection=AppCollections.CustomAppsPerAgent)
コード例 #5
0
ファイル: syncer.py プロジェクト: vFense/vFense
def update_supported_apps(json_data):

    try:
        rv_q = Queue('downloader', connection=RQ_PKG_POOL)
        conn = db_connect()

        inserted_count = 0
        all_customers = list(
            r.table(Collection.Customers).map(
                lambda x: x[CustomerKey.CustomerName]).run(conn))

        for i in range(len(json_data)):
            json_data[i][SupportedAppsKey.Customers] = all_customers
            json_data[i][SupportedAppsKey.ReleaseDate] = \
                r.epoch_time(json_data[i][SupportedAppsKey.ReleaseDate])
            json_data[i][SupportedAppsKey.FilesDownloadStatus] = \
                PackageCodes.FilePendingDownload
            json_data[i][SupportedAppsKey.Hidden] = 'no'
            json_data[i][SupportedAppsKey.VulnerabilityId] = ''

            insert_app_data(json_data[i],
                            DownloadCollections.LatestDownloadedSupported)
            file_data = json_data[i].get(SupportedAppsKey.FileData)
            add_file_data(json_data[i][SupportedAppsKey.AppId], file_data)
            data_to_update = {SupportedAppsKey.Customers: all_customers}
            exists = (r.table(AppCollections.SupportedApps).get(
                json_data[i][SupportedAppsKey.AppId]).run(conn))

            if exists:
                updated = (r.table(AppCollections.SupportedApps).get(
                    json_data[i][SupportedAppsKey.AppId]).update(
                        data_to_update).run(conn))

            else:
                updated = (r.table(AppCollections.SupportedApps).insert(
                    json_data[i]).run(conn))

            rv_q.enqueue_call(func=download_all_files_in_app,
                              args=(json_data[i][SupportedAppsKey.AppId],
                                    json_data[i][SupportedAppsKey.OsCode],
                                    None, file_data, 0,
                                    AppCollections.SupportedApps),
                              timeout=86400)

            inserted_count += updated['inserted']

        conn.close()

        update_apps = IncomingSupportedApps()
        update_apps.sync_supported_updates_to_all_agents(json_data)

    except Exception as e:
        logger.exception(e)
コード例 #6
0
ファイル: custom_apps.py プロジェクト: akaasjager/vFense
def add_custom_app_to_agents(username, customer_name, uri, method,
                             file_data, agent_id=None, app_id=None):

    if app_id and not agent_id:
        app_info = (
            fetch_app_data(
                app_id, collection=AppCollections.CustomApps
            )
        )

        agent_ids = get_all_agent_ids(customer_name, agent_os=app_info[AgentKey.OsCode])
        if len(agent_ids) > 0:
            for agentid in agent_ids:
                add_file_data(app_id, file_data, agent_id)
                agent_info_to_insert = (
                    {
                        CustomAppsPerAgentKey.AgentId: agentid,
                        CustomAppsPerAgentKey.AppId: app_id,
                        CustomAppsPerAgentKey.Status: CommonAppKeys.AVAILABLE,
                        CustomAppsPerAgentKey.CustomerName: customer_name,
                        CustomAppsPerAgentKey.InstallDate: r.epoch_time(0.0)
                    }
                )
                insert_app_data(
                    agent_info_to_insert,
                    collection=AppCollections.CustomAppsPerAgent
                )

    if agent_id and not app_id:
        agent_info = get_agent_info(agent_id)
        apps_info = fetch_apps_data_by_os_code(
            agent_info[AgentKey.OsCode], customer_name,
            collection=AppCollections.CustomApps
        )

        for app_info in apps_info:
            app_id = app_info.get(CustomAppsKey.AppId)
            file_data = fetch_file_data(app_id)
            add_file_data(app_id, file_data, agent_id)

            agent_info_to_insert = {
                CustomAppsPerAgentKey.AgentId: agent_id,
                CustomAppsPerAgentKey.AppId: app_id,
                CustomAppsPerAgentKey.Status: CommonAppKeys.AVAILABLE,
                CustomAppsPerAgentKey.CustomerName: customer_name,
                CustomAppsPerAgentKey.InstallDate: r.epoch_time(0.0)
            }

            insert_app_data(
                agent_info_to_insert, collection=AppCollections.CustomAppsPerAgent
            )