Uname:Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64

403WebShell
403Webshell
Server IP : 188.114.97.2  /  Your IP : 104.23.197.230
Web Server : Apache/2.4.59 (Debian)
System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64
User : edlftp ( 1002)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/nicolasj/www/sms.formationlangues.be/application/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/nicolasj/www/sms.formationlangues.be/application/models/Email_model.php
<?php

if (! defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class Email_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('generator');
        $this->load->database();
        $this->load->model('security_model');
        $this->load->model('users_model');
        $this->load->model('notification_model');
    }

    public function account_opening_email($lang = '', $account_type = '', $name='', $email = '', $password = '', $user_id='')
    {
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;

        $data = array(
            "name" => $name,
            "user" => $this->crud_model->get_user_email($user_id),
            "password" => $password,
            "system_name" => $system_name
        );


        if($account_type == "admin" || $account_type == "teacher") {
            $sub = "Account Creation";
            $body = $this->load->view('email/'.$lang.'/teacher/account_creation.php', $data, true);
        } elseif ($account_type == "invited") {
            $sub = "Account Creation";
            $body = $this->load->view('email/'.$lang.'/teacher/account_creation.php', $data, true);

        }
        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->log_message($user_id, $email, $email_sub, $email_msg, "1");
        $this->do_email($email_msg, $email_sub, $email_to, "[email protected]");
        return true;
    }

    public function password_reset_email($lang = '', $account_type = '', $name='', $email = '', $password = '', $user_id='')
    {
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;

        $data = array(
            "name" => $name,
            "user" => $email,
            "password" => $password,
            "system_name" => $system_name
        );


        $sub = "Password Reset";
        if($lang != "en" || $lang != "fr" || $lang != "nl") {
            $lang = "en";
        }
        $body = $this->load->view('email/'.$lang.'/general/reset.php', $data, true);

        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->do_email($email_msg, $email_sub, $email_to, "[email protected]");
        return true;

    }

    public function password_notification_email($lang = '', $password = '', $name = '', $email = '', $user_id='')
    {
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;

        $data = array(
            "name" => $name,
            "user" => $email,
            "password" => $password,
            "system_name" => $system_name
        );

        //return 'email/'.$lang.'/general/reset.php';
        $sub = "Password Notification";
        $body = $this->load->view('email/'.$lang.'/general/reset.php', $data, true);

        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->do_email($email_msg, $email_sub, $email_to, "[email protected]");
        return true;
    }


    public function invoice_request_email($lang = '', $link = '', $name = '', $email = '', $user_id='')
    {
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;

        $data = array(
            "name" => $name,
            "user" => $email,
            "paymentLink" => $link,
            "system_name" => $system_name
        );

        //return 'email/'.$lang.'/invoice/request.php';
        $sub = "Payment Notification";
        $body = $this->load->view('email/'.$lang.'/invoice/request.php', $data, true);

        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->do_email($email_msg, $email_sub, $email_to);
        return true;
    }
    public function invoice_request_email_custom($lang = '', $link = '', $name = '', $email = '', $message = '', $user_id='')
    {
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;

        $data = array(
            "name" => $name,
            "user" => $email,
            "paymentLink" => $link,
            "system_name" => $system_name,
            "message" => $message
        );

        //return 'email/'.$lang.'/invoice/request.php';
        $sub = "re-registration proposal";
        $body = $this->load->view('email/'.$lang.'/invoice/request_custom.php', $data, true);

        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->do_email($email_msg, $email_sub, $email_to);
        return true;
    }

    public function invoice_success_email($lang = '', $token = '', $id = '', $name = '', $email = '', $user_id='')
    {
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;

        $data = array(
            "name" => $name,
            "user" => $email,
            "id" => $id,
            "token" => $token,
            "system_name" => $system_name
        );

        //return 'email/'.$lang.'/invoice/request.php';
        $sub = "Payment Notification";
        $body = $this->load->view('email/'.$lang.'/invoice/success.php', $data, true);

        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->do_email($email_msg, $email_sub, $email_to);
        return true;
    }

    public function invoice_email($lang = '', $token = '', $id = '', $name = '', $email = '', $user_id='')
    {
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;

        $data = array(
            "name" => $name,
            "user" => $email,
            "id" => $id,
            "token" => $token,
            "system_name" => $system_name
        );

        //return 'email/'.$lang.'/invoice/request.php';
        $sub = "Payment Notification";
        $body = $this->load->view('email/'.$lang.'/invoice/invoice.php', $data, true);

        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->do_email($email_msg, $email_sub, $email_to);
        return true;
    }

    public function credit_note_email($lang = '', $token = '', $id = '', $name = '', $email = '', $user_id='')
    {
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;

        $data = array(
            "name" => $name,
            "user" => $email,
            "id" => $id,
            "token" => $token,
            "system_name" => $system_name
        );

        //return 'email/'.$lang.'/invoice/request.php';
        $sub = "Payment Notification";
        $body = $this->load->view('email/'.$lang.'/invoice/credit_note.php', $data, true);

        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->do_email($email_msg, $email_sub, $email_to);
        return true;
    }

    public function contact_message_email($email_from, $email_to, $email_message)
    {
        $email_sub = "Message from School Website";
        $this->do_email($email_message, $email_sub, $email_to, $email_from);
    }

    public function course_briefing($admin_id, $course_id)
    {
        //return 1;
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;
        $from = $this->mbox_model->generate_mail($course_id);//$this->notification_model->get_notification_sender_mail($sender,$course_id);

        $email = $this->get_master_email($admin_id, $type);

        $course = $this->crud_model->get_course_name($course_id);
        $name_formated = str_replace(' ', '', strtolower(preg_replace('/[\W]/', '', $course)));
        $course_hook = substr($name_formated, 0, 9)."-".$course_id;

        $course_data = $this->crud_model->get_course_info($course_id);


        $data = array(
            "course_id" => $course_id,
            "course_name" => $course,
            "course_hook" => $course_hook,
            "course_data" => $course_data,
            "start" => $this->crud_model->get_course_start($course_id),
            "end" => $this->crud_model->get_course_end($course_id),
            "total" => $this->crud_model->get_course_hours_total($course_id),
            "teachers" => $this->crud_model->get_course_teachers($course_id),
            "students_nb" => $this->crud_model->get_students_count($course_id),
            "system_name" => $system_name,
            "lang" => $lang,
        );


        $sub = '['.$course_hook.']  Course Brienfing -  '.$course.'';

        $lang = "en";
        $body = $this->load->view('email/'.$lang.'/notification/briefing.php', $data, true);

        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->do_email($email_msg, $email_sub, $email_to, $from, null, 'True');
        return $data;//true;
    }

    public function presence_notification_email($student_id, $lesson_id, $course_id, $presence, $lang, $sender = "[email protected]", $type)
    {
        //return 1;
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;
        $from = $sender;//$this->notification_model->get_notification_sender_mail($sender,$course_id);

        $email = $this->get_master_email($student_id, $type);
        $token = $this->security_model->generateToken($lesson_id.$student_id);
        //$email = "[email protected]"; // debug
        //return $this->crud_model->get_lesson_info($lesson_id);
        $course = $this->crud_model->get_course_name($course_id);
        $lesson = $this->crud_model->get_lesson_info($lesson_id);
        $name = $this->crud_model->get_student_name($student_id);

        $data = array(
            "name" => $name,
            "email" => $email,
            "token" => $token,
            "lesson_id" => $lesson_id,
            "student_id" => $student_id,
            "presence" => $presence,
            "lesson" => $lesson,
            "course" => $course,
            "system_name" => $system_name,
            "lang" => $lang,
            "debug" => $type
        );


        $sub = 'Presence Notification -  ['.$course.']-['.$name.']';
        //$lang = "en";//debug
        $body = $this->load->view('email/'.$lang.'/notification/presence.php', $data, true);

        $email_msg 	= mb_convert_encoding($body, "UTF-8");
        $email_sub		=	$sub;
        $email_to		=	$email;

        $this->do_email($email_msg, $email_sub, $email_to, $from);
        return $data;//true;
    }

    public function course_start_notification_email($student_id, $lesson_id, $course_id, $lang, $sender = "1", $type)
    {
        //return 1;
        $system_name	=	$this->db->get_where('settings', array('type' => 'system_name'))->row()->description;
        $from = $sender;//$this->notification_model->get_notification_sender_mail($sender,$course_id);

        $email = $this->get_master_email($student_id, $type);

        $course = $this->crud_model->get_course_name($course_id);
        $lesson = $this->crud_model->get_lesson_info($lesson_id);
        $name = $this->crud_model->get_student_name($student_id);

        $data = array(
            "name" => $name,
            "email" => $email,
            "lesson_id" => $lesson_id,
            "student_id" => $student_id,
            "lesson" => $lesson,
            "course" => $course,
            "system_name" => $system_name,
            "lang" => $lang,
            "debug" => $type
        );

        $sub = 'Course Notification -  ['.$course.']-['.$name.']';
        //$lang = "en";//debug
        $body = $this->load->view('email/'.$lang.'/notification/course_start.php', $data, true);

        $email_msg = mb_convert_encoding($body, "UTF-8");
        $email_sub = $sub;
        $email_to  = $email;

        $this->do_email($email_msg, $email_sub, $email_to, $from);
        return $data;//true;
    }

    /**
     * Basic mail sender
     *
     * @param string $msg
     * @param string $sub
     * @param string $to
     * @param string $from
     * @param string|null $course_name
     * @param string|null $group_id
     * @return boolean
     */
    public function send_mail(string $msg, string $sub, string $to, string $from, string $course_name = null, string $group_id = null) : bool
    {
        $domain = substr($to, strpos($to, '@') + 1);
        if($domain == "ecoledelangues.be" && $to != "[email protected]") {
            return false;
        }

        $this->load->library('email');
        $this->email->initialize($this->get_email_config());

        $system_name = $this->db->get_where('settings', array('type' => 'system_name'))->row()->description;
        if($from == null) {
            $from =	$this->db->get_where('settings', array('type' => 'system_email'))->row()->description;
        }

        if($option!="null" && $option!="" && $option!=" ") {
            $this->email->from($from, "[".$option."]".$system_name);
        } else {
            $this->email->from($from, $system_name);
        }

        $this->email->to($to);
        //track the id
        if(substr($from, 0, 4) == 'edl-') {
            //add the id for tracking
            $id = substr($from, 0, 13);
            $sub = "[" . $id . "] " . $sub;

            $this->email->bcc($from);
        } elseif($bcc == true) {
            $this->email->bcc($from);
        } elseif($from == "[email protected]") {
            $this->email->cc('[email protected]');
            $this->email->reply_to('[email protected]', 'info');
            $this->email->bcc($from);
        } elseif($from == "[email protected]") {
            $this->email->bcc($from);
        } elseif($from == "[email protected]") {
            $sub = "[Invoice] ".$sub;
            $this->email->cc('[email protected]');
            $this->email->reply_to('[email protected]', 'compta');
            $this->email->bcc($from);
        }

        $this->email->subject($sub);
        $this->email->message($msg);
        if ($this->email->send()) {
            $this->log_mail($from, $to, $sub, $group_id);
        }

        return true;
    }

    /**
     * Log a mail 
     *
     * @param string $from
     * @param string $to
     * @param string $subject
     * @return boolean
     */
    public function log_mail(string $from, string $to, string $subject, string $group_id = null) : bool 
    {
        try {
            $user = $this->users_model->get_entry_by(['email' => $to]);

            return $this->db->insert('mail_log', [
                'from_mail'   => $from,
                'to_mail'     => $to,
                'subject'     => $subject,
                'user_id'     => $user ? $user->user_id : null,
                'full_name'   => $user ? strtoupper($user->last_name) . ' ' . ucwords($user->first_name) : null,
                'sended_at'   => date('Y-m-d H:i:s'),
                'group_id'    => $group_id
            ]);   
        } catch (\Exception $e) {
            return false;
        }
    }

    /**
     * Send notification mail
     *
     * @param string $tpl
     * @param string $sub
     * @param string $to
     * @param string $from
     * @param string|null $bcc
     * @return boolean
     */
    public function send_notification_mail(string $tpl, string $sub, string $to, string $from, string $bcc = null): bool
    {
        $this->load->library('email');
        // TODO: Check if required (this one erase default configuration)
        $this->email->initialize($this->get_email_config());

        $this->email->from($from);
        $this->email->to($to);
        $this->email->subject($sub);
        $this->email->message($tpl);
        if ($bcc && filter_var($bcc, FILTER_VALIDATE_EMAIL)) {
            $this->email->bcc($bcc);
        }

        return $this->email->send();
    }

    public function do_email($msg=null, $sub=null, $to=null, $from=null, $option = null, $bcc = false)
    {
        //$to = "[email protected]";
        $domain = substr($to, strpos($to, '@') + 1);
        if($domain == "ecoledelangues.be" && $to != "[email protected]") {
            return false;
            //prevent lost mails
        }

        $this->load->library('email');
        $this->email->initialize($this->get_email_config());

        $system_name = $this->db->get_where('settings', array('type' => 'system_name'))->row()->description;
        if($from == null) {
            $from = $this->db->get_where('settings', array('type' => 'system_email'))->row()->description;
        }

        if($option!="null" && $option!="" && $option!=" ") {
            $this->email->from($from, "[".$option."]".$system_name);
        } else {
            $this->email->from($from, $system_name);
        }

        //	$this->email->from($from, $system_name);

        $this->email->to($to);
        //track the id
        if(substr($from, 0, 4) == 'edl-') {
            //add the id for tracking
            $id = substr($from, 0, 13);
            $sub = "[".$id."] ".$sub;
            //hook the ccc
            $this->email->bcc($from);
        } elseif($bcc == true) {
            $this->email->bcc($from);
        } elseif($from == "[email protected]") {
            //add to notif ccc
            $sub = "[notification] ".$sub;
            //hook the ccc
            $this->email->bcc($from);
        } elseif($from == "[email protected]") {
            //add to notif ccc
            $sub = "[notification] ".$sub;
            //hook the ccc
            $this->email->bcc($from);
        } else {
        }

        $this->email->subject($sub);

        $footer = "<br /><br /><br /><br /><br /><br /><br />";
        $footer = $footer ."<center><div class='col-sm-6 float-left'><img src='https://formationlangues.be/wp-content/uploads/2019/03/logo_newsletter_02-min.png'/></div>";
        $footer = $footer ."<div class='col-sm-6 float-right'><p>[email protected]</p><p>EcoleDeLangues.be</p><p>56, rue Henri Chomé | 1030 Bruxelles</p></div></center>";

        $msg	=	$msg.$footer;//"<br /><br /><br /><br /><br /><br /><br /><hr /><center><a href=\"http://codes.solutions/\"> 2019 SMS | Beta 1.3. Improved by Codes.Solutions</a></center>";
        $this->email->message($msg);

        $this->email->send();

        return $this->email->print_debugger();
    }

    public function log_message($user, $mail, $subject, $text, $type)
    {
        $date_otd = date('Y-m-d');
        $sql = array(
            'User_ID' => $user,
            'User_Email' => $mail,
            'Message_Subject' => $subject,
            'Message_Text' => $text,
            'Message_date' => $date_otd
        );
        $this->db->insert('message_message', $this->crud_model->cleanArray($sql));
        $id_msg = $this->db->insert_id();

        $sql2 = array(
            'Type_ID' => $type,
            'Message_ID' => $id_msg
        );

        $this->db->insert('message', $this->crud_model->cleanArray($sql2));
    }

    public function get_master_email($student_id, $type = "main")
    {
        $parent = $this->crud_model->get_child_parent($student_id);
        //return "ici:".$parent;
        if($parent == '0' or $parent == null or $parent == null or $parent == "") {

            if($type == "main") {
                return  $this->crud_model->get_user_email($student_id);
            } else {
                return  $this->crud_model->get_user_email_notification($student_id);
            }

        } else {
            //foreach ($parent as $key => $u) {
            if($type == "main") {
                $mail = $this->crud_model->get_user_email($parent);
                if($mail != null and $mail != null and $mail != "") {
                    return $mail;
                }
            } else {
                $mail = $this->crud_model->get_user_email_notification($parent);
                if($mail != null and $mail != null and $mail != "") {
                    return $mail;
                }
            }
            //}
        }
        return  $this->crud_model->get_user_email($student_id);
    }

    private function get_email_config(): array
    {
        $config = [
            'useragent' => "CodeIgniter",
            'mailpath' => '/usr/bin/sendmail',
            'smtp_host' => (ENVIRONMENT != 'development' ? 'smtp.sendgrid.net' : 'sms-smtp'),
            'smtp_port' => (ENVIRONMENT != 'development' ? '587' : '1025'),            
            'mailtype' => 'html',
            'charset' => 'utf-8',
            'newline' => "\r\n",
            'crlf' => "\r\n",
            'wordwrap' => true,
            'protocol' => 'smtp'
        ];

        if (ENVIRONMENT != 'development') {
            $config['smtp_user'] = 'apikey';
            $config['smtp_pass'] ='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';
        }

        return $config;
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit