예제 #1
0
def edit_failure(request=request):
    #Check response for referrer and return redirect page
    #We want to send user back to the page they got here from to retry
    try:
        errcode = int(request.args.get('code'))
        errstr = inventory_viewer.err_registry[errcode].message
    except:
        if inventory_live_data.get_lockout_state():
            errcode = 16
            errstr = inventory_viewer.err_registry[errcode].message
        else:
            errcode = -1
            errstr = "Undefined"
    linv.log_dest.error("Returning fail page " + errstr)

    new_url = str(request.referrer)
    url_info = ih.parse_edit_url(new_url)

    bread = [['⌂', url_for('index')],
             [url_pref.strip('/'),
              url_for('inventory_app.show_edit_root')]]
    mess = "Error " + str(errcode) + ": (" + str(dt.now().strftime(
        '%d/%m/%y %H:%M:%S')) + ") " + errstr + " for " + url_info[
            'db_name'] + "." + url_info['collection_name']
    return render_template('edit_failure.html',
                           new_url=new_url,
                           message=mess,
                           submit_contact=linv.email_contact,
                           bread=bread)
예제 #2
0
def show_edit_root():
    try:
        listing = inventory_viewer.get_edit_list()
        lockout = inventory_live_data.get_lockout_state()
    except ih.ConnectOrAuthFail as e:
        linv.log_dest.error("Returning auth fail page")

        new_url = str(request.referrer)

        bread = [['⌂', url_for('index')],
                 [
                     url_pref.strip('/'),
                     url_for('inventory_app.show_edit_root')
                 ]]
        mess = "Connect or Auth failure: (" + str(
            dt.now().strftime('%d/%m/%y %H:%M:%S')) + ") " + e.message
        return render_template('edit_authfail.html',
                               new_url=new_url,
                               message=mess,
                               submit_contact=linv.email_contact,
                               bread=bread)

    return render_template(
        'edit_show_list.html',
        db_name=None,
        nice_name=None,
        listing=listing,
        lockout=lockout,
        bread=[['⌂', url_for('index')],
               [url_pref.strip('/'),
                url_for('inventory_app.show_edit_root')]])
예제 #3
0
def report_connection(idb, inv_db):
    """Check connection, check is inventory, check inventory is as expected
    """

    roles = idb['admin'].command(SON({"connectionStatus":int(1)}))
    can_write = 'readWrite' in [el['role'] for el in roles['authInfo']['authenticatedUserRoles'] if el['db']=='inventory']
    inv_ok = inv.validate_mongodb(inv_db)
    lockout = get_lockout_state()
    return {'can_write':can_write, 'inv_ok': inv_ok, 'global_lock':lockout}
예제 #4
0
def report_connection():
    """Check connection, check is inventory, check inventory is as expected
    """
    # TODO fix this, when recreate scraper
    #    roles = idb['admin'].command(SON({"connectionStatus":int(1)}))
    #    can_write = 'readWrite' in [el['role'] for el in roles['authInfo']['authenticatedUserRoles'] if el['db']=='inventory']
    #    inv_ok = ??
    lockout = get_lockout_state()
    can_write = False
    inv_ok = False
    lockout = False
    return {'can_write': can_write, 'inv_ok': inv_ok, 'global_lock': lockout}
예제 #5
0
def show_edit_inventory(id, id2):
    try:
        valid = inventory_viewer.is_valid_db_table(id, id2)
        if not valid:
            raise BadNameError('')
        locked = inventory_live_data.get_lockout_state()
    except BadNameError:
        return render_template('edit_bad_name.html', db_name=id, table_name=id2, bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')],[id, url_for('inventory_app.show_edit_child', id=id)], [id2, url_for('inventory_app.show_edit_inventory', id=id, id2=id2)]])
    bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')], [id, url_for('inventory_app.show_edit_child', id=id)], [id2, url_for('inventory_app.show_inventory', id=id, id2=id2)], ['edit', url_for('inventory_app.show_edit_inventory', id=id, id2=id2)]]
    if locked:
        return render_template('edit_locked.html')
    else:
        return render_template('edit_inventory.html', db_name=id, table_name=id2, type_data=linv.get_type_strings_as_json(), bread=bread, table_fields=linv.display_field_order())
예제 #6
0
def show_edit_root():
    try:
        listing = inventory_viewer.retrieve_db_listing()
        lockout = inventory_live_data.get_lockout_state()
    except ih.ConnectOrAuthFail as e:
        linv.log_dest.error("Returning auth fail page")

        new_url = str(request.referrer)

        bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')]]
        mess = "Connect or Auth failure: ("+str(dt.now().strftime('%d/%m/%y %H:%M:%S'))+") "+e.message
        return render_template('edit_authfail.html', new_url=new_url, message = mess, submit_contact=linv.email_contact, bread=bread)

    return render_template('edit_show_list.html', db_name = None, nice_name=None, listing=listing, lockout=lockout, bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')]])
예제 #7
0
def show_edit_records(id, id2):
    try:
        valid = inventory_viewer.is_valid_db_collection(id, id2)
        if not valid:
            raise BadNameError('')
        locked = inventory_live_data.get_lockout_state()
    except BadNameError:
        return render_template('edit_bad_name.html', db_name=id, coll_name=id2, bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')],[id, url_for('inventory_app.show_edit_child', id=id)], [id2, url_for('inventory_app.show_edit_records', id=id, id2=id2)]])
    bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')], [id, url_for('inventory_app.show_edit_child', id=id)], [id2, url_for('inventory_app.show_inventory', id=id, id2=id2)], ['records', url_for('inventory_app.show_records', id=id, id2=id2)], ['edit', url_for('inventory_app.show_edit_records', id=id, id2=id2)]]
    nice_name = inventory_viewer.get_nicename(db_name = id, collection_name = id2)
    if locked:
        return render_template('edit_locked.html')
    else:
        return render_template('edit_records.html', db_name=id, collection_name=id2, type_data=linv.get_type_strings_as_json(), record_fields=linv.record_field_order(), bread=bread, nice_name =nice_name, record_noedit=linv.record_noeditable())
예제 #8
0
def check_locks(resp):
    """Check if request pertains to locked coll
    or editing is locked globally
    """
    if get_lockout_state():
        raise EditLockError('Global Edit Lock')
    try:
        db_name = resp['db']
        coll_name = resp['collection']
        db_id = idc.get_db_id(db_name)
        coll_id = idc.get_coll_id(db_id['id'], coll_name)
        if check_locked(coll_id['id']):
            raise EditLockError('Collection locked')
    except Exception as e:
        raise e
예제 #9
0
def check_locks(resp):
    """Check if request pertains to locked table
    or editing is locked globally
    """
    if get_lockout_state():
        raise EditLockError('Global Edit Lock')
    try:
        #db_name = resp['db']
        table_name = resp['table']
        #db_id = idc.get_db_id(db_name)
        table_id = idc.get_table_id(table_name)
        if check_locked(table_id):
            raise EditLockError('Table locked')
    except Exception as e:
        inv.log_dest.error("Error in locking "+str(e))
        raise e
예제 #10
0
def check_locks(resp):
    """Check if request pertains to locked table
    or editing is locked globally
    """
    if get_lockout_state():
        raise EditLockError('Global Edit Lock')
    try:
        #db_name = resp['db']
        table_name = resp['table']
        #db_id = idc.get_db_id(db_name)
        table_id = idc.get_table_id(table_name)
        if check_locked(table_id):
            raise EditLockError('Table locked')
    except Exception as e:
        inv.log_dest.error("Error in locking "+str(e))
        raise e
예제 #11
0
def show_edit_records(id, id2):
    try:
        valid = inventory_viewer.is_valid_db_collection(id, id2)
        if not valid:
            raise BadNameError('')
        locked = inventory_live_data.get_lockout_state()
    except BadNameError:
        return render_template(
            'edit_bad_name.html',
            db_name=id,
            coll_name=id2,
            bread=[['⌂', url_for('index')],
                   [
                       url_pref.strip('/'),
                       url_for('inventory_app.show_edit_root')
                   ], [id, url_for('inventory_app.show_edit_child', id=id)],
                   [
                       id2,
                       url_for('inventory_app.show_edit_records',
                               id=id,
                               id2=id2)
                   ]])
    bread = [
        ['⌂', url_for('index')],
        [url_pref.strip('/'),
         url_for('inventory_app.show_edit_root')],
        [id, url_for('inventory_app.show_edit_child', id=id)],
        [id2, url_for('inventory_app.show_inventory', id=id, id2=id2)],
        ['records',
         url_for('inventory_app.show_records', id=id, id2=id2)],
        ['edit',
         url_for('inventory_app.show_edit_records', id=id, id2=id2)]
    ]
    nice_name = inventory_viewer.get_nicename(db_name=id, collection_name=id2)
    if locked:
        return render_template('edit_locked.html')
    else:
        return render_template('edit_records.html',
                               db_name=id,
                               collection_name=id2,
                               type_data=linv.get_type_strings_as_json(),
                               record_fields=linv.record_field_order(),
                               bread=bread,
                               nice_name=nice_name,
                               record_noedit=linv.record_noeditable())
예제 #12
0
def show_edit_child(id):
    try:
        valid = inventory_viewer.is_valid_db(id)
        if not valid:
            raise BadNameError('')
        nice_name = inventory_viewer.get_nicename(db_name=id,
                                                  collection_name=None)
        listing = inventory_viewer.get_edit_list(id)
        lockout = inventory_live_data.get_lockout_state()
    except BadNameError as e:
        return render_template(
            'edit_bad_name.html',
            db_name=id,
            coll_name=None,
            bread=[['⌂', url_for('index')],
                   [
                       url_pref.strip('/'),
                       url_for('inventory_app.show_edit_root')
                   ], [id, url_for('inventory_app.show_edit_child', id=id)]])
    except ih.ConnectOrAuthFail as e:
        linv.log_dest.error("Returning auth fail page")
        new_url = str(request.referrer)
        bread = [['⌂', url_for('index')],
                 [
                     url_pref.strip('/'),
                     url_for('inventory_app.show_edit_root')
                 ]]
        mess = "Connect or Auth failure: (" + str(
            dt.now().strftime('%d/%m/%y %H:%M:%S')) + ") " + e.message
        return render_template('edit_authfail.html',
                               new_url=new_url,
                               message=mess,
                               submit_contact=linv.email_contact,
                               bread=bread)

    return render_template(
        'edit_show_list.html',
        db_name=id,
        nice_name=nice_name,
        listing=listing,
        lockout=lockout,
        bread=[['⌂', url_for('index')],
               [url_pref.strip('/'),
                url_for('inventory_app.show_edit_root')],
               [id, url_for('inventory_app.show_edit_child', id=id)]])
예제 #13
0
def show_edit_child(id):
    try:
        valid = inventory_viewer.is_valid_db(id)
        if not valid:
            raise BadNameError('')
        nice_name = inventory_viewer.get_nicename(db_name = id, table_name = None)
        listing = inventory_viewer.retrieve_db_listing(id)
        lockout = inventory_live_data.get_lockout_state()
    except BadNameError as e:
        return render_template('edit_bad_name.html', db_name=id, table_name=None, bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')],[id, url_for('inventory_app.show_edit_child', id=id)]])
    except ih.ConnectOrAuthFail as e:
        linv.log_dest.error("Returning auth fail page")
        new_url = str(request.referrer)
        bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')]]
        mess = "Connect or Auth failure: ("+str(dt.now().strftime('%d/%m/%y %H:%M:%S'))+") "+e.message
        return render_template('edit_authfail.html', new_url=new_url, message = mess, submit_contact=linv.email_contact, bread=bread)

    return render_template('edit_show_list.html', db_name=id, nice_name=nice_name, listing=listing, lockout=lockout, bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')],[id, url_for('inventory_app.show_edit_child', id=id)]])
예제 #14
0
def show_edit_inventory(id, id2):
    try:
        valid = inventory_viewer.is_valid_db_table(id, id2)
        if not valid:
            raise BadNameError('')
        locked = inventory_live_data.get_lockout_state()
    except BadNameError:
        return render_template(
            'edit_bad_name.html',
            db_name=id,
            table_name=id2,
            bread=[['⌂', url_for('index')],
                   [
                       url_pref.strip('/'),
                       url_for('inventory_app.show_edit_root')
                   ], [id, url_for('inventory_app.show_edit_child', id=id)],
                   [
                       id2,
                       url_for('inventory_app.show_edit_inventory',
                               id=id,
                               id2=id2)
                   ]])
    bread = [['⌂', url_for('index')],
             [url_pref.strip('/'),
              url_for('inventory_app.show_edit_root')],
             [id, url_for('inventory_app.show_edit_child', id=id)],
             [id2,
              url_for('inventory_app.show_inventory', id=id, id2=id2)],
             [
                 'edit',
                 url_for('inventory_app.show_edit_inventory', id=id, id2=id2)
             ]]
    if locked:
        return render_template('edit_locked.html')
    else:
        return render_template('edit_inventory.html',
                               db_name=id,
                               table_name=id2,
                               type_data=linv.get_type_strings_as_json(),
                               bread=bread,
                               table_fields=linv.display_field_order())
예제 #15
0
def check_locks(resp):
    """Check if request pertains to locked coll
    or editing is locked globally
    """
    inv.setup_internal_client()
    try:
        db = inv.int_client[inv.ALL_STRUC.name]
    except Exception:
        raise ih.ConnectOrAuthFail("")
    if get_lockout_state():
        raise EditLockError('Global Edit Lock')
    try:
        db_name = resp['db']
        coll_name = resp['collection']
        db_id = idc.get_db_id(db, db_name)
        coll_id = idc.get_coll_id(db, db_id['id'], coll_name)
        if check_locked(db, coll_id['id']):
            raise EditLockError('Collection locked')
    except Exception as e:
        inv.log_dest.error("Error in locking "+str(e))
        raise e
예제 #16
0
def edit_failure(request=request):
    #Check response for referrer and return redirect page
    #We want to send user back to the page they got here from to retry
    try:
        errcode = int(request.args.get('code'))
        errstr = inventory_viewer.err_registry[errcode].message
    except:
        if inventory_live_data.get_lockout_state():
            errcode = 16
            errstr = inventory_viewer.err_registry[errcode].message
        else:
            errcode = -1
            errstr = "Undefined"
    linv.log_dest.error("Returning fail page "+ errstr)

    new_url = str(request.referrer)
    url_info = ih.parse_edit_url(new_url)

    bread=[['⌂', url_for('index')],[url_pref.strip('/'), url_for('inventory_app.show_edit_root')]]
    mess = "Error "+str(errcode)+": ("+str(dt.now().strftime('%d/%m/%y %H:%M:%S'))+") "+errstr+" for "+url_info['db_name']+"."+url_info['table_name']
    return render_template('edit_failure.html', new_url=new_url, message = mess, submit_contact=linv.email_contact, bread=bread)
예제 #17
0
def check_locks(resp):
    """Check if request pertains to locked coll
    or editing is locked globally
    """
    inv.setup_internal_client()
    try:
        db = inv.int_client[inv.ALL_STRUC.name]
    except Exception:
        raise ih.ConnectOrAuthFail("")
    if get_lockout_state():
        raise EditLockError('Global Edit Lock')
    try:
        db_name = resp['db']
        coll_name = resp['collection']
        db_id = idc.get_db_id(db, db_name)
        coll_id = idc.get_coll_id(db, db_id['id'], coll_name)
        if check_locked(db, coll_id['id']):
            raise EditLockError('Collection locked')
    except Exception as e:
        inv.log_dest.error("Error in locking " + str(e))
        raise e
예제 #18
0
def report_connection():
    """Check connection, check is inventory, check inventory is as expected
    """
    can_write = not db._read_only
    lockout = get_lockout_state()
    return {'can_write':can_write, 'global_lock':lockout}