forked from ossec/ossec-hids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ossec2rss.php
124 lines (105 loc) · 2.47 KB
/
ossec2rss.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
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
/* OSSEC 2 RSS script.
* by Daniel B. Cid ( dcid @ ossec.net)
*
* Just upload it to any web-accessible directory, and make
* sure the web server can access the OSSEC alerts log file.
*/
$ossec_log = "/var/ossec/logs/alerts/alerts.log";
if(!is_readable($ossec_log))
{
echo "ERROR: Unable to access $ossec_log\n";
echo "*TIP: Make sure your web server can access that file. \n";
exit(1);
}
$timelp = filemtime($ossec_log);
$fh = fopen($ossec_log, "r");
if(!$fh)
{
exit(1);
}
if(filesize($ossec_log) > 30000)
{
fseek($fh, -30000, SEEK_END);
$line = fgets($fh, 4096);
}
$lastlines = array();
$event = array();
while($line = fgets($fh, 4096))
{
$line = trim($line);
if($line == "")
{
continue;
}
if(strncmp($line, "** Alert ", 9) == 0)
{
if(strncmp($event, "** Alert ", 9) == 0)
{
array_push($lastlines, $event);
}
unset($event);
$event = array();
$event[] = htmlspecialchars($line);
}
else
{
$event[] = htmlspecialchars($line);
}
}
fclose($fh);
$lastlines = array_reverse($lastlines);
$myhost = gethostname();
if($myhost === FALSE)
{
$myhost = "";
}
echo '<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/css/rss.css" type="text/css"?>
<rss version="2.0">
<channel>
<title>OSSEC '.$myhost.' RSS Feed</title>
<link>http://ossec.net</link>
<description>OSSEC RSS Feed for '.$myhost.'</description>
<language>en-us</language>
<lastBuildDate>'.date("r", $timelp).'</lastBuildDate>
<pubDate>'.date("r", $timelp).'</pubDate>
<copyright>(C) OSSEC.net 2008-2011</copyright>
<generator>OSSEC.net RSS feed</generator>
<ttl>30</ttl>
<webMaster>[email protected]</webMaster>
<image>
<title>OSSEC Alert Feed</title>
<url>http://www.ossec.net/img/ossec_logo.jpg</url>
<link>http://ossec.net</link>
</image>
';
foreach($lastlines as $myentry)
{
echo $myentry;
if(preg_match("/^.. Alert (\d+)\./", $myentry[0], $regs, PREG_OFFSET_CAPTURE, 0))
{
$myunixtime = $regs[1][0];
}
else
{
continue;
}
echo '
<item>
<title>'.$myentry[2]." ,from ".substr($myentry[1], 20).'</title>
<link>http://ossec.net</link>
<guid isPermaLink="false">'.$myentry[0].'</guid>
<description><![CDATA[';
foreach($myentry as $myline){ echo $myline."<br />\n"; }
echo '
]]></description>
<pubDate>'.date("r", $myunixtime).'</pubDate>
</item>
';
}
echo '
</channel>
</rss>
';
?>