84f379c09c768e103cbc7a61c20353dbba672be5
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 Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 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 Login-Javascript wurde fals...

Bernd Wurst authored 10 years ago

22)   javascript('certlogin.js', 'index');
Bernd Wurst Cookie-based autologin when...

Bernd Wurst authored 11 years ago

23) }
24) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

25) function get_logins_by_cert($cert) 
26) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

27) 	$result = db_query("SELECT type,username,startpage FROM system.clientcert WHERE cert=?", array($cert));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

29) 		return NULL;
30) 	else {
31) 		$ret = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

33) 			$ret[] = $row;
34) 		}
35) 		return $ret;
36) 	}
37) }
38) 
39) function get_cert_by_id($id) 
40) {
41)   $id = (int) $id;
42) 	if ($id == 0)
43) 	  system_failure('no ID');
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 8 years ago

44) 	$result = db_query("SELECT id,dn,issuer,serial,cert,username,startpage FROM system.clientcert WHERE `id`=?", array($id));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

48)   DEBUG($ret);
49)   return $ret;
50) }
51) 
52) 
53) function get_certs_by_username($username) 
54) {
55) 	if ($username == '')
56) 	  system_failure('empty username');
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 8 years ago

57) 	$result = db_query("SELECT id,dn,issuer,serial,cert,startpage FROM system.clientcert WHERE `username`=?", array($username));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

61) 	  $ret[] = $row;
62) 	}
63) 	return $ret;
64) }
65) 
66) 
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 8 years ago

67) function add_clientcert($certdata, $dn, $issuer, $serial, $startpage=NULL)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

68) {
bernd Ermögliche Client-Cert-Logi...

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

72)     $type = 'user';
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 12 years ago

74)     if (isset($_SESSION['subuser'])) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

79)     $type = 'email';
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 12 years ago

81)   }
82)   if (! $type || ! $username) {
83)     system_failure('cannot get type or username of login');
84)   }
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

85)   if ($startpage &&  ! check_path($startpage))
86)     system_failure('Startseite kaputt');
bernd Cert-Login geht jetztauch m...

bernd authored 13 years ago

87) 
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

88)   if ($certdata == '')
89)     system_failure('Kein Zertifikat');
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

90) 
91)   $args = array(":dn" => $dn,
92)                 ":issuer" => $issuer,
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 8 years ago

93)                 ":serial" => $serial,
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

94)                 ":certdata" => $certdata,
95)                 ":type" => $type,
96)                 ":username" => $username,
97)                 ":startpage" => $startpage);
98)   DEBUG($args);
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

99) 
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 8 years ago

100)   db_query("INSERT INTO system.clientcert (`dn`, `issuer`, `serial`, `cert`, `type`, `username`, `startpage`) 
101) VALUES (:dn, :issuer, :serial, :certdata, :type, :username, :startpage)", $args);
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

112)     $type = 'user';
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 12 years ago

114)     if (isset($_SESSION['subuser'])) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 12 years ago

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

bernd authored 12 years ago

119)     $type = 'email';
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 12 years ago

121)   }
122)   if (! $type || ! $username) {
123)     system_failure('cannot get type or username of login');
124)   }
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

125)   db_query("DELETE FROM system.clientcert WHERE id=:id AND type=:type AND username=:username", 
126)            array(":id" => $id, ":type" => $type, ":username" => $username));