|
35 | 35 | $v_cgi = $data[$v_domain]['CGI']; |
36 | 36 | $v_elog = $data[$v_domain]['ELOG']; |
37 | 37 | $v_ssl = $data[$v_domain]['SSL']; |
38 | | -if ( $v_ssl == 'yes' ) { |
| 38 | +$v_letsencrypt = $data[$v_domain]['LETSENCRYPT']; |
| 39 | +if ( $v_ssl == 'yes' && ($v_letsencrypt == 'no' || empty($v_letsencrypt))) { |
39 | 40 | exec (VESTA_CMD."v-list-web-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var); |
40 | 41 | $ssl_str = json_decode(implode('', $output), true); |
41 | 42 | unset($output); |
|
256 | 257 | $restart_proxy = 'yes'; |
257 | 258 | } |
258 | 259 |
|
259 | | - // Delete SSL certificate |
260 | | - if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
261 | | - exec (VESTA_CMD."v-delete-web-domain-ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var); |
| 260 | + // Disable Lets Encrypt support |
| 261 | + |
| 262 | + if (( $v_letsencrypt == 'yes' ) && (empty($_POST['v_letsencrypt'])) && (!empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) { |
| 263 | + exec (VESTA_CMD."v-add-letsencrypt-domain ".$user." ".$v_domain." '' 'no'", $output, $return_var); |
262 | 264 | check_return_code($return_var,$output); |
263 | 265 | unset($output); |
264 | | - $v_ssl = 'no'; |
| 266 | + $v_letsencrypt = 'no'; |
265 | 267 | $restart_web = 'yes'; |
266 | 268 | $restart_proxy = 'yes'; |
267 | | - } |
268 | | - |
269 | | - // Change SSL certificate |
270 | | - if (($v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
271 | | - if (( $v_ssl_crt != str_replace("\r\n", "\n", $_POST['v_ssl_crt'])) || ( $v_ssl_key != str_replace("\r\n", "\n", $_POST['v_ssl_key'])) || ( $v_ssl_ca != str_replace("\r\n", "\n", $_POST['v_ssl_ca']))) { |
272 | | - exec ('mktemp -d', $mktemp_output, $return_var); |
273 | | - $tmpdir = $mktemp_output[0]; |
274 | | - |
275 | | - // Certificate |
276 | | - if (!empty($_POST['v_ssl_crt'])) { |
277 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
278 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
279 | | - fwrite($fp, "\n"); |
280 | | - fclose($fp); |
281 | | - } |
282 | | - |
283 | | - // Key |
284 | | - if (!empty($_POST['v_ssl_key'])) { |
285 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
286 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
287 | | - fwrite($fp, "\n"); |
288 | | - fclose($fp); |
289 | | - } |
290 | | - |
291 | | - // CA |
292 | | - if (!empty($_POST['v_ssl_ca'])) { |
293 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
294 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
295 | | - fwrite($fp, "\n"); |
296 | | - fclose($fp); |
297 | | - } |
298 | | - |
299 | | - exec (VESTA_CMD."v-change-web-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var); |
300 | | - check_return_code($return_var,$output); |
301 | | - unset($output); |
302 | | - $restart_web = 'yes'; |
303 | | - $restart_proxy = 'yes'; |
304 | | - $v_ssl_crt = $_POST['v_ssl_crt']; |
305 | | - $v_ssl_key = $_POST['v_ssl_key']; |
306 | | - $v_ssl_ca = $_POST['v_ssl_ca']; |
307 | | - |
308 | | - // Cleanup certificate tempfiles |
309 | | - if (!empty($_POST['v_ssl_crt'])) { |
310 | | - unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
311 | | - } |
312 | | - |
313 | | - if (!empty($_POST['v_ssl_key'])) { |
314 | | - unlink($tmpdir."/".$_POST['v_domain'].".key"); |
315 | | - } |
316 | | - |
317 | | - if (!empty($_POST['v_ssl_ca'])) { |
318 | | - unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
319 | | - } |
320 | | - |
321 | | - rmdir($tmpdir); |
322 | | - } |
323 | | - } |
324 | | - |
325 | | - // Add SSL certificate |
326 | | - if (( $v_ssl == 'no') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
327 | | - if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_crt']))) $errors[] = 'ssl certificate'; |
328 | | - if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_key']))) $errors[] = 'ssl key'; |
329 | | - if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_home']))) $errors[] = 'ssl home'; |
330 | | - $v_ssl_home = escapeshellarg($_POST['v_ssl_home']); |
331 | | - if (!empty($errors[0])) { |
332 | | - foreach ($errors as $i => $error) { |
333 | | - if ( $i == 0 ) { |
334 | | - $error_msg = $error; |
335 | | - } else { |
336 | | - $error_msg = $error_msg.", ".$error; |
337 | | - } |
338 | | - } |
339 | | - $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg); |
340 | | - } else { |
341 | | - exec ('mktemp -d', $mktemp_output, $return_var); |
342 | | - $tmpdir = $mktemp_output[0]; |
343 | | - |
344 | | - // Certificate |
345 | | - if (!empty($_POST['v_ssl_crt'])) { |
346 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
347 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
348 | | - fclose($fp); |
349 | | - } |
350 | | - |
351 | | - // Key |
352 | | - if (!empty($_POST['v_ssl_key'])) { |
353 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
354 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
355 | | - fclose($fp); |
356 | | - } |
357 | | - |
358 | | - // CA |
359 | | - if (!empty($_POST['v_ssl_ca'])) { |
360 | | - $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
361 | | - fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
362 | | - fclose($fp); |
363 | | - } |
364 | | - exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var); |
| 269 | + } |
| 270 | + else { |
| 271 | + // Delete SSL certificate |
| 272 | + if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
| 273 | + exec (VESTA_CMD."v-delete-web-domain-ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var); |
365 | 274 | check_return_code($return_var,$output); |
366 | 275 | unset($output); |
367 | | - $v_ssl = 'yes'; |
| 276 | + $v_ssl = 'no'; |
368 | 277 | $restart_web = 'yes'; |
369 | 278 | $restart_proxy = 'yes'; |
370 | | - $v_ssl_crt = $_POST['v_ssl_crt']; |
371 | | - $v_ssl_key = $_POST['v_ssl_key']; |
372 | | - $v_ssl_ca = $_POST['v_ssl_ca']; |
373 | | - $v_ssl_home = $_POST['v_ssl_home']; |
374 | | - |
375 | | - // Cleanup certificate tempfiles |
376 | | - if (!empty($_POST['v_ssl_crt'])) { |
377 | | - unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
378 | | - } |
379 | | - |
380 | | - if (!empty($_POST['v_ssl_key'])) { |
381 | | - unlink($tmpdir."/".$_POST['v_domain'].".key"); |
382 | | - } |
383 | | - |
384 | | - if (!empty($_POST['v_ssl_ca'])) { |
385 | | - unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
386 | | - } |
387 | | - |
388 | | - rmdir($tmpdir); |
389 | 279 | } |
390 | | - } |
391 | | - |
| 280 | + } |
| 281 | + if (( $v_letsencrypt == 'no' || empty( $v_letsencrypt)) && (!empty($_POST['v_letsencrypt'])) && empty($_SESSION['error_msg'])) { |
| 282 | + exec (VESTA_CMD."v-add-letsencrypt-domain ".$user." ".$v_domain." '' 'no'", $output, $return_var); |
| 283 | + check_return_code($return_var,$output); |
| 284 | + unset($output); |
| 285 | + $v_letsencrypt = 'yes'; |
| 286 | + $restart_web = 'yes'; |
| 287 | + $restart_proxy = 'yes'; |
| 288 | + } |
| 289 | + else{ |
| 290 | + // Change SSL certificate |
| 291 | + if (($v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
| 292 | + if (( $v_ssl_crt != str_replace("\r\n", "\n", $_POST['v_ssl_crt'])) || ( $v_ssl_key != str_replace("\r\n", "\n", $_POST['v_ssl_key'])) || ( $v_ssl_ca != str_replace("\r\n", "\n", $_POST['v_ssl_ca']))) { |
| 293 | + exec ('mktemp -d', $mktemp_output, $return_var); |
| 294 | + $tmpdir = $mktemp_output[0]; |
| 295 | + |
| 296 | + // Certificate |
| 297 | + if (!empty($_POST['v_ssl_crt'])) { |
| 298 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
| 299 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
| 300 | + fwrite($fp, "\n"); |
| 301 | + fclose($fp); |
| 302 | + } |
| 303 | + |
| 304 | + // Key |
| 305 | + if (!empty($_POST['v_ssl_key'])) { |
| 306 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
| 307 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
| 308 | + fwrite($fp, "\n"); |
| 309 | + fclose($fp); |
| 310 | + } |
| 311 | + |
| 312 | + // CA |
| 313 | + if (!empty($_POST['v_ssl_ca'])) { |
| 314 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
| 315 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
| 316 | + fwrite($fp, "\n"); |
| 317 | + fclose($fp); |
| 318 | + } |
| 319 | + |
| 320 | + exec (VESTA_CMD."v-change-web-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var); |
| 321 | + check_return_code($return_var,$output); |
| 322 | + unset($output); |
| 323 | + $restart_web = 'yes'; |
| 324 | + $restart_proxy = 'yes'; |
| 325 | + $v_ssl_crt = $_POST['v_ssl_crt']; |
| 326 | + $v_ssl_key = $_POST['v_ssl_key']; |
| 327 | + $v_ssl_ca = $_POST['v_ssl_ca']; |
| 328 | + |
| 329 | + // Cleanup certificate tempfiles |
| 330 | + if (!empty($_POST['v_ssl_crt'])) { |
| 331 | + unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
| 332 | + } |
| 333 | + |
| 334 | + if (!empty($_POST['v_ssl_key'])) { |
| 335 | + unlink($tmpdir."/".$_POST['v_domain'].".key"); |
| 336 | + } |
| 337 | + |
| 338 | + if (!empty($_POST['v_ssl_ca'])) { |
| 339 | + unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
| 340 | + } |
| 341 | + |
| 342 | + rmdir($tmpdir); |
| 343 | + } |
| 344 | + } |
| 345 | + |
| 346 | + // Add SSL certificate |
| 347 | + if (( $v_ssl == 'no') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
| 348 | + if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_crt']))) $errors[] = 'ssl certificate'; |
| 349 | + if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_key']))) $errors[] = 'ssl key'; |
| 350 | + if ((!empty($_POST['v_ssl'])) && (empty($_POST['v_ssl_home']))) $errors[] = 'ssl home'; |
| 351 | + $v_ssl_home = escapeshellarg($_POST['v_ssl_home']); |
| 352 | + if (!empty($errors[0])) { |
| 353 | + foreach ($errors as $i => $error) { |
| 354 | + if ( $i == 0 ) { |
| 355 | + $error_msg = $error; |
| 356 | + } else { |
| 357 | + $error_msg = $error_msg.", ".$error; |
| 358 | + } |
| 359 | + } |
| 360 | + $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg); |
| 361 | + } else { |
| 362 | + exec ('mktemp -d', $mktemp_output, $return_var); |
| 363 | + $tmpdir = $mktemp_output[0]; |
| 364 | + |
| 365 | + // Certificate |
| 366 | + if (!empty($_POST['v_ssl_crt'])) { |
| 367 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
| 368 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
| 369 | + fclose($fp); |
| 370 | + } |
| 371 | + |
| 372 | + // Key |
| 373 | + if (!empty($_POST['v_ssl_key'])) { |
| 374 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
| 375 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
| 376 | + fclose($fp); |
| 377 | + } |
| 378 | + |
| 379 | + // CA |
| 380 | + if (!empty($_POST['v_ssl_ca'])) { |
| 381 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
| 382 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
| 383 | + fclose($fp); |
| 384 | + } |
| 385 | + exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var); |
| 386 | + check_return_code($return_var,$output); |
| 387 | + unset($output); |
| 388 | + $v_ssl = 'yes'; |
| 389 | + $restart_web = 'yes'; |
| 390 | + $restart_proxy = 'yes'; |
| 391 | + $v_ssl_crt = $_POST['v_ssl_crt']; |
| 392 | + $v_ssl_key = $_POST['v_ssl_key']; |
| 393 | + $v_ssl_ca = $_POST['v_ssl_ca']; |
| 394 | + $v_ssl_home = $_POST['v_ssl_home']; |
| 395 | + |
| 396 | + // Cleanup certificate tempfiles |
| 397 | + if (!empty($_POST['v_ssl_crt'])) { |
| 398 | + unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
| 399 | + } |
| 400 | + |
| 401 | + if (!empty($_POST['v_ssl_key'])) { |
| 402 | + unlink($tmpdir."/".$_POST['v_domain'].".key"); |
| 403 | + } |
| 404 | + |
| 405 | + if (!empty($_POST['v_ssl_ca'])) { |
| 406 | + unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
| 407 | + } |
| 408 | + |
| 409 | + rmdir($tmpdir); |
| 410 | + } |
| 411 | + } |
| 412 | + } |
392 | 413 | // Change document root for ssl domain |
393 | 414 | if (( $v_ssl == 'yes') && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
394 | 415 | if ( $v_ssl_home != $_POST['v_ssl_home'] ) { |
|
0 commit comments