Просмотр исходного кода

Aktualisierung der Authentifizierungsklasse zur Verwendung von Sitzungsdateien im richtigen Verzeichnis und Anpassung der Zeichencodierung

gc-server3 2 недель назад
Родитель
Сommit
e5d4307352
2 измененных файлов с 59 добавлено и 41 удалено
  1. 1 1
      apps/MISConfigurator/MISConfigurator.class.inc
  2. 58 40
      lib/Auth.class.inc

+ 1 - 1
apps/MISConfigurator/MISConfigurator.class.inc

@@ -135,7 +135,7 @@ class MISConfigurator extends App {
 				$ret.= '</div>';
 				
 				if($this->isRole("master")) {
-					$buffer = "";
+					$buffer = self::$version;
 
 					/*if ( @fsockopen("www.global-cube.de", 80, $errno, $errstr, 5)) {
 					$filestream = @fopen("http://www.global-cube.de/GAPS/version.txt", "r");

+ 58 - 40
lib/Auth.class.inc

@@ -36,10 +36,14 @@ class Auth
 									'ip'  => null
 							);
 	
-	private $_authSessionsFile = "authSessions.xml";
+	private $_authSessionsFile;
 	public $authFile;
 
-	protected function __construct(){	
+	protected function __construct(){
+		if(!file_exists(ROOT_DIR."sessions/".session_id().".xml")){	
+			copy(ROOT_DIR."lib/session.xml",ROOT_DIR."sessions/".session_id().".xml");
+		}
+		$this->_authSessionsFile = session_id().".xml";
 		$this->authFile = ROOT_DIR."lib/auth.xml";
 	}
 
@@ -109,7 +113,7 @@ class Auth
 			$_SESSION[AUTH_SESSION] = $this->_getProp('session');
 		} else if ($status == AUTH_FAILED) {
 			$this->_logFailure();
-            unset($_SESSION[AUTH_SESSION]);
+			unset($_SESSION[AUTH_SESSION]);
 		} else if ($status == AUTH_CONFIRM_LOGIN) {
 			$this->_insertConfirmSession();
 			$_SESSION[AUTH_SESSION] = $this->_getProp('session');
@@ -118,8 +122,8 @@ class Auth
 	}
 	
 	private function _confirmLogin() {
-		$authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-		$authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+		$authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		$authSessionsXpath = new DOMXpath($authSessionsDOM);	
 		
 		//$sessionsForUsername = $authSessionsXpath->query("/sessions/session/@status[./../@username='".$this->_getProp("username")."' and ./../@status='online' and ./../@ip!='".$this->_getProp("ip")."']");;
@@ -195,10 +199,10 @@ class Auth
 					$ret = '';
 				}
 				break;
-				
+
 			case 'username':
-				$authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-				$authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+				$authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+				$authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
 				$authSessionsXpath = new DOMXpath($authSessionsDOM);	
 		
 				$sessions = $authSessionsXpath->query("/sessions/session/@username[./../@id='".$this->_getProp('session')."' and ./../@status='online' and ./../@ip='".$this->_getProp('ip')."' and ./../@userAgent='".utf8_to_latin1($this->_getProp('userAgent'))."']");
@@ -211,7 +215,7 @@ class Auth
 				break;
 			
 			case 'global':
-				$authDOM = new DOMDocument('1.0', 'utf-8');
+				$authDOM = new DOMDocument('1.0', 'iso-8859-1');
 				$authDOM->load(dirname(__file__)."/".$this->authFile);
 				$authXpath = new DOMXpath($authDOM);	
 		
@@ -225,7 +229,7 @@ class Auth
 				break;				
 				
 			case 'securityLevel':
-				$authDOM = new DOMDocument('1.0', 'utf-8');
+				$authDOM = new DOMDocument('1.0', 'iso-8859-1');
 				$authDOM->load(dirname(__file__)."/".$this->authFile);
 				$authXpath = new DOMXpath($authDOM);	
 		
@@ -246,7 +250,7 @@ class Auth
 
 	private function _getPassword(){
 		$MISConfig = new MISConfig();
-		$authDOM = new DOMDocument('1.0', 'utf-8');
+		$authDOM = new DOMDocument('1.0', 'iso-8859-1');
 		$authDOM->load(dirname(__file__)."/".$this->authFile);
 		$authXpath = new DOMXpath($authDOM);
 		
@@ -261,8 +265,22 @@ class Auth
 	}
 	
 	private function _deleteOldSessions() {
-        $authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-        $authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+		$verzeichnis = openDir(ROOT_DIR."sessions/");
+		// Verzeichnis lesen
+		while ($file = readDir($verzeichnis)) {
+		 // Höhere Verzeichnisse nicht anzeigen!
+		 if ($file != "." && $file != ".." && (filemtime(ROOT_DIR."sessions/".$this->_authSessionsFile)<(time()-604800))) {
+		 // Link erstellen
+		  echo "<a href=\"daten/$file\">$file</a><br>\n";
+		 }
+		}
+		 // Verzeichnis schließen
+		closeDir($verzeichnis);
+		
+		
+		
+        $authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+        $authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
         $authSessionsXpath = new DOMXpath($authSessionsDOM);
         
         $sessions = $authSessionsXpath->query("/sessions/session[@login < '".(time()-604800)."' and @login != '' and @id!='master']");
@@ -272,15 +290,15 @@ class Auth
         	$sessionParent->removeChild($session);
         }
         }
-        $authSessionsDOM->save(dirname(__file__)."/".$this->_authSessionsFile);
+        $authSessionsDOM->save(ROOT_DIR."sessions/".$this->_authSessionsFile);
 	}
 
 	private function _insertSession(){
 		$this->_deleteOldSessions();
-		$authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-		$authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+		$authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		$authSessionsXpath = new DOMXpath($authSessionsDOM);
-				
+
 		do {
 			$id = mt_rand();
 			$sessions = $authSessionsXpath->query("/sessions/session[@id = '".$id."']");
@@ -295,9 +313,9 @@ class Auth
 				$session = $sessions->item($i);
 				$session->attributes->getNamedItem("status")->nodeValue = "security";
 				$session->attributes->getNamedItem("logout")->nodeValue = time();
-			}			
+			}
 		}
-		
+
 		$sessions = $authSessionsXpath->query("/sessions/session[@status='confirm' and @session='".$this->_getProp("session")."' and @username='".utf8_to_latin1($this->_getProp('username'))."' and @ip='".$this->_getProp('ip')."']");
 		if($sessions->length > 0) {
 			//Set status = 'security'
@@ -309,7 +327,7 @@ class Auth
 			return;			
 		}
 		}
-		
+
 		$master = $authSessionsXpath->query("/sessions/session[@id = 'master']")->item(0);
 		$newSession = $master->cloneNode(true);
 		$newSession->attributes->getNamedItem("id")->nodeValue = $id;
@@ -322,14 +340,14 @@ class Auth
 		$newSession->attributes->getNamedItem("userAgent")->nodeValue = utf8_to_latin1($this->_getProp("userAgent"));
 		
 		$master->parentNode->appendChild($newSession);
-		$authSessionsDOM->save(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM->save(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		
 		$this->_props['session'] = $id;
 	}
-	
+
 	private function _insertConfirmSession(){
-		$authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-		$authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+		$authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		$authSessionsXpath = new DOMXpath($authSessionsDOM);		
 		do {
 			$id = mt_rand();
@@ -348,21 +366,21 @@ class Auth
 		$newSession->attributes->getNamedItem("userAgent")->nodeValue = utf8_to_latin1($this->_getProp("userAgent"));
 		
 		$master->parentNode->appendChild($newSession);
-		$authSessionsDOM->save(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM->save(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		
 		$this->_props['session'] = $id;
 	}
 
 	private function _logFailure() {
-		$authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-		$authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+		$authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		$authSessionsXpath = new DOMXpath($authSessionsDOM);
 
 		$master = $authSessionsXpath->query("/sessions/session[@id = 'master']")->item(0);
 		$newSession = $master->cloneNode(true);
 		$newSession->attributes->getNamedItem("id")->nodeValue = $this->_getProp('session');
 		$newSession->attributes->getNamedItem("username")->nodeValue = utf8_to_latin1($this->_getProp('username'));
-		$newSession->attributes->getNamedItem("password")->nodeValue = $this->_getProp('password');
+		$newSession->attributes->getNamedItem("password")->nodeValue = "";
 		$newSession->attributes->getNamedItem("status")->nodeValue = "failed";
 		$newSession->attributes->getNamedItem("login")->nodeValue = time();
 		$newSession->attributes->getNamedItem("logout")->nodeValue = time();
@@ -374,8 +392,8 @@ class Auth
 	}
 
 	private function _updateTimeout() {		
-		$authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-		$authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+		$authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		$authSessionsXpath = new DOMXpath($authSessionsDOM);
 		
 		if ($this->_options["timeout"] > 0) {
@@ -394,13 +412,13 @@ class Auth
 				$expiredSession->attributes->getNamedItem("status")->nodeValue = "expired";
 			}						
 		}
-		$authSessionsDOM->save(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM->save(ROOT_DIR."sessions/".$this->_authSessionsFile);
 	}
 
 	// This method needs ISDN fastfix
 	private function _logout() {
-		$authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-		$authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+		$authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		$authSessionsXpath = new DOMXpath($authSessionsDOM);
 		
 		$sessions = $authSessionsXpath->query("/sessions/session[@status='online' and @id='".$this->_getProp("session")."' and @ip='".$this->_getProp("ip")."' and @userAgent='".utf8_to_latin1($this->_getProp("userAgent"))."']");
@@ -408,21 +426,21 @@ class Auth
 			$session = $sessions->item(($sessions->length-1));
 			$session->attributes->getNamedItem("status")->nodeValue = "logout";
 			$session->attributes->getNamedItem("logout")->nodeValue = time();
-			$authSessionsDOM->save(dirname(__file__)."/".$this->_authSessionsFile);
+			$authSessionsDOM->save(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		}
 	}
 
 	// This method needs ISDN fastfix
 	private function _updateLogin(){
-		$authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-		$authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+		$authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		$authSessionsXpath = new DOMXpath($authSessionsDOM);		
 		
 		$sessions = $authSessionsXpath->query("/sessions/session[@status = 'online' and @id = '".$this->_getProp('session')."' and @ip = '".$this->_getProp('ip')."' and @userAgent = '".utf8_to_latin1($this->_getProp('userAgent'))."']");
 		if($sessions->length > 0) {
 			$session = $sessions->item(($sessions->length-1));
 			$session->attributes->getNamedItem("logout")->nodeValue = time();
-			$authSessionsDOM->save(dirname(__file__)."/".$this->_authSessionsFile);			
+			$authSessionsDOM->save(ROOT_DIR."sessions/".$this->_authSessionsFile);			
 			return true;
 		} else {
 			return false;
@@ -434,8 +452,8 @@ class Auth
 		if ($this->_updateLogin() == true)
 			return AUTH_LOGGED_IN;
 			
-		$authSessionsDOM = new DOMDocument('1.0', 'utf-8');
-		$authSessionsDOM->load(dirname(__file__)."/".$this->_authSessionsFile);
+		$authSessionsDOM = new DOMDocument('1.0', 'iso-8859-1');
+		$authSessionsDOM->load(ROOT_DIR."sessions/".$this->_authSessionsFile);
 		$authSessionsXpath = new DOMXpath($authSessionsDOM);	
 
 		$sessions = $authSessionsXpath->query("/sessions/session/@status[./../@id='".$this->_getProp('session')."' and ./../@id!='' and ./../@ip='".$this->_getProp('ip')."' and ./../@userAgent='".utf8_to_latin1($this->_getProp('userAgent'))."']");
@@ -461,7 +479,7 @@ class Auth
 	
 	private function _getAllUsernames($p_configFile) {
 		$MISConfig = new MISConfig();
-		$authDOM = new DOMDocument('1.0', 'utf-8');
+		$authDOM = new DOMDocument('1.0', 'iso-8859-1');
 		$authDOM->load(dirname(__file__)."/".$this->authFile);
 		$authXpath = new DOMXpath($authDOM);	
 		if($p_configFile == "") $configFile = $MISConfig->getConfigFile();