<?php
/*
+ ------------------------------------------------------------------------
+ IPB SDK Script - [SDK]Easy-to-edit Login Script
+ Copyright (C) 2004 Timothy Leucht (lightsup55)
+ ------------------------------------------------------------------------
+ Login and logout script using templates for easy editing.
+ ------------------------------------------------------------------------
*/
//-----------------------------------------------
// USER CONFIGURABLE ELEMENTS
//-----------------------------------------------
// Define the path to where the IPB SDK files are
// located. This might be "./forums/" for example.
// Don't forget the trailing slash!
define( 'IPBSDK_PATH', "/home/flametid/public_html/ipbsdk/" );
// Define the path to where the template file are
// located. This might be "./templates/" for example.
// Don't forget the trailing slash!
$templates_dir = "./";
// The file names of the templates
// Only change if using a different name
$template_main = "main.html"; // Main template
$template_redirect = "redirect.html"; // The redirection page
$template_form_guests = "form_guests.html"; // Login form and guests stuff
$template_memberonly = "memberonly.php"; // Member only information
// Redirection Time (in seconds)
$redirectSeconds = "5";
// --- Optional ---
// If using a portal other than IPDynamic Lite, define it here
// Example: http://www.domain.com/someotherportal.php
$portal_url = "";
//-----------------------------------------------
// NO USER EDITABLE SECTIONS BELOW
//-----------------------------------------------
// You got error!
error_reporting (E_ERROR | E_WARNING | E_PARSE);
// Load and Start IPB SDK
require_once IPBSDK_PATH."ipbsdk_class.inc.php";
$SDK =& new IPBSDK();
$sdk_info = $SDK->get_advinfo();
$LoginScript = new scriptinfo();
class scriptinfo {
var $GetAction = "";
var $onload = "";
var $ipbMemberID = "";
var $ipbUsername = "";
var $ipbForumsURL = "";
var $portalURL = "";
var $scriptURL = "";
var $redirect = "";
var $message = "";
var $linkMsg = "";
var $ISloggedin = "";
var $NOTloggedin = "";
var $temp_form_guests = "";
var $temp_main = "";
var $temp_memberonly = "";
var $temp_redirect = "";
}
$LoginScript->scriptURL = $_SERVER["PHP_SELF"];
$LoginScript->redirect = '<meta http-equiv="refresh" content="'.$redirectSeconds.'; URL='.$LoginScript->scriptURL.'" />'."\r\n";
$LoginScript->ipbMemberID = $sdk_info['id']; // IPB Member ID (number, 0 is Guest)
$LoginScript->ipbUsername = $sdk_info['name']; // IPB Username
$LoginScript->ipbForumsURL = $INFO['board_url']."/index.".$INFO['php_ext']."?"; // The forums URL
$LoginScript->temp_form_guests = $template_form_guests ;
$LoginScript->temp_main = $template_main ;
$LoginScript->temp_memberonly = $template_memberonly ;
$LoginScript->temp_redirect = $template_redirect ;
// Did we enter a different URL for the portal?
if ($portal_url != "") {
// We did, now use it!
$LoginScript->portalURL = $portal_url;
} else {
// OK FINE! I'll use IPDynamic Lite.
$LoginScript->portalURL = $LoginScript->ipbForumsURL."act=home";
}
if ( isset($_GET['act']) ) {
$LoginScript->GetAction = $_GET['act'];
} else {
$LoginScript->GetAction = "";
}
// ------------------
// Decide what to do
// ------------------
switch ( $LoginScript->GetAction )
{
case 'Login':
do_login();
break;
case 'Logout':
do_logout();
break;
default:
do_default();
break;
}
// ------------------
// Deh {parse} template function
// ------------------
function parse_template( $template, $assigned=array() )
{
global $SDK, $LoginScript, $templates_dir;
foreach( $assigned as $word => $replace)
{
$template = preg_replace( "/\{$word\}/i", "$replace", $template );
}
return $template;
}
// ------------------
// Da load template function
// ------------------
function load_template($template="")
{
global $SDK, $LoginScript, $templates_dir;
$filename = $templates_dir.$template;
if ( file_exists($filename) )
{
if ( $FH = fopen($filename, 'r') )
{
$template = fread( $FH, filesize($filename) );
fclose($FH);
}
else
{
fatal_error("Couldn't open the template file");
}
}
else
{
fatal_error("Template file does not exist");
}
return $template;
}
// ------------------
// Oh no, dare's a problem wit deh template
// Oh what ta do, what ta do.
// ------------------
function fatal_error($message="") {
global $SDK, $LoginScript, $templates_dir;
echo("An error occured whilst processing this directive");
if ($message)
{
echo("<br />$message");
}
exit();
}
// ------------------
// Now pay attention when I'm talking to ya son.
// I said, I said... LOG-OUT son!
// ------------------
function do_logout() {
global $SDK, $LoginScript, $templates_dir;
$SDK->logout();
$LoginScript->message = "You have been logged out.";
$LoginScript->linkMsg = "Click here to continue";
$template = load_template($LoginScript->temp_redirect);
$to_echo = "";
$to_echo .= parse_template( $template,
array (
'redirect' => $LoginScript->redirect,
'message' => $LoginScript->message,
'link' => $LoginScript->scriptURL,
'link_msg' => $LoginScript->linkMsg
)
);
echo $to_echo;
exit();
}
// ------------------
// OK GUYS!... LOG-IN!
// ------------------
function do_login() {
global $SDK, $LoginScript, $templates_dir;
if ($_SERVER['REQUEST_METHOD'] == "POST") {
// The form was submitted. Lets authenticate!
$username = $_POST['username'];
$password = $_POST['password'];
$anonlogin = $_POST['anonlogin'] ? "1" : "0";
if ($SDK->login($username, $password, 1, $anonlogin)) {
// The login worked. :)
$LoginScript->message = "Login Successful!";
$LoginScript->linkMsg = "Click here to continue";
} else {
// The login failed :(
$LoginScript->message = "<b>Fatal Error:</b> ".$SDK->sdk_error();
$LoginScript->linkMsg = "Login again";
$LoginScript->redirect = "";
}
$template = load_template($LoginScript->temp_redirect);
$to_echo = "";
$to_echo .= parse_template( $template,
array (
'redirect' => $LoginScript->redirect,
'message' => $LoginScript->message,
'link' => $LoginScript->scriptURL,
'link_msg' => $LoginScript->linkMsg
)
);
echo $to_echo;
exit();
} else {
do_default();
}
// Ok, you can stop working with do_login!
}
// ------------------
// Do da default
// ------------------
function do_default() {
global $SDK, $LoginScript, $templates_dir;
// =====================
// START MEMBER ONLY
// =====================
if ($SDK->is_loggedin()) {
// Code for logged in users goes here
$ISloggedin_T = load_template($LoginScript->temp_memberonly);
$LoginScript->ISloggedin = "";
$LoginScript->ISloggedin .= parse_template( $ISloggedin_T,
array (
'logout_link' => $LoginScript->scriptURL."?act=Logout",
'profile_link' => $LoginScript->ipbForumsURL."showuser=".$LoginScript->ipbMemberID,
'profile_id' => $LoginScript->ipbMemberID,
'member_name' => $LoginScript->ipbUsername,
'forums_url' => $LoginScript->ipbForumsURL."act=idx",
'portal_url' => $LoginScript->portalURL
)
);
} else {
// Code for GUESTS goes here
// Give focus to the "username" field --- bug fix for Mozilla
$LoginScript->onload = 'document.theLoginForm.username.focus();';
$NOTloggedin_T = load_template($LoginScript->temp_form_guests);
$LoginScript->NOTloggedin = "";
$LoginScript->NOTloggedin .= parse_template( $NOTloggedin_T,
array (
'form_action' => $LoginScript->scriptURL."?act=Login",
'form_method' => "POST",
'forums_url' => $LoginScript->ipbForumsURL."act=idx",
'portal_url' => $LoginScript->portalURL,
'forums_reg_url' => $LoginScript->ipbForumsURL."act=Reg&CODE=00"
)
);
}
// =====================
// END MEMBER ONLY
// =====================
// =====================
// Print deh main template
// =====================
$template = load_template($LoginScript->temp_main);
$to_echo = "";
$to_echo .= parse_template( $template,
array (
'memberonly' => $LoginScript->ISloggedin,
'form_guests' => $LoginScript->NOTloggedin,
'onload' => $LoginScript->onload
)
);
echo $to_echo;
exit();
}
?>