From 3ee7fca02515179de7cd0ce7fa4ee8ccf653b769 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 28 Aug 2013 12:33:25 +0400 Subject: [PATCH] Add captcha to pre-chat survey --- src/messenger/webim/client.php | 22 +++++++++++++++++-- src/messenger/webim/libs/chat.php | 3 ++- src/messenger/webim/libs/common.php | 1 + src/messenger/webim/locales/en/properties | 2 ++ src/messenger/webim/locales/ru/properties | 2 ++ src/messenger/webim/operator/features.php | 2 +- src/messenger/webim/operator/themes.php | 2 +- .../webim/styles/default/templates/survey.tpl | 6 +++++ .../styles/original/templates/survey.tpl | 11 +++++++++- .../webim/styles/silver/templates/survey.tpl | 10 ++++++++- .../styles/simplicity/templates/survey.tpl | 6 +++++ src/messenger/webim/view/features.php | 9 ++++++++ 12 files changed, 69 insertions(+), 7 deletions(-) diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index 8d13cb97..8d6c1595 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -65,6 +65,16 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { $info = getparam("info"); $email = getparam("email"); $referrer = urldecode(getparam("referrer")); + if ($settings["surveyaskcaptcha"] == "1") { + $captcha = getparam('captcha'); + $original = isset($_SESSION["mibew_captcha"]) + ? $_SESSION["mibew_captcha"] + : ""; + $survey_captcha_failed = empty($original) + || empty($captcha) + || $captcha != $original; + unset($_SESSION['mibew_captcha']); + } if($settings['usercanchangename'] == "1" && isset($_POST['name'])) { $newname = getparam("name"); @@ -93,10 +103,18 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { exit; } - if($settings['enablepresurvey'] == '1' && !(isset($_POST['survey']) && $_POST['survey'] == 'on')) { + $show_survey = $settings['enablepresurvey'] == '1' + && ( + !(isset($_POST['survey']) && $_POST['survey'] == 'on') + || ($settings["surveyaskcaptcha"] == "1" && !empty($survey_captcha_failed)) + ); + if($show_survey) { $page = array(); setup_logo(); - setup_survey($visitor['name'], $email, $groupid, $info, $referrer); + if (!empty($survey_captcha_failed)) { + $errors[] = getlocal('errors.captcha'); + } + setup_survey($visitor['name'], $email, $groupid, $info, $referrer, can_show_captcha()); expand("styles", getchatstyle(), "survey.tpl"); exit; } diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index a52eaad3..0efdd9e9 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -308,7 +308,7 @@ function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info $page['referrer'] = urlencode(topage($referrer)); } -function setup_survey($name, $email, $groupid, $info, $referrer) +function setup_survey($name, $email, $groupid, $info, $referrer, $canshowcaptcha) { global $settings, $page; @@ -317,6 +317,7 @@ function setup_survey($name, $email, $groupid, $info, $referrer) $page['formgroupid'] = $groupid; $page['forminfo'] = topage($info); $page['referrer'] = urlencode(topage($referrer)); + $page['showcaptcha'] = ($settings["surveyaskcaptcha"] == "1" && $canshowcaptcha) ? "1" : ""; if ($settings['enablegroups'] == '1' && $settings["surveyaskgroup"] == "1") { $link = connect(); diff --git a/src/messenger/webim/libs/common.php b/src/messenger/webim/libs/common.php index 62aac72c..4377efbd 100644 --- a/src/messenger/webim/libs/common.php +++ b/src/messenger/webim/libs/common.php @@ -628,6 +628,7 @@ $settings = array( 'surveyaskmail' => '0', 'surveyaskgroup' => '1', 'surveyaskmessage' => '0', + 'surveyaskcaptcha' => '0', 'enablepopupnotification' => '0', 'showonlineoperators' => '0', 'enablecaptcha' => '0', diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index 448cf43b..f1b07385 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -491,6 +491,8 @@ settings.saved=Changes saved settings.sendmessagekey=Send messages with: settings.show_online_operators.description=Can slow down the update rate of the list settings.show_online_operators=Show online operators on "List of awaiting visitors" page +settings.survey.askcaptcha.description=Protection against automated spam (captcha) +settings.survey.askcaptcha=Force visitor to enter a verification code settings.survey.askgroup.description=Show/hide department selection field in the survey settings.survey.askgroup=Allows a visitor to choose department/group settings.survey.askmail.description=Show/hide email field in the survey diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index dfa08c06..bc54604e 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -487,6 +487,8 @@ settings.saved= settings.sendmessagekey=Посылать сообщение по: settings.show_online_operators.description=Может замедлить обновление списка settings.show_online_operators=Показывать доступных операторов на странице ожидающих посетителей +settings.survey.askcaptcha.description=Защита от автоматизированного спама (captcha) +settings.survey.askcaptcha=Завершать опрос только после ввода специального кода с картинки settings.survey.askgroup.description=Показать/спрятать выбор группы в диалоге перед началом чата settings.survey.askgroup=Позволять посетителю выбирать группу операторов settings.survey.askmail.description=Показать/спрятать поле ввода адреса электронной почты diff --git a/src/messenger/webim/operator/features.php b/src/messenger/webim/operator/features.php index f319b09c..20f6290b 100644 --- a/src/messenger/webim/operator/features.php +++ b/src/messenger/webim/operator/features.php @@ -29,7 +29,7 @@ $options = array( 'enableban', 'usercanchangename', 'enablegroups', 'enablestatistics', 'enablejabber', 'enablessl', 'forcessl', 'enablepresurvey', 'surveyaskmail', 'surveyaskgroup', 'surveyaskmessage', - 'enablepopupnotification', 'showonlineoperators', + 'surveyaskcaptcha', 'enablepopupnotification', 'showonlineoperators', 'enablecaptcha'); loadsettings(); diff --git a/src/messenger/webim/operator/themes.php b/src/messenger/webim/operator/themes.php index 982b0d41..1b3bf601 100644 --- a/src/messenger/webim/operator/themes.php +++ b/src/messenger/webim/operator/themes.php @@ -57,7 +57,7 @@ if ($show == 'chat' || $show == 'mail' || $show == 'leavemessage' || $show == 'l } if ($show == 'survey') { loadsettings(); - setup_survey("Visitor", "", "", "", "http://google.com"); + setup_survey("Visitor", "", "", "", "http://google.com", false); setup_logo(); expand("../styles", "$preview", "$show.tpl"); exit; diff --git a/src/messenger/webim/styles/default/templates/survey.tpl b/src/messenger/webim/styles/default/templates/survey.tpl index 2520a730..831aa878 100644 --- a/src/messenger/webim/styles/default/templates/survey.tpl +++ b/src/messenger/webim/styles/default/templates/survey.tpl @@ -139,6 +139,12 @@ ${if:showmessage} ${endif:showmessage} +${if:showcaptcha} + + + + +${endif:showcaptcha} diff --git a/src/messenger/webim/styles/original/templates/survey.tpl b/src/messenger/webim/styles/original/templates/survey.tpl index a9ee4b58..138a4948 100644 --- a/src/messenger/webim/styles/original/templates/survey.tpl +++ b/src/messenger/webim/styles/original/templates/survey.tpl @@ -107,7 +107,16 @@ ${if:showmessage} ${endif:showmessage} - + +${if:showcaptcha} + + + + + + +${endif:showcaptcha} +
diff --git a/src/messenger/webim/styles/silver/templates/survey.tpl b/src/messenger/webim/styles/silver/templates/survey.tpl index 13fc61ae..e92ebdd0 100644 --- a/src/messenger/webim/styles/silver/templates/survey.tpl +++ b/src/messenger/webim/styles/silver/templates/survey.tpl @@ -39,7 +39,9 @@
- + ${if:errors} + ${errors} + ${endif:errors}
@@ -72,6 +74,12 @@ ${endif:showmessage} + ${if:showcaptcha} + + + + + ${endif:showcaptcha} ${msg:presurvey.submit}
 
diff --git a/src/messenger/webim/styles/simplicity/templates/survey.tpl b/src/messenger/webim/styles/simplicity/templates/survey.tpl index 244d23a4..84337981 100644 --- a/src/messenger/webim/styles/simplicity/templates/survey.tpl +++ b/src/messenger/webim/styles/simplicity/templates/survey.tpl @@ -63,6 +63,12 @@ ${endif:showmessage} + ${if:showcaptcha} + + + + + ${endif:showcaptcha} diff --git a/src/messenger/webim/view/features.php b/src/messenger/webim/view/features.php index b7577e72..bb77bfe6 100644 --- a/src/messenger/webim/view/features.php +++ b/src/messenger/webim/view/features.php @@ -173,6 +173,15 @@ require_once('inc_errors.php');

+ +
+
+
+ /> +
+
+
+