示例#1
0
def proceed_ontap(version):
    """ Method which handles our use case of running checks
        on a remote ONTAP instance. This requires two stages
        of gathering user input data and checking the validity
        of such input data. Unlike the proceed_localhost() function,
        this method if prone to errors (i.e. invalid credentials); we
        therefore use the flash module to display errors on the
        client side """

    # grab user input data
    IPAddr = request.form['IPAddr'].encode('ascii', 'ignore')
    user = request.form['user'].encode('ascii', 'ignore')
    password = request.form['password'].encode('ascii', 'ignore')
    error = None

    # handle missing information
    if not IPAddr:
        error = 'IP Address is required.'
    if not user:
        error = 'User name is required.'
    if not password:
        error = 'Password is required.'

    # Attempt to check if login works
    if not test_login_credentials(IPAddr, user, password, version):
        error = 'Invalid login info.'
        current_app.logger.info(time.ctime() +
                                '\tFailed login request from {}'.format(
                                    socket.gethostbyname(socket.getfqdn())))

    if error is not None:
        # display any errors on the user side
        flash(error)
    else:
        # clear all cookies and set new ones
        session.clear()
        session['user'] = user
        session['IPAddr'] = IPAddr
        session['version'] = version

        # All sensitive data in the session must be encrypted
        AESKey = [ord(elem) for elem in current_app.config['SECRET_KEY']]
        myAES = AES.AESEncryptor(key=AESKey)

        session['password'] = myAES.encrypt(password)
        session['local'] = False

        # logging stage
        current_app.logger.info(
            time.ctime() + '\t{} successfully connected to {}'.format(
                socket.gethostbyname(socket.getfqdn()), IPAddr))
        current_app.logger.info(time.ctime() +
                                '\t continuing as ONTAP user {}'.format(user))

        return redirect(url_for('upload.upload'))
示例#2
0
def description():
    """ Method which renders our description webpage and adds functionality to
        POST calls. For GET requests, this method essentially creates several
        OVALRequests. For POST requests, this method converts the OVALRequests
        into OVALDrivers, which are used in the following webpage """

    # Captures the global requests variable
    global _requests

    if request.method == 'POST':

        global _drivers

        IPAddr = g.IPAddr

        # All sensitive data in the session must be encrypted

        password = None
        if g.password:
            AESKey = [ord(elem) for elem in current_app.config['SECRET_KEY']]
            myAES = AES.AESEncryptor(key=AESKey)
            password = myAES.decrypt(g.password)

        user = g.user
        ontap_version = g.version

        _drivers = [
            oval.OVALDriver(ovalrequest,
                            IPAddr=IPAddr,
                            user=user,
                            password=password,
                            verbose=False,
                            version=ontap_version) for ovalrequest in _requests
        ]
        current_app.logger.info(time.ctime() + "\tOVAL drivers initialized")

        # we have handled the requests so we no longer need them
        _remove_persist_storage('filenames')
        _remove_persist_storage('processType')
        _remove_persist_storage('coreFactor')
        del _requests[:]

        return redirect(url_for('checks.results_overview'))

    # GET
    # Calls all the backend code
    _create_descriptions()
    return render_template('checks/description.html', requests=_requests)