Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 271 lines (214 sloc) 8.828 kB
a417c45 @stwalkerster start api
stwalkerster authored
1 <?php
2 // API for helpmebot/other bots/etc
3 // This is a public-data-only read-only API, much in the same vein of ACCBot was.
4 //
5 // count - Displays statistics for the targeted user.
6 // status - Displays interface statistics, such as the number of open requests.
7 // stats - Gives a readout similar to the user list user information page.
8
9 require_once("config.inc.php");
10 require_once("includes/PdoDatabase.php");
11
12 // setup
13
14 $database = new PdoDatabase("mysql:host=".$toolserver_host.";dbname=".$toolserver_database,$toolserver_username, $toolserver_password);
15
16 // use exceptions on failed database queries
17 $database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
18
8e29707 @stwalkerster content type and error element
stwalkerster authored
19 header("Content-Type: text/xml");
20
a417c45 @stwalkerster start api
stwalkerster authored
21 $document = new DomDocument('1.0');
22 $doc_api = $document->createElement("api");
23 $document->appendChild($doc_api);
24
25
26 switch($_GET['action'])
27 {
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
28 case "count":
29 actionCount();
30 break;
c01e4d1 @stwalkerster status function
stwalkerster authored
31 case "status":
32 actionStatus();
33 break;
fc87dfe @stwalkerster stats user check
stwalkerster authored
34 case "stats":
35 actionStats();
36 break;
e89def8 @stwalkerster api deploy action
stwalkerster authored
37 case "deploy":
38 actionDeploy();
39 break;
a417c45 @stwalkerster start api
stwalkerster authored
40 default:
fc87dfe @stwalkerster stats user check
stwalkerster authored
41 $doc_api->setAttribute("actions", "count, status, stats");
a417c45 @stwalkerster start api
stwalkerster authored
42 break;
43 }
44
45 echo $document->saveXml();
46
e89def8 @stwalkerster api deploy action
stwalkerster authored
47 function actionDeploy()
48 {
49 $revision = isset( $_GET['r'] ) ? $_GET['r'] : '';
50 if( $revision == '' ) {
51 $err = $document->createElement("error");
52 $doc_api->appendChild($err);
53 $err->setAttribute("error", "Please specify a revision");
54 return;
55 }
56
57 $key = isset( $_GET['k'] ) ? $_GET['k'] : '';
58 if( $key == '' ) {
59 $err = $document->createElement("error");
60 $doc_api->appendChild($err);
61 $err->setAttribute("error", "Please specify a key");
62 return;
63 }
64
65 global $apiDeployPassword;
66
67 if( md5( md5($revision) . $apiDeployPassword ) != $key )
68 $err = $document->createElement("error");
69 $doc_api->appendChild($err);
70 $err->setAttribute("error", "Invalid key.");
71 return;
72 }
73
74 ob_start();
75 passthru('deploy.sh')
76 //$content_grabbed=ob_get_contents();
77 ob_end_clean();
78 }
fc87dfe @stwalkerster stats user check
stwalkerster authored
79
c01e4d1 @stwalkerster status function
stwalkerster authored
80 function actionStatus()
81 {
bf58760 @stwalkerster status command
stwalkerster authored
82 global $database, $document, $doc_api;
83
a36b49e @stwalkerster more friendly variable name
stwalkerster authored
84 $docStatus = $document->createElement("status");
85 $doc_api->appendChild($docStatus);
bf58760 @stwalkerster status command
stwalkerster authored
86
87 $status = "Open";
88 $mailconfirm = "Confirmed";
89 $query = $database->prepare("SELECT COUNT(*) AS count FROM acc_pend WHERE pend_status = :pstatus AND pend_mailconfirm = :pmailconfirm;");
90 $query->bindParam(":pstatus", $status);
91 $query->bindParam(":pmailconfirm", $mailconfirm);
92 $query->execute();
93 $sus = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
a36b49e @stwalkerster more friendly variable name
stwalkerster authored
94 $docStatus->setAttribute("open", $sus['count']);
bf58760 @stwalkerster status command
stwalkerster authored
95
96 $status = "Admin";
97 $query->execute();
98 $sus = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
a36b49e @stwalkerster more friendly variable name
stwalkerster authored
99 $docStatus->setAttribute("admin", $sus['count']);
bf58760 @stwalkerster status command
stwalkerster authored
100
101 $status = "Checkuser";
102 $query->execute();
103 $sus = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
a36b49e @stwalkerster more friendly variable name
stwalkerster authored
104 $docStatus->setAttribute("checkuser", $sus['count']);
bf58760 @stwalkerster status command
stwalkerster authored
105
106 $query = $database->prepare("SELECT COUNT(*) AS count FROM acc_ban");
107 $query->execute();
108 $sus = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
a36b49e @stwalkerster more friendly variable name
stwalkerster authored
109 $docStatus->setAttribute("bans", $sus['count']);
bf58760 @stwalkerster status command
stwalkerster authored
110
111 $level = "Admin";
112 $query = $database->prepare("SELECT COUNT(*) AS count FROM acc_user WHERE user_level = :ulevel;");
113 $query->bindParam(":ulevel",$level);
114 $query->execute();
115 $sus = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
a36b49e @stwalkerster more friendly variable name
stwalkerster authored
116 $docStatus->setAttribute("useradmin", $sus['count']);
bf58760 @stwalkerster status command
stwalkerster authored
117
118 $level = "User";
119 $query->execute();
120 $sus = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
a36b49e @stwalkerster more friendly variable name
stwalkerster authored
121 $docStatus->setAttribute("user", $sus['count']);
bf58760 @stwalkerster status command
stwalkerster authored
122
123 $level = "New";
124 $query->execute();
125 $sus = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
a36b49e @stwalkerster more friendly variable name
stwalkerster authored
126 $docStatus->setAttribute("usernew", $sus['count']);
c01e4d1 @stwalkerster status function
stwalkerster authored
127
128 }
a417c45 @stwalkerster start api
stwalkerster authored
129
fc87dfe @stwalkerster stats user check
stwalkerster authored
130 function actionStats()
131 {
132 global $document, $doc_api, $database;
133
134 $username = isset( $_GET['user'] ) ? $_GET['user'] : '';
135 if( $username == '' ) {
136 $err = $document->createElement("error");
137 $doc_api->appendChild($err);
138 $err->setAttribute("error", "Please specify a username");
139 return;
140 }
141
142 $username = trim($username); //Strip any whitespace from the username.
143
144 $docUser = $document->createElement("user");
145 $doc_api->appendChild($docUser);
146 // verify is a user
147
148 $isUserQuery = $database->prepare("SELECT COUNT(*) AS count FROM acc_user WHERE user_name = :username;");
149 $isUserQuery->bindParam(":username", $username);
150 $isUserQuery->execute();
151
152 $isUser = $isUserQuery->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
153
154 $isUser = ( ( $isUser['count'] == 0 ) ? false : true );
155
156 if( $isUser ) {
c7dd0ac @stwalkerster stats command
stwalkerster authored
157 $userQuery = $database->prepare("SELECT user_name, user_level, user_lastactive, user_welcome_templateid, user_onwikiname FROM acc_user WHERE user_name = :username;");
158 $userQuery->bindParam(":username", $username);
159 $userQuery->execute();
160
161 $user = $userQuery->fetch(PDO::FETCH_ASSOC) or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
162
163 foreach($user as $key => $value)
164 $docUser->setAttribute($key, $value);
165
fc87dfe @stwalkerster stats user check
stwalkerster authored
166 } else {
167 $docUser->setAttribute("missing","true");
168 }
169 }
170
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
171 function actionCount( ) {
607c122 @stwalkerster fix fatal
stwalkerster authored
172 global $document, $doc_api, $database;
a417c45 @stwalkerster start api
stwalkerster authored
173
174 $username = isset( $_GET['user'] ) ? $_GET['user'] : '';
175 if( $username == '' ) {
8e29707 @stwalkerster content type and error element
stwalkerster authored
176 $err = $document->createElement("error");
177 $doc_api->appendChild($err);
a9c9186 @stwalkerster fix error message
stwalkerster authored
178 $err->setAttribute("error", "Please specify a username");
8e29707 @stwalkerster content type and error element
stwalkerster authored
179 return;
a417c45 @stwalkerster start api
stwalkerster authored
180 }
181
182 $username = trim($username); //Strip any whitespace from the username.
183
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
184 $docUser = $document->createElement("user");
185 $doc_api->appendChild($docUser);
186 $docUser->setAttribute("name", $username);
a417c45 @stwalkerster start api
stwalkerster authored
187 // verify is a user
188
189 $isUserQuery = $database->prepare("SELECT COUNT(*) AS count FROM acc_user WHERE user_name = :username;");
190 $isUserQuery->bindParam(":username", $username);
191 $isUserQuery->execute();
192
23cee21 @stwalkerster fix
stwalkerster authored
193 $isUser = $isUserQuery->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
a417c45 @stwalkerster start api
stwalkerster authored
194
195 $isUser = ( ( $isUser['count'] == 0 ) ? false : true );
196
197 if( $isUser ) {
198 // accounts created
199 $query = $database->prepare("SELECT COUNT(*) AS count FROM acc_log WHERE (log_action = 'Closed 1' OR log_action = 'Closed custom-y') AND log_user = :username");
200 $query->bindParam(":username", $username);
201 $query->execute();
202
06dd752 @stwalkerster more fixes
stwalkerster authored
203 $count = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
982069c @stwalkerster fix attribute name - it's easier fixing here than fixing HMB :P
stwalkerster authored
204 $docUser->setAttribute("created",$count['count']);
a417c45 @stwalkerster start api
stwalkerster authored
205
206 $query = $database->prepare("SELECT * FROM acc_user WHERE user_name = :username");
207 $query->bindParam(":username", $username);
208 $query->execute();
209
06dd752 @stwalkerster more fixes
stwalkerster authored
210 $user = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
a417c45 @stwalkerster start api
stwalkerster authored
211
212
213 $adminInfo = '';
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
214 $docUser->setAttribute("level",$user['user_level']);
a417c45 @stwalkerster start api
stwalkerster authored
215 if( $user['user_level'] == 'Admin' ) {
95dcc36 @stwalkerster params by reference!
stwalkerster authored
216 $action = "Suspended";
a417c45 @stwalkerster start api
stwalkerster authored
217 $query = $database->prepare("SELECT COUNT(*) AS count FROM acc_log WHERE log_user = :username AND log_action = :action");
218 $query->bindParam(":username", $username);
95dcc36 @stwalkerster params by reference!
stwalkerster authored
219 $query->bindParam(":action", $action);
a417c45 @stwalkerster start api
stwalkerster authored
220 $query->execute();
06dd752 @stwalkerster more fixes
stwalkerster authored
221 $sus = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
222 $docUser->setAttribute("suspended", $sus['count']);
a417c45 @stwalkerster start api
stwalkerster authored
223
95dcc36 @stwalkerster params by reference!
stwalkerster authored
224 $action = "Promoted";
a417c45 @stwalkerster start api
stwalkerster authored
225 $query->execute();
06dd752 @stwalkerster more fixes
stwalkerster authored
226 $pro = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
227 $docUser->setAttribute("promoted",$pro['count']);
a417c45 @stwalkerster start api
stwalkerster authored
228
95dcc36 @stwalkerster params by reference!
stwalkerster authored
229 $action = "Approved";
06dd752 @stwalkerster more fixes
stwalkerster authored
230 $query->execute();
231 $app = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
232 $docUser->setAttribute("approved",$app['count']);
a417c45 @stwalkerster start api
stwalkerster authored
233
95dcc36 @stwalkerster params by reference!
stwalkerster authored
234 $action = "Demoted";
a417c45 @stwalkerster start api
stwalkerster authored
235 $query->execute();
06dd752 @stwalkerster more fixes
stwalkerster authored
236 $dem = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
237 $docUser->setAttribute("demoted",$dem['count']);
a417c45 @stwalkerster start api
stwalkerster authored
238
95dcc36 @stwalkerster params by reference!
stwalkerster authored
239 $action = "Declined";
a417c45 @stwalkerster start api
stwalkerster authored
240 $query->execute();
06dd752 @stwalkerster more fixes
stwalkerster authored
241 $dec = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
242 $docUser->setAttribute("declined",$dec['count']);
a417c45 @stwalkerster start api
stwalkerster authored
243
95dcc36 @stwalkerster params by reference!
stwalkerster authored
244 $action = "Renamed";
a417c45 @stwalkerster start api
stwalkerster authored
245 $query->execute();
06dd752 @stwalkerster more fixes
stwalkerster authored
246 $rnc = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
247 $docUser->setAttribute("renamed",$rnc['count']);
a417c45 @stwalkerster start api
stwalkerster authored
248
95dcc36 @stwalkerster params by reference!
stwalkerster authored
249 $action = "Edited";
a417c45 @stwalkerster start api
stwalkerster authored
250 $query->execute();
06dd752 @stwalkerster more fixes
stwalkerster authored
251 $mec = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
252 $docUser->setAttribute("edited",$mec['count']);
a417c45 @stwalkerster start api
stwalkerster authored
253
95dcc36 @stwalkerster params by reference!
stwalkerster authored
254 $action = "Prefchange";
a417c45 @stwalkerster start api
stwalkerster authored
255 $query->execute();
06dd752 @stwalkerster more fixes
stwalkerster authored
256 $pcc = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
257 $docUser->setAttribute("prefchange",$pcc['count']);
a417c45 @stwalkerster start api
stwalkerster authored
258 }
259
260 $query = $database->prepare("SELECT COUNT(*) AS count FROM acc_log WHERE log_time LIKE :date AND (log_action = 'Closed 1' OR log_action = 'Closed custom-y') AND log_user = :username");
261 $query->bindParam(":username", $username);
95dcc36 @stwalkerster params by reference!
stwalkerster authored
262 $date = date( 'Y-m-d' ) . "%";
263 $query->bindParam(":date", $date );
a417c45 @stwalkerster start api
stwalkerster authored
264 $query->execute();
06dd752 @stwalkerster more fixes
stwalkerster authored
265 $today = $query->fetch() or die( 'MySQL Error: ' . PDO::errorInfo() . "\n" );
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
266 $docUser->setAttribute("today",$today['count']);
a417c45 @stwalkerster start api
stwalkerster authored
267 } else {
ba2da63 @stwalkerster count bit done, needs testing
stwalkerster authored
268 $docUser->setAttribute("missing","true");
a417c45 @stwalkerster start api
stwalkerster authored
269 }
270 }
Something went wrong with that request. Please try again.