From 38742107519339f648b661c560436207d296d820 Mon Sep 17 00:00:00 2001
From: j1pe <32877747+j1pe@users.noreply.github.com>
Date: Thu, 23 Apr 2020 14:46:21 +0200
Subject: [PATCH 1/4] Send authentication log to the syslog
if you want, I've added a method to send logs (Public IP and username) during authentication.
---
index.php | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/index.php b/index.php
index b33dc2d..561e869 100644
--- a/index.php
+++ b/index.php
@@ -13,10 +13,23 @@
sleep(2);
if(!checkAuthentication(trim(strval($_POST['user'])), trim(strval($_POST['pass'])))){
echo "" . AUTHENTICATION_ERROR_CREDENTIAL . "";
+ #sending a log to the syslog when authentication is incorrect
+ $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+ $msg = "kodi_authd Client authentication failure: {$_SERVER['HTTP_X_FORWARDED_FOR']} ({$_POST['user']})";
+ $len = strlen($msg);
+ socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 514);
+ socket_close($sock);
exit;
} else {
echo "" . AUTHENTICATION_SUCCESS_REDIRECT . "
";
echo "";
+ #sending a log to the syslog when authentication is correct
+ $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+ $msg = "kodi_authd Client authentication failure: {$_SERVER['HTTP_X_FORWARDED_FOR']} ({$_POST['user']})";
+ $len = strlen($msg);
+ socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 514);
+ socket_close($sock);
+ exit;
exit;
}
}
From a4d7470b1dc1bdd880f47a5f764a72e0b7c640eb Mon Sep 17 00:00:00 2001
From: j1pe <32877747+j1pe@users.noreply.github.com>
Date: Tue, 28 Apr 2020 17:54:19 +0200
Subject: [PATCH 2/4] Add files via upload
---
config.php | 9 +++++++++
functions.php | 39 +++++++++++++++++++++++++++++++++++++++
index.php | 15 ++-------------
3 files changed, 50 insertions(+), 13 deletions(-)
diff --git a/config.php b/config.php
index 22891ea..2ee81f5 100644
--- a/config.php
+++ b/config.php
@@ -86,6 +86,15 @@
###############################################################################################################
define("WATCHED_STATUS_FOR_ALL", false);
$WATCH_STATUS_FOR_USERS = ["kodi", "mylogin"];
+###############################################################################################################
+# Send log to a syslog server
+# If SYSLOG_AUTHD_ENABLE is true, then all authentication log are send to a syslog server.
+# SYSLOG_AUTHD_HOST - Set Syslog's IP
+# SYSLOG_AUTHD_PORT - Set the UDP port
+###############################################################################################################
+define("SYSLOG_AUTHD_ENABLE", false);
+define("SYSLOG_AUTHD_HOST", "local");
+define("SYSLOG_AUTHD_PORT", "514");
###############################################################################################################
# XBMC / Kodi tables definition
diff --git a/functions.php b/functions.php
index 25fc2ea..61c5498 100644
--- a/functions.php
+++ b/functions.php
@@ -91,6 +91,45 @@ function sessionStartSecurely(){
session_start();
}
+/**
+ * Send authentication log to a syslog server
+*/
+
+function getClientIP(){
+ if (isset ($_SERVER['HTTP_X_FORWARDED_FOR'])){
+ return $_SERVER['HTTP_X_FORWARDED_FOR'];
+ } else {
+ return $_SERVER['REMOTE_ADDR'];
+ }
+}
+
+function badAuthSyslog(){
+ $ip = getClientIP();
+ $ip = preg_replace("/[^0-9.]/",'',getClientIP());
+ $sysUser = preg_replace("/[^A-Za-z0-9?!]/",'',$_POST['user']);
+ if(SYSLOG_AUTHD_ENABLE) {
+ $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+ $msg = "kodi_authd Client authentication failure: {$ip} {$sysUser}";
+ $len = strlen($msg);
+ socket_sendto($sock, $msg, $len, 0, SYSLOG_AUTHD_HOST, SYSLOG_AUTHD_PORT);
+ socket_close($sock);
+ exit;
+ }
+}
+function goodAuthSyslog(){
+ $ip = getClientIP();
+ $ip = preg_replace("/[^0-9.]/",'',getClientIP());
+ $sysUser = preg_replace("/[^A-Za-z0-9?!]/",'',$_POST['user']);
+ if(SYSLOG_AUTHD_ENABLE){
+ $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+ $msg = "kodi_authd New client authentication: {$ip} {$sysUser}";
+ $len = strlen($msg);
+ socket_sendto($sock, $msg, $len, 0, SYSLOG_AUTHD_HOST, SYSLOG_AUTHD_PORT);
+ socket_close($sock);
+ exit;
+ }
+}
+
/**
* Convert XML from KODI/XBMC database to array of URL.
*/
diff --git a/index.php b/index.php
index 561e869..cc75ee5 100644
--- a/index.php
+++ b/index.php
@@ -13,23 +13,12 @@
sleep(2);
if(!checkAuthentication(trim(strval($_POST['user'])), trim(strval($_POST['pass'])))){
echo "" . AUTHENTICATION_ERROR_CREDENTIAL . "";
- #sending a log to the syslog when authentication is incorrect
- $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- $msg = "kodi_authd Client authentication failure: {$_SERVER['HTTP_X_FORWARDED_FOR']} ({$_POST['user']})";
- $len = strlen($msg);
- socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 514);
- socket_close($sock);
+ badAuthSyslog();
exit;
} else {
echo "" . AUTHENTICATION_SUCCESS_REDIRECT . "
";
echo "";
- #sending a log to the syslog when authentication is correct
- $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- $msg = "kodi_authd Client authentication failure: {$_SERVER['HTTP_X_FORWARDED_FOR']} ({$_POST['user']})";
- $len = strlen($msg);
- socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 514);
- socket_close($sock);
- exit;
+ goodAuthSyslog();
exit;
}
}
From 38d83651ee4d65b851a6a953d40f81967a6e3c0b Mon Sep 17 00:00:00 2001
From: j1pe <32877747+j1pe@users.noreply.github.com>
Date: Tue, 28 Apr 2020 18:12:58 +0200
Subject: [PATCH 3/4] Add files via upload
---
functions.php | 22 ++++------------------
index.php | 4 ++--
2 files changed, 6 insertions(+), 20 deletions(-)
diff --git a/functions.php b/functions.php
index 61c5498..5428a79 100644
--- a/functions.php
+++ b/functions.php
@@ -103,32 +103,18 @@ function getClientIP(){
}
}
-function badAuthSyslog(){
- $ip = getClientIP();
+function authSyslog($message){
$ip = preg_replace("/[^0-9.]/",'',getClientIP());
- $sysUser = preg_replace("/[^A-Za-z0-9?!]/",'',$_POST['user']);
- if(SYSLOG_AUTHD_ENABLE) {
- $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- $msg = "kodi_authd Client authentication failure: {$ip} {$sysUser}";
- $len = strlen($msg);
- socket_sendto($sock, $msg, $len, 0, SYSLOG_AUTHD_HOST, SYSLOG_AUTHD_PORT);
- socket_close($sock);
- exit;
- }
-}
-function goodAuthSyslog(){
- $ip = getClientIP();
- $ip = preg_replace("/[^0-9.]/",'',getClientIP());
- $sysUser = preg_replace("/[^A-Za-z0-9?!]/",'',$_POST['user']);
+ $sysUser = preg_replace("/[^A-Za-z0-9]/",'',$_POST['user']);
if(SYSLOG_AUTHD_ENABLE){
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- $msg = "kodi_authd New client authentication: {$ip} {$sysUser}";
+ $msg = "kodi_authd ".$message." : {$ip} {$sysUser}";
$len = strlen($msg);
socket_sendto($sock, $msg, $len, 0, SYSLOG_AUTHD_HOST, SYSLOG_AUTHD_PORT);
socket_close($sock);
exit;
}
-}
+}
/**
* Convert XML from KODI/XBMC database to array of URL.
diff --git a/index.php b/index.php
index cc75ee5..a724ddc 100644
--- a/index.php
+++ b/index.php
@@ -13,12 +13,12 @@
sleep(2);
if(!checkAuthentication(trim(strval($_POST['user'])), trim(strval($_POST['pass'])))){
echo "" . AUTHENTICATION_ERROR_CREDENTIAL . "";
- badAuthSyslog();
+ authSyslog("Client authentication failure");
exit;
} else {
echo "" . AUTHENTICATION_SUCCESS_REDIRECT . "
";
echo "";
- goodAuthSyslog();
+ authSyslog("New client authentication");
exit;
}
}
From f2eee5b64a469c5b550de2f3926142c1f4c32341 Mon Sep 17 00:00:00 2001
From: j1pe <32877747+j1pe@users.noreply.github.com>
Date: Tue, 28 Apr 2020 18:15:59 +0200
Subject: [PATCH 4/4] Update config.php
---
config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config.php b/config.php
index 2ee81f5..690331f 100644
--- a/config.php
+++ b/config.php
@@ -93,7 +93,7 @@
# SYSLOG_AUTHD_PORT - Set the UDP port
###############################################################################################################
define("SYSLOG_AUTHD_ENABLE", false);
-define("SYSLOG_AUTHD_HOST", "local");
+define("SYSLOG_AUTHD_HOST", "localhost");
define("SYSLOG_AUTHD_PORT", "514");
###############################################################################################################