112e0dc636d8ef1ada467bd4a7a68b4362b1b140
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 2 years 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 2 years 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 6 years ago

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

bernd authored 15 years ago

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

Hanno Böck authored 3 years ago

18)     $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

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

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

39)     $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

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

54)     $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

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

bernd authored 15 years ago

62) }
63) 
64) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

67)     $type = null;
68)     $username = null;
69)     if ($_SESSION['role'] & ROLE_SYSTEMUSER) {
70)         $type = 'user';
71)         $username = $_SESSION['userinfo']['username'];
72)         if (isset($_SESSION['subuser'])) {
73)             $username = $_SESSION['subuser'];
74)             $type = 'subuser';
75)         }
76)     } elseif ($_SESSION['role'] & ROLE_VMAIL_ACCOUNT) {
77)         $type = 'email';
78)         $username = $_SESSION['mailaccount'];
79)     }
80)     if (! $type || ! $username) {
81)         system_failure('cannot get type or username of login');
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

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

Hanno authored 6 years ago

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

Hanno Böck authored 3 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 8 years ago

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

Bernd Wurst authored 8 years ago

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

Bernd Wurst authored 10 years ago

96)                 ":certdata" => $certdata,
97)                 ":type" => $type,
98)                 ":username" => $username,
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 3 years ago

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

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

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

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

109)     $id = (int) $id;
110)     $type = null;
111)     $username = null;
112)     if ($_SESSION['role'] & ROLE_SYSTEMUSER) {
113)         $type = 'user';
114)         $username = $_SESSION['userinfo']['username'];
115)         if (isset($_SESSION['subuser'])) {
116)             $username = $_SESSION['subuser'];
117)             $type = 'subuser';
118)         }
119)     } elseif ($_SESSION['role'] & ROLE_VMAIL_ACCOUNT) {
120)         $type = 'email';
121)         $username = $_SESSION['mailaccount'];
122)     }
123)     if (! $type || ! $username) {
124)         system_failure('cannot get type or username of login');
Bernd Wurst bugfix: missing brackets

Bernd Wurst authored 12 years ago

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

Hanno authored 6 years ago

126)     db_query(
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

127)         "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

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

Hanno authored 5 years ago

129)     );