49fd23ed86038fd5f9a9687e0d8f180438777c9a
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 Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 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) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
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) 
22) if ($_GET['action'] == 'new')
23) {
24)   check_form_token('vhosts_certs_new');
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

25)   if (! isset($_POST['cert'])) {
26)     system_failure("Es wurde kein Zertifikat eingegeben");
27)   }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

28)   $cert = $_POST['cert'];
Bernd Wurst Ermögliche einen Zertifikat...

Bernd Wurst authored 10 years ago

29)   $oldcert = NULL;
30)   if (isset($_REQUEST['replace']) && is_numeric($_REQUEST['replace']))
31)   {
32)     $oldcert = cert_details($_REQUEST['replace']);
33)     DEBUG('altes cert:');
34)     DEBUG($oldcert);
35)   }
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

36)   $key = NULL;
bernd CSR-Erstellung

bernd authored 14 years ago

37)   if (! isset($_POST['key']) && isset($_REQUEST['csr']))
38)   {
39)     $csr = csr_details($_REQUEST['csr']);
40)     $key = $csr['key'];
Bernd Wurst Ermögliche einen Zertifikat...

Bernd Wurst authored 10 years ago

41)   } elseif (isset($_POST['key']) and $_POST['key']) {
42)     $key = $_POST['key']; 
43)   } elseif ($oldcert) {
44)     $key = $oldcert['key'];
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

45)   }
bernd CSR-Erstellung

bernd authored 14 years ago

46) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

47)   if (! $cert or ! $key)
48)     system_failure('Es muss ein Zertifikat und der dazu passende private Schlüssel eingetragen werden');
49) 
50)   $result = validate_certificate($cert, $key);
51)   switch ($result)
52)   {
53)     case CERT_OK:
54)       $certinfo = parse_cert_details($cert);
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

55)       if ($oldcert)
56)         refresh_cert($oldcert['id'], $certinfo, $cert, $key);
57)       else
58)         save_cert($certinfo, $cert, $key);
bernd CSR-Erstellung

bernd authored 14 years ago

59)       if (isset($_REQUEST['csr']))
60)         delete_csr($_REQUEST['csr']);
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);
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

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

bernd authored 14 years ago

74)       output('<p>'.internal_link('certs', 'Zurück zur Übersicht').'</p>');
bernd CSR-Erstellung

bernd authored 14 years ago

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

bernd authored 14 years ago

77)       break;
78)   }
79) 
bernd Cert-Refresh

bernd authored 14 years ago

80) }
81) elseif ($_GET['action'] == 'refresh')
82) {
83)   check_form_token('vhosts_certs_refresh');
84)   $cert = $_POST['cert'];
85)   $oldcert = cert_details($_REQUEST['id']);
86)   $key = $oldcert['key'];
87)   $id = (int) $_REQUEST['id'];
88) 
89)   if (! $cert )
90)     system_failure('Es muss ein Zertifikat eingetragen werden');
91) 
92)   $result = validate_certificate($cert, $key);
93)   switch ($result)
94)   {
95)     case CERT_OK:
96)       $certinfo = parse_cert_details($cert);
97)       if ($certinfo['cn'] != $oldcert['cn'])
98)         system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
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);
110)       if ($certinfo['cn'] != $oldcert['cn'])
111)         system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
112) 
113)       refresh_cert($id, $certinfo, $cert);
114)       output('<p>'.internal_link('certs', 'Zurück zur Übersicht').'</p>');
115)       break;
116)   }
117) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

118) }
119) elseif ($_GET['action'] == 'delete')
120) {
121)   $cert = cert_details($_GET['id']);
122)   $sure = user_is_sure();
123)   if ($sure === NULL)
124)   {
125)     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?");
126)   }
127)   elseif ($sure === false)
128)   {
129)     header('Location: certs');
130)     die();
131)   }
132)   elseif ($sure === true)
133)   { 
134)     delete_cert($cert['id']);
135)     header('Location: certs');
136)     die();
137)   }
138) }
bernd CSR-Erstellung

bernd authored 14 years ago

139) elseif ($_GET['action'] == 'deletecsr')
140) {
141)   $csr = csr_details($_GET['id']);
142)   $sure = user_is_sure();
143)   if ($sure === NULL)
144)   {
145)     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?");
146)   }
147)   elseif ($sure === false)
148)   {
149)     header('Location: certs');
150)     die();
151)   }
152)   elseif ($sure === true)
153)   { 
154)     delete_csr($csr['id']);
155)     header('Location: certs');
156)     die();
157)   }
158) }
159) elseif ($_GET['action'] == 'newcsr')
160) {
Bernd Wurst Neuer Workflow für Cert-Rep...

Bernd Wurst authored 11 years ago

161)   $replace = NULL;
162)   if (isset($_REQUEST['replace'])) {
163)     $replace = $_REQUEST['replace'];
164)   }
Bernd Wurst Zunächst urldecode() auf de...

Bernd Wurst authored 10 years ago

165)   $cn = urldecode($_REQUEST['commonname']);
Bernd Wurst Neuer Workflow für Cert-Rep...

Bernd Wurst authored 11 years ago

166)   $bitlength = 4096;
167)   if (isset($_REQUEST['bitlength'])) {
168)     $bitlength = $_REQUEST['bitlength'];
169)   }
bernd CSR-Erstellung

bernd authored 14 years ago

170)   
Bernd Wurst Wildcard-CSRs können jetzt...

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

172) 
173)   header("Location: showcert?mode=csr&id={$id}");
174)   die();
175) }