|
| 1 | +<?php |
| 2 | +// Init |
| 3 | +error_reporting(NULL); |
| 4 | +session_start(); |
| 5 | +$TAB = 'WEB'; |
| 6 | +include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); |
| 7 | + |
| 8 | +// Header |
| 9 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); |
| 10 | + |
| 11 | +// Panel |
| 12 | +top_panel($user,$TAB); |
| 13 | + |
| 14 | +// Prepare values |
| 15 | +if (!empty($_GET['domain'])) { |
| 16 | + $v_domain = $_GET['domain']; |
| 17 | +} else { |
| 18 | + $v_domain = 'example.ltd'; |
| 19 | +} |
| 20 | +$v_email = 'admin@' . $v_domain; |
| 21 | +$v_country = 'US'; |
| 22 | +$v_state = 'California'; |
| 23 | +$v_locality = 'San Francisco'; |
| 24 | +$v_org = 'MyCompany LLC'; |
| 25 | +$v_org_unit = 'IT'; |
| 26 | + |
| 27 | +// Back uri |
| 28 | +$_SESSION['back'] = ''; |
| 29 | + |
| 30 | +// Check POST |
| 31 | +if (!isset($_POST['generate'])) { |
| 32 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/generate_ssl.html'); |
| 33 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); |
| 34 | + exit(); |
| 35 | +} |
| 36 | + |
| 37 | +// Check input |
| 38 | +if (empty($_POST['v_domain'])) $errors[] = __('domain'); |
| 39 | +if (empty($_POST['v_country'])) $errors[] = __('country'); |
| 40 | +if (empty($_POST['v_state'])) $errors[] = __('domain'); |
| 41 | +if (empty($_POST['v_locality'])) $errors[] = __('city'); |
| 42 | +if (empty($_POST['v_org'])) $errors[] = __('organization'); |
| 43 | +$v_domain = $_POST['v_domain']; |
| 44 | +$v_email = $_POST['v_email']; |
| 45 | +$v_country = $_POST['v_country']; |
| 46 | +$v_state = $_POST['v_state']; |
| 47 | +$v_locality = $_POST['v_locality']; |
| 48 | +$v_org = $_POST['v_org']; |
| 49 | + |
| 50 | +// Check for errors |
| 51 | +if (!empty($errors[0])) { |
| 52 | + foreach ($errors as $i => $error) { |
| 53 | + if ( $i == 0 ) { |
| 54 | + $error_msg = $error; |
| 55 | + } else { |
| 56 | + $error_msg = $error_msg.", ".$error; |
| 57 | + } |
| 58 | + } |
| 59 | + $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg); |
| 60 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/generate_ssl.html'); |
| 61 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); |
| 62 | + unset($_SESSION['error_msg']); |
| 63 | + exit(); |
| 64 | +} |
| 65 | + |
| 66 | +// Protect input |
| 67 | +$v_domain = escapeshellarg($_POST['v_domain']); |
| 68 | +$v_email = escapeshellarg($_POST['v_email']); |
| 69 | +$v_country = escapeshellarg($_POST['v_country']); |
| 70 | +$v_state = escapeshellarg($_POST['v_state']); |
| 71 | +$v_locality = escapeshellarg($_POST['v_locality']); |
| 72 | +$v_org = escapeshellarg($_POST['v_org']); |
| 73 | + |
| 74 | +exec (VESTA_CMD."v-generate-ssl-cert ".$v_domain." ".$v_email." ".$v_country." ".$v_state." ".$v_locality." ".$v_org." IT json", $output, $return_var); |
| 75 | + |
| 76 | +// Revert to raw values |
| 77 | +$v_domain = $_POST['v_domain']; |
| 78 | +$v_email = $_POST['v_email']; |
| 79 | +$v_country = $_POST['v_country']; |
| 80 | +$v_state = $_POST['v_state']; |
| 81 | +$v_locality = $_POST['v_locality']; |
| 82 | +$v_org = $_POST['v_org']; |
| 83 | + |
| 84 | +// Check return code |
| 85 | +if ($return_var != 0) { |
| 86 | + $error = implode('<br>', $output); |
| 87 | + if (empty($error)) $error = __('Error code:',$return_var); |
| 88 | + $_SESSION['error_msg'] = $error; |
| 89 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/generate_ssl.html'); |
| 90 | + include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); |
| 91 | + unset($_SESSION['error_msg']); |
| 92 | + exit(); |
| 93 | +} |
| 94 | + |
| 95 | +// OK message |
| 96 | +$_SESSION['ok_msg'] = __('SSL_GENERATED_OK'); |
| 97 | + |
| 98 | +// Parse output |
| 99 | +$data = json_decode(implode('', $output), true); |
| 100 | +unset($output); |
| 101 | +$v_crt = $data[$v_domain]['CRT']; |
| 102 | +$v_key = $data[$v_domain]['KEY']; |
| 103 | +$v_csr = $data[$v_domain]['CSR']; |
| 104 | + |
| 105 | +// Back uri |
| 106 | +$_SESSION['back'] = $_SERVER['REQUEST_URI']; |
| 107 | + |
| 108 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_ssl.html'); |
| 109 | +include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html'); |
| 110 | +unset($_SESSION['ok_msg']); |
| 111 | + |
| 112 | +?> |
0 commit comments