openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

IdentAuth.class.php (1270B)


      1 <?php
      2 
      3 namespace cms\auth;
      4 
      5 use logger\Logger;
      6 use util\Http;
      7 
      8 /**
      9  * Authentifizierung via Ident-Server.
     10  *
     11  * Der Benutzername wird über einen Ident-Server, der auf dem
     12  * Client installiert sein muss, ermittelt.
     13  *
     14  * @author dankert
     15  */
     16 class IdentAuth implements Auth
     17 {
     18 	public function username()
     19 	{
     20 		$ip = Http::getClientIP();
     21 		$port = Http::getClientPort();
     22 		$identPort = 113;
     23 		if (!$socket = @fsockopen($ip, $identPort, $errno, $errstr, 10)) {
     24 			return null;
     25 		}
     26 
     27 		$line = $port . ',' . $_SERVER['SERVER_PORT'] . "\r\n";
     28 		@fwrite($socket, $line);
     29 		$line = @fgets($socket, 1000); // 1000 octets according to RFC 1413
     30 		fclose($socket);
     31 
     32 		$array = explode(':', $line, 4);
     33 		if (count($array) >= 4 && !strcasecmp(trim($array[1]), 'USERID')) {
     34 			$username = trim($array[3]);
     35 			Logger::debug('Ident: User-Id: ' . $username);
     36 			return $username;
     37 		} elseif (count($array) >= 3 && !strcasecmp(trim($array[1]), 'ERROR')) {
     38 			Logger::debug('Ident: Error: ' . trim($array[2]));
     39 			return null;
     40 		} else {
     41 			Logger::warn('Ident: Invalid ident server response: ' . $line);
     42 			return null;
     43 		}
     44 	}
     45 
     46 
     47 	/**
     48 	 * Ueberpruefen des Kennwortes ist über Ident nicht möglich.
     49 	 */
     50 	public function login($user, $password, $token)
     51 	{
     52 		return Auth::STATUS_FAILED;
     53 	}
     54 }