*
* 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 .
*/
header('Content-Type: text/html; charset=UTF-8');
header('Pragma: no-cache');
header('Cache-Control: no-cache');
header('Expires: 0');
if($_SERVER['REQUEST_METHOD']==='HEAD'){
exit; // headers sent, no further processing needed
}
// initialize and load variables/configuration
date_default_timezone_set('UTC');
$A=array();// All registered members
$C=array();// Configuration
$F=array();// Fonts
$H=array();// HTML-stuff
$I=array();// Translations
$L=array();// Languages
$P=array();// All present users
$U=array();// This user data
$countmods=0;// Present moderators
$db;// Database connection
$memcached;// Memcached connection
load_config();
// set session variable to cookie if cookies are enabled
if(!isSet($_REQUEST['session']) && isSet($_COOKIE[COOKIENAME])){
$_REQUEST['session']=$_COOKIE[COOKIENAME];
}
load_fonts();
load_lang();
load_html();
check_db();
// main program: decide what to do based on queries
if(!isSet($_REQUEST['action'])){
if(!check_init()){
send_init();
}
send_login();
}elseif($_REQUEST['action']==='view'){
check_session();
send_messages(false);
}elseif($_REQUEST['action']==='jsview'){
check_session();
send_messages(true);
}elseif($_REQUEST['action']==='jsrefresh'){
if(!extension_loaded('json')){
send_fatal_error($I['jsonextrequired']);
}
check_session();
ob_start();
print_messages();
$msgs=ob_get_clean();
ob_start();
print_chatters();
$chatters=ob_get_clean();
echo json_encode(array($_REQUEST['id'], $msgs, $chatters, get_setting('topic')));
}elseif($_REQUEST['action']==='redirect' && !empty($_GET['url'])){
send_redirect($_GET['url']);
}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 || ($U['status']>=3 && $countmods===0 && get_setting('memkick'))){
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'){
if(isSet($_REQUEST['confirm'])){
del_all_messages($U['nickname'], 10, $U['entry']);
}else{
send_del_confirm();
}
}elseif($_REQUEST['what']==='last'){
del_last_message();
}
send_post();
}elseif($_REQUEST['action']==='profile'){
check_session();
$arg='';
if(isSet($_REQUEST['do']) && $_REQUEST['do']==='save'){
$arg=save_profile();
}
send_profile($arg);
}elseif($_REQUEST['action']==='logout'){
kill_session();
send_logout();
}elseif($_REQUEST['action']==='colours'){
check_session();
send_colours();
}elseif($_REQUEST['action']==='notes'){
check_session();
if(!empty($_REQUEST['do']) && $_REQUEST['do']==='admin' && $U['status']>6){
send_notes('admin');
}
if($U['status']<5){
send_access_denied();
}
send_notes('staff');
}elseif($_REQUEST['action']==='help'){
check_session();
send_help();
}elseif($_REQUEST['action']==='admin'){
check_session();
if($U['status']<5){
send_access_denied();
}
if(empty($_REQUEST['do'])){
}elseif($_REQUEST['do']==='clean'){
if($_REQUEST['what']==='choose'){
send_choose_messages();
}elseif($_REQUEST['what']==='selected'){
clean_selected();
}elseif($_REQUEST['what']==='room'){
clean_room();
}elseif($_REQUEST['what']==='nick'){
del_all_messages($_REQUEST['nickname'], $U['status'], 0);
}
}elseif($_REQUEST['do']==='kick'){
if(isSet($_REQUEST['name'])){
if(isSet($_REQUEST['what']) && $_REQUEST['what']==='purge'){
kick_chatter($_REQUEST['name'], $_REQUEST['kickmessage'], true);
}else{
kick_chatter($_REQUEST['name'], $_REQUEST['kickmessage'], false);
}
}
}elseif($_REQUEST['do']==='logout'){
if(isSet($_REQUEST['name'])){
logout_chatter($_REQUEST['name']);
}
}elseif($_REQUEST['do']==='sessions'){
if(isSet($_REQUEST['nick'])){
kick_chatter(array($_REQUEST['nick']), '', false);
}
send_sessions();
}elseif($_REQUEST['do']==='register'){
send_admin(register_guest(3, $_REQUEST['name']));
}elseif($_REQUEST['do']==='superguest'){
send_admin(register_guest(2, $_REQUEST['name']));
}elseif($_REQUEST['do']==='status'){
send_admin(change_status($_REQUEST['name'], $_REQUEST['set']));
}elseif($_REQUEST['do']==='regnew'){
send_admin(register_new($_REQUEST['name'], $_REQUEST['pass']));
}elseif($_REQUEST['do']==='approve'){
approve_session();
send_approve_waiting();
}elseif($_REQUEST['do']==='guestaccess'){
if(isSet($_REQUEST['guestaccess']) && preg_match('/^[0123]$/', $_REQUEST['guestaccess'])){
update_setting('guestaccess', $_REQUEST['guestaccess']);
}
}elseif($_REQUEST['do']==='filter'){
manage_filter();
send_filter();
}elseif($_REQUEST['do']==='linkfilter'){
manage_linkfilter();
send_linkfilter();
}elseif($_REQUEST['do']==='topic'){
if(isSet($_REQUEST['topic'])){
update_setting('topic', htmlspecialchars($_REQUEST['topic']));
}
}elseif($_REQUEST['do']==='passreset'){
send_admin(passreset($_REQUEST['name'], $_REQUEST['pass']));
}
send_admin();
}elseif($_REQUEST['action']==='setup'){
if(!check_init()){
send_init();
}
update_db();
if(!valid_admin()){
send_alogin();
}
$C['bool_settings']=array('suguests', 'imgembed', 'timestamps', 'trackip', 'memkick', 'forceredirect', 'incognito', 'enablejs', 'sendmail', 'modfallback');
$C['colour_settings']=array('colbg', 'coltxt');
$C['msg_settings']=array('msgenter', 'msgexit', 'msgmemreg', 'msgsureg', 'msgkick', 'msgmultikick', 'msgallkick', 'msgclean', 'msgsendall', 'msgsendmem', 'msgsendmod', 'msgsendadm', 'msgsendprv');
$C['number_settings']=array('memberexpire', 'guestexpire', 'kickpenalty', 'entrywait', 'captchatime', 'messageexpire', 'messagelimit', 'keeplimit', 'maxmessage', 'maxname', 'minpass', 'defaultrefresh', 'numnotes');
$C['textarea_settings']=array('rulestxt', 'css');
$C['text_settings']=array('dateformat', 'captchachars', 'redirect', 'chatname', 'mailsender', 'mailreceiver');
$C['settings']=array_merge(array('guestaccess', 'englobalpass', 'globalpass', 'captcha', 'dismemcaptcha', 'topic', 'guestreg'), $C['bool_settings'], $C['colour_settings'], $C['msg_settings'], $C['number_settings'], $C['textarea_settings'], $C['text_settings']); // All settings in the database
if(empty($_REQUEST['do'])){
}elseif($_REQUEST['do']==='save'){
foreach($C['msg_settings'] as $setting){
$_REQUEST[$setting]=htmlspecialchars($_REQUEST[$setting]);
}
foreach($C['number_settings'] as $setting){
settype($_REQUEST[$setting], 'int');
}
$_REQUEST['rulestxt']=preg_replace("/(\r?\n|\r\n?)/", '
', $_REQUEST['rulestxt']);
$_REQUEST['chatname']=htmlspecialchars($_REQUEST['chatname']);
if(!preg_match('/^[a-f0-9]{6}$/i', $_REQUEST['colbg'])){
unset($_REQUEST['colbg']);
}
if(!preg_match('/^[a-f0-9]{6}$/i', $_REQUEST['coltxt'])){
unset($_REQUEST['coltxt']);
}
if($_REQUEST['memberexpire']<5){
$_REQUEST['memberexpire']=5;
}
if($_REQUEST['captchatime']<30){
$_REQUEST['memberexpire']=30;
}
if($_REQUEST['defaultrefresh']<5){
$_REQUEST['defaultrefresh']=5;
}elseif($_REQUEST['defaultrefresh']>150){
$_REQUEST['defaultrefresh']=150;
}
if($_REQUEST['maxname']<1){
$_REQUEST['maxname']=1;
}elseif($_REQUEST['maxname']>50){
$_REQUEST['maxname']=50;
}
if($_REQUEST['maxmessage']<1){
$_REQUEST['maxmessage']=1;
}elseif($_REQUEST['maxmessage']>20000){
$_REQUEST['maxmessage']=20000;
}
if($_REQUEST['numnotes']<1){
$_REQUEST['numnotes']=1;
}
foreach($C['settings'] as $setting){
if(isSet($_REQUEST[$setting])) update_setting($setting, $_REQUEST[$setting]);
}
}elseif($_REQUEST['do']==='backup' && $U['status']==8){
send_backup();
}elseif($_REQUEST['do']==='restore' && $U['status']==8){
restore_backup();
send_backup();
}elseif($_REQUEST['do']==='destroy' && $U['status']==8){
if(isSet($_REQUEST['confirm'])){
destroy_chat();
}else{
send_destroy_chat();
}
}
send_setup();
}elseif($_REQUEST['action']==='init'){
init_chat();
}else{
send_login();
}
// html output subs
function print_stylesheet(){
$css=get_setting('css');
$colbg=get_setting('colbg');
$coltxt=get_setting('coltxt');
echo "";
}
function print_end(){
echo '