5effc2bd7685822df276c1372dab480cff321941
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 Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

29)   $key = NULL;
bernd CSR-Erstellung

bernd authored 14 years ago

30)   if (! isset($_POST['key']) && isset($_REQUEST['csr']))
31)   {
32)     $csr = csr_details($_REQUEST['csr']);
33)     $key = $csr['key'];
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

34)   } else {
35)     $key = $_POST['key'];
bernd CSR-Erstellung

bernd authored 14 years ago

36)   }
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

37)   $oldcert = NULL;
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

38)   if (isset($_REQUEST['replace']))
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

39)   {
40)     $oldcert = cert_details($_REQUEST['replace']);
41)   }
bernd CSR-Erstellung

bernd authored 14 years ago

42) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 14 years ago

51)       if ($oldcert)
52)         refresh_cert($oldcert['id'], $certinfo, $cert, $key);
53)       else
54)         save_cert($certinfo, $cert, $key);
bernd CSR-Erstellung

bernd authored 14 years ago

55)       if (isset($_REQUEST['csr']))
56)         delete_csr($_REQUEST['csr']);
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

hanno authored 13 years ago

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

65)       $certinfo = parse_cert_details($cert);
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

66)       if ($oldcert)
67)         refresh_cert($oldcert['id'], $certinfo, $cert, $key);
68)       else
69)         save_cert($certinfo, $cert, $key);
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 14 years ago

71)       if (isset($_REQUEST['csr']))
72)         delete_csr($_REQUEST['csr']);
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

73)       break;
74)   }
75) 
bernd Cert-Refresh

bernd authored 14 years ago

76) }
77) elseif ($_GET['action'] == 'refresh')
78) {
79)   check_form_token('vhosts_certs_refresh');
80)   $cert = $_POST['cert'];
81)   $oldcert = cert_details($_REQUEST['id']);
82)   $key = $oldcert['key'];
83)   $id = (int) $_REQUEST['id'];
84) 
85)   if (! $cert )
86)     system_failure('Es muss ein Zertifikat eingetragen werden');
87) 
88)   $result = validate_certificate($cert, $key);
89)   switch ($result)
90)   {
91)     case CERT_OK:
92)       $certinfo = parse_cert_details($cert);
93)       if ($certinfo['cn'] != $oldcert['cn'])
94)         system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
95) 
96)       refresh_cert($id, $certinfo, $cert);
97)       header('Location: certs');
98)       die();
99)       break;
100)     case CERT_INVALID:
101)       system_failure("Das Zertifikat konnte nicht gelesen werden. Eventuell ist es nicht wirklich eine neue Version des bisherigen Zertifikats.");
102)       break;
103)     case CERT_NOCHAIN:
104)       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.');
105)       $certinfo = parse_cert_details($cert);
106)       if ($certinfo['cn'] != $oldcert['cn'])
107)         system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
108) 
109)       refresh_cert($id, $certinfo, $cert);
110)       output('<p>'.internal_link('certs', 'Zurück zur Übersicht').'</p>');
111)       break;
112)   }
113) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 11 years ago

157)   $replace = NULL;
158)   if (isset($_REQUEST['replace'])) {
159)     $replace = $_REQUEST['replace'];
160)   }
Bernd Wurst Zunächst urldecode() auf de...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 11 years ago

162)   $bitlength = 4096;
163)   if (isset($_REQUEST['bitlength'])) {
164)     $bitlength = $_REQUEST['bitlength'];
165)   }
bernd CSR-Erstellung

bernd authored 14 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

168) 
169)   header("Location: showcert?mode=csr&id={$id}");
170)   die();
171) }