d96a86aa9e8ab73fd3b81d878ecaa669a4cfb1be
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 Login via Client-Zertifikat...

bernd authored 15 years ago

38) DEBUG($_ENV);
bernd Login vial Client-Cert über...

bernd authored 15 years ago

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

bernd authored 14 years ago

40) 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

41) {
42)   DEBUG('recording client-cert');
43)   if (isset($_ENV['REDIRECT_SSL_CLIENT_CERT']))
44)   {
45)     $_SESSION['clientcert_cert'] = prepare_cert($_ENV['REDIRECT_SSL_CLIENT_CERT']);
46)     $_SESSION['clientcert_dn'] = $_ENV['REDIRECT_SSL_CLIENT_S_DN'];
47)     $_SESSION['clientcert_issuer'] = $_ENV['REDIRECT_SSL_CLIENT_I_DN'];
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

49)     die();
50)   }
51)   else
52)   {
53)     system_failure('Ihr Browser hat kein Client-Zertifikat gesendet');
54)   }
55) }
56) elseif (isset($_REQUEST['type']) && isset($_REQUEST['username'])) {
bernd Login vial Client-Cert über...

bernd authored 15 years ago

57)   if (!isset($_ENV['REDIRECT_SSL_CLIENT_CERT'])) 
58)     system_failure('Ihr Browser hat kein Client-Zertifikat gesendet');
59) 
60)   $ret = get_logins_by_cert($_ENV['REDIRECT_SSL_CLIENT_CERT']);
61)   foreach ($ret as $account) {
62)     if (($account['type'] == $_REQUEST['type']) && ($account['username'] == $_REQUEST['username'])) {
63)       $uid = $account['username'];
64)       $role = find_role($uid, '', True);
65)       setup_session($role, $uid);
66)       $destination = 'go/index/index';
67)       if (check_path($account['startpage']))
68)         $destination = $account['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

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

bernd authored 15 years ago

71)       header('Location: ../'.$destination);
72)       die();
73)     }
74)   }
75)   system_failure('Der angegebene Account kann mit diesem Client-Zertifikat nicht eingeloggt werden.');
76) }
77) else
78) {
79)   if (isset($_ENV['REDIRECT_SSL_CLIENT_CERT'])) {
80)     $ret = get_logins_by_cert($_ENV['REDIRECT_SSL_CLIENT_CERT']);
81)     if ($ret === NULL) {
82)       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.');
83)     }
84)     if (count($ret) == 1) {
85)       $uid = $ret[0]['username'];
86)       $role = find_role($uid, '', True);
87)       setup_session($role, $uid);
88)       $destination = 'go/index/index';
89)       if (check_path($ret[0]['startpage']))
90)         $destination = $ret[0]['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

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

bernd authored 15 years ago

93)       header('Location: ../'.$destination);
94)       die();
95)     }
96)     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>
97)       <ul>');
98)     foreach ($ret as $account) {
99)       $type = 'System-Account';
100)       if ($account['type'] == 'email') {
101)         $type = 'E-Mail-Konto';
102)       }
103)       elseif ($account['type'] == 'customer') {
104)         $type = 'Kundenaccount';
105)       }
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

106)       output('<li>'.internal_link('', $type.': <strong>'.$account['username'].'</strong>', 'type='.$account['type'].'&username='.urlencode($account['username']).'&destination='.urlencode($destination)).'</li>');