Exemple #1
0
def switch_db():
    params = request.args.to_dict()
    params['ekeys'] = sorted(oplog_map.keys())
    p = os.getcwd() + '/..'
    files = [f for f in listdir(p) if isfile(join(p, f))]
    files.sort()
    if 'cmd' not in params.keys():
        curr_file = app.config['SQLALCHEMY_DATABASE_URI'].split('/')[-1]
        return render_template("switch_db.html",
                               params=params,
                               files=files,
                               curr_file=curr_file)
    if params['cmd'] == 'backup':
        t = strftime("%Y-%m-%d_%H%M%S")
        destfile = 'op25-backup-%s.db' % t
        src = app.config['SQLALCHEMY_DATABASE_URI'][10:]
        s = src.split('/')
        curr_file = s[-1]
        dst = src.replace(curr_file, destfile)
        copyfile(src, dst)
        return render_template("switch_db.html",
                               params=params,
                               destfile=destfile,
                               curr_file=curr_file,
                               files=files,
                               sm=1)
    if params['cmd'] == 'switch':
        new_f = params['file']
        database = app.config['SQLALCHEMY_DATABASE_URI']
        f = database.split('/')[-1]
        new_db = database.replace(f, new_f)
        print('switching database to: %s' % new_db)
        app.config['SQLALCHEMY_DATABASE_URI'] = new_db
        return redirect('/')
Exemple #2
0
def edittg():
    params = request.args.to_dict()
    params['ekeys'] = sorted(oplog_map.keys())
    cmd = params['cmd']
    sysid = int(params['sysid'])
    UnitIDTags = column_helper('unit_id_tags')
    TGIDTags = column_helper('tgid_tags')
    SysIDTags = column_helper('sysid_tags')
    if cmd == 'tgid':
        tbl = TGIDTags
    if cmd == 'unit':
        tbl = UnitIDTags
    column_d = {
        'tgid': [
            ColumnDT(TGIDTags.id),
            ColumnDT(TGIDTags.sysid),
            ColumnDT(TGIDTags.rid),
            ColumnDT(TGIDTags.tag),
            ColumnDT(TGIDTags.id)
        ],
        'unit': [
            ColumnDT(UnitIDTags.id),
            ColumnDT(UnitIDTags.sysid),
            ColumnDT(UnitIDTags.rid),
            ColumnDT(UnitIDTags.tag),
            ColumnDT(UnitIDTags.id)
        ]
    }
    q = db.session.query(tbl.id, tbl.sysid, tbl.rid, tbl.tag).order_by(tbl.rid)
    if sysid != 0:
        q = q.filter(tbl.sysid == sysid)
    rowTable = DataTables(params, q, column_d[cmd])
    js = jsonify(rowTable.output_result())
    return js
Exemple #3
0
def logs():
    UnitIDTags = column_helper('unit_id_tags')
    TGIDTags = column_helper('tgid_tags')
    tag = ''
    params = request.args.to_dict()
    params['ekeys'] = oplog_map.keys()
    params['cc_desc'] = cc_desc
    t = None if 'q' not in params.keys() else params['q']
    sysid = 0 if 'sysid' not in params.keys() else int(params['sysid'])
    if sysid != 0:
        if t is not None and params['r'] == 'tgid':
            q = db.session.query(TGIDTags.tag).where(
                and_(TGIDTags.rid == t, TGIDTags.sysid == sysid))
        if t is not None and params['r'] == 'su':
            q = db.session.query(UnitIDTags.tag).where(
                and_(UnitIDTags.rid == t, UnitIDTags.sysid == sysid))
        if q.count() > 0:
            tg = (db.session.execute(q).one())
            tag = (' - %s' % tg.tag)
    if params['r'] == 'cc_event':
        mapl = oplog_map[params['p'].strip()]
        params['ckeys'] = [
            s[1] for s in mapl if s[0] != 'opcode' and s[0] != 'cc_event'
        ]

    return render_template("logs.html", \
        project="logs", \
        params=params, \
        sysList=sysList(), \
        tag=tag )
Exemple #4
0
def edit_tags():
    UnitIDTags = column_helper('unit_id_tags')
    TGIDTags = column_helper('tgid_tags')
    SysIDTags = column_helper('sysid_tags')
    params = request.args.to_dict()
    params['ekeys'] = sorted(oplog_map.keys())
    if 'cmd' not in params.keys():  # render talkgroup by default
        params['cmd'] = 'tgid'
    cmd = params['cmd']
    session['cmd'] = cmd
    systems = db.session.query(SysIDTags.sysid, SysIDTags.tag)
    p = os.getcwd() + '/..'
    tsvs = []
    for root, dirs, files in os.walk(p, topdown=True):
        for file in files:
            if file.endswith(".tsv") and not file.startswith("._"):
                print(os.path.join(root, file))
                tsvs.append(os.path.join(root, file))
    tsvs.sort()
    return render_template("edit_tags.html",
                           params=params,
                           systems=systems,
                           sysList=sysList(),
                           p=p,
                           cmd=cmd,
                           tsvs=tsvs)
Exemple #5
0
def editsys():
    params = request.args.to_dict()
    params['ekeys'] = sorted(oplog_map.keys())
    params['cc_desc'] = cc_desc
    SysIDTags = column_helper('sysid_tags')
    systems = db.session.query(SysIDTags.sysid, SysIDTags.tag)
    return render_template("editsys.html",
                           params=params,
                           systems=systems,
                           sysList=sysList())
Exemple #6
0
def itt():
    params = request.args.to_dict()
    params['ekeys'] = sorted(oplog_map.keys())
    cmd = params['cmd']
    argv = [
        None, 'import_' + cmd,
        os.getcwd() + '/../' + params['file'], params['sysid']
    ]
    session['imp_results'] = import_tsv(argv)
    session['sm'] = 3
    return redirect('/edit_tags?cmd=' + cmd)
Exemple #7
0
def about():
    ds = dbstate()
    if ds is not 0:
        return redirect('error?code=%s' % ds)
    params = request.args.to_dict()
    params['ekeys'] = sorted(oplog_map.keys())
    params['cc_desc'] = cc_desc
    return render_template("about.html",
                           project="op25",
                           params=params,
                           sysList=sysList())
Exemple #8
0
def dtd():
    params = request.args.to_dict()
    params['ekeys'] = sorted(oplog_map.keys())
    cmd = params['cmd']
    UnitIDTags = column_helper('unit_id_tags')
    TGIDTags = column_helper('tgid_tags')
    SysIDTags = column_helper('sysid_tags')
    recId = params['id']
    if cmd == 'tgid':
        tbl = TGIDTags
    if cmd == 'unit':
        tbl = UnitIDTags
    delRec = delete(tbl.table_).where(tbl.id == recId)
    db.session.execute(delRec)
    db.session.commit()
    session['sm'] = 2
    return redirect('/edit_tags?cmd=' + cmd)
Exemple #9
0
def delTags():
    params = request.args.to_dict()
    params['ekeys'] = sorted(oplog_map.keys())
    cmd = params['cmd']
    UnitIDTags = column_helper('unit_id_tags')
    TGIDTags = column_helper('tgid_tags')
    SysIDTags = column_helper('sysid_tags')
    sysid = params['sysid']
    if cmd == 'tgid':
        tbl = TGIDTags
    if cmd == 'unit':
        tbl = UnitIDTags
    delRec = delete(tbl.table_).where(tbl.sysid == sysid)
    db.session.execute(delRec)
    db.session.commit()
    db.session.execute("VACUUM")  # sqlite3 clean up -- reduces file size
    session['sm'] = 4
    return redirect('/edit_tags?cmd=' + cmd)
Exemple #10
0
def purge():
    params = request.args.to_dict()
    params['ekeys'] = sorted(oplog_map.keys())
    DataStore = column_helper('data_store')
    destfile = ''
    b = False
    if 'bu' in params.keys():
        if params['bu'] == 'true':
            b = True
            t = strftime("%Y%m%d_%H%M%S")
            destfile = 'op25-backup-%s.db' % t
            src = app.config['SQLALCHEMY_DATABASE_URI'][10:]
            s = src.split('/')
            f = s[-1]
            dst = src.replace(f, destfile)
    if 'simulate' in params.keys():
        simulate = params['simulate']
    if 'action' in params.keys():
        if params['action'] == 'purge':
            sd = params['sd']
            ed = params['ed']
            sysid = int(params['sysid'])
            delRec = delete(DataStore.table_).where(DataStore.time >= int(sd),
                                                    DataStore.time <= int(ed))
            recCount = db.session.query(DataStore.id).filter(
                and_(DataStore.time >= int(sd), DataStore.time <= int(ed)))
            if sysid != 0:
                recCount = recCount.filter(DataStore.sysid == sysid)
                delRec = delRec.where(DataStore.sysid == sysid)
            if 'kv' in params.keys():  # keep voice calls
                if params['kv'] == 'true':
                    recCount = recCount.where(
                        and_(DataStore.opcode != 0, DataStore.opcode != 2))
                    delRec = delRec.where(
                        and_(DataStore.opcode != 0, DataStore.opcode != 2))
            recCount = recCount.count()
            dispQuery = delRec.compile(compile_kwargs={"literal_binds": True})
            if simulate == 'false':
                if b == True:
                    copyfile(src, dst)
                db.session.execute(delRec)
                db.session.commit()
                db.session.execute(
                    "VACUUM")  # sqlite3 clean up -- reduces file size
                successMessage = 1
            else:
                successMessage = 2
    else:
        recCount = 0
        successMessage = 0
        dispQuery = ''

    return render_template("purge.html", \
        project="op25", \
        params=params, \
        dbstats=dbStats(), \
        sysList=sysList(), \
        successMessage=successMessage, \
        recCount=recCount, \
        dispQuery=dispQuery, \
        destfile=destfile )