CVE-2022-4366: Missing Authorization (CWE-862)
value: Missing Authorization in GitHub repository lirantal/daloradius prior to master branch.
CWE description: The product does not perform an authorization check when an actor attempts to access a resource or perform an action.
CVSS v3 base score: 7.5
Published: 2022-12-08T19:15Z
Repository: https://github.com/lirantal/daloradius
Language: PHP
Files changed: include/config/logging.php, include/management/actionMessages.php, library/errorHandling.php, library/exten-boot_log.php, library/exten-daloradius_log.php, library/exten-maint-radclient.php, library/exten-radius_log.php, library/exten-radius_server_info.php, library/exten-server_info.php, library/exten-syslog_log.php, library/exten-welcome_page.php, rep-logs-boot.php, rep-logs-daloradius.php, rep-logs-radius.php, rep-logs-system.php, rep-logs.php, rep-stat-cron.php, rep-stat-raid.php, rep-stat-server.php, rep-stat-services.php, rep-stat-ups.php
Commit date: 2022-10-12 13:20:49 +0300
Commit message: fix: introduced security fixes (#263)

- dologin.php - validating user input and introduced CSRF token check
- logging.php - preventing direct access to this file, which means redirecting to index.php when directly hitting this include file, (repeated for other exten. / include / etc. files), and optimized logging features
- actionMessages.php and errorHandling.php same as logging.php
- library/exten-* files - preventing direct access to these files, generalized the approach of looking for known file locations, improved user input validation (params such as limit, etc.), improved output (escaping logfile output, etc.)
- in library/exten-server_info.php - i also have added new commands for retrieving network information and system distro/version
- opendb.php - general code optimization (TODO prevent direct access to this file)
- sessions.php - introduced new session handling (TODO prevent direct access to this file)
- login.php - removed the default username hardcoded in the form, added the csrf_token
- rep-* - user input validation, code optimization
Diff: diff --git a/include/config/logging.php b/include/config/logging.php
index 51482c6a..fc80d17a 100644
--- a/include/config/logging.php
+++ b/include/config/logging.php
@@ -1,107 +1,116 @@
 <?php
-/*********************************************************************
-* Name: logging.php
-* Author: Liran tal <liran.tal@gmail.com>
-*
-* This file is used for controlling the logging actions
-*
-*********************************************************************/
-
-
 /*
-* It is important to understand that when logging.php is included in
-* a page AFTER an include for config_read.php it gains access to all
-* of the variables it's scope including the $configValues[....] because
-* it was included just before it.
-*
-* But it should be noticed that these variables are only accessible
-* in the scope of the general or main block of php code and are
-* not accessible from functions, so we can't just use $configValues[...]
-* variables from within logMessageNotice() or any other function
-* and so we must use them here as references.
-*
-* The relevant variables are:
-*
-* $operator
-* $_SERVER["SCRIPT_NAME"]
-* $configValues['CONFIG_LOG_FILE']
-*
-*/
+ *********************************************************************************************************
+ * daloRADIUS - RADIUS Web Platform
+ * Copyright (C) 2007 - Liran Tal <liran@enginx.com> All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ *********************************************************************************************************
+ * Description:	   This file is used for controlling the logging actions
+ * 
+ * Authors:        Liran Tal <liran@enginx.com>
+ *                 Filippo Lauria <filippo.lauria@iit.cnr.it>
+ *
+ *********************************************************************************************************
+ */
 
-if ($configValues['CONFIG_LOG_PAGES'] == "yes") {
-	if (isset($log)) {
-	        $msgNotice = $operator . " " . $log;
-	        logMessage("NOTICE", $msgNotice, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
-	}
+// prevent this file to be directly accessed
+if (strpos($_SERVER['PHP_SELF'], '/include/config/logging.php') !== false) {
+    header("Location: ../../index.php");
+    exit;
 }
 
+/*
+ * It is important to understand that when logging.php is included in
+ * a page AFTER an include for config_read.php it gains access to all
+ * of the variables it's scope including the $configValues[....] because
+ * it was included just before it.
+ *
+ * But it should be noticed that these variables are only accessible
+ * in the scope of the general or main block of php code and are
+ * not accessible from functions, so we can't just use $configValues[...]
+ * variables from within logMessageNotice() or any other function
+ * and so we must use them here as references.
+ *
+ * The relevant variables are:
+ *
+ * $operator
+ * $_SERVER["SCRIPT_NAME"]
+ * $configValues['CONFIG_LOG_FILE']
+ *
+ */
 
+/*
+ * @param $type        The message type, for example, NOTICE, DEBUG, ERROR, ACTION, etc...
+ * @param $msg         The message string which should be logged to the file
+ * @param $logFile     The full path for the filename to write logs to
+ * @param $currPage    The current page that we included from
+ * @return $table      The table name, either radcheck or radreply
+ */
+function logMessage($type, $msg, $logFile, $currPage) {
+    $date = date('M d G:i:s');
+    $msgString = $date . " " . $type . " " . $msg . " " . $currPage;
 
-if ($configValues['CONFIG_LOG_QUERIES'] == "yes") {
-	if (isset($logQuery)) {
-	        $msgQuery = $operator . " " . $logQuery;
-	        logMessage("QUERY", $msgQuery, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
-	}
+    $fp = fopen($logFile, "a");
+    if ($fp) {
+        fwrite($fp, $msgString  . "\n");
+        fclose($fp);
+        return;
+    }
+
+    echo "<div>"
+       . '<span style="color: red">error: could not open the file for writing: <strong>'
+       . $logFile . "</strong></span><br>"
+       . "Check file permissions. The file should be writable by the webserver's user/group"
+       . "</div>";
 }
 
+$logger_work = array();
 
+if ($configValues['CONFIG_LOG_PAGES'] == "yes" && isset($log) && !empty($log)) {
+    $logger_work['NOTICE'] = "$operator $log";
+}
 
-if ($configValues['CONFIG_LOG_ACTIONS'] == "yes") {
-	if (isset($logAction)) {
-	        $msgAction = $operator . " " . $logAction;
-	        logMessage("ACTION", $msgAction, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
-	}
+if ($configValues['CONFIG_LOG_QUERIES'] == "yes" && isset($logQuery) && !empty($logQuery)) {
+    $logger_work['QUERIES'] = "$operator $logQuery";
 }
 
 
-/********************************************************************************
+if ($configValues['CONFIG_LOG_ACTIONS'] == "yes" && isset($logAction) && !empty($logAction)) {
+    $logger_work['ACTIONS'] = "$operator $logAction";
+}
+
+/*
+ ********************************************************************************
  * evaluating whether we need to debug SQL queries to the database as well.
  * $logDebugSQL is set for each $sql = "query statement..." on the actual page
  * in the following form:         $logDebugSQL += $sql . "\n";
  *
- ********************************************************************************/
-if ($configValues['CONFIG_DEBUG_SQL'] == "yes") {
-	if (isset($logDebugSQL)) {
-	        $msgDebugSQL = "- SQL -" . " " . $logDebugSQL . " on page: ";
-	        logMessage("DEBUG", $msgDebugSQL, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
-	}
+ ********************************************************************************
+ */
+if ($configValues['CONFIG_DEBUG_SQL'] == "yes" && isset($logDebugSQL) && !empty($logDebugSQL)) {
+    $logger_work['DEBUG'] = "- SQL -" . " " . $logDebugSQL . " on page: ";
 }
 
-/* the continuation of the CONFIG_DEBUG_SQL actually, this prints to the page
- * being viewed */
-if ($configValues['CONFIG_DEBUG_SQL_ONPAGE'] == "yes") {
-	if (isset($logDebugSQL)) {
-			echo "<br/><br/>";
-			echo "Debugging SQL Queries: <br/>";
-			echo $logDebugSQL;
-			echo "<br/><br/>";
-		}
+foreach ($logger_work as $type => $message) {
+    logMessage($type, $message, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
 }
 
-
-
-function logMessage($type, $msg, $logFile, $currPage) {
-/*
-* @param $type               The message type, for example, NOTICE, DEBUG, ERROR, ACTION, etc...
-* @param $msg           	The message string which should be logged to the file
-* @param $logFile           The full path for the filename to write logs to
-* @param $currPage       The current page that we included from
-* @return $table              The table name, either radcheck or radreply
-*/
-
-        $date = date('M d G:i:s');
-        $msgString = $date . " " . $type . " " . $msg . " " . $currPage;
-
-        $fp = fopen($logFile, "a");
-        if ($fp) {
-        fwrite($fp, $msgString  . "\n");
-                fclose($fp);
-        } else {
-
-                echo "<font color='#FF0000'>error: could not open the file for writing:<b> $logFile </b><br/></font>";
-                        echo "Check file permissions. The file should be writable by the webserver's user/group<br/>";
-        }
-
+/* the continuation of the CONFIG_DEBUG_SQL actually, this prints to the page
+ * being viewed */
+if ($configValues['CONFIG_DEBUG_SQL_ONPAGE'] == "yes"  && isset($logDebugSQL) && !empty($logDebugSQL)) {
+	echo "<br><br>"
+       . "Debugging SQL Queries: <br>"
+       . "<pre>$logDebugSQL</pre>"
+       . "<br><br>";
 }
 
 ?>
diff --git a/include/management/actionMessages.php b/include/management/actionMessages.php
index a883dd5b..4d7f17a4 100644
--- a/include/management/actionMessages.php
+++ b/include/management/actionMessages.php
@@ -1,27 +1,41 @@
 <?php
-/*********************************************************************
-* Name: actionMessages.php
-* Author: Liran tal <liran.tal@gmail.com>
-*
-* This file provides control for messages that are printed to the
-* screen in reply to actions such as applying forms, saving data,
-* removing data and such.
-*
-*********************************************************************/
+/*
+ *********************************************************************************************************
+ * daloRADIUS - RADIUS Web Platform
+ * Copyright (C) 2007 - Liran Tal <liran@enginx.com> All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ *********************************************************************************************************
+ *
+ * Description:
+ *             This file provides control for messages that are printed to the
+ *             screen in reply to actions such as applying forms, saving data,
+ *             removing data and such.
+ * 
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
+ *
+ *********************************************************************************************************
+ */
 
-
-if ((isset($failureMsg)) && ($failureMsg != "")) {
-	echo "<div class='failure'>
-		$failureMsg
-	</div>
-	";
+// prevent this file to be directly accessed
+if (strpos($_SERVER['PHP_SELF'], '/include/management/actionMessages.php') !== false) {
+    header("Location: ../../index.php");
+    exit;
 }
 
-
-if ((isset($successMsg)) && ($successMsg != "")) {
-	echo "<div class='success'>
-		$successMsg
-	</div>
-	";
+if (isset($failureMsg) && !empty($failureMsg)) {
+	printf('<div class="failure">%s</div>', $failureMsg);
 }
 
+if (isset($successMsg) && !empty($successMsg)) {
+	printf('<div class="success">%s</div>', $successMsg);
+}
diff --git a/library/errorHandling.php b/library/errorHandling.php
index bfacb988..087bd162 100644
--- a/library/errorHandling.php
+++ b/library/errorHandling.php
@@ -12,24 +12,32 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
- * Description:
- *		global error handling for all PEAR packages, it isn't too wise to do
- *		that as I've no idea what other php applications are running on this machine
- *		even though this is really just about handling the error but still.
- *		So instead we're using the object's error handling method (see library/opendb.php)
- *		PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errorHandler');
+ * 
+ * Description:    global error handling for all PEAR packages, it isn't too wise to do
+ *                 that as I've no idea what other php applications are running on this machine
+ *                 even though this is really just about handling the error but still.
+ *                 So instead we're using the object's error handling method (see library/opendb.php)
+ *                 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errorHandler');
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:        Liran Tal <liran@enginx.com>
+ *                 Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
+// prevent this file to be directly accessed
+if (strpos($_SERVER['PHP_SELF'], '/library/errorHandling.php') !== false) {
+    header("Location: ../index.php");
+    exit;
+}
 
 function errorHandler($err) {
-	echo("<br/><b>Database error</b><br>
-		<b>Error Message: </b>" . $err->getMessage() . "<br><b>Debug info: </b>" . $err->getDebugInfo() . "<br>");
+    echo '<div class="failure"><strong>Database error</strong><br>'
+       . "Error message: <strong>" . $err->getMessage() . "</strong><br>"
+       . "Debug info: <br>" . $err->getDebugInfo()
+       . "</div>";
 }
 
 ?>
diff --git a/library/exten-boot_log.php b/library/exten-boot_log.php
index ca323c76..3b5c3fd8 100644
--- a/library/exten-boot_log.php
+++ b/library/exten-boot_log.php
@@ -13,50 +13,81 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  * Description:
- *		this script displays the radius log file ofcourse
- *		proper premissions must be applied on the log file for the web
- *		server to be able to read it
+ *        this script displays the radius log file.
+ *        Of course proper premissions must be applied on the log file for the web
+ *        server to be able to read it
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-$logfile_loc1 = '/var/log/dmesg';
-$logfile_loc2 = '/usr/local/var/log/dmesg';
-
-if (file_exists($logfile_loc1))
-	$logfile = $logfile_loc1;
-else if (file_exists($logfile_loc2))
-	$logfile = $logfile_loc2;
-else {
-	$failureMsg = "error reading log file: <br/>".
-		"looked for log file in $logfile_loc1 and $logfile_loc2 but couldn't find it.<br/>".
-		"if you know where your dmesg (boot) log file is located, set it's location in " . $_SERVER[SCRIPT_NAME];
-	exit;
+// prevent this file to be directly accessed
+$extension_file = '/library/exten-boot_log.php';
+if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
+    header("Location: ../index.php");
+    exit;
 }
-	
 
-if (is_readable($logfile) == false) {
-	$failureMsg = "error reading log file: <u>$logfile</u> <br/>".
-		"possible cause is file premissions or file doesn't exist.<br/>";
+// possible locations for radius logs
+$logfile_loc = array(
+    '/var/log/boot',
+    '/var/log/dmesg',
+    '/usr/local/var/log/dmesg'
+);
+
+// select one log file
+$logfile = "";
+
+foreach ($logfile_loc as $tmp) {
+    if (file_exists($tmp)) { 
+    $logfile = $tmp;
+        break;
+    }
+}
+
+$logfile_enc = (!empty($logfile)) ? htmlspecialchars($logfile, ENT_QUOTES, 'UTF-8') : '(none)';
+
+// check if it is empty
+if (empty($logfile)) {
+    $failureMsg = sprintf("<br><br>Error accessing log file: <strong>%s</strong><br><br>" . 
+                          "Looked for log file in <strong>%s</strong> but could not find it.<br>" .
+                          "If you know where your <em>dmesg (boot) log file</em> is located, " .
+                          "specify its location in <strong>%s</strong>",
+              $logfile_enc,
+              htmlspecialchars(implode(", ", $logfile_loc), ENT_QUOTES, 'UTF-8'),
+              htmlspecialchars($extension_file, ENT_QUOTES, 'UTF-8'));
 } else {
-                if (file_get_contents($logfile)) {
-                        $fileReversed = array_reverse(file($logfile));
-                        $counter = $bootLineCount;
-                        foreach ($fileReversed as $line) {
-                                if (preg_match("/$bootFilter/i", $line)) {
-                                        if ($counter == 0)
-                                                break;
-                                        $ret = preg_replace("/\n/i", "<br>", $line);
-                                        echo $ret;
-                                        $counter--;
-                                }
-                        }
-                }
+
+    // check if it is readable
+    if (is_readable($logfile) !== true) {
+        $failureMsg = sprintf("<br><br>Error reading log file: <strong>%s</strong>.<br><br>Is this file readable?<br>",
+                              $logfile_enc);
+    } else {
+
+        // get its content
+        $logcontent = file_get_contents($logfile);
+        if (!empty($logcontent)) {
+            $counter = $bootLineCount;
+            $filter = (!empty($bootFilter)) ? preg_quote($bootFilter, "/") : ".+";
+            $fileReversed = array_reverse(file($logfile));
+
+            echo '<div style="font-family: monospace">';
+            foreach ($fileReversed as $line) {
+                if (preg_match("/$filter/i", $line)) {
+                    if ($counter == 0) {
+                        break;
+                    }
+                    echo nl2br(htmlspecialchars($line, ENT_QUOTES, 'UTF-8'), false);
+                    $counter--;
+            }
+            }
+            echo '</div>';
+        }
+    }
 }
 
 ?>
-
diff --git a/library/exten-daloradius_log.php b/library/exten-daloradius_log.php
index 9bdebbf5..e9904e24 100644
--- a/library/exten-daloradius_log.php
+++ b/library/exten-daloradius_log.php
@@ -13,63 +13,61 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  * Description:
- *		this script displays the daloradius log file ofcourse
- *		proper premissions must be applied on the log file for the web
- *		server to be able to read it
+ *        this script displays the daloradius log file ofcourse
+ *        proper premissions must be applied on the log file for the web
+ *        server to be able to read it
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
+// prevent this file to be directly accessed
+if (strpos($_SERVER['PHP_SELF'], '/library/exten-daloradius_log.php') !== false) {
+    header("Location: ../index.php");
+    exit;
+}
 
-if (isset($configValues['CONFIG_LOG_FILE'])) {
-	$logfile = $configValues['CONFIG_LOG_FILE'];
-
-	if (!file_exists($logfile)) {
-
-                $failureMsg = "error reading log file: <b>$logfile</b><br/>".
-				"looked for log file in $logfile but couldn't find it.<br/>".
-				"if you know where your daloradius log file is located, set it's location in your library/daloradius.conf file";
-	} else {
-
-
-		if (is_readable($logfile) == false) {
+// check if daloradius logfile is set
+if (array_key_exists('CONFIG_LOG_FILE', $configValues) && isset($configValues['CONFIG_LOG_FILE'])) {
 
-	                $failureMsg = "error reading log file: <b>$logfile</b><br/>".
-				"possible cause is file premissions or file doesn't exist.<br/>";
+    $logfile = $configValues['CONFIG_LOG_FILE'];
+    $logfile_enc = (!empty($logfile)) ? htmlspecialchars($logfile, ENT_QUOTES, 'UTF-8') : '(none)';
 
-		} else {
-		    if (file_get_contents($logfile)) {
-				$fileReversed = array_reverse(file($logfile));
-				$counter = $daloradiusLineCount;
+    // check if file exists
+    if (!file_exists($logfile)) {
+        $failureMsg = sprintf("<br><br>Error accessing log file: <strong>%s</strong><br><br>"
+                            . "Looked for log file in <strong>%s</strong> but could not find it.<br>"
+                            . "If you know where your <em>daloradius log file</em> is located, "
+                            . "specify its location in your <strong>library/daloradius.conf.php</strong> file",
+                              $logfile_enc, $logfile_enc);
+    } else {
+        // check if it is readable
+        if (is_readable($logfile) !== true) {
+            $failureMsg = sprintf("<br><br>Error reading log file: <strong>%s</strong>.<br><br>Is this file readable?<br>",
+                                  $logfile_enc);
+        } else {
+            // get its content
+            $logcontent = file_get_contents($logfile);
+            if (!empty($logcontent)) {
+                $counter = $daloradiusLineCount;
+                $fileReversed = array_reverse(file($logfile));
 
-				// This doesn't take in any filter value
-				// from the forms.
-				// This takes in the log count though.
-				foreach ($fileReversed as $line) {
-					if ($counter == 0) {
-						break;
-					}
-					echo $line . "<br>";
-					$counter--;
-				}
-				// Old Code
-				// $counter = $daloradiusLineCount;
-				// foreach ($fileReversed as $line) {
-				// 	if (preg_match("/$daloradiusFilter/i", $line)) {
-				// 		if ($counter == 0)
-				// 			break;
-				// 		$ret = eregi_replace("\n", "<br>", $line);
-				// 		echo $ret;
-				// 		$counter--;
-				// 	}
-				// }
-			}
-		}
-	}
+                echo '<div style="font-family: monospace">';
+                foreach ($fileReversed as $line) {
+                    if ($counter == 0) {
+                        break;
+                    }
+                    echo nl2br(htmlspecialchars($line, ENT_QUOTES, 'UTF-8'), false);
+                    $counter--;
+                
+                }
+                echo '</div>';
+            }
+        }
+    }
 }
-
 ?>
diff --git a/library/exten-maint-radclient.php b/library/exten-maint-radclient.php
index 6f3954d9..9ad5e016 100644
--- a/library/exten-maint-radclient.php
+++ b/library/exten-maint-radclient.php
@@ -13,108 +13,112 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  * Description:
- *		This code allows for running the 'radtest' binary tool provided with freeradius
- *		for performing a dry-run check to see if a user is able to successfully login
- *		or that there may be problems connecting.
+ *        This code allows for running the 'radtest' binary tool provided with freeradius
+ *        for performing a dry-run check to see if a user is able to successfully login
+ *        or that there may be problems connecting.
  *
- * Authors:	Liran Tal <liran@enginx.com>
- *		Giso Kegal <kegel@barum.de>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Giso Kegal <kegel@barum.de>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
 
+// prevent this file to be directly accessed
+$extension_file = '/library/exten-maint-radclient.php';
+if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
+    header("Location: ../index.php");
+    exit;
+}
+
+$extension_file_enc = htmlspecialchars($extension_file, ENT_QUOTES, 'UTF-8');
+
 // user_auth function
 // sends to the radius server an authentication request packet (for the sake of testing a user)
-// $radiusaddr	- the server address, this would most likely be the radius server IP Address/Hostname
+// $radiusaddr  - the server address, this would most likely be the radius server IP Address/Hostname
 // $radiusport  - the server's port number, radius server's port number (1812 or the old port for auth)
-// $options	- the options passed to the radclient program
-// $command	- the command string that radclient sends (auth, acct, status, coa, disconnect), by default this functions does 'auth'
-function user_auth($options,$user,$pass,$radiusaddr,$radiusport,$secret,$command="auth",$additional="") {
-
-	$user = escapeshellarg($user);
-	$pass = escapeshellarg($pass);
-
-	$args = escapeshellarg("$radiusaddr:$radiusport")." ".escapeshellarg($command).
-		" ".escapeshellarg($secret);
-	$query = "User-Name=$user,User-Password=$pass";
-
-	$radclient = "radclient"; 		// or you can change this with the full path if the binary radcilent program can not be
-									// found within your $PATH variable
-
-	$radclient_options = "-c ".escapeshellarg($options['count']).
-				" -n ".escapeshellarg($options['requests']).
-				" -r ".escapeshellarg($options['retries']).
-				" -t ".escapeshellarg($options['timeout']).
-				" ".$options['debug'];
-
-	if ($options['dictionary'])
-		$radclient_options .= " -d ".escapeshellarg($options['dictionary']);
-
-	$cmd = "echo ".escapeshellcmd($query)." | $radclient $radclient_options $args 2>&1";
-
-	$print_cmd = "<b>Executed:</b><br/>$cmd<br/><br/><b>Results:</b><br/>";
-	$res = shell_exec($cmd);
-
-	if ($res == "") {
-		echo "<b>Error:</b> Command did not return any results<br/>";
-		echo "Please check that you have the radclient binary program installed and that
-			it is found in your \$PATH variable<br/>
-			You may also consult the file library/exten-maint-radclient.php for other problems<br/>
-		";
-	}
-
-	// todo better layout
-	$output_html = nl2br($res);
-	return $print_cmd . $output_html;
+// $options     - the options passed to the radclient program
+// $command     - the command string that radclient sends (auth, acct, status, coa, disconnect), by default this functions does 'auth'
+function user_auth($options, $user, $pass, $radiusaddr, $radiusport, $secret, $command="auth", $additional="") {
+
+    $user = escapeshellarg($user);
+    $pass = escapeshellarg($pass);
+    $args = escapeshellarg("$radiusaddr:$radiusport") . " " . escapeshellarg($command) . " " . escapeshellarg($secret);
+    $query = "User-Name=$user,User-Password=$pass";
+
+    $radclient = "radclient";       // or you can change this with the full path if the binary radcilent program can not be
+                                    // found within your $PATH variable
+
+    $radclient_options = " -c " . escapeshellarg($options['count'])
+                       . " -n " . escapeshellarg($options['requests'])
+                       . " -r " . escapeshellarg($options['retries'])
+                       . " -t " . escapeshellarg($options['timeout'])
+                       . " " . $options['debug'];
+
+    if ($options['dictionary']) {
+        $radclient_options .= " -d " . escapeshellarg($options['dictionary']);
+    }
+
+    $cmd = sprintf('echo "%s" | %s %s %s 2>&1', escapeshellcmd($query), $radclient, $radclient_options, $args);
+    $res = shell_exec($cmd);
+
+    $print_cmd = "<strong>Executed:</strong><br>$cmd<br>";
+    if ($res == "") {
+        echo "<b>Error:</b> Command did not return any results.<br>"
+           . "Please check that you have the <em>radclient binary program</em> installed and that it is found in your \$PATH variable<br>"
+           . "You may also consult the file <strong>$extension_file_enc</strong> for other problems<br>";
+           return $print_cmd;
+    }
+
+    $output_html = '<br><strong>Results:</strong><br><div style="font-family: monospace">' . nl2br($res) . '</div>';
+    return $print_cmd . $output_html;
 }
 
 
 // user_disconnect function
 // sends to the NAS a CoA (Change of Authorization) or a CoD (Disconnect) packet
-// $nasaddr	- NAS address to receive the coa or disconnect request packet
-// $nasport	- NAS Port address (depends on the configuration on the NAS, this may be a different port for either CoA or Disconnect packets).
-function user_disconnect($options,$user,$nasaddr,$nasport="3779",$nassecret,$command="disconnect",$additional="") {
-
-	$user = escapeshellarg($user);
-
-	$args = escapeshellarg("$nasaddr:$nasport")." ".escapeshellarg($command)." ".
-			escapeshellarg($nassecret);
-	$query = "User-Name=$user";
-
-	if (!empty($additional)) {
-		$query .= ','.$additional;
-	}
-
-	$radclient = "radclient"; 		// or you can change this with the full path if the binary radcilent program can not be
-						// found within your $PATH variable
-
-	$radclient_options = "-c ".escapeshellarg($options['count']).
-				" -n ".escapeshellarg($options['requests']).
-				" -r ".escapeshellarg($options['retries']).
-				" -t ".escapeshellarg($options['timeout']).
-				" ".$options['debug'];
-
-	if ($options['dictionary'])
-		$radclient_options .= " -d ".escapeshellarg($options['dictionary']);
-
-	$cmd = "echo \"".escapeshellcmd($query)."\" | $radclient $radclient_options $args 2>&1";
-	$print_cmd = "<b>Executed:</b><br/>$cmd<br/><br/><b>Results:</b><br/>";
-	$res = shell_exec($cmd);
-
-	if ($res == "") {
-		echo "<b>Error:</b> Command did not return any results<br/>";
-		echo "Please check that you have the radclient binary program installed and that
-			it is found in your \$PATH variable<br/>
-			You may also consult the file library/exten-maint-radclient.php for other problems<br/>
-		";
-	}
-
-	// todo better layout
-	$output_html = nl2br($res);
-	return $print_cmd . $output_html;
+// $nasaddr    - NAS address to receive the coa or disconnect request packet
+// $nasport    - NAS Port address (depends on the configuration on the NAS, this may be a different port for either CoA or Disconnect packets).
+function user_disconnect($options, $user, $nasaddr, $nasport="3779", $nassecret, $command="disconnect", $additional="") {
+
+    $user = escapeshellarg($user);
+
+    $args = escapeshellarg("$nasaddr:$nasport") . " " . escapeshellarg($command). " " . escapeshellarg($nassecret);
+    $query = "User-Name=$user";
+
+    if (!empty($additional)) {
+        $query .= ',' . $additional;
+    }
+
+    $radclient = "radclient";    // or you can change this with the full path if the binary radcilent program can not be
+                                 // found within your $PATH variable
+
+    $radclient_options = " -c " . escapeshellarg($options['count'])
+                       . " -n " . escapeshellarg($options['requests'])
+                       . " -r " . escapeshellarg($options['retries'])
+                       . " -t " . escapeshellarg($options['timeout'])
+                       . " " . $options['debug'];
+
+    if ($options['dictionary']) {
+        $radclient_options .= " -d " . escapeshellarg($options['dictionary']);
+    }
+
+    $cmd = sprintf('echo "%s" | %s %s %s 2>&1', escapeshellcmd($query), $radclient, $radclient_options, $args);
+    $res = shell_exec($cmd);
+    
+    $print_cmd = "<strong>Executed:</strong><br>$cmd<br>";
+    if ($res == "") {
+        echo "<b>Error:</b> Command did not return any results.<br>"
+           . "Please check that you have the <em>radclient binary program</em> installed and that it is found in your \$PATH variable<br>"
+           . "You may also consult the file <strong>$extension_file_enc</strong> for other problems<br>";
+           return $print_cmd;
+    }
+    
+    $output_html = '<br><strong>Results:</strong><br><div style="font-family: monospace">' . nl2br($res) . '</div>';
+    return $print_cmd . $output_html;
 }
 
 ?>
diff --git a/library/exten-radius_log.php b/library/exten-radius_log.php
index 918bc458..20c24594 100644
--- a/library/exten-radius_log.php
+++ b/library/exten-radius_log.php
@@ -13,68 +13,79 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  * Description:
- *		this script displays the radius log file ofcourse
- *		proper premissions must be applied on the log file for the web
- *		server to be able to read it
+ *        this script displays the radius log file.
+ *              Of course proper premissions must be applied
+ *              on the log file for the web server to be able to read it
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:     Liran Tal <liran@enginx.com>
+ *              Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
- 
 
-$logfile_loc = array();
-$logfile_loc[1] = '/var/log/freeradius/radius.log';
-$logfile_loc[2] = '/usr/local/var/log/radius/radius.log';
-$logfile_loc[3] = '/var/log/radius/radius.log';
+// prevent this file to be directly accessed
+$extension_file = '/library/exten-radius_log.php';
+if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
+    header("Location: ../index.php");
+    exit;
+}
+
+// possible locations for radius logs
+$logfile_loc = array(
+    '/var/log/freeradius/radius.log',
+    '/usr/local/var/log/radius/radius.log',
+    '/var/log/radius/radius.log'
+);
+
+// select one log file
+$logfile = "";
 
 foreach ($logfile_loc as $tmp) {
-	if (file_exists($tmp)) { 
-		$logfile = $tmp; 
-		break;
-	}
+    if (file_exists($tmp)) { 
+    $logfile = $tmp;
+        break;
+    }
 }
- 
 
+$logfile_enc = (!empty($logfile)) ? htmlspecialchars($logfile, ENT_QUOTES, 'UTF-8') : '(none)';
+
+// check if it is empty
 if (empty($logfile)) {
-	echo "<br/><br/>
-		error reading log file: <br/><br/>
-		looked for log file in '".implode(", ", $logfile_loc)."' but couldn't find it.<br/>
-		if you know where your freeradius log file is located, set it's location in " . $_SERVER['SCRIPT_NAME'];
-	exit;
+    printf("<br><br>Error accessing log file: <strong>%s</strong>.<br><br>"
+         . "Looked for log file in <strong>%s</strong> but could not find it.<br>"
+         . "If you know where your <em>freeradius log file</em> is located, "
+         . "specify its location in <strong>%s</strong>",
+           $logfile_enc, htmlspecialchars(implode(", ", $logfile_loc), ENT_QUOTES, 'UTF-8'), $logfile_enc);
+    exit;
 }
-	
 
-if (is_readable($logfile) == false) {
-	echo "<br/><br/>
-		error reading log file: <u>$logfile</u> <br/><br/>
-		possible cause is file premissions or file doesn't exist.<br/>";
-} else {
-    if (file_get_contents($logfile)) {
+// check if it is readable
+if (is_readable($logfile) !== true) {
+    $failureMsg = sprintf("<br><br>Error reading log file: <strong>%s</strong>.<br><br>Is this file readable?<br>",
+                          $logfile_enc);
+    exit;
+}
+
+// get its content
+$logcontent = file_get_contents($logfile);
+if (!empty($logcontent)) {
+    $counter = $radiusLineCount;
+    $filter = (!empty($radiusFilter)) ? preg_quote($radiusFilter, "/") : ".+";
+    $fileReversed = array_reverse(file($logfile));
 
-     $counter = $radiusLineCount;
-     $fileReversed = array_reverse(file($logfile));
-     foreach ($fileReversed as $line) {
-        if($counter == 0) {
-          break;
+    echo '<div style="font-family: monospace">';
+    foreach ($fileReversed as $line) {
+    if (preg_match("/$filter/i", $line)) {
+        if ($counter == 0) {
+            break;
         }
-        echo $line . "<br>";
+        echo nl2br(htmlspecialchars($line, ENT_QUOTES, 'UTF-8'), false);
         $counter--;
-      }
-      // $counter = $radiusLineCount;
-      // foreach ($fileReversed as $line) {
-      //         if (preg_match("/$radiusFilter/i", $line)) {
-      //                 if ($counter == 0)
-      //                         break;
-      //                 $ret = eregi_replace("\n", "<br>", $line);
-      //                 echo $ret;
-      //                 $counter--;
-      //         }
-      // }
+        }
     }
+    echo '</div>';
 }
 
 ?>
-
diff --git a/library/exten-radius_server_info.php b/library/exten-radius_server_info.php
index 08ef4cea..d1ba14ce 100644
--- a/library/exten-radius_server_info.php
+++ b/library/exten-radius_server_info.php
@@ -13,43 +13,45 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  * Description:
- *		this script runs a check to see if freeradius is up and running
-*		the check is done by looking for a 'radius' process listening
-*		on any socket interface. clumsy, but that's what we got for now
+ *        this script uses pgrep to check if services stored
+ *              in $services_to_check are running
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *              Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
- 
-function check_service($sname) {
-	if ($sname != '') {
-		system("pgrep ".escapeshellarg($sname)." >/dev/null 2>&1", $ret_service);
-		if ($ret_service == 0) {
-			return "Enabled";
-		} else {
-			return "Disabled";
-		}
-	} else {
-		return "no service name";
-	}
+
+// prevent this file to be directly accessed
+if (strpos($_SERVER['PHP_SELF'], '/library/exten-radius_server_info.php') !== false) {
+    header("Location: ../index.php");
+    exit;
+}
+
+// given the $service_name, this function returns "Running" if that service is running
+function check_service($service_name) {
+    if (empty($service_name)) {
+        return "no service name";
+    }
+
+    $command = sprintf("pgrep %s", escapeshellarg($service_name));
+    exec($command, $output, $result_code);
+    return ($result_code === 0) ? "Running" : "Not running";
 }
 
+$services_to_check = array("FreeRADIUS", "MySQL", "MariaDB");
+
 ?>
 
+<h3>Service Status</h3>
+<table class="summarySection">
 <?php
-	echo "<h3>Service Status</h3>";
+    $format = '<tr><td class="summaryKey">%s</td><td class="summaryValue"><span class="sleft">%s'
+            . "</span></td></tr>\n";
+    foreach ($services_to_check as $service_name) {
+        printf($format, $service_name, check_service(strtolower($service_name)));
+    }
 ?>
-
-<table class='summarySection'>
-  <tr>
-    <td class='summaryKey'> Radius </td>
-    <td class='summaryValue'><span class='sleft'><?php echo check_service("radius"); ?></span> </td>
-  </tr>
-  <tr>
-    <td class='summaryKey'> Mysql </td>
-    <td class='summaryValue'><span class='sleft'><?php echo check_service("mysql");  ?></span> </td>
-  </tr>
 </table>
diff --git a/library/exten-server_info.php b/library/exten-server_info.php
index dedc52d6..f80a888e 100644
--- a/library/exten-server_info.php
+++ b/library/exten-server_info.php
@@ -13,145 +13,167 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  * Description:
- * 		this script process some important server information and displays it
+ *         this script process some important server information and displays it
  *
- * Authors:	Liran Tal <liran@enginx.com>
- *		Carlos Cesario <carloscesario@gmail.com>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Carlos Cesario <carloscesario@gmail.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
-	include_once('include/management/pages_common.php');
+
+// prevent this file to be directly accessed
+$extension_file = '/library/exten-server_info.php';
+if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
+    header("Location: ../index.php");
+    exit;
+}
+
+include_once('include/management/pages_common.php');
+
+// returns system name and version
+function get_system_name_and_version() {
+    $command = "cat /etc/*release | grep ^NAME\= | cut -d'=' -f2- | tr -d '\"'";
+    exec($command, $output, $result_code);
+    if ($result_code !== 0) {
+        return "(n/d)";
+    }
+    
+    $result = $output[0];
+    $output = null;
+    $result_code = null;
+    
+    $command = "cat /etc/*release | grep ^VERSION\= | cut -d'=' -f2- | tr -d '\"'";
+    exec($command, $output, $result_code);
+    if ($result_code === 0) {
+        $result .= sprintf(", version %s", $output[0]);
+    }
+    
+    return $result;
+}
+
 
 // Display uptime system
 // @return string Return uptime system
 function uptime() {
-	$file_name = "/proc/uptime";
-
-	$fopen_file = fopen($file_name, 'r');
-	$buffer = explode(' ', fgets($fopen_file, 4096));
-	fclose($fopen_file);
-
-	$sys_ticks = trim($buffer[0]);
-	$min = $sys_ticks / 60;
-	$hours = $min / 60;
-	$days = floor($hours / 24);
-	$hours = floor($hours - ($days * 24));
-	$min = floor($min - ($days * 60 * 24) - ($hours * 60));
-	$result = "";
-
-	if ($days != 0) {
-		if ($days > 1)
-			$result = "$days " . " days ";
-		else
-			$result = "$days " . " day ";
-	}
-
-	if ($hours != 0) {
-		if ($hours > 1)
-			$result .= "$hours " . " hours ";
-		else
-			$result .= "$hours " . " hour ";
-	}
-
-	if ($min > 1 || $min == 0)
-		$result .= "$min " . " minutes ";
-	elseif ($min == 1)
-		$result .= "$min " . " minute ";
-
-	return $result;
+    $file_name = "/proc/uptime";
+
+    $fopen_file = fopen($file_name, 'r');
+    $buffer = explode(' ', fgets($fopen_file, 4096));
+    fclose($fopen_file);
+
+    $sys_ticks = trim($buffer[0]);
+    $min = $sys_ticks / 60;
+    $hours = $min / 60;
+    $days = floor($hours / 24);
+    $hours = floor($hours - ($days * 24));
+    $min = floor($min - ($days * 60 * 24) - ($hours * 60));
+    $result = "";
+
+    if ($days != 0) {
+        $result .= $days;
+        $result .= ($days > 1) ? " days " : " day ";
+    }
+
+    if ($hours != 0) {
+        $result .= $hours;
+        $result .= ($hours > 1) ? " hours " : " hour ";
+    }
+
+    if ($min > 1 || $min == 0)
+        $result .= "$min " . " minutes ";
+    elseif ($min == 1)
+        $result .= "$min " . " minute ";
+
+    return $result;
 }
 
 
 // Display hostname system
 // @return string System hostname or none
 function get_hostname() {
-	$file_name = "/proc/sys/kernel/hostname";
+    $file_name = "/proc/sys/kernel/hostname";
 
-	if ($fopen_file = fopen($file_name, 'r')) {
-		$result = trim(fgets($fopen_file, 4096));
-		fclose($fopen_file);
-	} else {
-		$result = "(none)";
-	}
+    if ($fopen_file = fopen($file_name, 'r')) {
+        $result = trim(fgets($fopen_file, 4096));
+        fclose($fopen_file);
+    } else {
+        $result = "(n/d)";
+    }
 
-	return $result;
+    return $result;
 }
 
 
 // Display currenty date/time
 // @return string Current system date/time or none
 function get_datetime() {
-	if ($today = date("F j, Y, g:i a")) {
-		$result = $today;
-	} else {
-		$result = "(none)";
-	}
-
-	return $result;
+    $today = date("F j, Y, g:i a");
+    return ($today) ? $today : "(n/d)";
 }
 
 
 
 // Get System Load Average
 // @return array System Load Average
 function get_system_load() {
-	$file_name = "/proc/loadavg";
-	$result = "";
-	$output = "";
+    $file_name = "/proc/loadavg";
+    $result = "";
+    $output = "";
 
-	// get the /proc/loadavg information
-	if ($fopen_file = fopen($file_name, 'r')) {
-		$result = trim(fgets($fopen_file, 256));
-		fclose($fopen_file);
-	} else {
-		$result = "(none)";
-	}
+    // get the /proc/loadavg information
+    if ($fopen_file = fopen($file_name, 'r')) {
+        $result = trim(fgets($fopen_file, 256));
+        fclose($fopen_file);
+    } else {
+        $result = "(n/d)";
+    }
 
-	$loadavg = explode(" ", $result);
-	$output .= $loadavg[0] . " " . $loadavg[1] . " " . $loadavg[2] . "<br/>";
+    $loadavg = explode(" ", $result);
+    $output .= $loadavg[0] . " " . $loadavg[1] . " " . $loadavg[2] . "<br/>";
 
 
-	// get information the 'top' program
-	$file_name = "top -b -n1 | grep \"Tasks:\" -A1";
-	$result = "";
+    // get information the 'top' program
+    $file_name = "top -b -n1 | grep \"Tasks:\" -A1";
+    $result = "";
 
-	if ($popen_file = popen($file_name, 'r')) {
-		$result = trim(fread($popen_file, 2048));
-		pclose($popen_file);
-	} else {
-		$result = "(none)";
-	}
+    if ($popen_file = popen($file_name, 'r')) {
+        $result = trim(fread($popen_file, 2048));
+        pclose($popen_file);
+    } else {
+        $result = "(n/d)";
+    }
 
-	$result = str_replace("\n", "<br/>", $result);
-	$output .= $result;
+    $result = str_replace("\n", "<br/>", $result);
+    $output .= $result;
 
-	return $output;
+    return $output;
 }
 
 
 // Get Memory System MemTotal|MemFree
 // @return array Memory System MemTotal|MemFree
 function get_memory() {
-	$file_name = "/proc/meminfo";
-	$mem_array = array();
-
-	$buffer = file($file_name);
-
-	while (list($key, $value) = each($buffer)) {
-		if (strpos($value, ':') !== false) {
-			$match_line = explode(':', $value);
-			$match_value = explode(' ', trim($match_line[1]));
-			if (is_numeric($match_value[0])) {
-				$mem_array[trim($match_line[0])] = trim($match_value[0]);
-			}
-		}
-	}
-
-	return $mem_array;
+    $file_name = "/proc/meminfo";
+    $mem_array = array();
+
+    $buffer = file($file_name);
+
+    while (list($key, $value) = each($buffer)) {
+        if (strpos($value, ':') !== false) {
+            $match_line = explode(':', $value);
+            $match_value = explode(' ', trim($match_line[1]));
+            if (is_numeric($match_value[0])) {
+                $mem_array[trim($match_line[0])] = trim($match_value[0]);
+            }
+        }
+    }
+
+    return $mem_array;
 }
 
 
 //Get FreeDiskSpace
 function get_hdd_freespace() {
@@ -162,204 +184,183 @@ return $df;
 
 // Convert value to MB
 // @param decimal $value
 // @return int Memory MB
 function convert_ToMB($value) {
-	return round($value / 1024) . " MB\n";
+    return round($value / 1024) . " MB\n";
 }
 
 
 
 // Get all network names devices (eth[0-9])
 // @return array Get list network name interfaces
 function get_interface_list() {
-	$devices = array();
-	$file_name = "/proc/net/dev";
-
-	if ($fopen_file = fopen($file_name, 'r')) {
-		while ($buffer = fgets($fopen_file, 4096)) {
-			if (preg_match("/eth[0-9][0-9]*/i", trim($buffer), $match)) {
-				$devices[] = $match[0];
-			}
-		}
-		$devices = array_unique($devices);
-		sort($devices);
-		fclose ($fopen_file);
-	}
-	return $devices;
+    $devices = array();
+    $file_name = "/proc/net/dev";
+
+    if ($fopen_file = fopen($file_name, 'r')) {
+        while ($buffer = fgets($fopen_file, 4096)) {
+            if (preg_match("/eth[0-9][0-9]*/i", trim($buffer), $match)) {
+                $devices[] = $match[0];
+            }
+        }
+        $devices = array_unique($devices);
+        sort($devices);
+        fclose ($fopen_file);
+    }
+    return $devices;
 }
 
 
 
 // Get ip address
 // @param string $ifname
 // @return string Ip address or (none)
 function get_ip_addr($ifname) {
-	$command_name = "/sbin/ifconfig $ifname";
-	$ifip = "";
-
-	exec($command_name , $command_result);
-
-	$ifip = implode($command_result, "\n");
-	if (preg_match("/inet addr:[0-9\.]*/i", $ifip, $match)) {
-		$match = explode(":", $match[0]);
-		return $match[1];
-	} elseif (preg_match("/inet [0-9\.]*/i", $ifip, $match)) {
-		$match = explode(" ", $match[0]);
-		return $match[1];
-	} else {
-		return "(none)";
-	}
+    $command_formats = array(
+        '(ip addr show %s || /sbin/ip addr show %s) | grep inet | grep -v inet6 | sed -E "s/^\s+//g" | cut -d" " -f2 | cut -d"/" -f1',
+        '(ifconfig %s || /sbin/ifconfig %s) | grep -oE "inet ([0-9]{1,3}\.?){4}" | cut -d" " -f2'
+    );
+
+    foreach ($command_formats as $format) {
+        $command = sprintf($format, escapeshellarg($ifname), escapeshellarg($ifname));
+        exec($command, $output, $result_code);
+        if ($result_code === 0) {
+            return $output[0];
+        }
+    }
+
+    return "(n/d)";
 }
 
 // Get mac address
 // @param string $ifname
 // @return string Mac address or (none)
 function get_mac_addr($ifname) {
-	$command_name = "/sbin/ifconfig $ifname";
-	$ifip = "";
-
-	exec($command_name , $command_result);
-
-	$ifmac = implode($command_result, "\n");
-	if (preg_match("/hwaddr [0-9A-F:]*/i", $ifmac, $match)) {
-		$match = explode(" ", $match[0]);
-		return $match[1];
-	} elseif (preg_match("/ether [0-9A-F:]*/i", $ifmac, $match)) {
-		$match = explode(" ", $match[0]);
-		return $match[1];
-	} else {
-		return "(none)";
-	}
+    $command_formats = array(
+        '(ip addr show %s || /sbin/ip addr show %s) | grep "link/ether" | sed -E "s/^\s+//g" | cut -d" " -f2',
+        '(ifconfig %s || /sbin/ifconfig %s) | grep "ether" | sed -E "s/^\s+//g" | cut -d" " -f2'
+    );
+
+    foreach ($command_formats as $format) {
+        $command = sprintf($format, escapeshellarg($ifname), escapeshellarg($ifname));
+        exec($command, $output, $result_code);
+
+        if ($result_code === 0 && preg_match("/^([0-9A-F]{2}\:){5}[0-9A-F]{2}$/i", $output[0])) {
+            return $output[0];
+        }
+    }
+
+    return "(n/d)";
 }
 
 
 // Get netmask address
 // @param string $ifname
 // @return string Netmask address or (none)
 function get_mask_addr($ifname) {
-	$command_name = "/sbin/ifconfig $ifname";
-	$ifmask = "";
-
-	exec($command_name , $command_result);
-
-	$ifmask = implode($command_result, "\n");
-	if (preg_match("/mask:[0-9\.]*/i", $ifmask, $match)) {
-		$match = explode(":", $match[0]);
-		return $match[1];
-	} elseif (preg_match("/netmask [0-9\.]*/i", $ifmask, $match)) {
-		$match = explode(" ", $match[0]);
-		return $match[1];
-	} else {
-		return "(none)";
-	}
+    $command_formats = array(
+        'echo -n "/"; (ip addr show %s || /sbin/ip addr show %s) | grep inet | grep -v inet6 | sed -E "s/^\s+//g" | cut -d" " -f2 | cut -d"/" -f2',
+        '(ifconfig %s || /sbin/ifconfig %s) | grep -oE "netmask ([0-9]{1,3}\.?){4}" | cut -d" " -f2'
+    );
+    
+    foreach ($command_formats as $format) {
+        $command = sprintf($format, escapeshellarg($ifname), escapeshellarg($ifname));
+        exec($command, $output, $result_code);
+        if ($result_code === 0) {
+            return $output[0];
+        }
+    }
+    
+    return "(n/d)";
 }
 
-?>
+// memory info
+$meminfo = get_memory();
+$memused = ($meminfo['MemTotal'] - $meminfo['MemFree']);
 
+// hdd info
+$hddfreespace = get_hdd_freespace();
+
+// network interfaces info
+$iflist = get_interface_list();
 
-<?php
-	echo "<h3>General Information</h3>";
 ?>
 
-<table class='summarySection'>
+<h3>General Information</h3>
+<table class="summarySection">
   <tr>
-    <td class='summaryKey'> Uptime </td>
-    <td class='summaryValue'><span class='sleft'><?php echo uptime(); ?></span> </td>
+    <td class="summaryKey">System distro</td>
+    <td class="summaryValue"><span class="sleft"><?= get_system_name_and_version() ?></span></td>
   </tr>
+    
   <tr>
-    <td class='summaryKey'> System Load </td>
-    <td class='summaryValue'><span class='sleft'><?php echo get_system_load(); ?></span> </td>
+    <td class="summaryKey">Uptime</td>
+    <td class="summaryValue"><span class="sleft"><?= uptime() ?></span></td>
   </tr>
   <tr>
-    <td class='summaryKey'> Hostname </td>
-    <td class='summaryValue'><span class='sleft'><?php echo get_hostname(); ?></span> </td>
+    <td class="summaryKey">System Load</td>
+    <td class="summaryValue"><span class="sleft"><?= get_system_load() ?></span></td>
   </tr>
   <tr>
-    <td class='summaryKey'> Current Date </td>
-    <td class='summaryValue'><span class='sleft'><?php echo get_datetime(); ?></span> </td>
+    <td class="summaryKey">Hostname</td>
+    <td class="summaryValue"><span class="sleft"><?= get_hostname() ?></span></td>
+  </tr>
+  <tr>
+    <td class="summaryKey">Current Date</td>
+    <td class="summaryValue"><span class="sleft"><?= get_datetime() ?></span></td>
   </tr>
 </table>
 
 
-<?php
-	echo "<h3>Memory Information</h3>";
-	$meminfo = get_memory();
-?>
-
-
-<table class='summarySection'>
+<h3>Memory Information</h3>
+<table class="summarySection">
   <tr>
-    <td class='summaryKey'> Mem. Total </td>
-    <td class='summaryValue'><span class='sleft'><?php echo convert_ToMB ($meminfo['MemTotal']); ?></span> </td>
+    <td class="summaryKey">Mem. Total</td>
+    <td class="summaryValue"><span class="sleft"><?= convert_ToMB($meminfo['MemTotal']) ?></span></td>
   </tr>
   <tr>
-    <td class='summaryKey'> Mem. Free </td>
-    <td class='summaryValue'><span class='sleft'><?php echo convert_ToMB ($meminfo['MemFree']); ?></span> </td>
+    <td class="summaryKey">Mem. Free</td>
+    <td class="summaryValue"><span class="sleft"><?= convert_ToMB($meminfo['MemFree']) ?></span></td>
   </tr>
   <tr>
-    <td class='summaryKey'> Mem. Used </td>
-    <td class='summaryValue'>
-		<span class='sleft'>
-			<?php
-				$memused = ($meminfo['MemTotal'] - $meminfo['MemFree']);
-				echo convert_ToMB ($memused);
-			?>
-		</span> </td>
+    <td class="summaryKey">Mem. Used</td>
+    <td class="summaryValue"><span class="sleft"><?= convert_ToMB($memused) ?></span></td>
   </tr>
 </table>
 
 
-<?php
-	echo "<h3>Harddrive Information</h3>";
-	$hddfreespace = get_hdd_freespace();
-?>
+<h3>Harddrive Information</h3>
+<table class="summarySection">
+  <tr>
+    <td class="summaryKey">Free Drive Space</td>
+    <td class="summaryValue"><span class="sleft"><?= toxbyte($hddfreespace) ?></span></td>
+  </tr>
+</table>
 
+<h3>Network Interfaces</h3>
 
-<table class='summarySection'>
+<?php
+    foreach ($iflist as $ifname) {
+?>
+<table class="summarySection">    
   <tr>
-    <td class='summaryKey'> Free Drive Space </td>
-    <td class='summaryValue'><span class='sleft'><?php echo toxbyte ($hddfreespace); ?></span> </td>
+    <td class="summaryKey">Interface</td>
+    <td class="stitle"><?= $ifname ?></td>
+  </tr>
+  <tr>
+    <td class="summaryKey">Ip</td>
+    <td class="summaryValue"><span class="sleft"><?= get_ip_addr($ifname) ?></span></td>
+  </tr>
+  <tr>
+    <td class="summaryKey">Mask</td>
+    <td class="summaryValue"><span class="sleft"><?= get_mask_addr($ifname) ?></span></td>
+  </tr>
+  <tr>
+    <td class="summaryKey">MAC address</td>
+    <td class="summaryValue"><span class="sleft"><?= get_mac_addr($ifname) ?></span></td>
   </tr>
-
 </table>
 
 <?php
-	echo "<h3>Network Interfaces</h3>";
-	$iflist = get_interface_list();
-
-	foreach ($iflist as $ifname) {
-			echo "\t<table class='summarySection'>\n";
-			echo "\t<tr>\n";
-			echo "\t\t<td class='summaryKey'></td>\n";
-			echo "\t\t<td class='stitle'>\n";
-			echo "\t\t\t$ifname\n";
-			echo "\t\t</td>\n";
-			echo "\t</tr>\n";
-			echo "\t<tr>\n";
-			echo "\t<tr>\n";
-			echo "\t\t<td class='summaryKey'>\n";
-			echo "\t\t\tIp\n";
-			echo "\t\t</td>\n";
-			echo "\t\t<td class='summaryValue'>\n";
-			echo "\t\t\t".get_ip_addr($ifname)."\n";
-			echo "\t\t</td>\n";
-			echo "\t</tr>\n";
-			echo "\t<tr>\n";
-			echo "\t\t<td class='summaryKey'>\n";
-			echo "\t\t\tMask\n";
-			echo "\t\t</td>\n";
-			echo "\t\t<td class='summaryValue'>\n";
-			echo "\t\t\t".get_mask_addr($ifname)."\n";
-			echo "\t\t</td>\n";
-			echo "\t</tr>\n";
-			echo "\t<tr>\n";
-			echo "\t\t<td class='summaryKey'>\n";
-			echo "\t\t\tMAC address\n";
-			echo "\t\t<td class='summaryValue'>\n";
-			echo "\t\t\t".get_mac_addr($ifname)."\n";
-			echo "\t\t</td>\n";
-			echo "\t</tr>\n";
-		}
-
-	echo "\t</table>\n";
+    }
 ?>
diff --git a/library/exten-syslog_log.php b/library/exten-syslog_log.php
index 175f04df..ed5d68dd 100644
--- a/library/exten-syslog_log.php
+++ b/library/exten-syslog_log.php
@@ -13,50 +13,77 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  * Description:
- *		this script displays the radius log file ofcourse
- *		proper premissions must be applied on the log file for the web
- *		server to be able to read it
+ *             this script displays the radius log file ofcourse
+ *             proper premissions must be applied on the log file for the web
+ *             server to be able to read it
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
+// prevent this file to be directly accessed
+$extension_file = '/library/exten-syslog_log.php';
+if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
+    header("Location: ../index.php");
+    exit;
+}
+
+// possible locations for syslog files
+$logfile_loc = array(
+    '/var/log/syslog',
+    '/var/log/messages'
+);
 
-$logfile_loc1 = '/var/log/syslog';
-$logfile_loc2 = '/var/log/messages';
+// select one log file
+$logfile = "";
 
-if (file_exists($logfile_loc1))
-	$logfile = $logfile_loc1;
-else if (file_exists($logfile_loc2))
-	$logfile = $logfile_loc2;
-else {
-	$failureMsg = "error reading system log file:<br/>".
-		"looked for log file in $logfile_loc1 and $logfile_loc2 but couldn't find it.<br/>".
-		"if you know where your system log file is located, set it's location in " . $_SERVER[SCRIPT_NAME];
-	exit;
+foreach ($logfile_loc as $tmp) {
+    if (file_exists($tmp)) { 
+    $logfile = $tmp; 
+        break;
+    }
 }
 
-if (is_readable($logfile) == false) {
-	$failureMsg = "error reading log file: <u>$logfile</u> <br/>".
-		"possible cause is file premissions or file doesn't exist.<br/>";
+$logfile_enc = (!empty($logfile)) ? htmlspecialchars($logfile, ENT_QUOTES, 'UTF-8') : '(none)';
+
+// check if it is empty
+if (empty($logfile)) {
+    $failureMsg = sprintf("<br><br>Error accessing log file: <strong>%s</strong>.<br><br>" . 
+                          "Looked for log file in <strong>%s</strong> but could not find it.<br>" .
+                          "If you know where your <em>system log file</em> is located, specify its location in <strong>%s</strong>",
+                          $logfile_enc, htmlspecialchars(implode(", ", $logfile_loc), ENT_QUOTES, 'UTF-8'),
+                          htmlspecialchars($extension_file, ENT_QUOTES, 'UTF-8'));
 } else {
-                if (file_get_contents($logfile)) {
-                        $fileReversed = array_reverse(file($logfile));
-                        $counter = $systemLineCount;
-                        foreach ($fileReversed as $line) {
-                                if (preg_match("/$systemFilter/i", $line)) {
-                                        if ($counter == 0)
-                                                break;
-                                        $ret = preg_replace("/\n/i", "<br>", $line);
-                                        echo $ret;
-                                        $counter--;
-                                }
-                        }
+
+    // check if it is readable
+    if (is_readable($logfile) !== true) {
+        $failureMsg = sprintf("<br><br>Error reading log file: <strong>%s</strong>.<br><br>Is this file readable?<br>",
+                              $logfile_enc);
+    } else {
+
+        // get its content
+        $logcontent = file_get_contents($logfile);
+        if (!empty($logcontent)) {
+            $counter = $systemLineCount;
+            $filter = (!empty($systemFilter)) ? preg_quote($systemFilter, "/") : ".+";
+            $fileReversed = array_reverse(file($logfile));
+
+            echo '<div style="font-family: monospace">';
+            foreach ($fileReversed as $line) {
+                if (preg_match("/$filter/i", $line)) {
+                    if ($counter == 0) {
+                        break;
+                    }
+                    echo nl2br(htmlspecialchars($line, ENT_QUOTES, 'UTF-8'), false);
+                    $counter--;
                 }
+            }
+            echo '</div>';
+        }
+    }
 }
-
 ?>
-
diff --git a/library/exten-welcome_page.php b/library/exten-welcome_page.php
index a04e53b8..e911aab3 100644
--- a/library/exten-welcome_page.php
+++ b/library/exten-welcome_page.php
@@ -12,26 +12,27 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
- * Description:
- *		displays a welcome page for the main index.php file
+ * Description: displays a welcome page for the main index.php file
  *
- * Authors:	Liran Tal <liran@enginx.com>
- *          Miguel García <miguelvisgarcia@gmail.com>
+ * Authors:     Liran Tal <liran@enginx.com>
+ *              Miguel García <miguelvisgarcia@gmail.com>
+ *              Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-echo "
-	<center>
-
-		<h2> daloRADIUS Web Management Server </h2>
-		<h3> ".t('all','daloRADIUSVersion')." / ".$configValues['DALORADIUS_DATE']." </h3>
-		<h4> <a href=\"mailto:liran.tal@gmail.com\"> Liran Tal </a> </h4>
-		<br/><br/><br/>
-		<img src='images/daloradius_logo.jpg' border=0 />
-	</center>
-";
-
+// prevent this file to be directly accessed
+if (strpos($_SERVER['PHP_SELF'], '/library/exten-welcome_page.php') !== false) {
+    header("Location: ../index.php");
+    exit;
+}
 ?>
+
+<div style="text-align: center">
+    <h2>daloRADIUS Web Management Server</h2>
+    <h3><?= t('all', 'daloRADIUSVersion') ?> / <?= htmlspecialchars($configValues['DALORADIUS_DATE'], ENT_QUOTES, 'UTF-8') ?></h3>
+    <h4><a href="mailto:liran.tal@gmail.com">Liran Tal</a></h4>
+    <img src="images/daloradius_logo.jpg" style="border: 0; margin-top: 50px">
+</div>
diff --git a/rep-logs-boot.php b/rep-logs-boot.php
index f893afda..86fc9440 100644
--- a/rep-logs-boot.php
+++ b/rep-logs-boot.php
@@ -13,69 +13,66 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-    include ("library/checklogin.php");
+    include("library/checklogin.php");
     $operator = $_SESSION['operator_user'];
 
-	include('library/check_operator_perm.php');
+    include('library/check_operator_perm.php');
 
-        isset($_GET['bootLineCount']) ? $bootLineCount = $_GET['bootLineCount'] : $bootLineCount = 50;
-        isset($_GET['bootFilter']) ? $bootFilter = $_GET['bootFilter'] : $bootFilter = ".";
+    // parameter validation
+    $bootLineCount = (array_key_exists('bootLineCount', $_GET) && isset($_GET['bootLineCount']) &&
+                      intval($_GET['bootLineCount']) > 0)
+                   ? intval($_GET['bootLineCount']) : 50;
 
+    // preg quoted before usage
+    $bootFilter = (array_key_exists('bootFilter', $_GET) && isset($_GET['bootFilter']))
+                ? $_GET['bootFilter'] : "";
 
-	include_once('library/config_read.php');
+    include_once('library/config_read.php');
     $log = "visited page: ";
-    $logQuery = "performed query on page: ";
     include('include/config/logging.php');
 
+    include("menu-reports-logs.php");
+      
+?>    
+    <div id="contentnorightbar">
+        <h2 id="Intro">
+            <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
+                <?= t('Intro','replogsboot.php') ?> :: <?= $bootLineCount . " Lines Count " ?>
+<?php 
+    if (!empty($bootFilter) && $bootFilter !== '.+') {
+        echo " with filter set to " . htmlspecialchars($bootFilter, ENT_QUOTES, 'UTF-8');
+    }
 ?>
+                <h144>&#x2754;</h144>
+            </a>
+        </h2>
 
-<?php
-
-    include ("menu-reports-logs.php");
-  	
-?>	
-		<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#" onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogsboot.php'); ?>
-                :: <?php if (isset($bootLineCount)) { echo $bootLineCount . " Lines Count "; } ?>
-                   <?php if (isset($bootFilter)) { echo " with filter set to " . $bootFilter; } ?>
-		<h144>&#x2754;</h144></a></h2>
-
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<?php echo t('helpPage','replogsboot') ?>
-			<br/>
-		</div>
-		<br/>
+        <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage', 'replogsboot') ?><br></div>
+        <br>
 
 <?php
-	include 'library/exten-boot_log.php';
+    include('library/exten-boot_log.php');
+    include_once('include/management/actionMessages.php');
 ?>
+        </div>
 
-                <?php
-                        include_once('include/management/actionMessages.php');
-                ?>
-
-
-		</div>
-		
-		<div id="footer">
-		
-								<?php
-        include 'page-footer.php';
+        <div id="footer">
+<?php
+    include('page-footer.php');
 ?>
-		
-		</div>
-		
-</div>
+        </div>
+        
+    </div>
 </div>
 
 
 </body>
 </html>
diff --git a/rep-logs-daloradius.php b/rep-logs-daloradius.php
index f241e2ec..a908e83f 100644
--- a/rep-logs-daloradius.php
+++ b/rep-logs-daloradius.php
@@ -13,68 +13,57 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-	include ("library/checklogin.php");
-	$operator = $_SESSION['operator_user'];
+    include("library/checklogin.php");
+    $operator = $_SESSION['operator_user'];
 
-	include('library/check_operator_perm.php');
+    include('library/check_operator_perm.php');
 
-	isset($_GET['daloradiusLineCount']) ? $daloradiusLineCount = $_GET['daloradiusLineCount'] : $daloradiusLineCount = 50;
-	isset($_GET['daloradiusFilter']) ? $daloradiusFilter = $_GET['daloradiusFilter'] : $daloradiusFilter = ".";
+    // parameter validation
+    $daloradiusLineCount = (array_key_exists('daloradiusLineCount', $_GET) && isset($_GET['daloradiusLineCount']) &&
+                            intval($_GET['daloradiusLineCount']) > 0)
+                         ? intval($_GET['daloradiusLineCount']) : 50;
 
-	include_once('library/config_read.php');
-	$log = "visited page: ";
-	$logQuery = "performed query on page: ";
-	include('include/config/logging.php');
+    include_once('library/config_read.php');
+    $log = "visited page: ";
+    include('include/config/logging.php');
 
-?>
-
-<?php
-
-    include ("menu-reports-logs.php");
-  	
-?>	
+    include("menu-reports-logs.php");
 
+?>    
 
-	<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogsdaloradius.php'); ?>
-		:: <?php if (isset($daloradiusLineCount)) { echo $daloradiusLineCount . " Lines Count "; } ?>
-		   <?php if (isset($daloradiusFilter)) { echo " with filter set to " . $daloradiusFilter; } ?>
-		<h144>&#x2754;</h144></a></h2>
+    <div id="contentnorightbar">
+        <h2 id="Intro">
+            <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
+                <?= t('Intro','replogsdaloradius.php') ?> :: <?= $daloradiusLineCount . " Lines Count " ?>
+                <h144>&#x2754;</h144>
+            </a>
+        </h2>
 
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<?php echo t('helpPage','replogsdaloradius') ?>
-			<br/>
-		</div>
+        <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage','replogsdaloradius') ?><br></div>
 
 <?php
-	include 'library/exten-daloradius_log.php';
+    include('library/exten-daloradius_log.php');
+    include_once('include/management/actionMessages.php');
 ?>
+        </div>
 
-                <?php
-                        include_once('include/management/actionMessages.php');
-                ?>
-
-	</div>
-	
-	<div id="footer">
-	
+        <div id="footer">
 <?php
-	include 'page-footer.php';
+    include('page-footer.php');
 ?>
-
-	</div>
-
-</div>
+        </div>
+        
+    </div>
 </div>
 
 
 </body>
 </html>
diff --git a/rep-logs-radius.php b/rep-logs-radius.php
index 7f891300..706fc34d 100644
--- a/rep-logs-radius.php
+++ b/rep-logs-radius.php
@@ -13,67 +13,67 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-    include ("library/checklogin.php");
+    include("library/checklogin.php");
     $operator = $_SESSION['operator_user'];
 
-	include('library/check_operator_perm.php');
+    include('library/check_operator_perm.php');
 
-        isset($_GET['radiusLineCount']) ? $radiusLineCount = $_GET['radiusLineCount'] : $radiusLineCount = 50;
-        isset($_GET['radiusFilter']) ? $radiusFilter = $_GET['radiusFilter'] : $radiusFilter = ".";
+    // parameter validation
+    $radiusLineCount = (array_key_exists('radiusLineCount', $_GET) && isset($_GET['radiusLineCount']) &&
+                        intval($_GET['radiusLineCount']) > 0)
+                     ? intval($_GET['radiusLineCount']) : 50;
 
+    // preg quoted before usage
+    $radiusFilter = (array_key_exists('radiusFilter', $_GET) && isset($_GET['radiusFilter']) &&
+                     in_array($_GET['radiusFilter'], array( "Auth", "Info", "Error" )))
+                  ? $_GET['radiusFilter'] : "";
 
-	include_once('library/config_read.php');
+
+    include_once('library/config_read.php');
     $log = "visited page: ";
-    $logQuery = "performed query on page: ";
     include('include/config/logging.php');
 
+    include ("menu-reports-logs.php");
 
 ?>
+    <div id="contentnorightbar">
+        <h2 id="Intro">
+            <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
+                <?= t('Intro', 'replogsradius.php') ?> :: <?= $radiusLineCount . " Lines Count " ?>
+<?php 
+    if (!empty($radiusFilter) && $radiusFilter !== '.+') {
+        echo " with filter set to " . htmlspecialchars($radiusFilter, ENT_QUOTES, 'UTF-8');
+    }
+?>
+                <h144>&#x2754;</h144>
+            </a>
+        </h2>
 
-<?php
-
-    include ("menu-reports-logs.php");
-  	
-?>	
-		
-		
-		<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogsradius.php'); ?>
-                :: <?php if (isset($radiusLineCount)) { echo $radiusLineCount . " Lines Count "; } ?>
-                   <?php if (isset($radiusFilter)) { echo " with radiusFilter set to " . $radiusFilter; } ?>
-		<h144>&#x2754;</h144></a></h2>
-
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<?php echo t('helpPage','replogsradius') ?>
-			<br/>
-		</div>
-		<br/>
+        <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage', 'replogsradius') ?><br></div>
+        <br>
 
 <?php
-	include 'library/exten-radius_log.php';
+    include('library/exten-radius_log.php');
+    include_once('include/management/actionMessages.php');
 ?>
-
-		</div>
-		
-		<div id="footer">
-		
-								<?php
-        include 'page-footer.php';
+        </div>
+        
+        <div id="footer">
+<?php
+    include('page-footer.php');
 ?>
-		
-		</div>
-		
+        </div>
+        
+    </div>
 </div>
-</div>
-
 
 </body>
 </html>
diff --git a/rep-logs-system.php b/rep-logs-system.php
index ef78e5b6..4671fbdc 100644
--- a/rep-logs-system.php
+++ b/rep-logs-system.php
@@ -13,68 +13,64 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
  *
- * Authors:	Liran Tal <liran@enginx.com>
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-    include ("library/checklogin.php");
+    include("library/checklogin.php");
     $operator = $_SESSION['operator_user'];
 
-	include('library/check_operator_perm.php');
+    include('library/check_operator_perm.php');
 
-        isset($_GET['systemLineCount']) ? $systemLineCount = $_GET['systemLineCount'] : $systemLineCount = 50;
-        isset($_GET['systemFilter']) ? $systemFilter = $_GET['systemFilter'] : $systemFilter = ".";
+    // parameter validation
+    $systemLineCount = (array_key_exists('systemLineCount', $_GET) && isset($_GET['systemLineCount']) &&
+                        intval($_GET['systemLineCount']) > 0)
+                     ? intval($_GET['systemLineCount']) : 50;
 
-	include_once('library/config_read.php');
+    // preg quoted before usage
+    $systemFilter = (array_key_exists('systemFilter', $_GET) && isset($_GET['systemFilter']))
+                  ? $_GET['systemFilter'] : "";
+
+    include_once('library/config_read.php');
     $log = "visited page: ";
-    $logQuery = "performed query on page: ";
     include('include/config/logging.php');
 
+    include ("menu-reports-logs.php");      
+?>    
+        <div id="contentnorightbar">
+            <h2 id="Intro">
+                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
+                    <?= t('Intro', 'replogssystem.php'); ?> :: <?= $systemLineCount . " Lines Count" ?>
+<?php 
+    if (!empty($systemFilter)) {
+        echo " with filter set to " . htmlspecialchars($systemFilter, ENT_QUOTES, 'UTF-8');
+    }
 ?>
+                    <h144>&#x2754;</h144>
+                </a>
+            </h2>
+            
+            <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage', 'replogssystem') ?><br></div>
+            <br>
 
 <?php
-
-    include ("menu-reports-logs.php");
-  	
-?>	
-		<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogssystem.php'); ?>
-                :: <?php if (isset($systemLineCount)) { echo $systemLineCount . " Lines Count "; } ?>
-                   <?php if (isset($systemFilter)) { echo " with filter set to " . $systemFilter; } ?>
-		<h144>&#x2754;</h144></a></h2>
-
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<?php echo t('helpPage','replogssystem') ?>
-			<br/>
-		</div>
-		<br/>
-
+    include('library/exten-syslog_log.php');
+    include_once('include/management/actionMessages.php');
+?>
+        </div>
+        
+        <div id="footer">
 <?php
-	include 'library/exten-syslog_log.php';
+    include('page-footer.php');
 ?>
+        </div>
 
-                <?php
-                        include_once('include/management/actionMessages.php');
-                ?>
-
-
-		</div>
-		
-		<div id="footer">
-		
-								<?php
-        include 'page-footer.php';
-?>
-		
-		</div>
-		
+    </div>
 </div>
-</div>
-
 
 </body>
 </html>
diff --git a/rep-logs.php b/rep-logs.php
index 29aea742..553eed42 100644
--- a/rep-logs.php
+++ b/rep-logs.php
@@ -12,60 +12,52 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
-*
- * Authors:	Liran Tal <liran@enginx.com>
+ *
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-    include ("library/checklogin.php");
+    include("library/checklogin.php");
     $operator = $_SESSION['operator_user'];
         
-	include_once('library/config_read.php');
+    include_once('library/config_read.php');
     $log = "visited page: ";
 
+    include("menu-reports-logs.php");
 
 ?>
+        <div id="contentnorightbar">
+            <h2 id="Intro">
+                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
+                    <?= t('Intro','replogs.php'); ?>
+                    <h144>&#x2754;</h144>
+                </a>
+            </h2>
 
-<?php
-
-    include ("menu-reports-logs.php");
-
-?>
-		
-		<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#" onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogs.php'); ?>
-		<h144>&#x2754;</h144></a></h2>
-
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<?php echo t('helpPage','replogs') ?>
-			<br/>
-		</div>
-		<br/>
-
-
+            <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage','replogs') ?><br></div>
+            <br>
 
 <?php
-	include('include/config/logging.php');
+    include('include/config/logging.php');
 ?>
 
-		</div>
-		
-		<div id="footer">
-		
-								<?php
-        include 'page-footer.php';
+        </div>
+        
+        <div id="footer">
+        
+<?php
+        include('page-footer.php');
 ?>
 
-		
-		</div>
-		
-</div>
+        
+        </div>
+    </div>
 </div>
 
 
 </body>
 </html>
diff --git a/rep-stat-cron.php b/rep-stat-cron.php
index c32d2add..ee232868 100644
--- a/rep-stat-cron.php
+++ b/rep-stat-cron.php
@@ -12,111 +12,103 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
-*
- * Authors:	Liran Tal <liran@enginx.com>
+ *
+ * Authors:     Liran Tal <liran@enginx.com>
+ *              Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-    include ("library/checklogin.php");
-    //$operator = $_SESSION['operator_user']
-	//include('library/check_operator_perm.php');
+    include("library/checklogin.php");
+    $operator = $_SESSION['operator_user'];
+
+    include('library/check_operator_perm.php');
 
-	include_once('library/config_read.php');
+    include_once('library/config_read.php');
     $log = "visited page: ";
     $logQuery = "performed query on page: ";
     include('include/config/logging.php');
     
     $cronUser = get_current_user();
     
-    isset($_GET['cmd']) ? $cmd = $_GET['cmd'] : $cmd = "";
-    
+    // validating params
+    $cmd = (array_key_exists('cmd', $_GET) && isset($_GET['cmd']) &&
+            in_array(strtolower($_GET['cmd']), array( "enable", "disable" )))
+         ? strtolower($_GET['cmd']) : "";
+
     $dalo_crontab_file = dirname(__FILE__) . '/contrib/scripts/dalo-crontab';
     
+    $exec = "";
     
     switch ($cmd) {
-    	
-    	case "disable":
-    		exec("`which crontab` -u $cronUser -r");
-    		break;
-    	
-    	case "enable":
-    		exec("`which crontab` -u $cronUser $dalo_crontab_file");
-    		break;
+        case "disable":
+        $exec = sprintf("$(which crontab || command -v crontab) -u %s -r", escapeshellarg($cronUser));
+        break;
+        
+        case "enable":
+        $exec = sprintf("$(which crontab || command -v crontab) -u %s %s", escapeshellarg($cronUser), $dalo_crontab_file);
+        break;
     }
     
+    if (!empty($exec)) {
+        exec($exec);
+    }
     
-?>
-
-
-<?php
-
     include ("menu-reports-status.php");
     
-?>	
-		
-		
-		
-		<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')">CRON Status
-		<h144>&#x2754;</h144></a></h2>
-
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<br/>
-		</div>
-		<br/>
-
-
-<?php
-	
-	exec("/usr/bin/crontab -u $cronUser -l", $output, $retStatus);
-	
-?>
-
-
-	<h3>CRON Entries</h3>
+?>        
+    <div id="contentnorightbar">
+    
+        <h2 id="Intro">
+            <a href="#" onclick="javascript:toggleShowDiv('helpPage')">CRON Status
+                <h144>&#x2754;</h144>
+            </a>
+            </h2>
 
-	<a href='rep-stat-cron.php?cmd=enable' >Enable CRON</a>
-	&nbsp;
-	<a href='rep-stat-cron.php?cmd=disable' >Disable CRON</a>
+            <div id="helpPage" style="display:none;visibility:visible"><br></div>
+            <br>
 
-	<br/>
-	<br/>
+            <h3>CRON Entries</h3>
+            <a href="?cmd=enable">Enable CRON</a>
+            &nbsp;
+            <a href="?cmd=disable">Disable CRON</a>
 
-<?php 
-	if ($retStatus != 0):		 
-?>
-	<font color='red'><b>Error</b> no crontab is configured for this user or user does not exist</font>
-	<br/><br/>
+            <br>
+            <br>
 
 <?php
-	else:
-	
-	$i = 0;
-		foreach($output as $text) {
-			$i++;
-			echo "<b>#$i:</b> " . $text . '<br/>';
-		}
-		
-	endif;
+    $failureMsg = "";
+
+    $exec = sprintf("$(which crontab || command -v crontab) -u %s -l", escapeshellarg($cronUser));
+    exec($exec, $output, $retStatus);
+
+    if ($retStatus !== 0) {
+        $failureMsg = '<strong>Error</strong> no crontab is configured for this user or user does not exist<br><br>';
+    } else {
+        $i = 1;
+        foreach($output as $text) {
+            printf('<strong>#%d</strong>: %s<br>', $i, htmlspecialchars($text, ENT_QUOTES, 'UTF-8'));
+            $i++;
+        }
+    }
+    
+    if (!empty($failureMsg)) {
+        include_once('include/management/actionMessages.php');
+    }
 ?>
 
-		</div>
-		
-		<div id="footer">
-
+        </div>
+        
+        <div id="footer">
 <?php
-        include 'page-footer.php';
+    include('page-footer.php');
 ?>
-		
-		</div>
-		
-</div>
+        </div>
+        
+    </div>
 </div>
 
-
 </body>
 </html>
diff --git a/rep-stat-raid.php b/rep-stat-raid.php
index 09d1f3c0..076ef5a4 100644
--- a/rep-stat-raid.php
+++ b/rep-stat-raid.php
@@ -12,123 +12,98 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
-*
- * Authors:	Liran Tal <liran@enginx.com>
+ *
+ * Authors:     Liran Tal <liran@enginx.com>
+ *              Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
     include ("library/checklogin.php");
     $operator = $_SESSION['operator_user'];
 
     include('library/check_operator_perm.php');
 
-	include_once('library/config_read.php');
+    include_once('library/config_read.php');
     $log = "visited page: ";
     $logQuery = "performed query on page: ";
     include('include/config/logging.php');
 
-
-?>
-
-
-<?php
-	include_once ("library/tabber/tab-layout.php");
-?>
-<?php
-
     include ("menu-reports-status.php");
-  	
-?>	
-		
-		
-		<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')">RAID Status
-		<h144>&#x2754;</h144></a></h2>
-
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<br/>
-		</div>
-		<br/>
-
-
-
-<div class="tabber">
-
+      
+?>    
+        <div id="contentnorightbar">
+            <h2 id="Intro">
+                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
+                    RAID Status <h144>&#x2754;</h144>
+                </a>
+            </h2>
+
+            <div id="helpPage" style="display:none;visibility:visible"><br></div>
+            <br>
 
 <?php
-
-	if (!file_exists('/proc/mdstat')):
-?>
-	<font color='red'><b>Error</b> accessing RAID device information:</font>
-	<br/><br/>
-
-<?php 
-	else: 
-	exec("cat /proc/mdstat  | awk '/md/ {print $1}'", $mdstat);
+    $failureMsg = "";
+    $error = '<strong>Error</strong> accessing RAID device information<br><br>';
+    
+    if (!file_exists('/proc/mdstat')) {
+        $failureMsg = $error;
+    } else {
+        exec("cat /proc/mdstat | awk '/md/ {print $1}'", $mdstat, $retStatus);
+        
+        if ($retStatus !== 0) {
+            $failureMsg = $error;
+        } else {
+            if (count($mdstat) > 0) {
+                include_once("library/tabber/tab-layout.php");
+                echo '<div class="tabber">';
+                foreach($mdstat as $mddevice) {
+                    printf('<div class="tabbertab" title="%s">', htmlspecialchars($mddevice, ENT_QUOTES, 'UTF-8'));
+                    
+                    $dev = "/dev/$mddevice";
+                    $cmd = sprintf("sudo /sbin/mdadm --detail %s", escapeshellarg($dev));
+                    $output = "";
+                    exec($cmd, $output);
+
+                    echo '<table class="summarySection">';
+                    foreach($output as $line) {
+                        list($var, $val) = split(":", $line);
+                        $var = htmlspecialchars($var, ENT_QUOTES, 'UTF-8');
+                        $val = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
+                        
+                        printf('<tr><td class="summaryKey">%s</td>' .
+                               '<td class="summaryValue"><span class="sleft">%s</span></td></tr>', $var, $val); 
+                    }
+                    echo '</table>'
+                       . '</div>';
+
+                }
+                echo '</div>';
+
+            } else {
+                $failureMsg = $error;
+            }
+        }
+    }
+    
+    if (!empty($failureMsg)) {
+        include_once('include/management/actionMessages.php');
+    }
 
 ?>
-
-	<font color='red'><b>Error</b> accessing RAID device information:</font>
-	<br/><br/>
-
-	<?php
-		foreach($mdstat as $mddevice):
-	?>
-
-			<div class="tabbertab" title="<?php echo $mddevice ?>">
-
-				<?php
-					$output = "";
-					$cmd = "sudo /sbin/mdadm --detail /dev/$mddevice";
-					exec($cmd, $output);
-				?>
-		
-				<table class='summarySection'>
-		
-					<?php
-						foreach($output as $line):
-					?>
-			
-					<?php
-						list($var, $val) = split(":", $line);
-					?>
-			
-					  <tr>
-						<td class='summaryKey'> <?php echo $var ?> </td>
-						<td class='summaryValue'><span class='sleft'> <?php echo $val ?> </span> </td>
-					  </tr>
-			
-					<?php endforeach; ?>
-		
-				</table>
-		
-			</div>
-
-	<?php endforeach; ?>
-<?php endif; ?>
-
-</div>
-
-
-
-
-		</div>
-		
-		<div id="footer">
-		
+            
+        </div>
+        
+        <div id="footer">
 <?php
-        include 'page-footer.php';
+    include('page-footer.php');
 ?>
-		
-		</div>
-		
-</div>
+        </div>
+        
+    </div>
 </div>
 
-
 </body>
 </html>
diff --git a/rep-stat-server.php b/rep-stat-server.php
index 8d414d46..3aa77608 100644
--- a/rep-stat-server.php
+++ b/rep-stat-server.php
@@ -12,63 +12,54 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
-*
- * Authors:	Liran Tal <liran@enginx.com>
+ *
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-    include ("library/checklogin.php");
+    include("library/checklogin.php");
     $operator = $_SESSION['operator_user'];
 
-	include('library/check_operator_perm.php');
-
-
+    include('library/check_operator_perm.php');
 
-	include_once('library/config_read.php');
+    include_once('library/config_read.php');
     $log = "visited page: ";
-    $logQuery = "performed query on page: ";
     include('include/config/logging.php');
 
-?>
+    include("menu-reports-status.php");
+    
+?>    
+        <div id="contentnorightbar">
+            <h2 id="Intro">
+                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
+                    <?= t('Intro','repstatserver.php'); ?>
+                    <h144>&#x2754;</h144>
+                </a>
+            </h2>
 
+            <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage','repstatserver') ?><br></div>
+            <br>
+                
 <?php
-
-    include ("menu-reports-status.php");
-	
-?>	
-		
-		
-		<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#" onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','repstatserver.php'); ?>
-		<h144>&#x2754;</h144></a></h2>
-
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<?php echo t('helpPage','repstatserver') ?>
-			<br/>
-		</div>
-		<br/>
-				
-<?php
-	include 'library/exten-server_info.php';
+    include('library/exten-server_info.php');
 ?>
 
-		</div>
-		
-		<div id="footer">
-		
-								<?php
-        include 'page-footer.php';
+        </div>
+        
+        <div id="footer">
+        
+<?php
+    include('page-footer.php');
 ?>
-		
-		</div>
-		
-</div>
+        
+        </div>
+    </div>
 </div>
 
 
 </body>
 </html>
diff --git a/rep-stat-services.php b/rep-stat-services.php
index 8fd6806e..f28886d8 100644
--- a/rep-stat-services.php
+++ b/rep-stat-services.php
@@ -12,65 +12,53 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
-*
- * Authors:	Liran Tal <liran@enginx.com>
+ *
+ * Authors:    Liran Tal <liran@enginx.com>
+ *             Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-    include ("library/checklogin.php");
+    include("library/checklogin.php");
     $operator = $_SESSION['operator_user'];
 
-	include('library/check_operator_perm.php');
-
-
+    include('library/check_operator_perm.php');
 
-	include_once('library/config_read.php');
+    include_once('library/config_read.php');
     $log = "visited page: ";
-    $logQuery = "performed query on page: ";
     include('include/config/logging.php');
 
+    include("menu-reports-status.php");
+      
+?>    
+        <div id="contentnorightbar">            
+            <h2 id="Intro">
+                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
+                    <?= t('Intro','repstatradius.php'); ?>
+                    <h144>&#x2754;</h144>
+                </a>
+            </h2>
 
-?>
-
+            <div id="helpPage" style="display:none;visibility:visible" ><?= t('helpPage','repstatradius') ?><br></div>
+            <br>
 
 <?php
-
-    include ("menu-reports-status.php");
-  	
-?>	
-		
-		
-		<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','repstatradius.php'); ?>
-		<h144>&#x2754;</h144></a></h2>
-
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<?php echo t('helpPage','repstatradius') ?>
-			<br/>
-		</div>
-		<br/>
-
-<?php
-	include 'library/exten-radius_server_info.php';
+    include('library/exten-radius_server_info.php');
 ?>
 
-		</div>
-		
-		<div id="footer">
-		
-								<?php
-        include 'page-footer.php';
+        </div>
+        
+        <div id="footer">        
+<?php
+        include('page-footer.php');
 ?>
-		
-		</div>
-		
-</div>
+        
+        </div>
+    </div>
 </div>
 
 
 </body>
 </html>
diff --git a/rep-stat-ups.php b/rep-stat-ups.php
index 0fd4d29f..b7d61574 100644
--- a/rep-stat-ups.php
+++ b/rep-stat-ups.php
@@ -12,94 +12,84 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  *********************************************************************************************************
-*
- * Authors:	Liran Tal <liran@enginx.com>
+ *
+ * Authors:     Liran Tal <liran@enginx.com>
+ *              Filippo Lauria <filippo.lauria@iit.cnr.it>
  *
  *********************************************************************************************************
  */
 
-    include ("library/checklogin.php");
+    include("library/checklogin.php");
     $operator = $_SESSION['operator_user'];
 
     include('library/check_operator_perm.php');
 
-	include_once('library/config_read.php');
+    include_once('library/config_read.php');
     $log = "visited page: ";
     $logQuery = "performed query on page: ";
     include('include/config/logging.php');
 
-
+    include("menu-reports-status.php");
+      
 ?>
+        <div id="contentnorightbar">
+            <h2 id="Intro">
+                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
+                    UPS Status <h144>&#x2754;</h144>
+                </a>
+            </h2>
 
+            <div id="helpPage" style="display:none;visibility:visible"><br></div>
+            <br>
 
 <?php
+    exec("which apcaccess || command -v apcaccess", $output, $retStatus);
 
-    include ("menu-reports-status.php");
-  	
-?>	
-		
-		
-		<div id="contentnorightbar">
-		
-		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')">UPS Status
-		<h144>&#x2754;</h144></a></h2>
-
-		<div id="helpPage" style="display:none;visibility:visible" >
-			<br/>
-		</div>
-		<br/>
-
-
-
+    $failureMsg = "";
 
-<?php
-	exec("`which apcaccess`", $output, $retStatus);
+    $sep = ":";
+    if ($retStatus !== 0) {
+        $sep = "\n";
+        $failureMsg = '<strong>Error</strong> accessing UPS device information<br><br>';
+    } else {
 ?>
 
-
-	<h3>General Information</h3>
+            <h3>General Information</h3>
+            <table class="summarySection">
 
 <?php 
-	$sep = ":";
-	if ($retStatus != 0):
-		$sep = "\n";		 
+        foreach ($output as $line) {
+        list($var, $val) = split($sep, $line);
+        $var = htmlspecialchars($var, ENT_QUOTES, 'UTF-8');
+        $val = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
 ?>
-	<font color='red'><b>Error</b> accessing UPS device information:</font>
-	<br/><br/>
-<?php endif; ?>
-
-<table class='summarySection'>
-
-
-<?php 
-	foreach($output as $line):
-		list($var, $val) = split($sep, $line);
+                <tr>
+                <td class="summaryKey"><?= $var ?></td>
+                <td class="summaryValue"><span class="sleft"><?= $val ?></span></td>
+                </tr>
+<?php
+        }
 ?>
-
-  <tr>
-    <td class='summaryKey'> <?php echo $var ?> </td>
-    <td class='summaryValue'><span class='sleft'> <?php echo $val ?> </span> </td>
-  </tr>
-
-<?php endforeach; ?>
-
-</table>
-
-		</div>
-		
-		<div id="footer">
-
+            </table>
 <?php
-        include 'page-footer.php';
+    }
+    
+    if (!empty($failureMsg)) {
+        include_once('include/management/actionMessages.php');
+    }
 ?>
-		
-		</div>
-		
-</div>
+        </div>
+        
+        <div id="footer">
+<?php
+    include('page-footer.php');
+?>
+        </div>
+        
+    </div>
 </div>
 
-
 </body>
 </html>

Vulnerable code: /*********************************************************************
* Name: logging.php
* Author: Liran tal <liran.tal@gmail.com>
*
* This file is used for controlling the logging actions
*
*********************************************************************/


* It is important to understand that when logging.php is included in
* a page AFTER an include for config_read.php it gains access to all
* of the variables it's scope including the $configValues[....] because
* it was included just before it.
*
* But it should be noticed that these variables are only accessible
* in the scope of the general or main block of php code and are
* not accessible from functions, so we can't just use $configValues[...]
* variables from within logMessageNotice() or any other function
* and so we must use them here as references.
*
* The relevant variables are:
*
* $operator
* $_SERVER["SCRIPT_NAME"]
* $configValues['CONFIG_LOG_FILE']
*
*/
if ($configValues['CONFIG_LOG_PAGES'] == "yes") {
	if (isset($log)) {
	        $msgNotice = $operator . " " . $log;
	        logMessage("NOTICE", $msgNotice, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
	}
if ($configValues['CONFIG_LOG_QUERIES'] == "yes") {
	if (isset($logQuery)) {
	        $msgQuery = $operator . " " . $logQuery;
	        logMessage("QUERY", $msgQuery, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
	}
if ($configValues['CONFIG_LOG_ACTIONS'] == "yes") {
	if (isset($logAction)) {
	        $msgAction = $operator . " " . $logAction;
	        logMessage("ACTION", $msgAction, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
	}
/********************************************************************************
 ********************************************************************************/
if ($configValues['CONFIG_DEBUG_SQL'] == "yes") {
	if (isset($logDebugSQL)) {
	        $msgDebugSQL = "- SQL -" . " " . $logDebugSQL . " on page: ";
	        logMessage("DEBUG", $msgDebugSQL, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
	}
/* the continuation of the CONFIG_DEBUG_SQL actually, this prints to the page
 * being viewed */
if ($configValues['CONFIG_DEBUG_SQL_ONPAGE'] == "yes") {
	if (isset($logDebugSQL)) {
			echo "<br/><br/>";
			echo "Debugging SQL Queries: <br/>";
			echo $logDebugSQL;
			echo "<br/><br/>";
		}


function logMessage($type, $msg, $logFile, $currPage) {
/*
* @param $type               The message type, for example, NOTICE, DEBUG, ERROR, ACTION, etc...
* @param $msg           	The message string which should be logged to the file
* @param $logFile           The full path for the filename to write logs to
* @param $currPage       The current page that we included from
* @return $table              The table name, either radcheck or radreply
*/

        $date = date('M d G:i:s');
        $msgString = $date . " " . $type . " " . $msg . " " . $currPage;

        $fp = fopen($logFile, "a");
        if ($fp) {
        fwrite($fp, $msgString  . "\n");
                fclose($fp);
        } else {

                echo "<font color='#FF0000'>error: could not open the file for writing:<b> $logFile </b><br/></font>";
                        echo "Check file permissions. The file should be writable by the webserver's user/group<br/>";
        }

/*********************************************************************
* Name: actionMessages.php
* Author: Liran tal <liran.tal@gmail.com>
*
* This file provides control for messages that are printed to the
* screen in reply to actions such as applying forms, saving data,
* removing data and such.
*
*********************************************************************/

if ((isset($failureMsg)) && ($failureMsg != "")) {
	echo "<div class='failure'>
		$failureMsg
	</div>
	";

if ((isset($successMsg)) && ($successMsg != "")) {
	echo "<div class='success'>
		$successMsg
	</div>
	";
 * Description:
 *		global error handling for all PEAR packages, it isn't too wise to do
 *		that as I've no idea what other php applications are running on this machine
 *		even though this is really just about handling the error but still.
 *		So instead we're using the object's error handling method (see library/opendb.php)
 *		PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errorHandler');
 * Authors:	Liran Tal <liran@enginx.com>
	echo("<br/><b>Database error</b><br>
		<b>Error Message: </b>" . $err->getMessage() . "<br><b>Debug info: </b>" . $err->getDebugInfo() . "<br>");
 *		this script displays the radius log file ofcourse
 *		proper premissions must be applied on the log file for the web
 *		server to be able to read it
 * Authors:	Liran Tal <liran@enginx.com>
$logfile_loc1 = '/var/log/dmesg';
$logfile_loc2 = '/usr/local/var/log/dmesg';

if (file_exists($logfile_loc1))
	$logfile = $logfile_loc1;
else if (file_exists($logfile_loc2))
	$logfile = $logfile_loc2;
else {
	$failureMsg = "error reading log file: <br/>".
		"looked for log file in $logfile_loc1 and $logfile_loc2 but couldn't find it.<br/>".
		"if you know where your dmesg (boot) log file is located, set it's location in " . $_SERVER[SCRIPT_NAME];
	exit;
	
if (is_readable($logfile) == false) {
	$failureMsg = "error reading log file: <u>$logfile</u> <br/>".
		"possible cause is file premissions or file doesn't exist.<br/>";
                if (file_get_contents($logfile)) {
                        $fileReversed = array_reverse(file($logfile));
                        $counter = $bootLineCount;
                        foreach ($fileReversed as $line) {
                                if (preg_match("/$bootFilter/i", $line)) {
                                        if ($counter == 0)
                                                break;
                                        $ret = preg_replace("/\n/i", "<br>", $line);
                                        echo $ret;
                                        $counter--;
                                }
                        }
                }

 *		this script displays the daloradius log file ofcourse
 *		proper premissions must be applied on the log file for the web
 *		server to be able to read it
 * Authors:	Liran Tal <liran@enginx.com>
if (isset($configValues['CONFIG_LOG_FILE'])) {
	$logfile = $configValues['CONFIG_LOG_FILE'];

	if (!file_exists($logfile)) {

                $failureMsg = "error reading log file: <b>$logfile</b><br/>".
				"looked for log file in $logfile but couldn't find it.<br/>".
				"if you know where your daloradius log file is located, set it's location in your library/daloradius.conf file";
	} else {


		if (is_readable($logfile) == false) {
	                $failureMsg = "error reading log file: <b>$logfile</b><br/>".
				"possible cause is file premissions or file doesn't exist.<br/>";
		} else {
		    if (file_get_contents($logfile)) {
				$fileReversed = array_reverse(file($logfile));
				$counter = $daloradiusLineCount;
				// This doesn't take in any filter value
				// from the forms.
				// This takes in the log count though.
				foreach ($fileReversed as $line) {
					if ($counter == 0) {
						break;
					}
					echo $line . "<br>";
					$counter--;
				}
				// Old Code
				// $counter = $daloradiusLineCount;
				// foreach ($fileReversed as $line) {
				// 	if (preg_match("/$daloradiusFilter/i", $line)) {
				// 		if ($counter == 0)
				// 			break;
				// 		$ret = eregi_replace("\n", "<br>", $line);
				// 		echo $ret;
				// 		$counter--;
				// 	}
				// }
			}
		}
	}

 *		This code allows for running the 'radtest' binary tool provided with freeradius
 *		for performing a dry-run check to see if a user is able to successfully login
 *		or that there may be problems connecting.
 * Authors:	Liran Tal <liran@enginx.com>
 *		Giso Kegal <kegel@barum.de>
// $radiusaddr	- the server address, this would most likely be the radius server IP Address/Hostname
// $options	- the options passed to the radclient program
// $command	- the command string that radclient sends (auth, acct, status, coa, disconnect), by default this functions does 'auth'
function user_auth($options,$user,$pass,$radiusaddr,$radiusport,$secret,$command="auth",$additional="") {

	$user = escapeshellarg($user);
	$pass = escapeshellarg($pass);

	$args = escapeshellarg("$radiusaddr:$radiusport")." ".escapeshellarg($command).
		" ".escapeshellarg($secret);
	$query = "User-Name=$user,User-Password=$pass";

	$radclient = "radclient"; 		// or you can change this with the full path if the binary radcilent program can not be
									// found within your $PATH variable

	$radclient_options = "-c ".escapeshellarg($options['count']).
				" -n ".escapeshellarg($options['requests']).
				" -r ".escapeshellarg($options['retries']).
				" -t ".escapeshellarg($options['timeout']).
				" ".$options['debug'];

	if ($options['dictionary'])
		$radclient_options .= " -d ".escapeshellarg($options['dictionary']);

	$cmd = "echo ".escapeshellcmd($query)." | $radclient $radclient_options $args 2>&1";

	$print_cmd = "<b>Executed:</b><br/>$cmd<br/><br/><b>Results:</b><br/>";
	$res = shell_exec($cmd);

	if ($res == "") {
		echo "<b>Error:</b> Command did not return any results<br/>";
		echo "Please check that you have the radclient binary program installed and that
			it is found in your \$PATH variable<br/>
			You may also consult the file library/exten-maint-radclient.php for other problems<br/>
		";
	}

	// todo better layout
	$output_html = nl2br($res);
	return $print_cmd . $output_html;
// $nasaddr	- NAS address to receive the coa or disconnect request packet
// $nasport	- NAS Port address (depends on the configuration on the NAS, this may be a different port for either CoA or Disconnect packets).
function user_disconnect($options,$user,$nasaddr,$nasport="3779",$nassecret,$command="disconnect",$additional="") {

	$user = escapeshellarg($user);

	$args = escapeshellarg("$nasaddr:$nasport")." ".escapeshellarg($command)." ".
			escapeshellarg($nassecret);
	$query = "User-Name=$user";

	if (!empty($additional)) {
		$query .= ','.$additional;
	}

	$radclient = "radclient"; 		// or you can change this with the full path if the binary radcilent program can not be
						// found within your $PATH variable

	$radclient_options = "-c ".escapeshellarg($options['count']).
				" -n ".escapeshellarg($options['requests']).
				" -r ".escapeshellarg($options['retries']).
				" -t ".escapeshellarg($options['timeout']).
				" ".$options['debug'];

	if ($options['dictionary'])
		$radclient_options .= " -d ".escapeshellarg($options['dictionary']);

	$cmd = "echo \"".escapeshellcmd($query)."\" | $radclient $radclient_options $args 2>&1";
	$print_cmd = "<b>Executed:</b><br/>$cmd<br/><br/><b>Results:</b><br/>";
	$res = shell_exec($cmd);

	if ($res == "") {
		echo "<b>Error:</b> Command did not return any results<br/>";
		echo "Please check that you have the radclient binary program installed and that
			it is found in your \$PATH variable<br/>
			You may also consult the file library/exten-maint-radclient.php for other problems<br/>
		";
	}

	// todo better layout
	$output_html = nl2br($res);
	return $print_cmd . $output_html;
 *		this script displays the radius log file ofcourse
 *		proper premissions must be applied on the log file for the web
 *		server to be able to read it
 * Authors:	Liran Tal <liran@enginx.com>
 
$logfile_loc = array();
$logfile_loc[1] = '/var/log/freeradius/radius.log';
$logfile_loc[2] = '/usr/local/var/log/radius/radius.log';
$logfile_loc[3] = '/var/log/radius/radius.log';
	if (file_exists($tmp)) { 
		$logfile = $tmp; 
		break;
	}
 
	echo "<br/><br/>
		error reading log file: <br/><br/>
		looked for log file in '".implode(", ", $logfile_loc)."' but couldn't find it.<br/>
		if you know where your freeradius log file is located, set it's location in " . $_SERVER['SCRIPT_NAME'];
	exit;
	
if (is_readable($logfile) == false) {
	echo "<br/><br/>
		error reading log file: <u>$logfile</u> <br/><br/>
		possible cause is file premissions or file doesn't exist.<br/>";
} else {
    if (file_get_contents($logfile)) {
     $counter = $radiusLineCount;
     $fileReversed = array_reverse(file($logfile));
     foreach ($fileReversed as $line) {
        if($counter == 0) {
          break;
        echo $line . "<br>";
      }
      // $counter = $radiusLineCount;
      // foreach ($fileReversed as $line) {
      //         if (preg_match("/$radiusFilter/i", $line)) {
      //                 if ($counter == 0)
      //                         break;
      //                 $ret = eregi_replace("\n", "<br>", $line);
      //                 echo $ret;
      //                 $counter--;
      //         }
      // }

 *		this script runs a check to see if freeradius is up and running
*		the check is done by looking for a 'radius' process listening
*		on any socket interface. clumsy, but that's what we got for now
 * Authors:	Liran Tal <liran@enginx.com>
 
function check_service($sname) {
	if ($sname != '') {
		system("pgrep ".escapeshellarg($sname)." >/dev/null 2>&1", $ret_service);
		if ($ret_service == 0) {
			return "Enabled";
		} else {
			return "Disabled";
		}
	} else {
		return "no service name";
	}
	echo "<h3>Service Status</h3>";

<table class='summarySection'>
  <tr>
    <td class='summaryKey'> Radius </td>
    <td class='summaryValue'><span class='sleft'><?php echo check_service("radius"); ?></span> </td>
  </tr>
  <tr>
    <td class='summaryKey'> Mysql </td>
    <td class='summaryValue'><span class='sleft'><?php echo check_service("mysql");  ?></span> </td>
  </tr>
 * 		this script process some important server information and displays it
 * Authors:	Liran Tal <liran@enginx.com>
 *		Carlos Cesario <carloscesario@gmail.com>
	include_once('include/management/pages_common.php');
	$file_name = "/proc/uptime";

	$fopen_file = fopen($file_name, 'r');
	$buffer = explode(' ', fgets($fopen_file, 4096));
	fclose($fopen_file);

	$sys_ticks = trim($buffer[0]);
	$min = $sys_ticks / 60;
	$hours = $min / 60;
	$days = floor($hours / 24);
	$hours = floor($hours - ($days * 24));
	$min = floor($min - ($days * 60 * 24) - ($hours * 60));
	$result = "";

	if ($days != 0) {
		if ($days > 1)
			$result = "$days " . " days ";
		else
			$result = "$days " . " day ";
	}

	if ($hours != 0) {
		if ($hours > 1)
			$result .= "$hours " . " hours ";
		else
			$result .= "$hours " . " hour ";
	}

	if ($min > 1 || $min == 0)
		$result .= "$min " . " minutes ";
	elseif ($min == 1)
		$result .= "$min " . " minute ";

	return $result;
	$file_name = "/proc/sys/kernel/hostname";
	if ($fopen_file = fopen($file_name, 'r')) {
		$result = trim(fgets($fopen_file, 4096));
		fclose($fopen_file);
	} else {
		$result = "(none)";
	}
	return $result;
	if ($today = date("F j, Y, g:i a")) {
		$result = $today;
	} else {
		$result = "(none)";
	}

	return $result;
	$file_name = "/proc/loadavg";
	$result = "";
	$output = "";
	// get the /proc/loadavg information
	if ($fopen_file = fopen($file_name, 'r')) {
		$result = trim(fgets($fopen_file, 256));
		fclose($fopen_file);
	} else {
		$result = "(none)";
	}
	$loadavg = explode(" ", $result);
	$output .= $loadavg[0] . " " . $loadavg[1] . " " . $loadavg[2] . "<br/>";
	// get information the 'top' program
	$file_name = "top -b -n1 | grep \"Tasks:\" -A1";
	$result = "";
	if ($popen_file = popen($file_name, 'r')) {
		$result = trim(fread($popen_file, 2048));
		pclose($popen_file);
	} else {
		$result = "(none)";
	}
	$result = str_replace("\n", "<br/>", $result);
	$output .= $result;
	return $output;
	$file_name = "/proc/meminfo";
	$mem_array = array();

	$buffer = file($file_name);

	while (list($key, $value) = each($buffer)) {
		if (strpos($value, ':') !== false) {
			$match_line = explode(':', $value);
			$match_value = explode(' ', trim($match_line[1]));
			if (is_numeric($match_value[0])) {
				$mem_array[trim($match_line[0])] = trim($match_value[0]);
			}
		}
	}

	return $mem_array;
	return round($value / 1024) . " MB\n";
	$devices = array();
	$file_name = "/proc/net/dev";

	if ($fopen_file = fopen($file_name, 'r')) {
		while ($buffer = fgets($fopen_file, 4096)) {
			if (preg_match("/eth[0-9][0-9]*/i", trim($buffer), $match)) {
				$devices[] = $match[0];
			}
		}
		$devices = array_unique($devices);
		sort($devices);
		fclose ($fopen_file);
	}
	return $devices;
	$command_name = "/sbin/ifconfig $ifname";
	$ifip = "";

	exec($command_name , $command_result);

	$ifip = implode($command_result, "\n");
	if (preg_match("/inet addr:[0-9\.]*/i", $ifip, $match)) {
		$match = explode(":", $match[0]);
		return $match[1];
	} elseif (preg_match("/inet [0-9\.]*/i", $ifip, $match)) {
		$match = explode(" ", $match[0]);
		return $match[1];
	} else {
		return "(none)";
	}
	$command_name = "/sbin/ifconfig $ifname";
	$ifip = "";

	exec($command_name , $command_result);

	$ifmac = implode($command_result, "\n");
	if (preg_match("/hwaddr [0-9A-F:]*/i", $ifmac, $match)) {
		$match = explode(" ", $match[0]);
		return $match[1];
	} elseif (preg_match("/ether [0-9A-F:]*/i", $ifmac, $match)) {
		$match = explode(" ", $match[0]);
		return $match[1];
	} else {
		return "(none)";
	}
	$command_name = "/sbin/ifconfig $ifname";
	$ifmask = "";

	exec($command_name , $command_result);

	$ifmask = implode($command_result, "\n");
	if (preg_match("/mask:[0-9\.]*/i", $ifmask, $match)) {
		$match = explode(":", $match[0]);
		return $match[1];
	} elseif (preg_match("/netmask [0-9\.]*/i", $ifmask, $match)) {
		$match = explode(" ", $match[0]);
		return $match[1];
	} else {
		return "(none)";
	}
?>
<?php
	echo "<h3>General Information</h3>";
<table class='summarySection'>
    <td class='summaryKey'> Uptime </td>
    <td class='summaryValue'><span class='sleft'><?php echo uptime(); ?></span> </td>
    <td class='summaryKey'> System Load </td>
    <td class='summaryValue'><span class='sleft'><?php echo get_system_load(); ?></span> </td>
    <td class='summaryKey'> Hostname </td>
    <td class='summaryValue'><span class='sleft'><?php echo get_hostname(); ?></span> </td>
    <td class='summaryKey'> Current Date </td>
    <td class='summaryValue'><span class='sleft'><?php echo get_datetime(); ?></span> </td>
<?php
	echo "<h3>Memory Information</h3>";
	$meminfo = get_memory();
?>


<table class='summarySection'>
    <td class='summaryKey'> Mem. Total </td>
    <td class='summaryValue'><span class='sleft'><?php echo convert_ToMB ($meminfo['MemTotal']); ?></span> </td>
    <td class='summaryKey'> Mem. Free </td>
    <td class='summaryValue'><span class='sleft'><?php echo convert_ToMB ($meminfo['MemFree']); ?></span> </td>
    <td class='summaryKey'> Mem. Used </td>
    <td class='summaryValue'>
		<span class='sleft'>
			<?php
				$memused = ($meminfo['MemTotal'] - $meminfo['MemFree']);
				echo convert_ToMB ($memused);
			?>
		</span> </td>
<?php
	echo "<h3>Harddrive Information</h3>";
	$hddfreespace = get_hdd_freespace();
?>
<table class='summarySection'>
    <td class='summaryKey'> Free Drive Space </td>
    <td class='summaryValue'><span class='sleft'><?php echo toxbyte ($hddfreespace); ?></span> </td>

	echo "<h3>Network Interfaces</h3>";
	$iflist = get_interface_list();

	foreach ($iflist as $ifname) {
			echo "\t<table class='summarySection'>\n";
			echo "\t<tr>\n";
			echo "\t\t<td class='summaryKey'></td>\n";
			echo "\t\t<td class='stitle'>\n";
			echo "\t\t\t$ifname\n";
			echo "\t\t</td>\n";
			echo "\t</tr>\n";
			echo "\t<tr>\n";
			echo "\t<tr>\n";
			echo "\t\t<td class='summaryKey'>\n";
			echo "\t\t\tIp\n";
			echo "\t\t</td>\n";
			echo "\t\t<td class='summaryValue'>\n";
			echo "\t\t\t".get_ip_addr($ifname)."\n";
			echo "\t\t</td>\n";
			echo "\t</tr>\n";
			echo "\t<tr>\n";
			echo "\t\t<td class='summaryKey'>\n";
			echo "\t\t\tMask\n";
			echo "\t\t</td>\n";
			echo "\t\t<td class='summaryValue'>\n";
			echo "\t\t\t".get_mask_addr($ifname)."\n";
			echo "\t\t</td>\n";
			echo "\t</tr>\n";
			echo "\t<tr>\n";
			echo "\t\t<td class='summaryKey'>\n";
			echo "\t\t\tMAC address\n";
			echo "\t\t<td class='summaryValue'>\n";
			echo "\t\t\t".get_mac_addr($ifname)."\n";
			echo "\t\t</td>\n";
			echo "\t</tr>\n";
		}

	echo "\t</table>\n";
 *		this script displays the radius log file ofcourse
 *		proper premissions must be applied on the log file for the web
 *		server to be able to read it
 * Authors:	Liran Tal <liran@enginx.com>
$logfile_loc1 = '/var/log/syslog';
$logfile_loc2 = '/var/log/messages';
if (file_exists($logfile_loc1))
	$logfile = $logfile_loc1;
else if (file_exists($logfile_loc2))
	$logfile = $logfile_loc2;
else {
	$failureMsg = "error reading system log file:<br/>".
		"looked for log file in $logfile_loc1 and $logfile_loc2 but couldn't find it.<br/>".
		"if you know where your system log file is located, set it's location in " . $_SERVER[SCRIPT_NAME];
	exit;
if (is_readable($logfile) == false) {
	$failureMsg = "error reading log file: <u>$logfile</u> <br/>".
		"possible cause is file premissions or file doesn't exist.<br/>";
                if (file_get_contents($logfile)) {
                        $fileReversed = array_reverse(file($logfile));
                        $counter = $systemLineCount;
                        foreach ($fileReversed as $line) {
                                if (preg_match("/$systemFilter/i", $line)) {
                                        if ($counter == 0)
                                                break;
                                        $ret = preg_replace("/\n/i", "<br>", $line);
                                        echo $ret;
                                        $counter--;
                                }
                        }


 * Description:
 *		displays a welcome page for the main index.php file
 * Authors:	Liran Tal <liran@enginx.com>
 *          Miguel García <miguelvisgarcia@gmail.com>
echo "
	<center>

		<h2> daloRADIUS Web Management Server </h2>
		<h3> ".t('all','daloRADIUSVersion')." / ".$configValues['DALORADIUS_DATE']." </h3>
		<h4> <a href=\"mailto:liran.tal@gmail.com\"> Liran Tal </a> </h4>
		<br/><br/><br/>
		<img src='images/daloradius_logo.jpg' border=0 />
	</center>
";

 * Authors:	Liran Tal <liran@enginx.com>
    include ("library/checklogin.php");
	include('library/check_operator_perm.php');
        isset($_GET['bootLineCount']) ? $bootLineCount = $_GET['bootLineCount'] : $bootLineCount = 50;
        isset($_GET['bootFilter']) ? $bootFilter = $_GET['bootFilter'] : $bootFilter = ".";
	include_once('library/config_read.php');
    $logQuery = "performed query on page: ";
<?php

    include ("menu-reports-logs.php");
  	
?>	
		<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#" onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogsboot.php'); ?>
                :: <?php if (isset($bootLineCount)) { echo $bootLineCount . " Lines Count "; } ?>
                   <?php if (isset($bootFilter)) { echo " with filter set to " . $bootFilter; } ?>
		<h144>&#x2754;</h144></a></h2>

		<div id="helpPage" style="display:none;visibility:visible" >
			<?php echo t('helpPage','replogsboot') ?>
			<br/>
		</div>
		<br/>
	include 'library/exten-boot_log.php';
                <?php
                        include_once('include/management/actionMessages.php');
                ?>


		</div>
		
		<div id="footer">
		
								<?php
        include 'page-footer.php';
		
		</div>
		
</div>
 * Authors:	Liran Tal <liran@enginx.com>
	include ("library/checklogin.php");
	$operator = $_SESSION['operator_user'];
	include('library/check_operator_perm.php');
	isset($_GET['daloradiusLineCount']) ? $daloradiusLineCount = $_GET['daloradiusLineCount'] : $daloradiusLineCount = 50;
	isset($_GET['daloradiusFilter']) ? $daloradiusFilter = $_GET['daloradiusFilter'] : $daloradiusFilter = ".";
	include_once('library/config_read.php');
	$log = "visited page: ";
	$logQuery = "performed query on page: ";
	include('include/config/logging.php');
?>

<?php

    include ("menu-reports-logs.php");
  	
?>	
	<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogsdaloradius.php'); ?>
		:: <?php if (isset($daloradiusLineCount)) { echo $daloradiusLineCount . " Lines Count "; } ?>
		   <?php if (isset($daloradiusFilter)) { echo " with filter set to " . $daloradiusFilter; } ?>
		<h144>&#x2754;</h144></a></h2>
		<div id="helpPage" style="display:none;visibility:visible" >
			<?php echo t('helpPage','replogsdaloradius') ?>
			<br/>
		</div>
	include 'library/exten-daloradius_log.php';
                <?php
                        include_once('include/management/actionMessages.php');
                ?>

	</div>
	
	<div id="footer">
	
	include 'page-footer.php';

	</div>

</div>
 * Authors:	Liran Tal <liran@enginx.com>
    include ("library/checklogin.php");
	include('library/check_operator_perm.php');
        isset($_GET['radiusLineCount']) ? $radiusLineCount = $_GET['radiusLineCount'] : $radiusLineCount = 50;
        isset($_GET['radiusFilter']) ? $radiusFilter = $_GET['radiusFilter'] : $radiusFilter = ".";
	include_once('library/config_read.php');
    $logQuery = "performed query on page: ";
<?php

    include ("menu-reports-logs.php");
  	
?>	
		
		
		<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogsradius.php'); ?>
                :: <?php if (isset($radiusLineCount)) { echo $radiusLineCount . " Lines Count "; } ?>
                   <?php if (isset($radiusFilter)) { echo " with radiusFilter set to " . $radiusFilter; } ?>
		<h144>&#x2754;</h144></a></h2>

		<div id="helpPage" style="display:none;visibility:visible" >
			<?php echo t('helpPage','replogsradius') ?>
			<br/>
		</div>
		<br/>
	include 'library/exten-radius_log.php';

		</div>
		
		<div id="footer">
		
								<?php
        include 'page-footer.php';
		
		</div>
		
</div>

 * Authors:	Liran Tal <liran@enginx.com>
    include ("library/checklogin.php");
	include('library/check_operator_perm.php');
        isset($_GET['systemLineCount']) ? $systemLineCount = $_GET['systemLineCount'] : $systemLineCount = 50;
        isset($_GET['systemFilter']) ? $systemFilter = $_GET['systemFilter'] : $systemFilter = ".";
	include_once('library/config_read.php');
    $logQuery = "performed query on page: ";

    include ("menu-reports-logs.php");
  	
?>	
		<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogssystem.php'); ?>
                :: <?php if (isset($systemLineCount)) { echo $systemLineCount . " Lines Count "; } ?>
                   <?php if (isset($systemFilter)) { echo " with filter set to " . $systemFilter; } ?>
		<h144>&#x2754;</h144></a></h2>

		<div id="helpPage" style="display:none;visibility:visible" >
			<?php echo t('helpPage','replogssystem') ?>
			<br/>
		</div>
		<br/>

	include 'library/exten-syslog_log.php';
                <?php
                        include_once('include/management/actionMessages.php');
                ?>


		</div>
		
		<div id="footer">
		
								<?php
        include 'page-footer.php';
?>
		
		</div>
		
</div>

*
 * Authors:	Liran Tal <liran@enginx.com>
    include ("library/checklogin.php");
	include_once('library/config_read.php');
<?php

    include ("menu-reports-logs.php");

?>
		
		<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#" onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','replogs.php'); ?>
		<h144>&#x2754;</h144></a></h2>

		<div id="helpPage" style="display:none;visibility:visible" >
			<?php echo t('helpPage','replogs') ?>
			<br/>
		</div>
		<br/>


	include('include/config/logging.php');
		</div>
		
		<div id="footer">
		
								<?php
        include 'page-footer.php';
		
		</div>
		
</div>
*
 * Authors:	Liran Tal <liran@enginx.com>
    include ("library/checklogin.php");
    //$operator = $_SESSION['operator_user']
	//include('library/check_operator_perm.php');
	include_once('library/config_read.php');
    isset($_GET['cmd']) ? $cmd = $_GET['cmd'] : $cmd = "";
    
    	
    	case "disable":
    		exec("`which crontab` -u $cronUser -r");
    		break;
    	
    	case "enable":
    		exec("`which crontab` -u $cronUser $dalo_crontab_file");
    		break;
?>


<?php

?>	
		
		
		
		<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')">CRON Status
		<h144>&#x2754;</h144></a></h2>

		<div id="helpPage" style="display:none;visibility:visible" >
			<br/>
		</div>
		<br/>


<?php
	
	exec("/usr/bin/crontab -u $cronUser -l", $output, $retStatus);
	
?>


	<h3>CRON Entries</h3>
	<a href='rep-stat-cron.php?cmd=enable' >Enable CRON</a>
	&nbsp;
	<a href='rep-stat-cron.php?cmd=disable' >Disable CRON</a>
	<br/>
	<br/>
<?php 
	if ($retStatus != 0):		 
?>
	<font color='red'><b>Error</b> no crontab is configured for this user or user does not exist</font>
	<br/><br/>
	else:
	
	$i = 0;
		foreach($output as $text) {
			$i++;
			echo "<b>#$i:</b> " . $text . '<br/>';
		}
		
	endif;
		</div>
		
		<div id="footer">

        include 'page-footer.php';
		
		</div>
		
</div>

*
 * Authors:	Liran Tal <liran@enginx.com>
	include_once('library/config_read.php');

?>


<?php
	include_once ("library/tabber/tab-layout.php");
?>
<?php

  	
?>	
		
		
		<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')">RAID Status
		<h144>&#x2754;</h144></a></h2>

		<div id="helpPage" style="display:none;visibility:visible" >
			<br/>
		</div>
		<br/>



<div class="tabber">


	if (!file_exists('/proc/mdstat')):
?>
	<font color='red'><b>Error</b> accessing RAID device information:</font>
	<br/><br/>

<?php 
	else: 
	exec("cat /proc/mdstat  | awk '/md/ {print $1}'", $mdstat);

	<font color='red'><b>Error</b> accessing RAID device information:</font>
	<br/><br/>

	<?php
		foreach($mdstat as $mddevice):
	?>

			<div class="tabbertab" title="<?php echo $mddevice ?>">

				<?php
					$output = "";
					$cmd = "sudo /sbin/mdadm --detail /dev/$mddevice";
					exec($cmd, $output);
				?>
		
				<table class='summarySection'>
		
					<?php
						foreach($output as $line):
					?>
			
					<?php
						list($var, $val) = split(":", $line);
					?>
			
					  <tr>
						<td class='summaryKey'> <?php echo $var ?> </td>
						<td class='summaryValue'><span class='sleft'> <?php echo $val ?> </span> </td>
					  </tr>
			
					<?php endforeach; ?>
		
				</table>
		
			</div>

	<?php endforeach; ?>
<?php endif; ?>

</div>




		</div>
		
		<div id="footer">
		
        include 'page-footer.php';
		
		</div>
		
</div>

*
 * Authors:	Liran Tal <liran@enginx.com>
    include ("library/checklogin.php");
	include('library/check_operator_perm.php');


	include_once('library/config_read.php');
    $logQuery = "performed query on page: ";
?>

    include ("menu-reports-status.php");
	
?>	
		
		
		<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#" onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','repstatserver.php'); ?>
		<h144>&#x2754;</h144></a></h2>

		<div id="helpPage" style="display:none;visibility:visible" >
			<?php echo t('helpPage','repstatserver') ?>
			<br/>
		</div>
		<br/>
				
<?php
	include 'library/exten-server_info.php';
		</div>
		
		<div id="footer">
		
								<?php
        include 'page-footer.php';
		
		</div>
		
</div>
*
 * Authors:	Liran Tal <liran@enginx.com>
    include ("library/checklogin.php");
	include('library/check_operator_perm.php');


	include_once('library/config_read.php');
    $logQuery = "performed query on page: ";
?>


    include ("menu-reports-status.php");
  	
?>	
		
		
		<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')"><?php echo t('Intro','repstatradius.php'); ?>
		<h144>&#x2754;</h144></a></h2>

		<div id="helpPage" style="display:none;visibility:visible" >
			<?php echo t('helpPage','repstatradius') ?>
			<br/>
		</div>
		<br/>

<?php
	include 'library/exten-radius_server_info.php';
		</div>
		
		<div id="footer">
		
								<?php
        include 'page-footer.php';
		
		</div>
		
</div>
*
 * Authors:	Liran Tal <liran@enginx.com>
    include ("library/checklogin.php");
	include_once('library/config_read.php');

    include ("menu-reports-status.php");
  	
?>	
		
		
		<div id="contentnorightbar">
		
		<h2 id="Intro"><a href="#"  onclick="javascript:toggleShowDiv('helpPage')">UPS Status
		<h144>&#x2754;</h144></a></h2>

		<div id="helpPage" style="display:none;visibility:visible" >
			<br/>
		</div>
		<br/>



<?php
	exec("`which apcaccess`", $output, $retStatus);

	<h3>General Information</h3>
	$sep = ":";
	if ($retStatus != 0):
		$sep = "\n";		 
	<font color='red'><b>Error</b> accessing UPS device information:</font>
	<br/><br/>
<?php endif; ?>

<table class='summarySection'>


<?php 
	foreach($output as $line):
		list($var, $val) = split($sep, $line);

  <tr>
    <td class='summaryKey'> <?php echo $var ?> </td>
    <td class='summaryValue'><span class='sleft'> <?php echo $val ?> </span> </td>
  </tr>

<?php endforeach; ?>

</table>

		</div>
		
		<div id="footer">

        include 'page-footer.php';
		
		</div>
		
</div>

Fixed code:  *********************************************************************************************************
 * daloRADIUS - RADIUS Web Platform
 * Copyright (C) 2007 - Liran Tal <liran@enginx.com> All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 *********************************************************************************************************
 * Description:	   This file is used for controlling the logging actions
 * 
 * Authors:        Liran Tal <liran@enginx.com>
 *                 Filippo Lauria <filippo.lauria@iit.cnr.it>
 *
 *********************************************************************************************************
 */
// prevent this file to be directly accessed
if (strpos($_SERVER['PHP_SELF'], '/include/config/logging.php') !== false) {
    header("Location: ../../index.php");
    exit;
/*
 * It is important to understand that when logging.php is included in
 * a page AFTER an include for config_read.php it gains access to all
 * of the variables it's scope including the $configValues[....] because
 * it was included just before it.
 *
 * But it should be noticed that these variables are only accessible
 * in the scope of the general or main block of php code and are
 * not accessible from functions, so we can't just use $configValues[...]
 * variables from within logMessageNotice() or any other function
 * and so we must use them here as references.
 *
 * The relevant variables are:
 *
 * $operator
 * $_SERVER["SCRIPT_NAME"]
 * $configValues['CONFIG_LOG_FILE']
 *
 */
/*
 * @param $type        The message type, for example, NOTICE, DEBUG, ERROR, ACTION, etc...
 * @param $msg         The message string which should be logged to the file
 * @param $logFile     The full path for the filename to write logs to
 * @param $currPage    The current page that we included from
 * @return $table      The table name, either radcheck or radreply
 */
function logMessage($type, $msg, $logFile, $currPage) {
    $date = date('M d G:i:s');
    $msgString = $date . " " . $type . " " . $msg . " " . $currPage;
    $fp = fopen($logFile, "a");
    if ($fp) {
        fwrite($fp, $msgString  . "\n");
        fclose($fp);
        return;
    }

    echo "<div>"
       . '<span style="color: red">error: could not open the file for writing: <strong>'
       . $logFile . "</strong></span><br>"
       . "Check file permissions. The file should be writable by the webserver's user/group"
       . "</div>";
$logger_work = array();
if ($configValues['CONFIG_LOG_PAGES'] == "yes" && isset($log) && !empty($log)) {
    $logger_work['NOTICE'] = "$operator $log";
}
if ($configValues['CONFIG_LOG_QUERIES'] == "yes" && isset($logQuery) && !empty($logQuery)) {
    $logger_work['QUERIES'] = "$operator $logQuery";
if ($configValues['CONFIG_LOG_ACTIONS'] == "yes" && isset($logAction) && !empty($logAction)) {
    $logger_work['ACTIONS'] = "$operator $logAction";
}

/*
 ********************************************************************************
 ********************************************************************************
 */
if ($configValues['CONFIG_DEBUG_SQL'] == "yes" && isset($logDebugSQL) && !empty($logDebugSQL)) {
    $logger_work['DEBUG'] = "- SQL -" . " " . $logDebugSQL . " on page: ";
foreach ($logger_work as $type => $message) {
    logMessage($type, $message, $configValues['CONFIG_LOG_FILE'], $_SERVER["SCRIPT_NAME"]);
/* the continuation of the CONFIG_DEBUG_SQL actually, this prints to the page
 * being viewed */
if ($configValues['CONFIG_DEBUG_SQL_ONPAGE'] == "yes"  && isset($logDebugSQL) && !empty($logDebugSQL)) {
	echo "<br><br>"
       . "Debugging SQL Queries: <br>"
       . "<pre>$logDebugSQL</pre>"
       . "<br><br>";
/*
 *********************************************************************************************************
 * daloRADIUS - RADIUS Web Platform
 * Copyright (C) 2007 - Liran Tal <liran@enginx.com> All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 *********************************************************************************************************
 *
 * Description:
 *             This file provides control for messages that are printed to the
 *             screen in reply to actions such as applying forms, saving data,
 *             removing data and such.
 * 
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
 *
 *********************************************************************************************************
 */
// prevent this file to be directly accessed
if (strpos($_SERVER['PHP_SELF'], '/include/management/actionMessages.php') !== false) {
    header("Location: ../../index.php");
    exit;
if (isset($failureMsg) && !empty($failureMsg)) {
	printf('<div class="failure">%s</div>', $failureMsg);
if (isset($successMsg) && !empty($successMsg)) {
	printf('<div class="success">%s</div>', $successMsg);
}
 * 
 * Description:    global error handling for all PEAR packages, it isn't too wise to do
 *                 that as I've no idea what other php applications are running on this machine
 *                 even though this is really just about handling the error but still.
 *                 So instead we're using the object's error handling method (see library/opendb.php)
 *                 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errorHandler');
 * Authors:        Liran Tal <liran@enginx.com>
 *                 Filippo Lauria <filippo.lauria@iit.cnr.it>
// prevent this file to be directly accessed
if (strpos($_SERVER['PHP_SELF'], '/library/errorHandling.php') !== false) {
    header("Location: ../index.php");
    exit;
}
    echo '<div class="failure"><strong>Database error</strong><br>'
       . "Error message: <strong>" . $err->getMessage() . "</strong><br>"
       . "Debug info: <br>" . $err->getDebugInfo()
       . "</div>";
 *        this script displays the radius log file.
 *        Of course proper premissions must be applied on the log file for the web
 *        server to be able to read it
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
// prevent this file to be directly accessed
$extension_file = '/library/exten-boot_log.php';
if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
    header("Location: ../index.php");
    exit;
// possible locations for radius logs
$logfile_loc = array(
    '/var/log/boot',
    '/var/log/dmesg',
    '/usr/local/var/log/dmesg'
);

// select one log file
$logfile = "";

foreach ($logfile_loc as $tmp) {
    if (file_exists($tmp)) { 
    $logfile = $tmp;
        break;
    }
}

$logfile_enc = (!empty($logfile)) ? htmlspecialchars($logfile, ENT_QUOTES, 'UTF-8') : '(none)';

// check if it is empty
if (empty($logfile)) {
    $failureMsg = sprintf("<br><br>Error accessing log file: <strong>%s</strong><br><br>" . 
                          "Looked for log file in <strong>%s</strong> but could not find it.<br>" .
                          "If you know where your <em>dmesg (boot) log file</em> is located, " .
                          "specify its location in <strong>%s</strong>",
              $logfile_enc,
              htmlspecialchars(implode(", ", $logfile_loc), ENT_QUOTES, 'UTF-8'),
              htmlspecialchars($extension_file, ENT_QUOTES, 'UTF-8'));

    // check if it is readable
    if (is_readable($logfile) !== true) {
        $failureMsg = sprintf("<br><br>Error reading log file: <strong>%s</strong>.<br><br>Is this file readable?<br>",
                              $logfile_enc);
    } else {

        // get its content
        $logcontent = file_get_contents($logfile);
        if (!empty($logcontent)) {
            $counter = $bootLineCount;
            $filter = (!empty($bootFilter)) ? preg_quote($bootFilter, "/") : ".+";
            $fileReversed = array_reverse(file($logfile));

            echo '<div style="font-family: monospace">';
            foreach ($fileReversed as $line) {
                if (preg_match("/$filter/i", $line)) {
                    if ($counter == 0) {
                        break;
                    }
                    echo nl2br(htmlspecialchars($line, ENT_QUOTES, 'UTF-8'), false);
                    $counter--;
            }
            }
            echo '</div>';
        }
    }
 *        this script displays the daloradius log file ofcourse
 *        proper premissions must be applied on the log file for the web
 *        server to be able to read it
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
// prevent this file to be directly accessed
if (strpos($_SERVER['PHP_SELF'], '/library/exten-daloradius_log.php') !== false) {
    header("Location: ../index.php");
    exit;
}
// check if daloradius logfile is set
if (array_key_exists('CONFIG_LOG_FILE', $configValues) && isset($configValues['CONFIG_LOG_FILE'])) {
    $logfile = $configValues['CONFIG_LOG_FILE'];
    $logfile_enc = (!empty($logfile)) ? htmlspecialchars($logfile, ENT_QUOTES, 'UTF-8') : '(none)';
    // check if file exists
    if (!file_exists($logfile)) {
        $failureMsg = sprintf("<br><br>Error accessing log file: <strong>%s</strong><br><br>"
                            . "Looked for log file in <strong>%s</strong> but could not find it.<br>"
                            . "If you know where your <em>daloradius log file</em> is located, "
                            . "specify its location in your <strong>library/daloradius.conf.php</strong> file",
                              $logfile_enc, $logfile_enc);
    } else {
        // check if it is readable
        if (is_readable($logfile) !== true) {
            $failureMsg = sprintf("<br><br>Error reading log file: <strong>%s</strong>.<br><br>Is this file readable?<br>",
                                  $logfile_enc);
        } else {
            // get its content
            $logcontent = file_get_contents($logfile);
            if (!empty($logcontent)) {
                $counter = $daloradiusLineCount;
                $fileReversed = array_reverse(file($logfile));
                echo '<div style="font-family: monospace">';
                foreach ($fileReversed as $line) {
                    if ($counter == 0) {
                        break;
                    }
                    echo nl2br(htmlspecialchars($line, ENT_QUOTES, 'UTF-8'), false);
                    $counter--;
                
                }
                echo '</div>';
            }
        }
    }
 *        This code allows for running the 'radtest' binary tool provided with freeradius
 *        for performing a dry-run check to see if a user is able to successfully login
 *        or that there may be problems connecting.
 * Authors:    Liran Tal <liran@enginx.com>
 *             Giso Kegal <kegel@barum.de>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
// prevent this file to be directly accessed
$extension_file = '/library/exten-maint-radclient.php';
if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
    header("Location: ../index.php");
    exit;
}

$extension_file_enc = htmlspecialchars($extension_file, ENT_QUOTES, 'UTF-8');

// $radiusaddr  - the server address, this would most likely be the radius server IP Address/Hostname
// $options     - the options passed to the radclient program
// $command     - the command string that radclient sends (auth, acct, status, coa, disconnect), by default this functions does 'auth'
function user_auth($options, $user, $pass, $radiusaddr, $radiusport, $secret, $command="auth", $additional="") {

    $user = escapeshellarg($user);
    $pass = escapeshellarg($pass);
    $args = escapeshellarg("$radiusaddr:$radiusport") . " " . escapeshellarg($command) . " " . escapeshellarg($secret);
    $query = "User-Name=$user,User-Password=$pass";

    $radclient = "radclient";       // or you can change this with the full path if the binary radcilent program can not be
                                    // found within your $PATH variable

    $radclient_options = " -c " . escapeshellarg($options['count'])
                       . " -n " . escapeshellarg($options['requests'])
                       . " -r " . escapeshellarg($options['retries'])
                       . " -t " . escapeshellarg($options['timeout'])
                       . " " . $options['debug'];

    if ($options['dictionary']) {
        $radclient_options .= " -d " . escapeshellarg($options['dictionary']);
    }

    $cmd = sprintf('echo "%s" | %s %s %s 2>&1', escapeshellcmd($query), $radclient, $radclient_options, $args);
    $res = shell_exec($cmd);

    $print_cmd = "<strong>Executed:</strong><br>$cmd<br>";
    if ($res == "") {
        echo "<b>Error:</b> Command did not return any results.<br>"
           . "Please check that you have the <em>radclient binary program</em> installed and that it is found in your \$PATH variable<br>"
           . "You may also consult the file <strong>$extension_file_enc</strong> for other problems<br>";
           return $print_cmd;
    }

    $output_html = '<br><strong>Results:</strong><br><div style="font-family: monospace">' . nl2br($res) . '</div>';
    return $print_cmd . $output_html;
// $nasaddr    - NAS address to receive the coa or disconnect request packet
// $nasport    - NAS Port address (depends on the configuration on the NAS, this may be a different port for either CoA or Disconnect packets).
function user_disconnect($options, $user, $nasaddr, $nasport="3779", $nassecret, $command="disconnect", $additional="") {

    $user = escapeshellarg($user);

    $args = escapeshellarg("$nasaddr:$nasport") . " " . escapeshellarg($command). " " . escapeshellarg($nassecret);
    $query = "User-Name=$user";

    if (!empty($additional)) {
        $query .= ',' . $additional;
    }

    $radclient = "radclient";    // or you can change this with the full path if the binary radcilent program can not be
                                 // found within your $PATH variable

    $radclient_options = " -c " . escapeshellarg($options['count'])
                       . " -n " . escapeshellarg($options['requests'])
                       . " -r " . escapeshellarg($options['retries'])
                       . " -t " . escapeshellarg($options['timeout'])
                       . " " . $options['debug'];

    if ($options['dictionary']) {
        $radclient_options .= " -d " . escapeshellarg($options['dictionary']);
    }

    $cmd = sprintf('echo "%s" | %s %s %s 2>&1', escapeshellcmd($query), $radclient, $radclient_options, $args);
    $res = shell_exec($cmd);
    
    $print_cmd = "<strong>Executed:</strong><br>$cmd<br>";
    if ($res == "") {
        echo "<b>Error:</b> Command did not return any results.<br>"
           . "Please check that you have the <em>radclient binary program</em> installed and that it is found in your \$PATH variable<br>"
           . "You may also consult the file <strong>$extension_file_enc</strong> for other problems<br>";
           return $print_cmd;
    }
    
    $output_html = '<br><strong>Results:</strong><br><div style="font-family: monospace">' . nl2br($res) . '</div>';
    return $print_cmd . $output_html;
 *        this script displays the radius log file.
 *              Of course proper premissions must be applied
 *              on the log file for the web server to be able to read it
 * Authors:     Liran Tal <liran@enginx.com>
 *              Filippo Lauria <filippo.lauria@iit.cnr.it>
// prevent this file to be directly accessed
$extension_file = '/library/exten-radius_log.php';
if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
    header("Location: ../index.php");
    exit;
}

// possible locations for radius logs
$logfile_loc = array(
    '/var/log/freeradius/radius.log',
    '/usr/local/var/log/radius/radius.log',
    '/var/log/radius/radius.log'
);

// select one log file
$logfile = "";
    if (file_exists($tmp)) { 
    $logfile = $tmp;
        break;
    }
$logfile_enc = (!empty($logfile)) ? htmlspecialchars($logfile, ENT_QUOTES, 'UTF-8') : '(none)';

// check if it is empty
    printf("<br><br>Error accessing log file: <strong>%s</strong>.<br><br>"
         . "Looked for log file in <strong>%s</strong> but could not find it.<br>"
         . "If you know where your <em>freeradius log file</em> is located, "
         . "specify its location in <strong>%s</strong>",
           $logfile_enc, htmlspecialchars(implode(", ", $logfile_loc), ENT_QUOTES, 'UTF-8'), $logfile_enc);
    exit;
// check if it is readable
if (is_readable($logfile) !== true) {
    $failureMsg = sprintf("<br><br>Error reading log file: <strong>%s</strong>.<br><br>Is this file readable?<br>",
                          $logfile_enc);
    exit;
}

// get its content
$logcontent = file_get_contents($logfile);
if (!empty($logcontent)) {
    $counter = $radiusLineCount;
    $filter = (!empty($radiusFilter)) ? preg_quote($radiusFilter, "/") : ".+";
    $fileReversed = array_reverse(file($logfile));
    echo '<div style="font-family: monospace">';
    foreach ($fileReversed as $line) {
    if (preg_match("/$filter/i", $line)) {
        if ($counter == 0) {
            break;
        echo nl2br(htmlspecialchars($line, ENT_QUOTES, 'UTF-8'), false);
        }
    echo '</div>';
 *        this script uses pgrep to check if services stored
 *              in $services_to_check are running
 * Authors:    Liran Tal <liran@enginx.com>
 *              Filippo Lauria <filippo.lauria@iit.cnr.it>

// prevent this file to be directly accessed
if (strpos($_SERVER['PHP_SELF'], '/library/exten-radius_server_info.php') !== false) {
    header("Location: ../index.php");
    exit;
}

// given the $service_name, this function returns "Running" if that service is running
function check_service($service_name) {
    if (empty($service_name)) {
        return "no service name";
    }

    $command = sprintf("pgrep %s", escapeshellarg($service_name));
    exec($command, $output, $result_code);
    return ($result_code === 0) ? "Running" : "Not running";
$services_to_check = array("FreeRADIUS", "MySQL", "MariaDB");

<h3>Service Status</h3>
<table class="summarySection">
    $format = '<tr><td class="summaryKey">%s</td><td class="summaryValue"><span class="sleft">%s'
            . "</span></td></tr>\n";
    foreach ($services_to_check as $service_name) {
        printf($format, $service_name, check_service(strtolower($service_name)));
    }
 *         this script process some important server information and displays it
 * Authors:    Liran Tal <liran@enginx.com>
 *             Carlos Cesario <carloscesario@gmail.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>

// prevent this file to be directly accessed
$extension_file = '/library/exten-server_info.php';
if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
    header("Location: ../index.php");
    exit;
}

include_once('include/management/pages_common.php');

// returns system name and version
function get_system_name_and_version() {
    $command = "cat /etc/*release | grep ^NAME\= | cut -d'=' -f2- | tr -d '\"'";
    exec($command, $output, $result_code);
    if ($result_code !== 0) {
        return "(n/d)";
    }
    
    $result = $output[0];
    $output = null;
    $result_code = null;
    
    $command = "cat /etc/*release | grep ^VERSION\= | cut -d'=' -f2- | tr -d '\"'";
    exec($command, $output, $result_code);
    if ($result_code === 0) {
        $result .= sprintf(", version %s", $output[0]);
    }
    
    return $result;
}

    $file_name = "/proc/uptime";

    $fopen_file = fopen($file_name, 'r');
    $buffer = explode(' ', fgets($fopen_file, 4096));
    fclose($fopen_file);

    $sys_ticks = trim($buffer[0]);
    $min = $sys_ticks / 60;
    $hours = $min / 60;
    $days = floor($hours / 24);
    $hours = floor($hours - ($days * 24));
    $min = floor($min - ($days * 60 * 24) - ($hours * 60));
    $result = "";

    if ($days != 0) {
        $result .= $days;
        $result .= ($days > 1) ? " days " : " day ";
    }

    if ($hours != 0) {
        $result .= $hours;
        $result .= ($hours > 1) ? " hours " : " hour ";
    }

    if ($min > 1 || $min == 0)
        $result .= "$min " . " minutes ";
    elseif ($min == 1)
        $result .= "$min " . " minute ";

    return $result;
    $file_name = "/proc/sys/kernel/hostname";
    if ($fopen_file = fopen($file_name, 'r')) {
        $result = trim(fgets($fopen_file, 4096));
        fclose($fopen_file);
    } else {
        $result = "(n/d)";
    }
    return $result;
    $today = date("F j, Y, g:i a");
    return ($today) ? $today : "(n/d)";
    $file_name = "/proc/loadavg";
    $result = "";
    $output = "";
    // get the /proc/loadavg information
    if ($fopen_file = fopen($file_name, 'r')) {
        $result = trim(fgets($fopen_file, 256));
        fclose($fopen_file);
    } else {
        $result = "(n/d)";
    }
    $loadavg = explode(" ", $result);
    $output .= $loadavg[0] . " " . $loadavg[1] . " " . $loadavg[2] . "<br/>";
    // get information the 'top' program
    $file_name = "top -b -n1 | grep \"Tasks:\" -A1";
    $result = "";
    if ($popen_file = popen($file_name, 'r')) {
        $result = trim(fread($popen_file, 2048));
        pclose($popen_file);
    } else {
        $result = "(n/d)";
    }
    $result = str_replace("\n", "<br/>", $result);
    $output .= $result;
    return $output;
    $file_name = "/proc/meminfo";
    $mem_array = array();

    $buffer = file($file_name);

    while (list($key, $value) = each($buffer)) {
        if (strpos($value, ':') !== false) {
            $match_line = explode(':', $value);
            $match_value = explode(' ', trim($match_line[1]));
            if (is_numeric($match_value[0])) {
                $mem_array[trim($match_line[0])] = trim($match_value[0]);
            }
        }
    }

    return $mem_array;
    return round($value / 1024) . " MB\n";
    $devices = array();
    $file_name = "/proc/net/dev";

    if ($fopen_file = fopen($file_name, 'r')) {
        while ($buffer = fgets($fopen_file, 4096)) {
            if (preg_match("/eth[0-9][0-9]*/i", trim($buffer), $match)) {
                $devices[] = $match[0];
            }
        }
        $devices = array_unique($devices);
        sort($devices);
        fclose ($fopen_file);
    }
    return $devices;
    $command_formats = array(
        '(ip addr show %s || /sbin/ip addr show %s) | grep inet | grep -v inet6 | sed -E "s/^\s+//g" | cut -d" " -f2 | cut -d"/" -f1',
        '(ifconfig %s || /sbin/ifconfig %s) | grep -oE "inet ([0-9]{1,3}\.?){4}" | cut -d" " -f2'
    );

    foreach ($command_formats as $format) {
        $command = sprintf($format, escapeshellarg($ifname), escapeshellarg($ifname));
        exec($command, $output, $result_code);
        if ($result_code === 0) {
            return $output[0];
        }
    }

    return "(n/d)";
    $command_formats = array(
        '(ip addr show %s || /sbin/ip addr show %s) | grep "link/ether" | sed -E "s/^\s+//g" | cut -d" " -f2',
        '(ifconfig %s || /sbin/ifconfig %s) | grep "ether" | sed -E "s/^\s+//g" | cut -d" " -f2'
    );

    foreach ($command_formats as $format) {
        $command = sprintf($format, escapeshellarg($ifname), escapeshellarg($ifname));
        exec($command, $output, $result_code);

        if ($result_code === 0 && preg_match("/^([0-9A-F]{2}\:){5}[0-9A-F]{2}$/i", $output[0])) {
            return $output[0];
        }
    }

    return "(n/d)";
    $command_formats = array(
        'echo -n "/"; (ip addr show %s || /sbin/ip addr show %s) | grep inet | grep -v inet6 | sed -E "s/^\s+//g" | cut -d" " -f2 | cut -d"/" -f2',
        '(ifconfig %s || /sbin/ifconfig %s) | grep -oE "netmask ([0-9]{1,3}\.?){4}" | cut -d" " -f2'
    );
    
    foreach ($command_formats as $format) {
        $command = sprintf($format, escapeshellarg($ifname), escapeshellarg($ifname));
        exec($command, $output, $result_code);
        if ($result_code === 0) {
            return $output[0];
        }
    }
    
    return "(n/d)";
// memory info
$meminfo = get_memory();
$memused = ($meminfo['MemTotal'] - $meminfo['MemFree']);
// hdd info
$hddfreespace = get_hdd_freespace();

// network interfaces info
$iflist = get_interface_list();
<h3>General Information</h3>
<table class="summarySection">
    <td class="summaryKey">System distro</td>
    <td class="summaryValue"><span class="sleft"><?= get_system_name_and_version() ?></span></td>
    
    <td class="summaryKey">Uptime</td>
    <td class="summaryValue"><span class="sleft"><?= uptime() ?></span></td>
    <td class="summaryKey">System Load</td>
    <td class="summaryValue"><span class="sleft"><?= get_system_load() ?></span></td>
    <td class="summaryKey">Hostname</td>
    <td class="summaryValue"><span class="sleft"><?= get_hostname() ?></span></td>
  </tr>
  <tr>
    <td class="summaryKey">Current Date</td>
    <td class="summaryValue"><span class="sleft"><?= get_datetime() ?></span></td>
<h3>Memory Information</h3>
<table class="summarySection">
    <td class="summaryKey">Mem. Total</td>
    <td class="summaryValue"><span class="sleft"><?= convert_ToMB($meminfo['MemTotal']) ?></span></td>
    <td class="summaryKey">Mem. Free</td>
    <td class="summaryValue"><span class="sleft"><?= convert_ToMB($meminfo['MemFree']) ?></span></td>
    <td class="summaryKey">Mem. Used</td>
    <td class="summaryValue"><span class="sleft"><?= convert_ToMB($memused) ?></span></td>
<h3>Harddrive Information</h3>
<table class="summarySection">
  <tr>
    <td class="summaryKey">Free Drive Space</td>
    <td class="summaryValue"><span class="sleft"><?= toxbyte($hddfreespace) ?></span></td>
  </tr>
</table>
<h3>Network Interfaces</h3>
<?php
    foreach ($iflist as $ifname) {
?>
<table class="summarySection">    
    <td class="summaryKey">Interface</td>
    <td class="stitle"><?= $ifname ?></td>
  </tr>
  <tr>
    <td class="summaryKey">Ip</td>
    <td class="summaryValue"><span class="sleft"><?= get_ip_addr($ifname) ?></span></td>
  </tr>
  <tr>
    <td class="summaryKey">Mask</td>
    <td class="summaryValue"><span class="sleft"><?= get_mask_addr($ifname) ?></span></td>
  </tr>
  <tr>
    <td class="summaryKey">MAC address</td>
    <td class="summaryValue"><span class="sleft"><?= get_mac_addr($ifname) ?></span></td>
    }
 *             this script displays the radius log file ofcourse
 *             proper premissions must be applied on the log file for the web
 *             server to be able to read it
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
// prevent this file to be directly accessed
$extension_file = '/library/exten-syslog_log.php';
if (strpos($_SERVER['PHP_SELF'], $extension_file) !== false) {
    header("Location: ../index.php");
    exit;
}

// possible locations for syslog files
$logfile_loc = array(
    '/var/log/syslog',
    '/var/log/messages'
);
// select one log file
$logfile = "";
foreach ($logfile_loc as $tmp) {
    if (file_exists($tmp)) { 
    $logfile = $tmp; 
        break;
    }
$logfile_enc = (!empty($logfile)) ? htmlspecialchars($logfile, ENT_QUOTES, 'UTF-8') : '(none)';

// check if it is empty
if (empty($logfile)) {
    $failureMsg = sprintf("<br><br>Error accessing log file: <strong>%s</strong>.<br><br>" . 
                          "Looked for log file in <strong>%s</strong> but could not find it.<br>" .
                          "If you know where your <em>system log file</em> is located, specify its location in <strong>%s</strong>",
                          $logfile_enc, htmlspecialchars(implode(", ", $logfile_loc), ENT_QUOTES, 'UTF-8'),
                          htmlspecialchars($extension_file, ENT_QUOTES, 'UTF-8'));

    // check if it is readable
    if (is_readable($logfile) !== true) {
        $failureMsg = sprintf("<br><br>Error reading log file: <strong>%s</strong>.<br><br>Is this file readable?<br>",
                              $logfile_enc);
    } else {

        // get its content
        $logcontent = file_get_contents($logfile);
        if (!empty($logcontent)) {
            $counter = $systemLineCount;
            $filter = (!empty($systemFilter)) ? preg_quote($systemFilter, "/") : ".+";
            $fileReversed = array_reverse(file($logfile));

            echo '<div style="font-family: monospace">';
            foreach ($fileReversed as $line) {
                if (preg_match("/$filter/i", $line)) {
                    if ($counter == 0) {
                        break;
                    }
                    echo nl2br(htmlspecialchars($line, ENT_QUOTES, 'UTF-8'), false);
                    $counter--;
            }
            echo '</div>';
        }
    }
 * Description: displays a welcome page for the main index.php file
 * Authors:     Liran Tal <liran@enginx.com>
 *              Miguel García <miguelvisgarcia@gmail.com>
 *              Filippo Lauria <filippo.lauria@iit.cnr.it>
// prevent this file to be directly accessed
if (strpos($_SERVER['PHP_SELF'], '/library/exten-welcome_page.php') !== false) {
    header("Location: ../index.php");
    exit;
}

<div style="text-align: center">
    <h2>daloRADIUS Web Management Server</h2>
    <h3><?= t('all', 'daloRADIUSVersion') ?> / <?= htmlspecialchars($configValues['DALORADIUS_DATE'], ENT_QUOTES, 'UTF-8') ?></h3>
    <h4><a href="mailto:liran.tal@gmail.com">Liran Tal</a></h4>
    <img src="images/daloradius_logo.jpg" style="border: 0; margin-top: 50px">
</div>
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
    include("library/checklogin.php");
    include('library/check_operator_perm.php');
    // parameter validation
    $bootLineCount = (array_key_exists('bootLineCount', $_GET) && isset($_GET['bootLineCount']) &&
                      intval($_GET['bootLineCount']) > 0)
                   ? intval($_GET['bootLineCount']) : 50;
    // preg quoted before usage
    $bootFilter = (array_key_exists('bootFilter', $_GET) && isset($_GET['bootFilter']))
                ? $_GET['bootFilter'] : "";
    include_once('library/config_read.php');
    include("menu-reports-logs.php");
      
?>    
    <div id="contentnorightbar">
        <h2 id="Intro">
            <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
                <?= t('Intro','replogsboot.php') ?> :: <?= $bootLineCount . " Lines Count " ?>
<?php 
    if (!empty($bootFilter) && $bootFilter !== '.+') {
        echo " with filter set to " . htmlspecialchars($bootFilter, ENT_QUOTES, 'UTF-8');
    }
                <h144>&#x2754;</h144>
            </a>
        </h2>
        <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage', 'replogsboot') ?><br></div>
        <br>
    include('library/exten-boot_log.php');
    include_once('include/management/actionMessages.php');
        </div>
        <div id="footer">
<?php
    include('page-footer.php');
        </div>
        
    </div>
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
    include("library/checklogin.php");
    $operator = $_SESSION['operator_user'];
    include('library/check_operator_perm.php');
    // parameter validation
    $daloradiusLineCount = (array_key_exists('daloradiusLineCount', $_GET) && isset($_GET['daloradiusLineCount']) &&
                            intval($_GET['daloradiusLineCount']) > 0)
                         ? intval($_GET['daloradiusLineCount']) : 50;
    include_once('library/config_read.php');
    $log = "visited page: ";
    include('include/config/logging.php');
    include("menu-reports-logs.php");
?>    
    <div id="contentnorightbar">
        <h2 id="Intro">
            <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
                <?= t('Intro','replogsdaloradius.php') ?> :: <?= $daloradiusLineCount . " Lines Count " ?>
                <h144>&#x2754;</h144>
            </a>
        </h2>
        <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage','replogsdaloradius') ?><br></div>
    include('library/exten-daloradius_log.php');
    include_once('include/management/actionMessages.php');
        </div>
        <div id="footer">
    include('page-footer.php');
        </div>
        
    </div>
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
    include("library/checklogin.php");
    include('library/check_operator_perm.php');
    // parameter validation
    $radiusLineCount = (array_key_exists('radiusLineCount', $_GET) && isset($_GET['radiusLineCount']) &&
                        intval($_GET['radiusLineCount']) > 0)
                     ? intval($_GET['radiusLineCount']) : 50;
    // preg quoted before usage
    $radiusFilter = (array_key_exists('radiusFilter', $_GET) && isset($_GET['radiusFilter']) &&
                     in_array($_GET['radiusFilter'], array( "Auth", "Info", "Error" )))
                  ? $_GET['radiusFilter'] : "";

    include_once('library/config_read.php');
    include ("menu-reports-logs.php");
    <div id="contentnorightbar">
        <h2 id="Intro">
            <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
                <?= t('Intro', 'replogsradius.php') ?> :: <?= $radiusLineCount . " Lines Count " ?>
<?php 
    if (!empty($radiusFilter) && $radiusFilter !== '.+') {
        echo " with filter set to " . htmlspecialchars($radiusFilter, ENT_QUOTES, 'UTF-8');
    }
?>
                <h144>&#x2754;</h144>
            </a>
        </h2>
        <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage', 'replogsradius') ?><br></div>
        <br>
    include('library/exten-radius_log.php');
    include_once('include/management/actionMessages.php');
        </div>
        
        <div id="footer">
<?php
    include('page-footer.php');
        </div>
        
    </div>
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
    include("library/checklogin.php");
    include('library/check_operator_perm.php');
    // parameter validation
    $systemLineCount = (array_key_exists('systemLineCount', $_GET) && isset($_GET['systemLineCount']) &&
                        intval($_GET['systemLineCount']) > 0)
                     ? intval($_GET['systemLineCount']) : 50;
    // preg quoted before usage
    $systemFilter = (array_key_exists('systemFilter', $_GET) && isset($_GET['systemFilter']))
                  ? $_GET['systemFilter'] : "";

    include_once('library/config_read.php');
    include ("menu-reports-logs.php");      
?>    
        <div id="contentnorightbar">
            <h2 id="Intro">
                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
                    <?= t('Intro', 'replogssystem.php'); ?> :: <?= $systemLineCount . " Lines Count" ?>
<?php 
    if (!empty($systemFilter)) {
        echo " with filter set to " . htmlspecialchars($systemFilter, ENT_QUOTES, 'UTF-8');
    }
                    <h144>&#x2754;</h144>
                </a>
            </h2>
            
            <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage', 'replogssystem') ?><br></div>
            <br>
    include('library/exten-syslog_log.php');
    include_once('include/management/actionMessages.php');
?>
        </div>
        
        <div id="footer">
    include('page-footer.php');
        </div>
    </div>
 *
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
    include("library/checklogin.php");
    include_once('library/config_read.php');
    include("menu-reports-logs.php");
        <div id="contentnorightbar">
            <h2 id="Intro">
                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
                    <?= t('Intro','replogs.php'); ?>
                    <h144>&#x2754;</h144>
                </a>
            </h2>
            <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage','replogs') ?><br></div>
            <br>
    include('include/config/logging.php');
        </div>
        
        <div id="footer">
        
<?php
        include('page-footer.php');
        
        </div>
    </div>
 *
 * Authors:     Liran Tal <liran@enginx.com>
 *              Filippo Lauria <filippo.lauria@iit.cnr.it>
    include("library/checklogin.php");
    $operator = $_SESSION['operator_user'];

    include('library/check_operator_perm.php');
    include_once('library/config_read.php');
    // validating params
    $cmd = (array_key_exists('cmd', $_GET) && isset($_GET['cmd']) &&
            in_array(strtolower($_GET['cmd']), array( "enable", "disable" )))
         ? strtolower($_GET['cmd']) : "";

    $exec = "";
        case "disable":
        $exec = sprintf("$(which crontab || command -v crontab) -u %s -r", escapeshellarg($cronUser));
        break;
        
        case "enable":
        $exec = sprintf("$(which crontab || command -v crontab) -u %s %s", escapeshellarg($cronUser), $dalo_crontab_file);
        break;
    if (!empty($exec)) {
        exec($exec);
    }
?>        
    <div id="contentnorightbar">
    
        <h2 id="Intro">
            <a href="#" onclick="javascript:toggleShowDiv('helpPage')">CRON Status
                <h144>&#x2754;</h144>
            </a>
            </h2>
            <div id="helpPage" style="display:none;visibility:visible"><br></div>
            <br>
            <h3>CRON Entries</h3>
            <a href="?cmd=enable">Enable CRON</a>
            &nbsp;
            <a href="?cmd=disable">Disable CRON</a>
            <br>
            <br>
    $failureMsg = "";

    $exec = sprintf("$(which crontab || command -v crontab) -u %s -l", escapeshellarg($cronUser));
    exec($exec, $output, $retStatus);

    if ($retStatus !== 0) {
        $failureMsg = '<strong>Error</strong> no crontab is configured for this user or user does not exist<br><br>';
    } else {
        $i = 1;
        foreach($output as $text) {
            printf('<strong>#%d</strong>: %s<br>', $i, htmlspecialchars($text, ENT_QUOTES, 'UTF-8'));
            $i++;
        }
    }
    
    if (!empty($failureMsg)) {
        include_once('include/management/actionMessages.php');
    }
        </div>
        
        <div id="footer">
    include('page-footer.php');
        </div>
        
    </div>
 *
 * Authors:     Liran Tal <liran@enginx.com>
 *              Filippo Lauria <filippo.lauria@iit.cnr.it>
    include_once('library/config_read.php');
      
?>    
        <div id="contentnorightbar">
            <h2 id="Intro">
                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
                    RAID Status <h144>&#x2754;</h144>
                </a>
            </h2>

            <div id="helpPage" style="display:none;visibility:visible"><br></div>
            <br>
    $failureMsg = "";
    $error = '<strong>Error</strong> accessing RAID device information<br><br>';
    
    if (!file_exists('/proc/mdstat')) {
        $failureMsg = $error;
    } else {
        exec("cat /proc/mdstat | awk '/md/ {print $1}'", $mdstat, $retStatus);
        
        if ($retStatus !== 0) {
            $failureMsg = $error;
        } else {
            if (count($mdstat) > 0) {
                include_once("library/tabber/tab-layout.php");
                echo '<div class="tabber">';
                foreach($mdstat as $mddevice) {
                    printf('<div class="tabbertab" title="%s">', htmlspecialchars($mddevice, ENT_QUOTES, 'UTF-8'));
                    
                    $dev = "/dev/$mddevice";
                    $cmd = sprintf("sudo /sbin/mdadm --detail %s", escapeshellarg($dev));
                    $output = "";
                    exec($cmd, $output);

                    echo '<table class="summarySection">';
                    foreach($output as $line) {
                        list($var, $val) = split(":", $line);
                        $var = htmlspecialchars($var, ENT_QUOTES, 'UTF-8');
                        $val = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
                        
                        printf('<tr><td class="summaryKey">%s</td>' .
                               '<td class="summaryValue"><span class="sleft">%s</span></td></tr>', $var, $val); 
                    }
                    echo '</table>'
                       . '</div>';

                }
                echo '</div>';

            } else {
                $failureMsg = $error;
            }
        }
    }
    
    if (!empty($failureMsg)) {
        include_once('include/management/actionMessages.php');
    }
            
        </div>
        
        <div id="footer">
    include('page-footer.php');
        </div>
        
    </div>
 *
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
    include("library/checklogin.php");
    include('library/check_operator_perm.php');
    include_once('library/config_read.php');
    include("menu-reports-status.php");
    
?>    
        <div id="contentnorightbar">
            <h2 id="Intro">
                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
                    <?= t('Intro','repstatserver.php'); ?>
                    <h144>&#x2754;</h144>
                </a>
            </h2>
            <div id="helpPage" style="display:none;visibility:visible"><?= t('helpPage','repstatserver') ?><br></div>
            <br>
                
    include('library/exten-server_info.php');
        </div>
        
        <div id="footer">
        
<?php
    include('page-footer.php');
        
        </div>
    </div>
 *
 * Authors:    Liran Tal <liran@enginx.com>
 *             Filippo Lauria <filippo.lauria@iit.cnr.it>
    include("library/checklogin.php");
    include('library/check_operator_perm.php');
    include_once('library/config_read.php');
    include("menu-reports-status.php");
      
?>    
        <div id="contentnorightbar">            
            <h2 id="Intro">
                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
                    <?= t('Intro','repstatradius.php'); ?>
                    <h144>&#x2754;</h144>
                </a>
            </h2>
            <div id="helpPage" style="display:none;visibility:visible" ><?= t('helpPage','repstatradius') ?><br></div>
            <br>
    include('library/exten-radius_server_info.php');
        </div>
        
        <div id="footer">        
<?php
        include('page-footer.php');
        
        </div>
    </div>
 *
 * Authors:     Liran Tal <liran@enginx.com>
 *              Filippo Lauria <filippo.lauria@iit.cnr.it>
    include("library/checklogin.php");
    include_once('library/config_read.php');
    include("menu-reports-status.php");
      
        <div id="contentnorightbar">
            <h2 id="Intro">
                <a href="#" onclick="javascript:toggleShowDiv('helpPage')">
                    UPS Status <h144>&#x2754;</h144>
                </a>
            </h2>
            <div id="helpPage" style="display:none;visibility:visible"><br></div>
            <br>
    exec("which apcaccess || command -v apcaccess", $output, $retStatus);
    $failureMsg = "";
    $sep = ":";
    if ($retStatus !== 0) {
        $sep = "\n";
        $failureMsg = '<strong>Error</strong> accessing UPS device information<br><br>';
    } else {
            <h3>General Information</h3>
            <table class="summarySection">
        foreach ($output as $line) {
        list($var, $val) = split($sep, $line);
        $var = htmlspecialchars($var, ENT_QUOTES, 'UTF-8');
        $val = htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
                <tr>
                <td class="summaryKey"><?= $var ?></td>
                <td class="summaryValue"><span class="sleft"><?= $val ?></span></td>
                </tr>
<?php
        }
            </table>
    }
    
    if (!empty($failureMsg)) {
        include_once('include/management/actionMessages.php');
    }
        </div>
        
        <div id="footer">
<?php
    include('page-footer.php');
?>
        </div>
        
    </div>