*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see .
*/
if($_SERVER['REQUEST_METHOD']=='HEAD') exit; // ignore HEAD requests
date_default_timezone_set('UTC');
$A=array();// All registered members
$C=array();// Configuration
$F=array();// Fonts
$G=array();// Guests: display names
$H=array();// HTML-stuff
$I=array();// Translations
$L=array();// Languages
$M=array();// Members: display names
$P=array();// All present users
$U=array();// This user data
$countmods=0;// Present moderators
$memcached;// Memcached connection
$mysqli;// MySQL database connection
load_fonts();
load_config();
load_lang();
load_html();
check_db();
// set session variable to cookie if cookies are enabled
if(!isSet($_REQUEST['session']) && isSet($_COOKIE[$C['cookiename']])){
$_REQUEST['session']=$_COOKIE[$C['cookiename']];
}
// main program: decide what to do based on queries
if(!isSet($_REQUEST['action'])){
send_login();
}elseif($_REQUEST['action']=='view'){
check_session();
send_messages();
}elseif($_REQUEST['action']=='redirect' && !empty($_GET['url'])){
send_redirect();
}elseif($_REQUEST['action']=='wait'){
send_waiting_room();
}elseif($_REQUEST['action']=='post'){
check_session();
if(isSet($_REQUEST['kick']) && isSet($_REQUEST['sendto']) && valid_nick($_REQUEST['sendto'])){
if($U['status']>=5 || ($C['memkick'] && $countmods==0 && $U['status']>=3)){
if(isSet($_REQUEST['what']) && $_REQUEST['what']=='purge') kick_chatter(array($_REQUEST['sendto']), $_REQUEST['message'], true);
else kick_chatter(array($_REQUEST['sendto']), $_REQUEST['message'], false);
}
}elseif(isSet($_REQUEST['message']) && isSet($_REQUEST['sendto'])){
validate_input();
}
send_post();
}elseif($_REQUEST['action']=='login'){
check_login();
send_frameset();
}elseif($_REQUEST['action']=='controls'){
check_session();
send_controls();
}elseif($_REQUEST['action']=='delete'){
check_session();
if($_REQUEST['what']=='all') del_all_messages($U['nickname']);
if($_REQUEST['what']=='last') del_last_message();
send_post();
}elseif($_REQUEST['action']=='profile'){
check_session();
if(isSet($_REQUEST['do']) && $_REQUEST['do']=='save') save_profile();
send_profile();
}elseif($_REQUEST['action']=='logout'){
kill_session();
send_logout();
}elseif($_REQUEST['action']=='colours'){
check_session();
send_colours();
}elseif($_REQUEST['action']=='notes'){
check_session();
if(!$U['status']>=5) send_login();
send_notes('staff');
}elseif($_REQUEST['action']=='help'){
check_session();
send_help();
}elseif($_REQUEST['action']=='admnotes'){
check_session();
if(!$U['status']>=6) send_login();
send_notes('admin');
}elseif($_REQUEST['action']=='admin'){
check_session();
if(!$U['status']>=5) send_login();
if(!isSet($_REQUEST['do'])){
send_admin();
}elseif($_REQUEST['do']=='clean'){
if($_REQUEST['what']=='choose') send_choose_messages();
if($_REQUEST['what']=='selected') clean_selected();
if($_REQUEST['what']=='room') clean_room();
send_admin();
}elseif($_REQUEST['do']=='kick'){
if(!isSet($_REQUEST['name'])) send_admin();
if(isSet($_REQUEST['what']) && $_REQUEST['what']=='purge') kick_chatter($_REQUEST['name'], $_REQUEST['kickmessage'], true);
else kick_chatter($_REQUEST['name'], $_REQUEST['kickmessage'], false);
send_admin();
}elseif($_REQUEST['do']=='logout'){
if(!isSet($_REQUEST['name'])) send_admin();
logout_chatter($_REQUEST['name']);
send_admin();
}elseif($_REQUEST['do']=='sessions'){
send_sessions();
}elseif($_REQUEST['do']=='register'){
register_guest(3);
check_session();
send_admin();
}elseif($_REQUEST['do']=='superguest'){
register_guest(2);
check_session();
send_admin();
}elseif($_REQUEST['do']=='status'){
change_status();
}elseif($_REQUEST['do']=='regnew'){
register_new();
}elseif($_REQUEST['do']=='approve'){
approve_session();
send_approve_waiting();
}elseif($_REQUEST['do']=='guestaccess'){
if(isSet($_REQUEST['set']) && preg_match('/^[0123]$/', $_REQUEST['set'])){
update_setting('guestaccess', $_REQUEST['set']);
}
}elseif($_REQUEST['do']=='filter'){
manage_filter();
send_filter();
}elseif($_REQUEST['do']=='globalpass'){
if(isSet($_REQUEST['globalpass'])){
update_setting('globalpass', $_REQUEST['globalpass']);
}
if(isSet($_REQUEST['englobalpass']) && preg_match('/^[012]$/', $_REQUEST['englobalpass'])){
update_setting('englobalpass', $_REQUEST['englobalpass']);
}
}
send_admin();
}elseif($_REQUEST['action']=='setup'){
if(!$C['memcached'] || !$num_tables=$memcached->get("$C[dbname]-$C[prefix]num-tables")){
$tables=array("$C[prefix]captcha", "$C[prefix]filter", "$C[prefix]ignored", "$C[prefix]members", "$C[prefix]messages", "$C[prefix]notes", "$C[prefix]sessions", "$C[prefix]settings");
$num_tables=0;
$result=mysqli_query($mysqli, 'SHOW TABLES');
while($tmp=mysqli_fetch_array($result, MYSQLI_NUM)){
if(in_array($tmp[0],$tables)) ++$num_tables;
}
if($C['memcached']) $memcached->set("$C[dbname]-$C[prefix]num-tables", $num_tables, 60);
}
if($num_tables<7) send_init();
update_db();
if(!valid_admin()) send_alogin();
if(!isSet($_REQUEST['do'])){
}elseif($_REQUEST['do']=='guestaccess'){
if(isSet($_REQUEST['set']) && preg_match('/^[0123]$/', $_REQUEST['set'])){
update_setting('guestaccess', $_REQUEST['set']);
}
}elseif($_REQUEST['do']=='messages'){
update_messages();
}elseif($_REQUEST['do']=='rules'){
$_REQUEST['rulestxt']=preg_replace("/\r\n/", '
', $_REQUEST['rulestxt']);
$_REQUEST['rulestxt']=preg_replace("/\n/", '
', $_REQUEST['rulestxt']);
$_REQUEST['rulestxt']=preg_replace("/\r/", '
', $_REQUEST['rulestxt']);
update_setting('rulestxt', $_REQUEST['rulestxt']);
}elseif($_REQUEST['do']=='globalpass'){
if(isSet($_REQUEST['globalpass'])){
update_setting('globalpass', $_REQUEST['globalpass']);
}
if(isSet($_REQUEST['englobalpass']) && preg_match('/^[012]$/', $_REQUEST['englobalpass'])){
update_setting('englobalpass', $_REQUEST['englobalpass']);
}
}elseif($_REQUEST['do']=='dateformat'){
if(isSet($_REQUEST['dateformat'])){
update_setting('dateformat', $_REQUEST['dateformat']);
}
}elseif($_REQUEST['do']=='captcha'){
if(isSet($_REQUEST['captcha'])){
update_setting('captcha', $_REQUEST['captcha']);
}
}
send_setup();
}elseif($_REQUEST['action']=='init'){
init_chat();
}else{
send_login();
}
exit;
// html output subs
function print_credits(){
global $C, $I;
echo '';
if($C['showcredits']){
echo "$I[contributors]
";
echo 'Programming - Daniel Winzen
';
echo 'German - Daniel Winzen
';
echo 'English - Daniel Winzen
';
}
echo "
LE CHAT-PHP - $C[version]";
}
function print_stylesheet($arg1=''){
echo "";
}
function print_end(){
echo '