838077f18b71321a685c84329342e6a711d22d09
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) 
5) Written 2008-2012 by schokokeks.org Hosting, namely
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');
25)   $cert = $_POST['cert'];
26)   $key = $_POST['key'];
bernd CSR-Erstellung

bernd authored 14 years ago

27)   if (! isset($_POST['key']) && isset($_REQUEST['csr']))
28)   {
29)     $csr = csr_details($_REQUEST['csr']);
30)     $key = $csr['key'];
31)   }
bernd neue Bilder, mehr SSL-Zerti...

bernd authored 14 years ago

32)   $oldcert = NULL;
33)   if ($_REQUEST['replace'])
34)   {
35)     $oldcert = cert_details($_REQUEST['replace']);
36)   }
bernd CSR-Erstellung

bernd authored 14 years ago

37) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 14 years ago

46)       if ($oldcert)
47)         refresh_cert($oldcert['id'], $certinfo, $cert, $key);
48)       else
49)         save_cert($certinfo, $cert, $key);
bernd CSR-Erstellung

bernd authored 14 years ago

50)       if (isset($_REQUEST['csr']))
51)         delete_csr($_REQUEST['csr']);
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

hanno authored 13 years ago

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

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

bernd authored 14 years ago

61)       if ($oldcert)
62)         refresh_cert($oldcert['id'], $certinfo, $cert, $key);
63)       else
64)         save_cert($certinfo, $cert, $key);
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

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

bernd authored 14 years ago

66)       if (isset($_REQUEST['csr']))
67)         delete_csr($_REQUEST['csr']);
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

68)       break;
69)   }
70) 
bernd Cert-Refresh

bernd authored 14 years ago

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

bernd authored 14 years ago

109) }
110) elseif ($_GET['action'] == 'delete')
111) {
112)   $cert = cert_details($_GET['id']);
113)   $sure = user_is_sure();
114)   if ($sure === NULL)
115)   {
116)     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?");
117)   }
118)   elseif ($sure === false)
119)   {
120)     header('Location: certs');
121)     die();
122)   }
123)   elseif ($sure === true)
124)   { 
125)     delete_cert($cert['id']);
126)     header('Location: certs');
127)     die();
128)   }
129) }
bernd CSR-Erstellung

bernd authored 14 years ago

130) elseif ($_GET['action'] == 'deletecsr')
131) {
132)   $csr = csr_details($_GET['id']);
133)   $sure = user_is_sure();
134)   if ($sure === NULL)
135)   {
136)     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?");
137)   }
138)   elseif ($sure === false)
139)   {
140)     header('Location: certs');
141)     die();
142)   }
143)   elseif ($sure === true)
144)   { 
145)     delete_csr($csr['id']);
146)     header('Location: certs');
147)     die();
148)   }
149) }
150) elseif ($_GET['action'] == 'newcsr')
151) {
152)   $cn = $_POST['commonname'];
153)   $bitlength = $_POST['bitlength'];
154)   
155)   $wildcard = ! (count(explode('.', $cn)) > 2);
156)   $id = save_csr($cn, $bitlength, $wildcard);
157) 
158)   header("Location: showcert?mode=csr&id={$id}");
159)   die();
160) }