2007-10-10 19:15:47 +04:00
|
|
|
<?php
|
|
|
|
/*
|
2009-06-04 02:44:32 +04:00
|
|
|
* This file is part of Mibew Messenger project.
|
2007-10-10 19:15:47 +04:00
|
|
|
*
|
2009-06-04 02:44:32 +04:00
|
|
|
* Copyright (c) 2005-2009 Mibew Messenger Community
|
2007-10-10 19:15:47 +04:00
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
2009-08-04 17:38:37 +04:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* the GNU General Public License Version 2 or later (the "GPL"), in which case
|
|
|
|
* the provisions of the GPL are applicable instead of those above. If you wish
|
|
|
|
* to allow use of your version of this file only under the terms of the GPL, and
|
|
|
|
* not to allow others to use your version of this file under the terms of the
|
|
|
|
* EPL, indicate your decision by deleting the provisions above and replace them
|
|
|
|
* with the notice and other provisions required by the GPL.
|
|
|
|
*
|
2007-10-10 19:15:47 +04:00
|
|
|
* Contributors:
|
|
|
|
* Evgeny Gryaznov - initial API and implementation
|
|
|
|
*/
|
|
|
|
|
2008-06-05 01:36:54 +04:00
|
|
|
require_once('libs/common.php');
|
|
|
|
require_once('libs/chat.php');
|
|
|
|
require_once('libs/operator.php');
|
2009-03-25 02:50:38 +03:00
|
|
|
require_once('libs/groups.php');
|
2008-10-11 01:40:57 +04:00
|
|
|
require_once('libs/expand.php');
|
2007-10-10 19:15:47 +04:00
|
|
|
|
2009-04-05 03:51:16 +04:00
|
|
|
loadsettings();
|
|
|
|
if($settings['enablessl'] == "1" && $settings['forcessl'] == "1") {
|
|
|
|
if(!is_secure_request()) {
|
|
|
|
$requested = $_SERVER['PHP_SELF'];
|
|
|
|
if($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
|
|
|
|
header("Location: ".get_app_location(true,true)."/client.php?".$_SERVER['QUERY_STRING']);
|
|
|
|
} else {
|
2009-04-05 18:20:34 +04:00
|
|
|
die("only https connections are handled");
|
2009-04-05 03:51:16 +04:00
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-10 19:15:47 +04:00
|
|
|
if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
|
|
|
|
|
2008-11-21 19:47:03 +03:00
|
|
|
$chatstyle = verifyparam( "style", "/^\w+$/", "");
|
2009-03-08 23:53:16 +03:00
|
|
|
$info = getgetparam('info');
|
|
|
|
$email = getgetparam('email');
|
2007-10-10 19:15:47 +04:00
|
|
|
$thread = NULL;
|
2009-04-05 03:51:16 +04:00
|
|
|
$firstmessage = NULL;
|
2007-10-10 19:15:47 +04:00
|
|
|
if( isset($_SESSION['threadid']) ) {
|
|
|
|
$thread = reopen_thread($_SESSION['threadid']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !$thread ) {
|
2009-03-25 02:50:38 +03:00
|
|
|
$groupid = "";
|
|
|
|
if($settings['enablegroups'] == '1') {
|
|
|
|
$groupid = verifyparam( "group", "/^\d{1,8}$/", "");
|
|
|
|
if($groupid) {
|
|
|
|
$group = group_by_id($groupid);
|
|
|
|
if(!$group) {
|
|
|
|
$groupid = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-05 03:01:17 +04:00
|
|
|
|
|
|
|
if(!has_online_operators($groupid)) {
|
|
|
|
$page = array();
|
|
|
|
setup_logo();
|
|
|
|
$page['formname'] = topage(getgetparam('name'));
|
|
|
|
$page['formemail'] = topage($email);
|
2009-07-18 17:54:45 +04:00
|
|
|
$page['showcaptcha'] = $settings["enablecaptcha"] == "1" ? "1" : "";
|
2009-06-05 03:01:17 +04:00
|
|
|
$page['info'] = topage($info);
|
|
|
|
expand("styles", getchatstyle(), "leavemessage.tpl");
|
|
|
|
exit;
|
|
|
|
}
|
2009-03-25 02:50:38 +03:00
|
|
|
|
2009-04-05 03:51:16 +04:00
|
|
|
$visitor = visitor_from_request();
|
2009-02-04 02:33:30 +03:00
|
|
|
$referer = isset($_GET['url']) ? $_GET['url'] :
|
|
|
|
(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
|
|
|
|
if(isset($_GET['referrer']) && $_GET['referrer']) {
|
|
|
|
$referer .= "\n".$_GET['referrer'];
|
|
|
|
}
|
2009-04-05 03:51:16 +04:00
|
|
|
|
|
|
|
if($settings['enablepresurvey'] == '1') {
|
|
|
|
if(isset($_POST['survey']) && $_POST['survey'] == 'on') {
|
|
|
|
$firstmessage = getparam("message");
|
|
|
|
$info = getparam("info");
|
|
|
|
$email = getparam("email");
|
|
|
|
if($settings['usercanchangename'] == "1" && isset($_POST['name'])) {
|
|
|
|
$newname = getparam("name");
|
|
|
|
if($newname != $visitor['name']) {
|
|
|
|
$data = strtr(base64_encode(myiconv($webim_encoding,"utf-8",$newname)), '+/=', '-_,');
|
|
|
|
setcookie($namecookie, $data, time()+60*60*24*365);
|
|
|
|
$visitor['name'] = $newname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$referer = urldecode(getparam("referrer"));
|
|
|
|
} else {
|
|
|
|
$page = array();
|
|
|
|
setup_logo();
|
|
|
|
setup_survey($visitor['name'], $email, $groupid, $info, $referer);
|
|
|
|
expand("styles", getchatstyle(), "survey.tpl");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-05 02:51:46 +04:00
|
|
|
$extAddr = $_SERVER['REMOTE_ADDR'];
|
2008-10-03 19:11:02 +04:00
|
|
|
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
|
|
|
|
$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
|
|
|
|
$extAddr = $_SERVER['REMOTE_ADDR'].' ('.$_SERVER['HTTP_X_FORWARDED_FOR'].')';
|
|
|
|
}
|
|
|
|
$userbrowser = $_SERVER['HTTP_USER_AGENT'];
|
2008-06-05 02:51:46 +04:00
|
|
|
$remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
|
2009-04-05 18:20:34 +04:00
|
|
|
|
|
|
|
$link = connect();
|
|
|
|
if(!check_connections_from_remote($remoteHost, $link)) {
|
|
|
|
mysql_close($link);
|
|
|
|
die("number of connections from your IP is exceeded, try again later");
|
|
|
|
}
|
|
|
|
$thread = create_thread($groupid,$visitor['name'], $remoteHost, $referer,$current_locale,$visitor['id'], $userbrowser,$link);
|
2007-10-10 19:15:47 +04:00
|
|
|
$_SESSION['threadid'] = $thread['threadid'];
|
2009-04-05 18:20:34 +04:00
|
|
|
|
2007-10-10 19:15:47 +04:00
|
|
|
if( $referer ) {
|
2009-04-05 18:20:34 +04:00
|
|
|
post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.came.from',array($referer)),$link);
|
2007-10-10 19:15:47 +04:00
|
|
|
}
|
2009-04-05 18:20:34 +04:00
|
|
|
post_message_($thread['threadid'],$kind_info,getstring('chat.wait'),$link);
|
2009-03-08 23:53:16 +03:00
|
|
|
if($email) {
|
2009-04-05 18:20:34 +04:00
|
|
|
post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.visitor.email',array($email)),$link);
|
2009-03-08 23:53:16 +03:00
|
|
|
}
|
2009-02-08 03:28:33 +03:00
|
|
|
if($info) {
|
2009-04-05 18:20:34 +04:00
|
|
|
post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.visitor.info',array($info)),$link);
|
2009-02-08 03:28:33 +03:00
|
|
|
}
|
2009-04-05 03:51:16 +04:00
|
|
|
if($firstmessage) {
|
2009-04-05 18:20:34 +04:00
|
|
|
$postedid = post_message_($thread['threadid'],$kind_user,$firstmessage,$link,$visitor['name']);
|
2009-04-05 03:51:16 +04:00
|
|
|
commit_thread( $thread['threadid'], array('shownmessageid' => $postedid), $link);
|
|
|
|
}
|
2009-04-05 18:20:34 +04:00
|
|
|
mysql_close($link);
|
2007-10-10 19:15:47 +04:00
|
|
|
}
|
|
|
|
$threadid = $thread['threadid'];
|
|
|
|
$token = $thread['ltoken'];
|
|
|
|
$level = get_remote_level($_SERVER['HTTP_USER_AGENT']);
|
2008-11-21 19:47:03 +03:00
|
|
|
header("Location: $webimroot/client.php?thread=$threadid&token=$token&level=$level".($chatstyle ? "&style=$chatstyle" : ""));
|
2007-10-10 19:15:47 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$token = verifyparam( "token", "/^\d{1,8}$/");
|
|
|
|
$threadid = verifyparam( "thread", "/^\d{1,8}$/");
|
|
|
|
$level = verifyparam( "level", "/^(ajaxed|simple|old)$/");
|
|
|
|
|
|
|
|
$thread = thread_by_id($threadid);
|
|
|
|
if( !$thread || !isset($thread['ltoken']) || $token != $thread['ltoken'] ) {
|
|
|
|
die("wrong thread");
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_chatview_for_user($thread, $level);
|
|
|
|
|
|
|
|
$pparam = verifyparam( "act", "/^(mailthread)$/", "default");
|
|
|
|
if( $pparam == "mailthread" ) {
|
2008-10-15 00:21:25 +04:00
|
|
|
expand("styles", getchatstyle(), "mail.tpl");
|
2007-10-10 19:15:47 +04:00
|
|
|
} else if( $level == "ajaxed" ) {
|
2008-10-15 00:21:25 +04:00
|
|
|
expand("styles", getchatstyle(), "chat.tpl");
|
2007-10-10 19:15:47 +04:00
|
|
|
} else if( $level == "simple" ) {
|
2008-10-15 00:21:25 +04:00
|
|
|
expand("styles", getchatstyle(), "chatsimple.tpl");
|
2007-10-10 19:15:47 +04:00
|
|
|
} else if( $level == "old" ) {
|
2008-10-15 00:21:25 +04:00
|
|
|
expand("styles", getchatstyle(), "nochat.tpl");
|
2007-10-10 19:15:47 +04:00
|
|
|
}
|
|
|
|
|
2008-05-06 01:08:57 +04:00
|
|
|
?>
|