100e4c0c538943817ae529f7d69b74cb08ac2c6f
bernd Login vial Client-Cert über...

bernd authored 15 years ago

1) <?php
2) 
3) require_once('../config.php');
4) global $prefix;
5) $prefix = '../';
6) 
7) // Das Parent-Verzeichnis in den Include-Pfad, da wir uns jetzt in einem anderen Verzeichnis befinden.
8) ini_set('include_path', ini_get('include_path').':../');
9) 
10) require_once('session/start.php');
11) require_once('inc/base.php');
12) require_once('inc/debug.php');
13) require_once('inc/error.php');
14) 
15) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

16) function prepare_cert($cert)
17) {
18) 	return str_replace(array('-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', ' ', "\n"), array(), $cert);
19) }
bernd Login vial Client-Cert über...

bernd authored 15 years ago

20) 
21) 
22) function get_logins_by_cert($cert) 
23) {
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

24) 	$cert = mysql_real_escape_string(prepare_cert($cert));
bernd Login vial Client-Cert über...

bernd authored 15 years ago

25) 	$query = "SELECT type,username,startpage FROM system.clientcert WHERE cert='{$cert}'";
26) 	$result = db_query($query);
27) 	if (mysql_num_rows($result) < 1)
28) 		return NULL;
29) 	else {
30) 		$ret = array();
31) 		while ($row = mysql_fetch_assoc($result)) {
32) 			$ret[] = $row;
33) 		}
34) 		return $ret;
35) 	}
36) }
37) 
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

38) DEBUG('$_SERVER:');
39) DEBUG($_SERVER);
40) 
bernd Login vial Client-Cert über...

bernd authored 15 years ago

41) 
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

42) if ($_SESSION['role'] != ROLE_ANONYMOUS && isset($_REQUEST['record']) && isset($_REQUEST['backto']) && check_path($_REQUEST['backto']))
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

43) {
44)   DEBUG('recording client-cert');
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

45)   if (isset($_SERVER['REDIRECT_SSL_CLIENT_CERT']) && $_SERVER['REDIRECT_SSL_CLIENT_S_DN'] != '' && $_SERVER['REDIRECT_SSL_CLIENT_I_DN'] != '')
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

46)   {
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

47)     $_SESSION['clientcert_cert'] = prepare_cert($_SERVER['REDIRECT_SSL_CLIENT_CERT']);
48)     $_SESSION['clientcert_dn'] = $_SERVER['REDIRECT_SSL_CLIENT_S_DN'];
49)     $_SESSION['clientcert_issuer'] = $_SERVER['REDIRECT_SSL_CLIENT_I_DN'];
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

50)     header('Location: '.$prefix.$_REQUEST['backto'].encode_querystring(''));
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

51)     die();
52)   }
53)   else
54)   {
55)     system_failure('Ihr Browser hat kein Client-Zertifikat gesendet');
56)   }
57) }
58) elseif (isset($_REQUEST['type']) && isset($_REQUEST['username'])) {
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

59)   if (!isset($_SERVER['REDIRECT_SSL_CLIENT_CERT'])) 
bernd Login vial Client-Cert über...

bernd authored 15 years ago

60)     system_failure('Ihr Browser hat kein Client-Zertifikat gesendet');
61) 
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

62)   $ret = get_logins_by_cert($_SERVER['REDIRECT_SSL_CLIENT_CERT']);
bernd Login vial Client-Cert über...

bernd authored 15 years ago

63)   foreach ($ret as $account) {
64)     if (($account['type'] == $_REQUEST['type']) && ($account['username'] == $_REQUEST['username'])) {
65)       $uid = $account['username'];
66)       $role = find_role($uid, '', True);
67)       setup_session($role, $uid);
68)       $destination = 'go/index/index';
69)       if (check_path($account['startpage']))
70)         $destination = $account['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

71)       if (isset($_REQUEST['destination']) && check_path($_REQUEST['destination']))
72)         $destination = $_REQUEST['destination'];
bernd Login vial Client-Cert über...

bernd authored 15 years ago

73)       header('Location: ../'.$destination);
74)       die();
75)     }
76)   }
77)   system_failure('Der angegebene Account kann mit diesem Client-Zertifikat nicht eingeloggt werden.');
78) }
79) else
80) {
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

81)   if (isset($_SERVER['REDIRECT_SSL_CLIENT_CERT']) && $_SERVER['REDIRECT_SSL_CLIENT_S_DN'] != '' && $_SERVER['REDIRECT_SSL_CLIENT_I_DN'] != '') {
82)     $ret = get_logins_by_cert($_SERVER['REDIRECT_SSL_CLIENT_CERT']);
bernd Login vial Client-Cert über...

bernd authored 15 years ago

83)     if ($ret === NULL) {
84)       system_failure('Ihr Browser hat ein Client-Zertifikat gesendet, dieses ist aber noch nicht für den Zugang hinterlegt. Gehen Sie bitte zurück und melden Sie sich bitte per Benutzername und Passwort an.');
85)     }
86)     if (count($ret) == 1) {
87)       $uid = $ret[0]['username'];
88)       $role = find_role($uid, '', True);
89)       setup_session($role, $uid);
90)       $destination = 'go/index/index';
91)       if (check_path($ret[0]['startpage']))
92)         $destination = $ret[0]['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

93)       if (isset($_REQUEST['destination']) && check_path($_REQUEST['destination']))
94)         $destination = $_REQUEST['destination'];
bernd Login vial Client-Cert über...

bernd authored 15 years ago

95)       header('Location: ../'.$destination);
96)       die();
97)     }
98)     output('<p>Ihr Browser hat ein gültiges SSL-Client-Zertifikat gesendet, mit dem Sie sich auf dieser Seite einloggen können. Allerdings haben Sie dieses Client-Zertifikat für mehrere Zugänge hinterlegt. Wählen Sie bitte den Zugang aus, mit dem Sie sich anmelden möchten.</p>
99)       <ul>');
100)     foreach ($ret as $account) {
101)       $type = 'System-Account';
102)       if ($account['type'] == 'email') {
103)         $type = 'E-Mail-Konto';
104)       }
105)       elseif ($account['type'] == 'customer') {
106)         $type = 'Kundenaccount';
107)       }
bernd Situation repaiert, wenn ei...

bernd authored 14 years ago

108)       $destination = 'go/index/index';
109)       if (check_path($account['startpage']))
110)         $destination = $account['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

111)       output('<li>'.internal_link('', $type.': <strong>'.$account['username'].'</strong>', 'type='.$account['type'].'&username='.urlencode($account['username']).'&destination='.urlencode($destination)).'</li>');
bernd Login vial Client-Cert über...

bernd authored 15 years ago

112)     }
113)     output('</ul>');
114)   } else {
115)     system_failure('Ihr Browser hat kein Client-Zertifikat gesendet.');
116)   }
117) }
118) 
bernd Situation repaiert, wenn ei...

bernd authored 14 years ago

119) include('../inc/top.php');
120) print $output;
121) include('../inc/bottom.php');
122)