<?PHP
// Import the configuration file
include("./config.php");
// Test to see if it is installed
if(!isset($X7CHAT_CONFIG['INSTALLED'])){
header("location: ./install.php");
echo "<a href=\"./install.php\">Click Here to Install X7 Chat 2.0.0A3</a>";
exit;
}
// Test to make sure the user didn't miss the last install step
if(@$_GET['act'] != "frame"){
if(file_exists("./install.php") || file_exists("./upgradev1.php")){
print("<div align='center'><font color='red'>You must delete the files install.php and upgradev1.php before using the chatroom.</font></div>");
exit;
}
}
// Import the database library
include("./lib/db/".strtolower($X7CHAT_CONFIG['DB_TYPE']).".php");
// Create a new database connection
$db = new x7chat_db();
// Include the classes needed for loading
// Include the security
include("./lib/security.php");
// Clean all incoming data
parse_incoming();
include("./lib/load.php");
// Load the server variables
$x7c = new settings();
// Clean up the database a tad
include("./lib/cleanup.php");
cleanup_banned();
// Include the authentication functions
include("./lib/auth.php");
// Include the AuthMod file
include("./lib/auth/".strtolower($X7CHAT_CONFIG['AUTH_MODE']).".php");
// Force Settings from AuthMod
if($auth_disable_guest)
$x7c->settings['allow_guests'] = 0;
// Create a new session
$x7s = new session();
// Is the user trying to login? If so give them a cookie
if(isset($_POST['dologin']) && @$_POST['username'] != "")
$x7s->dologin();
// The alternate way to login is using GETs, check for that
if(isset($_GET['dologin']) && @$_GET['username'] != ""){
$_POST['username'] = $_GET['username'];
$_POST['password'] = $_GET['password'];
$x7s->dologin();
}
// If the user is logged in then load their settings and profile
if($x7s->loggedin == 1){
$x7p = new profile_info($x7s->username);
$x7c->usersettings();
}
// Include the language file
include("./lang/".$x7c->settings['default_lang'].".php");
// Include the output library
include("./lib/output.php");
// Load the skin data
$print = new load_skin($x7c->settings['default_skin']);
// Run these cleanups only if you are not part of a frame
if(@$_GET['act'] != "frame"){
cleanup_messages();
cleanup_guests();
}
// Now before all else we have to get them logged in if they are not already
// We also have to check and make sure they are not trying to register or remember their password which they stupidly forgot or get help or anything like that
// THis array contins the functions that you don't hvae to be logged in to do
$no_login_req[] = "register";
$no_login_req[] = "forgotmoipass";
$no_login_req[] = "sm_window";
$no_login_req[] = "help";
if($x7s->loggedin == 0 && !in_array(@$_GET['act'],$no_login_req)){
// They are not logged in
// Include controls for login and logout
include("./counter-lib.php");
page_login();
$print->dump_buffer();
exit;
}elseif($x7s->loggedin == 2 && !in_array(@$_GET['act'],$no_login_req)){
// They tried to login but with an incorrect pass or username
include("./counter-lib.php");
page_login("failed");
$print->dump_buffer();
exit;
}elseif($x7s->loggedin == 3 && !in_array(@$_GET['act'],$no_login_req)){
// They tried to login but their username was invalid
include("./counter-lib.php");
page_login("invalid");
$print->dump_buffer();
exit;
}elseif($x7s->loggedin == 4 && !in_array(@$_GET['act'],$no_login_req)){
// They tried to login but their username was invalid
include("./counter-lib.php");
page_login("activated");
$print->dump_buffer();
exit;
}
// Prevent their username and room from being deleted
prevent_cleanup();
// If the user has just entered as a guest then we need to remove old logs
// This variable is set in lib/auth.php IF it is set at all
if(isset($remove_old_guest_logs))
cleanup_guest_logs($x7s->username);
// Prevent errors
if(!isset($_GET['act']))
$_GET['act'] = "";
// We cannot allow a user to start the frameset without choosing a room
if($_GET['act'] == "frame" && $x7c->room_name == "")
$_GET['act'] = "";
// Test to see if server is running in single room mode
if($x7c->settings['single_room_mode'] != ""){
// Set the room name
$_GET['room'] = $x7c->settings['single_room_mode'];
// Fix problems with room passwords
$x7c->room_info($_GET['room']);
// Set action to frameset
if($_GET['act'] == "")
$_GET['act'] = "frame";
}
// See if the room is password protected
if(isset($_GET['room'])){
include("./sources/room_password.php");
$cookie_name = "rpw_".$x7c->room_data['id'];
// See if a cookie password is set
if(!isset($_COOKIE[$cookie_name]))
$_COOKIE[$cookie_name] = "";
// See if the password form was filled out
if(isset($_POST['room_pw']))
$_COOKIE[$cookie_name] = $_POST['room_pw'];
// Check the password returns 1 if correct, 2 if incorrect and 0 if there is no password
$result = check_password($_GET['room'],$_COOKIE[$cookie_name]);
if($result == 1){
setcookie($cookie_name,$_COOKIE[$cookie_name],time()+$x7c->settings['cookie_time'],$X7CHAT_CONFIG['COOKIE_PATH']);
}elseif($result == 2 && $x7c->permissions['access_pw_rooms'] != 1){
roomlogin_screen($_GET['room']);
$print->dump_buffer();
exit;
}
}
// See if a bandwidth error is occuring
if($x7c->settings['log_bandwidth'] == 1){
include("./lib/bandwidth.php");
$BW_CHECK = check_bandwidth($x7s->username);
if($BW_CHECK && ((@$_GET['frame'] != 'update' || $_GET['act'] != 'frame') && (@$_GET['pmf'] != "update" || $_GET['act'] != "pm")))
$_GET['act'] = "bw_error";
}
// See if the admin has disabled the chat server
if($x7c->settings['disable_chat'] == 1 && @$_GET['act'] != "logout" && $x7c->permissions['access_disabled'] != 1)
$_GET['act'] = "disabledchat";
// Time to see what's happening! The $act variable stored what the
// user wants to see. We need to determine that and bring up the
// correct page
// See if they are banned from this server
include("./lib/ban.php");
$x7p->bans_on_you = get_bans_onyou();
$bans = $x7p->bans_on_you;
foreach($bans as $key=>$row){
if($row[1] == "*" && ((@$_GET['frame'] != 'update' || $_GET['act'] != 'frame') && (@$_GET['pmf'] != "update" || $_GET['act'] != "pm"))){ // The reason we see if they are getting the update frame is cuz if they are we need to let them so it'll remove them from the room they are in now
$_GET['act'] = "sbanned";
$ban_reason = $row[5];
// Remove them from all online lists
$db->DoQuery("DELETE FROM {$prefix}online WHERE name='$x7s->username'");
}
}
// Ok let's see what's inside
switch($_GET['act']){
case "logout":
// The user is leaving us

setcookie($auth_ucookie,"",time()-$x7c->settings['cookie_time']-63000000,$X7CHAT_CONFIG['COOKIE_PATH']);
setcookie($auth_pcookie,"",time()-$x7c->settings['cookie_time']-63000000,$X7CHAT_CONFIG['COOKIE_PATH']);
// If the admin has choosen where to send the user to then send them there
$to_send = $x7c->settings['logout_page'];
if($to_send != ""){
header("Location: $to_send");
}else{
$print->normal_window($txt[16],"$txt[17]<br><Br> <a href=\"index.php\">[$txt[0]]</a>");
$print->dump_buffer();
exit;
}
break;
case "panic":
// Core error (probably database)
$print->normal_window($txt[14],"$txt[597]<Br><br><hr><b>Error Dump</b><br>$_GET[dump]<Br>$_GET[source]<Br>");
$print->dump_buffer();
exit;
break;
// Chat is disabled and user is not an admin
case "disabledchat":
$print->normal_window($txt[14],$txt[39]);
$print->dump_buffer();
exit;
break;
}
?>