forked from phpLicenseWatcher/phpLicenseWatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparselog.php
More file actions
124 lines (88 loc) · 3.88 KB
/
Copy pathparselog.php
File metadata and controls
124 lines (88 loc) · 3.88 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
if ( ! is_readable('./config.php') ) {
echo("<H2>Error: Configuration file config.php does not exist. Please
notify your system administrator.</H2>");
exit;
} else
include_once('./config.php');
if ( ! is_readable('./tools.php') ) {
echo("<H2>Error: Tools.php does not exist. Please
notify your system administrator.</H2>");
exit;
} else
include_once('./tools.php');
require_once("./common.php");
##################################################
# Load PEAR DB abstraction library
##################################################
require_once("DB.php");
################################################################
# Connect to the database
# Use persistent connections
################################################################
$db = DB::connect($dsn, true);
if (DB::isError($db)) {
die ($db->getMessage());
}
#########################################################
# This may take a long time depending on the size of your log files
# so we tell PHP not to limit the time of execution.
#########################################################
set_time_limit(0);
$mydate[] = date("Y-m-d", mktime (0,0,0,date("m"),date("d"), date("Y")));
$mydate[] = date("Y-m-d", mktime (0,0,0,date("m"),date("d")-1, date("Y")));
#########################################################
# Loop through the log files specified in config.php
#########################################################
for ( $k = 0 ; $k < sizeof($log_file) ; $k++ ) {
# Open the log file
$file = fopen ( $log_file[$k], "r");
if (!$file) {
echo "Unable to open file " . $log_file[$k] . "\n
Exiting ............";
exit;
} else {
echo "Processing file " . $log_file[$k] . "\n-------------------------\n";
}
#####################################################
# Loop through the file
#####################################################
while (!feof ($file)) {
$line = fgets ($file, 1024);
# print $line;
###################################################
# Look for the time stamp. Time stamp is actually current date
# which is logged only when FlexLM starts the log or at midnight.
###################################################
if (preg_match ("/TIMESTAMP (.*)/i", $line, $out2)) {
$timestamp_date = convert_to_mysql_date($out2[1]);
} else
# if ($timestamp_date && in_array($timestamp_date, $mydate) && eregi('(.*) \((.*)\) DENIED: "(.*)" (.*) (.*)', $line, $out2)) {
if (isset($timestamp_date) && preg_match('/(.*) \((.*)\) (IN:|OUT:|DENIED:) "(.*)" (.*)/i', $line, $out2)) {
# Strip :
$log_event = substr($out2[3],0, strpos($out2[3],":"));
# Strip username from the username@hostname
$username = substr($out2[5],0, strpos($out2[5],"@"));
preg_match('/(.*) \((.*)\) (OUT:|DENIED:) "(.*)" (.*) (.*)/i', $line, $out3);
if ( !isset( $out3[6] ) )
$out2[6] = "";
else
$out2[6] = $out3[6];
unset($out3);
$sql = "INSERT IGNORE INTO flexlm_events (flmevent_date, flmevent_time, flmevent_type, flmevent_feature, flmevent_user, flmevent_reason)
VALUES ('" . $timestamp_date . "','" . trim($out2[1]) . "','" . $log_event ."','" . $out2[4] . "','" . $username . "','" . trim($out2[6]) . "')";
unset($out2);
if ( isset($debug) && $debug == 1 )
print_sql ($sql);
$recordset = $db->query($sql);
if (DB::isError($recordset)) {
die ($recordset->getMessage());
}
unset($recordset);
}
}
# Close the log file
fclose($file);
}
$db->disconnect();
?>