|
39 | 39 | } else { |
40 | 40 | $v_status = 'active'; |
41 | 41 | } |
| 42 | + |
| 43 | + $v_ssl = $data[$v_domain]['SSL']; |
| 44 | + if (!empty($v_ssl)) { |
| 45 | + exec (HESTIA_CMD."v-list-mail-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var); |
| 46 | + $ssl_str = json_decode(implode('', $output), true); |
| 47 | + unset($output); |
| 48 | + $v_ssl_crt = $ssl_str[$v_domain]['CRT']; |
| 49 | + $v_ssl_key = $ssl_str[$v_domain]['KEY']; |
| 50 | + $v_ssl_ca = $ssl_str[$v_domain]['CA']; |
| 51 | + $v_ssl_subject = $ssl_str[$v_domain]['SUBJECT']; |
| 52 | + $v_ssl_aliases = $ssl_str[$v_domain]['ALIASES']; |
| 53 | + $v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE']; |
| 54 | + $v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER']; |
| 55 | + $v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE']; |
| 56 | + $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY']; |
| 57 | + $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER']; |
| 58 | + } |
| 59 | + $v_letsencrypt = $data[$v_domain]['LETSENCRYPT']; |
| 60 | + if (empty($v_letsencrypt)) $v_letsencrypt = 'no'; |
42 | 61 | } |
43 | 62 |
|
44 | 63 | // List mail account |
|
164 | 183 | check_return_code($return_var,$output); |
165 | 184 | unset($output); |
166 | 185 | } |
| 186 | + |
| 187 | + // Change SSL certificate |
| 188 | + if (( $v_letsencrypt == 'no' ) && (empty($_POST['v_letsencrypt'])) && ( $v_ssl == 'yes' ) && (!empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
| 189 | + if (( $v_ssl_crt != str_replace("\r\n", "\n", $_POST['v_ssl_crt'])) || ( $v_ssl_key != str_replace("\r\n", "\n", $_POST['v_ssl_key'])) || ( $v_ssl_ca != str_replace("\r\n", "\n", $_POST['v_ssl_ca']))) { |
| 190 | + exec ('mktemp -d', $mktemp_output, $return_var); |
| 191 | + $tmpdir = $mktemp_output[0]; |
| 192 | + |
| 193 | + // Certificate |
| 194 | + if (!empty($_POST['v_ssl_crt'])) { |
| 195 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
| 196 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
| 197 | + fwrite($fp, "\n"); |
| 198 | + fclose($fp); |
| 199 | + } |
| 200 | + |
| 201 | + // Key |
| 202 | + if (!empty($_POST['v_ssl_key'])) { |
| 203 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
| 204 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
| 205 | + fwrite($fp, "\n"); |
| 206 | + fclose($fp); |
| 207 | + } |
| 208 | + |
| 209 | + // CA |
| 210 | + if (!empty($_POST['v_ssl_ca'])) { |
| 211 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
| 212 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
| 213 | + fwrite($fp, "\n"); |
| 214 | + fclose($fp); |
| 215 | + } |
| 216 | + |
| 217 | + exec (HESTIA_CMD."v-change-mail-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var); |
| 218 | + check_return_code($return_var,$output); |
| 219 | + unset($output); |
| 220 | + $restart_web = 'yes'; |
| 221 | + $restart_proxy = 'yes'; |
| 222 | + |
| 223 | + exec (HESTIA_CMD."v-list-mail-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var); |
| 224 | + $ssl_str = json_decode(implode('', $output), true); |
| 225 | + unset($output); |
| 226 | + $v_ssl_crt = $ssl_str[$v_domain]['CRT']; |
| 227 | + $v_ssl_key = $ssl_str[$v_domain]['KEY']; |
| 228 | + $v_ssl_ca = $ssl_str[$v_domain]['CA']; |
| 229 | + $v_ssl_subject = $ssl_str[$v_domain]['SUBJECT']; |
| 230 | + $v_ssl_aliases = $ssl_str[$v_domain]['ALIASES']; |
| 231 | + $v_ssl_not_before = $ssl_str[$v_domain]['NOT_BEFORE']; |
| 232 | + $v_ssl_not_after = $ssl_str[$v_domain]['NOT_AFTER']; |
| 233 | + $v_ssl_signature = $ssl_str[$v_domain]['SIGNATURE']; |
| 234 | + $v_ssl_pub_key = $ssl_str[$v_domain]['PUB_KEY']; |
| 235 | + $v_ssl_issuer = $ssl_str[$v_domain]['ISSUER']; |
| 236 | + |
| 237 | + // Cleanup certificate tempfiles |
| 238 | + if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
| 239 | + if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$_POST['v_domain'].".key"); |
| 240 | + if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
| 241 | + rmdir($tmpdir); |
| 242 | + } |
| 243 | + } |
| 244 | + |
| 245 | + // Delete Lets Encrypt support |
| 246 | + if (( $v_letsencrypt == 'yes' ) && (empty($_POST['v_letsencrypt'])) && (empty($_SESSION['error_msg']))) { |
| 247 | + exec (HESTIA_CMD."v-delete-letsencrypt-mail-domain ".$user." ".$v_domain." 'no'", $output, $return_var); |
| 248 | + check_return_code($return_var,$output); |
| 249 | + unset($output); |
| 250 | + $v_ssl_crt = ''; |
| 251 | + $v_ssl_key = ''; |
| 252 | + $v_ssl_ca = ''; |
| 253 | + $v_letsencrypt = 'no'; |
| 254 | + $v_letsencrypt_deleted = 'yes'; |
| 255 | + $v_ssl = 'no'; |
| 256 | + $restart_mail = 'yes'; |
| 257 | + } |
| 258 | + |
| 259 | + // Delete SSL certificate |
| 260 | + if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) { |
| 261 | + exec (HESTIA_CMD."v-delete-mail-domain-ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var); |
| 262 | + check_return_code($return_var,$output); |
| 263 | + unset($output); |
| 264 | + $v_ssl_crt = ''; |
| 265 | + $v_ssl_key = ''; |
| 266 | + $v_ssl_ca = ''; |
| 267 | + $v_ssl = 'no'; |
| 268 | + $restart_mail = 'yes'; |
| 269 | + } |
| 270 | + |
| 271 | + // Add Lets Encrypt support |
| 272 | + if ((!empty($_POST['v_ssl'])) && ( $v_letsencrypt == 'no' ) && (!empty($_POST['v_letsencrypt'])) && empty($_SESSION['error_msg'])) { |
| 273 | + $l_aliases = 'mail.' . $v_domain; |
| 274 | + exec (HESTIA_CMD."v-add-letsencrypt-mail-domain ".$user." ".$v_domain." '".$l_aliases."' 'no'", $output, $return_var); |
| 275 | + check_return_code($return_var,$output); |
| 276 | + unset($output); |
| 277 | + $v_letsencrypt = 'yes'; |
| 278 | + $v_ssl = 'yes'; |
| 279 | + $restart_mail = 'yes'; |
| 280 | + } |
| 281 | + |
| 282 | + // Add SSL certificate |
| 283 | + if (( $v_ssl == 'no' ) && (!empty($_POST['v_ssl'])) && (empty($v_letsencrypt_deleted)) && (empty($_SESSION['error_msg']))) { |
| 284 | + if (empty($_POST['v_ssl_crt'])) $errors[] = 'ssl certificate'; |
| 285 | + if (empty($_POST['v_ssl_key'])) $errors[] = 'ssl key'; |
| 286 | + if (!empty($errors[0])) { |
| 287 | + foreach ($errors as $i => $error) { |
| 288 | + if ( $i == 0 ) { |
| 289 | + $error_msg = $error; |
| 290 | + } else { |
| 291 | + $error_msg = $error_msg.", ".$error; |
| 292 | + } |
| 293 | + } |
| 294 | + $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg); |
| 295 | + } else { |
| 296 | + exec ('mktemp -d', $mktemp_output, $return_var); |
| 297 | + $tmpdir = $mktemp_output[0]; |
| 298 | + |
| 299 | + // Certificate |
| 300 | + if (!empty($_POST['v_ssl_crt'])) { |
| 301 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".crt", 'w'); |
| 302 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_crt'])); |
| 303 | + fclose($fp); |
| 304 | + } |
| 305 | + |
| 306 | + // Key |
| 307 | + if (!empty($_POST['v_ssl_key'])) { |
| 308 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".key", 'w'); |
| 309 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_key'])); |
| 310 | + fclose($fp); |
| 311 | + } |
| 312 | + |
| 313 | + // CA |
| 314 | + if (!empty($_POST['v_ssl_ca'])) { |
| 315 | + $fp = fopen($tmpdir."/".$_POST['v_domain'].".ca", 'w'); |
| 316 | + fwrite($fp, str_replace("\r\n", "\n", $_POST['v_ssl_ca'])); |
| 317 | + fclose($fp); |
| 318 | + } |
| 319 | + exec (HESTIA_CMD."v-add-mail-domain-ssl ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var); |
| 320 | + check_return_code($return_var,$output); |
| 321 | + unset($output); |
| 322 | + $v_ssl = 'yes'; |
| 323 | + $restart_web = 'yes'; |
| 324 | + $restart_proxy = 'yes'; |
| 325 | + |
| 326 | + exec (HESTIA_CMD."v-list-mail-domain-ssl ".$user." '".$v_domain."' json", $output, $return_var); |
| 327 | + $ssl_str = json_decode(implode('', $output), true); |
| 328 | + unset($output); |
| 329 | + $v_ssl_crt = $ssl_str[$_POST['v_domain']]['CRT']; |
| 330 | + $v_ssl_key = $ssl_str[$_POST['v_domain']]['KEY']; |
| 331 | + $v_ssl_ca = $ssl_str[$_POST['v_domain']]['CA']; |
| 332 | + $v_ssl_subject = $ssl_str[$_POST['v_domain']]['SUBJECT']; |
| 333 | + $v_ssl_aliases = $ssl_str[$_POST['v_domain']]['ALIASES']; |
| 334 | + $v_ssl_not_before = $ssl_str[$_POST['v_domain']]['NOT_BEFORE']; |
| 335 | + $v_ssl_not_after = $ssl_str[$_POST['v_domain']]['NOT_AFTER']; |
| 336 | + $v_ssl_signature = $ssl_str[$_POST['v_domain']]['SIGNATURE']; |
| 337 | + $v_ssl_pub_key = $ssl_str[$_POST['v_domain']]['PUB_KEY']; |
| 338 | + $v_ssl_issuer = $ssl_str[$_POST['v_domain']]['ISSUER']; |
| 339 | + |
| 340 | + // Cleanup certificate tempfiles |
| 341 | + if (!empty($_POST['v_ssl_crt'])) unlink($tmpdir."/".$_POST['v_domain'].".crt"); |
| 342 | + if (!empty($_POST['v_ssl_key'])) unlink($tmpdir."/".$_POST['v_domain'].".key"); |
| 343 | + if (!empty($_POST['v_ssl_ca'])) unlink($tmpdir."/".$_POST['v_domain'].".ca"); |
| 344 | + rmdir($tmpdir); |
| 345 | + } |
| 346 | + } |
167 | 347 |
|
168 | 348 | // Set success message |
169 | 349 | if (empty($_SESSION['error_msg'])) { |
|
0 commit comments