3 /**********************************************************************************
4 ** (c) Copyright 2002, Brenno J.S.A.A.F. de Winter, De Winter Information Soltions
5 ** This is free software; you can redistribute it and/or modify it under the
6 ** terms of the GNU General Public License, see the file COPYING.
7 ***********************************************************************************/
11 /* The function linux_log will seperate the logline in several elements. This will
12 * ease the work of recognizing the type of logline. Once this has been detected
13 * the correct module will start using the data for a log_adv-table.
15 * GLOBALS : $dbms (database class containing the logline)
16 * OUTPUT : Status of success ('TRUE' for success and 'FALSE' for failure
20 global $developrelease;
22 $local_log_string = str_replace(" ", " ", $dbms->db_result_row[6]);
23 $local_logline_array = explode (" ", $local_log_string);
25 $service_type = $dbms->db_result_row[3];
26 switch (strtolower($service_type))
29 //This is a kernel logline now discover which type kernel-record we have
31 //Detect if this is a network-line
32 if (strtolower(substr($local_logline_array[5],0,3)) == "in=")
34 //this is a networkline call the processing the routines
35 $local_result = linux_kernel_network();
41 //This line is a kernel line writing about a device.
42 if (strtolower($local_logline_array[4]) == 'device')
44 echo $local_log_string;
46 $local_result = linux_kernel_device();
55 if ($developrelease == 'TRUE')
59 $local_failing_string = "Failing string: ".$dbms->db_result_row[5];
60 syslog (LOG_INFO, "Unrecognized kernelline:".$local_log_string);
61 syslog (LOG_INFO, $local_failing_string);
72 $local_result = linux_daemon();
76 $local_result = linux_daemon();
80 $local_result = linux_daemon();
84 $local_result = linux_daemon();
88 $local_result = linux_daemon();
92 $local_result = linux_daemon();
96 $local_result = linux_daemon();
100 $local_result = linux_daemon();
104 $local_result = linux_daemon();
108 $local_result = linux_daemon();
112 $local_result = linux_daemon();
116 $local_result = linux_daemon();
120 $local_result = linux_daemon();
128 function linux_kernel_network() {
130 /* This function is able to deal with the output of kernel-network messages
131 * coming from iptables and other similar tools. When elements are found
132 * that cannot be identified a notification will be written to the logbook
133 * for easy expansion of this routine.
135 * GLOBALS : $dbms, $dbms_working;
136 * OUTPUT : "TRUE" for success and "FALSE" for failure.
139 global $dbms_working;
141 $local_log_string = str_replace(" ", " ", $dbms->db_result_row[6]);
142 $local_logline_array = explode (" ", $local_log_string);
143 $local_sql_1 = "INSERT INTO log_adv_kernel_network"; //BASIC STATEMENT
144 $local_sql_2 = "logid, detailed_table"; //FIELDS
145 $local_sql_3 = "'".$dbms->db_result_row[0]."', 'kernel_network'"; //VALUES
149 for ($i = 4; $i <= ( count($local_logline_array) - 1); $i++) {
150 //Process each element by exploding this based on the sign: =
151 $local_element = explode("=", $local_logline_array[$i]);
152 switch (strtolower($local_element[0])) {
155 $local_sql_2 .= ", device_in";
156 $local_sql_3 .= ", '".$local_element[1]."'";
160 $local_sql_2 .= ", device_out";
161 $local_sql_3 .= ", '".$local_element[1]."'";
165 $local_sql_2 .= ", hw_address";
166 $local_sql_3 .= ", '".$local_element[1]."'";
170 $local_sql_2 .= ", source_ip";
171 $local_sql_3 .= ", '".$local_element[1]."'";
175 $local_sql_2 .= ", destination_ip";
176 $local_sql_3 .= ", '".$local_element[1]."'";
180 if ($local_len == 0) {
181 $local_sql_2 .= ", packet_length";
184 $local_sql_2 .= ", body_len";
187 $local_sql_3 .= ", '".$local_element[1]."'";
191 $local_sql_2 .= ", tos_bit";
192 $local_sql_3 .= ", '".$local_element[1]."'";
196 $local_sql_2 .= ", prec_bit";
197 $local_sql_3 .= ", '".$local_element[1]."'";
201 $local_sql_2 .= ", ttl";
202 $local_sql_3 .= ", '".$local_element[1]."'";
207 if ($local_id == 0) {
208 $local_sql_2 .= ", header_id";
209 $local_sql_3 .= ", '".$local_element[1]."'";
215 $local_sql_2 .= ", protocol";
216 $local_sql_3 .= ", '".$local_element[1]."'";
217 if ($local_element[1] == 'ICMP') {
223 $local_sql_2 .= ", destination_port";
224 $local_sql_3 .= ", '".$local_element[1]."'";
228 $local_sql_2 .= ", source_port";
229 $local_sql_3 .= ", '".$local_element[1]."'";
233 $local_sql_2 .= ", window";
234 $local_sql_3 .= ", '".$local_element[1]."'";
238 $local_sql_2 .= ", urgp";
239 $local_sql_3 .= ", '".$local_element[1]."'";
243 $local_sql_2 .= ", rst";
244 $local_sql_3 .= ", true";
248 $local_sql_2 .= ", syn";
249 $local_sql_3 .= ", true";
253 $local_sql_2 .= ", df";
254 $local_sql_3 .= ", true";
258 $local_sql_2 .= ", type";
259 $local_sql_3 .= ", '".$local_element[1]."'";
263 $local_sql_2 .= ", code";
264 $local_sql_3 .= ", '".$local_element[1]."'";
268 $local_sql_2 .= ", sequence_number";
269 $local_sql_3 .= ", '".$local_element[1]."'";
273 $local_sql_2 .= ", res";
274 $local_sql_3 .= ", '".$local_element[1]."'";
278 /*This record is different. In ICMP information is sometimes returned on an original packet.
279 * When the brackets are used a second line will be added to the
280 * log_adv_kernel_network-table. For that reason the processing into the database will be
281 * done here as well. After that a new insert-string will be created.
284 //Enter the data into the database
285 $local_sql = $local_sql_1." (".$local_sql_2.") VALUES (".$local_sql_3.")";
286 $dbms_working->query($local_sql);
288 $local_sql_1 = "INSERT INTO log_adv_kernel_network"; //BASIC STATEMENT
289 $local_sql_2 = "logid, detailed_table"; //FIELDS
290 $local_sql_3 = "'".$dbms->db_result_row[0]."', 'kernel_network'"; //VALUES
295 /* $local_element[0];
296 syslog(LOG_INFO, "Unrecognized kernel/network entry: ".$local_element[0]);
304 //Now that the data is complete create the SQL-statement
305 $local_sql = $local_sql_1." (".$local_sql_2.") VALUES (".$local_sql_3.")";
306 $dbms_working->query($local_sql);
311 function linux_kernel_device() {
312 /* This function is able to deal with the output of kernel-network messages
313 * coming from device related processes. Typically networkcard and other
314 * hardware-related data will show-up here
316 * GLOBALS : $dbms, $dbms_working
317 * OUTPUT : "TRUE" for success and "FALSE" for failure.
320 global $dbms, $dbms_working;
324 function linux_daemon() {
325 /* This function is able to deal with the output of kernel-network messages
326 * coming from device related processes. Typically networkcard and other
327 * hardware-related data will show-up here
329 * GLOBALS : $dbms, $dbms_working
330 * OUTPUT : "TRUE" for success and "FALSE" for failure.
333 global $dbms, $dbms_working;
335 $local_log_line = strtolower($dbms->db_result_row[6]);
337 //Find a sign of stop
338 //Using the word shutdown
339 $pos = strpos($local_log_line, "shutdown");
341 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
342 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'stop')";
343 $dbms_working->query($local_sql);
345 //Using the word stop
346 $pos = strpos($local_log_line, "stop");
348 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
349 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'stop')";
350 $dbms_working->query($local_sql);
352 //As the word restart
353 $pos = strpos($local_log_line, "restart");
355 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
356 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'stop')";
357 $dbms_working->query($local_sql);
359 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
360 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'start')";
361 $dbms_working->query($local_sql);
363 //As the word start this is an else for restart.
364 //If we wouldn't do so restart would also give a positive on start
365 $pos = strpos($local_log_line, "start");
367 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
368 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'start')";
369 $dbms_working->query($local_sql);
372 //The word error indicates problems.
373 $pos = strpos($local_log_line, "error");
374 $pos2 = strpost($local_log_line, "crash"); //The word crash is also considered to be an error
375 if ($pos > 0 or $pos2 > 0) {
377 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
378 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'error detected')";
379 $dbms_working->query($local_sql);
381 //Quite often an error will be followed with information that the daemon or service ended.
382 $pos = strpos($local_log_line, "abort");
384 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
385 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'abort')";
386 $dbms_working->query($local_sql);
388 $pos = strpos($local_log_line, "ended");
390 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
391 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'abort')";
392 $dbms_working->query($local_sql);
394 $pos = strpos($local_log_line, "stop");
396 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
397 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'abort')";
398 $dbms_working->query($local_sql);
401 //For power management there is a charge warning
402 $pos = strpos($local_log_line, "charge");
404 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
405 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'Power warning')";
406 $dbms_working->query($local_sql);
409 //As the word start this is an else for restart.
410 //If we wouldn't do so restart would also give a positive on start
411 //This can only be done if we ensured nothing else was the case
412 //PLEASE USE THIS AS LATE AS POSSIBLE!!!
413 $pos = strpos($local_log_line, "exiting");
415 $local_sql = "INSERT INTO log_adv_daemon (logid, detailed_table, service, event) VALUES ";
416 $local_sql .= "('".$dbms->db_result_row[0]."', 'log_adv_daemon', '".$dbms->db_result_row[3]."', 'start')";
417 $dbms_working->query($local_sql);