コード例 #1
0
def check_auth(username, password):
    """This function is called to check if a username /
    password combination is valid.
    """
    isDebug = NaFunctions.getConfigOption("Debug")
    server = NaFunctions.getConfigOption("LdapServer")
    base_dn = NaFunctions.getConfigOption("BaseUserDn")
    bind_user="******" + username + "," + base_dn
    tls_cacert_file = NaFunctions.getConfigOption("TLSCACertFile")

    if tls_cacert_file:
        ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, tls_cacert_file)

    if isDebug == True:
        ldap.set_option(ldap.OPT_DEBUG_LEVEL,255)

#     search_filter = "(&(objectClass=person)(uid=" + username + ")(member=cn=dba,cn=groups,cn=accounts," + base_dn + "))"
#     print "Filter is: " + search_filter
    connect = ldap.initialize(server)
    try:
        connect.bind_s(bind_user, password)
#         connect.search_s(base_dn, LDAP_SCOPE_SUBTREE, search_filter)
        connect.unbind_s()
        print("User %s successfully authenticated" % username)
        g.user = username
        g.env = "GENERAL"

        return True
    except Exception:
        connect.unbind_s()
        print("Authentication failed for %s" % username)
        return False
コード例 #2
0
    def openDbConn(self):
        server=NaFunctions.getConfigOption("Server", "RFCDBCONN")
        db=NaFunctions.getConfigOption("DB", "RFCDBCONN")
        uid=NaFunctions.getConfigOption("User", "RFCDBCONN")
        password=NaFunctions.getConfigOption("Password", "RFCDBCONN")
        driver=NaFunctions.getConfigOption("Driver", "RFCDBCONN")

        self.connection = pyodbc.connect(driver=driver, server=server, database=db, uid=uid, password=password)
        self.cursor = self.connection.cursor()
コード例 #3
0
 def decorated(*args, **kwargs):
     isAuthReq = NaFunctions.getConfigOption("AuthRequired")
     if (isAuthReq == "False"):
         g.user = "******"
         return f(*args, **kwargs)
     auth = request.authorization
     if not auth or not check_auth(auth.username, auth.password):
         return authenticate()
     return f(*args, **kwargs)
コード例 #4
0
def env_get():
    try:
        envs = NaFunctions.getEnvs()
#         jsonEnvs = json.dumps([env.__dict__ for env in envs])
        jsonData = jsonify(success=True, envs=[env.__dict__ for env in envs])
        app.logger.info('success', extra={'user':g.user, 'env':'n/a'})
    except Exception as e:
        app.logger.error('failure: ' + str(e), extra={'user':g.user, 'env':'n/a'})
        jsonData = jsonify(errorMsg = str(e))
        jsonData.status_code = 400
    finally:
        return jsonData
コード例 #5
0
def snapshot_create():
    request_dict = json.loads(request.data)
    g.env = request_dict["env"]
    volume = request_dict["volume"]
    newName = request_dict["newName"]

    ret = NaFunctions.createSnapshot(volume, newName)

    if (ret.results_status() == "failed"):
        app.logger.error('failure: ' + ret.results_reason(), extra={'user':g.user, 'env':g.env})
        jsonData = jsonify(errorMsg = ret.results_reason())
        jsonData.status_code = 400
    else:
        app.logger.info('success', extra={'user':g.user, 'env':g.env})
        jsonData = jsonify(success=True, data = ret.toEncodedString())

    return jsonData
コード例 #6
0
def snapshot_get():
    request_dict = json.loads(request.data)
    g.env = request_dict["env"]
    ret = NaFunctions.listSnapshots(request_dict["volume"])

    if ret.results_status() == "failed":
        app.logger.error('failure: ' + ret.results_reason(), extra={'user':g.user, 'env':g.env})
        jsonData = jsonify(errorMsg = ret.results_reason())
        jsonData.status_code = 400
    else:
        app.logger.info('success for ' + request_dict["volume"], extra={'user':g.user, 'env':g.env})
        snaplist = ret.child_get("snapshots")
        if snaplist:
            data = snaplist.toEncodedString()
        else:
            data = None
        jsonData = jsonify(success=True, data = data)
    return jsonData
コード例 #7
0
def volume_get():
    request_dict = json.loads(request.data)
    g.env = request_dict["env"]
    ret = NaFunctions.listVolumes()

    if ret.results_status() == "failed":
        app.logger.error('failure: ' + ret.results_reason(), extra={'user':g.user, 'env':g.env})
        jsonData = jsonify(errorMsg = ret.results_reason())
        jsonData.status_code = 400
        
    else:
        app.logger.info('success', extra={'user':g.user, 'env':g.env})
        vollist = ret.child_get("attributes-list")
        if vollist:
            data = vollist.toEncodedString()
        else:
            data = None
        jsonData = jsonify(success=True, data = data)
    return jsonData
コード例 #8
0
def snapshot_restore():
    request_dict = json.loads(request.data)
    g.env = request_dict["env"]
    volume = request_dict["volume"]
    snapshot = request_dict["snapshot"]

    if NaFunctions.EnvObj(g.env).get_rfc_required() == "True":
        rfcNumber = request_dict["rfcNumber"]
        try:
            rfcRes = RFCChecker.RFCChecker(rfcNumber)
        except Exception as e:
            errorMsg = str(e)
            app.logger.error('failure for ' + volume + ':' + snapshot + ' : ' + errorMsg, extra={'user':g.user, 'env':g.env})
            jsonData = jsonify(errorMsg = errorMsg)
            jsonData.status_code = 400
            return jsonData
                

        if rfcRes.isRFCScheduled():
            app.logger.info('RFC #' + rfcNumber + ' is Scheduled, proceeding', extra={'user':g.user, 'env':g.env})
        else:
            errorMsg = 'RFC #' + rfcNumber + ' is not in scheduled state'
            app.logger.error('failure for ' + volume + ':' + snapshot + ' : ' + errorMsg, extra={'user':g.user, 'env':g.env})
            jsonData = jsonify(errorMsg = errorMsg)
            jsonData.status_code = 400
            return jsonData
    
    ret = NaFunctions.restoreSnapshot(volume, snapshot)
    if (ret.results_status() == "failed"):
        app.logger.error('failure for ' + volume + ':' + snapshot +
                         ' : ' + ret.results_reason(), extra={'user':g.user, 'env':g.env})
        jsonData = jsonify(errorMsg = ret.results_reason())
        jsonData.status_code = 400
    else:
        app.logger.info('success for ' +
                        volume + ':' + snapshot, extra={'user':g.user, 'env':g.env})
        jsonData = jsonify(success=True, data = ret.toEncodedString())

    return jsonData
コード例 #9
0
import logging
from logging.handlers import RotatingFileHandler

from flask import Flask, render_template, request, json
from flask.globals import g
from flask.json import jsonify
from werkzeug.utils import redirect

import LoginAuth
import NaFunctions
import RFCChecker


app = Flask(__name__)
formatter = logging.Formatter("%(asctime)s %(levelname)s %(user)s %(env)s %(funcName)s : %(message)s")
handler = RotatingFileHandler(NaFunctions.getConfigOption("LogFile"), maxBytes=10000000, backupCount=3)
handler.setLevel(logging.INFO)
handler.setFormatter(formatter)
app.logger.addHandler(handler)
app.logger.setLevel(logging.INFO)
app.debug = NaFunctions.getConfigOption("Debug")

@app.route("/")
@LoginAuth.requires_auth
def index():
    return render_template('index.html')

@app.route('/snapmgr')
@app.route('/snapmgr/')
@LoginAuth.requires_auth
def snapmgr_index():
コード例 #10
0
from flask.json import jsonify
from werkzeug.utils import redirect

import LoginAuth
import NaFunctions
import RFCChecker


app = Flask(__name__)
formatter = logging.Formatter("%(asctime)s %(levelname)s %(user)s %(env)s %(funcName)s : %(message)s")
handler = RotatingFileHandler("/home/rgroten/git/NetApp-Snapshot-Manager/snapmgr/snapmgr.log", maxBytes=10000000, backupCount=3)
handler.setLevel(logging.INFO)
handler.setFormatter(formatter)
app.logger.addHandler(handler)
app.logger.setLevel(logging.INFO)
app.debug = NaFunctions.getConfigOption("Debug")

@app.route("/")
@LoginAuth.requires_auth
def index():
    return render_template('index.html')

@app.route('/snapmgr')
@app.route('/snapmgr/')
@LoginAuth.requires_auth
def snapmgr_index():
    return redirect('/#/snapmgr')


@app.route('/getenv')
@app.route('/api/get_envs.json')