浏览代码

Call this v1.3.0

Pentium44 4 年前
父节点
当前提交
2ebb907af0
共有 11 个文件被更改,包括 273 次插入94 次删除
  1. 37 0
      .Chraas.socket
  2. 35 0
      .Chraas2.socket
  3. 31 0
      .Unnamed.socket
  4. 6 0
      README.md
  5. 8 3
      config.php
  6. 11 4
      index.php
  7. 70 57
      irc.php
  8. 0 1
      log.txt
  9. 73 19
      server.php
  10. 0 8
      start.php
  11. 2 2
      style.css

+ 37 - 0
.Chraas.socket 查看文件

@@ -0,0 +1,37 @@
1
+:cddo.cf 001 Chraas :Hi, welcome to IRC
2
+:cddo.cf 002 Chraas :Your host is cddo.cf, running version MintIRCd-0.4.1
3
+:cddo.cf 003 Chraas :This server was created sometime
4
+:cddo.cf 004 Chraas :cddo.cf MintIRCd-0.4.1 o o
5
+:cddo.cf 251 Chraas :There are 7 user(s) and 1 service(s) on 1 server
6
+:cddo.cf 375 Chraas :- cddo.cf Message of the day -
7
+:cddo.cf 372 Chraas :-    *                     (    (
8
+:cddo.cf 372 Chraas :-  (  `                  ) )\ ) )\ )   (     (
9
+:cddo.cf 372 Chraas :-  )\))(   (          ( /((()/((()/(   )\    )\ )
10
+:cddo.cf 372 Chraas :- ((_)()\  )\   (     )\())/(_))/(_))(((_)  (()/(
11
+:cddo.cf 372 Chraas :- (_()((_)((_)  )\ ) (_))/(_)) (_))  )\___   ((_))
12
+:cddo.cf 372 Chraas :- |  \/  | (_) _(_/( | |_ |_ _|| _ \((/ __|  _| |
13
+:cddo.cf 372 Chraas :- | |\/| | | || ' \))|  _| | | |   / | (__ / _` |
14
+:cddo.cf 372 Chraas :- |_|  |_| |_||_||_|  \__||___||_|_\  \___|\__,_|
15
+:cddo.cf 372 Chraas :- 
16
+:cddo.cf 372 Chraas :- Hohoho, and Welcome! Radius Root :3
17
+:cddo.cf 372 Chraas :- 
18
+:cddo.cf 372 Chraas :- Local official channels:
19
+:cddo.cf 372 Chraas :- #theroot - General chitchat room
20
+:cddo.cf 372 Chraas :- #freonlinux - FreonLinux official IRC channel
21
+:cddo.cf 376 Chraas :End of /MOTD command
22
+:Chraas!Chraas@127.0.0.1 JOIN #theroot
23
+:cddo.cf 332 Chraas #theroot :Radius' Root <3 ~ https://cddo.cf
24
+:cddo.cf 353 Chraas = #theroot :Chraas Menchers MultiServ OldCoder Pentium44 mrtux zlg
25
+:cddo.cf 366 Chraas #theroot :End of NAMES list
26
+:MultiServ!MultiServ@127.0.0.1 PRIVMSG #theroot :Welcome Chraas
27
+PRIVMSG #theroot :Completely working now
28
+
29
+PRIVMSG #theroot :no issues
30
+
31
+PRIVMSG #freonlinux :Nothing
32
+
33
+PRIVMSG #freonlinux :except some line breaks
34
+
35
+PRIVMSG #freonlinux :should fix that now
36
+PRIVMSG #freonlinux :or not lmao
37
+PRIVMSG #freonlinux :Oh, I lied it works o/

+ 35 - 0
.Chraas2.socket 查看文件

@@ -0,0 +1,35 @@
1
+:cddo.cf 001 Chraas2 :Hi, welcome to IRC
2
+:cddo.cf 002 Chraas2 :Your host is cddo.cf, running version MintIRCd-0.4.1
3
+:cddo.cf 003 Chraas2 :This server was created sometime
4
+:cddo.cf 004 Chraas2 :cddo.cf MintIRCd-0.4.1 o o
5
+:cddo.cf 251 Chraas2 :There are 7 user(s) and 1 service(s) on 1 server
6
+:cddo.cf 375 Chraas2 :- cddo.cf Message of the day -
7
+:cddo.cf 372 Chraas2 :-    *                     (    (
8
+:cddo.cf 372 Chraas2 :-  (  `                  ) )\ ) )\ )   (     (
9
+:cddo.cf 372 Chraas2 :-  )\))(   (          ( /((()/((()/(   )\    )\ )
10
+:cddo.cf 372 Chraas2 :- ((_)()\  )\   (     )\())/(_))/(_))(((_)  (()/(
11
+:cddo.cf 372 Chraas2 :- (_()((_)((_)  )\ ) (_))/(_)) (_))  )\___   ((_))
12
+:cddo.cf 372 Chraas2 :- |  \/  | (_) _(_/( | |_ |_ _|| _ \((/ __|  _| |
13
+:cddo.cf 372 Chraas2 :- | |\/| | | || ' \))|  _| | | |   / | (__ / _` |
14
+:cddo.cf 372 Chraas2 :- |_|  |_| |_||_||_|  \__||___||_|_\  \___|\__,_|
15
+:cddo.cf 372 Chraas2 :- 
16
+:cddo.cf 372 Chraas2 :- Hohoho, and Welcome! Radius Root :3
17
+:cddo.cf 372 Chraas2 :- 
18
+:cddo.cf 372 Chraas2 :- Local official channels:
19
+:cddo.cf 372 Chraas2 :- #theroot - General chitchat room
20
+:cddo.cf 372 Chraas2 :- #freonlinux - FreonLinux official IRC channel
21
+:cddo.cf 376 Chraas2 :End of /MOTD command
22
+:Chraas2!Chraas2@127.0.0.1 JOIN #theroot
23
+:cddo.cf 332 Chraas2 #theroot :Radius' Root <3 ~ https://cddo.cf
24
+:cddo.cf 353 Chraas2 = #theroot :Chraas2 Menchers MultiServ OldCoder Pentium44 mrtux zlg
25
+:cddo.cf 366 Chraas2 #theroot :End of NAMES list
26
+:MultiServ!MultiServ@127.0.0.1 PRIVMSG #theroot :Welcome Chraas2
27
+PART #theroot
28
+JOIN #freonlinux
29
+
30
+:Chraas2!Chraas2@127.0.0.1 PART #theroot :Chraas2
31
+:Chraas2!Chraas2@127.0.0.1 JOIN #freonlinux
32
+:cddo.cf 331 Chraas2 #freonlinux :No topic is set
33
+:cddo.cf 353 Chraas2 = #freonlinux :Chraas2 MultiServ Pentium44 mrtux
34
+:cddo.cf 366 Chraas2 #freonlinux :End of NAMES list
35
+PING :cddo.cf

+ 31 - 0
.Unnamed.socket 查看文件

@@ -0,0 +1,31 @@
1
+:cddo.cf 001 Unnamed :Hi, welcome to IRC
2
+:cddo.cf 002 Unnamed :Your host is cddo.cf, running version MintIRCd-0.4.1
3
+:cddo.cf 003 Unnamed :This server was created sometime
4
+:cddo.cf 004 Unnamed :cddo.cf MintIRCd-0.4.1 o o
5
+:cddo.cf 251 Unnamed :There are 7 user(s) and 1 service(s) on 1 server
6
+:cddo.cf 375 Unnamed :- cddo.cf Message of the day -
7
+:cddo.cf 372 Unnamed :-    *                     (    (
8
+:cddo.cf 372 Unnamed :-  (  `                  ) )\ ) )\ )   (     (
9
+:cddo.cf 372 Unnamed :-  )\))(   (          ( /((()/((()/(   )\    )\ )
10
+:cddo.cf 372 Unnamed :- ((_)()\  )\   (     )\())/(_))/(_))(((_)  (()/(
11
+:cddo.cf 372 Unnamed :- (_()((_)((_)  )\ ) (_))/(_)) (_))  )\___   ((_))
12
+:cddo.cf 372 Unnamed :- |  \/  | (_) _(_/( | |_ |_ _|| _ \((/ __|  _| |
13
+:cddo.cf 372 Unnamed :- | |\/| | | || ' \))|  _| | | |   / | (__ / _` |
14
+:cddo.cf 372 Unnamed :- |_|  |_| |_||_||_|  \__||___||_|_\  \___|\__,_|
15
+:cddo.cf 372 Unnamed :- 
16
+:cddo.cf 372 Unnamed :- Hohoho, and Welcome! Radius Root :3
17
+:cddo.cf 372 Unnamed :- 
18
+:cddo.cf 372 Unnamed :- Local official channels:
19
+:cddo.cf 372 Unnamed :- #theroot - General chitchat room
20
+:cddo.cf 372 Unnamed :- #freonlinux - FreonLinux official IRC channel
21
+:cddo.cf 376 Unnamed :End of /MOTD command
22
+:Unnamed!Unnamed@127.0.0.1 JOIN #theroot
23
+:cddo.cf 332 Unnamed #theroot :Radius' Root <3 ~ https://cddo.cf
24
+:cddo.cf 353 Unnamed = #theroot :Menchers MultiServ OldCoder Pentium44 Unnamed mrtux zlg
25
+:cddo.cf 366 Unnamed #theroot :End of NAMES list
26
+:MultiServ!MultiServ@127.0.0.1 PRIVMSG #theroot :Welcome Unnamed
27
+PART #theroot
28
+JOIN 
29
+:Unnamed!Unnamed@127.0.0.1 PART #theroot :Unnamed
30
+:cddo.cf 461 Unnamed JOIN :Not enough parameters
31
+PING :cddo.cf

+ 6 - 0
README.md 查看文件

@@ -13,6 +13,12 @@ Installation:
13 13
         ~Use it!
14 14
 
15 15
 Changelog:
16
+	v1.3.0:
17
+		-Add /join commands as well as /msg
18
+		-Some security fixes
19
+		-AJax URI formatting
20
+		-Channel input boxes for login
21
+		-IRC client bugfixes (irc.php)
16 22
 	v1.0.1:
17 23
 		-Add message, and server activity timestamps to chat logs.
18 24
 

+ 8 - 3
config.php 查看文件

@@ -10,9 +10,14 @@ $desc = "Chris' Website IRC Chat"; // Chat description
10 10
 $server = "127.0.0.1"; // IRC server connected to (for information display panel)
11 11
 $port = "1337"; // IRC server port (for information display panel)
12 12
 $server_msgcount = "80"; // Number of messages to leave at the end of the server database
13
-$channels = array("#theroot"); // IRC channel
13
+$default_channel = "#theroot";
14
+$logfile = "irclog.txt";
14 15
 
15
-///// NO TOUCHY /////
16
-$version = "1.2.0"; // CWChat version
16
+///// NO TOUCHY SECTION /////
17
+$version = "1.3.0"; // CWChat version
18
+
19
+function doLog($string) {
20
+	file_put_contents($GLOBALS['logfile'], $string . "\r\n", FILE_APPEND);
21
+}
17 22
 
18 23
 ?>

+ 11 - 4
index.php 查看文件

@@ -7,6 +7,7 @@
7 7
 // https://git.minetest.org/Pentium44/webirc-client
8 8
 ///////
9 9
 
10
+// Start session for username saves.
10 11
 session_start();
11 12
 include "config.php";
12 13
 
@@ -16,6 +17,7 @@ function loginForm(){
16 17
 	<div class="login">
17 18
 		<form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=login" method="post">
18 19
 			Username: <input style="padding: 2px;" class="text" type="text" name="username"><br>
20
+			Channel: <input style="padding: 2px;" class="text" type="text" name="channel"><br>
19 21
 			<input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Login">
20 22
 		</form>
21 23
 	</div>
@@ -25,11 +27,15 @@ function loginForm(){
25 27
 //Logout
26 28
 if (isset($_GET['do']) && $_GET['do']=="logout") {
27 29
 	$_SESSION['cwchat-user'] = null;
30
+	$_SESSION['cwchat-channel'] = null;
28 31
 }
29 32
 
33
+// If web frontend is trying to login, process and connect
30 34
 if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn'])){
31 35
 	$name = isset($_POST['username']) && ($_POST['username'] !== "") ? htmlentities(stripslashes($_POST['username'])) : "Unnamed";
36
+	$channame = isset($_POST['channel']) && ($_POST['channel'] !== "") ? htmlentities(stripslashes($_POST['channel'])) : "#theroot";
32 37
 	$_SESSION['cwchat-user'] = $name;
38
+	$_SESSION['cwchat-channel'] = $channame;
33 39
 }
34 40
 
35 41
 //if(!isset($_SESSION['cwchat-user'])) { header("Location: ?do=login"); }
@@ -39,7 +45,7 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn'])){
39 45
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
40 46
 <html>
41 47
 <head>
42
-   <title>CWChat</title>
48
+   <title>IRC Web Chat</title>
43 49
    <link href="style.css" rel="stylesheet" type="text/css" />
44 50
     <script language="javascript" type="text/javascript">
45 51
     <!--
@@ -48,7 +54,7 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn'])){
48 54
 		var pinglink = "";
49 55
 		var timerID = 0;
50 56
 		var nickName = "<?php echo $_SESSION['cwchat-user']; ?>";
51
-
57
+		
52 58
 		// Get the HTTP Object
53 59
 		function getHTTPObject() {
54 60
 			if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
@@ -83,7 +89,7 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn'])){
83 89
 		function serverWrite() {    
84 90
 			ajaxVar = getHTTPObject();
85 91
 			if (ajaxVar != null) {
86
-				link = "server.php?nick="+nickName+"&msg="+document.getElementById('msg').value; 
92
+				link = "server.php?nick="+nickName+"&msg="+encodeURIComponent(document.getElementById('msg').value); 
87 93
 				ajaxVar.open("GET", link , true);
88 94
 				ajaxVar.send(null);
89 95
 			}
@@ -170,7 +176,8 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn'])){
170 176
     </script>   
171 177
 </head>
172 178
 <body onload="UpdateTimer();">
173
-     <div class="info"><?php echo "CWChat " . $version . " ~ Connected to: " . $server . ":" . $port . " on " . $channels[0]; ?></div>
179
+     <div class="info"><?php echo "CWChat " . $version . " ~ Connected to: " . $server . ":" . $port;
180
+     if(isset($_SESSION['cwchat-user'])) { echo " on " . $_SESSION['cwchat-channel']; } ?></div>
174 181
 <?php 
175 182
 if (!isset($_SESSION['cwchat-user'])){ 
176 183
     loginForm();

+ 70 - 57
irc.php 查看文件

@@ -1,89 +1,102 @@
1 1
 <?php
2
+///////
3
+// webirc-client - 2013-2020
4
+// (C) Chris Dorman, GPL v3
5
+// https://notabug.org/Pentium44/ircchat
6
+///////
7
+
8
+// irc.php - used to push and pull data from IRC server.
9
+// Currently supports PING / PONG, data receive, and data push
10
+// Done via PHP sockets.
2 11
 
3 12
 // Prevent PHP from stopping the script after 30 sec
4 13
 set_time_limit(0);
5 14
 
15
+// Include variables
6 16
 include_once("config.php");
7 17
 
8
-// Change these values!
18
+// Get username from command line argument / PHP-CLI
9 19
 $username = $argv[1];
10 20
 
21
+// If username isn't set, exit with error.
11 22
 if(!isset($username) || $username == "") {
12 23
 	echo "Username not given...";
13 24
 	exit(1);
14 25
 }
15 26
 
16
-echo "Starting client...";
17
-
18
-file_put_contents(".$username.socket", "Welcome");
19
-chmod(".$username.socket", 0777);
20
-
21
-file_put_contents(".$username.pingfile", "pong");
22
-chmod(".$username.pingfile", 0777);
23
-
24
-// Opening the socket to the Rizon network
27
+// Create a socket to use
25 28
 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
26 29
 
30
+// Connect to IRC server via socket above
27 31
 socket_connect($socket, $server, $port);
28 32
 
29
-
30
-// Send auth info
31
-// fputs($socket, "PASS " . $password . "\n");
32
-echo "Connected, sending nickname to IRC server...";
33
-
33
+// NICK and USER calls to IRC 
34 34
 $nickline = "NICK " . $username . "\n";
35 35
 $userline = "USER " . $username . " 0 * :" . $username . "'s Bot\n";
36 36
 
37
+// Pass NICK and USER back to IRC server over socket
37 38
 socket_write($socket, $nickline, strlen($nickline));
38 39
 socket_write($socket, $userline, strlen($userline));
39 40
 
40
-// Join channel
41
-foreach($channels as $channel) {
42
-	$channelline = "JOIN " . $channel . "\n";
43
-	socket_write($socket, $channelline, strlen($channelline));
44
-}
41
+sleep(1);
45 42
 
46
-// Force an endless while
47
-while (1) {
48
-    // Continue the rest of the script here
49
-    
50
-    while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') {
51
-		if($bytes !== FALSE) {
52
-			//$data = socket_read($socket, 2048, PHP_NORMAL_READ);
53
-			$data = $r_data;
54
-		}
55
-        // If client sent something, push it to the IRC server!
56
-        if(file_exists(".$username.push")) {
57
-			$pushFile = file_get_contents(".$username.push");
58
-			socket_write($socket, $pushFile, strlen($pushFile));
59
-			unlink(".$username.push");
60
-		}
43
+// Continue the rest of the script here
44
+// While script will continue as long as socket continues to be active
45
+while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') {
46
+	if($bytes !== FALSE) {
47
+		//$data = socket_read($socket, 2048, PHP_NORMAL_READ);
48
+		$data = $r_data;
49
+	}
50
+
51
+	// If client sent something, push it to the IRC server!
52
+	if(file_exists(".$username.push")) {
53
+		// Grab IRC command from server.php
54
+		$pushFile = file_get_contents(".$username.push");
55
+		// Push this / these commands to socket
56
+		socket_write($socket, $pushFile, strlen($pushFile));
57
+		// Remove the push file
58
+		unlink(".$username.push");
59
+	}
61 60
         
62
-        // Check if web client still up, if no pong after 15 seconds, connection closed.
63
-        if(!file_exists(".$username.pingfile") || (date("YmdHis.", filemtime(".$username.pingfile"))<(date("YmdHis.", filemtime(".$username.pingfile"))-10))) {
64
-			echo "Exiting, leaving IRC server...";
65
-			$quitline = "QUIT :Timed out\n";
66
-			socket_write($socket, $quitline, strlen($quitline));
67
-			socket_close($socket);
68
-            exit(1);
69
-		}
70
-		
71
-		if(isset($data)) {
72
-			$stringMsg = explode('PRIVMSG', $data);
73
-			$socketFileContents = file_get_contents(".$username.socket");
74
-			file_put_contents(".$username.socket", $socketFileContents . $data);
61
+	// Check if web client still up, if no pong after 15 seconds, connection closed.
62
+	if(!file_exists(".$username.pingfile")) { // If file is missing, quit
63
+		// Debug logging, check if IRC is exiting properly
64
+		doLog("Exiting, $username logged out...");
65
+		$quitline = "QUIT :$username left the web client\n"; // IRC QUIT line
66
+		socket_write($socket, $quitline, strlen($quitline)); // Push to socket
67
+		socket_close($socket); // Close the socket
68
+		exit(0); // Exit the script, nothing to do.
69
+	} else if (date("YmdHis.", filemtime(".$username.pingfile"))<(date("YmdHis.", filemtime(".$username.pingfile"))-10)) {
70
+		// Debug logging, check if IRC is exiting properly
71
+		doLog("Exiting, $username timed out...");
72
+		$quitline = "QUIT :$username's web session timed out\n"; // IRC QUIT line
73
+		socket_write($socket, $quitline, strlen($quitline)); // Push to socket
74
+		socket_close($socket); // Close the socket
75
+		exit(1); // Exit the script, nothing to do.
76
+	}
75 77
 	
76
-			$ex = explode(' ', $data);
78
+	// If data variable is set and buffer has data to recieve
79
+	// RECIEVE IT!
80
+	if(isset($data)) { // If data variable is set, there's data from socket
81
+		$stringMsg = explode('PRIVMSG', $data); // Strip IRC commands
82
+		// Get original contents from socket
83
+		$socketFileContents = file_get_contents(".$username.socket");
84
+		// Push all content to 
85
+		file_put_contents(".$username.socket", $socketFileContents . $data);
86
+		$ex = explode(' ', $data);
77 87
         
78
-			// Send PONG back to the server
79
-			if ($ex[0] == "PING") {
80
-				echo "PONG to IRC server...";
81
-				$pongline = "PONG " . $ex[1] . "\n";
82
-				socket_write($socket, $pongline, strlen($pongline));
83
-			}
88
+		// Send PONG back to the server
89
+		if ($ex[0] == "PING") {
90
+			// Log pong
91
+			doLog("PONG, $username response...");
92
+			$pongline = "PONG " . $ex[1] . "\n"; // PONG IRC CMD
93
+			// Push to IRC server via socket.
94
+			socket_write($socket, $pongline, strlen($pongline));
84 95
 		}
85
-		
86
-        usleep(500);
87 96
 	}
97
+	
98
+	// Half second sleep to prevent insane CPU load	
99
+	usleep(500);
88 100
 }
101
+
89 102
 ?>

+ 0 - 1
log.txt 查看文件

@@ -1 +0,0 @@
1
-IRC server up: 20201108232329

+ 73 - 19
server.php 查看文件

@@ -1,43 +1,97 @@
1 1
 <?php 
2 2
 ///////
3 3
 // webirc-client - 2013-2020
4
-// (C) Chris Dorman, GPL v3 - (C) Microchat devs
5
-// https://github.com/Pentium44/cwchat
4
+// (C) Chris Dorman, GPL v3
5
+// https://notabug.org/Pentium44/ircchat
6 6
 ///////
7 7
 
8
+// server.php - used to communicate between web frontend and irc client
9
+// Grabs from IRC client output
10
+// Pushes to IRC client input
11
+// Keeps IRC client informed on web frontend connection
12
+
13
+// Include PHP config file with server, title, and channel settings
8 14
 include_once("config.php");
9 15
 
16
+session_start();
17
+
18
+$channel = $_SESSION['cwchat-channel'];
19
+
20
+// If we have a message; grab user and content and push to IRC client
10 21
 if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['nick']!=""){		
11
-	$nick = $_GET['nick'];
12
-	$msg  = htmlentities(stripcslashes($_GET['msg']));
13
-	$line = "";
14
-	foreach($channels as $channel) {
22
+	$nick = stripslashes(htmlentities($_GET['nick'])); // Usernick
23
+	$msg  = urldecode(stripslashes(trim($_GET['msg']))); // User message content
24
+	$line = ""; // start with nothing
25
+
26
+	// Seperate message input via space
27
+	$cmd = explode(" ", $msg);
28
+	if($cmd[0]=="/msg") { // If using /msg, push private message
29
+		$prvmsg = array_splice($cmd, 2); // grab private message from string
30
+		$line .= "PRIVMSG" . " " . $cmd[1] . " :"; // set for push
31
+		foreach($prvmsg as $word) {
32
+			// Grab each word in the array after the privmsg username
33
+			$line .= $word . " ";
34
+		}
35
+		$line .= "\n";
36
+	} else if ($cmd[0]=="/join") {
37
+		doLog("$username: channel switch from $channel to" . $cmd[1] . "($msg)");
38
+		$line .= "PART $channel\n"; // push close command to IRC
39
+		$line .= "JOIN" . " " . $cmd[1] . "\n"; // set for push
40
+		$_SESSION['cwchat-channel'] = trim($cmd[1]);
41
+	} else {
42
+		// @@ This is a work in progress
43
+		// Sends every channel message to each channel :[
15 44
 		$line .= "PRIVMSG $channel :$msg\n";
16 45
 	}
17 46
 	
47
+	// Get original content
18 48
 	$content = file_get_contents(".$nick.socket");
19
-	echo nl2br(htmlentities(stripslashes($content)));
49
+	echo nl2br(stripslashes($content));
50
+	// Grab all contents, and push to socket output file.
20 51
 	file_put_contents(".$nick.socket", $content . $line);
52
+	// Grab user message and push to IRC client
21 53
 	file_put_contents(".$nick.push", $line);
22
-	echo nl2br(htmlentities(stripslashes($line)));
54
+	// Throw out your user message
55
+	echo nl2br(stripslashes($line));
56
+	// DONE
57
+		
23 58
 } else if (isset($_GET['get']) && isset($_GET['nick']) && $_GET['nick']!="") {
24
-	$nick = $_GET['nick'];
59
+	$nick = stripslashes(htmlentities($_GET['nick'])); // Username
60
+	// Grab IRC client output
25 61
 	$content = file_get_contents(".$nick.socket");
62
+	// Push content to the web frontend
26 63
 	echo nl2br(htmlentities(stripslashes($content)));
64
+	// DONE
27 65
 } else if (isset($_GET['do']) && isset($_GET['nick']) && $_GET['nick']!="") {
28
-	$nick = $_GET['nick'];
29
-	if($_GET['do']=="login") {
30
-		// Make sure users DB is clean
31
-		file_put_contents(".$nick.socket", "Welcome");
32
-		chmod(".$username.socket", 0777);
66
+	$nick = stripslashes(htmlentities($_GET['nick']));
67
+	if($_GET['do']=="login") { // Is user asking for login?
68
+		// Join channel
69
+		if(!isset($_SESSION['cwchat-channel'])) {
70
+			file_put_contents(".$nick.push", "JOIN " . $default_channel . "\n");
71
+		} else {
72
+			file_put_contents(".$nick.push", "JOIN " . $channel . "\n");
73
+		}
74
+		
75
+		// Make sure users DB is clean, put nothing into socket read file
76
+		file_put_contents(".$nick.socket", "");
77
+		chmod(".$username.socket", 0755); // file permissions for read / write
78
+		
79
+		// start pingfile - determines if webclient is active via write timestamp 
33 80
 		file_put_contents(".$nick.pingfile", "pong");
34
-		chmod(".$username.pingfile", 0777);
81
+		chmod(".$username.pingfile", 0755); // file permissions for read / write
82
+		
83
+		// Execute IRC client in background
84
+		// IRC server will die when either 1) pingfile is deleted, or
85
+		// 2) if pingfile is older than 10 seconds of current sys time
86
+		$realpath = realpath("./irc.php"); // get full file path
35 87
 		
36
-		$realpath = realpath("./irc.php");
37
-		shell_exec("/usr/bin/php $realpath $nick > /dev/null 2>/dev/null &");
38
-	} else if($_GET['do']=="logout") {
88
+		// Execute IRC client
89
+		shell_exec("/usr/bin/php $realpath $nick > /dev/null 2>/dev/null &"); 
90
+	} else if($_GET['do']=="logout") { // Is user asking for logout?
91
+		// Remove ping file if user logs out. IRC server will close
39 92
 		unlink(".$nick.pingfile");
40
-	} else if($_GET['do']=="keepup") {
93
+	} else if($_GET['do']=="keepup") { // Client asking for keepup ping.
94
+		// PONG to server.
41 95
 		file_put_contents(".$nick.pingfile", "ping");
42 96
 	}
43 97
 }

+ 0 - 8
start.php 查看文件

@@ -1,8 +0,0 @@
1
-<?php
2
-
3
-$output = shell_exec("/bin/bash connect.sh Chraas &");
4
-echo $output;
5
-exit(0);
6
-
7
-?>
8
-

+ 2 - 2
style.css 查看文件

@@ -12,7 +12,7 @@ body {
12 12
 	min-width: 730px;
13 13
 	min-height: 700px;
14 14
 	max-height: 700px;
15
-	overflow: hidden;
15
+	overflow: scroll;
16 16
 }
17 17
 
18 18
 .info {
@@ -59,7 +59,7 @@ input, button, select, textarea{
59 59
 	background-color: #323232;
60 60
 	border: solid 1px #454545;
61 61
 	padding: 8px; 
62
-	height: 520px;
62
+	height: 420px;
63 63
 	margin: 0 auto;
64 64
 	overflow-y: scroll; 
65 65
 }