ec5ed2ed870b5374ab2c05502621d0c161c3c2d8
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 Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 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) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

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');
schokokeks.org web services changes to cert login stuff

schokokeks.org web services authored 6 years ago

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

bernd authored 15 years ago

33) 
34) 
bernd PHP 5.3: es gibt kein $_ENV...

bernd authored 14 years ago

35) DEBUG('$_SERVER:');
36) DEBUG($_SERVER);
37) 
Bernd Wurst verstehe Umgebungsvariablen...

Bernd Wurst authored 8 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 8 years ago

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

bernd authored 15 years ago

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

Hanno authored 5 years ago

43) if ($_SESSION['role'] != ROLE_ANONYMOUS && isset($_REQUEST['record']) && isset($_REQUEST['backto']) && check_path($_REQUEST['backto'])) {
44)     DEBUG('recording client-cert');
45)     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

46)       isset($_SERVER[$redirect.'SSL_CLIENT_I_DN']) && isset($_SERVER[$redirect.'SSL_CLIENT_M_SERIAL']) &&
47)       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

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

bernd authored 15 years ago

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

Hanno authored 5 years ago

69)     $ret = get_logins_by_cert($_SERVER[$redirect.'SSL_CLIENT_CERT']);
70)     DEBUG($ret);
71)     foreach ($ret as $account) {
72)         DEBUG('/'.$account['type'].'/'.$_REQUEST['type'].'/    /'.$account['username'].'/'.$_REQUEST['username'].'/    =>');
73)         if (($account['type'] == urldecode($_REQUEST['type'])) && ($account['username'] == urldecode($_REQUEST['username']))) {
74)             $uid = $account['username'];
75)             $role = find_role($uid, '', true);
76)             setup_session($role, $uid);
77)             $destination = 'go/index/index';
78)             if (check_path($account['startpage'])) {
79)                 $destination = $account['startpage'];
80)             }
81)             if (isset($_REQUEST['destination']) && check_path($_REQUEST['destination'])) {
82)                 $destination = $_REQUEST['destination'];
83)             }
84)             header('Location: ../'.$destination);
85)             die();
86)         }
bernd Login vial Client-Cert über...

bernd authored 15 years ago

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

Hanno authored 5 years ago

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

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

Hanno authored 5 years ago

90)     # User hat sich grade eingeloggt
91)     header('Location: ../'.$destination);
92) } else {
93)     if (isset($_SERVER[$redirect.'SSL_CLIENT_CERT']) &&
94)       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

95)       isset($_SERVER[$redirect.'SSL_CLIENT_I_DN']) && $_SERVER[$redirect.'SSL_CLIENT_I_DN'] != '' &&
96)       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

97)         $ret = get_logins_by_cert($_SERVER[$redirect.'SSL_CLIENT_CERT']);
98)         if ($ret === null) {
99)             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.');
100)         }
101)         if (count($ret) == 1) {
102)             $uid = $ret[0]['username'];
103)             $role = find_role($uid, '', true);
104)             setup_session($role, $uid);
105)             DEBUG("Set Cookie!");
106)             setcookie('CLIENTCERT_AUTOLOGIN', '1', strtotime("+ 1 year"), '/', '', true, true);
107)             $destination = 'go/index/index';
108)             if (check_path($ret[0]['startpage'])) {
109)                 $destination = $ret[0]['startpage'];
110)             }
111)             if (isset($_REQUEST['destination']) && check_path($_REQUEST['destination'])) {
112)                 $destination = $_REQUEST['destination'];
113)             }
114)             header('Location: ../'.$destination);
115)             die();
116)         }
117)         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

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

Hanno authored 5 years ago

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

bernd authored 15 years ago

139)     }
140) }
141)