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 pathx509_logs.php
executable file
·71 lines (66 loc) · 2.72 KB
/
x509_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
65
66
67
68
69
70
<?php
include_once('functions.php');
include_once('config.php');
function LoadBroX509Logs($fileName) {
/**
* This file contains all of the functionality to import bro X509 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
//$fileName = "../test2/x509.log"; //use only for testing
print("Importing X509 log file $fileName \n");
$file = fopen($fileName, "r");
$i = 1;
$insertStatement = X509_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
$fuid = $tmpRecord[X509_FUID];
$version = ReturnNum($tmpRecord[X509_VERSION]);
$serial = ReturnString($tmpRecord[X509_SERIAL]);
$subject = ReturnString($tmpRecord[X509_SUBJECT]);
$issuer = ReturnString($tmpRecord[X509_ISSUER]);
$notValidBefore = ReturnString($tmpRecord[X509_NOTVALIDBEFORE]);
$notValidAfter = ReturnString($tmpRecord[X509_NOTVALIDAFTER]);
$keyAlg = ReturnString($tmpRecord[X509_KEYALG]);
$sigAlg = ReturnString($tmpRecord[X509_SIGALG]);
$keyType = ReturnString($tmpRecord[X509_KEYTYPE]);
$keyLen = ReturnString($tmpRecord[X509_KEYLENGTH]);
//Build $currentRecordVals
$currentRecordVals = "('$fuid', $version, '$serial', '$subject', '$issuer', FROM_UNIXTIME($notValidBefore),
FROM_UNIXTIME($notValidAfter), '$keyAlg', '$sigAlg', '$keyType', $keyLen)";
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 = X509_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;
}
}
?>