-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.txt
382 lines (227 loc) · 11.7 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
* @package AJAX_Chat
* @author Sebastian Tschan
* @copyright (c) Sebastian Tschan
* @license GNU Affero General Public License
* @link https://blueimp.net/ajax/
*/
AJAX Chat
=========
This is the standalone version running without another web application.
AJAX stands for "Asynchronous JavaScript and XML".
The AJAX Chat clients (the user browsers) use JavaScript to query the web server for updates.
Instead of delivering a complete HTML page only updated data is send in XML format.
By using JavaScript the chat page can be updated without having to reload the whole page.
Requirements
============
Server-Side:
- PHP >= 4
- MySQL >= 4
- Ruby >= 1.8 (optional)
Client-Side:
- Enabled JavaScript
- Enabled Cookies
- Flash Plugin >= 9 (optional)
Installation
============
1. Configuration settings
----------------------
The primary configuration settings necessary for chat to function must be in the file lib/config.php
You will need to create this file. An example config file can be found in lib/config.php.example
Duplicate this file and save it as config.php once you have filled out at least the following four fields:
$config['dbConnection']['host'] = 'your_database_hostname';
$config['dbConnection']['user'] = 'your_database_username';
$config['dbConnection']['pass'] = 'your_database_password';
$config['dbConnection']['name'] = 'your_database_name';
In most cases, chat will function with only these fields filled out and you can proceed to step 2.
If your host does not use mysqli you will need to change the connection type field:
$config['dbConnection']['type'] = null;
If this is set to "null" it defaults to "mysqli" if existing, else to "mysql".
You can reference an existing database connection link or object by changing:
$config['dbConnection']['link'] = null;
If this is set to null, a new database connection is created.
2. Channel settings:
-----------------
Edit channels in lib/data/channels.php.
Each channel must have a unique id (the $channels array index) and a unique name.
Whitespace in the channel names will be converted to the underscore "_".
3. User settings:
--------------
Edit users in lib/data/users.php.
Each user must have a unique id (the $users array index) and a unique name.
The first user in the list (array index 0) is used for the guest user settings.
All guest users will have access to the channels set for this user and the user role AJAX_CHAT_GUEST.
Registered users can have the user roles AJAX_CHAT_USER, AJAX_CHAT_MODERATOR or AJAX_CHAT_ADMIN.
The list of channels a user has access to can be set for each user individually.
Whitespace in the user names will be converted to the underscore "_".
4. Upload to the server
--------------------
Upload the chat folder to your server somewhere under your document root:
e.g. http://example.org/path/to/chat/
5. Creation of database tables
---------------------------
Execute the provided installation script by visiting the following URL with your browser:
http://example.org/path/to/chat/install.php
Replace "http://example.org/path/to/chat/" with the real URL to your chat directory.
6. Delete the installation script
------------------------------
Delete the file install.php from the chat directory on your server.
Ready! Just place a link to the chat directory on your website. :)
Configuration files:
====================
AJAX Chat is fully customizable and contains two configuration files:
1. lib/config.php
--------------
This file contains the server side (PHP) settings.
2. js/config.js
------------
This file contains the client side (JavaScript) settings.
Each configuration option is explained with a comment prior to the setting assignment.
Customizing the layout:
=======================
The layout of AJAX Chat is fully customizable by using CSS (Cascaded Style Sheets).
AJAX Chat comes with a predefined set of styles. To add your own style, do the following:
1. Add a new CSS file (e.g. mystyle.css) by copying one of the existing styles from the CSS directory.
2. Edit your file (css/mystyle.css) and adjust the CSS settings to your liking.
3. Add the name of your style without file extension to the available styles in lib/config.php:
// Available styles:
$config['styleAvailable'] = array('mystyle','beige','black','grey');
// Default style:
$config['styleDefault'] = 'mystyle';
To further customize the layout you can adjust the template files in lib/template/.
Make sure you are creating valid XHTML, else you will produce errors in modern browsers.
This is due to the page content-type served as "application/xhtml+xml".
Using this content-type improves performance when manipulating the Document Object Model (DOM).
If for some reason you cannot create valid XHTML you can force a HTML content-type.
Just edit lib/config.php and set the following option:
$config['contentType'] = 'text/html';
Adjusting the language settings:
================================
AJAX Chat comes with two language file directories:
1. js/lang/
--------
This directory contains the language files used for the chat messages localization.
These are JavaScript files with the extension ".js".
2. lib/lang/
---------
This directory contains the language files used for the template output.
These are PHP files with the extension ".php".
For each language, you need a file in each of these directories, with the language code as file name.
The language code is used following the ISO 639 standards.
The files for the english (language code "en") localization are the following:
js/lang/en.js
lib/lang/en.php
To enable a language, you need to add the language code in lib/config.php:
$config['langAvailable'] = array('en');
For the language selection you also need to add the language name:
$config['langNames'] = array('en'=>'English');
To avoid errors, you should follow these rules:
1. Make sure you encode your localization files in UTF-8 (without Byte-order mark).
2. Don't use HTML entities in your localization files.
3. Don't remove any "%s" inside the JavaScript language files - these are filled with dynamic data.
Logs:
=====
By default, AJAX Chat stores all chat messages in the database.
To access the logs you have to add the GET parameter view=logs to your chat url:
e.g. http://example.org/path/to/chat/?view=logs
If you are not already logged in, you have to login as administrator to access the logs.
The log view enables you to monitor the latest chat messages on all channels.
It is also possible to view the logs of private rooms and private messages.
You have the option to filter the logs by date, time and search strings.
The search filter accepts MySQL style regular expressions:
http://dev.mysql.com/doc/refman/5.1/en/regexp.html
To search for IPs, use the following syntax:
ip=127.0.0.1
Shoutbox:
=========
AJAX Chat is also usable as shoutbox - this is a short guide on how to set it up:
1. Shoutbox stylesheet
-------------------
Add the following line to the stylesheet (CSS) of all pages displaying the shoutbox:
@import url("http://example.org/path/to/chat/css/shoutbox.css");
Replace http://example.org/path/to/chat/ with the URL to the chat.
Modify css/shoutbox.css to your liking.
2. Shoutbox function
-----------------
Add the following function to your PHP code:
<?php
function getShoutBoxContent() {
// URL to the chat directory:
if(!defined('AJAX_CHAT_URL')) {
define('AJAX_CHAT_URL', './chat/');
}
// Path to the chat directory:
if(!defined('AJAX_CHAT_PATH')) {
define('AJAX_CHAT_PATH', realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/chat').'/');
}
// Validate the path to the chat:
if(@is_file(AJAX_CHAT_PATH.'lib/classes.php')) {
// Include Class libraries:
require_once(AJAX_CHAT_PATH.'lib/classes.php');
// Initialize the shoutbox:
$ajaxChat = new CustomAJAXChatShoutBox();
// Parse and return the shoutbox template content:
return $ajaxChat->getShoutBoxContent();
}
return null;
}
?>
Make sure AJAX_CHAT_URL and AJAX_CHAT_PATH point to the chat directory.
3. Shoutbox output
---------------
Display the shoutbox content using the shoutbox function:
<div style="width:200px;"><?php echo getShoutBoxContent(); ?></div>
Socket Server:
==============
Using the AJAX technology alone the chat clients have to permanently pull updates from the server.
This is due to AJAX being a web technology and HTTP being a stateless protocol.
Events pushed from server-side need a permanent or long-lasting socket connection between clients and server.
This requires either a custom HTTP server (called "comet") or another custom socket server.
AJAX Chat uses a JavaScript-to-Flash bridge to establish a permanent socket connection from client side.
The JavaScript-to-Flash bridge requires a Flash plugin >= 9 installed on the user browser.
Clients without this requirement will fall back to pull the server for updates.
1. Installation
---------------
The socket server coming with AJAX Chat is implemented in Ruby.
You need to be able to run a Ruby script as a service to run the socket server.
To be able to start the service, the script files in the socket/ directory have to be executable:
$ chmod +x server
$ chmod +x server.rb
"server" is a simple bash script to start and stop a service.
"server.rb" is the ruby socket server script.
"server.conf" is a configuration file - each setting is explained with a comment.
To start the service, execute the "server" script with the parameter "start":
$ ./server start
This will create two additional files:
"server.pid" contains the process id of the service.
"server.log" is filled with the socket server log.
To monitor the socket server logs, you can use the "tail" command included in most GNU/Linux distributions:
$ tail -f server.log
By default only errors and start/stop of the server are logged.
To get more detailed logs configure the log level by editing the configuration file.
To stop the service, execute the "server" script with the parameter "stop":
$ ./server stop
If the socket server is running, you have to enable the following option in lib/config.php:
$config['socketServerEnabled'] = true;
This tells the server-side chat script to broadcast chat messages via the socket server.
Chat clients will establish a permanent connection to the socket server to listen for chat messages.
By default only local clients (127.0.0.1,::1) may broadcast messages.
Clients allowed to broadcast messages may also handle the channel authentication.
If your socket server is running on another host you should set the broadcast_clients option to the chat server IP.
Using the socket server increases response time while improving server performance at the same time.
2. Flash Permissions
--------------------
Since Flash 9.0.115.0 and all Flash 10 versions, permissions for creating sockets using Flash have changed.
Now an explicit permission (using xml-syntax) is required for creating socket connections.
In the current state, socket server won't work with the newest Flash versions.
You will get a "Flash security error" in the browser.
A solution is to use a policy-files server which will listen to connections in port 843 in the server.
Each time a client tries to connect to the chat, the Flash client will request the policy authorization to the server.
The policy-files server is downloadable from http://ammonlauritzen.com/FlashPolicyService-09b.zip
It works with FF3 and IE7 (not yet tested in other browsers).
A more detailed explanation can be found here:
* http://ammonlauritzen.com/blog/2007/12/13/new-flash-security-policies/
* http://ammonlauritzen.com/blog/2008/04/22/flash-policy-service-daemon/
Official Adobe documentation:
* http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security.html
* http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security_04.html