4b480f5bd868ef15ef37628f18a6f82815691291
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 Wurst jQuery-based Certlogin, so...

Bernd Wurst authored 11 years ago

17) // Setze das Arbeitsverzeichnis auf das Stammverzeichnis, damit die Voraussetzungen gleich sind wie bei allen anderen Requests
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

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

bernd authored 13 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 12 years ago

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

bernd authored 15 years ago

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

bernd authored 12 years ago

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

bernd authored 15 years ago

85)       $uid = $account['username'];
86)       $role = find_role($uid, '', True);
87)       setup_session($role, $uid);
88)       $destination = 'go/index/index';
89)       if (check_path($account['startpage']))
90)         $destination = $account['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)   }
97)   system_failure('Der angegebene Account kann mit diesem Client-Zertifikat nicht eingeloggt werden.');
98) }
99) else
100) {
bernd Freundlichere Fehlermeldung...

bernd authored 12 years ago

101)   if (isset($_SERVER['REDIRECT_SSL_CLIENT_CERT']) && 
102)       isset($_SERVER['REDIRECT_SSL_CLIENT_S_DN']) && $_SERVER['REDIRECT_SSL_CLIENT_S_DN'] != '' && 
103)       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

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 12 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

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

bernd authored 12 years ago

140)     title('Kein Client-Zertifikat');
141)     output('<p>Ihr Browser hat kein Client-Zertifikat gesendet. Eventuell müssen Sie in den Einstellungen des Browsers diese Funktion einschalten.</p>');
142)     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

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

bernd authored 13 years ago

146) show_page('certlogin');