-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
261 lines (230 loc) · 7.49 KB
/
index.php
File metadata and controls
261 lines (230 loc) · 7.49 KB
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
<?php
header('Content-type: text/html; charset=utf-8');
$useauthuser = true;
if(!@file_exists('config.php') ) {
$links = array();
} else {
include_once('config.php');
}
$maxlines = 40;
require("chatlib.php");
// php5.2 and earlier user php_auth_user, later has remote user
if ((!isset($_SERVER['PHP_AUTH_USER'])) and (isset($_SERVER['REMOTE_USER'])))
{
$_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER']; // php52 and earlier compatible;
}
// Normally a .htaccess and .htpasswd file would force an auth basic
// but if it doesnt work, the systeme still need a php auth user to work
if (($useauthuser) and (!isset($_SERVER['PHP_AUTH_USER']))) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
}
session_start();
function createForm(){
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center">
<tr><td colspan="2">Please select a chat name:</td></tr>
<tr><td>Your name : </td>
<td><input class="text" type="text" name="name" /></td></tr>
<tr><td colspan="2" align="center">
<input class="text" type="submit" name="submitBtn" value="Login" />
</td></tr>
</table>
</form>
<?php
}
// a bit messy with the u and nickname mixup
if (isset($_GET['u'])){
unset($_SESSION['nickname']);
}
// Process login info
if (isset($_POST['submitBtn'])){
$name = isset($_POST['name']) ? $_POST['name'] : "Unnamed";
$_SESSION['nickname'] = $name;
}
$nickname = isset($_SESSION['nickname']) ? $_SESSION['nickname'] : "Hidden";
if (($useauthuser) and (isset($_SERVER['PHP_AUTH_USER']))) {
$nickname = $_SERVER['PHP_AUTH_USER'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>chat</title>
<link href="style/style2.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
<!--
var httpObject = null;
var timerID = 0;
var nickName = "<?php echo $nickname; ?>";
var lasthtml = "";
// Get the HTTP Object
var link = "";
function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}
function addlinetoMsg(s)
{
var objDiv = document.getElementById("result");
objDiv.innerHTML += s;
objDiv.scrollTop = objDiv.scrollHeight;
d = document.getElementById('msg');
d.style.backgroundImage ='';
}
function setMsg(s)
{
var objDiv = document.getElementById("result");
if (s != lasthtml)
{
objDiv.innerHTML = s;
lasthtml = s;
objDiv.scrollTop = objDiv.scrollHeight;
}
d = document.getElementById('msg');
d.style.backgroundImage ='';
}
// Change the value of the outputText field
function handleresponse(){
if(httpObject.readyState == 4){
var response = httpObject.responseText;
if (response)
{
z = response.substr(0,3); // the command
response = response.substr(4); // rest
if (z == 'one')
addlinetoMsg(response);
if (z == 'all') {
setMsg(response);
}
if (z == 'nul') {
d = document.getElementById('msg');
d.style.backgroundImage ='';
}
}
}
}
// clear the input field
// if a paramter is added, the input field gets the value appended
// and the aret moved to the end of the field
function clearmsg(s){
var inpObj = document.getElementById("msg");
if (s){
inpObj.value += " "+ s + " ";
if (typeof inpObj.selectionStart == "number") {
inpObj.selectionStart = inpObj.selectionEnd = inpObj.value.length;
}
} else
{
inpObj.value = "";
}
inpObj.focus();
}
function sendtoserver(s)
{
httpObject = getHTTPObject();
if (httpObject != null) {
httpObject.open("GET", s , true);
httpObject.onreadystatechange = handleresponse;
httpObject.send(null);
}
}
// Implement business logic
function doWork(){
d = document.getElementById('msg');
if (d != null) {
link = "message.php?nick="+nickName+"&msg="+d.value;
clearmsg();
d.style.backgroundImage ='url(ajax-loader.gif)';
sendtoserver(link);
}
}
// Implement business logic
function doReload(){
var randomnumber=Math.floor(Math.random()*10000);
link = "message.php?all=1&rnd="+randomnumber;
sendtoserver(link);
}
// refresh
function UpdateTimer() {
if (document.getElementById('msg').value == '') {
doReload();
timerID = setTimeout("UpdateTimer()", 5000); // if nothing happens wait 5 seconds
} else
{
timerID = setTimeout("UpdateTimer()", 500); // if we are not loading anyway, check every second
}
}
function keypressed(e){
if(e.keyCode=='13'){
doWork();
}
}
//-->
</script>
</head>
<body onload="UpdateTimer();">
<div id="main" align=left valign=left>
<div style="float:right">
<ul>
<?php
foreach($links as $key => $value ) {
echo "<li><a href='". $value. "' target='_blank'>" . $key ."</a></li>";
}
?>
</ul>
</div>
<?php
if ((!$useauthuser) and (!isset($_SESSION['nickname']))) {
createForm();
} else
{
if (($useauthuser) and (isset($_SERVER['PHP_AUTH_USER']))) {
$name = $_SERVER['PHP_AUTH_USER'];
} else {
$name = isset($_POST['name']) ? $_POST['name'] : "Unnamed";
}
echo "<div>Hej ". $name ."</div>";
$_SESSION['nickname'] = $name;
?>
<div id="result">
<?php
$data = file("msg.html");
foreach ($data as $line) {
echo stripslashes($line);
}
writetolog('First load')
?>
</div>
<div id="sender" onkeyup="keypressed(event);" style="vertical-align:text-top">
Msg:
<textarea cols="30" rows="5" name="msg" id="msg"
style="background-repeat:no-repeat;background-image:'url(ajax-loader.gif)" ></textarea>
<button onclick="doWork();">Send</button>
<div style="float:right">
<button onclick="clearmsg();">Clear</button>
<img src="imgs/smiley_emoticons_heart.gif" onclick="clearmsg('<3');">
<img src="imgs/smiley_emoticons_smile.gif" onclick="clearmsg(':)');">
<img src="imgs/smiley_emoticons_razz.gif" onclick="clearmsg(':p');">
<img src="imgs/smiley_emoticons_bussi.gif" onclick="clearmsg(':*');">
</div>
</div>
<div id="upload">
<form enctype="multipart/form-data" action="uploadfile.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
Photo: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
</div>
<?php
}
?>
</div>
</body>