· 9 years ago · May 05, 2017, 05:26 AM
1<?php
2//////////////////////////////
3// The Hosting Tool
4// Free - THT Type
5// By Jonny H
6// Released under the GNU-GPL
7//////////////////////////////
8
9//Check if called by script
10if(THT != 1){die();}
11
12//Create the class
13class p2h {
14
15 public $acpForm = array(), $orderForm = array(), $acpNav = array(), $acpSubNav = array(); # The HTML Forms arrays
16 public $signup = true; # Does this type have a signup function?
17 public $cron = true; # Do we have a cron?
18 public $acpBox = true; # Want to show a box thing?
19 public $clientBox = true; # Show a box in client cp?
20 public $name = "Post2Host"; # Human readable name of the package.
21
22 private $con; # Forum SQL
23
24 # Start the functions #
25
26 public function __construct() { # Assign stuff to variables on creation
27 global $main, $db;
28 $this->acpForm[] = array("Signup Points", '<input name="signup" type="text" id="signup" size="5" onkeypress="return onlyNumbers();" />', 'signup');
29 $this->acpForm[] = array("Monthly Points", '<input name="monthly" type="text" id="monthly" size="5" onkeypress="return onlyNumbers();" />', 'monthly');
30 $this->orderForm[] = array("Forum Username", '<input name="type_fuser" type="text" id="type_fuser" />', 'fuser');
31 $this->orderForm[] = array("Forum Password", '<input name="type_fpass" type="password" id="type_fpass" />', 'fpass');
32 $query = $db->query("SELECT * FROM `<PRE>config` WHERE `name` LIKE 'p2hforum;:;%'");
33 while($data = $db->fetch_array($query)) {
34 $content = explode(";:;", $data['name']);
35 if($fname != $content[2]) {
36 $values[] = array($content[2], $content[2]);
37 }
38 $fname = $content[2];
39 }
40 $this->acpForm[] = array("Forum", $main->dropDown("forum", $values), 'forum');
41 $this->acpNav[] = array("P2H Forums", "forums", "lightning.png", "P2H Forums");
42 $this->clientNav[] = array("Forum Posting", "forums", "lightning.png", "Forum Posting");
43 }
44
45 public function acpPage() {
46 global $main, $style, $db;
47 switch($main->getvar['do']) {
48 default:
49 if($_POST) {
50 foreach($main->postvar as $key => $value) {
51 if($value == "" && !$n) {
52 $main->errors("Please fill in all the fields!");
53 $n++;
54 }
55 }
56 if(!$n) {
57 $forumcon = @mysql_connect($main->postvar['hostname'], $main->postvar['username'], $main->postvar['password'], true);
58 if(!$forumcon) {
59 $main->errors("mySQL Details incorrect!");
60 }
61 else {
62 $select = @mysql_select_db($main->postvar['database'], $forumcon);
63 if(!$select) {
64 $main->errors("Couldn't select database!");
65 }
66 else {
67 $query = $this->queryForums($main->postvar['name']);
68 if($db->num_rows($query) != 0) {
69 $main->errors("Forum name exists!");
70 }
71 else {
72 $db->query("INSERT INTO `<PRE>config` (name, value) VALUES('p2hforum;:;username;:;{$main->postvar['name']}', '{$main->postvar['username']}')");
73 $db->query("INSERT INTO `<PRE>config` (name, value) VALUES('p2hforum;:;password;:;{$main->postvar['name']}', '{$main->postvar['password']}')");
74 $db->query("INSERT INTO `<PRE>config` (name, value) VALUES('p2hforum;:;database;:;{$main->postvar['name']}', '{$main->postvar['database']}')");
75 $db->query("INSERT INTO `<PRE>config` (name, value) VALUES('p2hforum;:;hostname;:;{$main->postvar['name']}', '{$main->postvar['hostname']}')");
76 $db->query("INSERT INTO `<PRE>config` (name, value) VALUES('p2hforum;:;prefix;:;{$main->postvar['name']}', '{$main->postvar['prefix']}')");
77 $db->query("INSERT INTO `<PRE>config` (name, value) VALUES('p2hforum;:;type;:;{$main->postvar['name']}', '{$main->postvar['forum']}')");
78 $main->errors("Forum Added!");
79 }
80 }
81 }
82 }
83 }
84 $array['CONTENT'] = $style->replaceVar("tpl/addforum.tpl");
85 break;
86
87 case "edit":
88 $query = $this->queryForums();
89 if($db->num_rows($query) == 0) {
90 $array['CONTENT'] = "There are no forums to delete!";
91 }
92 else {
93 if($main->getvar['name']) {
94 if($_POST) {
95 foreach($main->postvar as $key => $value) {
96 if($value == "" && !$n && $key != "password") {
97 $main->errors("Please fill in all the fields!");
98 $n++;
99 }
100 }
101 if(!$n) {
102 $db->query("UPDATE `<PRE>config` SET `value` = '{$main->postvar['username']}' WHERE `name` = 'p2hforum;:;username;:;{$main->getvar['name']}'");
103 $db->query("UPDATE `<PRE>config` SET `value` = '{$main->postvar['database']}' WHERE `name` = 'p2hforum;:;database;:;{$main->getvar['name']}'");
104 $db->query("UPDATE `<PRE>config` SET `value` = '{$main->postvar['hostname']}' WHERE `name` = 'p2hforum;:;hostname;:;{$main->getvar['name']}'");
105 $db->query("UPDATE `<PRE>config` SET `value` = '{$main->postvar['prefix']}' WHERE `name` = 'p2hforum;:;prefix;:;{$main->getvar['name']}'");
106 if($main->postvar['password']) {
107 $db->query("UPDATE `<PRE>config` SET `value` = '{$main->postvar['password']}' WHERE `name` = 'p2hforum;:;password;:;{$main->getvar['name']}'");
108 }
109 $main->errors("Forum Edited!");
110 }
111 }
112 $forumdata = $this->forumData($main->getvar['name']);
113 $array2['USER'] = $forumdata['username'];
114 $array2['DB'] = $forumdata['database'];
115 $array2['HOST'] = $forumdata['hostname'];
116 $array2['NAME'] = $main->getvar['name'];
117 $array2['PREFIX'] = $forumdata['prefix'];
118 $array['CONTENT'] = $style->replaceVar("tpl/editforum.tpl", $array2);
119 }
120 else {
121 $array['CONTENT'] .= "<ERRORS>";
122 while($data = $db->fetch_array($query)) {
123 $content = explode(";:;", $data['name']);
124 if($fname != $content[2]) {
125 $array['CONTENT'] .= $main->sub("<strong>".$content[2]."</strong>", '<a href="?page=type&type=p2h&sub=forums&do=edit&name='.$content[2].'"><img src="'. URL .'themes/icons/pencil.png"></a>');
126 }
127 $fname = $content[2];
128 }
129 }
130 }
131 break;
132
133 case "delete":
134 $query = $this->queryForums();
135 if($db->num_rows($query) == 0) {
136 $array['CONTENT'] = "There are no forums to delete!";
137 }
138 else {
139 if($main->getvar['name']) {
140 $db->query("DELETE FROM `<PRE>config` WHERE `name` LIKE 'p2hforum;:;%;:;{$main->getvar['name']}'");
141 $main->errors("Forum deleted!");
142 }
143 $array['CONTENT'] .= "<ERRORS>";
144 while($data = $db->fetch_array($query)) {
145 $content = explode(";:;", $data['name']);
146 if($fname != $content[2]) {
147 $array['CONTENT'] .= $main->sub("<strong>".$content[2]."</strong>", '<a href="?page=type&type=p2h&sub=forums&do=delete&name='.$content[2].'"><img src="'. URL .'themes/icons/delete.png"></a>');
148 }
149 $fname = $content[2];
150 }
151 }
152 break;
153 }
154 echo $style->replaceVar("tpl/manageforums.tpl", $array);
155 }
156
157 public function signup() {
158 global $db, $main, $type;
159 $fuser = $main->getvar['type_fuser'];
160 $forum = $this->determineForum($main->getvar['package']);
161 $this->con = $this->forumCon($forum);
162 $details = $this->forumData($forum);
163 $select = $db->query("SELECT * FROM `<PRE>user_packs`");
164 while($data = $db->fetch_array($select)) {
165 $pdetails = $type->userAdditional($data['id']);
166 if($pdetails['fuser'] == $fuser) {
167 $n++;
168 }
169 }
170 if(!$n) {
171 switch($this->checkSignup($details['type'], $details['prefix'])) {
172 case 1:
173 //What we do here?
174 $main->getvar['type_fpass'] = 0;
175 break;
176
177 case 0:
178 return "You haven't got enough points for this package!<br />The required amount is: ". $this->getSignup($main->getvar['package']);
179 break;
180
181 case 3:
182 return "Forum username is false!";
183 break;
184
185 case 4:
186 return "Forum password is false!";
187 break;
188 }
189 }
190 else {
191 return "That forum username is already used!";
192 }
193 }
194
195 public function cron() {
196 global $db, $main, $type, $server, $email;
197 $query = $db->query("SELECT * FROM `<PRE>user_packs`");
198 $checkdate = explode(":", $db->config("p2hcheck"));
199 while($data = $db->fetch_array($query)) {
200 $ptype = $type->determineType($data['pid']);
201 if($ptype == "p2h") {
202 $fuser = $type->userAdditional($data['id']);
203 $forum = $this->determineForum($data['pid']);
204 $fdetails = $this->forumData($forum);
205 $this->con = $this->forumCon($forum);
206 $posts = $this->checkMonthly($fdetails['type'], $fuser['fuser'], $fdetails['prefix']);
207 $mposts = $this->getMonthly($data['pid']);
208 if($checkdate[0] < date("m")) {
209 if(date("d") == date("t")) {
210 if($posts < $mposts) {
211 $user = $db->client($data['userid']);
212 $server->suspend($data['id'], "Only posted $posts out of $mposts!");
213 echo "<b>". $user['user'] ." (".$fuser['fuser'].")</b>: Suspended for not having enough points by posting monthly amount! ($posts out of $mposts)<br />";
214 $dbcheck = 1;
215 }
216 }
217 if(date("d") == "20" && $checkdate[1] != "1") {
218 if($posts < $mposts) {
219 $user = $db->client($data['userid']);
220 $emaildata = $db->emailTemplate("p2hwarning");
221 $array['USERPOSTS'] = $posts;
222 $array['MONTHLY'] = $mposts;
223 $email->send($user['email'], $emaildata['subject'], $emaildata['content'], $array);
224 echo "<b>". $user['user'] ." (".$fuser['fuser'].")</b>: Has been warned about monthly posting!<br />";
225 $dbcheck = 2;
226 }
227 }
228 }
229 }
230 }
231 if($dbcheck == 1) {
232 if(date("m") == 12) {
233 $checkmonth = "0";
234 }
235 else {
236 $checkmonth = date("m");
237 }
238 $db->updateConfig("p2hcheck", $checkmonth);
239 }
240 elseif($dbcheck == 2) {
241 $db->updateConfig("p2hcheck", $checkdate[0].":1");
242 }
243 }
244
245 public function acpBox() {
246 global $main, $db, $type;
247 $box[0] = "Forum Posting:<br />";
248 $user = $main->getvar['do'];
249 $query = $db->query("SELECT * FROM `<PRE>user_packs` WHERE `userid` = '{$user}'");
250 $data = $db->fetch_array($query);
251 $forum = $this->determineForum($data['pid']);
252 $user = $type->userAdditional($data['id']);
253 $fdetails = $this->forumData($forum);
254 $this->con = $this->forumCon($forum);
255 $posts = $this->checkMonthly($fdetails['type'], $user['fuser'], $fdetails['prefix']);
256 $box[1] = $posts ." (". $this->getMonthly($data['pid']) ." Needed)<br />Forum Username: ". $user['fuser'];
257 return $box;
258 }
259
260 public function clientBox() {
261 global $main, $db, $type;
262 $box[0] = "Forum Posting:<br />";
263 $user = $_SESSION['cuser'];
264 $query = $db->query("SELECT * FROM `<PRE>user_packs` WHERE `userid` = '{$user}'");
265 $data = $db->fetch_array($query);
266 $forum = $this->determineForum($data['pid']);
267 $user = $type->userAdditional($data['id']);
268 $fdetails = $this->forumData($forum);
269 $this->con = $this->forumCon($forum);
270 $posts = $this->checkMonthly($fdetails['type'], $user['fuser'], $fdetails['prefix']);
271 $box[1] = $posts ." (". $this->getMonthly($data['pid']) ." Needed)<br />Forum Username: ". $user['fuser'];
272 return $box;
273 }
274
275 public function clientPage() {
276 global $main, $db, $type, $style;
277 $user = $_SESSION['cuser'];
278 $query = $db->query("SELECT * FROM `<PRE>user_packs` WHERE `userid` = '{$user}'");
279 $data = $db->fetch_array($query);
280 $forum = $this->determineForum($data['pid']);
281 $user = $type->userAdditional($data['id']);
282 $fdetails = $this->forumData($forum);
283 $this->con = $this->forumCon($forum);
284 $posts = $this->checkMonthly($fdetails['type'], $user['fuser'], $fdetails['prefix']);
285 $monthly = $this->getMonthly($data['pid']);
286 $array['USER'] = $user['fuser'];
287 if($posts >= $monthly) {
288 $array['MESSAGE'] = "<strong>Well Done!</strong><br />You have achieved the monthly points of ". $monthly .". You're total posts is ". $posts .".";
289 }
290 else {
291 $need = $monthly - $posts;
292 $array['MESSAGE'] = "<strong>You Need More Posts!</strong><br />You haven't achieved the monthly posts of ". $monthly .". You're total posts is ". $posts .". You need ". $need ." more posts!";
293 }
294 echo $style->replaceVar("tpl/forumposting.tpl", $array);
295 }
296
297 private function forumCon($name) { # Returns a forum sql
298 global $main;
299 $data = $this->forumData($name);
300 $forumcon = @mysql_connect($data['hostname'], $data['username'], $data['password'], true);
301 if(!$forumcon) {
302 $array['Error'] = "Forum SQL Details incorrect!";
303 $array['Forum Name'] = $name;
304 $main->error($array);
305 }
306 else {
307 $select = @mysql_select_db($data['database'], $forumcon);
308 if(!$select) {
309 $array['Error'] = "Couldn't select forum database!";
310 $array['Forum Name'] = $name;
311 $main->error($array);
312 }
313 else {
314 return $forumcon;
315 }
316 }
317 }
318
319 private function getSignup($id) { # Returns the signup posts for a package
320 global $type;
321 $data = $type->additional($id);
322 return $data['signup'];
323 }
324
325 private function getMonthly($id) { # Returns the signup posts for a package
326 global $type;
327 $data = $type->additional($id);
328 return $data['monthly'];
329 }
330
331 private function checkMonthly($forum, $fuser, $prefix) {
332 $nmonth = date("m");
333 $nyear = date("y");
334
335 switch($forum) {
336 case "ipb":
337 $n = 0;
338 $forumuser = $fuser;
339 $select = mysql_query("SELECT * FROM {$prefix}members WHERE `name` = '{$forumuser}'", $this->con);
340 $display = mysql_fetch_array($select);
341 $dname = $display['members_display_name'];
342
343 //Get Posts
344 $sposts = mysql_query("SELECT * FROM {$prefix}credits_bank WHERE `author_name` = '{$dname}'", $this->con);
345
346 //Count with time
347 while($data2 = mysql_fetch_array($sposts)) {
348 $date = explode(":", strftime("%m:%y" ,$data2['post_date']));
349 if($nmonth <= $date[0] && $nyear <= $date[1]) {
350 $n++;
351 }
352 }
353 break;
354 case "ipb3":
355 $n = 0;
356 $forumuser = $fuser;
357 $select = mysql_query("SELECT * FROM {$prefix}members WHERE `name` = '{$forumuser}'", $this->con);
358 $display = mysql_fetch_array($select);
359 $dname = $display['members_display_name'];
360
361 //Get Posts
362 $sposts = mysql_query("SELECT * FROM {$prefix}credits_bank WHERE `userid` = '{$dname}'", $this->con);
363
364 //Count with time
365 while($data2 = mysql_fetch_array($sposts)) {
366 $date = explode(":", strftime("%m:%y" ,$data2['post_date']));
367 if($nmonth <= $date[0] && $nyear <= $date[1]) {
368 $n++;
369 }
370 }
371 break;
372
373 case "mybb":
374 $n = 0;
375 $forumuser = $fuser;
376 $select = mysql_query("SELECT * FROM {$prefix}posts WHERE `username` = '{$forumuser}'", $this->con);
377
378 while($data2 = mysql_fetch_array($select)) {
379 $date = explode(":", strftime("%m:%y" ,$data2['dateline']));
380 if($nmonth <= $date[0] && $nyear <= $date[1]) {
381 $n++;
382 }
383 }
384 break;
385
386 case "phpbb":
387 $n = 0;
388 $result = mysql_query("SELECT * FROM `{$prefix}users` WHERE username = '{$fuser}'", $this->con);
389 $mem = mysql_fetch_array($result);
390 $select = mysql_query("SELECT * FROM {$prefix}posts WHERE `poster_id` = '{$mem['user_id']}'", $this->con);
391
392 while($data2 = mysql_fetch_array($select)) {
393 $date = explode(":", strftime("%m:%y" ,$data2['post_time']));
394 if($nmonth <= $date[0] && $nyear <= $date[1]) {
395 $n++;
396 }
397 }
398 break;
399
400 case "phpbb2":
401 $n = 0;
402 $result = mysql_query("SELECT * FROM `{$prefix}users` WHERE username = '{$fuser}'", $this->con);
403 $mem = mysql_fetch_array($result);
404 $select = mysql_query("SELECT * FROM {$prefix}posts WHERE `poster_id` = '{$mem['user_id']}'", $this->con);
405
406 while($data2 = mysql_fetch_array($select)) {
407 $date = explode(":", strftime("%m:%y" ,$data2['post_time']));
408 if($nmonth <= $date[0] && $nyear <= $date[1]) {
409 $n++;
410 }
411 }
412 break;
413
414 case "vb":
415 $n = 0;
416 $forumuser = $fuser;
417 $select = mysql_query("SELECT * FROM {$prefix}user WHERE `userid` = '{$forumuser}'", $this->con);
418
419 while($data2 = mysql_fetch_array($select)) {
420 $date = explode(":", strftime("%m:%y" ,$data2['dateline']));
421 if($nmonth <= $date[0] && $nyear <= $date[1]) {
422 $n++;
423 }
424 }
425 break;
426
427 case "smf":
428 $n = 0;
429 $forumuser = $fuser;
430 $select = mysql_query("SELECT * FROM {$prefix}messages WHERE `posterName` = '{$forumuser}'", $this->con);
431
432 while($data2 = mysql_fetch_array($select)) {
433 $date = explode(":", strftime("%m:%y" ,$data2['posterTime']));
434 if($nmonth <= $date[0] && $nyear <= $date[1]) {
435 $n++;
436 }
437 }
438 break;
439
440 case "aef":
441 $n = 0;
442 $forumuser = $fuser;
443 $result = mysql_query("SELECT * FROM `{$prefix}users` WHERE username = '{$fuser}'", $this->con);
444 $mem = mysql_fetch_array($result);
445 $select = mysql_query("SELECT * FROM {$prefix}posts WHERE `poster_id` = '{$mem['id']}'", $this->con);
446
447 while($data2 = mysql_fetch_array($select)) {
448 $date = explode(":", strftime("%m:%y" ,$data2['ptime']));
449 if($nmonth <= $date[0] && $nyear <= $date[1]) {
450 $n++;
451 }
452 }
453 break;
454 }
455 return $n;
456 }
457
458 private function checkSignup($forum, $prefix) {
459 global $db, $main;
460
461 $fuser = $main->getvar['type_fuser'];
462 $fpass = $main->getvar['type_fpass'];
463 $signup = $this->getSignup($main->getvar['package']);
464
465 switch($forum) {
466 case "ipb":
467 // Look up member
468 $result = mysql_query("SELECT * FROM `{$prefix}members` WHERE name = '{$fuser}'", $this->con);
469 $member = $db->fetch_array($result);
470 $memail = $member['email'];
471
472 //Get Salt
473 $select = mysql_query("SELECT * FROM `{$prefix}members_converge` WHERE `converge_email` = '{$memail}'", $this->con);
474 $hash = mysql_fetch_array($select);
475
476 if(md5(md5($hash['converge_pass_salt']) . md5($fpass)) == $hash['converge_pass_hash']) {
477 if(mysql_num_rows($result) == "1") {
478 //Check Posts
479 if(stripslashes($signup) <= $member['posts']) {
480 return 1;
481 }
482 //That shit below looks complicated doesn't it lol. I thought the same. To many brackets for my mind.
483 else {
484 return 0;
485 }
486 }
487 else {
488 return 3;
489 }
490 }
491 else {
492 return 4;
493 }
494 break;
495
496 case "ipb3":
497 // Look up member
498 $result = mysql_query("SELECT * FROM `{$prefix}members` WHERE name = '{$fuser}'", $this->con);
499 $member = $db->fetch_array($result);
500 $memail = $member['email'];
501
502 //Get Salt
503 //$select = mysql_query("SELECT * FROM `{$prefix}members_converge` WHERE `converge_email` = '{$memail}'", $this->con);
504 $select = mysql_query("SELECT * FROM `{$prefix}members` WHERE `email` = '{$memail}'", $this->con);
505 $hash = mysql_fetch_array($select);
506
507 if(md5(md5($hash['members_pass_salt']) . md5($fpass)) == $hash['members_pass_hash']) {
508 if(mysql_num_rows($result) == "1") {
509 //Check Posts
510 if(stripslashes($signup) <= $member['posts']) {
511 return 1;
512 }
513 //That shit below looks complicated doesn't it lol. I thought the same. To many brackets for my mind.
514 else {
515 return 0;
516 }
517 }
518 else {
519 return 3;
520 }
521 }
522 else {
523 return 4;
524 }
525 break;
526
527 case "mybb":
528 // Look up member
529 $result = mysql_query("SELECT * FROM `{$prefix}users` WHERE username = '{$fuser}'", $this->con);
530 if($db->num_rows($result) == "0") {
531 return 3;
532 }
533 else {
534 $member = mysql_fetch_array($result);
535 if(md5(md5($member['salt']) . md5($fpass)) == $member['password']) {
536 if($member['postnum'] >= $signup) {
537 return 1;
538 }
539 else {
540 return 0;
541 }
542 }
543 else {
544 return 4;
545 }
546 }
547 break;
548
549 case "phpbb":
550 $result = mysql_query("SELECT * FROM `{$prefix}users` WHERE username = '{$fuser}'", $this->con);
551 if(mysql_num_rows($result) == "0") {
552 return 3;
553 }
554 else {
555 $member = mysql_fetch_array($result);
556 if(phpbb_check_hash($fpass, $member['user_password'])) {
557 $posts = mysql_query("SELECT * FROM `{$prefix}posts` WHERE poster_id = '{$member['user_id']}'", $this->con);
558 $mposts = stripslashes(mysql_num_rows($posts));
559 if($mposts >= $signup) {
560 return 1;
561 }
562 else {
563 return 0;
564 }
565 }
566 else {
567 return 4;
568 }
569 }
570 break;
571
572 case "phpbb2":
573 $result = mysql_query("SELECT * FROM `{$prefix}users` WHERE username = '{$fuser}'", $this->con);
574 if(mysql_num_rows($result) == "0") {
575 return 3;
576 }
577 else {
578 $member = mysql_fetch_array($result);
579 if(md5($fpass) == $member['user_password']) {
580 if($member['user_posts'] >= $signup) {
581 return 1;
582 }
583 else {
584 return 0;
585 }
586 }
587 else {
588 return 4;
589 }
590 }
591 break;
592
593 case "vb":
594 $result = mysql_query("SELECT * FROM `{$prefix}user` WHERE username = '{$fuser}'", $this->con);
595 if(mysql_num_rows($result) == "0") {
596 return 3;
597 }
598 else {
599 $member = mysql_fetch_array($result);
600 if(md5(md5($fpass) . $member['salt']) == $member['password']) {
601 if($member['credits'] >= $signup) {
602 return 1;
603 }
604 else {
605 return 0;
606 }
607 }
608 else {
609 return 4;
610 }
611 }
612 break;
613
614 case "smf":
615 $result = mysql_query("SELECT * FROM `{$prefix}members` WHERE memberName = '{$fuser}'", $this->con);
616 if(mysql_num_rows($result) == "0") {
617 return 3;
618 }
619 else {
620 $member = mysql_fetch_array($result);
621 if(sha1(strtolower($member['memberName']) . $fpass) == $member['passwd']) {
622 if($member['posts'] >= $signup) {
623 return 1;
624 }
625 else {
626 return 0;
627 }
628 }
629 else {
630 return 4;
631 }
632 }
633 break;
634
635 case "aef":
636 $result = mysql_query("SELECT * FROM `{$prefix}users` WHERE username = '{$fuser}'", $this->con);
637 if(mysql_num_rows($result) == "0") {
638 return 3;
639 }
640 else {
641 $member = mysql_fetch_array($result);
642 if(md5($member['salt'] . $fpass) == $member['password']) {
643 if($member['posts'] >= $signup) {
644 return 1;
645 }
646 else {
647 return 0;
648 }
649 }
650 else {
651 return array('true' => '0', 'customerror' => '<h1>Error</h1>That forum password is incorrect!');
652 }
653 }
654 break;
655 }
656 }
657
658 private function queryForums($name = 0) { # Returns the query for the forums in config table
659 global $db;
660 if($name) {
661 return $db->query("SELECT * FROM `<PRE>config` WHERE `name` LIKE 'p2hforum;:;%;:;{$name}' ORDER BY `name` DESC");
662 }
663 else {
664 return $db->query("SELECT * FROM `<PRE>config` WHERE `name` LIKE 'p2hforum;:;%'");
665 }
666 }
667
668 private function forumData($name) { # Returns all the data for a forum
669 global $db, $main;
670 $query = $this->queryForums($name);
671 if($db->num_rows($query) == 0) {
672 $array['Error'] = "That forum doesn't exist!";
673 $array['Forum Name'] = $name;
674 }
675 else {
676 while($data = $db->fetch_array($query)) {
677 $content = explode(";:;", $data['name']);
678 $forumData[$content[1]] = $data['value'];
679 }
680 return $forumData;
681 }
682 }
683
684 private function determineForum($id) { # Returns forum name with PID
685 global $db;
686 global $main, $type;
687 $query = $db->query("SELECT * FROM `<PRE>packages` WHERE `id` = '{$db->strip($id)}'");
688 if($db->num_rows($query) == 0) {
689 $array['Error'] = "That package doesn't exist!";
690 $array['User ID'] = $id;
691 $main->error($array);
692 return;
693 }
694 else {
695 $data = $type->additional($id);
696 return $data['forum'];
697 }
698 }
699}
700//End Type
701
702///////////////////////////////////////////
703// phpBB Password functions - All written by the phpBB team. All credit to them.
704// Why don't you use a salt? ha mo f***ers
705///////////////////////////////////////////
706
707function phpbb_check_hash($password, $hash)
708{
709 $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
710 if (strlen($hash) == 34)
711 {
712 return (_hash_crypt_private($password, $hash, $itoa64) === $hash) ? true : false;
713 }
714
715 return (md5($password) === $hash) ? true : false;
716}
717
718/**
719* Encode hash
720*/
721function _hash_encode64($input, $count, &$itoa64)
722{
723 $output = '';
724 $i = 0;
725
726 do
727 {
728 $value = ord($input[$i++]);
729 $output .= $itoa64[$value & 0x3f];
730
731 if ($i < $count)
732 {
733 $value |= ord($input[$i]) << 8;
734 }
735
736 $output .= $itoa64[($value >> 6) & 0x3f];
737
738 if ($i++ >= $count)
739 {
740 break;
741 }
742
743 if ($i < $count)
744 {
745 $value |= ord($input[$i]) << 16;
746 }
747
748 $output .= $itoa64[($value >> 12) & 0x3f];
749
750 if ($i++ >= $count)
751 {
752 break;
753 }
754
755 $output .= $itoa64[($value >> 18) & 0x3f];
756 }
757 while ($i < $count);
758
759 return $output;
760}
761
762/**
763* The crypt function/replacement
764*/
765function _hash_crypt_private($password, $setting, &$itoa64)
766{
767 $output = '*';
768
769 // Check for correct hash
770 if (substr($setting, 0, 3) != '$H$')
771 {
772 return $output;
773 }
774
775 $count_log2 = strpos($itoa64, $setting[3]);
776
777 if ($count_log2 < 7 || $count_log2 > 30)
778 {
779 return $output;
780 }
781
782 $count = 1 << $count_log2;
783 $salt = substr($setting, 4, 8);
784
785 if (strlen($salt) != 8)
786 {
787 return $output;
788 }
789
790 /**
791 * We're kind of forced to use MD5 here since it's the only
792 * cryptographic primitive available in all versions of PHP
793 * currently in use. To implement our own low-level crypto
794 * in PHP would result in much worse performance and
795 * consequently in lower iteration counts and hashes that are
796 * quicker to crack (by non-PHP code).
797 */
798 if (PHP_VERSION >= 5)
799 {
800 $hash = md5($salt . $password, true);
801 do
802 {
803 $hash = md5($hash . $password, true);
804 }
805 while (--$count);
806 }
807 else
808 {
809 $hash = pack('H*', md5($salt . $password));
810 do
811 {
812 $hash = pack('H*', md5($hash . $password));
813 }
814 while (--$count);
815 }
816
817 $output = substr($setting, 0, 12);
818 $output .= _hash_encode64($hash, 16, $itoa64);
819
820 return $output;
821}
822?>