PageRenderTime 38ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/include/class/class_check.php

https://github.com/Bigjoos/U-232-V2
PHP | 199 lines | 100 code | 25 blank | 74 comment | 17 complexity | 028f6b651473f13d8c8497acb5c63b7a MD5 | raw file
  1. <?php
  2. /**
  3. * https://09source.kicks-ass.net:8443/svn/installer09/
  4. * Licence Info: GPL
  5. * Copyright (C) 2010 Installer09 v.2
  6. * A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
  7. * Project Leaders: Mindless,putyn,kidvision.
  8. **/
  9. //==include/class_check.php
  10. /*
  11. class_check by pdq,
  12. autopost and 404 idea by Retro,
  13. staff array & auth by system,
  14. PIN idea by SirSnuggleBunny.
  15. */
  16. /**
  17. // USAGE in staff pages: //
  18. // below:
  19. dbconn();
  20. loggedinorreturn();
  21. // add:
  22. require_once 'include/class_check.php';
  23. class_check(UC_MODERATOR); // staff class check
  24. // require PIN:
  25. require_once 'include/class_check.php';
  26. class_check(UC_MODERATOR, true, true); // staff class check & require PIN
  27. // USAGE in non-staff pages: //
  28. require_once 'include/class_check.php';
  29. class_check(UC_POWER_USER, false); // use for non-staff pages
  30. // END //
  31. **/
  32. if (!defined('TBVERSION')) { //cannot access this file directly
  33. $HTMLOUT='';
  34. $HTMLOUT .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  35. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  36. <head>
  37. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  38. <title>ERROR</title>
  39. </head><body>
  40. <h1>ERROR</h1>Cannot Access this file directly.
  41. </body></html>';
  42. echo $HTMLOUT;
  43. exit();
  44. }
  45. /** $class = UC_CLASS_NAME: minimum class required to view page
  46. $staff = true: make sure staff are really staff and have permission to view page
  47. $pin = true: require staff PIN
  48. **/
  49. function class_check($class = 0, $staff = true, $pin = false) {
  50. global $CURUSER, $INSTALLER09, $mc1;
  51. /** basic checking **/
  52. if (!$CURUSER) {
  53. require_once '404.html';
  54. //die('404');
  55. exit();
  56. }
  57. /** required class check **/
  58. if ($CURUSER['class'] >= $class) {
  59. /** require correct staff PIN **/
  60. if ($pin) {
  61. // not allowed staff!
  62. if (!isset($INSTALLER09['staff']['allowed'][$CURUSER['username']])) {
  63. require_once '404.html';
  64. //die('404 - Kiss my aRse !!');
  65. exit();
  66. }
  67. $passed = false;
  68. // have sent a username/pass and are using their own username
  69. if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])
  70. && $_SERVER['PHP_AUTH_USER'] === ($CURUSER['username'])) {
  71. // generate a passhash from the sent password
  72. $hash = md5($INSTALLER09['site']['salt2'].$_SERVER['PHP_AUTH_PW'].$CURUSER['secret']);
  73. // if the password is correct, exit this function
  74. if (md5($INSTALLER09['site']['salt2'].$INSTALLER09['staff']['staff_pin'].$CURUSER['secret']) === $hash)
  75. $passed = true;
  76. }
  77. if (!$passed) {
  78. // they're not allowed, the username doesn't match their own, the password is
  79. // wrong or they have not sent user/pass yet so we exit
  80. header('WWW-Authenticate: Basic realm="Administration"');
  81. header('HTTP/1.0 401 Unauthorized');
  82. $HTMLOUT='';
  83. $HTMLOUT .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  84. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  85. <head>
  86. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  87. <title>ERROR</title>
  88. </head><body>
  89. <h1 align="center">ERROR</h1><p align="center">Sorry! Access denied!</p>
  90. </body></html>';
  91. echo $HTMLOUT;
  92. exit();
  93. }
  94. } // end PIN
  95. if ($staff) { // staff class required
  96. /** do some checking **/
  97. //if ((!valid_class($CURUSER['class'])) || (!isset($INSTALLER09['staff']['allowed'][strtolower($CURUSER['username'])]))) { // failed: illegal access ...
  98. if (($CURUSER['class'] > UC_MAX) || (!isset($INSTALLER09['staff']['allowed'][$CURUSER['username']]))) { // failed: illegal access ...
  99. /** user info **/
  100. $ip = getip();
  101. /** file ban them **/
  102. // @fclose(@fopen(INCL_DIR.'bans/'.$ip, 'w'));
  103. /** SQL ban them **/
  104. //require_once(INCL_DIR.'bans.php');
  105. //make_bans($ip, $_SERVER['REMOTE_ADDR'], 'Bad Class. Join IRC for assistance.');
  106. /** auto post to forums**/
  107. $body = sqlesc("User ".$CURUSER['username']." - ".$ip.
  108. "\n Class ".$CURUSER['class'].
  109. "\n Current page: ".$_SERVER['PHP_SELF'].
  110. ", Previous page: ".(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'no referer').
  111. ", Action: ".$_SERVER['REQUEST_URI'].
  112. "\n Member has been disabled and demoted by class check system.");
  113. /*
  114. $body2 = sqlesc("User ".$CURUSER['username']." - ".$ip.
  115. " Class ".$CURUSER['class'].
  116. " Current page: ".$_SERVER['PHP_SELF'].
  117. ", Previous page: ".(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'no referer').
  118. ", Action: ".$_SERVER['REQUEST_URI'].
  119. " Member has been disabled and demoted by class check system. - Kill the fuX0r");
  120. */
  121. $topicid = (int)$INSTALLER09['staff']['forumid'];
  122. $added = time();
  123. sql_query("INSERT INTO posts (topic_id, user_id, added, body) ".
  124. "VALUES($topicid , ".$INSTALLER09['bot_id'].", $added, $body)") or sqlerr(__file__, __line__);
  125. /** get mysql_insert_id(); **/
  126. $res = sql_query("SELECT id FROM posts WHERE topic_id = $topicid
  127. ORDER BY id DESC LIMIT 1") or sqlerr(__file__,__line__);
  128. $arr = mysql_fetch_row($res) or die('No staff post found');
  129. $postid = $arr[0];
  130. sql_query("UPDATE topics SET last_post = $postid WHERE id = $topicid")
  131. or sqlerr(__file__,__line__);
  132. /** PM Owner **/
  133. $subject = sqlesc('Warning Class Check System!');
  134. sql_query("INSERT INTO messages (sender, receiver, added, subject, msg)
  135. VALUES (0, ".$INSTALLER09['site']['owner'].", $added, $subject, $body)")
  136. or sqlerr(__file__,__line__);
  137. /** punishments **/
  138. //mysql_query("UPDATE users SET enabled = 'no', class = 1 WHERE id = $CURUSER[id]") or sqlerr(__file__, __line__);
  139. sql_query("UPDATE users SET class = 1 WHERE id = $CURUSER[id]") or sqlerr(__file__, __line__);
  140. /** remove caches **/
  141. $mc1->delete_value('user'.$CURUSER['id']);
  142. $mc1->delete_value('MyUser_'.$CURUSER['id']);
  143. //==
  144. /** log **/
  145. //write_log("<span style='color:#FA0606;'>Class Check System Initialized</span><a href='forums.php?action=viewtopic&amp;topicid=$topicid&amp;page=last#$postid'>VIEW</a>", UC_SYSOP, false);
  146. write_log('Class Check System Initialized [url='.$INSTALLER09['baseurl'].'/forums.php?action=view_topic&amp;topic_id='.$topicid.'&amp;page=last#'.$postid.']VIEW[/url]');
  147. //require_once(INCL_DIR.'user_functions.php');
  148. //autoshout($body2);
  149. $HTMLOUT='';
  150. $HTMLOUT .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
  151. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  152. <html xmlns='http://www.w3.org/1999/xhtml'>
  153. <head>
  154. <title>Error!</title>
  155. </head>
  156. <body>
  157. <div style='font-size:18px;color:black;background-color:red;text-align:center;'>Incorrect access<br />Silly Rabbit - Trix are for kids.. You dont have the correct credentials to be here !</div>
  158. </body></html>";
  159. echo $HTMLOUT;
  160. exit();
  161. //die('No access!'); // give em some Output
  162. }
  163. }
  164. } else { // if less than required class
  165. if (!$staff) // if not staff page :P
  166. stderr('ERROR', 'No Permission. Page is for '.get_user_class_name($class).'s and above. Read FAQ.');
  167. else { // if staff page
  168. require_once '404.html';
  169. //die('404');
  170. exit();
  171. }
  172. }
  173. }
  174. ?>