/**
 * Cronjob function to end a cronjob in a critical condition
 * but not without sending a notification mail to the admin
 *
 * @param string $message
 * @param string $subject
 *
 * @return void
 */
function dieWithMail($message, $subject = "[froxlor] Cronjob error")
{
    if (Settings::Get('system.send_cron_errors') == '1') {
        $_mail = new PHPMailer(true);
        $_mail->CharSet = "UTF-8";
        if (PHPMailer::ValidateAddress(Settings::Get('panel.adminmail')) !== false) {
            // set return-to address and custom sender-name, see #76
            $_mail->SetFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));
            if (Settings::Get('panel.adminmail_return') != '') {
                $_mail->AddReplyTo(Settings::Get('panel.adminmail_return'), Settings::Get('panel.adminmail_defname'));
            }
        }
        $_mailerror = false;
        try {
            $_mail->Subject = $subject;
            $_mail->AltBody = $message;
            $_mail->MsgHTML(nl2br($message));
            $_mail->AddAddress(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));
            $_mail->Send();
        } catch (phpmailerException $e) {
            $mailerr_msg = $e->errorMessage();
            $_mailerror = true;
        } catch (Exception $e) {
            $mailerr_msg = $e->getMessage();
            $_mailerror = true;
        }
        $_mail->ClearAddresses();
        if ($_mailerror) {
            echo 'Error sending mail: ' . $mailerr_msg . "\n";
        }
    }
    die($message);
}
Example #2
0
 public function SetAdress($sMail, $sName = null)
 {
     if (PHPMailer::ValidateAddress($sMail)) {
         return parent::SetAdress($sMail, $sName);
     } else {
         // todo: добавить логгирование ошибки
     }
 }
Example #3
0
 /**
  * Check if a mail address is valid
  *
  * @param string $address the mail address to check
  *
  * @return true if address is valid, false otherwise
  */
 public static function isValidEmail($address)
 {
     $valid = \PHPMailer::ValidateAddress($address);
     if (!$valid) {
         Analog::log('[GaletteMail] Address `' . $address . '` is not valid ', Analog::DEBUG);
     }
     return $valid;
 }
Example #4
0
     echo "Please enter the required information!";
     exit;
 }
 foreach ($_POST as $value) {
     if (stripos($value, 'Content-Type:') !== FALSE) {
         echo "There was a problem with the information you entered.";
         exit;
     }
 }
 if ($_POST["address"]) {
     echo "You got a problem, son.";
     exit;
 }
 require_once "phpmailer/PHPMailerAutoload.php";
 $mail = new PHPMailer();
 if (!$mail->ValidateAddress($email)) {
     echo "Real email address required";
 }
 $email_body = "";
 $email_body = $email_body . "Name:" . "&nbsp;" . $name . "<br>";
 $email_body = $email_body . "Email:" . "&nbsp;" . $email . "<br><br>";
 $email_body = $email_body . "Services:" . "&nbsp;" . $services . "<br><br>";
 $email_body = $email_body . "Subject:" . "&nbsp;" . $subject . "<br>";
 $email_body = $email_body . "Message:" . "&nbsp;" . $message . "<br>";
 //Set who the message is to be sent from
 $mail->setFrom($email, $name);
 //Set who the message is to be sent to
 $mail->addAddress('*****@*****.**', 'Rafay Choudhury');
 //Set the subject line
 $mail->Subject = 'Fywave Beverly Hills Digital Marketing' . $name;
 //Read an HTML message body from an external file, convert referenced images to embedded,
Example #5
0
    showUpdateStep("Updating from 0.9.5 to 0.9.6-svn1", false);
    showUpdateStep("Adding time-to-live configuration setting");
    Database::query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'defaultttl', '604800');");
    lastStepStatus(0);
    showUpdateStep("Updating database table structure for panel_ticket_categories");
    Database::query("ALTER TABLE `" . TABLE_PANEL_TICKET_CATS . "` ADD `logicalorder` int(3) NOT NULL default '1' AFTER `adminid`;");
    lastStepStatus(0);
    updateToVersion('0.9.6-svn1');
}
if (isFroxlorVersion('0.9.6-svn1')) {
    showUpdateStep("Updating from 0.9.6-svn1 to 0.9.6-svn2", false);
    $update_adminmail = isset($_POST['update_adminmail']) ? validate($_POST['update_adminmail'], 'update_adminmail') : false;
    $do_update = true;
    if ($update_adminmail !== false) {
        showUpdateStep("Checking newly entered admin-mail");
        if (!PHPMailer::ValidateAddress($update_adminmail)) {
            $do_update = false;
            lastStepStatus(2, 'E-Mail still not valid, go back and try again');
        } else {
            $stmt = Database::prepare("\n\t\t\t\tUPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = :adminmail\n\t\t\t\tWHERE `settinggroup` = 'panel' AND `varname` = 'adminmail';");
            Database::pexecute($stmt, array('adminmail' => $update_adminmail));
            lastStepStatus(0);
        }
    }
    if ($do_update) {
        updateToVersion('0.9.6-svn2');
    }
}
if (isFroxlorVersion('0.9.6-svn2')) {
    showUpdateStep("Updating from 0.9.6-svn2 to 0.9.6-svn3", false);
    $update_deferr_enable = isset($_POST['update_deferr_enable']) ? true : false;
/**
 * checks if the new-version has some updating to do
 *
 * @param boolean $has_preconfig   pointer to check if any preconfig has to be output
 * @param string  $return          pointer to output string
 * @param string  $current_version current froxlor version
 *
 * @return null
 */
function parseAndOutputPreconfig(&$has_preconfig, &$return, $current_version)
{
    global $lng;
    if (versionInUpdate($current_version, '0.9.4-svn2')) {
        $has_preconfig = true;
        $description = 'Froxlor now enables the usage of a domain-wildcard entry and subdomains for this domain at the same time (subdomains are parsed before the main-domain vhost container).';
        $description .= 'This makes it possible to catch all non-existing subdomains with the main vhost but also have the ability to use subdomains for that domain.<br />';
        $description .= 'If you would like Froxlor to do so with your domains, the update script can set the correct values for existing domains for you. Note: future domains will have wildcard-entries enabled by default no matter how you decide here.';
        $question = '<strong>Do you want to use wildcard-entries for existing domains?:</strong>&nbsp;';
        $question .= makeyesno('update_domainwildcardentry', '1', '0', '1');
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.6-svn2')) {
        if (!PHPMailer::ValidateAddress(Settings::Get('panel.adminmail'))) {
            $has_preconfig = true;
            $description = 'Froxlor uses a newer version of the phpMailerClass and determined that your current admin-mail address is invalid.';
            $question = '<strong>Please specify a new admin-email address:</strong>&nbsp;<input type="text" class="text" name="update_adminmail" value="' . Settings::Get('panel.adminmail') . '" />';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.6-svn3')) {
        $has_preconfig = true;
        $description = 'You now have the possibility to define default error-documents for your webserver which replace the default webserver error-messages.';
        $question = '<strong>Do you want to enable default error-documents?:</strong>&nbsp;';
        $question .= makeyesno('update_deferr_enable', '1', '0', '0') . '<br /><br />';
        if (Settings::Get('system.webserver') == 'apache2') {
            $question .= 'Path/URL for error 500:&nbsp;<input type="text" class="text" name="update_deferr_500" /><br /><br />';
            $question .= 'Path/URL for error 401:&nbsp;<input type="text" class="text" name="update_deferr_401" /><br /><br />';
            $question .= 'Path/URL for error 403:&nbsp;<input type="text" class="text" name="update_deferr_403" /><br /><br />';
        }
        $question .= 'Path/URL for error 404:&nbsp;<input type="text" class="text" name="update_deferr_404" />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.6-svn4')) {
        $has_preconfig = true;
        $description = 'You can define a default support-ticket priority level which is pre-selected for new support-tickets.';
        $question = '<strong>Which should be the default ticket-priority?:</strong>&nbsp;';
        $question .= '<select name="update_deftic_priority">';
        $priorities = makeoption($lng['ticket']['high'], '1', '2');
        $priorities .= makeoption($lng['ticket']['normal'], '2', '2');
        $priorities .= makeoption($lng['ticket']['low'], '3', '2');
        $question .= $priorities . '</select>';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.6-svn5')) {
        $has_preconfig = true;
        $description = 'If you have more than one PHP configurations defined in Froxlor you can now set a default one which will be used for every domain.';
        $question = '<strong>Select default PHP configuration:</strong>&nbsp;';
        $question .= '<select name="update_defsys_phpconfig">';
        $configs_array = getPhpConfigs();
        $configs = '';
        foreach ($configs_array as $idx => $desc) {
            $configs .= makeoption($desc, $idx, '1');
        }
        $question .= $configs . '</select>';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.6-svn6')) {
        $has_preconfig = true;
        $description = 'For the new FTP-quota feature, you can now chose the currently used ftpd-software.';
        $question = '<strong>Used FTPd-software:</strong>&nbsp;';
        $question .= '<select name="update_defsys_ftpserver">';
        $question .= makeoption('ProFTPd', 'proftpd', 'proftpd');
        $question .= makeoption('PureFTPd', 'pureftpd', 'proftpd');
        $question .= '</select>';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.7-svn1')) {
        $has_preconfig = true;
        $description = 'You can now choose whether customers can select the http-redirect code and which of them acts as default.';
        $question = '<strong>Allow customer chosen redirects?:</strong>&nbsp;';
        $question .= makeyesno('update_customredirect_enable', '1', '0', '1') . '<br /><br />';
        $question .= '<strong>Select default redirect code (default: empty):</strong>&nbsp;';
        $question .= '<select name="update_customredirect_default">';
        $redirects = makeoption('--- (' . $lng['redirect_desc']['rc_default'] . ')', 1, '1');
        $redirects .= makeoption('301 (' . $lng['redirect_desc']['rc_movedperm'] . ')', 2, '1');
        $redirects .= makeoption('302 (' . $lng['redirect_desc']['rc_found'] . ')', 3, '1');
        $redirects .= makeoption('303 (' . $lng['redirect_desc']['rc_seeother'] . ')', 4, '1');
        $redirects .= makeoption('307 (' . $lng['redirect_desc']['rc_tempred'] . ')', 5, '1');
        $question .= $redirects . '</select>';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.7-svn2')) {
        $result = Database::query("SELECT `domain` FROM " . TABLE_PANEL_DOMAINS . " WHERE `documentroot` LIKE '%:%' AND `documentroot` NOT LIKE 'http://%' AND `openbasedir_path` = '0' AND `openbasedir` = '1'");
        $wrongOpenBasedirDomain = array();
        while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
            $wrongOpenBasedirDomain[] = $row['domain'];
        }
        if (count($wrongOpenBasedirDomain) > 0) {
            $has_preconfig = true;
            $description = 'Resetting the open_basedir to customer - root';
            $question = '<strong>Due to a security - issue regarding open_basedir, Froxlor will set the open_basedir for the following domains to the customers root instead of the chosen documentroot:</strong><br />&nbsp;';
            $question .= '<ul>';
            $idna_convert = new idna_convert_wrapper();
            foreach ($wrongOpenBasedirDomain as $domain) {
                $question .= '<li>' . $idna_convert->decode($domain) . '</li>';
            }
            $question .= '</ul>';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.9-svn1')) {
        $has_preconfig = true;
        $description = 'When entering MX servers to Froxlor there was no mail-, imap-, pop3- and smtp-"A record" created. You can now chose whether this should be done or not.';
        $question = '<strong>Do you want these A-records to be created even with MX servers given?:</strong>&nbsp;';
        $question .= makeyesno('update_defdns_mailentry', '1', '0', '0');
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.10-svn1')) {
        $has_nouser = false;
        $has_nogroup = false;
        $result_stmt = Database::query("SELECT * FROM `" . TABLE_PANEL_SETTINGS . "` WHERE `settinggroup` = 'system' AND `varname` = 'httpuser'");
        $result = $result_stmt->fetch(PDO::FETCH_ASSOC);
        if (!isset($result) || !isset($result['value'])) {
            $has_preconfig = true;
            $has_nouser = true;
            $guessed_user = '******';
            if (function_exists('posix_getuid') && function_exists('posix_getpwuid')) {
                $_httpuser = posix_getpwuid(posix_getuid());
                $guessed_user = $_httpuser['name'];
            }
        }
        $result_stmt = Database::query("SELECT * FROM `" . TABLE_PANEL_SETTINGS . "` WHERE `settinggroup` = 'system' AND `varname` = 'httpgroup'");
        $result = $result_stmt->fetch(PDO::FETCH_ASSOC);
        if (!isset($result) || !isset($result['value'])) {
            $has_preconfig = true;
            $has_nogroup = true;
            $guessed_group = 'www-data';
            if (function_exists('posix_getgid') && function_exists('posix_getgrgid')) {
                $_httpgroup = posix_getgrgid(posix_getgid());
                $guessed_group = $_httpgroup['name'];
            }
        }
        if ($has_nouser || $has_nogroup) {
            $description = 'Please enter the correct username/groupname of the webserver on your system We\'re guessing the user but it might not be correct, so please check.';
            if ($has_nouser) {
                $question = '<strong>Please enter the webservers username:</strong>&nbsp;<input type="text" class="text" name="update_httpuser" value="' . $guessed_user . '" />';
            } elseif ($has_nogroup) {
                $question2 = '<strong>Please enter the webservers groupname:</strong>&nbsp;<input type="text" class="text" name="update_httpgroup" value="' . $guessed_group . '" />';
                if ($has_nouser) {
                    $question .= '<br /><br />' . $question2;
                } else {
                    $question = $question2;
                }
            }
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.10')) {
        $has_preconfig = true;
        $description = 'you can now decide whether Froxlor should be reached via hostname/froxlor or directly via the hostname.';
        $question = '<strong>Do you want Froxlor to be reached directly via the hostname?:</strong>&nbsp;';
        $question .= makeyesno('update_directlyviahostname', '1', '0', '0');
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.11-svn1')) {
        $has_preconfig = true;
        $description = 'It is possible to enhance security with setting a regular expression to force your customers to enter more complex passwords.';
        $question = '<strong>Enter a regular expression to force a higher password complexity (leave empty for none):</strong>&nbsp;';
        $question .= '<input type="text" class="text" name="update_pwdregex" value="" />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.11-svn3')) {
        $has_preconfig = true;
        $description = 'As Froxlor can now handle perl, you have to specify where the perl executable is (only if you\'re running lighttpd, else just leave empty).';
        $question = '<strong>Path to perl (default \'/usr/bin/perl\'):</strong>&nbsp;';
        $question .= '<input type="text" class="text" name="update_perlpath" value="/usr/bin/perl" />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.12-svn1')) {
        if (Settings::Get('system.mod_fcgid') == 1) {
            $has_preconfig = true;
            $description = 'You can chose whether you want Froxlor to use FCGID itself too now.';
            $question = '<strong>Use FCGID for the Froxlor Panel?:</strong>&nbsp;';
            $question .= makeyesno('update_fcgid_ownvhost', '1', '0', '0') . '<br /><br />';
            $question .= '<strong>If \'yes\', please specify local user/group (have to exist, Froxlor does not add them automatically):</strong><br /><br />';
            $question .= 'Local user:&nbsp;';
            $question .= '<input type="text" class="text" name="update_fcgid_httpuser" value="froxlorlocal" /><br /><br />';
            $question .= 'Local group:&nbsp;';
            $question .= '<input type="text" class="text" name="update_fcgid_httpgroup" value="froxlorlocal" /><br />';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.12-svn2')) {
        $has_preconfig = true;
        $description = 'Many apache user will have problems using perl/CGI as the customer docroots are not within the suexec path. Froxlor provides a simple workaround for that.';
        $question = '<strong>Enable Apache/SuExec/Perl workaround?:</strong>&nbsp;';
        $question .= makeyesno('update_perl_suexecworkaround', '1', '0', '0') . '<br /><br />';
        $question .= '<strong>If \'yes\', please specify a path within the suexec path where Froxlor will create symlinks to customer perl-enabled paths:</strong><br /><br />';
        $question .= 'Path for symlinks (must be within suexec path):&nbsp;';
        $question .= '<input type="text" class="text" name="update_perl_suexecpath" value="/var/www/cgi-bin/" /><br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.12-svn4')) {
        if ((int) Settings::Get('system.awstats_enabled') == 1) {
            $has_preconfig = true;
            $description = 'Due to different paths of awstats_buildstaticpages.pl and awstats.pl you can set a different path for awstats.pl now.';
            $question = '<strong>Path to \'awstats.pl\'?:</strong>&nbsp;';
            $question .= '<input type="text" class="text" name="update_awstats_awstatspath" value="' . Settings::Get('system.awstats_path') . '" /><br />';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.13-svn1')) {
        if ((int) Settings::Get('autoresponder.autoresponder_active') == 1) {
            $has_preconfig = true;
            $description = 'Froxlor can now limit the number of autoresponder-entries for each user. Here you can set the value which will be available for each customer (Of course you can change the value for each customer separately after the update).';
            $question = '<strong>How many autoresponders should your customers be able to add?:</strong>&nbsp;';
            $question .= '<input type="text" class="text" name="update_autoresponder_default" value="0" />&nbsp;' . makecheckbox('update_autoresponder_default', $lng['customer']['unlimited'], '-1', false, 0, true, true) . '<br />';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.13.1')) {
        if ((int) Settings::Get('system.mod_fcgid_ownvhost') == 1) {
            $has_preconfig = true;
            $description = 'You have FCGID for Froxlor itself activated. You can now specify a PHP-configuration for this.';
            $question = '<strong>Select Froxlor-vhost PHP configuration:</strong>&nbsp;';
            $question .= '<select name="update_defaultini_ownvhost">';
            $configs_array = getPhpConfigs();
            $configs = '';
            foreach ($configs_array as $idx => $desc) {
                $configs .= makeoption($desc, $idx, '1');
            }
            $question .= $configs . '</select>';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.14-svn3')) {
        if ((int) Settings::Get('system.awstats_enabled') == 1) {
            $has_preconfig = true;
            $description = 'To have icons in AWStats statistic-pages please enter the path to AWStats icons folder.';
            $question = '<strong>Path to AWSTats icons folder:</strong>&nbsp;';
            $question .= '<input type="text" class="text" name="update_awstats_icons" value="' . Settings::Get('system.awstats_icons') . '" />';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.14-svn4')) {
        if ((int) Settings::Get('system.use_ssl') == 1) {
            $has_preconfig = true;
            $description = 'Froxlor now has the possibility to set \'SSLCertificateChainFile\' for the apache webserver.';
            $question = '<strong>Enter filename (leave empty for none):</strong>&nbsp;';
            $question .= '<input type="text" class="text" name="update_ssl_cert_chainfile" value="' . Settings::Get('system.ssl_cert_chainfile') . '" />';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.14-svn6')) {
        $has_preconfig = true;
        $description = 'You can now allow customers to use any of their domains as username for the login.';
        $question = '<strong>Do you want to enable domain-login for all customers?:</strong>&nbsp;';
        $question .= makeyesno('update_allow_domain_login', '1', '0', '0');
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.14-svn10')) {
        $has_preconfig = true;
        $description = '<strong>This update removes the unsupported real-time option. Additionally the deprecated tables for navigation and cronscripts are removed, any modules using these tables need to be updated to the new structure!</strong>';
        $question = '';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.16-svn1')) {
        $has_preconfig = true;
        $description = 'Froxlor now features support for php-fpm.';
        $question = '<strong>Do you want to enable php-fpm?:</strong>&nbsp;';
        $question .= makeyesno('update_phpfpm_enabled', '1', '0', '0') . '<br /><br />';
        $question .= 'If \'yes\', please specify the configuration directory:&nbsp;';
        $question .= '<input type="text" class="text" name="update_phpfpm_configdir" value="/etc/php-fpm.d/" /><br /><br />';
        $question .= 'Please specify the temporary files directory:&nbsp;';
        $question .= '<input type="text" class="text" name="update_phpfpm_tmpdir" value="/var/customers/tmp/" /><br /><br />';
        $question .= 'Please specify the PEAR directory:&nbsp;';
        $question .= '<input type="text" class="text" name="update_phpfpm_peardir" value="/usr/share/php/:/usr/share/php5/" /><br /><br />';
        $question .= 'Please specify the php-fpm restart-command:&nbsp;';
        $question .= '<input type="text" class="text" name="update_phpfpm_reload" value="/etc/init.d/php-fpm restart" /><br /><br />';
        $question .= 'Please specify the php-fpm rocess manager control:&nbsp;';
        $question .= '<select name="update_phpfpm_pm">';
        $redirects = makeoption('static', 'static', 'static');
        $redirects .= makeoption('dynamic', 'dynamic', 'static');
        $question .= $redirects . '</select><br /><br />';
        $question .= 'Please specify the number of child processes:&nbsp;';
        $question .= '<input type="text" class="text" name="update_phpfpm_max_children" value="1" /><br /><br />';
        $question .= 'Please specify the number of requests per child before respawning:&nbsp;';
        $question .= '<input type="text" class="text" name="update_phpfpm_max_requests" value="0" /><br /><br />';
        $question .= '<em>The following settings are only required if you chose process manager = dynamic</em><br /><br />';
        $question .= 'Please specify the number of child processes created on startup:&nbsp;';
        $question .= '<input type="text" class="text" name="update_phpfpm_start_servers" value="20" /><br /><br />';
        $question .= 'Please specify the desired minimum number of idle server processes:&nbsp;';
        $question .= '<input type="text" class="text" name="update_phpfpm_min_spare_servers" value="5" /><br /><br />';
        $question .= 'Please specify the desired maximum number of idle server processes:&nbsp;';
        $question .= '<input type="text" class="text" name="update_phpfpm_max_spare_servers" value="35" /><br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.16-svn2')) {
        if ((int) Settings::Get('phpfpm.enabled') == 1) {
            $has_preconfig = true;
            $description = 'You can chose whether you want Froxlor to use PHP-FPM itself too now.';
            $question = '<strong>Use PHP-FPM for the Froxlor Panel?:</strong>&nbsp;';
            $question .= makeyesno('update_phpfpm_enabled_ownvhost', '1', '0', '0') . '<br /><br />';
            $question .= '<strong>If \'yes\', please specify local user/group (have to exist, Froxlor does not add them automatically):</strong><br /><br />';
            $question .= 'Local user:&nbsp;';
            $question .= '<input type="text" class="text" name="update_phpfpm_httpuser" value="' . Settings::Get('system.mod_fcgid_httpuser') . '" /><br /><br />';
            $question .= 'Local group:&nbsp;';
            $question .= '<input type="text" class="text" name="update_phpfpm_httpgroup" value="' . Settings::Get('system.mod_fcgid_httpgroup') . '" /><br />';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.17-svn1')) {
        $has_preconfig = true;
        $description = 'Select if you want to enable the web- and traffic-reports';
        $question = '<strong>Enable?:</strong>&nbsp;';
        $question .= makeyesno('update_system_report_enable', '1', '0', '1') . '<br /><br />';
        $question .= '<strong>If \'yes\', please specify a percentage value for web- and traffic when reports are to be sent:</strong><br /><br />';
        $question .= 'Webusage warning level:&nbsp;';
        $question .= '<input type="text" class="text" name="update_system_report_webmax" value="90" /><br /><br />';
        $question .= 'Traffic warning level:&nbsp;';
        $question .= '<input type="text" class="text" name="update_system_report_trafficmax" value="90" /><br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.18-svn2')) {
        $has_preconfig = true;
        $description = 'As you can (obviously) see, Froxlor now comes with a new theme. You also have the possibility to switch back to "Classic" if you want to.';
        $question = '<strong>Select default panel theme:</strong>&nbsp;';
        $question .= '<select name="update_default_theme">';
        $themes = getThemes();
        foreach ($themes as $cur_theme) {
            $question .= makeoption($cur_theme, $cur_theme, 'Froxlor');
        }
        $question .= '</select>';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.28-svn4')) {
        $has_preconfig = true;
        $description = 'This version introduces a lot of profound changes:';
        $description .= '<br /><ul><li>Improving the whole template system</li><li>Full UTF-8 support</li><li><strong>Removing support for the former default theme \'Classic\'</strong></li></ul>';
        $description .= '<br /><br />Notice: This update will <strong>alter your Froxlor database to use UTF-8</strong> as default charset. ';
        $description .= 'Even though this is already tested, we <span class="red">strongly recommend</span> to ';
        $description .= 'test this update in a testing environment using your existing data.<br /><br />';
        $question = '<strong>Select your preferred Classic Theme replacement:</strong>&nbsp;';
        $question .= '<select name="classic_theme_replacement">';
        $themes = getThemes();
        foreach ($themes as $cur_theme) {
            $question .= makeoption($cur_theme, $cur_theme, 'Froxlor');
        }
        $question .= '</select>';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.28-svn6')) {
        if (Settings::Get('system.webserver') == 'apache2') {
            $has_preconfig = true;
            $description = 'Froxlor now supports the new Apache 2.4. Please be aware that you need to load additional apache-modules in ordner to use it.<br />';
            $description .= '<pre>LoadModule authz_core_module modules/mod_authz_core.so
					LoadModule authz_host_module modules/mod_authz_host.so</pre><br />';
            $question = '<strong>Do you want to enable the Apache-2.4 modification?:</strong>&nbsp;';
            $question .= makeyesno('update_system_apache24', '1', '0', '0');
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        } elseif (Settings::Get('system.webserver') == 'nginx') {
            $has_preconfig = true;
            $description = 'The path to nginx\'s fastcgi_params file is now customizable.<br /><br />';
            $question = '<strong>Please enter full path to you nginx/fastcgi_params file (including filename):</strong>&nbsp;';
            $question .= '<input type="text" class="text" name="nginx_fastcgi_params" value="/etc/nginx/fastcgi_params" />';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.28-rc2')) {
        $has_preconfig = true;
        $description = 'This version adds an option to append the domain-name to the document-root for domains and subdomains.<br />';
        $description .= 'You can enable or disable this feature anytime from settings -> system settings.<br />';
        $question = '<strong>Do you want to automatically append the domain-name to the documentroot of newly created domains?:</strong>&nbsp;';
        $question .= makeyesno('update_system_documentroot_use_default_value', '1', '0', '0');
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.28')) {
        $has_preconfig = true;
        // just an information about the new sendmail parameter (#1134)
        $description = 'Froxlor changed the default parameter-set of sendmail (php.ini)<br />';
        $description .= 'sendmail_path = "/usr/sbin/sendmail -t <strong>-i</strong> -f {CUSTOMER_EMAIL}"<br /><br />';
        $description .= 'If you don\'t have any problems with sending mails, you don\'t need to change this';
        if (Settings::Get('system.mod_fcgid') == '1' || Settings::Get('phpfpm.enabled') == '1') {
            // information about removal of php's safe_mode
            $description .= '<br /><br />The php safe_mode flag has been removed as current versions of PHP<br />';
            $description .= 'do not support it anymore.<br /><br />';
            $description .= 'Please check your php-configurations and remove safe_mode-directives to avoid php notices/warnings.';
        }
        $question = '';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.29-dev1')) {
        // we only need to ask if fcgid|php-fpm is enabled
        if (Settings::Get('system.mod_fcgid') == '1' || Settings::Get('phpfpm.enabled') == '1') {
            $has_preconfig = true;
            $description = 'Standard-subdomains can now be hidden from the php-configuration overview.<br />';
            $question = '<strong>Do you want to hide the standard-subdomains (this can be changed in the settings any time)?:</strong>&nbsp;';
            $question .= makeyesno('hide_stdsubdomains', '1', '0', '0');
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.29-dev2')) {
        $has_preconfig = true;
        $description = 'You can now decide whether admins/customers are able to change the theme<br />';
        $question = '<strong>If you want to disallow theme-changing, select "no" from the dropdowns:</strong>&nbsp;';
        $question .= "Admins: " . makeyesno('allow_themechange_a', '1', '0', '1') . '&nbsp;&nbsp;';
        $question .= "Customers: " . makeyesno('allow_themechange_c', '1', '0', '1');
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.29-dev3')) {
        $has_preconfig = true;
        $description = 'There is now a possibility to specify AXFR servers for your bind zone-configuration<br />';
        $question = '<strong>Enter a comma-separated list of AXFR servers or leave empty (default):</strong>&nbsp;';
        $question .= '<input type="text" class="text" name="system_afxrservers" value="" />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.29-dev4')) {
        $has_preconfig = true;
        $description = 'As customers can now specify ssl-certificate data for their domains, you need to specify where the generated files are stored<br />';
        $question = '<strong>Specify the directory for customer ssl-certificates:</strong>&nbsp;';
        $question .= '<input type="text" class="text" name="system_customersslpath" value="/etc/ssl/froxlor-custom/" />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.29.1-dev3')) {
        $has_preconfig = true;
        $description = 'The build in logrotation-feature has been removed. Please follow the configuration-instructions for your system to enable logrotating again.';
        $question = '';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    // let the apache+fpm users know that they MUST change their config
    // for the domains / webserver to work after the update
    if (versionInUpdate($current_version, '0.9.30-dev1')) {
        if (Settings::Get('system.webserver') == 'apache2' && Settings::Get('phpfpm.enabled') == '1') {
            $has_preconfig = true;
            $description = 'The PHP-FPM implementation for apache2 has changed. Please look for the "<b>fastcgi.conf</b>" (Debian/Ubuntu) or "<b>70_fastcgi.conf</b>" (Gentoo) within /etc/apache2/ and change it as shown below:<br /><br />';
            $description .= '<pre class="code-block">&lt;IfModule mod_fastcgi.c&gt;
    FastCgiIpcDir /var/lib/apache2/fastcgi/
    &lt;Location "/fastcgiphp"&gt;
        Order Deny,Allow
        Deny from All
        # Prevent accessing this path directly
        Allow from env=REDIRECT_STATUS
    &lt;/Location&gt;
&lt;/IfModule&gt;</pre>';
            $question = '';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.31-dev2')) {
        if (Settings::Get('system.webserver') == 'apache2' && Settings::Get('phpfpm.enabled') == '1') {
            $has_preconfig = true;
            $description = 'The FPM socket directory is now a setting in froxlor. Its default is <b>/var/lib/apache2/fastcgi/</b>.<br/>If you are using <b>/var/run/apache2</b> in the "<b>fastcgi.conf</b>" (Debian/Ubuntu) or "<b>70_fastcgi.conf</b>" (Gentoo) please correct this path accordingly<br />';
            $question = '';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.31-dev4')) {
        $has_preconfig = true;
        $description = 'The template-variable {PASSWORD} has been replaced with {LINK}. Please update your password reset templates!<br />';
        $question = '';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.31-dev5')) {
        $has_preconfig = true;
        $description = 'You can enable/disable error-reporting for admins and customers!<br /><br />';
        $question = '<strong>Do you want to enable error-reporting for admins? (default: yes):</strong>&nbsp;';
        $question .= makeyesno('update_error_report_admin', '1', '0', '1') . '<br />';
        $question .= '<strong>Do you want to enable error-reporting for customers? (default: no):</strong>&nbsp;';
        $question .= makeyesno('update_error_report_customer', '1', '0', '0');
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.31-rc2')) {
        $has_preconfig = true;
        $description = 'You can enable/disable the display/usage of the news-feed for admins<br /><br />';
        $question = '<strong>Do you want to enable the news-feed for admins? (default: yes):</strong>&nbsp;';
        $question .= makeyesno('update_admin_news_feed', '1', '0', '1') . '<br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.32-dev2')) {
        $has_preconfig = true;
        $description = 'To enable logging of the mail-traffic, you need to set the following settings accordingly<br /><br />';
        $question = '<strong>Do you want to enable the traffic collection for mail? (default: yes):</strong>&nbsp;';
        $question .= makeyesno('mailtraffic_enabled', '1', '0', '1') . '<br />';
        $question .= '<strong>Mail Transfer Agent</strong><br />';
        $question .= 'Type of your MTA:&nbsp;';
        $question .= '<select name="mtaserver">';
        $question .= makeoption('Postfix', 'postfix', 'postfix');
        $question .= makeoption('Exim4', 'exim4', 'postfix');
        $question .= '</select><br />';
        $question .= 'Logfile for your MTA:&nbsp;';
        $question .= '<input type="text" class="text" name="mtalog" value="/var/log/mail.log" /><br />';
        $question .= '<strong>Mail Delivery Agent</strong><br />';
        $question .= 'Type of your MDA:&nbsp;';
        $question .= '<select name="mdaserver">';
        $question .= makeoption('Dovecot', 'dovecot', 'dovecot');
        $question .= makeoption('Courier', 'courier', 'dovecot');
        $question .= '</select><br /><br />';
        $question .= 'Logfile for your MDA:&nbsp;';
        $question .= '<input type="text" class="text" name="mdalog" value="/var/log/mail.log" /><br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.32-dev5')) {
        $has_preconfig = true;
        $description = 'Froxlor now generates a cron-configuration file for the cron-daemon. Please set a filename which will be included automatically by your crond (e.g. files in /etc/cron.d/)<br /><br />';
        $question = '<strong>Path to the cron-service configuration-file.</strong> This file will be updated regularly and automatically by froxlor.<br />Note: please <b>be sure</b> to use the same filename as for the main froxlor cronjob (default: /etc/cron.d/froxlor)!<br />';
        $question .= '<input type="text" class="text" name="crondfile" value="/etc/cron.d/froxlor" /><br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.32-dev6')) {
        $has_preconfig = true;
        $description = 'In order for the new cron.d file to work properly, we need to know about the cron-service reload command.<br /><br />';
        $question = '<strong>Please specify the reload-command of your cron-daemon</strong> (default: /etc/init.d/cron reload)<br />';
        $question .= '<input type="text" class="text" name="crondreload" value="/etc/init.d/cron reload" /><br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.32-rc2')) {
        $has_preconfig = true;
        $description = 'To customize the command which executes the cronjob (php - basically) change the path below according to your system.<br /><br />';
        $question = '<strong>Please specify the command to execute cronscripts</strong> (default: "/usr/bin/nice -n 5 /usr/bin/php5 -q")<br />';
        $question .= '<input type="text" class="text" name="croncmdline" value="/usr/bin/nice -n 5 /usr/bin/php5 -q" /><br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.33-dev1')) {
        $has_preconfig = true;
        $description = 'You can enable/disable the display/usage of the custom newsfeed for customers.<br /><br />';
        $question = '<strong>Do you want to enable the custom newsfeed for customer? (default: no):</strong>&nbsp;';
        $question .= makeyesno('customer_show_news_feed', '1', '0', '0') . '<br />';
        $question .= '<strong>You have to set the URL for your RSS-feed here, if you have chosen to enable the custom newsfeed on the customer-dashboard:</strong>&nbsp;';
        $question .= '<input type="text" class="text" name="customer_news_feed_url" value="" /><br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.33-dev2')) {
        // only if bind is used - if not the default will be set, which is '0' (off)
        if (Settings::get('system.bind_enable') == 1) {
            $has_preconfig = true;
            $description = 'You can enable/disable the generation of the bind-zone / config for the system hostname.<br /><br />';
            $question = '<strong>Do you want to generate a bind-zone for the system-hostname? (default: no):</strong>&nbsp;';
            $question .= makeyesno('dns_createhostnameentry', '1', '0', '0') . '<br />';
            eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
        }
    }
    if (versionInUpdate($current_version, '0.9.33-rc2')) {
        $has_preconfig = true;
        $description = 'You can chose whether you want to receive an e-mail on cronjob errors. Keep in mind that this can lead to an e-mail being sent every 5 minutes.<br /><br />';
        $question = '<strong>Do you want to receive cron-errors via mail? (default: no):</strong>&nbsp;';
        $question .= makeyesno('system_send_cron_errors', '1', '0', '0') . '<br />';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
    if (versionInUpdate($current_version, '0.9.34-dev3')) {
        $has_preconfig = true;
        $description = 'Froxlor now requires the PHP mbstring-extension as we need to be multibyte-character safe in some cases';
        $question = '<strong>PHP mbstring</strong> is currently: ';
        if (!extension_loaded('mbstring')) {
            $question .= '<span class="red">not installed/loaded</span>';
            $question .= '<br>Please install the PHP mbstring extension in order to finish the update';
        } else {
            $question .= '<span class="green">installed/loaded</span>';
        }
        $question .= '<br>';
        eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";");
    }
}
Example #7
0
/**
 * The CSV file is parsed here so validation errors can be returned to the
 * user. The data from a successful parsing is stored in the <var>$CVSDATA</var>
 * array so it can be accessed by the submit function
 *
 * @param Pieform  $form   The form to validate
 * @param array    $values The values submitted
 */
function uploadcsv_validate(Pieform $form, $values)
{
    global $CSVDATA, $ALLOWEDKEYS, $FORMAT, $USER, $INSTITUTIONNAME, $UPDATES;
    // Don't even start attempting to parse if there are previous errors
    if ($form->has_errors()) {
        return;
    }
    $steps_done = 0;
    $steps_total = $values['updateusers'] ? 5 : 4;
    if ($values['file']['size'] == 0) {
        $form->set_error('file', $form->i18n('rule', 'required', 'required', array()));
        return;
    }
    if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
        $maxquotaenabled = get_config_plugin('artefact', 'file', 'maxquotaenabled');
        $maxquota = get_config_plugin('artefact', 'file', 'maxquota');
        if ($maxquotaenabled && $values['quota'] > $maxquota) {
            $form->set_error('quota', get_string('maxquotaexceededform', 'artefact.file', display_size($maxquota)));
        }
    }
    require_once 'csvfile.php';
    $authinstance = (int) $values['authinstance'];
    $institution = get_field('auth_instance', 'institution', 'id', $authinstance);
    if (!$USER->can_edit_institution($institution)) {
        $form->set_error('authinstance', get_string('notadminforinstitution', 'admin'));
        return;
    }
    $authobj = AuthFactory::create($authinstance);
    $csvusers = new CsvFile($values['file']['tmp_name']);
    $csvusers->set('allowedkeys', $ALLOWEDKEYS);
    // Now we know all of the field names are valid, we need to make
    // sure that the required fields are included
    $mandatoryfields = array('username', 'email', 'firstname', 'lastname');
    if (!$values['updateusers']) {
        $mandatoryfields[] = 'password';
    }
    $csvusers->set('mandatoryfields', $mandatoryfields);
    $csvdata = $csvusers->get_data();
    if (!empty($csvdata->errors['file'])) {
        $form->set_error('file', $csvdata->errors['file']);
        return;
    }
    $csverrors = new CSVErrors();
    $formatkeylookup = array_flip($csvdata->format);
    // First pass validates usernames & passwords in the file, and builds
    // up a list indexed by username.
    $emails = array();
    if (isset($formatkeylookup['remoteuser'])) {
        $remoteusers = array();
    }
    $num_lines = count($csvdata->data);
    $maxcsvlines = get_config('maxusercsvlines');
    if ($maxcsvlines && $maxcsvlines < $num_lines) {
        $form->set_error('file', get_string('uploadcsverrortoomanyusers', 'admin', get_string('nusers', 'mahara', $maxcsvlines)));
        return;
    }
    $existing_usernames = get_records_menu('usr', '', NULL, '', 'LOWER(username) AS username, 1 AS key2');
    $existing_usr_email_addresses = get_records_menu('usr', '', NULL, '', 'email, 1 AS key2');
    $existing_internal_email_addresses = get_records_menu('artefact_internal_profile_email', 'verified', 1, '', 'email, 1 AS key2');
    foreach ($csvdata->data as $key => $line) {
        // If headers exists, increment i = key + 2 for actual line number
        $i = $csvusers->get('headerExists') ? $key + 2 : $key + 1;
        if (!($key % 25)) {
            set_progress_info('uploaduserscsv', $key, $num_lines * $steps_total, get_string('validating', 'admin'));
        }
        // Trim non-breaking spaces -- they get left in place by File_CSV
        foreach ($line as &$field) {
            $field = preg_replace('/^(\\s|\\xc2\\xa0)*(.*?)(\\s|\\xc2\\xa0)*$/', '$2', $field);
        }
        if (count($line) != count($csvdata->format)) {
            $csverrors->add($i, get_string('uploadcsverrorwrongnumberoffields', 'admin', $i));
            continue;
        }
        // We have a line with the correct number of fields, but should validate these fields
        // Note: This validation should really be methods on each profile class, that way
        // it can be used in the profile screen as well.
        $username = $line[$formatkeylookup['username']];
        $password = isset($formatkeylookup['password']) ? $line[$formatkeylookup['password']] : null;
        $email = $line[$formatkeylookup['email']];
        if (isset($remoteusers)) {
            $remoteuser = strlen($line[$formatkeylookup['remoteuser']]) ? $line[$formatkeylookup['remoteuser']] : null;
        }
        if (method_exists($authobj, 'is_username_valid_admin')) {
            if (!$authobj->is_username_valid_admin($username)) {
                $csverrors->add($i, get_string('uploadcsverrorinvalidusername', 'admin', $i));
            }
        } else {
            if (method_exists($authobj, 'is_username_valid')) {
                if (!$authobj->is_username_valid($username)) {
                    $csverrors->add($i, get_string('uploadcsverrorinvalidusername', 'admin', $i));
                }
            }
        }
        if (!$values['updateusers']) {
            // Note: only checks for valid form are done here, none of the checks
            // like whether the password is too easy. The user is going to have to
            // change their password on first login anyway.
            if (method_exists($authobj, 'is_password_valid') && !$authobj->is_password_valid($password)) {
                $csverrors->add($i, get_string('uploadcsverrorinvalidpassword', 'admin', $i));
            }
        }
        if (isset($emails[$email])) {
            // Duplicate email within this file.
            $csverrors->add($i, get_string('uploadcsverroremailaddresstaken', 'admin', $i, $email));
        } else {
            if (!PHPMailer::ValidateAddress($email)) {
                $csverrors->add($i, get_string('uploadcsverrorinvalidemail', 'admin', $i, $email));
            } else {
                if (!$values['updateusers']) {
                    // The email address must be new
                    if (array_key_exists($email, $existing_usr_email_addresses) || array_key_exists($email, $existing_internal_email_addresses)) {
                        $csverrors->add($i, get_string('uploadcsverroremailaddresstaken', 'admin', $i, $email));
                    }
                }
            }
        }
        $emails[$email] = 1;
        if (isset($remoteusers) && $remoteuser) {
            if (isset($remoteusers[$remoteuser])) {
                $csverrors->add($i, get_string('uploadcsverrorduplicateremoteuser', 'admin', $i, $remoteuser));
            } else {
                if (!$values['updateusers']) {
                    if ($remoteuserowner = get_record_sql('
                    SELECT u.username
                    FROM {auth_remote_user} aru JOIN {usr} u ON aru.localusr = u.id
                    WHERE aru.remoteusername = ? AND aru.authinstance = ?', array($remoteuser, $authinstance))) {
                        $csverrors->add($i, get_string('uploadcsverrorremoteusertaken', 'admin', $i, $remoteuser, $remoteuserowner->username));
                    }
                }
            }
            $remoteusers[$remoteuser] = true;
        }
        // If we didn't even get a username, we can't check for duplicates, so move on.
        if (strlen($username) < 1) {
            continue;
        }
        if (isset($usernames[strtolower($username)])) {
            // Duplicate username within this file.
            $csverrors->add($i, get_string('uploadcsverroruseralreadyexists', 'admin', $i, $username));
        } else {
            if (!$values['updateusers'] && array_key_exists(strtolower($username), $existing_usernames)) {
                $csverrors->add($i, get_string('uploadcsverroruseralreadyexists', 'admin', $i, $username));
            }
            $usernames[strtolower($username)] = array('username' => $username, 'password' => $password, 'email' => $email, 'lineno' => $i, 'raw' => $line);
            if (!empty($remoteuser) && !empty($remoteusers[$remoteuser])) {
                $usernames[strtolower($username)]['remoteuser'] = $remoteuser;
            }
        }
    }
    // If the admin is trying to overwrite existing users, identified by username,
    // this second pass performs some additional checks
    if ($values['updateusers']) {
        $key = 0;
        foreach ($usernames as $lowerusername => $data) {
            if (!($key % 25)) {
                set_progress_info('uploaduserscsv', $num_lines + $key, $num_lines * $steps_total, get_string('checkingupdates', 'admin'));
            }
            $key++;
            $line = $data['lineno'];
            $username = $data['username'];
            $password = $data['password'];
            $email = $data['email'];
            // If the user already exists, they must already be in this institution.
            $userinstitutions = get_records_sql_assoc("\n                SELECT COALESCE(ui.institution, 'mahara') AS institution, u.id\n                FROM {usr} u LEFT JOIN {usr_institution} ui ON u.id = ui.usr\n                WHERE LOWER(u.username) = ?", array($lowerusername));
            if ($userinstitutions) {
                if (!isset($userinstitutions[$institution])) {
                    if ($institution == 'mahara') {
                        $institutiondisplay = array();
                        foreach ($userinstitutions as $i) {
                            $institutiondisplay[] = $INSTITUTIONNAME[$i->institution];
                        }
                        $institutiondisplay = join(', ', $institutiondisplay);
                        $message = get_string('uploadcsverroruserinaninstitution', 'admin', $line, $username, $institutiondisplay);
                    } else {
                        $message = get_string('uploadcsverrorusernotininstitution', 'admin', $line, $username, $INSTITUTIONNAME[$institution]);
                    }
                    $csverrors->add($line, $message);
                } else {
                    // Remember that this user is being updated
                    $UPDATES[$username] = 1;
                }
            } else {
                // New user, check the password
                if (method_exists($authobj, 'is_password_valid') && !$authobj->is_password_valid($password)) {
                    $csverrors->add($line, get_string('uploadcsverrorinvalidpassword', 'admin', $line));
                }
            }
            // Check if the email already exists and if it's owned by this user.  This query can return more
            // than one row when there are duplicate emails already on the site.  If that happens, things are
            // already a bit out of hand, and we'll just allow an update if this user is one of the users who
            // owns the email.
            $emailowned = get_records_sql_assoc('
                SELECT LOWER(u.username) AS lowerusername, ae.principal FROM {usr} u
                LEFT JOIN {artefact_internal_profile_email} ae ON u.id = ae.owner AND ae.verified = 1 AND ae.email = ?
                WHERE ae.owner IS NOT NULL OR u.email = ?', array($email, $email));
            // If the email is owned by someone else, it could still be okay provided
            // that other user's email is also being changed in this csv file.
            if ($emailowned && !isset($emailowned[$lowerusername])) {
                foreach ($emailowned as $e) {
                    // Only primary emails can be set in uploadcsv, so it's an error when someone else
                    // owns the email as a secondary.
                    if (!$e->principal) {
                        $csverrors->add($line, get_string('uploadcsverroremailaddresstaken', 'admin', $line, $email));
                        break;
                    }
                    // It's also an error if the email owner is not being updated in this file
                    if (!isset($usernames[$e->lowerusername])) {
                        $csverrors->add($line, get_string('uploadcsverroremailaddresstaken', 'admin', $line, $email));
                        break;
                    }
                    // If the other user is being updated in this file, but isn't changing their
                    // email address, it's ok, we've already notified duplicate emails within the file.
                }
            }
            if (isset($remoteusers) && !empty($data['remoteuser'])) {
                $remoteuser = $data['remoteuser'];
                $remoteuserowner = get_field_sql('
                    SELECT LOWER(u.username)
                    FROM {usr} u JOIN {auth_remote_user} aru ON u.id = aru.localusr
                    WHERE aru.remoteusername = ? AND aru.authinstance = ?', array($remoteuser, $authinstance));
                if ($remoteuserowner && $remoteuserowner != $lowerusername && !isset($usernames[$remoteuserowner])) {
                    // The remote username is owned by some other user who is not being updated in this file
                    $csverrors->add($line, get_string('uploadcsverrorremoteusertaken', 'admin', $line, $remoteuser, $remoteuserowner));
                }
            }
        }
    }
    if ($errors = $csverrors->process()) {
        $form->set_error('file', clean_html($errors), false);
        return;
    }
    $FORMAT = $csvdata->format;
    $CSVDATA = $csvdata->data;
}
 /**
  * ฟังก์ชั่นส่งเมล์แบบกำหนดรายละเอียดเอง
  *
  * @param string $mailto ที่อยู่อีเมล์ผู้รับ  คั่นแต่ละรายชื่อด้วย ,
  * @param string $replyto ที่อยู่อีเมล์สำหรับการตอบกลับจดหมาย ถ้าระบุเป็นค่าว่างจะใช้ที่อยู่อีเมล์จาก noreply_email
  * @param string $subject หัวข้อจดหมาย
  * @param string $msg รายละเอียดของจดหมาย (รองรับ HTML)
  * @return string สำเร็จคืนค่าว่าง ไม่สำเร็จ คืนค่าข้อความผิดพลาด
  */
 public static function send($mailto, $replyto, $subject, $msg)
 {
     $charset = empty(self::$cfg->email_charset) ? 'utf-8' : strtolower(self::$cfg->email_charset);
     if (empty($replyto)) {
         $replyto = array(self::$cfg->noreply_email, strip_tags(self::$cfg->web_title));
     } elseif (preg_match('/^(.*)<(.*?)>$/', $replyto, $match)) {
         $replyto = array($match[1], empty($match[2]) ? $match[1] : $match[2]);
     } else {
         $replyto = array($replyto, $replyto);
     }
     if ($charset !== 'utf-8') {
         $subject = iconv('utf-8', $charset, $subject);
         $msg = iconv('utf-8', $charset, $msg);
         $replyto[1] = iconv('utf-8', $charset, $replyto[1]);
     }
     $messages = array();
     if (empty(self::$cfg->email_use_phpMailer)) {
         // ส่งอีเมล์ด้วยฟังก์ชั่นของ PHP
         foreach (explode(',', $mailto) as $email) {
             $headers = "MIME-Version: 1.0\r\n";
             $headers .= "Content-type: text/html; charset={$charset}\r\n";
             $headers .= "Content-Transfer-Encoding: quoted-printable\r\n";
             $headers .= "To: {$email}\r\n";
             $headers .= "From: {$replyto['1']}\r\n";
             $headers .= "Reply-to: {$replyto['0']}\r\n";
             $headers .= "X-Mailer: PHP mailer\r\n";
             if (!@mail($email, $subject, $msg, $headers)) {
                 $messages = array(Language::get('Unable to send mail'));
             }
         }
     } else {
         // ส่งอีเมล์ด้วย PHPMailer
         include_once VENDOR_DIR . 'PHPMailer/class.phpmailer.php';
         // Create a new PHPMailer instance
         $mail = new \PHPMailer();
         // Tell PHPMailer to use SMTP
         $mail->isSMTP();
         // charset
         $mail->CharSet = $charset;
         // use html
         $mail->IsHTML();
         $mail->SMTPAuth = empty(self::$cfg->email_SMTPAuth) ? false : true;
         if ($mail->SMTPAuth) {
             $mail->Username = self::$cfg->email_Username;
             $mail->Password = self::$cfg->email_Password;
             $mail->SMTPSecure = self::$cfg->email_SMTPSecure;
         }
         if (!empty(self::$cfg->email_Host)) {
             $mail->Host = self::$cfg->email_Host;
         }
         if (!empty(self::$cfg->email_Port)) {
             $mail->Port = self::$cfg->email_Port;
         }
         $mail->AddReplyTo($replyto[0], $replyto[1]);
         $mail->SetFrom(self::$cfg->noreply_email, strip_tags(self::$cfg->web_title));
         // subject
         $mail->Subject = $subject;
         // message
         $mail->MsgHTML(preg_replace('/(<br([\\s\\/]{0,})>)/', "\$1\r\n", $msg));
         $mail->AltBody = strip_tags($msg);
         foreach (explode(',', $mailto) as $email) {
             if (preg_match('/^(.*)<(.*)>$/', $email, $match)) {
                 if ($mail->ValidateAddress($match[1])) {
                     $mail->AddAddress($match[1], $match[2]);
                 }
             } else {
                 if ($mail->ValidateAddress($email)) {
                     $mail->AddAddress($email, $email);
                 }
             }
             if (false === $mail->send()) {
                 $messages[$mail->ErrorInfo] = $mail->ErrorInfo;
             }
             $mail->clearAddresses();
         }
     }
     return empty($messages) ? '' : implode("\n", $messages);
 }
Example #9
0
<?php

require_once 'class.phpmailer.php';
$_POST = array_map('trim', $_POST);
$error = false;
if (!isset($_POST['contact_name']) || empty($_POST['contact_name'])) {
    $error = true;
}
if (!isset($_POST['contact_email']) || empty($_POST['contact_email']) || !PHPMailer::ValidateAddress($_POST['contact_email'])) {
    $error = true;
}
if (!isset($_POST['contact_body']) || empty($_POST['contact_body'])) {
    $error = true;
}
if (!isset($_POST['contact_check']) || empty($_POST['contact_check']) || (int) $_POST['contact_check'] !== (int) $_POST['contact_check_data'][0] + (int) $_POST['contact_check_data'][1]) {
    $error = true;
}
if ($error) {
    exit('nok');
}
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->SetFrom($_POST['contact_email'], $_POST['contact_name']);
$mail->AddAddress('*****@*****.**');
$mail->Subject = 'Wiadomość ze strony internetowej';
$mail->Body = $_POST['contact_body'];
if (!$mail->Send()) {
    exit('nok');
}
exit('ok');
Example #10
0
 public function parseEmailTo($string)
 {
     if (empty($string)) {
         return false;
     }
     $mailingList = array();
     $splitString = explode(',', $string);
     require_once 'protected/components/phpMailer/class.phpmailer.php';
     foreach ($splitString as &$token) {
         $token = trim($token);
         if (empty($token)) {
             continue;
         }
         $matches = array();
         if (PHPMailer::ValidateAddress($token)) {
             // if it's just a simple email, we're done!
             $mailingList[] = array('', $token);
         } else {
             if (preg_match('/^"?([^"]*)"?\\s*<(.+)>$/i', $token, $matches)) {
                 if (count($matches) == 3 && PHPMailer::ValidateAddress($matches[2])) {
                     $mailingList[] = array($matches[1], $matches[2]);
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         }
     }
     if (count($mailingList) < 1) {
         return false;
     }
     return $mailingList;
 }
Example #11
0
/**
 * check to see that the format is valid and that the mx record exists
 * @param string $p_email An email address.
 * @return boolean
 */
function email_is_valid($p_email)
{
    $t_validate_email = config_get('validate_email');
    # if we don't validate then just accept
    # If blank email is allowed or current user is admin, then accept blank emails which are useful for
    # accounts that should never receive email notifications (e.g. anonymous account)
    if (OFF == $t_validate_email || ON == config_get('use_ldap_email') || is_blank($p_email) && (ON == config_get('allow_blank_email') || current_user_is_administrator())) {
        return true;
    }
    # E-mail validation method
    # Note: PHPMailer offers alternative validation methods.
    # It was decided in PR 172 (https://github.com/mantisbt/mantisbt/pull/172)
    # to just default to HTML5 without over-complicating things for end users
    # by offering a potentially confusing choice between the different methods.
    # Refer to PHPMailer documentation for ValidateAddress method for details.
    # @link https://github.com/PHPMailer/PHPMailer/blob/v5.2.9/class.phpmailer.php#L863
    $t_method = 'html5';
    # check email address is a valid format
    log_event(LOG_EMAIL_VERBOSE, "Validating address '{$p_email}' with method '{$t_method}'");
    if (PHPMailer::ValidateAddress($p_email, $t_method)) {
        $t_domain = substr($p_email, strpos($p_email, '@') + 1);
        # see if we're limited to a set of known domains
        $t_limit_email_domains = config_get('limit_email_domains');
        if (!empty($t_limit_email_domains)) {
            foreach ($t_limit_email_domains as $t_email_domain) {
                if (0 == strcasecmp($t_email_domain, $t_domain)) {
                    return true;
                    # no need to check mx record details (below) if we've explicity allowed the domain
                }
            }
            log_event(LOG_EMAIL, "failed - not in limited domains list '{$t_limit_email_domains}'");
            return false;
        }
        if (ON == config_get('check_mx_record')) {
            $t_mx = '';
            # Check for valid mx records
            if (getmxrr($t_domain, $t_mx)) {
                return true;
            } else {
                $t_host = $t_domain . '.';
                # for no mx record... try dns check
                if (checkdnsrr($t_host, 'ANY')) {
                    return true;
                }
                log_event(LOG_EMAIL, "failed - mx/dns record check");
            }
        } else {
            # Email format was valid but didn't check for valid mx records
            return true;
        }
    } else {
        log_event(LOG_EMAIL, "failed - invalid address");
    }
    # Everything failed.  The email is invalid
    return false;
}
Example #12
0
 /**
  * @param string $emailAddress a given email address to be validated
  * @return bool
  */
 public static function validateAddress($emailAddress)
 {
     if (strpos($emailAddress, '@') === false) {
         return false;
     }
     $emailAddress = self::buildAsciiEmail($emailAddress);
     return PHPMailer::ValidateAddress($emailAddress);
 }
Example #13
0
 /**
  * validate_address
  *
  * Checks whether what we have looks like a valid address.
  */
 public static function validate_address($address)
 {
     return PHPMailer::ValidateAddress($address);
 }
Example #14
0
 if ($message == "" && !isset($error_message)) {
     $error_message = "We would love to hear from you, but please specify a message before submitting the form.";
 }
 if (!isset($error_message)) {
     foreach ($_POST as $value) {
         if (stripos($value, 'Content-Type:') !== FALSE) {
             $error_message = "There was a problem with the information entered.";
         }
     }
 }
 if ($_POST["address"] != "" && !isset($error_message)) {
     $error_message = "Your form submission has an error.";
 }
 require_once "inc/class.phpmailer.php";
 $mail = new PHPMailer();
 if (!$mail->ValidateAddress($email) && !isset($error_message)) {
     $error_message = "You must use a valid email address in order to contact us.";
 }
 if (!isset($error_message)) {
     $email_body = "";
     $email_body = $email_body . "Name: " . $name . "<br />";
     //line break in source code
     $email_body = $email_body . "Email: " . $email . "<br />";
     $email_body = $email_body . "Message: " . $message;
     echo $email_body;
     //if refresh process page it might resubmit email
     $mail->SetFrom($email, $name);
     $address = "*****@*****.**";
     $mail->AddAddress($address, "Shirts 4 Mike");
     $mail->Subject = "Contact Form Submission " . $name;
     $mail->MsgHTML($email_body);
Example #15
0
/**
 * check to see that the format is valid and that the mx record exists
 * @param string $p_email An email address.
 * @return boolean
 */
function email_is_valid( $p_email ) {
	# if we don't validate then just accept
	if( OFF == config_get( 'validate_email' ) ||
		ON == config_get( 'use_ldap_email' ) ||
		( is_blank( $p_email ) && ON == config_get( 'allow_blank_email' ) )
	) {
		return true;
	}

	# check email address is a valid format
	$t_email = filter_var( $p_email, FILTER_SANITIZE_EMAIL );
	if( PHPMailer::ValidateAddress( $t_email ) ) {
		$t_domain = substr( $t_email, strpos( $t_email, '@' ) + 1 );

		# see if we're limited to a set of known domains
		$t_limit_email_domains = config_get( 'limit_email_domains' );
		if( !empty( $t_limit_email_domains ) ) {
			foreach( $t_limit_email_domains as $t_email_domain ) {
				if( 0 == strcasecmp( $t_email_domain, $t_domain ) ) {
					return true; # no need to check mx record details (below) if we've explicity allowed the domain
				}
			}
			return false;
		}

		if( ON == config_get( 'check_mx_record' ) ) {
			$t_mx = '';

			# Check for valid mx records
			if( getmxrr( $t_domain, $t_mx ) ) {
				return true;
			} else {
				$t_host = $t_domain . '.';

				# for no mx record... try dns check
				if( checkdnsrr( $t_host, 'ANY' ) ) {
					return true;
				}
			}
		} else {
			# Email format was valid but did't check for valid mx records
			return true;
		}
	}

	# Everything failed.  The email is invalid
	return false;
}
Example #16
0
 $email2 = trim($_POST["email2"]);
 $message2 = trim($_POST["message2"]);
 $to2 = '*****@*****.**';
 if ($name2 == "" or $email2 == "" or $message2 == "") {
     echo "Completați toate secțiunile.";
     exit;
 }
 foreach ($_POST as $value) {
     if (stripos($value, 'Content-Type:') !== FALSE) {
         echo "Ați comis o eroare, încercați din nou";
         exit;
     }
 }
 require_once "phpmailer/class.phpmailer.php";
 $mail2 = new PHPMailer();
 if (!$mail2->ValidateAddress($email2)) {
     echo "Specificați o adresa validă.";
     exit;
 }
 $email_body2 = "";
 $email_body2 = $email_body2 . "Name: " . $name2 . "\n";
 $email_body2 = $email_body2 . "Email: " . $email2 . "\n";
 $email_body2 = $email_body2 . "Message: " . $message2;
 //$mail->SetFrom($email, $name);
 //$address = "*****@*****.**";
 //$mail->AddAddress($address, "Nicolae Mih");
 //$mail->Subject    = "roboclub" . $name;
 //$mail->MsgHTML($email_body);
 mail($to2, $name2, $email_body2, $email2);
 // if(!$mail2->Send()) {
 //  echo "Mailer Error: " . $mail2->ErrorInfo;
 function ValidateEmail($Value, $Field = '')
 {
     $Result = PHPMailer::ValidateAddress($Value);
     $Result = (bool) $Result;
     return $Result;
 }
Example #18
0
    $main_stylesheet = str_replace($replace_string, '', $main_stylesheet);
    // embed the stylesheet in the raw xml file
    $replace_string = '<ContinuityOfCareRecord xmlns="urn:astm-org:CCR">';
    $main_stylesheet = $replace_string . $main_stylesheet;
    $main_xml = str_replace($replace_string, $main_stylesheet, $main_xml);
    // insert style1 id into the stylesheet parameter
    $substitute_string = 'xsl:stylesheet id="style1" exclude-result-prefixes';
    $replace_string = 'xsl:stylesheet exclude-result-prefixes';
    $main_xml = str_replace($replace_string, $substitute_string, $main_xml);
    // prepare the filename to use
    //   LASTNAME-FIRSTNAME-PID-DATESTAMP-ccr.xml
    $main_filename = getReportFilename() . "-ccr.xml";
    // send the output as a file to the user
    header("Content-type: text/xml");
    header("Content-Disposition: attachment; filename=" . $main_filename . "");
    echo $main_xml;
}
if ($_POST['ccrAction']) {
    $raw = $_POST['raw'];
    /* If transmit requested, fail fast if the recipient address fails basic validation */
    if (substr($raw, 0, 4) == "send") {
        $send_to = trim(stripslashes(substr($raw, 5)));
        if (!PHPMailer::ValidateAddress($send_to)) {
            echo htmlspecialchars(xl('Invalid recipient address. Please try again.'), ENT_QUOTES);
            return;
        }
        createCCR($_POST['ccrAction'], $raw, $_POST['requested_by']);
    } else {
        createCCR($_POST['ccrAction'], $raw);
    }
}
Example #19
0
 //Protection against email header injection attack
 if (!isset($error_message)) {
     foreach ($_POST as $value) {
         if (stripos($value, 'Content-Type:') !== FALSE) {
             $error_message = "There was a problem with the information you entered.";
         }
     }
 }
 //Protection against comment spam bot (Spam Honey Pot)
 if (!isset($error_message) and $_POST["address"] != "") {
     $error_message = "Your form submission has an error.";
 }
 //Include PHPMailer Library and validate email field format
 require_once ROOT_PATH . "inc/lib/phpmailer/class.phpmailer.php";
 $mail = new PHPMailer();
 if (!isset($error_message) and !$mail->ValidateAddress($email)) {
     $error_message = "You must enter a valid email address.";
 }
 if (!isset($error_message)) {
     //Echo form data to the browser
     $email_body = "";
     $email_body = $email_body . "Name: " . $name . "<br>";
     $email_body = $email_body . "Email: " . $email . "<br>";
     $email_body = $email_body . "Message: " . $message . "<br>";
     //echo $email_body;
     //***************CODE FOR SENDING EMAIL BEGINS***************//
     $mail->From = $email;
     $mail->FromName = $name;
     $address = "*****@*****.**";
     $mail->addAddress($address, 'Shirts 4 Mike');
     $mail->Subject = 'Shirts 4 Mike Contact Form Submission | ' . $name;
 function ValidateEmail($Value, $Field = '')
 {
     if (is_null($Value)) {
         return TRUE;
     }
     // if (!ValidateRequired($Value))
     //    return TRUE;
     if (class_exists('PHPMailer')) {
         $Result = PHPMailer::ValidateAddress($Value);
     } else {
         $Result = preg_match('/^(?!(?>(?1)"?(?>\\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\\x0D\\x0A)?[  ])+|(?>[    ]*\\x0D\\x0A)?[  ]+)?)(\\((?>(?2)(?>[\\x01-\\x08\\x0B\\x0C\\x0E-\'*-\\[\\]-\\x7F]|\\\\[\\x00-\\x7F]|(?3)))*(?2)\\)))+(?2))|(?2))?)([!#-\'*+\\/-9=?^-~-]+|"(?>(?2)(?>[\\x01-\\x08\\x0B\\x0C\\x0E-!#-\\[\\]-\\x7F]|\\\\[\\x00-\\x7F]))*(?2)")(?>(?1)\\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\\.(?9)){3}))\\])(?1)$/isD', $Value);
     }
     $Result = (bool) $Result;
     return $Result;
 }
Example #21
0
 /**
  * Test email address validation
  * Test addresses obtained from http://isemail.info
  * Some failing cases commented out that are apparently up for debate!
  */
 function testValidate()
 {
     $validaddresses = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '"first\\"last"@iana.org', '"first@last"@iana.org', '"first\\last"@iana.org', 'first.last@[12.34.56.78]', 'first.last@[IPv6:::12.34.56.78]', 'first.last@[IPv6:1111:2222:3333::4444:12.34.56.78]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78]', 'first.last@[IPv6:::1111:2222:3333:4444:5555:6666]', 'first.last@[IPv6:1111:2222:3333::4444:5555:6666]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666::]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]', '*****@*****.**', '*****@*****.**', '*****@*****.**', '"first\\last"@iana.org', 'first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78]', 'first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777]', 'first.last@example.123', 'first.last@com', '"Abc\\@def"@iana.org', '"Fred\\ Bloggs"@iana.org', '"Joe.\\Blow"@iana.org', '"Abc@def"@iana.org', '"Fred Bloggs"@iana.org', '*****@*****.**', 'customer/department=shipping@iana.org', '$A12345@iana.org', '!def!xyz%abc@iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', '"Doug \\"Ace\\" L."@iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', 't*est@iana.org', '+1~1+@iana.org', '{_test_}@iana.org', '"[[ test ]]"@iana.org', '*****@*****.**', '"test.test"@iana.org', 'test."test"@iana.org', '"test@test"@iana.org', 'test@123.123.123.x123', 'test@123.123.123.123', 'test@[123.123.123.123]', '*****@*****.**', '*****@*****.**', '"test\\test"@iana.org', 'test@example', '"test\\blah"@iana.org', '"test\\blah"@iana.org', '"test\\"blah"@iana.org', 'customer/department@iana.org', '*****@*****.**', '~@iana.org', '"Austin@Powers"@iana.org', '*****@*****.**', '"Ima.Fool"@iana.org', '"Ima Fool"@iana.org', '"first"."last"@iana.org', '"first".middle."last"@iana.org', '"first"*****@*****.**', 'first."last"@iana.org', '"first"."middle"."last"@iana.org', '"first.middle"."last"@iana.org', '"first.middle.last"@iana.org', '"first..last"@iana.org', '"first\\"last"@iana.org', 'first."mid\\dle"."last"@iana.org', '"test blah"@iana.org', '(foo)cal(bar)@(baz)iamcal.com(quux)', 'cal@iamcal(woo).(yay)com', 'cal(woo(yay)hoopla)@iamcal.com', 'cal(foo\\@bar)@iamcal.com', 'cal(foo\\)bar)@iamcal.com', 'first().last@iana.org', 'pete(his account)@silly.test(his host)', 'c@(Chris\'s host.)public.example', 'jdoe@machine(comment). example', '1234 @ local(blah) .machine .example', 'first(abc.def).last@iana.org', 'first(a"bc.def).last@iana.org', 'first.(")middle.last(")@iana.org', 'first(abc\\(def)@iana.org', 'first.last@x(1234567890123456789012345678901234567890123456789012345678901234567890).com', 'a(a(b(c)d(e(f))g)h(i)j)@iana.org', '*****@*****.**', 'a@b', '*****@*****.**', 'aaa@[123.123.123.123]', 'a@bar', '*****@*****.**', '+@b.c', '*****@*****.**', '*****@*****.**', '"hello my name is"@stutter.com', '"Test \\"Fail\\" Ing"@iana.org', '*****@*****.**', '*****@*****.**', 'foobar@192.168.0.1', '"Joe\\Blow"@iana.org', 'HM2Kinsists@(that comments are allowed)this.is.ok', 'user%uucp!path@berkeley.edu', 'first.last @iana.org', 'cdburgess+!#$%&\'*-/=?+_{}|~test@gmail.com', 'first.last@[IPv6:::a2:a3:a4:b1:b2:b3:b4]', 'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3::]', 'first.last@[IPv6:::]', 'first.last@[IPv6:::b4]', 'first.last@[IPv6:::b3:b4]', 'first.last@[IPv6:a1::b4]', 'first.last@[IPv6:a1::]', 'first.last@[IPv6:a1:a2::]', 'first.last@[IPv6:0123:4567:89ab:cdef::]', 'first.last@[IPv6:0123:4567:89ab:CDEF::]', 'first.last@[IPv6:::a3:a4:b1:ffff:11.22.33.44]', 'first.last@[IPv6:::a2:a3:a4:b1:ffff:11.22.33.44]', 'first.last@[IPv6:a1:a2:a3:a4::11.22.33.44]', 'first.last@[IPv6:a1:a2:a3:a4:b1::11.22.33.44]', 'first.last@[IPv6:a1::11.22.33.44]', 'first.last@[IPv6:a1:a2::11.22.33.44]', 'first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.44]', 'first.last@[IPv6:0123:4567:89ab:CDEF::11.22.33.44]', 'first.last@[IPv6:a1::b2:11.22.33.44]', '*****@*****.**', '*****@*****.**', '*****@*****.**');
     $invalidaddresses = array('first.last@sub.do,com', 'first\\@last@iana.org', '123456789012345678901234567890123456789012345678901234567890@12345678901234567890123456789012345678901234 [...]', 'first.last', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '"first"last"@iana.org', '"""@iana.org', '"\\"@iana.org', 'first\\@last@iana.org', 'first.last@', 'x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23 [...]', 'first.last@[.12.34.56.78]', 'first.last@[12.34.56.789]', 'first.last@[::12.34.56.78]', 'first.last@[IPv5:::12.34.56.78]', 'first.last@[IPv6:1111:2222:3333:4444:5555:12.34.56.78]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:12.34.56.78]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]', 'first.last@[IPv6:1111:2222::3333::4444:5555:6666]', 'first.last@[IPv6:1111:2222:333x::4444:5555]', 'first.last@[IPv6:1111:2222:33333::4444:5555]', '*****@*****.**', '*****@*****.**', '*****@*****.**', 'abc\\@def@iana.org', 'abc\\@iana.org', 'Doug\\ \\"Ace\\"\\ Lovell@iana.org', 'abc@def@iana.org', 'abc\\@def@iana.org', 'abc\\@iana.org', '@iana.org', 'doug@', '"*****@*****.**', 'ote"@iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', '"Doug "Ace" L."@iana.org', 'Doug\\ \\"Ace\\"\\ L\\.@iana.org', 'hello world@iana.org', 'gatsby@f.sc.ot.t.f.i.tzg.era.l.d.', 'test.iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', 'test@test@iana.org', 'test@@iana.org', '-- test --@iana.org', '[test]@iana.org', '"test"test"@iana.org', '()[]\\;:,><@iana.org', 'test@.', 'test@example.', 'test@.org', 'test@1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 [...]', 'test@[123.123.123.123', 'test@123.123.123.123]', 'NotAnEmail', '@NotAnEmail', '"test"blah"@iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', 'Ima Fool@iana.org', 'phil.h\\@\\@ck@haacked.com', 'foo@[\\1.2.3.4]', 'first\\last@iana.org', 'Abc\\@def@iana.org', 'Fred\\ Bloggs@iana.org', 'Joe.\\Blow@iana.org', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.567.89]', '{^c\\@**Dog^}@cartoon.com', 'cal(foo(bar)@iamcal.com', 'cal(foo)bar)@iamcal.com', 'cal(foo\\)@iamcal.com', 'first(12345678901234567890123456789012345678901234567890)last@(123456789012345678901234567890123456789012 [...]', 'first(middle)last@iana.org', 'first(abc("def".ghi).mno)middle(abc("def".ghi).mno).last@(abc("def".ghi).mno)example(abc("def".ghi).mno). [...]', 'a(a(b(c)d(e(f))g)(h(i)j)@iana.org', '.@', '@bar.com', '@@bar.com', 'aaa.com', 'aaa@.com', 'aaa@.123', 'aaa@[123.123.123.123]a', 'aaa@[123.123.123.333]', 'a@bar.com.', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', 'invalid@about.museum-', '*****@*****.**', '"Unicode NULL' . chr(0) . '"@char.com', 'Unicode NULL' . chr(0) . '@char.com', 'first.last@[IPv6::]', 'first.last@[IPv6::::]', 'first.last@[IPv6::b4]', 'first.last@[IPv6::::b4]', 'first.last@[IPv6::b3:b4]', 'first.last@[IPv6::::b3:b4]', 'first.last@[IPv6:a1:::b4]', 'first.last@[IPv6:a1:]', 'first.last@[IPv6:a1:::]', 'first.last@[IPv6:a1:a2:]', 'first.last@[IPv6:a1:a2:::]', 'first.last@[IPv6::11.22.33.44]', 'first.last@[IPv6::::11.22.33.44]', 'first.last@[IPv6:a1:11.22.33.44]', 'first.last@[IPv6:a1:::11.22.33.44]', 'first.last@[IPv6:a1:a2:::11.22.33.44]', 'first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.xx]', 'first.last@[IPv6:0123:4567:89ab:CDEFF::11.22.33.44]', 'first.last@[IPv6:a1::a4:b1::b4:11.22.33.44]', 'first.last@[IPv6:a1::11.22.33]', 'first.last@[IPv6:a1::11.22.33.44.55]', 'first.last@[IPv6:a1::b211.22.33.44]', 'first.last@[IPv6:a1::b2::11.22.33.44]', 'first.last@[IPv6:a1::b3:]', 'first.last@[IPv6::a2::b4]', 'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3:]', 'first.last@[IPv6::a2:a3:a4:b1:b2:b3:b4]', 'first.last@[IPv6:a1:a2:a3:a4::b1:b2:b3:b4]');
     $goodfails = array();
     foreach ($validaddresses as $address) {
         if (!PHPMailer::ValidateAddress($address)) {
             $goodfails[] = $address;
             //"Valid address <$address> failed validation"
         }
     }
     $badpasses = array();
     foreach ($invalidaddresses as $address) {
         if (PHPMailer::ValidateAddress($address)) {
             $badpasses[] = $address;
         }
     }
     $err = '';
     if (count($goodfails) > 0) {
         $err .= "Good addreses that failed validation:\n";
         $err .= implode("\n", $goodfails);
     }
     if (count($badpasses) > 0) {
         if (!empty($err)) {
             $err .= "\n\n";
         }
         $err .= "Bad addreses that passed validation:\n";
         $err .= implode("\n", $badpasses);
     }
     $this->assertEmpty($err, $err);
 }
Example #22
0
 public function parseEmailTo($string)
 {
     if (empty($string)) {
         return false;
     }
     $mailingList = array();
     $splitString = explode(',', $string);
     require_once 'protected/components/phpMailer/class.phpmailer.php';
     foreach ($splitString as &$token) {
         $token = trim($token);
         if (empty($token)) {
             continue;
         }
         $matches = array();
         if (PHPMailer::ValidateAddress($token)) {
             // if it's just a simple email, we're done!
             $mailingList[] = array('', $token);
         } else {
             if (preg_match('/^"?([^"]*)"?\\s*<(.+)>$/i', $token, $matches)) {
                 if (count($matches) == 3 && PHPMailer::ValidateAddress($matches[2])) {
                     $mailingList[] = array($matches[1], $matches[2]);
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         }
         // if(preg_match('/^"(.*)"/i',$token,$matches)) {        // if there is a name like <First Last> at the beginning,
         // $token = trim(preg_replace('/^".*"/i','',$token));    // remove it
         // if(isset($matches[1]))
         // $name = trim($matches[1]);                        // and put it in $name
         // }
         // $address = trim(preg_replace($token);
         // if(PHPMailer::ValidateAddress($address))
         // $mailingList[] = array($address,$name);
         // else
         // return false;
     }
     // echo var_dump($mailingList);
     if (count($mailingList) < 1) {
         return false;
     }
     return $mailingList;
 }
Example #23
0
 *
 * @copyright  (c) the authors
 * @author     Florian Lippert <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Cron
 *
 */
$cronlog->logAction(CRON_ACTION, LOG_INFO, 'Web- and Traffic-usage reporting started...');
$yesterday = time() - 60 * 60 * 24;
/**
 * Initialize the mailingsystem
 */
$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
if (PHPMailer::ValidateAddress(Settings::Get('panel.adminmail')) !== false) {
    // set return-to address and custom sender-name, see #76
    $mail->SetFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));
    if (Settings::Get('panel.adminmail_return') != '') {
        $mail->AddReplyTo(Settings::Get('panel.adminmail_return'), Settings::Get('panel.adminmail_defname'));
    }
}
// Warn the customers at xx% traffic-usage
$result_stmt = Database::prepare("\n\tSELECT `c`.`customerid`, `c`.`adminid`, `c`.`name`, `c`.`firstname`,\n\t`c`.`company`, `c`.`traffic`, `c`.`email`, `c`.`def_language`,\n\t`a`.`name` AS `adminname`, `a`.`email` AS `adminmail`,\n\t(SELECT SUM(`t`.`http` + `t`.`ftp_up` + `t`.`ftp_down` + `t`.`mail`)\n\tFROM `" . TABLE_PANEL_TRAFFIC . "` `t`\n\tWHERE `t`.`customerid` = `c`.`customerid` AND `t`.`year` = :year AND `t`.`month` = :month\n\t) as `traffic_used`\n\tFROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c`\n\tLEFT JOIN `" . TABLE_PANEL_ADMINS . "` AS `a`\n\tON `a`.`adminid` = `c`.`adminid` WHERE `c`.`reportsent` <> '1'\n");
$result_data = array('year' => date("Y", $yesterday), 'month' => date("m", $yesterday));
Database::pexecute($result_stmt, $result_data);
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
    if (isset($row['traffic']) && $row['traffic'] > 0 && $row['traffic_used'] != null && $row['traffic_used'] * 100 / $row['traffic'] >= (int) Settings::Get('system.report_trafficmax')) {
        $rep_userinfo = array('name' => $row['name'], 'firstname' => $row['firstname'], 'company' => $row['company']);
        $replace_arr = array('SALUTATION' => getCorrectUserSalutation($rep_userinfo), 'NAME' => $row['name'], 'TRAFFIC' => round($row['traffic'] / 1024, 2), 'TRAFFICUSED' => round($row['traffic_used'] / 1024, 2), 'USAGE_PERCENT' => round($row['traffic_used'] * 100 / $row['traffic'], 2), 'MAX_PERCENT' => Settings::Get('system.report_trafficmax'));
        $lngfile_stmt = Database::prepare("\n\t\t\tSELECT `file` FROM `" . TABLE_PANEL_LANGUAGE . "`\n\t\t\tWHERE `language` = :deflang\n\t\t");
Example #24
0
/**
 * check to see that the format is valid and that the mx record exists
 * @param string $p_email
 * @return bool
 */
function email_is_valid($p_email)
{
    # if we don't validate then just accept
    if (OFF == config_get('validate_email')) {
        return true;
    }
    if (LDAP == config_get('login_method') && ON == config_get('use_ldap_email')) {
        return true;
    }
    if (is_blank($p_email) && ON == config_get('allow_blank_email')) {
        return true;
    }
    # Delegate email validation to PHPMailer
    if (PHPMailer::ValidateAddress($p_email)) {
        $t_domain = end(explode('@', $p_email));
        # see if we're limited to one domain
        $t_limit_email_domain = config_get('limit_email_domain');
        if ($t_limit_email_domain !== OFF) {
            if (0 != strcasecmp($t_limit_email_domain, $t_domain)) {
                return false;
            }
        }
        if (ON == config_get('check_mx_record')) {
            $temp = '';
            # Check for valid mx records
            if (getmxrr($t_domain, $temp)) {
                return true;
            } else {
                $host = $t_domain . '.';
                # for no mx record... try dns check
                if (checkdnsrr($host, 'ANY')) {
                    return true;
                }
            }
        } else {
            # Email format was valid but did't check for valid mx records
            return true;
        }
    }
    # Everything failed.  The email is invalid
    return false;
}
Example #25
0
                 $alert[$arr['title']] = 'error';
             }
         }
         if ($arr['valid_type'] != 'none') {
             if ($arr['valid_type'] == 'numeric' && !is_numeric($_POST[$arr['title']])) {
                 $alert[$arr['title']] = array('type' => 'error', 'label' => 'NUMERIC');
             }
             if ($arr['valid_type'] == 'min' && strlen($_POST[$arr['title']]) < $arr['valid_value']) {
                 $alert[$arr['title']] = array('type' => 'error', 'label' => 'MIN');
             }
             if ($arr['valid_type'] == 'max' && strlen($_POST[$arr['title']]) > $arr['valid_value']) {
                 $alert[$arr['title']] = array('type' => 'error', 'label' => 'MAX');
             }
             if ($arr['valid_type'] == 'email') {
                 require FRONTEND . 'include/phpmailer/PHPMailerAutoload.php';
                 if (!PHPMailer::ValidateAddress($_POST[$arr['title']])) {
                     $alert[$arr['title']] = array('type' => 'error', 'label' => 'EMAIL');
                 }
             }
             if ($arr['valid_type'] == 'url' && !filter_var($_POST[$arr['title']], FILTER_VALIDATE_URL) === true) {
                 $alert[$arr['title']] = array('type' => 'error', 'label' => 'URL');
             }
             if ($arr['valid_type'] == 'regex' && !preg_match("/" . $arr['valid_value'] . "/", $_POST[$arr['title']])) {
                 $alert[$arr['title']] = array('type' => 'error', 'label' => 'REGEX');
             }
         }
     }
 }
 $update_parent = true;
 if (!isset($alert)) {
     if (isset($action) && $action == 'edit') {
 function ValidateEmail($Value, $Field = '')
 {
     if (!ValidateRequired($Value)) {
         return TRUE;
     }
     $Result = PHPMailer::ValidateAddress($Value);
     $Result = (bool) $Result;
     return $Result;
 }
Example #27
0
 /**
  * @since 3.0.4
  * is the email really an email (more strict than JMailHelper::isEmailAddress())
  * @param string $email
  * @return bool
  */
 public function isEmail($email)
 {
     $conf = JFactory::getConfig();
     $mail = JFactory::getMailer();
     $mailer = $conf->get('mailer');
     if ($mailer === 'mail') {
         //sendmail and Joomla isEmailAddress dont use the same conditions
         return JMailHelper::isEmailAddress($email) && PHPMailer::ValidateAddress($email);
     }
     return JMailHelper::isEmailAddress($email);
 }
Example #28
0
 /**
  * @param string $emailAddress a given email address to be validated
  * @return bool
  */
 public static function validateAddress($emailAddress)
 {
     $emailAddress = self::buildAsciiEmail($emailAddress);
     return PHPMailer::ValidateAddress($emailAddress);
 }
Example #29
0
 /**
  * @param string $emailAddress a given email address to be validated
  * @return bool
  */
 public static function ValidateAddress($emailAddress)
 {
     return PHPMailer::ValidateAddress($emailAddress);
 }
Example #30
0
function profileform_validate(Pieform $form, $values)
{
    global $profilefields;
    if (!isset($values['email']['default']) || !in_array($values['email']['default'], $profilefields['email']['validated']) || !in_array($values['email']['default'], $values['email']['validated'])) {
        $form->set_error('email', get_string('primaryemailinvalid'));
    }
    if (isset($values['email']['unsent']) && is_array($values['email']['validated'])) {
        require_once 'phpmailer/class.phpmailer.php';
        foreach ($values['email']['unsent'] as $email) {
            if (!PHPMailer::ValidateAddress($email)) {
                $form->set_error('email', get_string('invalidemailaddress', 'artefact.internal') . ': ' . hsc($email));
                break;
            } else {
                if (record_exists('artefact_internal_profile_email', 'email', $email)) {
                    $form->set_error('email', get_string('unvalidatedemailalreadytaken', 'artefact.internal'));
                    break;
                }
            }
        }
    }
}