Permits email to be sent using Mail, Sendmail, or SMTP.
Esempio n. 1
0
 function getMailer()
 {
     $this->ci->load->library('email');
     $Email = new CI_Email();
     $Email->initialize(array('protocol' => 'smtp', 'smtp_host' => 'infizi.com', 'smtp_user' => '*****@*****.**', 'smtp_pass' => 'Kb}v]w[t%.@&', 'smtp_port' => '26', 'mailtype' => 'html'));
     return $Email;
 }
Esempio n. 2
0
 /**
  * Constructor method
  * 
  * @return void
  */
 public function __construct($config = array())
 {
     parent::__construct($config);
     //set mail protocol
     $config['protocol'] = Settings::get('mail_protocol');
     //set a few config items (duh)
     $config['mailtype'] = "html";
     $config['charset'] = "utf-8";
     $config['crlf'] = Settings::get('mail_line_endings') ? "\r\n" : PHP_EOL;
     $config['newline'] = Settings::get('mail_line_endings') ? "\r\n" : PHP_EOL;
     //sendmail options
     if (Settings::get('mail_protocol') == 'sendmail') {
         if (Settings::get('mail_sendmail_path') == '') {
             //set a default
             $config['mailpath'] = '/usr/sbin/sendmail';
         } else {
             $config['mailpath'] = Settings::get('mail_sendmail_path');
         }
     }
     //smtp options
     if (Settings::get('mail_protocol') == 'smtp') {
         $config['smtp_host'] = Settings::get('mail_smtp_host');
         $config['smtp_user'] = Settings::get('mail_smtp_user');
         $config['smtp_pass'] = Settings::get('mail_smtp_pass');
         $config['smtp_port'] = Settings::get('mail_smtp_port');
     }
     $this->initialize($config);
 }
 /**
  * Constructor
  *
  */
 function __construct()
 {
     // Call the Email Constructor
     parent::__construct();
     // Create an instance to CI
     $this->CI =& get_instance();
     // Retrieve the email protocol
     $config['protocol'] = $this->CI->ClanCMS->get_setting('email_protocol');
     // Configure sendmail settings
     if ($config['protocol'] == 'sendmail') {
         // Check the sendmail path
         if ($this->CI->ClanCMS->get_setting('email_sendmail_path') == '') {
             // Set mail path
             $config['mailpath'] = '/usr/sbin/sendmail';
         } else {
             // Set mail path
             $config['mailpath'] = $this->CI->ClanCMS->get_setting('email_sendmail_path');
         }
     }
     // Configure smtp settings
     if ($config['protocol'] == 'smtp') {
         // Configure additional settings
         $config['smtp_host'] = $this->CI->ClanCMS->get_setting('email_smtp_host');
         $config['smtp_user'] = $this->CI->ClanCMS->get_setting('email_smtp_user');
         $config['smtp_pass'] = $this->CI->ClanCMS->get_setting('email_smtp_pass');
         $config['smtp_port'] = $this->CI->ClanCMS->get_setting('email_smtp_port');
         $config['smtp_timeout'] = '30';
         $config['charset'] = 'utf-8';
         $config['newline'] = "\r\n";
     }
     // Initialize settings
     $this->initialize($config);
 }
Esempio n. 4
0
 /**
  * Constructor method
  *
  * @access public
  * @return void
  */
 function __construct()
 {
     parent::__construct();
     $this->ci =& get_instance();
     //set mail protocol
     $config['protocol'] = $this->ci->settings->mail_protocol;
     //set a few config items (duh)
     $config['mailtype'] = 'html';
     $config['charset'] = 'utf-8';
     $config['crlf'] = '\\r\\n';
     $config['newline'] = '\\r\\n';
     //sendmail options
     if ($this->ci->settings->mail_protocol == 'sendmail') {
         if ($this->ci->settings->mail_sendmail_path == '') {
             //set a default
             $config['mailpath'] = '/usr/sbin/sendmail';
         } else {
             $config['mailpath'] = $this->ci->settings->mail_sendmail_path;
         }
     }
     //smtp options
     if ($this->ci->settings->mail_protocol == 'smtp') {
         $config['smtp_host'] = $this->ci->settings->mail_smtp_host;
         $config['smtp_user'] = $this->ci->settings->mail_smtp_user;
         $config['smtp_pass'] = $this->ci->settings->mail_smtp_pass;
         $config['smtp_port'] = $this->ci->settings->mail_smtp_port;
     }
     $this->initialize($config);
 }
Esempio n. 5
0
 /**
  *
  */
 function __construct()
 {
     date_default_timezone_set('Asia/Calcutta');
     $ci = CI::get_instance();
     $ci->load->Model('Email_settings/Mdl_email_settings');
     //load email settings model
     $smtp = $ci->Mdl_email_settings->toArray();
     //get object valeus in array
     $config = array();
     $config['protocol'] = 'smtp';
     $config['mailpath'] = '/usr/sbin/sendmail';
     $config['smtp_host'] = $smtp['smtp_host'];
     $config['smtp_pass'] = $smtp['smtp_pass'];
     // email's password    - set smtp values
     $config['smtp_user'] = $smtp['smtp_user'];
     $config['smtp_port'] = $smtp['smtp_port'];
     //gmail port 465 (ssl) and 587 (TSL) required
     $config['smtp_timeout'] = 10;
     //smtp timeout in seconds
     $config['wordwrap'] = TRUE;
     $config['wrapchars'] = 76;
     $config['mailtype'] = 'html';
     $config['charset'] = 'utf-8';
     $config['validate'] = TRUE;
     $config['priority'] = 3;
     $config['crif'] = "\r\n";
     $config['newline'] = "\r\n";
     $config['bcc_batch_mode'] = TRUE;
     $config['bcc_batch_size'] = 200;
     parent::__construct($config);
 }
 public function __construct(array $config = array())
 {
     parent::__construct($config);
     $this->CI =& get_instance();
     $this->CI->load->helper('file');
     $this->CI->load->model('Shared/Environment');
     $this->set_newline("\r\n");
 }
Esempio n. 7
0
 public function message($body, $parse_data = NULL)
 {
     if (!empty($parse_data)) {
         $body = $this->parse_template($body, $parse_data);
     }
     $body = $this->mailtype === 'html' ? $this->_build_html_mail($body) : strip_tags($body);
     return parent::message($body);
 }
Esempio n. 8
0
 /**
  * Send Email
  *
  * @access  public
  * @return  bool
  */
 public function send()
 {
     $result = parent::send();
     if ($result && $this->log_emails) {
         $this->_log_email_to_file();
     }
     return $result;
 }
 public function to($to)
 {
     // 이메일 주소를 변경
     $this->ci =& get_instance();
     $_to = $this->ci->config->item('dev_receive_email');
     $to = !$_to ? $to : $_to;
     return parent::to($to);
 }
Esempio n. 10
0
 /**
  * Constructor
  *
  * @access	public
  * @return	null
  */
 function MY_Email($init = TRUE)
 {
     parent::CI_Email();
     if ($init != TRUE) {
         return;
     }
     $this->first_init();
 }
Esempio n. 11
0
 function __construct($config = array())
 {
     parent::__construct($config);
     // If defined in the config set from/name
     if (isset($config['from'])) {
         $from = $config['from'];
         $name = isset($config['name']) ? $config['name'] : '';
         $this->from($from, $name);
     }
 }
Esempio n. 12
0
 /**
  * Constructor
  */
 function __construct($init = TRUE)
 {
     parent::__construct();
     if ($init != TRUE) {
         return;
     }
     // Make a local reference to the ExpressionEngine super object
     $this->EE =& get_instance();
     $this->EE_initialize();
 }
Esempio n. 13
0
 /**
  * Initialize the Email Data
  *
  * @access	public
  * @return	void
  */
 function clear($clear_attachments = FALSE)
 {
     // patch for bug # 7826
     // http://codeigniter.com/bug_tracker/bug/7826/
     if ($this->_get_protocol() == "smtp") {
         $this->_cc_array = array();
         $this->_bcc_array = array();
     }
     parent::clear($clear_attachments);
 }
Esempio n. 14
0
 protected function send_email($to, $subject, $text)
 {
     $this->load->library('email');
     $this->email->from(MAIL_FROM_ADDRESS, MAIL_FROM_NAME);
     $this->email->bcc($to);
     $this->email->bcc_batch_mode = true;
     $this->email->subject($subject);
     $this->email->message($text);
     $this->email->batch_bcc_send();
     return $this->email->send();
 }
Esempio n. 15
0
 /**
  * Initialize preferences
  *
  * @param	array
  * @return	CI_Email
  */
 public function initialize($config = array())
 {
     $this->CI =& get_instance();
     $config['protocol'] = $this->CI->config->item('protocol');
     $config['mailtype'] = $this->CI->config->item('mailtype');
     $config['smtp_host'] = $this->CI->config->item('smtp_host');
     $config['smtp_port'] = $this->CI->config->item('smtp_port');
     $config['smtp_user'] = $this->CI->config->item('smtp_user');
     $config['smtp_pass'] = $this->CI->config->item('smtp_pass');
     $config['newline'] = "\r\n";
     return parent::initialize($config);
 }
Esempio n. 16
0
function chron_scheduler_send_message($to, $from, $subject, $message)
{
    $em = new \CI_Email();
    $em->from($from);
    $em->to($to);
    $em->subject($subject);
    $em->message($message);
    return $em->send();
}
Esempio n. 17
0
function backup_email_log($to, $from, $subject)
{
    $tmp = function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : '/tmp';
    $email_options = array('useragent' => 'freepbx', 'protocol' => 'mail');
    $email = new CI_Email();
    $msg[] = _('BACKUP LOG ATTACHED');
    $email->from($from);
    $email->to($to);
    $email->subject(_('Backup Log:') . $subject);
    $email->message(implode("\n", $msg));
    $email->attach($tmp . '/backup.log');
    $email->send();
    unset($msg);
}
Esempio n. 18
0
 /**
  * Constructor - Sets Email Preferences
  *
  * The constructor can be passed an array of config values
  */
 function __construct()
 {
     parent::__construct();
     $this->CI =& get_instance();
     $this->protocol = $this->CI->config->item('email_protocal') ? $this->CI->config->item('email_protocal') : 'mail';
     // mail/sendmail/smtp
     $this->smtp_host = $this->CI->config->item('email_smtp_host');
     // SMTP Server. Example: mail.earthlink.net
     $this->smtp_user = $this->CI->config->item('email_smtp_user');
     // SMTP Username
     $this->smtp_pass = $this->CI->config->item('email_smtp_pass');
     // SMTP Password
     $this->smtp_port = $this->CI->config->item('email_smtp_port');
     // SMTP Port
     $this->smtp_crypto = $this->CI->config->item('email_smtp_crypto');
     // SMTP Encryption. Can be null, tls or ssl.
     $this->mailtype = 'html';
 }
Esempio n. 19
0
 function send($queue = FALSE)
 {
     $CI =& get_instance();
     if ($queue == FALSE) {
         // are we using Postmark?
         if (empty($this->_attach_name) and setting('postmark_api') != '' and function_exists('curl_init') and $this->_plaintext_from_email == $CI->config->item('site_email')) {
             // create to, cc, and bcc strings
             $to = is_array($this->_recipients) ? implode(', ', $this->_recipients) : $this->_recipients;
             $cc = is_array($this->_cc_array) ? implode(', ', $this->_cc_array) : $this->_cc_array;
             $bcc = is_array($this->_bcc_array) ? implode(', ', $this->_bcc_array) : $this->_bcc_array;
             // prepare data array
             $data = array();
             $data['Subject'] = $this->_plaintext_subject;
             $data['From'] = "{$this->_plaintext_from_name} <{$this->_plaintext_from_email}>";
             $data['To'] = $to;
             if (!empty($cc)) {
                 $data['Cc'] = $cc;
             }
             if (!empty($bcc)) {
                 $data['Bcc'] = $bcc;
             }
             if (strip_tags($this->_plaintext_body) != $this->_plaintext_body) {
                 $data['HtmlBody'] = $this->_plaintext_body;
             } else {
                 $data['TextBody'] = $this->_plaintext_body;
             }
             $encoded_data = json_encode($data);
             $headers = array('Accept: application/json', 'Content-Type: application/json', 'X-Postmark-Server-Token: ' . setting('postmark_api'));
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, 'http://api.postmarkapp.com/email');
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
             curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data);
             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
             $return = curl_exec($ch);
             if (curl_error($ch) != '') {
                 show_error(curl_error($ch));
             }
             $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
             if (intval($httpCode / 100) != 2) {
                 $message = json_decode($return)->Message;
                 show_error('Error while mailing. Postmark returned HTTP code ' . $httpCode . ' with message "' . $message . '"');
             }
         } else {
             // send using traditional means
             parent::send();
         }
     } else {
         // let's put this in the queue
         // do we have a mail queue folder?
         $mail_queue_folder = setting('path_writeable') . 'mail_queue';
         if (!file_exists($mail_queue_folder)) {
             $CI->settings_model->make_writeable_folder($mail_queue_folder, TRUE);
         }
         // if this body is the same as the last,
         // then the body file doesn't need to be regenerated
         if (empty($this->_previous_body) or $this->_plaintext_body != $this->_previous_body) {
             // create the file
             if (!function_exists('write_file')) {
                 $CI->load->helper('file');
             }
             $body_file = md5($this->_plaintext_body) . '.email';
             write_file($mail_queue_folder . '/' . $body_file, $this->_plaintext_body);
             $this->_previous_body = $this->_plaintext_body;
             $this->_previous_body_file = $body_file;
         } else {
             $body_file = $this->_previous_body_file;
         }
         if (is_array($this->_recipients)) {
             $to = implode(', ', $this->_recipients);
         } else {
             $to = $this->_recipients;
         }
         $CI->db->insert('mail_queue', array('`to`' => $to, '`from_name`' => $this->_plaintext_from_name, '`from_email`' => $this->_plaintext_from_email, '`subject`' => $this->_plaintext_subject, '`body`' => $body_file, '`date`' => date('Y-m-d H:i:s'), '`wordwrap`' => $this->wordwrap == TRUE ? '1' : '0', '`is_html`' => $this->mailtype == 'html' ? '1' : '0'));
         unset($CI);
         return TRUE;
     }
 }
Esempio n. 20
0
/** FINALIZE PRINT TASK 
 * 
 * @param $tid - TASK ID
 * @param $status - TASK STATUS (STOPPED - PERFORMED)
 * 
 **/
function finalize_print($tid, $status)
{
    //global $log;
    //$log->info('Task #'.$tid.' print '.$status);
    //$log->info('Task #'.$tid.' start finalizing');
    //LOAD DB
    $db = new Database();
    //GET TASK
    $task = $db->query('select * from sys_tasks where id=' . $tid);
    $reset = false;
    //CHECK IF TASK WAS ALREARDY FINALIZED
    if ($task['status'] == 'stopped' || $task['status'] == 'performed') {
        //$log->info('Task #'.$tid.' already finalized. Exit');
        return;
    }
    //GET TASK ATTRIBUTES
    $attributes = json_decode($task['attributes'], TRUE);
    $print_type = $attributes['print_type'];
    if ($status == 'stopped' && $print_type == 'additive') {
        //IF % PROGRESS IS < 0.5 FOR SECURITY REASON I RESET THE BOARD CONTROLLER
        $monitor = json_decode(file_get_contents($attributes['monitor']), TRUE);
        $percent = $monitor['print']['stats']['percent'];
        if ($percent < 0.2) {
            /** FORCE RESET CONTROLLER */
            $_command = 'sudo python ' . PYTHON_PATH . 'force_reset.py';
            shell_exec($_command);
            $reset = true;
            //$log->info('Task #'.$tid.' reset controller');
        }
    }
    //GET TYPE OF FILE (ADDITIVE OR SUBTRACTIVE) FOR ENDING MACRO
    $file = $db->query('select * from sys_files where id=' . $attributes['id_file']);
    //UPDATE TASK
    update_task($tid, $status);
    $_macro_end_print_response = TEMP_PATH . 'macro_response';
    $_macro_end_print_trace = TEMP_PATH . 'macro_trace';
    /*
    if(($file['print_type'] == 'additive') && !$reset){
    	echo 'sudo python '.PYTHON_PATH.'gmacro.py end_print_additive_safe_zone '.$_macro_end_print_trace.' '.$_macro_end_print_response.' > /dev/null &';
    	shell_exec('sudo python '.PYTHON_PATH.'gmacro.py end_print_additive_safe_zone '.$_macro_end_print_trace.' '.$_macro_end_print_response.' > /dev/null &');
    }
    */
    $end_macro = $file['print_type'] == 'subtractive' ? 'end_print_subtractive' : 'end_print_additive';
    write_file($_macro_end_print_trace, '', 'w');
    chmod($_macro_end_print_trace, 0777);
    write_file($_macro_end_print_response, '', 'w');
    chmod($_macro_end_print_response, 0777);
    //EXEC END MACRO
    shell_exec('sudo python ' . PYTHON_PATH . 'gmacro.py ' . $end_macro . ' ' . $_macro_end_print_trace . ' ' . $_macro_end_print_response . ' > /dev/null &');
    //$log->info('Task #'.$tid.' end macro: '.$end_macro);
    sleep(2);
    shell_exec('sudo kill ' . $attributes['pid']);
    // SEND MAIL
    if (isset($attributes['mail']) && $attributes['mail'] == 1 && $status == 'peformed') {
        $user = $db->query('select * from sys_user where id=' . $task['user']);
        // CREATE IMAGE TO SEND
        write_file($attributes['folder'] . 'print.jpg', '', 'w');
        chmod($attributes['folder'] . 'print.jpg', 0777);
        // TAKE PICTURE
        shell_exec('sudo raspistill -hf -vf -rot 90  --exposure off -awb sun -ISO 400 -w 768 -h 1024 -o ' . $attributes['folder'] . 'print.jpg' . '  -t 0');
        $email = new CI_Email();
        $config['mailtype'] = 'html';
        $email->initialize($config);
        $email->from('*****@*****.**', 'Your Personal Fabricator - Fabtotum');
        $email->to($user['email']);
        // ATTACH
        $email->attach($attributes['folder'] . 'print.jpg');
        $email->subject('Your print is finished');
        $message = 'Dear <strong>' . ucfirst($user['first_name']) . '</strong>,<br>i want to inform you that the print is finished right now';
        $email->message($message);
        if (!$email->send()) {
            //$log->error('Task #'.$tid.' mail sent to '.$user['email']);
        } else {
            //$log->info('Task #'.$tid.' mail sent to '.$user['email']);
        }
    }
    $db->close();
    //WAIT FOR THE UI TO FINALIZE THE PROCESS
    //sleep(7);
    //REMOVE ALL TEMPORARY FILES
    shell_exec('sudo rm -rf ' . $attributes['folder']);
    //$log->info('Task #'.$tid.' end finalizing');
}
 public function send($auto_clear = true)
 {
     $auto_clear = !empty($auto_clear);
     if ($this->mailer_engine == 'phpmailer') {
         if ($this->mailtype == 'html') {
             // Modified by Ivan Tcholakov, 01-AUG-2015.
             // See https://github.com/ivantcholakov/codeigniter-phpmailer/issues/8
             //$this->phpmailer->AltBody = $this->_get_alt_message();
             $this->phpmailer->AltBody = str_replace(array('{unwrap}', '{/unwrap}'), '', $this->_get_alt_message());
             //
         }
         $result = (bool) $this->phpmailer->send();
         if ($result) {
             $this->_set_error_message('lang:email_sent', $this->_get_protocol());
             if ($auto_clear) {
                 $this->clear();
             }
         } else {
             $this->_set_error_message($this->phpmailer->ErrorInfo);
         }
     } else {
         if ($this->_is_ci_3) {
             $result = parent::send($auto_clear);
         } else {
             $result = parent::send();
         }
     }
     return $result;
 }
Esempio n. 22
0
 protected function _get_alt_message()
 {
     $generate_alt_message = empty($this->alt_message);
     if ($generate_alt_message) {
         $protect_body = $this->_body;
         $html = str_get_html($this->_body, true, true, DEFAULT_TARGET_CHARSET, false);
         foreach ($html->find('a') as $a_tag) {
             if ($a_tag->plaintext != $a_tag->href) {
                 $a_tag_clone = clone $a_tag;
                 $a_tag_clone->innertext = $a_tag_clone->href;
                 $new_a_tag = $a_tag->innertext . '[' . $a_tag_clone . ']';
                 $a_tag->outertext = $new_a_tag;
                 unset($a_tag_clone);
             }
         }
         $this->_body = $html->__toString();
     }
     $output = parent::_get_alt_message();
     if ($generate_alt_message) {
         $output = html_entity_decode($output);
         $this->_body = $protect_body;
     }
     return $output;
 }
Esempio n. 23
0
 public function send($auto_clear = true)
 {
     $auto_clear = !empty($auto_clear);
     if ($this->mailer_engine == 'phpmailer') {
         if ($this->mailtype == 'html') {
             $this->phpmailer->AltBody = $this->_get_alt_message();
         }
         $result = (bool) $this->phpmailer->send();
         if ($result) {
             $this->_set_error_message('lang:email_sent', $this->_get_protocol());
             if ($auto_clear) {
                 $this->clear();
             }
         } else {
             $this->_set_error_message($this->phpmailer->ErrorInfo);
         }
     } else {
         if ($this->_is_ci_3) {
             $result = parent::send($auto_clear);
         } else {
             $result = parent::send();
         }
     }
     return $result;
 }
Esempio n. 24
0
 * This is meant for when using external packaging systems (eg, deb or rpm) to manage
 * modules. Package maintainers should set AMPEXTERNPACKAGES to true in /etc/amportal.conf.
 * Optionally, the other way is to remove the below lines, and instead just define
 * EXTERNAL_PACKAGE_MANAGEMENT as 1. This prevents changing the setting from amportal.conf.
 */
if (!isset($amp_conf['AMPEXTERNPACKAGES']) || $amp_conf['AMPEXTERNPACKAGES'] != 'true') {
    define('EXTERNAL_PACKAGE_MANAGEMENT', 0);
} else {
    define('EXTERNAL_PACKAGE_MANAGEMENT', 1);
}
$modulef = module_functions::create();
// Handle the ajax post back of an update online updates email array and status
//
if ($quietmode && isset($_REQUEST['update_email'])) {
    $update_email = $_REQUEST['update_email'];
    $ci = new CI_Email();
    if (!$ci->valid_email($update_email) && $update_email) {
        $json_array['status'] = _("Invalid email address") . ' : ' . $update_email;
    } else {
        $cm = cronmanager::create($db);
        $cm->save_email($update_email);
        $cm->set_machineid($_REQUEST['machine_id']);
        $json_array['status'] = true;
    }
    header("Content-type: application/json");
    echo json_encode($json_array);
    exit;
}
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
global $active_repos;
$loc_domain = 'amp';
Esempio n. 25
0
 function __construct()
 {
     parent::__construct();
 }
Esempio n. 26
0
 /**
  * Overrides the CI_Email subject function because it seems to set the
  * subject in the _headers property array instead of the _subject property.
  *
  * @param	string		the email subject
  * @return	Postmark
  */
 public function subject($subject)
 {
     parent::subject($subject);
     $this->_subject = $subject;
     return $this;
 }
Esempio n. 27
0
 /**
  * Send an email to a user
  * @param int $id      The user ID
  * @param string $subject The email subject
  * @param string $body    The email body
  */
 public function sendEmail($id, $subject, $body)
 {
     $user = $this->getUserByID($id);
     if (empty($user) || empty($user['email'])) {
         return false;
     }
     $email_options = array('useragent' => $this->brand, 'protocol' => 'mail');
     $email = new \CI_Email();
     //TODO: Stop gap until sysadmin becomes a full class
     if (!function_exists('sysadmin_get_storage_email') && $this->FreePBX->Modules->checkStatus('sysadmin') && file_exists($this->FreePBX->Config()->get('AMPWEBROOT') . '/admin/modules/sysadmin/functions.inc.php')) {
         include $this->FreePBX->Config()->get('AMPWEBROOT') . '/admin/modules/sysadmin/functions.inc.php';
     }
     $femail = $this->FreePBX->Config()->get('AMPUSERMANEMAILFROM');
     if (function_exists('sysadmin_get_storage_email')) {
         $emails = sysadmin_get_storage_email();
         if (!empty($emails['fromemail']) && filter_var($emails['fromemail'], FILTER_VALIDATE_EMAIL)) {
             $femail = $emails['fromemail'];
         }
     }
     $from = !empty($femail) ? $femail : get_current_user() . '@' . gethostname();
     $email->from($from);
     $email->to($user['email']);
     $email->subject($subject);
     $email->message($body);
     $email->send();
 }
Esempio n. 28
0
 /**
  * Support PHP4...
  */
 function MY_Email()
 {
     parent::CI_Email();
 }
Esempio n. 29
0
 function __construct()
 {
     parent::__construct();
     $CI =& get_instance();
 }
Esempio n. 30
-1
 function store_backup()
 {
     foreach ($this->b['storage_servers'] as $s) {
         $s = $this->s[$s];
         switch ($s['type']) {
             case 'local':
                 $path = backup__($s['path']) . '/' . $this->b['_dirname'];
                 //ensure directory structure
                 if (!is_dir($path)) {
                     mkdir($path, 0755, true);
                 }
                 //would rather use the native copy() here, but by defualt
                 //php doesnt support files > 2GB
                 //see here for a posible solution:
                 //http://ca3.php.net/manual/en/function.fopen.php#37791
                 $cmd[] = fpbx_which('cp');
                 $cmd[] = $this->b['_tmpfile'];
                 $cmd[] = $path . '/' . $this->b['_file'] . '.tgz';
                 exec(implode(' ', $cmd), $error, $status);
                 unset($cmd, $error);
                 if ($status !== 0) {
                     $this->b['error'] = 'Error copying ' . $this->b['_tmpfile'] . ' to ' . $path . '/' . $this->b['_file'] . '.tgz: ' . $error;
                     backup_log($this->b['error']);
                 }
                 //run maintenance on the directory
                 $this->maintenance($s['type'], $s);
                 break;
             case 'email':
                 //TODO: set agent to something informative, including fpbx & backup versions
                 $email_options = array('useragent' => 'freepbx', 'protocol' => 'mail');
                 $email = new \CI_Email();
                 $from = $this->amp_conf['AMPBACKUPEMAILFROM'] ? $this->amp_conf['AMPBACKUPEMAILFROM'] : '*****@*****.**';
                 $msg[] = _('Name') . ': ' . $this->b['name'];
                 $msg[] = _('Created') . ': ' . date('r', $this->b['_ctime']);
                 $msg[] = _('Files') . ': ' . $this->manifest['file_count'];
                 $msg[] = _('Mysql Db\'s') . ': ' . $this->manifest['mysql_count'];
                 $msg[] = _('astDb\'s') . ': ' . $this->manifest['astdb_count'];
                 $email->from($from);
                 $email->to(backup__($s['addr']));
                 $email->subject(_('Backup') . ' ' . $this->b['name']);
                 $body = implode("\n", $msg);
                 // If the backup file is more than 25MB, yell
                 $encodedsize = ceil(filesize($this->b['_tmpfile']) / 3) * 4;
                 if ($encodedsize > 26214400) {
                     $email->subject(_('Backup ERROR (exceeded SMTP limits)') . ' ' . $this->b['name']);
                     $email->message(_('BACKUP NOT ATTACHED') . "\n" . _('The backup file exceeded the maximum SMTP limits of 25MB. It was not attempted to be sent. Please shrink your backup, or use a different method of transferring your backup.') . "\n{$body}\n");
                 } elseif ($encodedsize > $s['maxsize']) {
                     $email->subject(_('Backup ERROR (exceeded soft limit)') . ' ' . $this->b['name']);
                     $email->message(_('BACKUP NOT ATTACHED') . "\n" . _('The backup file exceeded the soft limit set in SMTP configuration (%s bytes). It was not attempted to be sent. Please shrink your backup, or use a different method of transferring your backup.') . "\n{$body}\n");
                 } else {
                     $email->message($body);
                     $email->attach($this->b['_tmpfile']);
                 }
                 $email->send();
                 unset($msg);
                 break;
             case 'ftp':
                 //subsitute variables if nesesary
                 $s['host'] = backup__($s['host']);
                 $s['port'] = backup__($s['port']);
                 $s['user'] = backup__($s['user']);
                 $s['password'] = backup__($s['password']);
                 $s['path'] = backup__($s['path']);
                 $ftp = @ftp_connect($s['host'], $s['port']);
                 if ($ftp === false) {
                     $this->b['error'] = _("Error connecting to the FTP Server... Check your host name or DNS");
                     backup_log($this->b['error']);
                     return $ftp;
                 }
                 if (ftp_login($ftp, $s['user'], $s['password'])) {
                     //chose pasive/active transfer mode
                     ftp_pasv($ftp, $s['transfer'] == 'passive');
                     //switch to directory. If we fail, build directory structure and try again
                     if (!@ftp_chdir($ftp, $s['path'] . '/' . $this->b['_dirname'])) {
                         //ensure directory structure
                         @ftp_mkdir($ftp, $s['path']);
                         @ftp_mkdir($ftp, $s['path'] . '/' . $this->b['_dirname']);
                         ftp_chdir($ftp, $s['path'] . '/' . $this->b['_dirname']);
                     }
                     //copy file
                     ftp_put($ftp, $this->b['_file'] . '.tgz', $this->b['_tmpfile'], FTP_BINARY);
                     //run maintenance on the directory
                     $this->maintenance($s['type'], $s, $ftp);
                     //release handel
                     ftp_close($ftp);
                 } else {
                     $this->b['error'] = _("Error connecting to the FTP Server...");
                     backup_log($this->b['error']);
                 }
                 break;
             case 'awss3':
                 //subsitute variables if nesesary
                 $s['bucket'] = backup__($s['bucket']);
                 $s['awsaccesskey'] = backup__($s['awsaccesskey']);
                 $s['awssecret'] = backup__($s['awssecret']);
                 $awss3 = new \S3($s['awsaccesskey'], $s['awssecret']);
                 // Does this bucket already exist?
                 $buckets = $awss3->listBuckets();
                 if (!in_array($s['bucket'], $buckets)) {
                     // Create the bucket
                     $awss3->putBucket($s['bucket'], \S3::ACL_PUBLIC_READ);
                 }
                 //copy file
                 if ($awss3->putObjectFile($this->b['_tmpfile'], $s['bucket'], $this->b['name'] . "/" . $this->b['_file'] . '.tgz', \S3::ACL_PUBLIC_READ)) {
                     dbug('S3 successfully uploaded your backup file.');
                 } else {
                     dbug('S3 failed to accept your backup file');
                 }
                 //run maintenance on the directory
                 $this->maintenance($s['type'], $s, $awss3);
                 break;
             case 'ssh':
                 //subsitute variables if nesesary
                 $s['path'] = backup__($s['path']);
                 $s['user'] = backup__($s['user']);
                 $s['host'] = backup__($s['host']);
                 $destdir = $s['path'] . '/' . $this->b['_dirname'];
                 //ensure directory structure
                 $cmd = fpbx_which('ssh') . ' -o StrictHostKeyChecking=no -i ';
                 $cmd .= $s['key'] . " -l " . $s['user'] . ' ' . $s['host'] . ' -p ' . $s['port'];
                 $cmd .= " 'mkdir -p {$destdir}'";
                 exec($cmd, $output, $ret);
                 if ($ret !== 0) {
                     backup_log("SSH Error ({$ret}) - Received " . json_encode($output) . " from {$cmd}");
                 }
                 $output = null;
                 //put file
                 // Note that SCP (*unlike SSH*) needs IPv6 addresses in ['s. Consistancy is awesome.
                 if (filter_var($s['host'], \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
                     $scphost = "[" . $s['host'] . "]";
                 } else {
                     $scphost = $s['host'];
                 }
                 $cmd = fpbx_which('scp') . ' -o StrictHostKeyChecking=no -i ' . $s['key'] . ' -P ' . $s['port'];
                 $cmd .= " " . $this->b['_tmpfile'] . " " . $s['user'] . "@{$scphost}:{$destdir}";
                 exec($cmd, $output, $ret);
                 if ($ret !== 0) {
                     backup_log("SCP Error ({$ret}) - Received " . json_encode($output) . " from {$cmd}");
                 }
                 //run maintenance on the directory
                 $this->maintenance($s['type'], $s);
                 break;
         }
     }
 }