• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ General Support (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Quick hack for a global user /kick

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
11 posts • Page 1 of 1

Postby iezzip » Wed Apr 26, 2006 5:36 pm

I love your application but I just can't wait for v.1.0 and need some way to kick a user. Actually I want to kick them all (because they deserve it!).
I'm doing authentication on my own and once the admin logs out, the whole channel gets deleted (say: remove the whole phpfreechat/data/private/chat/*channel* directory). On logout there should be no way to track back an old chat-session, so this seemed to be the easiest way to go.
Now I'm getting tons of Ajax-warnings.
Could anybody give me a hint how to write a quick hack to avoid those Ajax-warnings for the other still logged-in users and redirect them to a different page?

phpfreechat/src/phpfreechatcontainerfile.class.php, line 170 (function updateNick()):

Code: Select all
    if (!@touch($my_filename)) {
       // do something like a header("Location: http://..."); here
       // but in the ajax-way ...I'm pretty new to Ajax.
    }

Thx a lot!!
iezzip
New member
 
Posts: 9
Joined: Wed Apr 26, 2006 5:00 pm
Top

Postby phpfreechat » Wed Apr 26, 2006 6:27 pm

I had a few minutes to help you, I wrote a small patch based on your @touch return value :

Code: Select all
Index: phpfreechatcontainerfile.class.php
===================================================================
--- phpfreechatcontainerfile.class.php  (révision 473)
+++ phpfreechatcontainerfile.class.php  (copie de travail)
@@ -162,15 +162,15 @@
   function updateNick($nickname)
   {
     $c =& $this->c;
-    $there = false;
+    $ret = 0;

     // update my online status file
     $my_filename = $c->container_cfg_nickname_dir."/".$this->_encode($c->nick);
-    if (file_exists($my_filename)) $there = true;
-    touch($my_filename);
-    @chmod($my_filename, 0777);
+    if (file_exists($my_filename)) $ret = 1;
+    if (!@touch($my_filename)) $ret = 2;
+    @chmod($my_filename, 0777);

-    return $there;
+    return $ret;
   }

   /**
Index: pfccommand_updatemynick.class.php
===================================================================
--- pfccommand_updatemynick.class.php   (révision 473)
+++ pfccommand_updatemynick.class.php   (copie de travail)
@@ -8,8 +8,9 @@
   {
     $c =& $this->c;
     $container =& $c->getContainerInstance();
-    $was_there = $container->updateNick($c->nick);
-    if (!$was_there)
+    $ret = $container->updateNick($c->nick);
+    if ($ret == 2) $xml_reponse->addRedirect("http://www.google.com");
+    //    if (!$was_there)
     {
       /*
       @todo: write the timeout adjustment when the user object will be available
@@ -22,4 +23,4 @@
   }
 }

-?>
 No newline at end of file
+?>

Keep me informed if it works.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby iezzip » Wed Apr 26, 2006 6:41 pm

Wow Kerphi! You are wonderful!

Thanks a lot. That's exactly what I was looking for. Works like a charm - deleting directory and all users get kicked right away. Something like this should be implemented in the params, e.g.:
$params["redirectondelete"]

Have a nice evening
and one more time: THANKS!!!
pipo
iezzip
New member
 
Posts: 9
Joined: Wed Apr 26, 2006 5:00 pm
Top

Postby phpfreechat » Wed Apr 26, 2006 6:53 pm

In the 0.x branche I will not implement the /kick command and I will not change anymore the container API.
However I take in consideration your idea for the next 1.x branche which will support real moderation.

regards,
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby iezzip » Fri May 12, 2006 10:15 am

Hi kerphi / hi all

I've got one more problem with your wonderful hack:
Once I delete the chat directory in /data/private/chat/ all users get correctly kicked out and redirected to a given URL. Now, I'd like to re-open a chat in the same browser window. phpFreeChat/Ajax prints a whole bunch of errors (see below).
Somehow the phpFreeChat-Session must be deleted. I'm not able to close the browser window and re-open it, because my users should stay logged in in my phpFreeChat-external application.
If you provide me a solution during the next couple of hours, I'm ready to contribute by PayPal. My problem is that I'm leaving for vacation tomorrow and this whole thing should be up and running by the end of the day.
But hey, anyway I'd like to support your GREAT project!!!

take care
Pipo


** PHP Error Messages: **
----
[WARNING] opendir(D:DP_devphpfreechatsrc/../data/private/chat/chat143chphpfreechat/nicknames) [<a href='function.opendir'>function.opendir</a>]: failed to open dir: Invalid argument
error in line 250 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
----
[WARNING] readdir(): supplied argument is not a valid Directory resource
error in line 251 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
----
[WARNING] file(D:DP_devphpfreechatsrc/../data/private/chat/chat143chphpfreechat/messages.data) [<a href='function.file'>function.file</a>]: failed to open stream: No such file or directory
error in line 293 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
----
[WARNING] array_slice() [<a href='function.array-slice'>function.array-slice</a>]: The first argument should be an array
error in line 296 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
----
[WARNING] implode() [<a href='function.implode'>function.implode</a>]: Bad arguments.
error in line 298 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
----
[WARNING] fopen(D:DP_devphpfreechatsrc/../data/private/chat/chat143chphpfreechat/messages.data) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory
error in line 300 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
----
[WARNING] flock() expects parameter 1 to be resource, boolean given
error in line 301 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
----
[WARNING] flock() expects parameter 1 to be resource, boolean given
error in line 303 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
----
[WARNING] fclose(): supplied argument is not a valid stream resource
error in line 304 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
----
[WARNING] Invalid argument supplied for foreach()
error in line 309 of file D:DP_devphpfreechatsrcphpfreechatcontainerfile.class.php
Last edited by iezzip on Fri May 12, 2006 10:16 am, edited 1 time in total.
iezzip
New member
 
Posts: 9
Joined: Wed Apr 26, 2006 5:00 pm
Top

Postby phpfreechat » Fri May 12, 2006 12:40 pm

Try to change this line :
Code: Select all
if ($ret == 2) $xml_reponse->addRedirect("http://www.google.com");

To :
Code: Select all
  if ($ret == 2)
  {
    unset($_COOKIE["phpfreechat"]);
    $xml_reponse->addRedirect("http://www.google.com");
  }

If it doesn't work, try that:
Code: Select all
  if ($ret == 2)
  {
    session_destroy();
    $xml_reponse->addRedirect("http://www.google.com");
  }

The basic idea is to clear the user session in order to forgot the obsolete cached parameters.

Keep me informed.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby iezzip » Fri May 12, 2006 1:31 pm

Hi Kerphi

Thanks a lot for your solution!!
The first one (unsetting the phpfreechat cookie) didn't work but the second one (session_destroy()) worked great. Glad I'm using my own implementation of session management, like this it's not interfering with my own sessions.

hey, you really deserve it!!, I've just transfered EUR 50.00 to your PayPal account.

take care and enjoy the sun
pipo
iezzip
New member
 
Posts: 9
Joined: Wed Apr 26, 2006 5:00 pm
Top

Postby phpfreechat » Fri May 12, 2006 1:43 pm

Thank you for your paypal contribution, it will motivate my work a bit more :)

I don't understand well why the unset($_COOKIE["phpfreechat"]); solution doesn't work.
Maybe try to do that :
Code: Select all
if (isset($_COOKIE[session_name()])) {
   setcookie(session_name(), '', time()-42000, '/');
}

Just deleting the phpfreechat cookie should be cleaner than a brutal session_destroy(). But as you have your own session managment, the second solution is ok.
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby iezzip » Sun Jun 18, 2006 2:38 pm

Hi Kerphi

I'm currently switching from 0.9.3 to 1.0-beta2 and I'm a bit stuck figuring out how to patch the new files with your hack presented above in post 1234
Could you please provide me with the modified hack for 1.0-beta2? I would really appreciate that.

Thanks lot!
pipo
iezzip
New member
 
Posts: 9
Joined: Wed Apr 26, 2006 5:00 pm
Top

Postby iezzip » Fri Jul 07, 2006 9:21 am

hi kerphi

thanks for another great beta!
If you provide me with a nice implementation of this small hack in 1.0-beta3, I'm more than willing to press the PayPal button again! :)

thanx a lot!
pipo
iezzip
New member
 
Posts: 9
Joined: Wed Apr 26, 2006 5:00 pm
Top

Postby phpfreechat » Fri Jul 07, 2006 12:54 pm

I like when people press the Paypal button :)

So here is a more clean patch to support "chat locking" feature.
I integrated this patch to the official code, but I will maybe rename the parameters in future, I was not very inspired with the "lock" appellation. Feel free to suggest a better name for this feature.


Code: Select all
Modified: trunk/src/pfcglobalconfig.class.php
===================================================================
--- trunk/src/pfcglobalconfig.class.php 2006-07-07 07:48:48 UTC (rev 651)
+++ trunk/src/pfcglobalconfig.class.php 2006-07-07 11:45:12 UTC (rev 652)
@@ -36,9 +36,12 @@
  var $nick                = ""; // the initial nickname ("" means the user will be queried)
  var $isadmin             = false;
  var $admins              = array("admin" => ""); // nicknames is the key, password is the value
+
+  var $islocked            = false; // set this parameter to true to lock the chat for all users
+  var $lockurl             = "http://www.phpfreechat.net"; // this is the url where the users must be redirected when the chat is locked

  // these parameters are static (cached)
-  var $proxys              = array("auth", "noflood", "censor");
+  var $proxys              = array("lock", "auth", "noflood", "censor");
  var $proxys_cfg          = array("auth"    => array(),
                                   "noflood" => array("limit"=>10,"delay"=>5),
                                   "censor"  => array("words"=>array("fuck","sex","bitch"),"replaceby"=>"*"));
@@ -459,9 +462,10 @@
      $pfc_configvar = unserialize(file_get_contents($cachefile));
      foreach($pfc_configvar as $key => $val)
      {
-        // the 'nick' and 'isadmin' are dynamic parameters, it must not be cached
+        // the 'nick', 'isadmin', and 'islocked' are dynamic parameters, it must not be cached
        if ($key != "nick" &&
-            $key != "isadmin")
+            $key != "isadmin" &&
+            $key != "islocked" )
          $this->$key = $val;
      }


Added: trunk/src/proxys/lock.class.php
===================================================================
--- trunk/src/proxys/lock.class.php                             (rev 0)
+++ trunk/src/proxys/lock.class.php     2006-07-07 11:45:12 UTC (rev 652)
@@ -0,0 +1,51 @@
+<?php
+/**
+ * lock.class.php
+ *
+ * Copyright © 2006 Stephane Gully <stephane.gully@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ */
+require_once dirname(__FILE__)."/../pfci18n.class.php";
+require_once dirname(__FILE__)."/../pfcuserconfig.class.php";
+require_once dirname(__FILE__)."/../pfcproxycommand.class.php";
+
+/**
+ * pfcProxyCommand_lock
+ * if the chat is locked, redirect users to a given url
+ * @author Stephane Gully <stephane.gully@gmail.com>
+ */
+class pfcProxyCommand_lock extends pfcProxyCommand
+{
+  function run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid)
+  {
+    $c =& $this->c;
+    $u =& $this->u;
+
+    // check if the chat is locked
+    if ($c->islocked)
+    {
+      $xml_reponse->addRedirect($c->lockurl);
+    }
+    else
+    {
+      // forward the command to the next proxy or to the final command
+      $this->next->run(&$xml_reponse, $clientid, $param, $sender, $recipient, $recipientid);
+    }
+  }
+}
+
+?>

In fact, just use the "islocked" and "lockurl" parameters to configure the redirection and the chat lock status.
Ex: to lock the chat
Code: Select all
<?php

require_once "src/phpfreechat.class.php"; // adjust to your own path
$params["serverid"] = md5(__FILE__); // used to identify the chat
$params["islocked"] = true;
$params["lockurl"] = "http://www.google.fr"; // this will redirect users to google when the chat is locked.
$chat = new phpFreeChat($params);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>phpFreeChat demo</title>
    <?php $chat->printJavascript(); ?>
    <?php $chat->printStyle(); ?>
  </head>
  <body>
    <?php $chat->printChat(); ?>
  </body>
</html>

Thank you for your support.

regards,
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top


Post a reply
11 posts • Page 1 of 1

Return to General Support (v1.x)

Who is online

Users browsing this forum: No registered users and 17 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
cron
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub