Beispiel #1
0
 function preInit()
 {
     Pommo::requireOnce($this->_baseDir . 'inc/classes/log.php');
     Pommo::requireOnce($this->_baseDir . 'inc/lib/safesql/SafeSQL.class.php');
     Pommo::requireOnce($this->_baseDir . 'inc/classes/db.php');
     Pommo::requireOnce($this->_baseDir . 'inc/classes/auth.php');
     // initialize logger
     $this->_logger = new PommoLog();
     // NOTE -> this clears messages that may have been retained (not outputted) from logger.
     // read in config.php (configured by user)
     // TODO -> write a web-based frontend to config.php creation
     $config = PommoHelper::parseConfig($this->_baseDir . 'config.php');
     // check to see if config.php was "properly" loaded
     if (count($config) < 5) {
         Pommo::kill('Could not read config.php');
     }
     $this->_workDir = empty($config['workDir']) ? $this->_baseDir . 'cache' : $config['workDir'];
     $this->_debug = strtolower($config['debug']) != 'on' ? false : true;
     $this->_default_subscriber_sort = empty($config['default_subscriber_sort']) ? 'email' : $config['default_subscriber_sort'];
     $this->_verbosity = empty($config['verbosity']) ? 3 : $config['verbosity'];
     $this->_logger->_verbosity = $this->_verbosity;
     $this->_dateformat = $config['date_format'] >= 1 && $cofig['date_format'] <= 3 ? intval($config['date_format']) : 1;
     // the regex strips port info from hostname
     $this->_hostname = empty($config['hostname']) ? preg_replace('/:\\d+$/i', '', $_SERVER['HTTP_HOST']) : $config['hostname'];
     $this->_hostport = empty($config['hostport']) ? $_SERVER['SERVER_PORT'] : $config['hostport'];
     $this->_ssl = !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ? false : true;
     $this->_http = ($this->_ssl ? 'https://' : 'http://') . $this->_hostname;
     if ($this->_hostport != 80 && $this->_hostport != 443) {
         $this->_http .= ':' . $this->_hostport;
     }
     $this->_language = empty($config['lang']) ? 'en' : strtolower($config['lang']);
     $this->_slanguage = defined('_poMMo_lang') ? _poMMo_lang : false;
     // include translation (l10n) methods if language is not English
     $this->_l10n = FALSE;
     if ($this->_language != 'en') {
         $this->_l10n = TRUE;
         Pommo::requireOnce($this->_baseDir . 'inc/helpers/l10n.php');
         PommoHelperL10n::init($this->_language, $this->_baseDir);
     }
     // set base URL (e.g. http://mysite.com/news/pommo => 'news/pommo/')
     // TODO -> provide validation of baseURL ?
     if (isset($config['baseURL'])) {
         $this->_baseUrl = $config['baseURL'];
     } else {
         // If we're called from an outside (embedded) script, read baseURL from "last known good".
         // Else, set it based off of REQUEST
         if (defined('_poMMo_embed')) {
             Pommo::requireOnce($this->_baseDir . 'inc/helpers/maintenance.php');
             $this->_baseUrl = PommoHelperMaintenance::rememberBaseURL();
         } else {
             $baseUrl = preg_replace('@/(inc|setup|user|install|support(/tests)?|admin(/subscribers|/user|/mailings|/setup)?(/ajax|/mailing|/config)?)$@i', '', dirname($_SERVER['PHP_SELF']));
             $this->_baseUrl = $baseUrl == '/' ? $baseUrl : $baseUrl . '/';
         }
     }
     // make sure workDir is writable
     if (!is_dir($this->_workDir . '/pommo/smarty')) {
         $wd = $this->_workDir;
         $this->_workDir = null;
         if (!is_dir($wd)) {
             Pommo::kill(sprintf(Pommo::_T('Work Directory (%s) not found! Make sure it exists and the webserver can write to it. You can change its location from the config.php file.'), $wd));
         }
         if (!is_writable($wd)) {
             Pommo::kill(sprintf(Pommo::_T('Cannot write to Work Directory (%s). Make sure it has the proper permissions.'), $wd));
         }
         if (ini_get('safe_mode') == "1") {
             Pommo::kill(sprintf(Pommo::_T('Working Directory (%s) cannot be created under PHP SAFE MODE. See Documentation, or disable SAFE MODE.'), $wd));
         }
         if (!is_dir($wd . '/pommo')) {
             if (!mkdir($wd . '/pommo')) {
                 Pommo::kill(Pommo::_T('Could not create directory') . ' ' . $wd . '/pommo');
             }
         }
         if (!mkdir($wd . '/pommo/smarty')) {
             Pommo::kill(Pommo::_T('Could not create directory') . ' ' . $wd . '/pommo/smarty');
         }
         $this->_workdir = $wd;
     }
     // set the current "section" -- should be "user" for /user/* files, "mailings" for /admin/mailings/* files, etc. etc.
     $this->_section = preg_replace('@^admin/?@i', '', str_replace($this->_baseUrl, '', dirname($_SERVER['PHP_SELF'])));
     // initialize database link
     $this->_dbo = @new PommoDB($config['db_username'], $config['db_password'], $config['db_database'], $config['db_hostname'], $config['db_prefix']);
     // turn off debugging if in user area
     if ($this->_section == 'user') {
         $this->_debug = false;
         $this->_dbo->debug(FALSE);
     }
     // if debugging is set in config.php, enable debugging on the database.
     if ($this->_debug) {
         // don't enable debugging in ajax requests unless verbosity is < 3
         if (PommoHelper::isAjax() && $this->_verbosity > 2) {
             $this->_debug = false;
         } else {
             $this->_dbo->debug(TRUE);
         }
     }
 }
$pommo->init();
Pommo::requireOnce($pommo->_baseDir . 'inc/classes/mailctl.php');
echo 'Merci de patienter quelques secondes...';
ob_flush();
flush();
$code = PommoHelper::makeCode();
if (!PommoMailCtl::spawn($pommo->_baseUrl . 'support/tests/mailing.test2.php?code=' . $code, true)) {
    Pommo::kill('Echec du d&eacute;clenchement du m&eacute;canisme. Vous devez corriger ce probl&egrave;me pour que poMMo puisse envoyer des e-mails.');
}
sleep(6);
if (!is_file($pommo->_workDir . '/mailing.test.php')) {
    // make sure we can write to the file
    if (!($handle = fopen($pommo->_workDir . '/mailing.test.php', 'w'))) {
        die('Impossible d\'&eacute;crire dans le fichier de test.');
    }
    fclose($handle);
    unlink($pommo->_workDir . '/mailing.test.php');
    Pommo::kill('Echec du d&eacute;clenchement du m&eacute;canisme (probl&egrave;me d\'&eacute;criture au niveau du fichier de test). Vous devez corriger ce probl&egrave;me pour que poMMo puisse envoyer des e-mails.');
}
$o = PommoHelper::parseConfig($pommo->_workDir . '/mailing.test.php');
unlink($pommo->_workDir . '/mailing.test.php') or die('impossible de supprimer mailing.test.php');
if (isset($o['error'])) {
    Pommo::kill('UNE ERREUR A ETE TROUVEE. MERCI DE VERIFIER LE RESULTAT DE \'MAILING_TEST\' DANS LE REPERTOIRE DE TRAVAIL');
}
if (!isset($o['code']) || $o['code'] != $code) {
    Pommo::kill('Le test a &eacute;chou&eacute;. Certains codes ne correspondent pas.');
}
if (!isset($o['spawn']) || $o['spawn'] == 0) {
    Pommo::kill('D&eacute;clenchement r&eacute;ussi mais &eacute;chec des envois &agrave; r&eacute;p&eacute;tition.');
}
Pommo::kill('D&eacute;clenchement r&eacute;ussi. Envois &agrave; r&eacute;p&eacute;tition r&eacute;ussis. La fonction d\'envoi massif est op&eacute;rationnelle.');
 function rememberBaseURL()
 {
     global $pommo;
     $config = PommoHelper::parseConfig($pommo->_workDir . '/maintenance.php');
     return $config['baseURL'];
 }