Ejemplo n.º 1
0
def callers_blocked_add():
    """
    Add a new blacklist entry
    """
    caller = {}
    number = transform_number(request.form["phone"])
    caller['NMBR'] = number
    caller['NAME'] = request.form["name"]
    print("Adding " + number + " to blacklist")
    blacklist = Blacklist(get_db(), current_app.config)
    success = blacklist.add_caller(caller, request.form["reason"])
    if success:
        return redirect("/callers/blocked", code=303)
    else:
        # Probably already exists... attempt to update with original form data
        return redirect('/callers/blocked/update/{}'.format(number), code=307)
Ejemplo n.º 2
0
def callers_manage(call_no):
    """
    Display the Manage Caller form
    """

    post_count = None

    # Post changes to the blacklist or whitelist table before rendering
    if request.method == 'POST':
        number = request.form['phone_no'].replace('-', '')
        if request.form['action'] == 'add-permit':
            caller = {}
            caller['NMBR'] = number
            caller['NAME'] = request.form['name']
            print(" >> Adding " + caller['NAME'] + " to whitelist")
            whitelist = Whitelist(get_db(), current_app.config)
            whitelist.add_caller(caller, request.form['reason'])

        elif request.form['action'] == 'remove-permit':
            print(" >> Removing " + number + " from whitelist")
            whitelist = Whitelist(get_db(), current_app.config)
            whitelist.remove_number(number)

        elif request.form['action'] == 'add-block':
            caller = {}
            caller['NMBR'] = number
            caller['NAME'] = request.form['name']
            print(" >> Adding " + caller['NAME'] + " to blacklist")
            blacklist = Blacklist(get_db(), current_app.config)
            blacklist.add_caller(caller, request.form['reason'])

        elif request.form['action'] == 'remove-block':
            print(" >> Removing " + number + " from blacklist")
            blacklist = Blacklist(get_db(), current_app.config)
            blacklist.remove_number(number)
        # Keep track of the number of posts so we can to unwind the history
        # to bo "back" the original referrer
        post_count = int(request.form['post_count'])
        post_count += 1
    else:
        post_count = 0

    # Retrieve the caller information for the given call log entry
    query = """SELECT
      a.CallLogID,
      a.Name,
      a.Number,
      CASE WHEN b.PhoneNo IS NULL THEN 'N' ELSE 'Y' END Whitelisted,
      CASE WHEN c.PhoneNo IS NULL THEN 'N' ELSE 'Y' END Blacklisted,
      CASE WHEN b.PhoneNo IS NOT NULL THEN b.Reason ELSE '' END WhitelistReason,
      CASE WHEN c.PhoneNo IS NOT NULL THEN c.Reason ELSE '' END BlacklistReason
    FROM calllog AS a
    LEFT JOIN whitelist AS b ON a.Number = b.PhoneNo
    LEFT JOIN blacklist AS c ON a.Number = c.PhoneNo
    WHERE a.CallLogID=:call_log_id"""
    arguments = {"call_log_id": call_no}
    result_set = query_db(get_db(), query, arguments)
    # Prepare a caller dictionary object for the form
    caller = {}
    if len(result_set) > 0:
        record = result_set[0]
        number = record[2]
        caller.update(
            dict(call_no=record[0],
                 phone_no='{}-{}-{}'.format(number[0:3], number[3:6],
                                            number[6:]),
                 name=record[1],
                 whitelisted=record[3],
                 blacklisted=record[4],
                 whitelist_reason=record[5],
                 blacklist_reason=record[6]))
    else:
        caller.update(
            dict(call_no=call_no,
                 phone_no='Number Not Found',
                 name='',
                 whitelisted='N',
                 blacklisted='N',
                 whitelist_reason='',
                 blacklist_reason=''))

    # Re-render the same page to show the updated content
    return render_template('callers_manage.html',
                           caller=caller,
                           post_count=post_count)
Ejemplo n.º 3
0
def manage_caller(call_log_id):
    """
    Display the Manage Caller form
    """
    # Post changes to the blacklist or whitelist table before rendering
    if request.method == 'POST':
        number = request.form['phone_no'].replace('-', '')
        if request.form['action'] == 'Permit':
            caller = {}
            caller['NMBR'] = number
            caller['NAME'] = request.form['name']
            print("Adding " + caller['NAME'] + " to whitelist")
            whitelist = Whitelist(get_db(), current_app.config)
            whitelist.add_caller(caller, request.form['reason'])

        elif request.form['action'] == 'RemovePermit':
            print("Removing " + number + " from whitelist")
            whitelist = Whitelist(get_db(), current_app.config)
            whitelist.remove_number(number)

        elif request.form['action'] == 'Block':
            caller = {}
            caller['NMBR'] = number
            caller['NAME'] = request.form['name']
            print("Adding " + caller['NAME'] + " to blacklist")
            blacklist = Blacklist(get_db(), current_app.config)
            blacklist.add_caller(caller, request.form['reason'])

        elif request.form['action'] == 'RemoveBlock':
            print("Removing " + number + " from blacklist")
            blacklist = Blacklist(get_db(), current_app.config)
            blacklist.remove_number(number)

    # Retrieve the caller information for the given call log entry
    query = """SELECT
      a.CallLogID,
      a.Name,
      a.Number,
      CASE WHEN b.PhoneNo IS NULL THEN 'N' ELSE 'Y' END Whitelisted,
      CASE WHEN c.PhoneNo IS NULL THEN 'N' ELSE 'Y' END Blacklisted,
      CASE WHEN b.PhoneNo IS NOT NULL THEN b.Reason ELSE '' END WhitelistReason,
      CASE WHEN c.PhoneNo IS NOT NULL THEN c.Reason ELSE '' END BlacklistReason
    FROM calllog AS a
    LEFT JOIN whitelist AS b ON a.Number = b.PhoneNo
    LEFT JOIN blacklist AS c ON a.Number = c.PhoneNo
    WHERE a.CallLogID=:call_log_id"""
    arguments = {"call_log_id": call_log_id}
    result_set = screening.utils.query_db(get_db(), query, arguments)
    # Prepare a caller dictionary object for the form
    caller = {}
    if len(result_set) > 0:
        record = result_set[0]
        number = record[2]
        caller.update(
            dict(Call_ID=record[0],
                 Phone_Number='{}-{}-{}'.format(number[0:3], number[3:6],
                                                number[6:]),
                 Name=record[1],
                 Whitelisted=record[3],
                 Blacklisted=record[4],
                 WhitelistReason=record[5],
                 BlacklistReason=record[6]))
    else:
        caller.update(
            dict(Call_ID=call_log_id,
                 Phone_Number='Number Not Found',
                 Name='',
                 Whitelisted='N',
                 Blacklisted='N',
                 WhitelistReason='',
                 BlacklistReason=''))
    return render_template('manage_caller.htm', caller=caller)