예제 #1
0
def uninstall_windows():
    """Attempts to uninstall the CTQA Audit task with the Schtasks command"""

    params = '/delete /TN "CTQA" /f'
    params_weekly = '/delete /TN "CTQA-Weekly" /f'

    logger.debug('Uninstalling with script: ' + params)

    # Attempt to exec as admin. Catch denial of UAC prompt.
    try:
        # Uninstall daily audit
        dict = shell.ShellExecuteEx(fMask=256 + 64,
                                    lpVerb='runas',
                                    lpFile='Schtasks.exe',
                                    lpParameters=params)
        hh = dict['hProcess']
        ret = win32event.WaitForSingleObject(hh, -1)
        logger.debug("Shell uninstallation result: " + str(ret))

        # Uninstall weekly audit
        dict = shell.ShellExecuteEx(fMask=256 + 64,
                                    lpVerb='runas',
                                    lpFile='Schtasks.exe',
                                    lpParameters=params_weekly)
        hh = dict['hProcess']
        ret = win32event.WaitForSingleObject(hh, -1)
        logger.debug("Shell uninstallation result: " + str(ret))

    except pywintypes.error as e:
        logger.error("Error in UAC prompt for windows installation: " + str(e))

    confutil.updateConfig(
        os.path.join(LOCATION, confutil.DEFAULT_CONFIG_LOCATION),
        "ServicesInstalled", False)
예제 #2
0
파일: orthanc.py 프로젝트: Brikwerk/ctqa
def fetchImages(URL, lastImageNumber, profileinit=False):
    '''Retreives image URLs from an Orthanc server instance through the REST API'''

    if not profileinit:  # We want only the latest slice if not profile init
        start = lastImageNumber
    else:
        start = 0
    imgURLs = []

    # Looping through all images after the passed image number and
    # adding their paths to an array.
    while True:
        r = get(
            URL + '/changes',
            {
                'since': start,
                'limit': 16  # Retrieve at most 16 changes at once
            })

        if len(r['Changes']) is 0:
            start = r['Last']
            break

        start = r['Last']
        for change in r['Changes']:
            # We are only interested interested in the arrival of new instances
            if change['ChangeType'] == 'NewInstance':
                # Store imgs in the imgs array
                path = change['Path']
                imgURLs.append(path)

    logger.debug("Fetched Orthanc image urls")
    logger.debug("Downloading images...")

    images = []
    for imgurl in imgURLs:
        with urllib.request.urlopen(URL + imgurl + '/file') as response:
            logger.debug("Downloading image from: %s",
                         (URL + imgurl + '/file'))
            with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
                shutil.copyfileobj(response, tmp_file)
                images.append(tmp_file.name)

    logger.debug("Retrieved/stored images: %s", images)

    # If this isn't a profile initialization run from the auto-profiler
    if not profileinit:
        configpath = os.path.join(LOCATION, confutil.DEFAULT_CONFIG_LOCATION)
        confutil.updateConfig(configpath, "LastImageNumber", start)

    return images
예제 #3
0
def test_update_config_bad_key():
    '''Testing for detection of bad update'''

    # Setup
    confutil.createConfig("testUpdateConfig.json")

    res = confutil.updateConfig("testUpdateConfig.json", "TEST", "TEST")
    assert res == -1

    os.remove("testUpdateConfig.json")
예제 #4
0
def main():
    # Setup
    logPath = LOCATION + "/" + logutil.MAIN_LOG_FILE_NAME
    logutil.initLog(logPath, logutil.MAIN_LOG_NAME, __DEBUG)

    confPath = LOCATION + "/" + confutil.DEFAULT_CONFIG_LOCATION
    config = confutil.loadConfig(confPath)

    # Checking for blank report location
    if type(config) == dict and "ReportLocation" in config:
        if config["ReportLocation"] == "":
            confutil.updateConfig(confPath, "ReportLocation",
                                  confutil.DEFAULT_REPORT_FOLDER_LOCATION)

    logger = logging.getLogger(logutil.MAIN_LOG_NAME)
    logger.debug("Config Location: %s", confPath)
    logger.debug("Log Location: %s", logPath)

    profileutil.init(LOCATION + '/profiles.json')
    profiles = profileutil.openProfiles(LOCATION + '/profiles.json')

    # Ensuring data folder exists. If not, they are created.
    if not os.path.isdir(LOCATION + "/data"):
        os.makedirs(LOCATION + '/data')

    # Choose and run
    # Check for first run if not a service call
    frconf = confutil.openConfig(
        confPath)  # Checking config file without validation
    if type(frconf) == dict and (frconf.get("FirstRun") == True):
        firstrun.run()
    elif __RUNTYPE == 1:  # Audit run
        try:
            if __WEEKLY:
                app.run(config, profiles, __DEBUG, weekly=True)
            else:
                app.run(config, profiles, __DEBUG)
        except Exception as e:
            logger.error(e)
    else:  # Client Run
        client.app.run()
예제 #5
0
def test_update_config():
    # Setup
    confutil.createConfig("testconf.json")

    res = confutil.updateConfig("testconf.json", "Source", "ORTHANC")
    if res != 1:
        assert False

    config = confutil.openConfig("testconf.json")
    assert config["Source"] == "ORTHANC"

    os.remove("testconf.json")
예제 #6
0
def install_windows():
    """Attempts to install the CTQA Audit utility as a task in Windows Task Scheduler."""

    params = '/Create /SC Daily /RU System /TN "CTQA" /TR "' + os.path.join(
        LOCATION, sys.argv[0]) + ' --audit --debug" /ST 07:00'
    params_weekly = '/Create /SC Weekly /RU System /D MON /TN "CTQA-Weekly" /TR "' + os.path.join(
        LOCATION, sys.argv[0]) + ' --audit --weekly --debug" /ST 07:00'
    logger.debug('Installing with script: ' + params)

    # Attempt to exec as admin. Catch denial of UAC prompt.
    try:
        # Daily audit installation
        dict = shell.ShellExecuteEx(fMask=256 + 64,
                                    lpVerb='runas',
                                    lpFile='Schtasks.exe',
                                    lpParameters=params)
        hh = dict['hProcess']
        ret = win32event.WaitForSingleObject(hh, -1)
        logger.debug("Shell CTQA Daily Audit installation result: " + str(ret))

        # Weekly audit installation
        dict = shell.ShellExecuteEx(fMask=256 + 64,
                                    lpVerb='runas',
                                    lpFile='Schtasks.exe',
                                    lpParameters=params_weekly)
        hh = dict['hProcess']
        ret = win32event.WaitForSingleObject(hh, -1)
        logger.debug("Shell CTQA Weekly Audit installation result: " +
                     str(ret))

    except pywintypes.error as e:
        logger.error("Error in UAC prompt for windows installation: " + str(e))

    print(os.path.join(LOCATION, confutil.DEFAULT_CONFIG_LOCATION))
    confutil.updateConfig(
        os.path.join(LOCATION, confutil.DEFAULT_CONFIG_LOCATION),
        "ServicesInstalled", True)