mail-wrapper.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/local/hestia/php/bin/php
  2. <?php
  3. if (empty($argv[1])) {
  4. echo "ERROR: not enough arguments\n";
  5. echo "USAGE: mail-wrapper.php -s SUBJECT EMAIL [NOTIFY]\n";
  6. exit(3);
  7. }
  8. $options = getopt("s:f:");
  9. if ((!empty($argv[4])) && ($argv[4] == 'no')) {
  10. exit;
  11. }
  12. define('NO_AUTH_REQUIRED',true);
  13. include("/usr/local/hestia/web/inc/main.php");
  14. // Set system language
  15. exec (HESTIA_CMD . "v-list-sys-config json", $output, $return_var);
  16. $data = json_decode(implode('', $output), true);
  17. if (!empty( $data['config']['LANGUAGE'])) {
  18. $_SESSION['language'] = $data['config']['LANGUAGE'];
  19. } else {
  20. $_SESSION['language'] = 'en';
  21. }
  22. //define vars
  23. //make hostname detection a bit more feature proof
  24. $hostname = (function():string{
  25. $badValues = array(false, null, 0, '', "localhost", "127.0.0.1", "::1", "0000:0000:0000:0000:0000:0000:0000:0001");
  26. $ret = gethostname();
  27. if(in_array($ret, $badValues, true)){
  28. throw new Exception('gethostname() failed');
  29. }
  30. $ret2 = gethostbyname($ret);
  31. if(in_array($ret2, $badValues, true)){
  32. return $ret;
  33. }
  34. $ret3 = gethostbyaddr($ret2);
  35. if(in_array($ret3, $badValues, true)){
  36. return $ret2;
  37. }
  38. return $ret3;
  39. })();
  40. $from = 'noreply@'.$hostname;
  41. $from_name = _('Hestia Control Panel');
  42. $to = $argv[3]."\n";
  43. $subject = $argv[2]."\n";
  44. $mailtext = file_get_contents("php://stdin");
  45. // Send email
  46. if ((!empty($to)) && (!empty($subject))) {
  47. send_email($to,$subject,$mailtext,$from, $from_name);
  48. }