3ef995c2108fe77d22c0b556fb9717cb848bc48f
bernd Neue Zertifikatsverwaltung

bernd authored 16 years ago

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

Hanno Böck authored 11 months 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 3 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 3 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 Neue Zertifikatsverwaltung

bernd authored 16 years ago

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

Hanno Böck authored 3 years ago

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

bernd authored 16 years ago

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

Hanno authored 7 years ago

21) if ($_GET['action'] == 'new') {
22)     check_form_token('vhosts_certs_new');
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

23)     if (!isset($_POST['cert'])) {
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

24)         system_failure("Es wurde kein Zertifikat eingegeben");
25)     }
26)     $cert = $_POST['cert'];
27)     $oldcert = null;
28)     if (isset($_REQUEST['replace']) && is_numeric($_REQUEST['replace'])) {
29)         $oldcert = cert_details($_REQUEST['replace']);
30)         DEBUG('altes cert:');
31)         DEBUG($oldcert);
32)     }
33)     $key = null;
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

34)     if (!isset($_POST['key']) && isset($_REQUEST['csr'])) {
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

35)         $csr = csr_details($_REQUEST['csr']);
36)         $key = $csr['key'];
37)     } elseif (isset($_POST['key']) and $_POST['key']) {
38)         $key = $_POST['key'];
39)     } elseif ($oldcert) {
40)         $key = $oldcert['key'];
41)     }
42) 
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

43)     if (!$cert or !$key) {
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

44)         system_failure('Es muss ein Zertifikat und der dazu passende private Schlüssel eingetragen werden');
45)     }
46) 
47)     $result = validate_certificate($cert, $key);
48)     switch ($result) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 3 years ago

49)         case CERT_OK:
50)             $certinfo = parse_cert_details($cert);
51)             if ($oldcert) {
52)                 refresh_cert($oldcert['id'], $certinfo, $cert, $key);
53)             } else {
54)                 save_cert($certinfo, $cert, $key);
55)             }
56)             if (isset($_REQUEST['csr'])) {
57)                 delete_csr($_REQUEST['csr']);
58)             }
59)             header('Location: certs');
60)             die();
61)             break;
62)         case CERT_INVALID:
63)             system_failure("Das Zertifikat konnte nicht gelesen werden. Eventuell ist der private Schlüssel mit einem Paswort versehen?");
64)             break;
65)         case CERT_NOCHAIN:
66)             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.');
67)             $certinfo = parse_cert_details($cert);
68)             if ($oldcert) {
69)                 refresh_cert($oldcert['id'], $certinfo, $cert, $key);
70)             } else {
71)                 save_cert($certinfo, $cert, $key);
72)             }
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

73)             output('<p>' . internal_link('certs', 'Zurück zur Übersicht') . '</p>');
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 3 years ago

74)             if (isset($_REQUEST['csr'])) {
75)                 delete_csr($_REQUEST['csr']);
76)             }
77)             break;
78)     }
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

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

bernd authored 16 years ago

85) 
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

86)     if (!$cert) {
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

87)         system_failure('Es muss ein Zertifikat eingetragen werden');
88)     }
bernd Cert-Refresh

bernd authored 16 years ago

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

Hanno authored 7 years ago

90)     $result = validate_certificate($cert, $key);
91)     switch ($result) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 3 years ago

92)         case CERT_OK:
93)             $certinfo = parse_cert_details($cert);
94)             if ($certinfo['cn'] != $oldcert['cn']) {
95)                 system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
96)             }
bernd Cert-Refresh

bernd authored 16 years ago

97) 
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 3 years ago

98)             refresh_cert($id, $certinfo, $cert);
99)             header('Location: certs');
100)             die();
101)             break;
102)         case CERT_INVALID:
103)             system_failure("Das Zertifikat konnte nicht gelesen werden. Eventuell ist es nicht wirklich eine neue Version des bisherigen Zertifikats.");
104)             break;
105)         case CERT_NOCHAIN:
106)             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.');
107)             $certinfo = parse_cert_details($cert);
108)             if ($certinfo['cn'] != $oldcert['cn']) {
109)                 system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
110)             }
bernd Cert-Refresh

bernd authored 16 years ago

111) 
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 3 years ago

112)             refresh_cert($id, $certinfo, $cert);
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

113)             output('<p>' . internal_link('certs', 'Zurück zur Übersicht') . '</p>');
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 3 years ago

114)             break;
115)     }
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

116) } elseif ($_GET['action'] == 'delete') {
117)     $cert = cert_details($_GET['id']);
118)     $sure = user_is_sure();
119)     if ($sure === null) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

120)         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 7 years ago

121)     } elseif ($sure === false) {
122)         header('Location: certs');
123)         die();
124)     } elseif ($sure === true) {
125)         delete_cert($cert['id']);
126)         header('Location: certs');
127)         die();
128)     }
129) } elseif ($_GET['action'] == 'deletecsr') {
130)     $csr = csr_details($_GET['id']);
131)     $sure = user_is_sure();
132)     if ($sure === null) {
133)         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?");
134)     } elseif ($sure === false) {
135)         header('Location: certs');
136)         die();
137)     } elseif ($sure === true) {
138)         delete_csr($csr['id']);
139)         header('Location: certs');
140)         die();
141)     }
142) } elseif ($_GET['action'] == 'newcsr') {
143)     $replace = null;
144)     if (isset($_REQUEST['replace'])) {
145)         $replace = $_REQUEST['replace'];
146)     }
147)     $cn = urldecode($_REQUEST['commonname']);
148)     $bitlength = 4096;
149)     if (isset($_REQUEST['bitlength'])) {
150)         $bitlength = $_REQUEST['bitlength'];
151)     }
Hanno remove whitespace in empty...

Hanno authored 7 years ago

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

Hanno authored 7 years ago

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

bernd authored 16 years ago

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

Hanno authored 7 years ago

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