f12aba6daa6e2848a8ed60ea57b26874d6675f52
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) 
Bernd Wurst Updated copyright notice (2...

Bernd Wurst authored 11 years ago

5) Written 2008-2013 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 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;
Bernd Wurst bugfix: (once again) most u...

Bernd Wurst authored 12 years ago

70)   if ($_SESSION['role'] & ROLE_SYSTEMUSER) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

71)     $type = 'user';
72)     $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

73)     if (isset($_SESSION['subuser'])) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

74)       $username = mysql_real_escape_string($_SESSION['subuser']);
75)       $type = 'subuser';
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

76)     }
Bernd Wurst bugfix: (once again) most u...

Bernd Wurst authored 12 years ago

77)   } elseif ($_SESSION['role'] & ROLE_VMAIL_ACCOUNT) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

78)     $type = 'email';
79)     $username = mysql_real_escape_string($_SESSION['mailaccount']);
80)   }
81)   if (! $type || ! $username) {
82)     system_failure('cannot get type or username of login');
83)   }
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

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

bernd authored 13 years ago

90) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

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

bernd authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 12 years ago

106)   $type = NULL;
107)   $username = NULL;
Bernd Wurst bugfix: (once again) most u...

Bernd Wurst authored 12 years ago

108)   if ($_SESSION['role'] & ROLE_SYSTEMUSER) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

109)     $type = 'user';
110)     $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

111)     if (isset($_SESSION['subuser'])) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

112)       $username = mysql_real_escape_string($_SESSION['subuser']);
113)       $type = 'subuser';
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

114)     }
Bernd Wurst bugfix: (once again) most u...

Bernd Wurst authored 12 years ago

115)   } elseif ($_SESSION['role'] & ROLE_VMAIL_ACCOUNT) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

116)     $type = 'email';
117)     $username = mysql_real_escape_string($_SESSION['mailaccount']);
118)   }
119)   if (! $type || ! $username) {
120)     system_failure('cannot get type or username of login');
121)   }
122)   db_query("DELETE FROM system.clientcert WHERE id={$id} AND type='{$type}' AND username='{$username}' LIMIT 1");