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

bernd authored 15 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Bernd Wurst Updated copyright notice (2...

Bernd Wurst authored 11 years ago

5) Written 2008-2013 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15) */
bernd Login vial Client-Cert über...

bernd authored 15 years ago

16) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

17) chdir('..');
18) 
19) require_once('config.php');
bernd Login vial Client-Cert über...

bernd authored 15 years ago

20) global $prefix;
21) $prefix = '../';
22) 
23) // Das Parent-Verzeichnis in den Include-Pfad, da wir uns jetzt in einem anderen Verzeichnis befinden.
24) ini_set('include_path', ini_get('include_path').':../');
25) 
26) require_once('session/start.php');
27) require_once('inc/base.php');
28) require_once('inc/debug.php');
29) require_once('inc/error.php');
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

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

bernd authored 15 years ago

31) 
32) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

33) function prepare_cert($cert)
34) {
35) 	return str_replace(array('-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', ' ', "\n"), array(), $cert);
36) }
bernd Login vial Client-Cert über...

bernd authored 15 years ago

37) 
38) 
39) function get_logins_by_cert($cert) 
40) {
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

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

bernd authored 15 years ago

42) 	$query = "SELECT type,username,startpage FROM system.clientcert WHERE cert='{$cert}'";
43) 	$result = db_query($query);
44) 	if (mysql_num_rows($result) < 1)
45) 		return NULL;
46) 	else {
47) 		$ret = array();
48) 		while ($row = mysql_fetch_assoc($result)) {
49) 			$ret[] = $row;
50) 		}
51) 		return $ret;
52) 	}
53) }
54) 
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

55) DEBUG('$_SERVER:');
56) DEBUG($_SERVER);
57) 
bernd Login vial Client-Cert über...

bernd authored 15 years ago

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

bernd authored 14 years ago

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

60) {
61)   DEBUG('recording client-cert');
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

68)     die();
69)   }
70)   else
71)   {
72)     system_failure('Ihr Browser hat kein Client-Zertifikat gesendet');
73)   }
74) }
75) elseif (isset($_REQUEST['type']) && isset($_REQUEST['username'])) {
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

79)   $ret = get_logins_by_cert($_SERVER['REDIRECT_SSL_CLIENT_CERT']);
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

80)   DEBUG($ret);
bernd Login vial Client-Cert über...

bernd authored 15 years ago

81)   foreach ($ret as $account) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

82)     DEBUG('/'.$account['type'].'/'.$_REQUEST['type'].'/    /'.$account['username'].'/'.$_REQUEST['username'].'/    =>');
83)     if (($account['type'] == urldecode($_REQUEST['type'])) && ($account['username'] == urldecode($_REQUEST['username']))) {
bernd Login vial Client-Cert über...

bernd authored 15 years ago

84)       $uid = $account['username'];
85)       $role = find_role($uid, '', True);
86)       setup_session($role, $uid);
87)       $destination = 'go/index/index';
88)       if (check_path($account['startpage']))
89)         $destination = $account['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

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

bernd authored 15 years ago

92)       header('Location: ../'.$destination);
93)       die();
94)     }
95)   }
96)   system_failure('Der angegebene Account kann mit diesem Client-Zertifikat nicht eingeloggt werden.');
97) }
98) else
99) {
bernd Freundlichere Fehlermeldung...

bernd authored 12 years ago

100)   if (isset($_SERVER['REDIRECT_SSL_CLIENT_CERT']) && 
101)       isset($_SERVER['REDIRECT_SSL_CLIENT_S_DN']) && $_SERVER['REDIRECT_SSL_CLIENT_S_DN'] != '' && 
102)       isset($_SERVER['REDIRECT_SSL_CLIENT_I_DN']) && $_SERVER['REDIRECT_SSL_CLIENT_I_DN'] != '') {
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

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

bernd authored 15 years ago

104)     if ($ret === NULL) {
105)       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.');
106)     }
107)     if (count($ret) == 1) {
108)       $uid = $ret[0]['username'];
109)       $role = find_role($uid, '', True);
110)       setup_session($role, $uid);
111)       $destination = 'go/index/index';
112)       if (check_path($ret[0]['startpage']))
113)         $destination = $ret[0]['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

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

bernd authored 15 years ago

116)       header('Location: ../'.$destination);
117)       die();
118)     }
119)     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>
120)       <ul>');
121)     foreach ($ret as $account) {
122)       $type = 'System-Account';
123)       if ($account['type'] == 'email') {
124)         $type = 'E-Mail-Konto';
125)       }
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

126)       elseif ($account['type'] == 'subuser') {
127)         $type = 'Unter-Nutzer';
128)       }
bernd Login vial Client-Cert über...

bernd authored 15 years ago

129)       elseif ($account['type'] == 'customer') {
130)         $type = 'Kundenaccount';
131)       }
bernd Situation repaiert, wenn ei...

bernd authored 14 years ago

132)       $destination = 'go/index/index';
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

133)       if ($account['startpage'] && check_path($account['startpage']))
bernd Situation repaiert, wenn ei...

bernd authored 14 years ago

134)         $destination = $account['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

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

136)     }
137)     output('</ul>');
138)   } else {
bernd Freundlichere Fehlermeldung...

bernd authored 12 years ago

139)     title('Kein Client-Zertifikat');
140)     output('<p>Ihr Browser hat kein Client-Zertifikat gesendet. Eventuell müssen Sie in den Einstellungen des Browsers diese Funktion einschalten.</p>');
141)     output('<p>Bitte verwenden Sie <a href="/">die reguläre Anmeldung mit Benutzername und Passwort</a>.</p>');
bernd Login vial Client-Cert über...

bernd authored 15 years ago

142)   }
143) }
144) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

145) show_page('certlogin');