d9f74479a25fe7470a8419e03c1c06dde2bde7fc
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 Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 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) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

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) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Bernd Wurst authored 11 years ago

24) }
25) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

28)     $result = db_query("SELECT type,username,startpage FROM system.clientcert WHERE cert=? ORDER BY type,username", array($cert));
29)     if ($result->rowCount() < 1) {
Bernd Wurst Entferne Javascript-Konstru...

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

31)         return null;
32)     } else {
33)         $ret = array();
34)         while ($row = $result->fetch()) {
35)             $ret[] = $row;
36)         }
Bernd Wurst Entferne Javascript-Konstru...

Bernd Wurst authored 6 years ago

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

Hanno authored 6 years ago

39)         return $ret;
40)     }
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

41) }
42) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

45)     $id = (int) $id;
46)     if ($id == 0) {
47)         system_failure('no ID');
48)     }
49)     $result = db_query("SELECT id,dn,issuer,serial,valid_from,valid_until,cert,username,startpage FROM system.clientcert WHERE `id`=?", array($id));
50)     if ($result->rowCount() < 1) {
51)         return null;
52)     }
53)     $ret = $result->fetch();
54)     DEBUG($ret);
55)     return $ret;
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

56) }
57) 
58) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

61)     if ($username == '') {
62)         system_failure('empty username');
63)     }
64)     $result = db_query("SELECT id,dn,issuer,serial,valid_from,valid_until,cert,startpage FROM system.clientcert WHERE `username`=?", array($username));
65)     if ($result->rowCount() < 1) {
66)         return null;
67)     }
68)     while ($row = $result->fetch()) {
69)         $ret[] = $row;
70)     }
71)     return $ret;
bernd Login via Client-Zertifikat...

bernd authored 15 years ago

72) }
73) 
74) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

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

Bernd Wurst authored 12 years ago

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

Hanno authored 6 years ago

93)     if ($startpage &&  ! check_path($startpage)) {
94)         system_failure('Startseite kaputt');
95)     }
96) 
97)     if ($certdata == '') {
98)         system_failure('Kein Zertifikat');
99)     }
100) 
101)     $args = array(":dn" => $dn,
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 8 years ago

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

Bernd Wurst authored 8 years ago

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

Bernd Wurst authored 10 years ago

106)                 ":certdata" => $certdata,
107)                 ":type" => $type,
108)                 ":username" => $username,
109)                 ":startpage" => $startpage);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

bernd authored 15 years ago

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

Hanno authored 6 years ago

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

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

bernd authored 15 years ago

114) }
115) 
116) 
117) function delete_clientcert($id)
118) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

Bernd Wurst authored 12 years ago

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

Hanno authored 6 years ago

136)     db_query(
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

137)         "DELETE FROM system.clientcert WHERE id=:id AND type=:type AND username=:username",
138)         array(":id" => $id, ":type" => $type, ":username" => $username)
Hanno Fix codingstyle

Hanno authored 5 years ago

139)     );