/wp-content/plugins/mailz/lists/admin/index.php
PHP | 450 lines | 367 code | 38 blank | 45 comment | 155 complexity | 24cb88971e141d22feb311e5cee1e002 MD5 | raw file
- <?php
- @ob_start();
- $er = error_reporting(0);
- # check for commandline and cli version
- if (!isset($_SERVER["SERVER_NAME"]) && !PHP_SAPI == "cli") {
- print "Warning: commandline only works well with the cli version of PHP";
- }
- if (isset($_REQUEST['_SERVER'])) { exit; }
- $cline = array();
- $GLOBALS['commandline'] = 0;
- require_once dirname(__FILE__) .'/commonlib/lib/unregister_globals.php';
- require_once dirname(__FILE__) .'/commonlib/lib/magic_quotes.php';
- # setup commandline
- if (php_sapi_name() == "cli") {
- for ($i=0; $i<$_SERVER['argc']; $i++) {
- $my_args = array();
- if (ereg("(.*)=(.*)",$_SERVER['argv'][$i], $my_args)) {
- $_GET[$my_args[1]] = $my_args[2];
- $_REQUEST[$my_args[1]] = $my_args[2];
- }
- }
- $GLOBALS["commandline"] = 1;
- $cline = parseCLine();
- $dir = dirname($_SERVER["SCRIPT_FILENAME"]);
- chdir($dir);
- } else {
- $GLOBALS["commandline"] = 0;
- header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
- header("Pragma: no-cache"); // HTTP/1.0
- }
- if (isset($_SERVER["ConfigFile"]) && is_file($_SERVER["ConfigFile"])) {
- print '<!-- using '.$_SERVER["ConfigFile"].'-->'."\n";
- include $_SERVER["ConfigFile"];
- } elseif (isset($cline["c"]) && is_file($cline["c"])) {
- print '<!-- using '.$cline["c"].' -->'."\n";
- include $cline["c"];
- } elseif ($GLOBALS['commandline'] && isset($_ENV["CONFIG"]) && is_file($_ENV["CONFIG"])) {
- # print '<!-- using '.$_ENV["CONFIG"].'-->'."\n";
- include $_ENV["CONFIG"];
- } elseif (is_file("../config/config.php")) {
- print '<!-- using ../config/config.php -->'."\n";
- include "../config/config.php";
- } else {
- print "Error, cannot find config file\n";
- exit;
- }
- # record the start time(usec) of script
- $now = gettimeofday();
- $GLOBALS["pagestats"] = array();
- $GLOBALS["pagestats"]["time_start"] = $now["sec"] * 1000000 + $now["usec"];
- $GLOBALS["pagestats"]["number_of_queries"] = 0;
- if (!$GLOBALS["commandline"] && isset($GLOBALS["developer_email"]) && $_SERVER['HTTP_HOST'] != 'cvs.phplist.com' && $GLOBALS['show_dev_errors']) {
- error_reporting(E_ALL | E_NOTICE);
- ini_set('display_errors',1);
- foreach ($_REQUEST as $key => $val) {
- unset($$key);
- }
- } else {
- # error_reporting($er);
- error_reporting(0);
- }
- # load all required files
- require_once dirname(__FILE__).'/init.php';
- require_once dirname(__FILE__).'/'.$GLOBALS["database_module"];
- require_once dirname(__FILE__)."/../texts/english.inc";
- include_once dirname(__FILE__)."/../texts/".$GLOBALS["language_module"];
- require_once dirname(__FILE__)."/defaultconfig.inc";
- require_once dirname(__FILE__).'/connect.php';
- include_once dirname(__FILE__)."/languages.php";
- include_once dirname(__FILE__)."/lib.php";
- require_once dirname(__FILE__)."/commonlib/lib/interfacelib.php";
- include_once dirname(__FILE__)."/pagetop.php";
- if ($GLOBALS["commandline"]) {
- if (!isset($_SERVER["USER"]) && sizeof($GLOBALS["commandline_users"])) {
- clineError("USER environment variable is not defined, cannot do access check. Please make sure USER is defined.");
- exit;
- }
- if (is_array($GLOBALS["commandline_users"]) && sizeof($GLOBALS["commandline_users"]) && !in_array($_SERVER["USER"],$GLOBALS["commandline_users"])) {
- clineError("Sorry, You (".$_SERVER["USER"].") do not have sufficient permissions to run phplist on commandline");
- exit;
- }
- $GLOBALS["require_login"] = 0;
- # getopt is actually useless
- #$opt = getopt("p:");
- if ($cline["p"]) {
- if (!in_array($cline["p"],$GLOBALS["commandline_pages"])) {
- clineError($cline["p"]." does not process commandline");
- } else {
- $_GET["page"] = $cline["p"];
- }
- } else {
- clineUsage(" [other parameters]");
- exit;
- }
- } else {
- if (CHECK_REFERRER && isset($_SERVER['HTTP_REFERER'])) {
- ## do a crude check on referrer. Won't solve everything, as it can be faked, but shouldn't hurt
- $ref = parse_url($_SERVER['HTTP_REFERER']);
- if ($ref['host'] != $_SERVER['HTTP_HOST'] && !in_array($ref['host'],$allowed_referrers)) {
- print 'Access denied';exit;
- }
- }
- }
- # fix for old PHP versions, although not failsafe :-(
- if (!isset($_POST) && isset($HTTP_POST_VARS)) {
- include_once dirname(__FILE__) ."/commonlib/lib/oldphp_vars.php";
- }
- if (!isset($_GET['page']))
- $page = 'home';
- else
- $page = $_GET['page'];
- preg_match("/([\w_]+)/",$page,$regs);
- $page = $regs[1];
- if (!is_file($page.'.php') && !isset($_GET['pi'])) {
- $page = 'home';
- }
- if (!$GLOBALS["admin_auth_module"]) {
- # stop login system when no admins exist
- if (!Sql_Table_Exists($tables["admin"])) {
- $GLOBALS["require_login"] = 0;
- } else {
- $num = Sql_Query("select * from {$tables["admin"]}");
- if (!Sql_Affected_Rows())
- $GLOBALS["require_login"] = 0;
- }
- } elseif (!Sql_Table_exists($GLOBALS['tables']['config'])) {
- $GLOBALS['require_login'] = 0;
- }
- $page_title = NAME;
- @include_once dirname(__FILE__)."/lan/".$_SESSION['adminlanguage']['iso']."/pagetitles.php";
- print '<script language="javascript" type="text/javascript" src="js/select_style.js"></script>';
- print '<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">'; // HTTP/1.1
- print '<meta http-equiv="Pragma" content="no-cache">'; // HTTP/1.1
- print "<title>".NAME." :: ";
- if (isset($GLOBALS["installation_name"]))
- print $GLOBALS["installation_name"] .' :: ';
- print "$page_title</title>";
- if (isset($GLOBALS["require_login"]) && $GLOBALS["require_login"]) {
- if ($GLOBALS["admin_auth_module"] && is_file("auth/".$GLOBALS["admin_auth_module"])) {
- require_once "auth/".$GLOBALS["admin_auth_module"];
- } elseif ($GLOBALS["admin_auth_module"] && is_file($GLOBALS["admin_auth_module"])) {
- require_once $GLOBALS["admin_auth_module"];
- } else {
- if ($GLOBALS["admin_auth_module"]) {
- logEvent("Warning: unable to use ".$GLOBALS["admin_auth_module"]. " for admin authentication, reverting back to phplist authentication");
- $GLOBALS["admin_auth_module"] = 'phplist_auth.inc';
- }
- require_once 'auth/phplist_auth.inc';
- }
- if (class_exists('admin_auth')) {
- $GLOBALS["admin_auth"] = new admin_auth();
- } else {
- print Fatal_Error($GLOBALS['I18N']->get('admininitfailure'));
- return;
- }
- if ((!isset($_SESSION["adminloggedin"]) || !$_SESSION["adminloggedin"]) && isset($_REQUEST["login"]) && isset($_REQUEST["password"])) {
- $loginresult = $GLOBALS["admin_auth"]->validateLogin($_REQUEST["login"],$_REQUEST["password"]);
- if (!$loginresult[0]) {
- $_SESSION["adminloggedin"] = "";
- $_SESSION["logindetails"] = "";
- $page = "login";
- logEvent(sprintf($GLOBALS['I18N']->get('invalid login from %s, tried logging in as %s'),$_SERVER['REMOTE_ADDR'],$_REQUEST["login"]));
- $msg = $loginresult[1];
- } else {
- $_SESSION["adminloggedin"] = $_SERVER["REMOTE_ADDR"];
- $_SESSION["logindetails"] = array(
- "adminname" => $_REQUEST["login"],
- "id" => $loginresult[0],
- "superuser" => $admin_auth->isSuperUser($loginresult[0]),
- );
- if ($_POST["page"] && $_POST["page"] != "") {
- $page = $_POST["page"];
- }
- }
- } elseif (isset($_REQUEST["forgotpassword"])) {
- $pass = '';
- if (is_email($_REQUEST["forgotpassword"])) {
- $pass = $GLOBALS["admin_auth"]->getPassword($_REQUEST["forgotpassword"]);
- }
- if ($pass) {
- sendMail ($_REQUEST["forgotpassword"],$GLOBALS['I18N']->get('yourpassword'),"\n\n".$GLOBALS['I18N']->get('yourpasswordis')." $pass");
- $msg = $GLOBALS['I18N']->get('passwordsent');
- logEvent(sprintf($GLOBALS['I18N']->get('successful password request from %s for %s'),$_SERVER['REMOTE_ADDR'],$_REQUEST["forgotpassword"]));
- } else {
- $msg = $GLOBALS['I18N']->get('cannotsendpassword');
- logEvent(sprintf($GLOBALS['I18N']->get('failed password request from %s for %s'),$_SERVER['REMOTE_ADDR'],$_REQUEST["forgotpassword"]));
- }
- $page = "login";
- } elseif (!isset($_SESSION["adminloggedin"]) || !$_SESSION["adminloggedin"]) {
- #$msg = 'Not logged in';
- $page = "login";
- } elseif (CHECK_SESSIONIP && $_SESSION["adminloggedin"] && $_SESSION["adminloggedin"] != $_SERVER["REMOTE_ADDR"]) {
- logEvent(sprintf($GLOBALS['I18N']->get('login ip invalid from %s for %s (was %s)'),$_SERVER['REMOTE_ADDR'],$_SESSION["logindetails"]['adminname'],$_SESSION["adminloggedin"]));
- $msg = $GLOBALS['I18N']->get('ipchanged');
- $_SESSION["adminloggedin"] = "";
- $_SESSION["logindetails"] = "";
- $page = "login";
- } elseif ($_SESSION["adminloggedin"] && $_SESSION["logindetails"]) {
- $validate = $GLOBALS["admin_auth"]->validateAccount($_SESSION["logindetails"]["id"]);
- if (!$validate[0]) {
- logEvent(sprintf($GLOBALS['I18N']->get('invalidated login from %s for %s (error %s)'),$_SERVER['REMOTE_ADDR'],$_SESSION["logindetails"]['adminname'],$validate[1]));
- $_SESSION["adminloggedin"] = "";
- $_SESSION["logindetails"] = "";
- $page = "login";
- $msg = $validate[1];
- }
- }
- }
- $include = '';
- include "header.inc";
- if ($page != '') {
- preg_match("/([\w_]+)/",$page,$regs);
- $include = $regs[1];
- $include .= ".php";
- $include = $page . ".php";
- } else {
- $include = "home.php";
- }
- print '<p class="leaftitle">'.NAME.' - '.strtolower($page_title).'</p>';
- if ($GLOBALS["require_login"] && $page != "login") {
- if ($page == 'logout') {
- $greeting = $GLOBALS['I18N']->get('goodbye');
- } else {
- $hr = date("G");
- if ($hr > 0 && $hr < 12) {
- $greeting = $GLOBALS['I18N']->get('goodmorning');
-