Simple PHP IRC web client using Ajax calls.

server.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. ///////
  3. // webirc-client - 2013-2020
  4. // (C) Chris Dorman, GPL v3 - (C) Microchat devs
  5. // https://github.com/Pentium44/cwchat
  6. ///////
  7. include_once("config.php");
  8. if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['nick']!=""){
  9. $nick = $_GET['nick'];
  10. $msg = htmlentities(stripcslashes($_GET['msg']));
  11. $line = "";
  12. foreach($channels as $channel) {
  13. $line .= "PRIVMSG $channel :$msg\n";
  14. }
  15. $content = file_get_contents(".$nick.socket");
  16. echo nl2br(htmlentities(stripslashes($content)));
  17. file_put_contents(".$nick.socket", $content . $line);
  18. file_put_contents(".$nick.push", $line);
  19. echo nl2br(htmlentities(stripslashes($line)));
  20. } else if (isset($_GET['get']) && isset($_GET['nick']) && $_GET['nick']!="") {
  21. $nick = $_GET['nick'];
  22. $content = file_get_contents(".$nick.socket");
  23. echo nl2br(htmlentities(stripslashes($content)));
  24. } else if (isset($_GET['do']) && isset($_GET['nick']) && $_GET['nick']!="") {
  25. $nick = $_GET['nick'];
  26. if($_GET['do']=="login") {
  27. // Make sure users DB is clean
  28. file_put_contents(".$nick.socket", "Welcome");
  29. chmod(".$username.socket", 0777);
  30. file_put_contents(".$nick.pingfile", "pong");
  31. chmod(".$username.pingfile", 0777);
  32. $realpath = realpath("./irc.php");
  33. shell_exec("/usr/bin/php $realpath $nick > /dev/null 2>/dev/null &");
  34. } else if($_GET['do']=="logout") {
  35. unlink(".$nick.pingfile");
  36. } else if($_GET['do']=="keepup") {
  37. file_put_contents(".$nick.pingfile", "ping");
  38. }
  39. }
  40. ?>