예제 #1
0
def query():
    '''
    @return airplane info
    '''
    datas = request.form.get("data", None)
    if not datas:
        datas = request.get_json(force=True)
    else:
        datas = json.loads(datas)
    app.logger.info('request params: {}'.format(json.dumps(datas, ensure_ascii=False)))
    aireplane_id = datas.get('aireplane_id', 0)

    # mock: search db get Lockheed Corporation aireplane info    
    airplane_name = db.search_db(aireplane_id)
    code = 1
    msg = "welcome to Lockheed Corporation!"
    data = {"aireplane_id":aireplane_id, "airplane_name":airplane_name}
    if airplane_name is None:
        code = 1
        msg = 'sorry, can not search ' + str(aireplane_id) +' airplane'
        data = {}
    
    app.logger.info('search db data is {}'.format(airplane_name))
    return json.dumps({'code': code,\
                       'msg': msg,\
                       'data': data})
예제 #2
0
def listguest():
    """
    Displays the guest table
    @return: html page of the table
    """
    data = db.search_db(dbname, "guest")
    return render_template("list-guest.html", rows=data)
예제 #3
0
def listdomain():
    """
    Displays the domain table
    @return: html page of the table
    """
    data = db.search_db(dbname, "domain")
    return render_template("list-domain.html", rows=data)
예제 #4
0
def listdevice():
    """
    Displays the device table
    @return: html page of the table
    """
    data = db.search_db(dbname, "device")
    return render_template("list-device.html", rows=data)
예제 #5
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
예제 #6
0
def syncdbs():

    """
    Synchronizes the user data base table with the UCXN Server
    @return: redirect to "/" with a status code of 302
    """
    # Make a call to the voice mail application to get all users
    synchronize_dbs()

    global lastsynchronize

    now = datetime.datetime.now()
    lastsynchronize=now.strftime("%m-%d-%Y %H:%M")

    print (lastsynchronize)

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

    #return render_template("list-users.html", rows=data, ipaddress=vmip)
    return redirect("/", code=302)
예제 #7
0
def test_search_db(temp_database, database):
    ret = db.search_db(temp_database, database)
    ret1 = db.search_db(temp_database, database)
    assert ret == ret1
예제 #8
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
예제 #9
0
def home():

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

    return render_template("list-users.html", rows=data, ipaddress=vmip, lastsynchronized=lastsynchronize)