dcc202fb249a446ac15c7cf413b9f1b4a3f31b58
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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

5) Written 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) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

10) 
11) 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.
12) */
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

13) 
14) require_once('inc/security.php');
15) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

16) function do_ajax_cert_login()
17) {
18)     global $prefix;
19)     require_once('inc/jquery.php');
20)     javascript('certlogin.js', 'index');
Bernd Wurst Cookie-based autologin when...

Bernd Wurst authored 11 years ago

21) }
22) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

23) function get_logins_by_cert($cert)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

24) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

25)     $result = db_query("SELECT type,username,startpage FROM system.clientcert WHERE cert=? ORDER BY type,username", [$cert]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

26)     if ($result->rowCount() < 1) {
Bernd Wurst Entferne Javascript-Konstru...

Bernd Wurst authored 6 years ago

27)         DEBUG("No certlogin found for this cert!");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

28)         return null;
29)     } else {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

30)         $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

31)         while ($row = $result->fetch()) {
32)             $ret[] = $row;
33)         }
Bernd Wurst Entferne Javascript-Konstru...

Bernd Wurst authored 6 years ago

34)         DEBUG("Logins for this cert:");
35)         DEBUG($ret);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

36)         return $ret;
37)     }
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

38) }
39) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

40) function get_cert_by_id($id)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

41) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

42)     $id = (int) $id;
43)     if ($id == 0) {
44)         system_failure('no ID');
45)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

46)     $result = db_query("SELECT id,dn,issuer,serial,valid_from,valid_until,cert,username,startpage FROM system.clientcert WHERE `id`=?", [$id]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

47)     if ($result->rowCount() < 1) {
48)         return null;
49)     }
50)     $ret = $result->fetch();
51)     DEBUG($ret);
52)     return $ret;
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

53) }
54) 
55) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

56) function get_certs_by_username($username)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

57) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

58)     if ($username == '') {
59)         system_failure('empty username');
60)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

61)     $result = db_query("SELECT id,dn,issuer,serial,valid_from,valid_until,cert,startpage FROM system.clientcert WHERE `username`=?", [$username]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

62)     if ($result->rowCount() < 1) {
63)         return null;
64)     }
65)     while ($row = $result->fetch()) {
66)         $ret[] = $row;
67)     }
68)     return $ret;
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

69) }
70) 
71) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

72) function add_clientcert($certdata, $dn, $issuer, $serial, $vstart, $vend, $startpage=null)
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

73) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

74)     $type = null;
75)     $username = null;
76)     if ($_SESSION['role'] & ROLE_SYSTEMUSER) {
77)         $type = 'user';
78)         $username = $_SESSION['userinfo']['username'];
79)         if (isset($_SESSION['subuser'])) {
80)             $username = $_SESSION['subuser'];
81)             $type = 'subuser';
82)         }
83)     } elseif ($_SESSION['role'] & ROLE_VMAIL_ACCOUNT) {
84)         $type = 'email';
85)         $username = $_SESSION['mailaccount'];
86)     }
87)     if (! $type || ! $username) {
88)         system_failure('cannot get type or username of login');
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

89)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

90)     if ($startpage &&  ! check_path($startpage)) {
91)         system_failure('Startseite kaputt');
92)     }
93) 
94)     if ($certdata == '') {
95)         system_failure('Kein Zertifikat');
96)     }
97) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

98)     $args = [":dn" => $dn,
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

99)                 ":issuer" => $issuer,
Bernd Wurst Speichere und zeige Serienn...

Bernd Wurst authored 8 years ago

100)                 ":serial" => $serial,
Bernd Wurst Speichere und zeige Start-...

Bernd Wurst authored 8 years ago

101)                 ":vstart" => $vstart,
102)                 ":vend" => $vend,
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

103)                 ":certdata" => $certdata,
104)                 ":type" => $type,
105)                 ":username" => $username,
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

106)                 ":startpage" => $startpage, ];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

107)     DEBUG($args);
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

108) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

109)     db_query("INSERT INTO system.clientcert (`dn`, `issuer`, `serial`, `valid_from`, `valid_until`, `cert`, `type`, `username`, `startpage`) 
Bernd Wurst Speichere und zeige Start-...

Bernd Wurst authored 8 years ago

110) VALUES (:dn, :issuer, :serial, :vstart, :vend, :certdata, :type, :username, :startpage)", $args);
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

111) }
112) 
113) 
114) function delete_clientcert($id)
115) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

116)     $id = (int) $id;
117)     $type = null;
118)     $username = null;
119)     if ($_SESSION['role'] & ROLE_SYSTEMUSER) {
120)         $type = 'user';
121)         $username = $_SESSION['userinfo']['username'];
122)         if (isset($_SESSION['subuser'])) {
123)             $username = $_SESSION['subuser'];
124)             $type = 'subuser';
125)         }
126)     } elseif ($_SESSION['role'] & ROLE_VMAIL_ACCOUNT) {
127)         $type = 'email';
128)         $username = $_SESSION['mailaccount'];
129)     }
130)     if (! $type || ! $username) {
131)         system_failure('cannot get type or username of login');
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

132)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

133)     db_query(
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

134)         "DELETE FROM system.clientcert WHERE id=:id AND type=:type AND username=:username",
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

135)         [":id" => $id, ":type" => $type, ":username" => $username]
Hanno Fix codingstyle

Hanno authored 4 years ago

136)     );