require( "../global_config.inc.php" );
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
$config['title'] = "Personal Account Manager";
$config['pgm_id'] = "CKPAM061206"; // Used in session variables
$config['secret_word'] = 'CKPAM061206';
$config['debug'] = 0;
$config['fontFamily'] = "Arial, Sans Serif, Times New Roman";
$config['banIP'] = 1;
$config['badWordFilter'] = 0;
$config['tablewidth'] = 1010;
$config['items_per_page'] = 30;
$config['altcolor1'] = '#F1F1F1';
$config['altcolor2'] = '#DFDFDF';
$config['hd_path'] = "/usr/local/www/groups/club.kingsnake.com/public_html"; // no trailing slash
$config['logfile'] = '/usr/local/www/groups/club.kingsnake.com/public_html/myaccount/tmp/error.log';
$config['community_email'] = "jeffb@kingsnake.com";
$config['bcc'] = 'jeffb@kingsnake.com';
$config['siteurl'] = "http://club.kingsnake.com/myaccount"; // no trailing slash
$config['header_file'] = 'http://club.kingsnake.com/ssi/top_tmpl.html';
$config['footer_file'] = 'http://club.kingsnake.com/ssi/bottom.html';
$config['forgot_pw_url'] = $config['siteurl'] . "/member.php?action=forgot";
$config['register_url'] = $config['siteurl'] . "/register.php";
$expire_types = array ("epoch", "date", "date/time");
$config['autoMessage'] = <<
require( "../global_common.inc.php" );
// ---------------------------------------------
function verifyUser() {
global $config;
if( isset($_SESSION["usernamein"]) && isset($_SESSION["passwd"]) ) {
if ( $_SESSION['pgm_id']==$config['pgm_id']) {
return $_SESSION['sec_level'];
}
}
return false;
}
// ---------------------------------------------
function auto_login() {
global $myaccountdblink, $authlink, $config;
if ( isset($_SESSION['usernamein']) && isset($_SESSION['passwd']) ) {
if ($_SESSION['pgm_id'] == $config['pgm_id']) {
return true;
}
}
if ($_COOKIE['login']) {
list($f_email,$cookie_hash) = split(',', urldecode($_COOKIE['login']));
if ( md5($f_email . $config['secret_word']) == $cookie_hash) {
// This f_email is good info, pull contact info
if (!$authlink) { dbConnectAuth(); }
$sql = "SELECT username, password, userid FROM users WHERE email='$f_email' AND usergroupid > '3'";
$result = @mysqli_query($authlink, $sql);
if (@mysqli_num_rows($result) == 1) {
$form = @mysqli_fetch_array($result);
$_SESSION['usernamein'] = $form['username'];
$_SESSION['passwd'] = $form['password'];
$_SESSION['pgm_id'] = $config['pgm_id'];
$_SESSION['sess_userid'] = $form['userid'];
// Check to see if they have a local user record, read in & set values
dbConnectMyAccount();
$sql = "SELECT sec_level, status FROM tbl_users WHERE username='" . addslashes($form['username']) . "'";
$result = @mysqli_query($myaccountdblink, $sql);
if (@mysqli_num_rows($result) == 1 ) {
$myrow = @mysqli_fetch_array($result);
// Deny access to anybody Suspended
if ($myrow['status'] != 'a') {
error( "Sorry, the system is currently unavailable at the moment.", "MyAccount: suspended user: $client_username");
}
$_SESSION['sec_level'] = $myrow['sec_level'];
$todays_date = date("Y-m-d") . " " . date("H:i:s");
$sql = "UPDATE tbl_users SET logins=logins+1, last_login='$todays_date' WHERE username = '" . addslashes($form['username']) . "'";
$result = @mysqli_query($myaccountdblink, $sql);
}
return true;
} else {
return false;
}
}
} else {
return false;
}
}
// ---------------------------------------------
function displayHeader($title) {
global $config;
// Capture the header template
if ($file = @fopen($config['header_file'],"r")) {
ob_start();
@fpassthru($file);
$page = ob_get_contents();
ob_end_clean();
@fclose($file);
}
// Capture the banner
if ($file = @fopen("http://banner.kingsnake.com/ssi/get_banner.php?region=$banner_rotation","r")) {
ob_start();
@fpassthru($file);
$banner = ob_get_contents();
ob_end_clean();
@fclose($file);
}
$css = <<
HTML;
$page = str_replace("{title}", strip_tags($title), $page);
$page = str_replace("{css}", $css, $page);
$page = str_replace("{banner}", $banner, $page);
//$page = str_replace("{splash}", $splash, $page);
echo $page;
}
// ---------------------------------------------
function displayFooter() {
global $config;
echo "\n";
if($myfile = @fopen($config['footer_file'],'r')) {
@fpassthru($myfile);
}
exit;
}
// ---------------------------------------------
function toolbar() {
global $config;
if ( isset($_SESSION['usernamein']) && isset($_SESSION['passwd']) ) {
$TITLE = $_SESSION['usernamein'] . "'s Personal Account Manager";
} else {
$TITLE = $config['title'];
}
print <<
| $TITLE |
HTML;
echo "\n";
}
// ---------------------------------------------
function error( $error, $details="" ) {
global $config;
displayHeader("Error Page");
toolbar();
echo "
Error Page
Error: $error
Back | {$config['title']}
";
$mydate = date("Y-m-d H:i:s") . ": ";
error_log($mydate . " " . $error . "(" . $config['title'] . ")\n", 3, $config['logfile']);
if ($details) { error_log ("\t\t\t$details\n", 3, $config['logfile']); }
displayFooter();
exit;
}
//------------------------------------------------------------------
function logit($logtext) {
global $config;
$logdate = date("Y-m-d H:i:s");
$ip = $_SERVER['REMOTE_ADDR'];
$logscript = $_SERVER['SCRIPT_FILENAME'];
$logheader = "Entry made from $ip on $logdate\n\t[script: $logscript]\n";
error_log ($logheader, 3, $config['logfile']);
$f_logtext = "\t$logtext\n";
error_log ($f_logtext, 3, $config['logfile']);
}
// ---------------------------------------------
function print_message($text) {
global $config;
print <<
HTML;
} // end print_message
// ---------------------------------------------
function banIPcheck () {
global $config, $myaccountdblink;
if (!$myaccountdblink) { dbConnectMyAccount(); }
if ($config['banIP'] == 1 ) {
$result = @mysqli_query($myaccountdblink, "SELECT ip FROM bannedip WHERE ip='" . $_SERVER['REMOTE_ADDR'] . "' LIMIT 1");
if ( @mysqli_num_rows($result)==1 ) {
return true;
}
}
return false;
}
// ---------------------------------------------
function monitor_ip_check($ip="") {
global $myaccountdblink;
if (!$ip) { return false; }
if (!$myaccountdblink) { dbConnectMyAccount(); }
$result = @mysqli_query($myaccountdblink, "SELECT ip FROM ipmonitor WHERE ip='$ip' LIMIT 1");
if ( @mysqli_num_rows( $result ) == 1 ) {
return true;
}
return false;
}
// ---------------------------------------------
function substrcount($needle, $haystack) {
$strcount = explode($needle, $haystack);
return count($strcount);
}
// ---------------------------------------------
function is_hostname($hostname) {
$tokens = explode(".", $hostname);
for ($error = $j = 0; $j < sizeof($tokens); $j++) {
if ((!preg_match("/^[a-zA-Z]/", $tokens[$j])) || preg_match("/[^a-zA-Z0-9\-]/", $tokens[$j]) || (!preg_match("/[a-zA-Z0-9]$/", $tokens[$j]))):
$error = 1;
break;
endif;
}
return ($error == 0) ? true : false;
}
// ---------------------------------------------
function listbox_expire_types($fieldname, $key="") {
GLOBAL $expire_types;
echo "\n";
}
// ---------------------------------------------
function create_random_passwd() {
global $config;
$first = rand(0, 100);
$second = $first * (int)time();
$third = md5($second);
$fourth = substr($third, 0, 6);
if ($config['debug']==1) { echo "DEBUG: password generated is [$fourth]
\n"; }
return $fourth;
}
// ---------------------------------------------
function display_message($text="") {
global $config;
print <<
|
$text
|
HTML;
}
//----------------------------------------------------
function display_banreason_dropdown($key) {
// These items also need to be updated in:
// banusers, admin-usernotes (x3)
echo "\n";
}
// ----------------------- Send out Confirmation email ----------------------
function send_email($keynum, $remail, $uid) {
global $config;
$letter=<<IsSMTP();
$mail->Host = $config['smtp_servername'];
$mail->From = "DoNotReply@pethobbyist.com";
$mail->FromName = "Club.Kingsnake.com";
$mail->AddAddress( $remail );
$mail->Subject = "Confirm your Club Kingsnake Registration (action needed)";
$mail->Body = $config['autoMessage'] . $letter;
if($mail->Send()) {
return true;
} else {
$mydate = date("Y-m-d H:i:s") . ": ";
$details = "send_email function; $remail, $uid - " . $mail->ErrorInfo;
error_log ("$mydate $error ($THIS_SITE)\n", 3, $config['hd_path'] . "/tmp/error.log");
error_log ("\t\t\t$details\n", 3, $config['hd_path'] . "/tmp/error.log");
return false;
}
} // end send_email function
// ---------------------------------------------
function email_ip_monitor ($ip="", $username="", $email="", $groupid="") {
if (!$ip || !$username || !$email) { return false; }
global $config;
$TEXT=<<IsSMTP();
$mail->Host = $config['smtp_servername'];
$mail->From = "DoNotReply@pethobbyist.com";
$mail->FromName = "Club.Kingsnake.com";
//$mail->AddAddress("phginger@pethobbyist.com");
$mail->AddAddress($config['community_email']);
$mail->Subject = "$ip: New Club Kingsnake Registration from Monitored IP";
$mail->Body = $TEXT;
if($mail->Send()) {
return true;
} else {
return false;
}
} // end email_ip_monitor function
// ---------------------------------------------
function send_an_email($emailto="", $message="", $subject="", $bcc="") {
global $config;
if (!$message || !$subject || !$emailto) { return false; }
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = $config['smtp_servername'];
$mail->From = "DoNotReply@pethobbyist.com";
$mail->FromName = "Club.Kingsnake.com";
if ($config['bcc']) {
$mail->AddBCC($config['bcc']);
}
if ( is_array($emailto) ) {
foreach ($emailto as $sendto) {
$mail->AddAddress($sendto);
}
} else {
$mail->AddAddress($emailto);
}
$mail->Subject = $subject;
$mail->Body = displayFormatTEXT($message);
if($mail->Send()) {
return true;
} else {
return false;
}
}
// ---------------------------------------------
function add_usernote($username="", $userid="", $reason="", $notes="") {
global $myaccountdblink;
if (!$myaccountdblink) { dbConnectMyAccount(); }
$sql = 'LOCK TABLES usernotes WRITE';
$result = @mysqli_query($myaccountdblink, $sql) or
error("Unable to lock the database. Please try again later.", $_SERVER['PHP_SELF'] . ": $sql : " . mysqli_error($myaccountdblink) );
$sql = "SELECT MAX(thread_id) AS my_id FROM usernotes";
$result = @mysqli_query($myaccountdblink, $sql);
$row = @mysqli_fetch_array($result);
$form = array();
$form['thread_id'] = $row['my_id'] + 1;
$form['parent_id'] = 0;
$form['level'] = 0;
$form['thread_pos'] = 0;
if ($_SESSION['usernamein']) {
$form['enteredby'] = $_SESSION['usernamein'];
} else {
$form['enteredby'] = 'AutoPilot';
}
$form['date'] = date("Y-m-d H:i:s");
$form['username'] = $username;
$form['userid'] = $userid;
$form['reason'] = $reason;
$form['notes'] = $notes;
$form['token'] = uniqid(microtime(),1);
foreach ($form as $var => $value) {
if ($value) {
$form[$var] = displayFormatHTML($value);
$form[$var] = addslashes($value);
}
}
$fields = array('date', 'userid', 'username', 'reason', 'notes', 'enteredby', 'thread_id', 'parent_id', 'level', 'thread_pos', 'token');
$insert_values = array();
foreach ($fields as $field) {
$insert_values[] = "\"" . $form[$field] . "\"";
}
$sql = "INSERT INTO usernotes (" . join(',',$fields) . ") VALUES (" . join(',',$insert_values) . ")";
$result = @mysqli_query($myaccountdblink, $sql) or
error("Unable to save usernotes to the database. Please try again later.", $_SERVER['PHP_SELF'] . ": $sql : " . mysqli_error($myaccountdblink) );
$parent_id = @mysqli_insert_id($myaccountdblink);
// Tell MySQL that others can use the pc_message table now
$sql = 'UNLOCK TABLES';
$result = @mysqli_query($myaccountdblink, $sql) or
error("Unable to unlock the database. Please try again later.", $_SERVER['PHP_SELF'] . ": $sql : " . mysqli_error($myaccountdblink) );
return $parent_id;
}
// ---------------------------------------------
function dump_array($array) {
if (is_array($array)) {
$size=count($array);
if ($size) {
$count = 0;
$string .= "{ ";
// add each element's key and value to the string
foreach($array as $var => $value) {
$string .= "$var = $value";
if ($count++ < ($size -1)) {
$string .= ", ";
}
}
return $string;
} else {
// If it is not an array, just return it
return $array;
}
}
}
?>