64ea2c9cacfd02710fb2e86cf29fb029e6cc406c
Bernd Wurst jQuery-based Certlogin, so...

Bernd Wurst authored 11 years ago

1) <?php
2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
5) Written 2008-2013 by schokokeks.org Hosting, namely
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) */
16) 
17) // Setze das Arbeitsverzeichnis auf das Stammverzeichnis, damit die Voraussetzungen gleich sind wie bei allen anderen Requests
18) chdir('..');
19) 
20) require_once('config.php');
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');
31) require_once('inc/theme.php');
32) 
33) 
34) function prepare_cert($cert)
35) {
36) 	return str_replace(array('-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', ' ', "\n"), array(), $cert);
37) }
38) 
39) 
40) function get_logins_by_cert($cert) 
41) {
42) 	$cert = mysql_real_escape_string(prepare_cert($cert));
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) 
56) DEBUG('$_SERVER:');
57) DEBUG($_SERVER);
58) 
59) header('Content-type: text/plain');
60) 
61) if (isset($_SERVER['REDIRECT_SSL_CLIENT_CERT']) && 
62)     isset($_SERVER['REDIRECT_SSL_CLIENT_S_DN']) && $_SERVER['REDIRECT_SSL_CLIENT_S_DN'] != '' && 
63)     isset($_SERVER['REDIRECT_SSL_CLIENT_I_DN']) && $_SERVER['REDIRECT_SSL_CLIENT_I_DN'] != '') {
64)   $ret = get_logins_by_cert($_SERVER['REDIRECT_SSL_CLIENT_CERT']);
65)   if ($ret === NULL) {
66)     echo 'error';
67)     die();
68)   }
69)   if (count($ret) == 1) {
70)     $uid = $ret[0]['username'];
71)     $role = find_role($uid, '', True);
72)     setup_session($role, $uid);
Bernd Wurst Cookie-based autologin when...

Bernd Wurst authored 11 years ago

73)     setcookie('CLIENTCERT_AUTOLOGIN', '1', time()+3600*24*365, '/');