4c630eb1d90ef9c268aeff3700814575bdf24ed6
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");
18) require_role(ROLE_SYSTEMUSER);
19) 
20) $section = 'vhosts_certs';
21) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

hanno authored 13 years ago

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

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

98) 
99)       refresh_cert($id, $certinfo, $cert);
100)       header('Location: certs');
101)       die();
102)       break;
103)     case CERT_INVALID:
104)       system_failure("Das Zertifikat konnte nicht gelesen werden. Eventuell ist es nicht wirklich eine neue Version des bisherigen Zertifikats.");
105)       break;
106)     case CERT_NOCHAIN:
107)       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.');
108)       $certinfo = parse_cert_details($cert);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

117) } elseif ($_GET['action'] == 'delete') {
118)     $cert = cert_details($_GET['id']);
119)     $sure = user_is_sure();
120)     if ($sure === null) {
121)         are_you_sure("action=delete&id={$cert['id']}", "Soll das Zertifikat für »{$cert['subject']}« (gültig von {$cert['valid_from']} bis {$cert['valid_until']}) wirklich entfernt werden?");
122)     } elseif ($sure === false) {
123)         header('Location: certs');
124)         die();
125)     } elseif ($sure === true) {
126)         delete_cert($cert['id']);
127)         header('Location: certs');
128)         die();
129)     }
130) } elseif ($_GET['action'] == 'deletecsr') {
131)     $csr = csr_details($_GET['id']);
132)     $sure = user_is_sure();
133)     if ($sure === null) {
134)         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?");
135)     } elseif ($sure === false) {
136)         header('Location: certs');
137)         die();
138)     } elseif ($sure === true) {
139)         delete_csr($csr['id']);
140)         header('Location: certs');
141)         die();
142)     }
143) } elseif ($_GET['action'] == 'newcsr') {
144)     $replace = null;
145)     if (isset($_REQUEST['replace'])) {
146)         $replace = $_REQUEST['replace'];
147)     }
148)     $cn = urldecode($_REQUEST['commonname']);
149)     $bitlength = 4096;
150)     if (isset($_REQUEST['bitlength'])) {
151)         $bitlength = $_REQUEST['bitlength'];
152)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 14 years ago

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

Hanno authored 5 years ago

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