This repository has been archived by the owner on Feb 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssl_logs.php
executable file
·64 lines (60 loc) · 2.32 KB
/
ssl_logs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
include_once('functions.php');
include_once('config.php');
function LoadBroSSLLogs($fileName) {
/**
* This file contains all of the functionality to import bro conn logs into the database
* All CONSTANTS are defined within config.php
*/
$insertStatement = ""; //Holds the overall SQL insert statement
$currentRecordVals = ""; //Holds the values for this particular record before adding to $insertStatement
//$currentFile = "../test2/ssl.log"; //use only for testing
print("Importing SSL log file $fileName \n");
$file = fopen($fileName, "r");
$i = 1;
$insertStatement = SSL_LOG_INSERT;
$completeStatement = True;
while(! feof($file)){
$tmpRecord = fgetcsv($file, 0, "\t");
// Check to ensure that the first charachter
// isn't '#' and if it is, skip the line
if ($tmpRecord[0][0] == '#') continue; //Line is a header
if ($tmpRecord[0][0] == false) continue; //Line is blank
$uid = $tmpRecord[SSL_UID];
$version = ReturnString($tmpRecord[SSL_VERSION]);
$cipher = ReturnString($tmpRecord[SSL_CIPHER]);
$server = ReturnString($tmpRecord[SSL_SERVER]);
$subject = ReturnString($tmpRecord[SSL_SUBJECT]);
$issuer = ReturnString($tmpRecord[SSL_ISSUER]);
//Build $currentRecordVals
$currentRecordVals = "('$uid', '$version', '$cipher', '$server', '$subject', '$issuer')";
if ($i == 1) { //First record, no need to add the comma
$insertStatement = $insertStatement . $currentRecordVals;
$i++;
$completeStatement = False;
} elseif ($i == 10) { //Final record in the current set, close out the sql statement and insert
$insertStatement = $insertStatement . ", " . $currentRecordVals . ";";
//INSERT THE RECORD INTO THE DATABASE
if (! db_query($insertStatement)){
echo "ERROR...... $insertStatement \n";
}
$i = 1; //Reset the counter
$completeStatement = True;
$insertStatement = SSL_LOG_INSERT;
} else { //add a comma and the the next set of values
$insertStatement = $insertStatement . ", " . $currentRecordVals;
$i++;
$completeStatement = False;
}
}
//If we reach end of file without properly finishing and inserting the sql statement, do it now
if (! $completeStatement){
$insertStatement = $insertStatement . ";";
//INSERT THE RECORD INTO THE DATABASE
if (! db_query($insertStatement)){
echo "ERROR...... $insertStatement \n";
}
$completeStatement = True;
}
}
?>