f1f231f5e074dfa038e70a67d39849e80f2b4b4d
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) 
Bernd Wurst Cookie-based autologin when...

Bernd Wurst authored 11 years ago

19) function do_ajax_cert_login() {
20)   global $prefix;
Bernd Wurst Nutze zentrales JQuery

Bernd Wurst authored 10 years ago

21)   require_once('inc/jquery.php');
Bernd Wurst Cookie-based autologin when...

Bernd Wurst authored 11 years ago

22)   html_header('
23) <script type="text/javascript">
24)   function redirect(status) {
25)     if (status == "ok") {
26)       window.location.reload();
27)     } else {
28)       window.location.href="../../certlogin/";
29)     }
30)   }
31)   $.get("'.$prefix.'certlogin/ajax.php", redirect);
32) </script>
33) ');
34) }
35) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

36) function get_logins_by_cert($cert) 
37) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

38) 	$cert = db_escape_string(str_replace(array('-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', ' ', "\n"), array(), $cert));
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

39) 	$query = "SELECT type,username,startpage FROM system.clientcert WHERE cert='{$cert}'";
40) 	$result = db_query($query);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

41) 	if ($result->rowCount() < 1)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

42) 		return NULL;
43) 	else {
44) 		$ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

45) 		while ($row = $result->fetch()) {
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

46) 			$ret[] = $row;
47) 		}
48) 		return $ret;
49) 	}
50) }
51) 
52) function get_cert_by_id($id) 
53) {
54)   $id = (int) $id;
55) 	if ($id == 0)
56) 	  system_failure('no ID');
57) 	$query = "SELECT id,dn,issuer,cert,username,startpage FROM system.clientcert WHERE `id`='{$id}' LIMIT 1";
58) 	$result = db_query($query);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

59) 	if ($result->rowCount() < 1)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

60) 		return NULL;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

61) 	$ret = $result->fetch();
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

62)   DEBUG($ret);
63)   return $ret;
64) }
65) 
66) 
67) function get_certs_by_username($username) 
68) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

69) 	$username = db_escape_string($username);
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

70) 	if ($username == '')
71) 	  system_failure('empty username');
72) 	$query = "SELECT id,dn,issuer,cert,startpage FROM system.clientcert WHERE `username`='{$username}'";
73) 	$result = db_query($query);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

74) 	if ($result->rowCount() < 1)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

75) 		return NULL;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

76) 	while ($row = $result->fetch()) {
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

77) 	  $ret[] = $row;
78) 	}
79) 	return $ret;
80) }
81) 
82) 
83) function add_clientcert($certdata, $dn, $issuer, $startpage='')
84) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

88)     $type = 'user';
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

89)     $username = db_escape_string($_SESSION['userinfo']['username']);
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

90)     if (isset($_SESSION['subuser'])) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

91)       $username = db_escape_string($_SESSION['subuser']);
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

92)       $type = 'subuser';
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

95)     $type = 'email';
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

96)     $username = db_escape_string($_SESSION['mailaccount']);
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

97)   }
98)   if (! $type || ! $username) {
99)     system_failure('cannot get type or username of login');
100)   }
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

101)   $certdata = db_escape_string($certdata);
102)   $dn = maybe_null(db_escape_string($dn));
103)   $issuer = maybe_null(db_escape_string($issuer));
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

104)   if ($startpage &&  ! check_path($startpage))
105)     system_failure('Startseite kaputt');
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

106)   $startpage = maybe_null(db_escape_string($startpage));
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

107) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

108)   if ($certdata == '')
109)     system_failure('Kein Zertifikat');
110)   DEBUG($certdata);
111)   DEBUG($dn);
112)   DEBUG($issuer);
113) 
114)   db_query("INSERT INTO system.clientcert (`dn`, `issuer`, `cert`, `type`, `username`, `startpage`) 
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

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

bernd authored 15 years ago

116) 
117) }
118) 
119) 
120) function delete_clientcert($id)
121) {
122)   $id = (int) $id;
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

126)     $type = 'user';
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

127)     $username = db_escape_string($_SESSION['userinfo']['username']);
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

128)     if (isset($_SESSION['subuser'])) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

129)       $username = db_escape_string($_SESSION['subuser']);
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

130)       $type = 'subuser';
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

133)     $type = 'email';
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

134)     $username = db_escape_string($_SESSION['mailaccount']);
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

135)   }
136)   if (! $type || ! $username) {
137)     system_failure('cannot get type or username of login');
138)   }
139)   db_query("DELETE FROM system.clientcert WHERE id={$id} AND type='{$type}' AND username='{$username}' LIMIT 1");