index.php 3.2 KB

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