bd22f03937341179a1beaf87aafcde8e61882589
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;
21)   $path = config('jquery_ui_path');
22)   html_header('
23) <link rel="stylesheet" href="'.$path.'/themes/base/jquery-ui.css" />
24) <script type="text/javascript" src="'.$path.'/jquery-1.9.0.js" ></script>
25) <script type="text/javascript" src="'.$path.'/ui/jquery-ui.js" ></script>
26) <script type="text/javascript">
27)   function redirect(status) {
28)     if (status == "ok") {
29)       window.location.reload();
30)     } else {
31)       window.location.href="../../certlogin/";
32)     }
33)   }
34)   $.get("'.$prefix.'certlogin/ajax.php", redirect);
35) </script>
36) ');
37) }
38) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

39) function get_logins_by_cert($cert) 
40) {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

42) 	$query = "SELECT type,username,startpage FROM system.clientcert WHERE cert='{$cert}'";
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

43) 	$result = db_query($query);
44) 	if (mysql_num_rows($result) < 1)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

45) 		return NULL;
46) 	else {
47) 		$ret = array();
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

48) 		while ($row = mysql_fetch_assoc($result)) {
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

61) 	$result = db_query($query);
62) 	if (mysql_num_rows($result) < 1)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

63) 		return NULL;
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

64) 	$ret = mysql_fetch_assoc($result);
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

65)   DEBUG($ret);
66)   return $ret;
67) }
68) 
69) 
70) function get_certs_by_username($username) 
71) {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

72) 	$username = mysql_real_escape_string($username);
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

73) 	if ($username == '')
74) 	  system_failure('empty username');
75) 	$query = "SELECT id,dn,issuer,cert,startpage FROM system.clientcert WHERE `username`='{$username}'";
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

76) 	$result = db_query($query);
77) 	if (mysql_num_rows($result) < 1)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

78) 		return NULL;
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

79) 	while ($row = mysql_fetch_assoc($result)) {
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

91)     $type = 'user';
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 12 years ago

93)     if (isset($_SESSION['subuser'])) {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

98)     $type = 'email';
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

bernd authored 12 years ago

100)   }
101)   if (! $type || ! $username) {
102)     system_failure('cannot get type or username of login');
103)   }
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

104)   $certdata = mysql_real_escape_string($certdata);
105)   $dn = maybe_null(mysql_real_escape_string($dn));
106)   $issuer = maybe_null(mysql_real_escape_string($issuer));
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

107)   if ($startpage &&  ! check_path($startpage))
108)     system_failure('Startseite kaputt');
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

109)   $startpage = maybe_null(mysql_real_escape_string($startpage));
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

110) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

111)   if ($certdata == '')
112)     system_failure('Kein Zertifikat');
113)   DEBUG($certdata);
114)   DEBUG($dn);
115)   DEBUG($issuer);
116) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

117)   db_query("INSERT INTO system.clientcert (`dn`, `issuer`, `cert`, `type`, `username`, `startpage`) 
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

129)     $type = 'user';
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 12 years ago

131)     if (isset($_SESSION['subuser'])) {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

136)     $type = 'email';
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

bernd authored 12 years ago

138)   }
139)   if (! $type || ! $username) {
140)     system_failure('cannot get type or username of login');
141)   }
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

142)   db_query("DELETE FROM system.clientcert WHERE id={$id} AND type='{$type}' AND username='{$username}' LIMIT 1");