Esempio n. 1
0
def toggle_status(emailid):
    '''
    This function will toggle the VMO Status for a particular user.

    :param emailid: The emailid id of the user you want to toggle
    :return: redirect to "/" with a Status Code of 302
    '''

    if WEBDEBUG:
        print_details(request)

    print ("Toggling VMO Status for: "+emailid)

    ret, msg = db.search_database(dbname, "users", "Alias", emailid)
    print("Current Value of VMO Status: "+msg['Active'])

    if ret:
        value = msg['Active']
        if value == "True":
            value = "False"
        else:
            value = "True"

    updatestring = "Active='" + value +"'"
    print (msg['CallHandlerObjectId'])
    ret, msg = db.update_database(dbname, "users", updatestring, "Alias='" + emailid + "'")


    if value == "True":
        print ("Submitting a request to set an alert on: "+emailid)
    else:
        print ("Submitting a request to turn off the alert on: "+emailid)

    apistring = mailip + "/monitor"

    print(apistring)

    headers = {
        'Content-Type': 'application/json'
    }

    user = {}
    user['email'] = emailid
    user['status'] = value

    print(user)
    try:
        resp = requests.post(apistring, data=json.dumps(user),
                                 headers=headers)
    except requests.exceptions.RequestException as e:
        flash("ERROR: Error when attempting to toggle status of user : "******"ERROR: Synchronization failed to ("+apistring+"): "+" Status Code ("+str(resp.status_code)+"): "+str(resp.reason))

    return redirect("/", code=302)
Esempio n. 2
0
def getuserbyid():
    """
    Returns the email address of the user specified by the teamsid parameter
    @return:
    """
    if WEBDEBUG:
        print_details(request)

    if 'teamsid' not in request.args:
        return (jsonify({"result": "no parameter"}))
    return jsonify(email=teamsapi.getemailfromid(teamsurl, teamstoken, request.args['teamsid']))
Esempio n. 3
0
def getendpointid():
    """
    This function will determine if a endpoint id already exists in the database.
    @return: id of the deviceid
    """
    if WEBDEBUG:
        print_details(request)
    if 'deviceid' not in request.args:
        return jsonify({"result": "no parameter"})
    ret,msg = db.search_database(dbname, "device", "name", request.args['deviceid'])

    return jsonify({"result":msg})
Esempio n. 4
0
def postemaildomain():
    """
    This function will add a new domain to the white list database
    @return: result of the insert
    """
    if WEBDEBUG:
        print_details(request)
    if 'domain' not in request.args:
        return jsonify({"result": "no parameter"})
    ret,msg= db.insert_into_database(dbname, "domain", NAME=request.args['domain'])

    return jsonify({"result":msg})
Esempio n. 5
0
def getemaildomain():
    """
    This function will see if an email domain is in the white list database
    @return: id of the record
    """
    if WEBDEBUG:
        print_details(request)

    if 'domain' not in request.args:
        return jsonify({"result": "no parameter"})

    ret,msg = db.search_database(dbname, "domain", "name", request.args['domain'])
    return jsonify({"result": msg})
Esempio n. 6
0
def getdetailedinfo():
    """
    Returns the detailed information about the user specified by the teamsid
    @return:
    """

    if WEBDEBUG:
        print("Debugging")
        print_details(request)

    if 'teamsid' not in request.args:
        return jsonify({"result": "no parameter"})
    return jsonify(teamsapi.getdetailedinfofromid(teamsurl, teamstoken, request.args['teamsid']))
Esempio n. 7
0
def statusguestaccount():
    """
    This function will return the status of the guest account provided by the email address
    @return:  status
    """
    if WEBDEBUG:
        print_details(request)

    if 'email' not in request.args:
        return jsonify({"result": "no parameter"})
    else:
        emailaddress = request.args['email']
        ret, msg = db.search_database(dbname, "guest", "name", emailaddress)

        return jsonify({"result":msg})
Esempio n. 8
0
def setup():
    '''
    This function implements the setup API call.   This call is used first by the mail server gateway to receive all users
    within the database table.   Once the call is executed, this function iterates through all users and sends the information
    along with if the VMO function is enabled and disabled.   It is normally called when the mail interface first starts up.

    :return: JSON {"result": "True"} and a web status code 200
    '''

    if WEBDEBUG:
        print_details(request)

    # Search for all the records within the "users" table.
    data = db.search_db(dbname, "users")

    # For each record in the database, send a message to the email server to register the user
    for i in data:
        print ("Send Register Event to Email Server for: "+i[2]+" to "+i[6])

        apistring = mailip+"/monitor"

        print (apistring)

        headers = {
            'Content-Type': 'application/json'
        }

        user={}
        user['email'] = i[2]
        user['status'] = i[6]

        try:
            response = requests.post(apistring, data=json.dumps(user),
                                     headers=headers, timeout=10)
        except requests.exceptions.RequestException as e:
            print(e)

        else:
            print ("Response Code: "+str(response.status_code))
            print ("Response: "+response.text)
            if response.status_code == 200:
                data=response.text
                print(str(data))
                print("")


    return jsonify({"result": "True"}), 200
Esempio n. 9
0
def apphealth():
    if WEBDEBUG:
        print_details(request)
    return jsonify({"health":"running"})
Esempio n. 10
0
def about():
    if WEBDEBUG:
        print_details(request)
    return render_template('about.html')
Esempio n. 11
0
def home():
    if WEBDEBUG:
        print_details(request)
    return render_template('home.html')
Esempio n. 12
0
def updatestatusguestaccount():
    """
    This function will update the status of the guest account
    @return:
    """
    if WEBDEBUG:
        print_details(request)

    # determine if both the emailid and status is provided in the request, if not, return the error value

    if ('emailid' in request.args) and ('status' in request.args):


        emailid = request.args['emailid']

        print("Emailid: "+emailid)

        # check to see if the status is completed.   If so, then we are going to ecxpect the guest password
        if request.args['status']=="completed":
            print("Status passed to function is completed")
            # If guest password is not passed to the parameter, then return an error message
            if ('guestpassword' not in request.args):
                print("Guestpassword is not passed to the function")
                return jsonify({"result":"no guest password"})
            else:

                print("Guest Password:"******"STATUS='" + request.args['status'] + "', GUESTPASSWORD='******'guestpassword']+"'"

                # Search the database record to return the room id so we can alert the user.
                ret, msg = db.search_database(dbname, "guest", "name", emailid)

                # If guest record is found then send the message to the teams room

                if ret:
                    print(str(msg))
                    ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                     "--------------------------------------------------------")
                    ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                     "Congratulations, Your account was successfully created!")
                    ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                     "Guest Credentials are located below:")
                    ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                    "ssid: **_platinum-guest_**")
                    ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                    "username: **_"+emailid+"_**")
                    ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                    "password: **_"+request.args['guestpassword']+"_**")
                else:
                    print("(Email id Found)")
                    return jsonify({"result": "emailid not found"})


        else:

            # Update the status of the record.
            updatestring = "STATUS='" + request.args['status'] + "'"

        ret, msg = db.update_database(dbname, "guest", updatestring, "NAME='" + request.args['emailid'] + "'")
        print(str(msg))

        return jsonify({"result":ret})
    else:
        return jsonify({"result":"wrong paramters"})
Esempio n. 13
0
def generateguestaccount():
    """
    This function will trigger the process of a creation of a guest account.

    @return:
    """
    if WEBDEBUG:
        print_details(request)

    # This function must be called with both the deviceid parameter and the teamsid parameter
    if ('deviceid' in request.args) and ('teamsid' in request.args):

        # Determine if deviceid is in white list database.   If not, then the device isnt authorized to generate
        # guest account

        deviceid=request.args['deviceid']
        ret, msg = db.search_database(dbname, "device", "name", deviceid)

        if not ret:
            return jsonify({"result": "deviceid not authorized"})

        # Determine if the teamsid is a valid WebEx Teams user.   If not, then quit
        ret= teamsapi.getemailfromid(teamsurl, teamstoken, request.args['teamsid'])

        if ret=="":
            return jsonify({"result": "teamsid not found"})

        # Determine if emaildomain is in white list database, if not, then the email domain isn't authorized to generate
        # a guest account
        emailaddress=ret[0]
        emaildomain=emailaddress.split("@")[1]

        ret, msg = db.search_database(dbname, "domain", "name", emaildomain)

        if (not ret):
            return jsonify({"result": "email domain not authorized"})


        # Now that we know we are authorized, serach the guest table to determine if a guest account has already
        # been initiated
        ret, msg = db.search_database(dbname, "guest", "name", emailaddress)

        if (not ret):
            # Trigger the initiation of the guest account creation

            # Create a new teamsroom to communicate the status back to the user
            ret=teamsapi.createteamsroom(teamsurl, teamstoken,"Platinum Onboard Guest Wireless "+str(date.today())+" - "+emailaddress)
            if ret == '':
                print("Unable to create the teams room")
            else:
                roomId = ret

            # Add the user to the teams room that we just created
            ret=teamsapi.adduserstoroom(teamsurl, teamstoken,roomId,emailaddress)
            if ret == '':
                print("Unable to add people to the teams room")

            teamsapi.sendmessagetoroom(teamsurl, teamstoken, roomId,
                                            "--------------------------------------------------------")
            teamsapi.sendmessagetoroom(teamsurl, teamstoken, roomId, "**Welcome to the Platinum Onboard Service**")
            teamsapi.sendmessagetoroom(teamsurl, teamstoken, roomId, "We have initiated the creation of the guest wireless account for "+emailaddress)
            teamsapi.sendmessagetoroom(teamsurl, teamstoken, roomId, "Please give us a few moments until your account is provisioned")


            # Insert a new guest record into the database.
            ret, msg = db.insert_into_database(dbname, "guest", NAME=emailaddress, DEVICE=deviceid, STATUS="initiated", TEAMSROOMID=roomId)

            if (not ret):
                # There was an issue with inserting the record.  This is a problem since we should role back the creation.
                print("Unable to insert the record")
                return (jsonify({"result":msg}))
            else:
                print("Successful insertion of record")
                # This was successful

            # Send a request to the provisioning server
            print("Triggering Guest Creation of '"+emailaddress+"' from device '"+deviceid+"' to "+provisionip)

            apistring = "http://"+provisionip+"/api/check-guest.php?emailid="+emailaddress
            print("Sending API to trigger guest creation: "+apistring)

            # Post the API call to the provisioning engine

            resp = requests.post(apistring)
            print(str(resp))

            return jsonify({"result": "success", "record_id": msg})

        else:
            # User already has a guest account initiated:


            print(str(msg))
            print("User " + emailaddress + " already has a account initiated!")

            # Search the database for the record.

            ret, msg = db.search_database(dbname, "guest", "name", emailaddress)

            # If the status is initiated, then let the user know via the teams room, that we already initiated
            # a guest account.

            if (msg['status'] == 'initiated'):
                ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                 "--------------------------------------------------------")
                ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                 "Your account request was already initiated!")
                print("Initiated")
                return jsonify({"result": "initiated"})
            else:

                # Otherwise, the guest account is created, so end back the data concerning the wireless credentials

                ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                 "--------------------------------------------------------")
                ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                 "Your account was already provisioned:")
                ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                 "Guest Credentials are located below:")
                ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                 "ssid: **_platinum-guest_**")
                ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                 "username: **_" + emailaddress + "_**")
                ret = teamsapi.sendmessagetoroom(teamsurl, teamstoken, msg['teamsroomid'],
                                                 "password: **_" + msg['guestpassword'] + "_**")

                print("Guest Password is: "+ msg['guestpassword'])
                return jsonify({"result": "completed", "password": msg['guestpassword']})

    else:
        print("Wrong Parameters")
        return jsonify({"result": "wrong paramters"})
Esempio n. 14
0
def setstatus():
    '''
    This function will implement the setstatus function.   The setstatus will be used anytime the mail server wants to
    change the status of the a user.   For example, if they go from Out Of Office = True or Out Of Office = False.

    :return: {"result":"True"} and Status Code 200 if the request was successful
             {"result":"Invalid JSON"} and Status Code 400 if the inbound JSON is incorrect
             {"result":"Not Found"} and Status Code 404 if the user was not found in the database
             {"result":str(e)} and Status Code 403 if a generic error occurred and the 'e' is the error message
             {"result": "Internal Error"} and any Status Code if another web error occured when communicating to the mail gateway

    '''

    if WEBDEBUG:
        print_details(request)


    req_data = request.get_json(force=True, silent=True)

    # Check to see if the email and status fields are included in the inbound JSON
    try:
        email = req_data['email']
        status = req_data['status']
    except (KeyError, TypeError, ValueError):
        return jsonify({"result":"Invalid JSON"}),400

    # Check to see if the OOO message is included
    try:
        message = req_data['message']
    except (KeyError, TypeError, ValueError):
        print("Incoming Message doesn't include a OOO message")
    else:
        print("Incoming Message does include a OOO message")
        print("The message is: '"+message+"'")


    print("Setting the status for: "+email+" to: "+ status)

    # Search the database table for the user
    ret, msg = db.search_database(dbname, "users", "Alias", email)

    if not ret:
        return jsonify({"result":"Not Found"}),404


    # Create the API call to send to UCXN
    apistring = vmip+"/ucxn/users/"+msg['CallHandlerObjectId']+"/greeting"

    headers = {
        'Content-Type': 'application/json'
    }

    jsonmsg = {}
    jsonmsg['action']=status
    jsonmsg['extension']=msg['Extension']
    if message:
        jsonmsg['message']=message


    print (apistring)
    print (jsonmsg)

    # Try to post the message to the UCXN server
    try:
        resp = requests.post(apistring,data=json.dumps(jsonmsg),headers=headers,timeout=10)
    except requests.exceptions.RequestException as e:
        flash("ERROR: Error when attempting to set status: "+str(e))
        return jsonify({"result":str(e)}),403

    print (resp.status_code)
    if resp.status_code == 200:
        data=resp.json()
        print(str(data))

        updatestring = "AlternateGreetingEnabled='" + status +"'"
        ret, msg = db.update_database(dbname, "users", updatestring, "Alias='" + email + "'")

        data = db.search_db(dbname, "users")

        return jsonify({"result":"True"}),200
    else:
        print("ItExecuted")
        flash ("ERROR: Unable to set status failed to ("+apistring+"): "+" Status Code ("+str(resp.status_code)+"): "+str(resp.reason))
        return jsonify({"result": "Internal Error"}),resp.status_code