dcc202fb249a446ac15c7cf413b9f1b4a3f31b58
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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

5) Written 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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

10) 
11) 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.
12) */
bernd Login vial Client-Cert über...

bernd authored 15 years ago

13) 
Bernd Wurst jQuery-based Certlogin, so...

Bernd Wurst authored 11 years ago

14) // 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

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

bernd authored 15 years ago

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

bernd authored 13 years ago

28) require_once('inc/theme.php');
schokokeks.org web services changes to cert login stuff

schokokeks.org web services authored 6 years ago

29) require_once('modules/index/include/x509.php');
bernd Login vial Client-Cert über...

bernd authored 15 years ago

30) 
31) 
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

32) DEBUG('$_SERVER:');
33) DEBUG($_SERVER);
34) 
Bernd Wurst verstehe Umgebungsvariablen...

Bernd Wurst authored 8 years ago

35) $redirect = "";
36) if (! isset($_SERVER['SSL_CLIENT_CERT']) && isset($_SERVER['REDIRECT_SSL_CLIENT_CERT'])) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

37)     $redirect = "REDIRECT_";
Bernd Wurst verstehe Umgebungsvariablen...

Bernd Wurst authored 8 years ago

38) }
bernd Login vial Client-Cert über...

bernd authored 15 years ago

39) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

40) if ($_SESSION['role'] != ROLE_ANONYMOUS && isset($_REQUEST['record']) && isset($_REQUEST['backto']) && check_path($_REQUEST['backto'])) {
41)     DEBUG('recording client-cert');
42)     if (isset($_SERVER[$redirect.'SSL_CLIENT_CERT']) && isset($_SERVER[$redirect.'SSL_CLIENT_S_DN']) &&
Bernd Wurst Speichere und zeige Start-...

Bernd Wurst authored 8 years ago

43)       isset($_SERVER[$redirect.'SSL_CLIENT_I_DN']) && isset($_SERVER[$redirect.'SSL_CLIENT_M_SERIAL']) &&
44)       isset($_SERVER[$redirect.'SSL_CLIENT_V_START']) && isset($_SERVER[$redirect.'SSL_CLIENT_V_END'])
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

45)       ) {
46)         $_SESSION['clientcert_cert'] = $_SERVER[$redirect.'SSL_CLIENT_CERT'];
47)         $_SESSION['clientcert_dn'] = $_SERVER[$redirect.'SSL_CLIENT_S_DN'];
48)         $_SESSION['clientcert_issuer'] = $_SERVER[$redirect.'SSL_CLIENT_I_DN'];
49)         $_SESSION['clientcert_serial'] = $_SERVER[$redirect.'SSL_CLIENT_M_SERIAL'];
50)         $vstart = new DateTime($_SERVER[$redirect.'SSL_CLIENT_V_START']);
51)         $_SESSION['clientcert_valid_from'] = date_format($vstart, 'Y-m-d');
52)         $vend = new DateTime($_SERVER[$redirect.'SSL_CLIENT_V_END']);
53)         $_SESSION['clientcert_valid_until'] = date_format($vend, 'Y-m-d');
54)         header('Location: '.$prefix.$_REQUEST['backto'].encode_querystring(''));
55)         die();
56)     } else {
57)         warning('Ihr Browser hat kein Client-Zertifikat gesendet');
58)         header('Location: '.$prefix.$_REQUEST['backto'].encode_querystring(''));
59)         die();
60)     }
61) } elseif (isset($_REQUEST['type']) && isset($_REQUEST['username'])) {
62)     if (!isset($_SERVER[$redirect.'SSL_CLIENT_CERT'])) {
63)         system_failure('Ihr Browser hat kein Client-Zertifikat gesendet');
64)     }
bernd Login vial Client-Cert über...

bernd authored 15 years ago

65) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

66)     $ret = get_logins_by_cert($_SERVER[$redirect.'SSL_CLIENT_CERT']);
67)     DEBUG($ret);
68)     foreach ($ret as $account) {
69)         DEBUG('/'.$account['type'].'/'.$_REQUEST['type'].'/    /'.$account['username'].'/'.$_REQUEST['username'].'/    =>');
70)         if (($account['type'] == urldecode($_REQUEST['type'])) && ($account['username'] == urldecode($_REQUEST['username']))) {
71)             $uid = $account['username'];
72)             $role = find_role($uid, '', true);
73)             setup_session($role, $uid);
74)             $destination = 'go/index/index';
75)             if (check_path($account['startpage'])) {
76)                 $destination = $account['startpage'];
77)             }
78)             if (isset($_REQUEST['destination']) && check_path($_REQUEST['destination'])) {
79)                 $destination = $_REQUEST['destination'];
80)             }
Bernd Wurst Bug gefixed, durch den beim...

Bernd Wurst authored 5 years ago

81)             header('Location: ../'.ltrim($destination, '/'));
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

82)             die();
83)         }
bernd Login vial Client-Cert über...

bernd authored 15 years ago

84)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

85)     system_failure('Der angegebene Account kann mit diesem Client-Zertifikat nicht eingeloggt werden.');
Bernd Wurst Warning beim Certlogin verm...

Bernd Wurst authored 5 years ago

86) } elseif ($_SESSION['role'] != ROLE_ANONYMOUS && isset($_REQUEST['destination']) && $_REQUEST['destination'] != '') {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

87)     # User hat sich grade eingeloggt
Bernd Wurst Bug gefixed, durch den beim...

Bernd Wurst authored 5 years ago

88)     header('Location: ../'.ltrim($destination, '/'));
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

89) } else {
90)     if (isset($_SERVER[$redirect.'SSL_CLIENT_CERT']) &&
91)       isset($_SERVER[$redirect.'SSL_CLIENT_S_DN']) && $_SERVER[$redirect.'SSL_CLIENT_S_DN'] != '' &&
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 8 years ago

92)       isset($_SERVER[$redirect.'SSL_CLIENT_I_DN']) && $_SERVER[$redirect.'SSL_CLIENT_I_DN'] != '' &&
93)       isset($_SERVER[$redirect.'SSL_CLIENT_M_SERIAL']) && $_SERVER[$redirect.'SSL_CLIENT_M_SERIAL'] != '') {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

94)         $ret = get_logins_by_cert($_SERVER[$redirect.'SSL_CLIENT_CERT']);
95)         if ($ret === null) {
96)             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.');
97)         }
98)         if (count($ret) == 1) {
99)             $uid = $ret[0]['username'];
100)             $role = find_role($uid, '', true);
101)             setup_session($role, $uid);
102)             DEBUG("Set Cookie!");
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

103)             setcookie('CLIENTCERT_AUTOLOGIN', '1', ['expires'=>strtotime("+ 1 year"), 'path'=>'/', 'secure'=>true, 'httponly'=>true, 'samesite'=>'Lax']);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

104)             $destination = 'go/index/index';
105)             if (check_path($ret[0]['startpage'])) {
106)                 $destination = $ret[0]['startpage'];
107)             }
108)             if (isset($_REQUEST['destination']) && check_path($_REQUEST['destination'])) {
109)                 $destination = $_REQUEST['destination'];
110)             }
Bernd Wurst Bug gefixed, durch den beim...

Bernd Wurst authored 5 years ago

111)             header('Location: ../'.ltrim($destination, '/'));
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

112)             die();
113)         }
114)         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>
bernd Login vial Client-Cert über...

bernd authored 15 years ago

115)       <ul>');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

116)         foreach ($ret as $account) {
117)             $type = 'System-Account';
118)             if ($account['type'] == 'email') {
119)                 $type = 'E-Mail-Konto';
120)             } elseif ($account['type'] == 'subuser') {
121)                 $type = 'Unter-Nutzer';
122)             } elseif ($account['type'] == 'customer') {
123)                 $type = 'Kundenaccount';
124)             }
125)             $destination = 'go/index/index';
126)             if ($account['startpage'] && check_path($account['startpage'])) {
127)                 $destination = $account['startpage'];
128)             }
129)             output('<li>'.internal_link('', $type.': <strong>'.$account['username'].'</strong>', 'type='.$account['type'].'&username='.urlencode($account['username']).'&destination='.urlencode($destination)).'</li>');
130)         }
131)         output('</ul>');
132)     } else {
133)         warning('Ihr Browser hat kein Client-Zertifikat gesendet. Eventuell müssen Sie in den Einstellungen des Browsers diese Funktion einschalten.');
134)         redirect('/');
135)         die();
bernd Login vial Client-Cert über...

bernd authored 15 years ago

136)     }
137) }
138)