Commit f2b8706c authored by haemmer's avatar haemmer

Fixed #2786 and #2787

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