logfile}.loginfo")) { $loginfo = file("{$this->logfile}.loginfo"); $md5 = trim($loginfo[0]); $lastline = trim($loginfo[1]); echo "getnewlogs:".$lastline."\n"; $logsmd5 = array_map("md5", $this->logs); /* Check wether the last sent line is found */ $lastkey = array_search($md5, $logsmd5); if ($lastkey !== false) $this->newlogs = array_slice($this->logs, $lastkey+1); else $this->newlogs = $this->logs; } else { $this->newlogs = $this->logs; } } function writeoffset() { if (count($this->newlogs) >= 1) { /* Get md5 hash of last line */ $new_lastline = trim($this->newlogs[count($this->newlogs)-1]); $new_md5 = md5($new_lastline); /* Write offset and md5 to {$logfile}.loginfo */ $loginfo = $new_md5."\n"; $loginfo .= $new_lastline; file_put_contents("{$this->logfile}.loginfo", $loginfo); echo "writeoffset:".$loginfo."\n"; } else { // echo "nothing new"; } } function logtail($logfile) { $this->logfile = $logfile; /* Read logs */ exec ("clog {$logfile}", $this->logs); /* $this->logs = file($logfile); $this->logs = array_map ("trim", $this->logs); */ /* This will seek the handle to the position where to continue to read the logs .. If all fails, from the beginning */ $this->getnewlogs(); /* Read new log entries */ $this->writeoffset(); //$this->sendmail(); } } class logtailmail { var $body; function sendmail() { global $config; $mycnf = &$config["installedpackages"]["logtailmail"]; require_once ("class.smtp.php"); $smtp = new smtp_class; $smtp->host_name = $mycnf["remotesmtp"]; /* Change this variable to the address of the SMTP server to relay, like "smtp.myisp.com" */ $smtp->host_port = $mycnf["remotesmtpport"];; /* Change this variable to the port of the SMTP server to use, like 465 */ $smtp->direct_delivery = 1; /* Set to 1 to deliver directly to the recepient SMTP server */ $smtp->ssl = 0; /* Change this variable if the SMTP server requires an secure connection using SSL */ $smtp->debug = 1; /* Set to 1 to output the communication with the SMTP server */ $smtp->html_debug = 0; /* Set to 1 to format the debug output as HTML */ $from = $mycnf["from"]; $to = $mycnf["to"]; $headers = array( "From: $from", "To: $to", // "Subject: ".genhtmltitle('logtailmail'), "Subject: logtailmail", "Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z") ); if($smtp->SendMessage($from, array($to), $headers, $this->body)) echo "Message sent to $to OK.\n"; else echo "Cound not send the message to $to.\nError: ".$smtp->error."\n"; } function logtailmail ($logfiles) { if (!is_array($logfiles)) exit ("No array given"); foreach ($logfiles as $logfile) { $logtail = new logtail($logfile); $this->body .= "\n\n\n"; $this->body .= "{$logfile}:\n"; $this->body .= "________________________________________________________________________________\n"; $this->body .= "(".count($logtail->newlogs)." lines)\n"; $this->body .= implode ("\n", $logtail->newlogs); unset($logtail); } $this->sendmail(); //echo $this->body; } } new logtailmail($config['installedpackages']['logtailmail']['logfiles']); echo "\n"; ?>