|
18 | 18 | // Check for empty fields |
19 | 19 | if (empty($_POST['v_domain'])) $errors[] = __('domain'); |
20 | 20 | if (empty($_POST['v_ip'])) $errors[] = __('ip'); |
21 | | - if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_crt']))) $errors[] = __('ssl certificate'); |
22 | | - if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_key']))) $errors[] = __('ssl key'); |
| 21 | + if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_crt']))&& (empty($_POST['v_letsencrypt']))) $errors[] = __('ssl certificate'); |
| 22 | + if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_key']))&& (empty($_POST['v_letsencrypt']))) $errors[] = __('ssl key'); |
23 | 23 | if (!empty($errors[0])) { |
24 | 24 | foreach ($errors as $i => $error) { |
25 | 25 | if ( $i == 0 ) { |
|
79 | 79 | $v_ssl_key = $_POST['v_ssl_key']; |
80 | 80 | $v_ssl_ca = $_POST['v_ssl_ca']; |
81 | 81 | $v_ssl_home = $data[$v_domain]['SSL_HOME']; |
| 82 | + $v_letsencrypt = $_POST['v_letsencrypt']; |
82 | 83 | $v_stats = escapeshellarg($_POST['v_stats']); |
83 | 84 | $v_stats_user = $data[$v_domain]['STATS_USER']; |
84 | 85 | $v_stats_password = $data[$v_domain]['STATS_PASSWORD']; |
|
96 | 97 | if ((!empty($_POST['v_ssl'])) || (!empty($_POST['v_elog']))) $v_adv = 'yes'; |
97 | 98 | if ((!empty($_POST['v_ssl_crt'])) || (!empty($_POST['v_ssl_key']))) $v_adv = 'yes'; |
98 | 99 | if ((!empty($_POST['v_ssl_ca'])) || ($_POST['v_stats'] != 'none')) $v_adv = 'yes'; |
| 100 | + if ((!empty($_POST['v_letsencrypt']))) $v_adv = 'yes'; |
99 | 101 |
|
100 | 102 | // Check advanced features |
101 | 103 | if (empty($_POST['v_dns'])) $v_dns = 'off'; |
|
144 | 146 | unset($output); |
145 | 147 | } |
146 | 148 |
|
147 | | - // Add SSL certificates |
148 | | - if ((!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
149 | | - exec ('mktemp -d', $output, $return_var); |
150 | | - $tmpdir = $output[0]; |
151 | | - unset($output); |
152 | | - |
153 | | - // Save certificate |
154 | | - if (!empty($_POST['v_ssl_crt'])) { |
155 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
156 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
157 | | - fwrite($fp, "\n"); |
158 | | - fclose($fp); |
159 | | - } |
160 | | - |
161 | | - // Save private key |
162 | | - if (!empty($_POST['v_ssl_key'])) { |
163 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
164 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
165 | | - fwrite($fp, "\n"); |
166 | | - fclose($fp); |
167 | | - } |
| 149 | + // Add Lets Encrypt support |
168 | 150 |
|
169 | | - // Save CA bundle |
170 | | - if (!empty($_POST['v_ssl_ca'])) { |
171 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
172 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
173 | | - fwrite($fp, "\n"); |
174 | | - fclose($fp); |
175 | | - } |
176 | | - |
177 | | - $v_ssl_home = escapeshellarg($_POST['v_ssl_home']); |
178 | | - exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var); |
| 151 | + if ((!empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) { |
| 152 | + exec (VESTA_CMD."v-list-web-domain ".$user." ".$v_domain." json", $output, $return_var); |
| 153 | + $data = json_decode(implode('', $output), true); |
| 154 | + exec (VESTA_CMD."v-add-letsencrypt-domain ".$user." ".$v_domain." '".$data['ALIAS']."' 'no'", $output, $return_var); |
179 | 155 | check_return_code($return_var,$output); |
180 | 156 | unset($output); |
181 | | - } |
182 | | - |
| 157 | + } |
| 158 | + else { |
| 159 | + // Add SSL certificates only if Lets Encrypt is off |
| 160 | + if ((!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
| 161 | + exec ('mktemp -d', $output, $return_var); |
| 162 | + $tmpdir = $output[0]; |
| 163 | + unset($output); |
| 164 | + |
| 165 | + // Save certificate |
| 166 | + if (!empty($_POST['v_ssl_crt'])) { |
| 167 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
| 168 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
| 169 | + fwrite($fp, "\n"); |
| 170 | + fclose($fp); |
| 171 | + } |
| 172 | + |
| 173 | + // Save private key |
| 174 | + if (!empty($_POST['v_ssl_key'])) { |
| 175 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
| 176 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
| 177 | + fwrite($fp, "\n"); |
| 178 | + fclose($fp); |
| 179 | + } |
| 180 | + |
| 181 | + // Save CA bundle |
| 182 | + if (!empty($_POST['v_ssl_ca'])) { |
| 183 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
| 184 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
| 185 | + fwrite($fp, "\n"); |
| 186 | + fclose($fp); |
| 187 | + } |
| 188 | + |
| 189 | + $v_ssl_home = escapeshellarg($_POST['v_ssl_home']); |
| 190 | + exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var); |
| 191 | + check_return_code($return_var,$output); |
| 192 | + unset($output); |
| 193 | + } |
| 194 | + |
| 195 | + } |
183 | 196 | // Add web stats |
184 | 197 | if ((!empty($_POST['v_stats'])) && ($_POST['v_stats'] != 'none' ) && (empty($_SESSION['error_msg']))) { |
185 | 198 | $v_stats = escapeshellarg($_POST['v_stats']); |
|
0 commit comments