index.php 2.8 KB

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