def get_version_info(pmacontrolURL): """ Get version info from PMA.control instance running at pmacontrolURL """ # why? because GetVersionInfo can be invoked WITHOUT a valid SessionID; _pma_api_url() takes session information into account url = pma._pma_join(pmacontrolURL, "api/version") try: headers = {'Accept': 'application/json'} r = pma._pma_http_get(url, headers) except Exception as e: print(e) return None return r.json()
def user_exists(admSessionID, u): from pma_python import pma url = (_pma_admin_url(admSessionID) + "SearchUsers?source=Local" + "&SessionID=" + pma._pma_q(admSessionID) + "&query=" + pma._pma_q(u)) try: r = pma._pma_http_get(url, {'Accept': 'application/json'}) except Exception as e: print(e) return None results = r.json() for usr in results: if usr["Login"].lower() == u.lower(): return True return False
def _pma_get_training_sessions(pmacontrolURL, pmacoreSessionID): """ Retrieve a list of currently defined training sessions in PMA.control. """ url = pma._pma_join( pmacontrolURL, "api/Sessions?sessionID=" + pma._pma_q(pmacoreSessionID)) try: headers = {'Accept': 'application/json'} r = pma._pma_http_get(url, headers) except Exception as e: print(e) return None return r.json()
def _pma_get_projects(pmacontrolURL, pmacoreSessionID): """ Retrieve all projects and their data in PMA.control (RAW JSON data; not suited for human consumption) """ global _pma_projects_json url = pma._pma_join( pmacontrolURL, "api/Projects?sessionID=" + pma._pma_q(pmacoreSessionID)) try: headers = {'Accept': 'application/json'} r = pma._pma_http_get(url, headers) return r.json() except Exception as e: return None
def _pma_get_case_collections(pmacontrolURL, pmacoreSessionID): """ Retrieve all the data for all the defined case collections in PMA.control (RAW JSON data; not suited for human consumption) """ global _pma_casecollections_json url = pma._pma_join( pmacontrolURL, "api/CaseCollections?sessionID=" + pma._pma_q(pmacoreSessionID)) try: headers = {'Accept': 'application/json'} r = pma._pma_http_get(url, headers) return r.json() except Exception as e: return None
def get_training_session_participants(pmacontrolURL, pmacontrolTrainingSessionID, pmacoreSessionID): """ Extract the participants in a particular session """ url = pma._pma_join( pmacontrolURL, "api/Sessions/" + str(pmacontrolTrainingSessionID) + "/Participants?sessionID=" + pma._pma_q(pmacoreSessionID)) try: headers = {'Accept': 'application/json'} r = pma._pma_http_get(url, headers) except Exception as e: print(e) return None parts = {} for part in r.json(): parts[part['User']] = part return parts
def admin_connect(pmacoreURL, pmacoreAdmUsername, pmacoreAdmPassword): """ Attempt to connect to PMA.core instance; success results in a SessionID only success if the user has administrative status """ _pma_check_for_pma_start("admin_connect", pmacoreURL) # purposefully DON'T use helper function _pma_api_url() here: # why? Because_pma_api_url() takes session information into account (which we don't have yet) url = pma._pma_join(pmacoreURL, "admin/json/AdminAuthenticate?caller=SDK.Python") url += "&username="******"&password="******"Success"]).lower() != "true"): admSessionID = None else: admSessionID = loginresult["SessionId"] core._pma_sessions[admSessionID] = pmacoreURL core._pma_usernames[admSessionID] = pmacoreAdmUsername if not (admSessionID in core._pma_slideinfos): core._pma_slideinfos[admSessionID] = dict() core._pma_amount_of_data_downloaded[admSessionID] = len(loginresult) return (admSessionID)