Commit f2b8706c authored by haemmer's avatar haemmer

Fixed #2786 and #2787

parent ccd69df9
......@@ -397,8 +397,8 @@ function decomposeLocale($locale){
}
/******************************************************************************/
// Gets a string in the user's language. If no localized version is available
// for the string, the English string is returned as default.
// Gets a string in a specific language. Fallback to default language and
// to English.
function getLocalString($string, $encoding = ''){
global $defaultLanguage, $langStrings, $language;
......@@ -406,8 +406,10 @@ function getLocalString($string, $encoding = ''){
$textString = '';
if (isset($langStrings[$language][$string])){
$textString = $langStrings[$language][$string];
} else {
} elseif (isset($langStrings[$defaultLanguage][$string])){
$textString = $langStrings[$defaultLanguage][$string];
} else {
$textString = $langStrings['en'][$string];
}
// Change encoding if necessary
......@@ -699,38 +701,53 @@ function redirectToSP($url, $IdP){
function logAccessEntry($protocol, $type, $sp, $idp){
global $WAYFLogFile, $useLogging;
// Return if logging deactivated
if (!$useLogging){
return;
}
// Let's make sure the file exists and is writable first.
if (is_writable($WAYFLogFile)) {
// Create log entry
$entry = date('Y-m-d H:i:s').' '.$_SERVER['REMOTE_ADDR'].' '.$protocol.' '.$type.' '.$idp.' '.$sp."\n";
// We are opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($WAYFLogFile, 'a')) {
return;
}
// Try getting lock
while (!flock($handle, LOCK_EX)){
usleep(rand(10, 100));
}
// Write $somecontent to our opened file.
fwrite($handle, $entry);
// Release the lock
flock($handle, LOCK_UN);
// Close file handle
fclose($handle);
// Create log file if it does not exist yet
if (!file_exists($WAYFLogFile) && !touch($WAYFLogFile)){
// File does not exist and cannot be written to
logFatalErrorAndExit('WAYF log file '.$WAYFLogFile.' does not exist and could not be created.');
}
// Ensure that the file exists and is writable
if (!is_writable($WAYFLogFile)) {
logFatalErrorAndExit('Current file permission do not allow WAYF to write to its log file '.$WAYFLogFile.'.');
}
// Compose log entry
$entry = date('Y-m-d H:i:s').' '.$_SERVER['REMOTE_ADDR'].' '.$protocol.' '.$type.' '.$idp.' '.$sp."\n";
// Open file in append mode
if (!$handle = fopen($WAYFLogFile, 'a')) {
logFatalErrorAndExit('Could not open file '.$WAYFLogFile.' for appending log entries.');
}
// Try getting the lock
while (!flock($handle, LOCK_EX)){
usleep(rand(10, 100));
}
// Write entry
fwrite($handle, $entry);
// Release the lock
flock($handle, LOCK_UN);
// Close file handle
fclose($handle);
}
/******************************************************************************/
// Logs an fatal error message
function logFatalErrorAndExit($errorMsg){
syslog(LOG_ERR, $errorMsg);
exit;
}
/******************************************************************************/
// Returns true if PATH info indicates a request of type $type
function isRequestType($type){
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment