Ejemplo n.º 1
0
def applyFilterOnCase(caseName, newFilter, mode = "edit", start = '', end = ''):
    syslog.syslog("PCAP APP: applyFilterOnCase: "+caseName+" started: "+str(datetime.datetime.now()))
    IDs = SQLHelper.getCaseAndFilterIDs(caseName)
    if IDs is None:
        return
    caseID = IDs[0]
    filterID = IDs[1]
    conn = sqlite3.connect(DATABASE)
    conn.execute('pragma foreign_keys=ON')
    if mode == "edit":
        if filterID:
            q = conn.execute("UPDATE FILTERS SET CONTENT = ?, START_DATETIME = ?, END_DATETIME = ? WHERE FILTERS.ID = ?", (newFilter, start, end, filterID,))
            #q = conn.execute("UPDATE FILTERS SET CONTENT = \'"+newFilter+"\', START_DATETIME = \'"+start+"\', end_DATETIME = \'"+end+"\' WHERE FILTERS.ID = "+str(filterID))
        else:
            q = conn.execute("INSERT INTO FILTERS VALUES(null, ?, ?, ?)",(newFilter, start, end,))
            q = conn.execute('SELECT max(ID) FROM FILTERS')
            filterID = q.fetchone()[0]
            q = conn.execute("UPDATE CASES SET FILTERID = ? WHERE CASES.ID = ?", (filterID, caseID))
        q = conn.execute("SELECT FILENAME FROM FILES WHERE FILES.TYPE = ? AND FILES.CASEID = ?", ('origin', caseID,))
    else:
        #q = conn.execute("SELECT CONTENT FROM FILTERS WHERE FILTERS.ID = ?", (filterID,))
        #currentFilter = q.fetchone()
        #currentFilter = currentFilter[0]
        #if newFilter:
        #        newFilter = currentFilter + " && " + newFilter if currentFilter else newFilter
        #else:
        #newFilter = currentFilter
        q = conn.execute("UPDATE FILTERS SET CONTENT = ?, START_DATETIME = ?, end_DATETIME = ? WHERE FILTERS.ID = ?", (newFilter, start, end, filterID,))
        q = conn.execute("SELECT FILENAME FROM FILES WHERE FILES.TYPE = ? AND FILES.CASEID = ?", ('filtered', caseID))
    files = []
    for row in q:
        files.append(CASES_DIR + caseName + PCAP_DIR + row[0])
    conn.commit()
    conn.close()
    for file in files:
        filteredFileName = applyFilterOnFile(file, newFilter, caseName, override = True)
        if not os.path.isfile(CASES_DIR + caseName + PCAP_DIR + filteredFileName):
            f = open(CASES_DIR + caseName + PCAP_DIR + filteredFileName, 'w')
            f.write("")
            f.close()
        if mode == "append":
            os.rename(CASES_DIR + caseName + PCAP_DIR + filteredFileName, file)
            filteredFileName = os.path.basename(file)
        applyTimeFilterOnFile(CASES_DIR + caseName + PCAP_DIR + filteredFileName, caseName, start, end, override = True)
        helper.updateFile(CASES_DIR + caseName + PCAP_DIR + filteredFileName, caseName, filterID)
    helper.clearTmp(caseName)
    syslog.syslog("PCAP APP: applyFilterOnCase: "+caseName+"   ended: "+str(datetime.datetime.now()))
Ejemplo n.º 2
0
    if start and end:
        ret = Filter.applyTimeFilterOnFile(form['filePath'].value, caseName, start, end, override = False)
        form['filePath'].value = ret


if "uploadFile" in actions:
    if form.has_key('caseName') and form.has_key('uploadFileItem'):
        ret = saveFile.saveFile(form['caseName'].value, form['uploadFileItem'])
        message = ret[0]
        messageType = ret[1]
    else:
        message = "You have to choose a file."

if "deleteFile" in actions:
    if form.has_key('clearTmp'):
        helper.clearTmp(form['caseName'].value)
        pagesToRender = ['case','saveFile']
        message = "<strong>Success!</strong> All temporary files was deleted."
        messageType = "success"
if "editDescription" in actions:
    if form.has_key('Edit'):
        helper.updateFileDescription(form['filePath'].value, form['caseName'].value, form['description'].value)

# generate begining of html
print "Content-Type: text/html\n\n"
print genBegining('Main')

# begining of render section
print '<div class="alert alert-'+messageType+'">'+message+'</div>' if message else ""
print '<div class="row">\n'
print '<div class="col-md-12">'
Ejemplo n.º 3
0
def applyFilterOnCase(caseName, newFilter, mode="edit", start='', end=''):
    syslog.syslog("PCAP APP: applyFilterOnCase: " + caseName + " started: " +
                  str(datetime.datetime.now()))
    IDs = SQLHelper.getCaseAndFilterIDs(caseName)
    if IDs is None:
        return
    caseID = IDs[0]
    filterID = IDs[1]
    conn = sqlite3.connect(DATABASE)
    conn.execute('pragma foreign_keys=ON')
    if mode == "edit":
        if filterID:
            q = conn.execute(
                "UPDATE FILTERS SET CONTENT = ?, START_DATETIME = ?, END_DATETIME = ? WHERE FILTERS.ID = ?",
                (
                    newFilter,
                    start,
                    end,
                    filterID,
                ))
            #q = conn.execute("UPDATE FILTERS SET CONTENT = \'"+newFilter+"\', START_DATETIME = \'"+start+"\', end_DATETIME = \'"+end+"\' WHERE FILTERS.ID = "+str(filterID))
        else:
            q = conn.execute("INSERT INTO FILTERS VALUES(null, ?, ?, ?)", (
                newFilter,
                start,
                end,
            ))
            q = conn.execute('SELECT max(ID) FROM FILTERS')
            filterID = q.fetchone()[0]
            q = conn.execute(
                "UPDATE CASES SET FILTERID = ? WHERE CASES.ID = ?",
                (filterID, caseID))
        q = conn.execute(
            "SELECT FILENAME FROM FILES WHERE FILES.TYPE = ? AND FILES.CASEID = ?",
            (
                'origin',
                caseID,
            ))
    else:
        #q = conn.execute("SELECT CONTENT FROM FILTERS WHERE FILTERS.ID = ?", (filterID,))
        #currentFilter = q.fetchone()
        #currentFilter = currentFilter[0]
        #if newFilter:
        #        newFilter = currentFilter + " && " + newFilter if currentFilter else newFilter
        #else:
        #newFilter = currentFilter
        q = conn.execute(
            "UPDATE FILTERS SET CONTENT = ?, START_DATETIME = ?, end_DATETIME = ? WHERE FILTERS.ID = ?",
            (
                newFilter,
                start,
                end,
                filterID,
            ))
        q = conn.execute(
            "SELECT FILENAME FROM FILES WHERE FILES.TYPE = ? AND FILES.CASEID = ?",
            ('filtered', caseID))
    files = []
    for row in q:
        files.append(CASES_DIR + caseName + PCAP_DIR + row[0])
    conn.commit()
    conn.close()
    for file in files:
        filteredFileName = applyFilterOnFile(file,
                                             newFilter,
                                             caseName,
                                             override=True)
        if not os.path.isfile(CASES_DIR + caseName + PCAP_DIR +
                              filteredFileName):
            f = open(CASES_DIR + caseName + PCAP_DIR + filteredFileName, 'w')
            f.write("")
            f.close()
        if mode == "append":
            os.rename(CASES_DIR + caseName + PCAP_DIR + filteredFileName, file)
            filteredFileName = os.path.basename(file)
        applyTimeFilterOnFile(CASES_DIR + caseName + PCAP_DIR +
                              filteredFileName,
                              caseName,
                              start,
                              end,
                              override=True)
        helper.updateFile(CASES_DIR + caseName + PCAP_DIR + filteredFileName,
                          caseName, filterID)
    helper.clearTmp(caseName)
    syslog.syslog("PCAP APP: applyFilterOnCase: " + caseName + "   ended: " +
                  str(datetime.datetime.now()))