Exemple #1
0
def applyTmpFilter(filePath, filterContent, caseName):
    currentFilter = helper.getFilter(caseName, helper.getDBNameFromPath(filePath), type = 'file')
    filteredFileName = applyFilterOnFile(filePath, filterContent, caseName, True)
    if not os.path.isfile(CASES_DIR + caseName + TMP_DIR + filteredFileName):
        return None
    summFilter = currentFilter + ' && ' + filterContent if currentFilter != 'None' else filterContent
    conn = sqlite3.connect(DATABASE)
    conn.execute('pragma foreign_keys=ON')
    # crete new fitler in db
    conn.execute("INSERT INTO FILTERS VALUES(null, ?, \'\', \'\')",(summFilter,))
    q = conn.execute('SELECT max(ID) FROM FILTERS')
    filterID = q.fetchone()[0]
    q = conn.execute("SELECT ID FROM CASES WHERE CASES.NAME = ?",(caseName,))
    IDs = q.fetchone()
    caseID = IDs[0]
    if SQLHelper.getFileID(helper.getDBNameFromPath(CASES_DIR + caseName + TMP_DIR + filteredFileName), caseName) is not None:
        conn.commit()
        conn.close()
        helper.updateFile(CASES_DIR + caseName + TMP_DIR + filteredFileName, caseName, filterID)
    else:
        sourceFile = helper.getDBNameFromPath(filePath)
        fileSize = os.path.getsize(CASES_DIR + caseName + TMP_DIR + filteredFileName)
        dateTimes = helper.getDateTimeFromFile(CASES_DIR + caseName + TMP_DIR + filteredFileName)
        conn.execute("INSERT INTO FILES VALUES (null, ?, ?, ?, ?, ?, ?, ?, ?, ?)", ("tmp/"+filteredFileName, "tmp", caseID, filterID, fileSize, dateTimes[0], dateTimes[1], sourceFile,'description',))
        #conn.execute("INSERT INTO FILES VALUES (null,\'"+"tmp/"+filteredFileName+"\',\'tmp\',"+str(caseID)+","+str(filterID)+","+str(fileSize)+",\'"+dateTimes[0]+"\',\'"+ dateTimes[1]+"\',\'"+sourceFile+"\')")
        conn.commit()
        conn.close()
    return filteredFileName
Exemple #2
0
def applyTimeFilterOnFile(filePath, caseName, start = '', end = '', override = False):
    syslog.syslog("PCAP APP: applyTimeFilterOnFile: "+filePath+" started: "+str(datetime.datetime.now()))
    if start == '' and end == '':
        return None
    tmpF = tempfile.NamedTemporaryFile(delete=True)
    outputFileName = os.path.basename(tmpF.name + '.pcap') 
    outputFilePath = CASES_DIR + caseName + TMP_DIR + outputFileName
    subprocess.call(['editcap','-A', start, '-B',end, filePath,outputFilePath])
    if not os.path.isfile(outputFilePath):
        return None
    if override:
        os.rename(outputFilePath, filePath)
        outputFilePath = filePath
        outputFileName = helper.getDBNameFromPath(filePath)
    conn = sqlite3.connect(DATABASE)
    conn.execute('pragma foreign_keys=ON')
    # crete new fitler in db
    q = conn.execute("SELECT ID FROM CASES WHERE CASES.NAME = ?", (caseName,))
    IDs = q.fetchone()
    caseID = IDs[0]
    if SQLHelper.getFileID(helper.getDBNameFromPath(outputFilePath), caseName) is not None:
        conn.commit()
        conn.close()
        helper.updateFile(outputFilePath, caseName, 'null')
    else:
        sourceFile = helper.getDBNameFromPath(filePath)
        fileSize = os.path.getsize(outputFilePath)
        dateTimes = helper.getDateTimeFromFile(outputFilePath)
        conn.execute("INSERT INTO FILES VALUES (null, ?, ?, ?, null, ?, ?, ?, ?, ?)", ("tmp/"+outputFileName, "tmp", caseID, fileSize, dateTimes[0], dateTimes[1], sourceFile,'description',))
#        conn.execute("INSERT INTO FILES VALUES (null,\'"+"tmp/"+outputFileName+"\',\'tmp\',"+str(caseID)+",null,"+str(fileSize)+",\'"+dateTimes[0]+"\',\'"+ dateTimes[1]+"\',\'"+sourceFile+"\')")
        conn.commit()
        conn.close()
    syslog.syslog("PCAP APP: applyTimeFilterOnFile: "+filePath+"   ended: "+str(datetime.datetime.now()))
    return outputFilePath
Exemple #3
0
def applyTimeFilterOnFile(filePath,
                          caseName,
                          start='',
                          end='',
                          override=False):
    syslog.syslog("PCAP APP: applyTimeFilterOnFile: " + filePath +
                  " started: " + str(datetime.datetime.now()))
    if start == '' and end == '':
        return None
    tmpF = tempfile.NamedTemporaryFile(delete=True)
    outputFileName = os.path.basename(tmpF.name + '.pcap')
    outputFilePath = CASES_DIR + caseName + TMP_DIR + outputFileName
    subprocess.call(
        ['editcap', '-A', start, '-B', end, filePath, outputFilePath])
    if not os.path.isfile(outputFilePath):
        return None
    if override:
        os.rename(outputFilePath, filePath)
        outputFilePath = filePath
        outputFileName = helper.getDBNameFromPath(filePath)
    conn = sqlite3.connect(DATABASE)
    conn.execute('pragma foreign_keys=ON')
    # crete new fitler in db
    q = conn.execute("SELECT ID FROM CASES WHERE CASES.NAME = ?", (caseName, ))
    IDs = q.fetchone()
    caseID = IDs[0]
    if SQLHelper.getFileID(helper.getDBNameFromPath(outputFilePath),
                           caseName) is not None:
        conn.commit()
        conn.close()
        helper.updateFile(outputFilePath, caseName, 'null')
    else:
        sourceFile = helper.getDBNameFromPath(filePath)
        fileSize = os.path.getsize(outputFilePath)
        dateTimes = helper.getDateTimeFromFile(outputFilePath)
        conn.execute(
            "INSERT INTO FILES VALUES (null, ?, ?, ?, null, ?, ?, ?, ?, ?)", (
                "tmp/" + outputFileName,
                "tmp",
                caseID,
                fileSize,
                dateTimes[0],
                dateTimes[1],
                sourceFile,
                'description',
            ))
        #        conn.execute("INSERT INTO FILES VALUES (null,\'"+"tmp/"+outputFileName+"\',\'tmp\',"+str(caseID)+",null,"+str(fileSize)+",\'"+dateTimes[0]+"\',\'"+ dateTimes[1]+"\',\'"+sourceFile+"\')")
        conn.commit()
        conn.close()
    syslog.syslog("PCAP APP: applyTimeFilterOnFile: " + filePath +
                  "   ended: " + str(datetime.datetime.now()))
    return outputFilePath
Exemple #4
0
def applyTmpFilter(filePath, filterContent, caseName):
    currentFilter = helper.getFilter(caseName,
                                     helper.getDBNameFromPath(filePath),
                                     type='file')
    filteredFileName = applyFilterOnFile(filePath, filterContent, caseName,
                                         True)
    if not os.path.isfile(CASES_DIR + caseName + TMP_DIR + filteredFileName):
        return None
    summFilter = currentFilter + ' && ' + filterContent if currentFilter != 'None' else filterContent
    conn = sqlite3.connect(DATABASE)
    conn.execute('pragma foreign_keys=ON')
    # crete new fitler in db
    conn.execute("INSERT INTO FILTERS VALUES(null, ?, \'\', \'\')",
                 (summFilter, ))
    q = conn.execute('SELECT max(ID) FROM FILTERS')
    filterID = q.fetchone()[0]
    q = conn.execute("SELECT ID FROM CASES WHERE CASES.NAME = ?", (caseName, ))
    IDs = q.fetchone()
    caseID = IDs[0]
    if SQLHelper.getFileID(
            helper.getDBNameFromPath(CASES_DIR + caseName + TMP_DIR +
                                     filteredFileName), caseName) is not None:
        conn.commit()
        conn.close()
        helper.updateFile(CASES_DIR + caseName + TMP_DIR + filteredFileName,
                          caseName, filterID)
    else:
        sourceFile = helper.getDBNameFromPath(filePath)
        fileSize = os.path.getsize(CASES_DIR + caseName + TMP_DIR +
                                   filteredFileName)
        dateTimes = helper.getDateTimeFromFile(CASES_DIR + caseName + TMP_DIR +
                                               filteredFileName)
        conn.execute(
            "INSERT INTO FILES VALUES (null, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (
                "tmp/" + filteredFileName,
                "tmp",
                caseID,
                filterID,
                fileSize,
                dateTimes[0],
                dateTimes[1],
                sourceFile,
                'description',
            ))
        #conn.execute("INSERT INTO FILES VALUES (null,\'"+"tmp/"+filteredFileName+"\',\'tmp\',"+str(caseID)+","+str(filterID)+","+str(fileSize)+",\'"+dateTimes[0]+"\',\'"+ dateTimes[1]+"\',\'"+sourceFile+"\')")
        conn.commit()
        conn.close()
    return filteredFileName
def printCurrentFile(filePath):
    print '<h1>'+helper.getDBNameFromPath(filePath)+'</h1>'
def printInputFilterForm(filePath, caseName):
    info = helper.getReadableFileInfo(helper.getDBNameFromPath(filePath), caseName)
    approximateTime = helper.getRenderGraphTime(os.path.getsize(filePath))
    title = 'Approximate time to render graph is: ' + helper.getReadableTimeInfo(approximateTime)
    originFiles = SQLHelper.loadFiles(caseName, 'origin')
    filteredFiles = SQLHelper.loadFiles(caseName, 'filtered')
    tmpFiles = SQLHelper.loadFiles(caseName, 'tmp')
    filesApproxStr = generateFilesAproximateTimeString(originFiles, caseName)
    filesApproxStr += generateFilesAproximateTimeString(filteredFiles, caseName)
    filesApproxStr += generateFilesAproximateTimeString(tmpFiles, caseName)
    options = '<optgroup label="Original files">'
    for file in originFiles:
        options += '  <option value="'+file+'">'+file+'</option>'
    options += '</optgroup>'
    options += '<option data-divider="true"></option>'
    options += '<optgroup label="Filtered files">'
    for file in filteredFiles:
        options += '  <option value="'+file+'">'+file+'</option>'
    options += '</optgroup>'
    options += '<option data-divider="true"></option>'
    options += '<optgroup label="Temporary files">'
    for file in tmpFiles:
        options += '  <option value="'+file+'">'+file+'</option>'
    allFiles = originFiles + filteredFiles + tmpFiles
    table = '<div id="files" class="collapse">'
    table += '<table id="" class="display" cellspacing="0" width="100%">'
    table += '<thead><tr><th>ID</th><th>Name</th><th>Size</th><th>First Packet</th><th>Last Packet</th><th>Filter</th><th>Source File</th><th>Description</th></tr><tbody>'
    for file in allFiles:
        info = helper.getReadableFileInfo(file, caseName)
        sourceID = str(SQLHelper.getFileID(info[4],caseName)) + '.' if str(SQLHelper.getFileID(info[4],caseName)) != 'None' else ''
        table += '<tr><th>%s</th><th><div class="checkbox"><label><input type="checkbox" value="%s" name="additionalFiles" id="additionalFiles"><b>%s</b></label></div> </th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>' % (str(info[6]), file, file, info[1], info[2], info[3], info[0], sourceID + info[4], info[5])
    table += '</tbody></table></div>'
    info = helper.getReadableFileInfo(helper.getDBNameFromPath(filePath), caseName)
    options += '</optgroup>'
    print '<h2>File Details</h2>'
    formStr = '<form action="main.py" class="form-horizontal" method="post">'
    formStr += '<div class="form-group"><label class="col-md-2">Current filter on File:</label>'
    formStr += '<p class="col-md-10 form-control-static">'+info[0]+'</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Size:</label>'
    formStr += '<p class="col-md-10 form-control-static">'+info[1]+'</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">First Packet:</label>'
    formStr += '<p class="col-md-10 form-control-static">'+info[2]+'</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Last Packet:</label>'
    formStr += '<p class="col-md-10 form-control-static">'+info[3]+'</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Source File:</label>'
    formStr += '<p class="col-md-10 form-control-static">'+info[4]+'</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Description:</label>'
    formStr += '<div class="col-md-4"><input type="text" class="form-control" name="description"value="%s" /></div>' % info[5]
    formStr += '<input type="hidden" name="pagesToRender" value="showFile">'
    formStr += '<input type="hidden" name="caseName" value="'+caseName+'"/>'
    formStr += '<input type="hidden" name="filePath" value="'+filePath+'"/>'
    formStr += '<input type="hidden" name="actions" value="editDescription"/>'
    formStr += '<input type="submit" class="btn btn-default" value="Edit" name="Edit"/></div></form>'

    formStr += '<h2>Graph settings</h2>'
    formStr += '<form action="main.py" class="form-horizontal" method="post">'
    formStr += '<div class="form-group"><label class="col-md-2">Time window:</label>'
    formStr += '<div class="col-md-2"><label>From:</label><input type="text" title="Enter date and time in format: YYYY-MM-DD HH:MM:SS" class="form-control" value="%s"name="start"/></div>' % (info[2])
    formStr += '<div class="col-md-2"><label>To:</label><input type="text" title="Enter date and time in format: YYYY-MM-DD HH:MM:SS" class="form-control" value="%s"name="end"/></div><div class="col-md-4">*This condition applies on ALL selected files.</div></div>' % (info[3])
    formStr += '<div class="form-group"><label class="col-md-2">Files to compare:</label>'
    formStr += '<div class="col-md-10"><a data-toggle="collapse" href="#files">Show/Hide</a></div></div>'
    formStr += '<div class="form-group"><div class="col-md-12"> '+table+'</div></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Edit filter:</label>'
    formStr += '<div class="col-md-4"><textarea class="form-control" name="filterContent"></textarea></div><div class="col-md-4">*This condition applies ONLY on primary selected file.</div></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Graph time sample rate(s):</label>'
    formStr += '<div class="col-md-4"><input type="text" title="Enter amount of seconds is one time tick in graph. To low value can cause text label colisions. If empty, default value will be used." class="form-control" name="xtics"/></div></div>'
    formStr += '<div class="form-group"><div class="col-md-6">'
    formStr += '<input type="submit" class="btn btn-default pull-right" title="'+title+'"value="Render Graph" name="renderGraph" id="renderGraph" onclick="var t = getSumTime(\''+filesApproxStr+'\','+str(approximateTime)+');startProgresBar(t);">'
    formStr += '<input type="submit" class="btn btn-default pull-right" title="'+title+'"name="renderDetailedGraph" value="Render Detailed Graph" name="renderDetailedGraph" id="renderDetailedGraph" onclick="var t = getSumTime(\''+filesApproxStr+'\','+str(approximateTime)+');startProgresBar(t);"></div></div>'

    formStr += '<input type="hidden" name="actions" value="applyFilter">'
    formStr += '<input type="hidden" name="pagesToRender" value="showFile:showGraph">'

    formStr += '<input type="hidden" name="caseName" value="'+caseName+'">'
    formStr += '<input type="hidden" name="filePath" value="'+filePath+'">'
    formStr += '</form>'
    print formStr
    print '<hr/>'

    print htmlGen.generateProgresBar()
Exemple #7
0
def render(caseName, filePath, additionalFiles=[], type="png", start="", end="", xtics=""):
    syslog.syslog("PCAP APP: renderGraph: started: " + str(datetime.datetime.now()))
    colors = ["red", "black", "yellow", "green", "blue", "cyan", "orange", "violet"]
    originFileName = helper.getDBNameFromPath(filePath)
    dirpath = os.path.dirname(filePath) + "/tmp"

    dirpath = CASES_DIR + caseName + TMP_DIR
    shutil.copy(GRAPH_SCRIPT_DIR + "Makefile", dirpath)

    if type == "png":
        shutil.copy(GRAPH_SCRIPT_DIR + "throughput.gpi", dirpath + "/" + "throughput.gpi")
    else:
        shutil.copy(GRAPH_SCRIPT_DIR + "throughputDetail.gpi", dirpath + "/" + "throughput.gpi")

    data = open(dirpath + "/" + os.path.basename(filePath) + ".data", "w")
    syslog.syslog("PCAP APP: Processing file: " + filePath + " started: " + str(datetime.datetime.now()))
    subprocess.call(["tshark", "-q", "-nr", filePath, "-t", "ad", "-z" "io,stat,1"], stdout=data)
    syslog.syslog("PCAP APP: Processing file: " + filePath + "   ended: " + str(datetime.datetime.now()))
    script = open(dirpath + "/throughput.gpi", "a")
    if xtics != "":
        try:
            xtics = int(xtics)
            script.write("set xtics " + str(xtics) + "\n")
        except ValueError:
            pass
    f = helper.getFilter(caseName, helper.getDBNameFromPath(filePath))
    info = helper.getReadableFileInfo(helper.getDBNameFromPath(filePath), caseName)
    if info[4]:
        originFileName = info[4]
    syslog.syslog("PCAP APP: " + helper.getDBNameFromPath(filePath))
    plot = (
        'plot "'
        + os.path.basename(data.name)
        + '" using 2:4  every ::13 with lines ls 1 lc rgb "'
        + colors[0]
        + '" title "'
        + originFileName
        + ", filter: "
        + f
        + '"'
    )
    syslog.syslog("PCAP APP: " + plot)
    data.close()
    i = 1
    for file in additionalFiles:
        filePath = CASES_DIR + caseName + PCAP_DIR + file
        ret = Filter.applyTimeFilterOnFile(filePath, caseName, start, end)
        if ret:
            filePath = ret
            dirpath = os.path.dirname(filePath)
        data = open(dirpath + "/" + file.replace("/", "-") + ".data", "w")
        syslog.syslog("PCAP APP: Processing file: " + file + " started: " + str(datetime.datetime.now()))
        subprocess.call(["tshark", "-q", "-nr", filePath, "-t", "ad", "-z" "io,stat,1"], stdout=data)
        syslog.syslog("PCAP APP: Processing file: " + file + "   ended: " + str(datetime.datetime.now()))
        info = helper.getReadableFileInfo(file, caseName)
        f = helper.getFilter(caseName, file)
        if info[4] != "n/a":
            file = info[4]
        plot += (
            ', "'
            + os.path.basename(data.name)
            + '" using 2:4  every ::13 with lines ls 1 lc rgb "'
            + colors[i % 8]
            + '" title "'
            + file
            + ",filter: "
            + f
            + '"'
        )
        data.close()
        i += 1
    script.write(plot)
    script.close()

    os.chdir(dirpath)
    if type == "png":
        subprocess.check_output(["make", "png"])
        ret = dirpath + "/throughput.png"
    else:
        subprocess.check_output(["make"])
        ret = dirpath + "/throughput.pdf"
    syslog.syslog("PCAP APP: renderGraph:   ended: " + str(datetime.datetime.now()))
    return ret
Exemple #8
0
def printCurrentFile(filePath):
    print '<h1>' + helper.getDBNameFromPath(filePath) + '</h1>'
Exemple #9
0
def printInputFilterForm(filePath, caseName):
    info = helper.getReadableFileInfo(helper.getDBNameFromPath(filePath),
                                      caseName)
    approximateTime = helper.getRenderGraphTime(os.path.getsize(filePath))
    title = 'Approximate time to render graph is: ' + helper.getReadableTimeInfo(
        approximateTime)
    originFiles = SQLHelper.loadFiles(caseName, 'origin')
    filteredFiles = SQLHelper.loadFiles(caseName, 'filtered')
    tmpFiles = SQLHelper.loadFiles(caseName, 'tmp')
    filesApproxStr = generateFilesAproximateTimeString(originFiles, caseName)
    filesApproxStr += generateFilesAproximateTimeString(
        filteredFiles, caseName)
    filesApproxStr += generateFilesAproximateTimeString(tmpFiles, caseName)
    options = '<optgroup label="Original files">'
    for file in originFiles:
        options += '  <option value="' + file + '">' + file + '</option>'
    options += '</optgroup>'
    options += '<option data-divider="true"></option>'
    options += '<optgroup label="Filtered files">'
    for file in filteredFiles:
        options += '  <option value="' + file + '">' + file + '</option>'
    options += '</optgroup>'
    options += '<option data-divider="true"></option>'
    options += '<optgroup label="Temporary files">'
    for file in tmpFiles:
        options += '  <option value="' + file + '">' + file + '</option>'
    allFiles = originFiles + filteredFiles + tmpFiles
    table = '<div id="files" class="collapse">'
    table += '<table id="" class="display" cellspacing="0" width="100%">'
    table += '<thead><tr><th>ID</th><th>Name</th><th>Size</th><th>First Packet</th><th>Last Packet</th><th>Filter</th><th>Source File</th><th>Description</th></tr><tbody>'
    for file in allFiles:
        info = helper.getReadableFileInfo(file, caseName)
        sourceID = str(SQLHelper.getFileID(info[4], caseName)) + '.' if str(
            SQLHelper.getFileID(info[4], caseName)) != 'None' else ''
        table += '<tr><th>%s</th><th><div class="checkbox"><label><input type="checkbox" value="%s" name="additionalFiles" id="additionalFiles"><b>%s</b></label></div> </th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>' % (
            str(info[6]), file, file, info[1], info[2], info[3], info[0],
            sourceID + info[4], info[5])
    table += '</tbody></table></div>'
    info = helper.getReadableFileInfo(helper.getDBNameFromPath(filePath),
                                      caseName)
    options += '</optgroup>'
    print '<h2>File Details</h2>'
    formStr = '<form action="main.py" class="form-horizontal" method="post">'
    formStr += '<div class="form-group"><label class="col-md-2">Current filter on File:</label>'
    formStr += '<p class="col-md-10 form-control-static">' + info[
        0] + '</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Size:</label>'
    formStr += '<p class="col-md-10 form-control-static">' + info[
        1] + '</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">First Packet:</label>'
    formStr += '<p class="col-md-10 form-control-static">' + info[
        2] + '</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Last Packet:</label>'
    formStr += '<p class="col-md-10 form-control-static">' + info[
        3] + '</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Source File:</label>'
    formStr += '<p class="col-md-10 form-control-static">' + info[
        4] + '</p></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Description:</label>'
    formStr += '<div class="col-md-4"><input type="text" class="form-control" name="description"value="%s" /></div>' % info[
        5]
    formStr += '<input type="hidden" name="pagesToRender" value="showFile">'
    formStr += '<input type="hidden" name="caseName" value="' + caseName + '"/>'
    formStr += '<input type="hidden" name="filePath" value="' + filePath + '"/>'
    formStr += '<input type="hidden" name="actions" value="editDescription"/>'
    formStr += '<input type="submit" class="btn btn-default" value="Edit" name="Edit"/></div></form>'

    formStr += '<h2>Graph settings</h2>'
    formStr += '<form action="main.py" class="form-horizontal" method="post">'
    formStr += '<div class="form-group"><label class="col-md-2">Time window:</label>'
    formStr += '<div class="col-md-2"><label>From:</label><input type="text" title="Enter date and time in format: YYYY-MM-DD HH:MM:SS" class="form-control" value="%s"name="start"/></div>' % (
        info[2])
    formStr += '<div class="col-md-2"><label>To:</label><input type="text" title="Enter date and time in format: YYYY-MM-DD HH:MM:SS" class="form-control" value="%s"name="end"/></div><div class="col-md-4">*This condition applies on ALL selected files.</div></div>' % (
        info[3])
    formStr += '<div class="form-group"><label class="col-md-2">Files to compare:</label>'
    formStr += '<div class="col-md-10"><a data-toggle="collapse" href="#files">Show/Hide</a></div></div>'
    formStr += '<div class="form-group"><div class="col-md-12"> ' + table + '</div></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Edit filter:</label>'
    formStr += '<div class="col-md-4"><textarea class="form-control" name="filterContent"></textarea></div><div class="col-md-4">*This condition applies ONLY on primary selected file.</div></div>'
    formStr += '<div class="form-group"><label class="col-md-2">Graph time sample rate(s):</label>'
    formStr += '<div class="col-md-4"><input type="text" title="Enter amount of seconds is one time tick in graph. To low value can cause text label colisions. If empty, default value will be used." class="form-control" name="xtics"/></div></div>'
    formStr += '<div class="form-group"><div class="col-md-6">'
    formStr += '<input type="submit" class="btn btn-default pull-right" title="' + title + '"value="Render Graph" name="renderGraph" id="renderGraph" onclick="var t = getSumTime(\'' + filesApproxStr + '\',' + str(
        approximateTime) + ');startProgresBar(t);">'
    formStr += '<input type="submit" class="btn btn-default pull-right" title="' + title + '"name="renderDetailedGraph" value="Render Detailed Graph" name="renderDetailedGraph" id="renderDetailedGraph" onclick="var t = getSumTime(\'' + filesApproxStr + '\',' + str(
        approximateTime) + ');startProgresBar(t);"></div></div>'

    formStr += '<input type="hidden" name="actions" value="applyFilter">'
    formStr += '<input type="hidden" name="pagesToRender" value="showFile:showGraph">'

    formStr += '<input type="hidden" name="caseName" value="' + caseName + '">'
    formStr += '<input type="hidden" name="filePath" value="' + filePath + '">'
    formStr += '</form>'
    print formStr
    print '<hr/>'

    print htmlGen.generateProgresBar()
Exemple #10
0
def render(caseName,
           filePath,
           additionalFiles=[],
           type='png',
           start='',
           end='',
           xtics=''):
    syslog.syslog("PCAP APP: renderGraph: started: " +
                  str(datetime.datetime.now()))
    colors = [
        "red", "black", "yellow", "green", "blue", "cyan", "orange", "violet"
    ]
    originFileName = helper.getDBNameFromPath(filePath)
    dirpath = os.path.dirname(filePath) + '/tmp'

    dirpath = CASES_DIR + caseName + TMP_DIR
    shutil.copy(GRAPH_SCRIPT_DIR + 'Makefile', dirpath)

    if type == 'png':
        shutil.copy(GRAPH_SCRIPT_DIR + 'throughput.gpi',
                    dirpath + "/" + 'throughput.gpi')
    else:
        shutil.copy(GRAPH_SCRIPT_DIR + 'throughputDetail.gpi',
                    dirpath + "/" + 'throughput.gpi')

    data = open(dirpath + '/' + os.path.basename(filePath) + '.data', 'w')
    syslog.syslog("PCAP APP: Processing file: " + filePath + " started: " +
                  str(datetime.datetime.now()))
    subprocess.call(
        ['tshark', '-q', '-nr', filePath, '-t', 'ad', '-z'
         'io,stat,1'],
        stdout=data)
    syslog.syslog("PCAP APP: Processing file: " + filePath + "   ended: " +
                  str(datetime.datetime.now()))
    script = open(dirpath + '/throughput.gpi', 'a')
    if xtics != '':
        try:
            xtics = int(xtics)
            script.write("set xtics " + str(xtics) + '\n')
        except ValueError:
            pass
    f = helper.getFilter(caseName, helper.getDBNameFromPath(filePath))
    info = helper.getReadableFileInfo(helper.getDBNameFromPath(filePath),
                                      caseName)
    if info[4]:
        originFileName = info[4]
    syslog.syslog("PCAP APP: " + helper.getDBNameFromPath(filePath))
    plot = 'plot "' + os.path.basename(
        data.name
    ) + '" using 2:4  every ::13 with lines ls 1 lc rgb "' + colors[
        0] + '" title "' + originFileName + ", filter: " + f + '"'
    syslog.syslog("PCAP APP: " + plot)
    data.close()
    i = 1
    for file in additionalFiles:
        filePath = CASES_DIR + caseName + PCAP_DIR + file
        ret = Filter.applyTimeFilterOnFile(filePath, caseName, start, end)
        if ret:
            filePath = ret
            dirpath = os.path.dirname(filePath)
        data = open(dirpath + '/' + file.replace('/', '-') + '.data', 'w')
        syslog.syslog("PCAP APP: Processing file: " + file + " started: " +
                      str(datetime.datetime.now()))
        subprocess.call(
            ['tshark', '-q', '-nr', filePath, '-t', 'ad', '-z'
             'io,stat,1'],
            stdout=data)
        syslog.syslog("PCAP APP: Processing file: " + file + "   ended: " +
                      str(datetime.datetime.now()))
        info = helper.getReadableFileInfo(file, caseName)
        f = helper.getFilter(caseName, file)
        if info[4] != 'n/a':
            file = info[4]
        plot += ', "' + os.path.basename(
            data.name
        ) + '" using 2:4  every ::13 with lines ls 1 lc rgb "' + colors[
            i % 8] + '" title "' + file + ",filter: " + f + '"'
        data.close()
        i += 1
    script.write(plot)
    script.close()

    os.chdir(dirpath)
    if type == 'png':
        subprocess.check_output(['make', 'png'])
        ret = dirpath + '/throughput.png'
    else:
        subprocess.check_output(['make'])
        ret = dirpath + '/throughput.pdf'
    syslog.syslog("PCAP APP: renderGraph:   ended: " +
                  str(datetime.datetime.now()))
    return ret