index.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. error_reporting(NULL);
  3. $TAB = 'WEB';
  4. header('Content-Type: application/json');
  5. // Main include
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. // Prepare values
  8. if (!empty($_GET['domain'])) {
  9. $v_domain = $_GET['domain'];
  10. } else {
  11. $v_domain = 'example.ltd';
  12. }
  13. $v_email = 'admin@' . $v_domain;
  14. $v_country = 'US';
  15. $v_state = 'California';
  16. $v_locality = 'San Francisco';
  17. $v_org = 'MyCompany LLC';
  18. $v_org_unit = 'IT';
  19. if (isset($_POST['generate'])) {
  20. // Check input
  21. if (empty($_POST['v_domain'])) $errors[] = __('Domain');
  22. if (empty($_POST['v_country'])) $errors[] = __('Country');
  23. if (empty($_POST['v_state'])) $errors[] = __('State');
  24. if (empty($_POST['v_locality'])) $errors[] = __('City');
  25. if (empty($_POST['v_org'])) $errors[] = __('Organization');
  26. if (empty($_POST['v_email'])) $errors[] = __('Email');
  27. $v_domain = $_POST['v_domain'];
  28. $v_email = $_POST['v_email'];
  29. $v_country = $_POST['v_country'];
  30. $v_state = $_POST['v_state'];
  31. $v_locality = $_POST['v_locality'];
  32. $v_org = $_POST['v_org'];
  33. // Check for errors
  34. if (!empty($errors[0])) {
  35. foreach ($errors as $i => $error) {
  36. if ( $i == 0 ) {
  37. $error_msg = $error;
  38. } else {
  39. $error_msg = $error_msg.", ".$error;
  40. }
  41. }
  42. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  43. unset($_SESSION['error_msg']);
  44. exit;
  45. }
  46. // Protect input
  47. $v_domain = escapeshellarg($_POST['v_domain']);
  48. $v_email = escapeshellarg($_POST['v_email']);
  49. $v_country = escapeshellarg($_POST['v_country']);
  50. $v_state = escapeshellarg($_POST['v_state']);
  51. $v_locality = escapeshellarg($_POST['v_locality']);
  52. $v_org = escapeshellarg($_POST['v_org']);
  53. exec (VESTA_CMD."v-generate-ssl-cert ".$v_domain." ".$v_email." ".$v_country." ".$v_state." ".$v_locality." ".$v_org." IT '' json", $output, $return_var);
  54. // Revert to raw values
  55. $v_domain = $_POST['v_domain'];
  56. $v_email = $_POST['v_email'];
  57. $v_country = $_POST['v_country'];
  58. $v_state = $_POST['v_state'];
  59. $v_locality = $_POST['v_locality'];
  60. $v_org = $_POST['v_org'];
  61. // Check return code
  62. if ($return_var != 0) {
  63. $error = implode('<br>', $output);
  64. if (empty($error)) $error = __('Error code:',$return_var);
  65. $_SESSION['error_msg'] = $error;
  66. unset($_SESSION['error_msg']);
  67. exit;
  68. }
  69. // OK message
  70. $_SESSION['ok_msg'] = __('SSL_GENERATED_OK');
  71. // Parse output
  72. $data = json_decode(implode('', $output), true);
  73. unset($output);
  74. $v_crt = $data[$v_domain]['CRT'];
  75. $v_key = $data[$v_domain]['KEY'];
  76. $v_csr = $data[$v_domain]['CSR'];
  77. }
  78. $result = array(
  79. 'domain' => $v_domain,
  80. 'email' => $v_email,
  81. 'country' => $v_country,
  82. 'state' => $v_state,
  83. 'locality' => $v_locality,
  84. 'org' => $v_org,
  85. 'org_unit' => $v_org_unit,
  86. 'crt' => $v_crt,
  87. 'key' => $v_key,
  88. 'csr' => $v_csr,
  89. 'ok_msg' => $_SESSION['ok_msg'],
  90. 'error_msg' => $_SESSION['error_msg']
  91. );
  92. echo json_encode($result);
  93. unset($_SESSION['ok_msg']);
  94. unset($_SESSION['error_msg']);