Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send authentication log to the syslog #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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", "localhost");
define("SYSLOG_AUTHD_PORT", "514");

###############################################################################################################
# XBMC / Kodi tables definition
Expand Down
25 changes: 25 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ 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 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 ".$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.
*/
Expand Down
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
sleep(2);
if(!checkAuthentication(trim(strval($_POST['user'])), trim(strval($_POST['pass'])))){
echo "<span class='error'>" . AUTHENTICATION_ERROR_CREDENTIAL . "</span>";
authSyslog("Client authentication failure");
exit;
} else {
echo "<span class='success'>" . AUTHENTICATION_SUCCESS_REDIRECT . "&nbsp;&nbsp;&nbsp;</span><img src='./images/loading-login.gif' />";
echo "<script type='text/javascript'>document.location='./';</script>";
authSyslog("New client authentication");
exit;
}
}
Expand Down