3ef995c2108fe77d22c0b556fb9717cb848bc48f
bernd Login via Client-Zertifikat...

bernd authored 16 years ago

1) <?php
Hanno Böck Add newlines before comment...

Hanno Böck authored 1 week ago

2) 
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 13 years ago

3) /*
4) This file belongs to the Webinterface of schokokeks.org Hosting
5) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

6) Written by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 13 years ago

7)   Bernd Wurst <bernd@schokokeks.org>
8)   Hanno Böck <hanno@schokokeks.org>
9) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 13 years ago

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

bernd authored 16 years ago

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

Hanno authored 6 years ago

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

bernd authored 16 years ago

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

Hanno Böck authored 3 years ago

19)     $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 6 years ago

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

Bernd Wurst authored 7 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

25)         while ($row = $result->fetch()) {
26)             $ret[] = $row;
27)         }
Bernd Wurst Entferne Javascript-Konstru...

Bernd Wurst authored 7 years ago

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

Hanno authored 6 years ago

30)         return $ret;
31)     }
bernd Login via Client-Zertifikat...

bernd authored 16 years ago

32) }
33) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 16 years ago

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

Hanno authored 6 years ago

36)     $id = (int) $id;
37)     if ($id == 0) {
38)         system_failure('no ID');
39)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

40)     $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 6 years ago

41)     if ($result->rowCount() < 1) {
42)         return null;
43)     }
44)     $ret = $result->fetch();
45)     DEBUG($ret);
46)     return $ret;
bernd Login via Client-Zertifikat...

bernd authored 16 years ago

47) }
48) 
49) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 16 years ago

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

Hanno authored 6 years ago

52)     if ($username == '') {
53)         system_failure('empty username');
54)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

55)     $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 6 years ago

56)     if ($result->rowCount() < 1) {
57)         return null;
58)     }
59)     while ($row = $result->fetch()) {
60)         $ret[] = $row;
61)     }
62)     return $ret;
bernd Login via Client-Zertifikat...

bernd authored 16 years ago

63) }
64) 
65) 
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 1 year ago

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

bernd authored 16 years ago

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

Hanno authored 6 years ago

68)     $type = null;
69)     $username = null;
70)     if ($_SESSION['role'] & ROLE_SYSTEMUSER) {
71)         $type = 'user';
72)         $username = $_SESSION['userinfo']['username'];
73)         if (isset($_SESSION['subuser'])) {
74)             $username = $_SESSION['subuser'];
75)             $type = 'subuser';
76)         }
77)     } elseif ($_SESSION['role'] & ROLE_VMAIL_ACCOUNT) {
78)         $type = 'email';
79)         $username = $_SESSION['mailaccount'];
80)     }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

81)     if (!$type || !$username) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

82)         system_failure('cannot get type or username of login');
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

83)     }
Hanno Böck Remove some unneeded whites...

Hanno Böck authored 1 year ago

84)     if ($startpage && !check_path($startpage)) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

85)         system_failure('Startseite kaputt');
86)     }
87) 
88)     if ($certdata == '') {
89)         system_failure('Kein Zertifikat');
90)     }
91) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

92)     $args = [":dn" => $dn,
Hanno Böck Neue codingstyle-rule array...

Hanno Böck authored 11 months ago

93)         ":issuer" => $issuer,
94)         ":serial" => $serial,
95)         ":vstart" => $vstart,
96)         ":vend" => $vend,
97)         ":certdata" => $certdata,
98)         ":type" => $type,
99)         ":username" => $username,
100)         ":startpage" => $startpage, ];
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 16 years ago

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

Hanno authored 6 years ago

103)     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

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

bernd authored 16 years ago

105) }
106) 
107) 
108) function delete_clientcert($id)
109) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

110)     $id = (int) $id;
111)     $type = null;
112)     $username = null;
113)     if ($_SESSION['role'] & ROLE_SYSTEMUSER) {
114)         $type = 'user';
115)         $username = $_SESSION['userinfo']['username'];
116)         if (isset($_SESSION['subuser'])) {
117)             $username = $_SESSION['subuser'];
118)             $type = 'subuser';
119)         }
120)     } elseif ($_SESSION['role'] & ROLE_VMAIL_ACCOUNT) {
121)         $type = 'email';
122)         $username = $_SESSION['mailaccount'];
123)     }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 1 year ago

124)     if (!$type || !$username) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

125)         system_failure('cannot get type or username of login');
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

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

Hanno authored 6 years ago

127)     db_query(
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 5 years ago

130)     );