65032a1c549e72f9a59ee57328d48df3dfe8cd4e
bernd Neue Zertifikatsverwaltung

bernd authored 14 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 5 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 Neue Zertifikatsverwaltung

bernd authored 14 years ago

16) 
17) require_once("certs.php");
Hanno Böck Fix XSS when deleting cert

Hanno Böck authored 1 year ago

18) require_once("inc/security.php");
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

19) require_role(ROLE_SYSTEMUSER);
20) 
21) $section = 'vhosts_certs';
22) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

23) if ($_GET['action'] == 'new') {
24)     check_form_token('vhosts_certs_new');
25)     if (! isset($_POST['cert'])) {
26)         system_failure("Es wurde kein Zertifikat eingegeben");
27)     }
28)     $cert = $_POST['cert'];
29)     $oldcert = null;
30)     if (isset($_REQUEST['replace']) && is_numeric($_REQUEST['replace'])) {
31)         $oldcert = cert_details($_REQUEST['replace']);
32)         DEBUG('altes cert:');
33)         DEBUG($oldcert);
34)     }
35)     $key = null;
36)     if (! isset($_POST['key']) && isset($_REQUEST['csr'])) {
37)         $csr = csr_details($_REQUEST['csr']);
38)         $key = $csr['key'];
39)     } elseif (isset($_POST['key']) and $_POST['key']) {
40)         $key = $_POST['key'];
41)     } elseif ($oldcert) {
42)         $key = $oldcert['key'];
43)     }
44) 
45)     if (! $cert or ! $key) {
46)         system_failure('Es muss ein Zertifikat und der dazu passende private Schlüssel eingetragen werden');
47)     }
48) 
49)     $result = validate_certificate($cert, $key);
50)     switch ($result) {
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

51)     case CERT_OK:
52)       $certinfo = parse_cert_details($cert);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

53)       if ($oldcert) {
54)           refresh_cert($oldcert['id'], $certinfo, $cert, $key);
55)       } else {
56)           save_cert($certinfo, $cert, $key);
57)       }
58)       if (isset($_REQUEST['csr'])) {
59)           delete_csr($_REQUEST['csr']);
60)       }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

61)       header('Location: certs');
62)       die();
63)       break;
64)     case CERT_INVALID:
65)       system_failure("Das Zertifikat konnte nicht gelesen werden. Eventuell ist der private Schlüssel mit einem Paswort versehen?");
66)       break;
67)     case CERT_NOCHAIN:
hanno fehlermeldung genauer, abge...

hanno authored 13 years ago

68)       warning('Ihr Zertifikat konnte nicht mit einer Zertifikats-Kette validiert werden. Dies wird zu Problemen beim Betrachten der damit betriebenen Websites führen. Dies kann daran liegen dass es abgelaufen ist oder wenn kein passendes CA-Bundle hinterlegt wurde. Die Admins können Ihr Zertifikats-Bundle auf dem System eintragen. Das Zertifikat wurde dennoch gespeichert.');
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

69)       $certinfo = parse_cert_details($cert);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

70)       if ($oldcert) {
71)           refresh_cert($oldcert['id'], $certinfo, $cert, $key);
72)       } else {
73)           save_cert($certinfo, $cert, $key);
74)       }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

75)       output('<p>'.internal_link('certs', 'Zurück zur Übersicht').'</p>');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

76)       if (isset($_REQUEST['csr'])) {
77)           delete_csr($_REQUEST['csr']);
78)       }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

79)       break;
80)   }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

81) } elseif ($_GET['action'] == 'refresh') {
82)     check_form_token('vhosts_certs_refresh');
83)     $cert = $_POST['cert'];
84)     $oldcert = cert_details($_REQUEST['id']);
85)     $key = $oldcert['key'];
86)     $id = (int) $_REQUEST['id'];
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

Hanno authored 5 years ago

88)     if (! $cert) {
89)         system_failure('Es muss ein Zertifikat eingetragen werden');
90)     }
bernd Cert-Refresh

bernd authored 14 years ago

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

Hanno authored 5 years ago

92)     $result = validate_certificate($cert, $key);
93)     switch ($result) {
bernd Cert-Refresh

bernd authored 14 years ago

94)     case CERT_OK:
95)       $certinfo = parse_cert_details($cert);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

96)       if ($certinfo['cn'] != $oldcert['cn']) {
97)           system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
98)       }
bernd Cert-Refresh

bernd authored 14 years ago

99) 
100)       refresh_cert($id, $certinfo, $cert);
101)       header('Location: certs');
102)       die();
103)       break;
104)     case CERT_INVALID:
105)       system_failure("Das Zertifikat konnte nicht gelesen werden. Eventuell ist es nicht wirklich eine neue Version des bisherigen Zertifikats.");
106)       break;
107)     case CERT_NOCHAIN:
108)       warning('Ihr Zertifikat konnte nicht mit einer Zertifikats-Kette validiert werden. Dies wird zu Problemen beim Betrachten der damit betriebenen Websites führen. Meist liegt dies an einem nicht hinterlegten CA-Bundle. Die Admins können Ihr Zertifikats-Bundle auf dem System eintragen. Das Zertifikat wurde dennoch gespeichert.');
109)       $certinfo = parse_cert_details($cert);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

110)       if ($certinfo['cn'] != $oldcert['cn']) {
111)           system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
112)       }
bernd Cert-Refresh

bernd authored 14 years ago

113) 
114)       refresh_cert($id, $certinfo, $cert);
115)       output('<p>'.internal_link('certs', 'Zurück zur Übersicht').'</p>');
116)       break;
117)   }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

118) } elseif ($_GET['action'] == 'delete') {
119)     $cert = cert_details($_GET['id']);
120)     $sure = user_is_sure();
121)     if ($sure === null) {
Hanno Böck Fix XSS when deleting cert

Hanno Böck authored 1 year ago

122)         are_you_sure("action=delete&id={$cert['id']}", "Soll das Zertifikat für »".filter_output_html($cert['subject'])."« (gültig von {$cert['valid_from']} bis {$cert['valid_until']}) wirklich entfernt werden?");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

123)     } elseif ($sure === false) {
124)         header('Location: certs');
125)         die();
126)     } elseif ($sure === true) {
127)         delete_cert($cert['id']);
128)         header('Location: certs');
129)         die();
130)     }
131) } elseif ($_GET['action'] == 'deletecsr') {
132)     $csr = csr_details($_GET['id']);
133)     $sure = user_is_sure();
134)     if ($sure === null) {
135)         are_you_sure("action=deletecsr&id={$csr['id']}", "Soll der CSR für »{$csr['hostname']}« ({$csr['bits']} Bits, erstellt am {$csr['created']}) wirklich entfernt werden?");
136)     } elseif ($sure === false) {
137)         header('Location: certs');
138)         die();
139)     } elseif ($sure === true) {
140)         delete_csr($csr['id']);
141)         header('Location: certs');
142)         die();
143)     }
144) } elseif ($_GET['action'] == 'newcsr') {
145)     $replace = null;
146)     if (isset($_REQUEST['replace'])) {
147)         $replace = $_REQUEST['replace'];
148)     }
149)     $cn = urldecode($_REQUEST['commonname']);
150)     $bitlength = 4096;
151)     if (isset($_REQUEST['bitlength'])) {
152)         $bitlength = $_REQUEST['bitlength'];
153)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

155)     $id = save_csr($cn, $bitlength, $replace);
bernd CSR-Erstellung

bernd authored 14 years ago

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

Hanno authored 5 years ago

157)     header("Location: showcert?mode=csr&id={$id}");
158)     die();
159) } else {
160)     system_failure('not implemented');