-
Notifications
You must be signed in to change notification settings - Fork 5
/
admin.php
177 lines (150 loc) · 5.61 KB
/
admin.php
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
<?php
///////////////////////////////////
// ajax im 3.41 //
// AJAX Instant Messenger //
// Copyright (c) 2006-2008 //
// http://www.ajaxim.com/ //
// Do not remove this notice //
///////////////////////////////////
/**
* ajax im - admin panel script
*
* @author Joshua Gross, unwieldy studios
* @version 3.4
* @copyright 2006 - 2008
* @package ajax_im
**/
require('config.php');
// begin code //
// note: do not edit below unless //
// you know what you're doing! //
// JSON Class //
include('json.php');
// connect to database //
$link = mysql_connect($sql_host, $sql_user, $sql_pass);
mysql_select_db($sql_db);
mysql_query('SET NAMES \'utf8\'');
session_start();
/**
* ajax im, admin class.
*
* @package ajax_im
* @author Joshua Gross / unwieldy studios
**/
class Ajax_IM_Admin {
/**
* Constructor.
*
* @return void
* @author Joshua Gross
*/
function Ajax_IM_Admin($call) {
if($_SESSION['admin'] == 0) print 'access_denied';
$this->json = new JSON_obj();
$this->username = $_SESSION['username'];
$this->password = $_SESSION['password'];
if($this->checkInfo($this->username, $this->password)) {
switch($call) {
case 'search':
print $this->search(strtolower($_POST['by']), $_POST['for']);
break;
case 'kick':
print $this->kickUser($_POST['user']);
break;
case 'ban':
print $this->banUser($_POST['user']);
break;
case 'admin':
print $this->adminUser($_POST['user']);
break;
}
}
}
/**
* Searches the user database by the method specified, for the keyword specified
*
* @return void
* @author Joshua Gross
**/
function search($by, $for) {
if($by != 'email' && $by != 'username') return '[]';
$search_query = mysql_query('SELECT username, email, last_ip, last_ping, is_online, admin, banned FROM ' . SQL_PREFIX . 'users WHERE ' . $by . ' LIKE \'' . mysql_real_escape_string(str_replace('*', '%', $for)) . '\'');
$found = array();
while($row = mysql_fetch_assoc($search_query)) {
$found[] = array('username'=>$row['username'], 'email'=>$row['email'], 'lastKnownIP'=>$row['last_ip'], 'lastActive'=>$row['last_ping'],
'currentStatus'=>$row['is_online'], 'banned'=>($row['banned']==1?'true':'false'), 'admin'=>($row['admin']==1?'true':'false'));
}
return $this->json->encode($found);
}
/**
* Kick the user from the server (log him off)
*
* @return "kicked"
* @author Joshua Gross
**/
function kickUser($user) {
mysql_query('INSERT INTO ' . SQL_PREFIX . "messages (message, type, sender, recipient, stamp) VALUES ('kick', 'server', '{$this->username}', '" . mysql_real_escape_string($user) . "', '" . time() . "')");
return 'kicked';
}
/**
* Ban & kick the user from the server
*
* @return "true" if banned, "false" if unbanned, "no_such_user" if the user doesn't exist
* @author Joshua Gross
**/
function banUser($user) {
$ban_status = mysql_query('SELECT banned FROM ' . SQL_PREFIX . 'users WHERE username=\'' . mysql_real_escape_string($user) . '\'');
if(mysql_num_rows($ban_status) == 0)
return 'no_such_user';
$is = mysql_fetch_assoc($ban_status);
if($is['banned'] == 1) {
mysql_query('UPDATE ' . SQL_PREFIX . 'users SET banned=0 WHERE username=\'' . mysql_real_escape_string($user) . '\'');
return 'false';
} else {
$this->kickUser(mysql_real_escape_string($user));
mysql_query('UPDATE ' . SQL_PREFIX . 'users SET banned=1 WHERE username=\'' . mysql_real_escape_string($user) . '\'');
return 'true';
}
}
/**
* Toggle on/off the admin status of a user.
*
* @return "on" if now an admin, "off" if not, "no_such_user" if the user doesn't exist
* @author Joshua Gross
**/
function adminUser($user) {
$admin_status = mysql_query('SELECT admin FROM ' . SQL_PREFIX . 'users WHERE username=\'' . mysql_real_escape_string($user) . '\'');
if(mysql_num_rows($admin_status) == 0)
return 'no_such_user';
$is = mysql_fetch_assoc($admin_status);
if($is['admin'] == 1) {
mysql_query('UPDATE ' . SQL_PREFIX . 'users SET admin=0 WHERE username=\'' . mysql_real_escape_string($user) . '\'');
return 'false';
} else {
mysql_query('UPDATE ' . SQL_PREFIX . 'users SET admin=1 WHERE username=\'' . mysql_real_escape_string($user) . '\'');
return 'true';
}
}
/**
* Check to see if the supplied user information is valid, and if so return specific information.
*
* @return false if information is invalid, array of data otherwise
* @author Joshua Gross
**/
function checkInfo($username, $password, $return=array()) {
if(count($return) > 0)
$columns = implode(',', $return);
else
$columns = 'id';
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$query = mysql_query('SELECT ' . $columns . ' FROM ' . SQL_PREFIX . 'users WHERE username=\'' . $username . '\' AND password=\'' . $password . '\' LIMIT 1');
if(mysql_num_rows($query) > 0)
return mysql_fetch_assoc($query);
else
return false;
}
}
$admin = new Ajax_IM_Admin($_POST['call']);
?>
You don't want to be here...(this is not the admin panel!)