Author Topic: user ban question  (Read 11271 times)

0 Members and 1 Guest are viewing this topic.

power87

  • Full Member
  • ***
  • Posts: 7
user ban question
« on: August 19, 2013, 05:56:33 PM »
Hi,

i m using mibew as a direct chat - the users are able to click on the chatbutton and they land directly in the chat. For this user comfort i must accept spam of course i added the ip adresses to the spamlist but i still receive notifications with the tray icon.

Any option to go on with my direct chat and ban spam/googlebot etc. or must i enable a form before?

Dmitriy Simushev

  • Moderator
  • Native
  • *****
  • Posts: 345
Re: user ban question
« Reply #1 on: August 20, 2013, 08:59:03 AM »
Hi,

In version 1.6.5 banned visitors only marked as spam bots but not removed from the visitors list.

Some kind of fix is discribed here http://mibew.org/forums/index.php/topic,938.msg195653.html#msg195653.
I should notice that we did not test it, so use it on your own risk.

power87

  • Full Member
  • ***
  • Posts: 7
Re: user ban question
« Reply #2 on: August 20, 2013, 05:08:03 PM »
thx a lot for your answer, can you help me to add this new lines into the .php file. I am not a programmer and the description is not clear enough for me:
I've got a fix that prevent chats from banned IPs to be shown in the list.

In the file update.php, function thread_to_xml, add these lines just before the return $result; line in the end of the function:

if ($banForThread) {
$result = "";
}

i copy the whole function here, maybe you can add the code for me :)

Code: [Select]
function thread_to_xml($thread, $link)
{
global $state_chatting, $threadstate_to_string, $threadstate_key,
$webim_encoding, $operator, $settings,
$can_viewthreads, $can_takeover, $mysqlprefix;
$state = $threadstate_to_string[$thread['istate']];
$result = "<thread id=\"" . $thread['threadid'] . "\" stateid=\"$state\"";
if ($state == "closed")
return $result . "/>";

$state = getstring($threadstate_key[$thread['istate']]);
$nextagent = $thread['nextagent'] != 0 ? operator_by_id_($thread['nextagent'], $link) : null;
$threadoperator = $nextagent ? get_operator_name($nextagent)
: ($thread['agentName'] ? $thread['agentName'] : "-");

if ($threadoperator == "-" && $thread['groupname']) {
$threadoperator = "- " . $thread['groupname'] . " -";
}

if (!($thread['istate'] == $state_chatting && $thread['agentId'] != $operator['operatorid'] && !is_capable($can_takeover, $operator))) {
$result .= " canopen=\"true\"";
}
if ($thread['agentId'] != $operator['operatorid'] && $thread['nextagent'] != $operator['operatorid']
&& is_capable($can_viewthreads, $operator)) {
$result .= " canview=\"true\"";
}
if ($settings['enableban'] == "1") {
$result .= " canban=\"true\"";
}

$banForThread = $settings['enableban'] == "1" ? ban_for_addr_($thread['remote'], $link) : false;
if ($banForThread) {
$result .= " ban=\"blocked\" banid=\"" . $banForThread['banid'] . "\"";
}

$result .= " state=\"$state\" typing=\"" . $thread['userTyping'] . "\">";
$result .= "<name>";
if ($banForThread) {
$result .= htmlspecialchars(getstring('chat.client.spam.prefix'));
}
$result .= htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'], $thread['remote'], $thread['userid']))) . "</name>";
$result .= "<addr>" . htmlspecialchars(get_user_addr($thread['remote'])) . "</addr>";
$result .= "<agent>" . htmlspecialchars(htmlspecialchars($threadoperator)) . "</agent>";
$result .= "<time>" . $thread['unix_timestamp(dtmcreated)'] . "000</time>";
$result .= "<modified>" . $thread['unix_timestamp(dtmmodified)'] . "000</modified>";

if ($banForThread) {
$result .= "<reason>" . $banForThread['comment'] . "</reason>";
}

$userAgent = get_useragent_version($thread['userAgent']);
$result .= "<useragent>" . $userAgent . "</useragent>";
if ($thread["shownmessageid"] != 0) {
$query = "select tmessage from ${mysqlprefix}chatmessage where messageid = " . $thread["shownmessageid"];
$line = select_one_row($query, $link);
if ($line) {
$message = preg_replace("/[\r\n\t]+/", " ", $line["tmessage"]);
$result .= "<message>" . htmlspecialchars(htmlspecialchars($message)) . "</message>";
}
}
$result .= "</thread>";
return $result;
}

faf

  • Mibew Staff Member
  • Native
  • *****
  • Posts: 951
    • Mibew Messenger
Re: user ban question
« Reply #3 on: August 21, 2013, 11:27:51 AM »
@power87

Without offense, but are you sure you want to change any PHP code without even basic knowledge of the subject? It seems a little bit risky and irresponsible...

As for the recipe above, actually the instructions were plain and simple. Here is your modified function if you really sure that you want it:

Code: [Select]
function thread_to_xml($thread, $link)
{
global $state_chatting, $threadstate_to_string, $threadstate_key,
$webim_encoding, $operator, $settings,
$can_viewthreads, $can_takeover, $mysqlprefix;
$state = $threadstate_to_string[$thread['istate']];
$result = "<thread id=\"" . $thread['threadid'] . "\" stateid=\"$state\"";
if ($state == "closed")
return $result . "/>";

$state = getstring($threadstate_key[$thread['istate']]);
$nextagent = $thread['nextagent'] != 0 ? operator_by_id_($thread['nextagent'], $link) : null;
$threadoperator = $nextagent ? get_operator_name($nextagent)
: ($thread['agentName'] ? $thread['agentName'] : "-");

if ($threadoperator == "-" && $thread['groupname']) {
$threadoperator = "- " . $thread['groupname'] . " -";
}

if (!($thread['istate'] == $state_chatting && $thread['agentId'] != $operator['operatorid'] && !is_capable($can_takeover, $operator))) {
$result .= " canopen=\"true\"";
}
if ($thread['agentId'] != $operator['operatorid'] && $thread['nextagent'] != $operator['operatorid']
&& is_capable($can_viewthreads, $operator)) {
$result .= " canview=\"true\"";
}
if ($settings['enableban'] == "1") {
$result .= " canban=\"true\"";
}

$banForThread = $settings['enableban'] == "1" ? ban_for_addr_($thread['remote'], $link) : false;
if ($banForThread) {
$result .= " ban=\"blocked\" banid=\"" . $banForThread['banid'] . "\"";
}

$result .= " state=\"$state\" typing=\"" . $thread['userTyping'] . "\">";
$result .= "<name>";
if ($banForThread) {
$result .= htmlspecialchars(getstring('chat.client.spam.prefix'));
}
$result .= htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'], $thread['remote'], $thread['userid']))) . "</name>";
$result .= "<addr>" . htmlspecialchars(get_user_addr($thread['remote'])) . "</addr>";
$result .= "<agent>" . htmlspecialchars(htmlspecialchars($threadoperator)) . "</agent>";
$result .= "<time>" . $thread['unix_timestamp(dtmcreated)'] . "000</time>";
$result .= "<modified>" . $thread['unix_timestamp(dtmmodified)'] . "000</modified>";

if ($banForThread) {
$result .= "<reason>" . $banForThread['comment'] . "</reason>";
}

$userAgent = get_useragent_version($thread['userAgent']);
$result .= "<useragent>" . $userAgent . "</useragent>";
if ($thread["shownmessageid"] != 0) {
$query = "select tmessage from ${mysqlprefix}chatmessage where messageid = " . $thread["shownmessageid"];
$line = select_one_row($query, $link);
if ($line) {
$message = preg_replace("/[\r\n\t]+/", " ", $line["tmessage"]);
$result .= "<message>" . htmlspecialchars(htmlspecialchars($message)) . "</message>";
}
}
$result .= "</thread>";

if ($banForThread) {
$result = "";
}

return $result;
}

But as it was stated previously we did not test this recipe, so use it at your own risk. And don't ask us about what could go wrong. We don't know.

power87

  • Full Member
  • ***
  • Posts: 7
Re: user ban question
« Reply #4 on: August 21, 2013, 05:51:43 PM »
thanks for your help, i was a bit irrated about the 2nd return result.
What could happen in the worst case, do my server epxlode?  ;D

When its not working i will add the form before and remove the 2 lines of code, when its working i will leave another message.
The form is not very userfriendly, i want to have "one click and chat" as it is at the moment but the banned bots are a bit annoying.