This file is part of poMMo (http://www.pommo.org)
poMMo is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2, or any later version.
poMMo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with program; see the file docs/LICENSE. If not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
function delDir($dirName, $orig = false) { if (!$orig) { $orig = $dirName; } if (empty($dirName)) { return true; } if (file_exists($dirName)) { $dir = dir($dirName); while ($file = $dir->read()) { if ($file != '.' && $file != '..') { if (is_dir($dirName . '/' . $file)) { Pommo_Helper_Maintenance::delDir($dirName . '/' . $file, $orig); } else { unlink($dirName . '/' . $file) or die('File ' . $dirName . '/' . $file . ' couldn\'t be deleted!'); } } } $dir->close(); if ($dirName != $orig) { @rmdir($dirName) or die('Folder ' . $dirName . ' couldn\'t be deleted!'); } } else { return false; } return true; }
Pommo::$_auth->logout(); header('Location: ' . Pommo::$_http . Pommo::$_baseUrl . 'index.php'); } // check if user is already logged in if (Pommo::$_hasConfigFile && Pommo::$_auth->isAuthenticated()) { // If user is authenticated (has logged in), redirect to admin.php Pommo::redirect(Pommo::$_http . Pommo::$_baseUrl . 'admin.php'); } elseif (isset($_POST['submit']) && !empty($_POST['username']) && !empty($_POST['password'])) { require_once Pommo::$_baseDir . 'classes/Pommo_User.php'; $user = new Pommo_user(); if ($user->login($_POST['username'], $_POST['password'])) { // don't perform maintenance if accessing support area if (!isset($_GET['referer']) || !basename($_GET['referer']) == 'support.php') { // login success. Perform maintenance, set auth, redirect to referer require_once Pommo::$_baseDir . 'classes/Pommo_Helper_Maintenance.php'; Pommo_Helper_Maintenance::perform(); } Pommo::$_auth->login($_POST['username']); Pommo::redirect(Pommo::$_http . $_POST['referer']); } else { $logger->addMsg(Pommo::_T('Failed login attempt. Try again.')); } } elseif (!empty($_POST['resetPassword'])) { // TODO -- visit this function later // Check if a reset password request has been received // check that captcha matched if (!isset($_POST['captcha'])) { // generate captcha $captcha = substr(md5(rand()), 0, 4); $view->assign('captcha', $captcha); } elseif ($_POST['captcha'] == $_POST['realdeal']) {
public static function preInit($baseDir) { // Remove quotes added by magic_quotes if (get_magic_quotes_gpc()) { $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { unset($process[$key][$k]); if (is_array($v)) { $process[$key][stripslashes($k)] = $v; $process[] =& $process[$key][stripslashes($k)]; } else { $process[$key][stripslashes($k)] = stripslashes($v); } } } unset($process); } self::$_baseDir = $baseDir; self::$_config = array(); self::$_auth = null; self::$_escaping = false; require_once self::$_baseDir . 'classes/Pommo_Log.php'; require_once self::$_baseDir . 'lib/SafeSQL.class.php'; require_once self::$_baseDir . 'classes/Pommo_Db.php'; require_once self::$_baseDir . 'classes/Pommo_Auth.php'; // initialize logger // Check where this config variable comes from self::$_logger = new Pommo_Log(); self::$_workDir = empty($config['workDir']) ? self::$_baseDir . 'cache' : $config['workDir']; self::$_debug = strtolower($config['debug']) != 'on' ? false : true; self::$_default_subscriber_sort = empty($config['default_subscriber_sort']) ? 'email' : $config['default_subscriber_sort']; self::$_verbosity = empty($config['verbosity']) ? 3 : $config['verbosity']; self::$_logger->_verbosity = self::$_verbosity; self::$_dateformat = $config['date_format'] >= 1 && $cofig['date_format'] <= 3 ? intval($config['date_format']) : 1; // set base URL (e.g. http://mysite.com/news/pommo => 'news/pommo/') if (isset($config['baseURL'])) { self::$_baseUrl = $config['baseURL']; } else { // If we're called from an embedded script, read baseURL from // "last known good". Else, set it based off of REQUEST. if (defined('_poMMo_embed')) { require_once self::$_baseDir . 'classes/Pommo_Helper_Maintenance.php'; self::$_baseUrl = Pommo_Helper_Maintenance::rememberBaseURL(); } else { $regex = '@/(ajax|inc|setup|user|install|support(/tests|/util)?|' . 'admin(/subscribers|/user|/mailings|/setup)?' . '(/ajax|/mailing|/config)?)$@i'; // This is to fix backslashes on windows systems $dirname = str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])); $baseUrl = preg_replace($regex, '', $dirname); self::$_baseUrl = $baseUrl == '/' ? $baseUrl : $baseUrl . '/'; } } // read in config.php (configured by user) $config = Pommo_Helper::parseConfig(self::$_baseDir . 'config.php'); // check to see if config.php was "properly" loaded if (count($config) < 5) { self::$_hasConfigFile = false; return self::$_hasConfigFile; } self::$_hasConfigFile = true; // the regex strips port info from hostname self::$_hostname = empty($config['hostname']) ? preg_replace('/:\\d+$/i', '', $_SERVER['HTTP_HOST']) : $config['hostname']; self::$_hostport = empty($config['hostport']) ? $_SERVER['SERVER_PORT'] : $config['hostport']; self::$_ssl = !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ? false : true; self::$_http = (self::$_ssl ? 'https://' : 'http://') . self::$_hostname; if (self::$_hostport != 80 && self::$_hostport != 443) { self::$_http .= ':' . self::$_hostport; } self::$_language = empty($config['lang']) ? 'en' : strtolower($config['lang']); self::$_slanguage = defined('_poMMo_lang') ? _poMMo_lang : false; // include translation (l10n) methods if language is not English self::$_l10n = FALSE; if (self::$_language != 'en') { self::$_l10n = TRUE; require_once self::$_baseDir . 'classes/Pommo_Helper_L10n.php'; Pommo_Helper_L10n::init(self::$_language, self::$_baseDir); } // set the current "section" -- should be "user" for /user/* files, // "mailings" for /admin/mailings/* files, etc. etc. self::$_section = preg_replace('@^admin/?@i', '', str_replace(self::$_baseUrl, '', dirname($_SERVER['PHP_SELF']))); $db_conn_compress = strtolower($config['db_conn_compress']) != 'on' ? 0 : MYSQL_CLIENT_COMPRESS; $db_conn_secure = strtolower($config['db_conn_secure']) != 'on' ? 0 : MYSQL_CLIENT_SSL; // initialize database link self::$_dbo = @new Pommo_Db($config['db_username'], $config['db_password'], $config['db_database'], $config['db_hostname'], $config['db_prefix'], $db_conn_compress, $db_conn_secure); // turn off debugging if in user area if (self::$_section == 'user') { self::$_debug = false; self::$_dbo->debug(FALSE); } // if debugging is set in config.php, enable debugging on the database. if (self::$_debug) { // don't enable debugging in ajax requests unless verbosity is < 3 if (Pommo_Helper::isAjax() && self::$_verbosity > 2) { self::$_debug = false; } else { self::$_dbo->debug(TRUE); } } return true; }
<?php /** * Copyright (C) 2005, 2006, 2007, 2008 Brice Burgess <*****@*****.**> * * This file is part of poMMo (http://www.pommo.org) * * poMMo is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2, or any later version. * * poMMo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with program; see the file docs/LICENSE. If not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ /********************************** INITIALIZATION METHODS *********************************/ define('_poMMo_support', TRUE); require 'bootstrap.php'; Pommo::init(); require_once Pommo::$_baseDir . 'classes/Pommo_Helper_Maintenance.php'; echo Pommo_Helper_Maintenance::delDir(Pommo::$_workDir) ? 'Work Directory Cleared' : 'Unable to Clear Work Directory -- Does it exist?';
public static function preInit($baseDir) { self::$_baseDir = $baseDir; self::$_config = array(); self::$_auth = null; self::$_escaping = false; require_once self::$_baseDir . 'classes/Pommo_Log.php'; require_once self::$_baseDir . 'lib/SafeSQL.class.php'; require_once self::$_baseDir . 'classes/Pommo_Db.php'; require_once self::$_baseDir . 'classes/Pommo_Auth.php'; // initialize logger // Check where this config variable comes from self::$_logger = new Pommo_Log(); self::$_workDir = empty($config['workDir']) ? self::$_baseDir . 'cache' : $config['workDir']; self::$_debug = strtolower($config['debug']) != 'on' ? false : true; self::$_default_subscriber_sort = empty($config['default_subscriber_sort']) ? 'email' : $config['default_subscriber_sort']; self::$_verbosity = empty($config['verbosity']) ? 3 : $config['verbosity']; self::$_logger->_verbosity = self::$_verbosity; self::$_dateformat = $config['date_format'] >= 1 && $cofig['date_format'] <= 3 ? intval($config['date_format']) : 1; // set base URL (e.g. http://mysite.com/news/pommo => 'news/pommo/') if (isset($config['baseURL'])) { self::$_baseUrl = $config['baseURL']; } else { // If we're called from an embedded script, read baseURL from // "last known good". Else, set it based off of REQUEST. if (defined('_poMMo_embed')) { require_once self::$_baseDir . 'classes/Pommo_Helper_Maintenance.php'; self::$_baseUrl = Pommo_Helper_Maintenance::rememberBaseURL(); } else { $regex = '@/(ajax|inc|setup|user|install|support(/tests|/util)?|' . 'admin(/subscribers|/user|/mailings|/setup)?' . '(/ajax|/mailing|/config)?)$@i'; $baseUrl = preg_replace($regex, '', dirname($_SERVER['PHP_SELF'])); self::$_baseUrl = $baseUrl == '/' ? $baseUrl : $baseUrl . '/'; } } // read in config.php (configured by user) $config = Pommo_Helper::parseConfig(self::$_baseDir . 'config.php'); // check to see if config.php was "properly" loaded if (count($config) < 5) { self::$_hasConfigFile = false; return self::$_hasConfigFile; } self::$_hasConfigFile = true; // the regex strips port info from hostname self::$_hostname = empty($config['hostname']) ? preg_replace('/:\\d+$/i', '', $_SERVER['HTTP_HOST']) : $config['hostname']; self::$_hostport = empty($config['hostport']) ? $_SERVER['SERVER_PORT'] : $config['hostport']; self::$_ssl = !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ? false : true; self::$_http = (self::$_ssl ? 'https://' : 'http://') . self::$_hostname; if (self::$_hostport != 80 && self::$_hostport != 443) { self::$_http .= ':' . self::$_hostport; } self::$_language = empty($config['lang']) ? 'en' : strtolower($config['lang']); self::$_slanguage = defined('_poMMo_lang') ? _poMMo_lang : false; // include translation (l10n) methods if language is not English self::$_l10n = FALSE; if (self::$_language != 'en') { self::$_l10n = TRUE; require_once self::$_baseDir . 'classes/Pommo_Helper_L10n.php'; Pommo_Helper_L10n::init(self::$_language, self::$_baseDir); } // make sure workDir is writable if (!is_dir(self::$_workDir . '/pommo/smarty')) { $wd = self::$_workDir; self::$_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 ('1' == ini_get('safe_mode')) { 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'); } self::$_workdir = $wd; } // set the current "section" -- should be "user" for /user/* files, // "mailings" for /admin/mailings/* files, etc. etc. self::$_section = preg_replace('@^admin/?@i', '', str_replace(self::$_baseUrl, '', dirname($_SERVER['PHP_SELF']))); // initialize database link self::$_dbo = @new Pommo_Db($config['db_username'], $config['db_password'], $config['db_database'], $config['db_hostname'], $config['db_prefix']); // turn off debugging if in user area if (self::$_section == 'user') { self::$_debug = false; self::$_dbo->debug(FALSE); } // if debugging is set in config.php, enable debugging on the database. if (self::$_debug) { // don't enable debugging in ajax requests unless verbosity is < 3 if (Pommo_Helper::isAjax() && self::$_verbosity > 2) { self::$_debug = false; } else { self::$_dbo->debug(TRUE); } } return true; }
$logger->addErr(sprintf(Pommo::_T('To upgrade poMMo, %s click here %s'), '<a href="' . Pommo::$_baseUrl . 'upgrade.php?continue=TRUE">', '</a>')); } else { $smarty->assign('attempt', TRUE); if (isset($_REQUEST['debugInstall'])) { $dbo->debug(TRUE); } if (isset($_REQUEST['forceUpgrade'])) { $GLOBALS['pommoFakeUpgrade'] = true; } if (PommoUpgrade()) { $logger->addErr(Pommo::_T('Upgrade Complete!')); // Read in RELEASE Notes -- TODO -> use file_get_contents() one day when everyone has PHP 4.3 $filename = Pommo::$_baseDir . 'docs/RELEASE'; $handle = fopen($filename, "r"); $x = fread($handle, filesize($filename)); fclose($handle); $smarty->assign('notes', $x); $smarty->assign('upgraded', TRUE); } else { $logger->addErr(Pommo::_T('Upgrade Failed!')); } // clear the working directory template files $smarty->display('upgrade.tpl'); require_once Pommo::$_baseDir . 'classes/Pommo_Helper_Maintenance.php'; if (!Pommo_Helper_Maintenance::delDir(Pommo::$_workDir . '/pommo/smarty')) { $logger->addErr('Unable to Clear Working Directory (non fatal)'); } Pommo::kill(); } $smarty->display('upgrade.tpl'); Pommo::kill();