d73051da9b31a70a6349868ef3c83400b3f1ae47
bernd Login vial Client-Cert über...

bernd authored 15 years ago

1) <?php
2) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

3) chdir('..');
4) 
5) require_once('config.php');
bernd Login vial Client-Cert über...

bernd authored 15 years ago

6) global $prefix;
7) $prefix = '../';
8) 
9) // Das Parent-Verzeichnis in den Include-Pfad, da wir uns jetzt in einem anderen Verzeichnis befinden.
10) ini_set('include_path', ini_get('include_path').':../');
11) 
12) require_once('session/start.php');
13) require_once('inc/base.php');
14) require_once('inc/debug.php');
15) require_once('inc/error.php');
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

16) require_once('inc/theme.php');
bernd Login vial Client-Cert über...

bernd authored 15 years ago

17) 
18) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

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

bernd authored 15 years ago

23) 
24) 
25) function get_logins_by_cert($cert) 
26) {
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

41) DEBUG('$_SERVER:');
42) DEBUG($_SERVER);
43) 
bernd Login vial Client-Cert über...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

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

bernd authored 14 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

86)     if ($ret === NULL) {
87)       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.');
88)     }
89)     if (count($ret) == 1) {
90)       $uid = $ret[0]['username'];
91)       $role = find_role($uid, '', True);
92)       setup_session($role, $uid);
93)       $destination = 'go/index/index';
94)       if (check_path($ret[0]['startpage']))
95)         $destination = $ret[0]['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 15 years ago

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

bernd authored 15 years ago

98)       header('Location: ../'.$destination);
99)       die();
100)     }
101)     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>
102)       <ul>');
103)     foreach ($ret as $account) {
104)       $type = 'System-Account';
105)       if ($account['type'] == 'email') {
106)         $type = 'E-Mail-Konto';
107)       }
108)       elseif ($account['type'] == 'customer') {
109)         $type = 'Kundenaccount';
110)       }
bernd Situation repaiert, wenn ei...

bernd authored 14 years ago

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

bernd authored 15 years ago

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

115)     }
116)     output('</ul>');
117)   } else {
118)     system_failure('Ihr Browser hat kein Client-Zertifikat gesendet.');
119)   }
120) }
121) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

122) show_page('certlogin');