6dc51ba446a2faec08d321f9703e7c34a0aa82c6
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 Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 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) 
34) function get_logins_by_cert($cert) 
35) {
Bernd Wurst Sortiere Cert-Logins alphab...

Bernd Wurst authored 9 years ago

36) 	$result = db_query("SELECT type,username,startpage FROM system.clientcert WHERE cert=? ORDER BY type,username", array($cert));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

37) 	if ($result->rowCount() < 1)
bernd Login vial Client-Cert über...

bernd authored 15 years ago

38) 		return NULL;
39) 	else {
40) 		$ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

41) 		while ($row = $result->fetch()) {
bernd Login vial Client-Cert über...

bernd authored 15 years ago

42) 			$ret[] = $row;
43) 		}
44) 		return $ret;
45) 	}
46) }
47) 
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

48) DEBUG('$_SERVER:');
49) DEBUG($_SERVER);
50) 
Bernd Wurst verstehe Umgebungsvariablen...

Bernd Wurst authored 8 years ago

51) $redirect = "";
52) if (! isset($_SERVER['SSL_CLIENT_CERT']) && isset($_SERVER['REDIRECT_SSL_CLIENT_CERT'])) {
53)   $redirect = "REDIRECT_";
54) }
bernd Login vial Client-Cert über...

bernd authored 15 years ago

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

bernd authored 14 years ago

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

57) {
58)   DEBUG('recording client-cert');
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 7 years ago

59)   if (isset($_SERVER[$redirect.'SSL_CLIENT_CERT']) && isset($_SERVER[$redirect.'SSL_CLIENT_S_DN']) && 
Bernd Wurst Speichere und zeige Start-...

Bernd Wurst authored 7 years ago

60)       isset($_SERVER[$redirect.'SSL_CLIENT_I_DN']) && isset($_SERVER[$redirect.'SSL_CLIENT_M_SERIAL']) &&
61)       isset($_SERVER[$redirect.'SSL_CLIENT_V_START']) && isset($_SERVER[$redirect.'SSL_CLIENT_V_END'])
62)       )
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

63)   {
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 7 years ago

64)     $_SESSION['clientcert_cert'] = $_SERVER[$redirect.'SSL_CLIENT_CERT'];
Bernd Wurst verstehe Umgebungsvariablen...

Bernd Wurst authored 8 years ago

65)     $_SESSION['clientcert_dn'] = $_SERVER[$redirect.'SSL_CLIENT_S_DN'];
66)     $_SESSION['clientcert_issuer'] = $_SERVER[$redirect.'SSL_CLIENT_I_DN'];
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 7 years ago

67)     $_SESSION['clientcert_serial'] = $_SERVER[$redirect.'SSL_CLIENT_M_SERIAL'];
Bernd Wurst Speichere und zeige Start-...

Bernd Wurst authored 7 years ago

68)     $vstart = new DateTime($_SERVER[$redirect.'SSL_CLIENT_V_START']);
69)     $_SESSION['clientcert_valid_from'] = date_format($vstart, 'Y-m-d');
70)     $vend = new DateTime($_SERVER[$redirect.'SSL_CLIENT_V_END']);
71)     $_SESSION['clientcert_valid_until'] = date_format($vend, 'Y-m-d');
bernd Bug im Client-Zertfikat-Man...

bernd authored 14 years ago

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

bernd authored 15 years ago

73)     die();
74)   }
75)   else
76)   {
Bernd Wurst Zeige eine Warnung und kein...

Bernd Wurst authored 10 years ago

77)     warning('Ihr Browser hat kein Client-Zertifikat gesendet');
78)     header('Location: '.$prefix.$_REQUEST['backto'].encode_querystring(''));
79)     die();
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

80)   }
81) }
82) elseif (isset($_REQUEST['type']) && isset($_REQUEST['username'])) {
Bernd Wurst verstehe Umgebungsvariablen...

Bernd Wurst authored 8 years ago

83)   if (!isset($_SERVER[$redirect.'SSL_CLIENT_CERT'])) 
bernd Login vial Client-Cert über...

bernd authored 15 years ago

84)     system_failure('Ihr Browser hat kein Client-Zertifikat gesendet');
85) 
Bernd Wurst verstehe Umgebungsvariablen...

Bernd Wurst authored 8 years ago

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

bernd authored 12 years ago

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

bernd authored 15 years ago

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

bernd authored 12 years ago

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

bernd authored 15 years ago

91)       $uid = $account['username'];
92)       $role = find_role($uid, '', True);
93)       setup_session($role, $uid);
94)       $destination = 'go/index/index';
95)       if (check_path($account['startpage']))
96)         $destination = $account['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

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

bernd authored 15 years ago

99)       header('Location: ../'.$destination);
100)       die();
101)     }
102)   }
103)   system_failure('Der angegebene Account kann mit diesem Client-Zertifikat nicht eingeloggt werden.');
104) }
Bernd Wurst Leite nach dem Login auf di...

Bernd Wurst authored 10 years ago

105) elseif ($_SESSION['role'] != ROLE_ANONYMOUS && $_REQUEST['destination'] != '') {
106)   # User hat sich grade eingeloggt
107)   header('Location: ../'.$destination);
108) }
bernd Login vial Client-Cert über...

bernd authored 15 years ago

109) else
110) {
Bernd Wurst verstehe Umgebungsvariablen...

Bernd Wurst authored 8 years ago

111)   if (isset($_SERVER[$redirect.'SSL_CLIENT_CERT']) && 
112)       isset($_SERVER[$redirect.'SSL_CLIENT_S_DN']) && $_SERVER[$redirect.'SSL_CLIENT_S_DN'] != '' && 
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 7 years ago

113)       isset($_SERVER[$redirect.'SSL_CLIENT_I_DN']) && $_SERVER[$redirect.'SSL_CLIENT_I_DN'] != '' &&
114)       isset($_SERVER[$redirect.'SSL_CLIENT_M_SERIAL']) && $_SERVER[$redirect.'SSL_CLIENT_M_SERIAL'] != '') {
Bernd Wurst verstehe Umgebungsvariablen...

Bernd Wurst authored 8 years ago

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

bernd authored 15 years ago

116)     if ($ret === NULL) {
Bernd Wurst Wenn CErt-Login fehlschlägt...

Bernd Wurst authored 10 years ago

117)       login_screen('Ihr Browser hat ein Client-Zertifikat gesendet, dieses ist aber noch nicht für den Zugang hinterlegt. Melden Sie sich bitte per Benutzername und Passwort an.');
bernd Login vial Client-Cert über...

bernd authored 15 years ago

118)     }
119)     if (count($ret) == 1) {
120)       $uid = $ret[0]['username'];
121)       $role = find_role($uid, '', True);
122)       setup_session($role, $uid);
Bernd Wurst String 'NULL' eliminiert

Bernd Wurst authored 10 years ago

123)       setcookie('CLIENTCERT_AUTOLOGIN', '1', time()+3600*24*365, '/');
bernd Login vial Client-Cert über...

bernd authored 15 years ago

124)       $destination = 'go/index/index';
125)       if (check_path($ret[0]['startpage']))
126)         $destination = $ret[0]['startpage'];
bernd Ermögliche Angabe einer Red...

bernd authored 14 years ago

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

bernd authored 15 years ago

129)       header('Location: ../'.$destination);
130)       die();
131)     }
132)     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>
133)       <ul>');
134)     foreach ($ret as $account) {
135)       $type = 'System-Account';
136)       if ($account['type'] == 'email') {
137)         $type = 'E-Mail-Konto';
138)       }
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

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

bernd authored 15 years ago

142)       elseif ($account['type'] == 'customer') {
143)         $type = 'Kundenaccount';
144)       }
bernd Situation repaiert, wenn ei...

bernd authored 14 years ago

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

bernd authored 12 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

149)     }
150)     output('</ul>');
151)   } else {
Bernd Wurst Wenn CErt-Login fehlschlägt...

Bernd Wurst authored 10 years ago

152)     login_screen('Ihr Browser hat kein Client-Zertifikat gesendet. Eventuell müssen Sie in den Einstellungen des Browsers diese Funktion einschalten.');
bernd Login vial Client-Cert über...

bernd authored 15 years ago

153)   }
154) }
155) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

156) show_page('certlogin');