Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
WebSysLog
WebSysLog 2.0
=========

This is a simple Syslog viewer written in PHP. Your syslog server must be configured to push syslog messages to a MySQL database.
Expand All @@ -7,5 +7,11 @@ Instructions for writing syslog to MySQL can be found here: [[http://www.rsyslog

Edit config.php to enter your database information and basic setup.

Version 2.0:
![Screenshot](https://github.com/SnipeLike/WebSysLog/blob/master/screenshot_v2.png)


----

Version 1.0 (by github.com/tmanternach):
![Screenshot](https://raw.github.com/tmanternach/WebSysLog/master/screenshot.png)
61 changes: 42 additions & 19 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
<?php
$title = "Syslog WebViewer"; //This appears as the <title> of your page and also the h1 header at the top of the page.
$hostname = "localhost"; //Change this to IP or hostname of your database server. Probably localhost.
$username = "user"; //This is a MySQL user that has access to the Syslog database.
$password = "pass"; //Password for above user.
$database_name = "syslog"; //The name of the database for the Syslog events.
$search_limit = 200;

# COLORS
$background_color = "#111111";
$header_color = "#111111";
$date_color = "#009E52";
$host_color = "#FFFA9E";
$tag_color = "#0081C2";
$msg_color = "#ffffff";
$warning_color = "#AA0000";

$title = "Syslog Viewer"; //This appears as the <title> of your page and also the h1 header at the top of the page.
$hostname = "localhost"; //Change this to IP or hostname of your database server. Probably localhost.
$username = "root"; //This is a MySQL user that has access to the Syslog database.
$password = "password"; //Password for above user.
$database_name = "Syslog"; //The name of the database for the Syslog events.
$search_limit = 300;

# COLORS
$background_color = "rgb(17,17,17)";
$header_color = "rgb(17,17,17)";
$date_color = "#009E52";
$host_color = "#FFFA9E";
$tag_color = "#0081C2";
// DB-Table
$tbl_name = "syslog"; //The Table where Syslog events are stored.
//$tbl_name = "SystemEvents";

# DO NOT EDIT BELOW THIS LINE
//Translation-Table for the various columnNames
// Hint: Change only the right values! Left-Values are the indexes!
$columnNames = array(
"id" => "id",
"ReceivedAt" => "timestamp",
"FromHost" => "host",
"SysLogTag" => "tag",
"Priority" => "level",
"Message" => "msg",
);
/*
$columnNames = array(
"id" => "ID",
"ReceivedAt" => "ReceivedAt",
"FromHost" => "FromHost",
"SysLogTag" => "SysLogTag",
"Priority" => "Priority",
"Message" => "Message",
);
*/

$con = mysql_connect($hostname,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
# ---DO NOT EDIT BELOW THIS LINE---
require_once('dbhelper.php');

mysql_select_db($database_name, $con);
$database = new DBObject($hostname, $username, $password, $database_name);
$tbl = new TableObject($database, $tbl_name, $columnNames);
?>
104 changes: 104 additions & 0 deletions dbhelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

/*
Simple Database Object which holds all data required for connecting to a database.
- Such Object automatically opens a connection if it's needed
- When this Object is deconstructed, an open mysql-connection will be automatically closed!
*/
class DBObject {
private $hostname;
private $username;
private $password;

private $con = NULL;

private $database;

public function getDBName(){
return $this->database;
}

public function getUserName(){
return $this->username;
}

public function getDBCon(){
if(!isset($this->con)){
$this->connect();
}
return $this->con;
}


private function connect(){
$con = mysql_connect(
$this->hostname,
$this->username,
$this->password
);
if(!$con){
die('Could not connect: ' . mysql_error()
. debug_print_backtrace());
} else {
$this->con = $con;
set_time_limit(300);
mysql_select_db($this->database, $con);
}
}

function __construct($hostname, $username, $password, $database){
$this->hostname = $hostname;
$this->username = $username;
$this->password = $password;
$this->database = $database;
}

function __destruct(){
if(isset($this->con)){
mysql_close($this->con);
}
}
}


class TableObject {
private $DBObject;

private $TableName;

private $ColumnTranslations;

public function __construct($DBObject, $TableName, $ColumnTranslations){
if(!is_object($DBObject) || !(get_class($DBObject) == 'DBObject')){
die("First argument isn't a DBObject!". debug_print_backtrace());
}
if(isset($ColumnTranslations) && !is_array($ColumnTranslations)){
die("ColumnTranslation isn't an array!" . debug_print_backtrace());
}
$this->DBObject = $DBObject;
$this->TableName = $TableName;
if(isset($ColumnTranslations)){
$this->ColumnTranslations = $ColumnTranslations;
} else {
$this->ColumnTranslations = NULL;
}
//var_dump($this->ColumnTranslations);
}

public function tableName(){
return $this->DBObject->getDBName() . '.' . $this->TableName;
}

public function long_columnName($columnIdentifier){
return $this->tableName() . '.' . $this->columnName($columnIdentifier);
}

public function columnName($columnIdentifier){
if(array_key_exists($columnIdentifier, $this->ColumnTranslations)){
return $this->ColumnTranslations[$columnIdentifier];
}
return $columnIdentifier;
}
}

?>
24 changes: 12 additions & 12 deletions distinct.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
require_once("config.php");
$sql="SELECT DISTINCT FromHost FROM SystemEvents ORDER BY FromHost DESC";
$result = mysql_query($sql);
$arr = array();
while($row = mysql_fetch_array($result))
{
//if (strpos($row['FromHost'],$_GET['term']) !== false) {
$arr[] = $row['FromHost'];
//}
}
echo json_encode($arr);
mysql_close($con);
require_once("config.php");
$sql="SELECT DISTINCT " $tbl->long_columnName('FromHost') . " FROM " . $tbl->TableName() . " ORDER BY " . $tbl->long_columnName('FromHost') . " DESC";
$result = mysql_query($sql, $database->getDBcon());
$arr = array();
while($row = mysql_fetch_array($result)) {
//if (strpos($row[$tbl->columnName('FromHost')],$_GET['term']) !== false) {
$arr[] = $row[$tbl->columnName('FromHost')];
//}
}
echo json_encode($arr);
?>
32 changes: 32 additions & 0 deletions function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
//Include
require_once("config.php");

//Function for no results found
function noResFound() {
echo "<span class=\"warning\">No results found! ¯\_(ツ)_/¯</span><br>";
}

//Function for SELECT in search.php, 4 Days Archive
function selectFromArchive4DaysDBM($db, $date, $query, $limit) {
$sql="SELECT * FROM (
SELECT * FROM ".$db." WHERE timestamp LIKE '".$date."%' AND (timestamp LIKE '%".$query."%' OR host LIKE '%".$query."%' OR msg LIKE '%".$query."%')
ORDER BY id DESC
)
sub
ORDER BY timestamp DESC LIMIT 500";
$result = mysql_query($sql);

return $result;
}

//Function for SELECT in search.php
function selectFromArchiveDBM($db, $date, $query, $limit) {
$sql="SELECT id,timestamp,host,facility,level,tag,msg FROM ".$db." WHERE timestamp LIKE '".$date."%' AND (timestamp LIKE '%".$query."%' OR host LIKE '%".$query."%'
OR msg LIKE '%".$query."%')
ORDER BY timestamp DESC LIMIT 500";
$result = mysql_query($sql);

return $result;
}
?>
18 changes: 18 additions & 0 deletions get_mysql_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
require_once("config.php");

//Get Proc list
$sql="SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER LIKE \"" . $database.getUserName() . "\" AND COMMAND LIKE 'Query' AND TIME > 600";
$result = mysql_query($sql, $database->getDBcon());

while($row = mysql_fetch_array($result)) {
$id = $row['ID'];
$rtime = $row['TIME'];

echo $id ." ". $rtime ."<br>";

//Kill
$kill_proc = "KILL $id";
mysql_query($kill_proc, $database->getDBcon());
}
?>
Loading