index.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. $v_domain = $_POST['v_domain'];
  38. $v_email = $_POST['v_email'];
  39. $v_country = $_POST['v_country'];
  40. $v_state = $_POST['v_state'];
  41. $v_locality = $_POST['v_locality'];
  42. $v_org = $_POST['v_org'];
  43. // Check for errors
  44. if (!empty($errors[0])) {
  45. foreach ($errors as $i => $error) {
  46. if ( $i == 0 ) {
  47. $error_msg = $error;
  48. } else {
  49. $error_msg = $error_msg.", ".$error;
  50. }
  51. }
  52. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  53. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/generate_ssl.html');
  54. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
  55. unset($_SESSION['error_msg']);
  56. exit();
  57. }
  58. // Protect input
  59. $v_domain = escapeshellarg($_POST['v_domain']);
  60. $v_email = escapeshellarg($_POST['v_email']);
  61. $v_country = escapeshellarg($_POST['v_country']);
  62. $v_state = escapeshellarg($_POST['v_state']);
  63. $v_locality = escapeshellarg($_POST['v_locality']);
  64. $v_org = escapeshellarg($_POST['v_org']);
  65. exec (VESTA_CMD."v-generate-ssl-cert ".$v_domain." ".$v_email." ".$v_country." ".$v_state." ".$v_locality." ".$v_org." IT json", $output, $return_var);
  66. // Revert to raw values
  67. $v_domain = $_POST['v_domain'];
  68. $v_email = $_POST['v_email'];
  69. $v_country = $_POST['v_country'];
  70. $v_state = $_POST['v_state'];
  71. $v_locality = $_POST['v_locality'];
  72. $v_org = $_POST['v_org'];
  73. // Check return code
  74. if ($return_var != 0) {
  75. $error = implode('<br>', $output);
  76. if (empty($error)) $error = __('Error code:',$return_var);
  77. $_SESSION['error_msg'] = $error;
  78. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/generate_ssl.html');
  79. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
  80. unset($_SESSION['error_msg']);
  81. exit();
  82. }
  83. // OK message
  84. $_SESSION['ok_msg'] = __('SSL_GENERATED_OK');
  85. // Parse output
  86. $data = json_decode(implode('', $output), true);
  87. unset($output);
  88. $v_crt = $data[$v_domain]['CRT'];
  89. $v_key = $data[$v_domain]['KEY'];
  90. $v_csr = $data[$v_domain]['CSR'];
  91. // Back uri
  92. $_SESSION['back'] = $_SERVER['REQUEST_URI'];
  93. include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_ssl.html');
  94. include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
  95. unset($_SESSION['ok_msg']);