diff --git a/README.md b/README.md
index 06c884f..bc5873f 100644
--- a/README.md
+++ b/README.md
@@ -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.
@@ -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:
+
+
+----
+
+Version 1.0 (by github.com/tmanternach):

diff --git a/config.php b/config.php
index a32c8ed..7a56ca5 100644
--- a/config.php
+++ b/config.php
@@ -1,26 +1,49 @@
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
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);
?>
diff --git a/dbhelper.php b/dbhelper.php
new file mode 100644
index 0000000..5a789e0
--- /dev/null
+++ b/dbhelper.php
@@ -0,0 +1,104 @@
+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;
+ }
+}
+
+?>
diff --git a/distinct.php b/distinct.php
index b05154f..7673f23 100644
--- a/distinct.php
+++ b/distinct.php
@@ -1,14 +1,14 @@
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);
?>
diff --git a/function.php b/function.php
new file mode 100644
index 0000000..622a1ae
--- /dev/null
+++ b/function.php
@@ -0,0 +1,32 @@
+No results found! ¯\_(ツ)_/¯ ";
+ }
+
+ //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;
+ }
+?>
diff --git a/get_mysql_query.php b/get_mysql_query.php
new file mode 100644
index 0000000..3698b74
--- /dev/null
+++ b/get_mysql_query.php
@@ -0,0 +1,18 @@
+ 600";
+ $result = mysql_query($sql, $database->getDBcon());
+
+ while($row = mysql_fetch_array($result)) {
+ $id = $row['ID'];
+ $rtime = $row['TIME'];
+
+ echo $id ." ". $rtime ." ";
+
+ //Kill
+ $kill_proc = "KILL $id";
+ mysql_query($kill_proc, $database->getDBcon());
+ }
+?>
diff --git a/index.php b/index.php
index fbf2f80..ec72f82 100644
--- a/index.php
+++ b/index.php
@@ -1,300 +1,481 @@
-
+
+
-=$title; ?>
-
-
-
-
-
+ =$title;?>
+
+
+
+
+
+
+
+
-