def main():
    configfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
                              'config.conf')
    config = ConfigParser()

    if not os.path.exists(configfile):
        # Well there wasn't a config file located in the parent directory
        # so we should create a new one.
        config.add_section('SecurityCenter')
        config.set('SecurityCenter', 'host',
                   input('SecurityCenter IP Address : '))
        config.set('SecurityCenter', 'user',
                   input('SecurityCenter Username : '******'SecurityCenter', 'pass',
                   getpass.getpass('SecurityCenter Password : '******'SecurityCenter', 'path',
                   os.path.join(input('Folder to place reports : '), ''))

        with open(configfile, 'w') as fobj:
            config.write(fobj)
    else:
        config.read(configfile)

    hostip = config.get('SecurityCenter', 'host')
    username = config.get('SecurityCenter', 'user')
    password = config.get('SecurityCenter', 'pass')
    fldrloc = config.get('SecurityCenter', 'path')

    # What the element header for each set of data should be called
    elementname = 'PortsAndServices'

    # Begin collecting data from SecurityCenter
    data = collect(hostip, username, password)

    # Enable the writedev line below to help with development and
    # troubleshooting data from SecurityCenter
    #
    # Creates a JSON and XML output of the raw SecurityCenter data
    #
    # If you are developing, it is helpful to comment out the
    # data = parsedata(data) and writexml lines in order to get the JSON
    # file by itself to see what the data structure is like
    #writedev(fldrloc, scriptname, data, logger)

    # Parse the data retrieved from SecurityCenter
    data = parsedata(data)

    # Write parse data (stored as dictionary objects in a list variable) to XML
    try:
        if optcsv:
            writecsv(fldrloc, scriptname, data, logger)
        else:
            writexml(fldrloc, scriptname, data, elementname, logger)
    except Exception:
        logger.error('Error in writexml function', exc_info=True)
        closeexit(1)

    # Close log file and exit script cleanly
    closeexit(0)
Exemplo n.º 2
0
def main():
    configfile = os.path.join(os.path.dirname(
        os.path.abspath(__file__)), '..', 'config.conf')
    config = ConfigParser()

    if not os.path.exists(configfile):
        # Well there wasn't a config file located in the parent directory
        # so we should create a new one.
        config.add_section('SecurityCenter')
        config.set('SecurityCenter', 'host', input(
            'SecurityCenter IP Address : '))
        config.set('SecurityCenter', 'user', input(
            'SecurityCenter Username : '******'SecurityCenter', 'pass', getpass.getpass(
            'SecurityCenter Password : '******'SecurityCenter', 'path', os.path.join(input(
            'Folder to place reports : '), ''))

        with open(configfile, 'w') as fobj:
            config.write(fobj)
    else:
        config.read(configfile)

    hostip = config.get('SecurityCenter', 'host')
    username = config.get('SecurityCenter', 'user')
    password = config.get('SecurityCenter', 'pass')
    fldrloc = config.get('SecurityCenter', 'path')

    data = getRuleData(hostip, username, password)

    # What the element header for each set of data should be called
    elementname = 'RecastRiskRules'

    # Write parse data (stored as dictionary objects in a list variable) to XML
    try:
        if optcsv:
            writecsv(fldrloc, scriptname, data, logger)
        else:
            writexml(fldrloc, scriptname, data, elementname, logger)
    except Exception:
        logger.error('Error in writexml function', exc_info=True)
        closeexit(1)

    # Close log file and exit script cleanly
    closeexit(0)