c208bd906b3991555db11b9229846c4601ca408c
bernd Login via Client-Zertifikat...

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) 
5) Written 2008-2012 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) */
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

16) 
17) require_once('inc/security.php');
18) 
19) function get_logins_by_cert($cert) 
20) {
21) 	$cert = mysql_real_escape_string(str_replace(array('-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', ' ', "\n"), array(), $cert));
22) 	$query = "SELECT type,username,startpage FROM system.clientcert WHERE cert='{$cert}'";
23) 	$result = db_query($query);
24) 	if (mysql_num_rows($result) < 1)
25) 		return NULL;
26) 	else {
27) 		$ret = array();
28) 		while ($row = mysql_fetch_assoc($result)) {
29) 			$ret[] = $row;
30) 		}
31) 		return $ret;
32) 	}
33) }
34) 
35) function get_cert_by_id($id) 
36) {
37)   $id = (int) $id;
38) 	if ($id == 0)
39) 	  system_failure('no ID');
40) 	$query = "SELECT id,dn,issuer,cert,username,startpage FROM system.clientcert WHERE `id`='{$id}' LIMIT 1";
41) 	$result = db_query($query);
42) 	if (mysql_num_rows($result) < 1)
43) 		return NULL;
44) 	$ret = mysql_fetch_assoc($result);
45)   DEBUG($ret);
46)   return $ret;
47) }
48) 
49) 
50) function get_certs_by_username($username) 
51) {
52) 	$username = mysql_real_escape_string($username);
53) 	if ($username == '')
54) 	  system_failure('empty username');
55) 	$query = "SELECT id,dn,issuer,cert,startpage FROM system.clientcert WHERE `username`='{$username}'";
56) 	$result = db_query($query);
57) 	if (mysql_num_rows($result) < 1)
58) 		return NULL;
59) 	while ($row = mysql_fetch_assoc($result)) {
60) 	  $ret[] = $row;
61) 	}
62) 	return $ret;
63) }
64) 
65) 
66) function add_clientcert($certdata, $dn, $issuer, $startpage='')
67) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

68)   $type = NULL;
69)   $username = NULL;
70)   if ($_SESSION['role'] == ROLE_SYSTEMUSER) {
71)     $type = 'user';
72)     $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
73)     if (isset($_SESSION['subuser']))
74)       $username = mysql_real_escape_string($_SESSION['subuser']);
75)       $type = 'subuser';
76)   } elseif ($_SESSION['role'] == ROLE_VMAIL_ACCOUNT) {
77)     $type = 'email';
78)     $username = mysql_real_escape_string($_SESSION['mailaccount']);
79)   }
80)   if (! $type || ! $username) {
81)     system_failure('cannot get type or username of login');
82)   }
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

83)   $certdata = mysql_real_escape_string($certdata);
84)   $dn = maybe_null(mysql_real_escape_string($dn));
85)   $issuer = maybe_null(mysql_real_escape_string($issuer));
86)   if ($startpage &&  ! check_path($startpage))
87)     system_failure('Startseite kaputt');
88)   $startpage = maybe_null(mysql_real_escape_string($startpage));
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

89) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

90)   if ($certdata == '')
91)     system_failure('Kein Zertifikat');
92)   DEBUG($certdata);
93)   DEBUG($dn);
94)   DEBUG($issuer);
95) 
96)   db_query("INSERT INTO system.clientcert (`dn`, `issuer`, `cert`, `type`, `username`, `startpage`) 
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

97) VALUES ({$dn}, {$issuer}, '{$certdata}', '{$type}', '{$username}', {$startpage})");
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

98) 
99) }
100) 
101) 
102) function delete_clientcert($id)
103) {
104)   $id = (int) $id;
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

105)   $type = NULL;
106)   $username = NULL;
107)   if ($_SESSION['role'] == ROLE_SYSTEMUSER) {
108)     $type = 'user';
109)     $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
110)     if (isset($_SESSION['subuser']))
111)       $username = mysql_real_escape_string($_SESSION['subuser']);
112)       $type = 'subuser';
113)   } elseif ($_SESSION['role'] == ROLE_VMAIL_ACCOUNT) {
114)     $type = 'email';
115)     $username = mysql_real_escape_string($_SESSION['mailaccount']);
116)   }
117)   if (! $type || ! $username) {
118)     system_failure('cannot get type or username of login');
119)   }
120)   db_query("DELETE FROM system.clientcert WHERE id={$id} AND type='{$type}' AND username='{$username}' LIMIT 1");