Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.64 KB | None | 0 0
  1. <?php
  2.  
  3. final class Settings {
  4. public static $TRUE = "1", $FALSE = "0";
  5.  
  6. public function __construct($connect = true) {
  7. // Web interface language. Languages are stored in the "lang/" directory.
  8. $this->lang = 'en_US.utf8';
  9.  
  10. // Database information
  11. $this->host = '144.217.242.88';
  12. $this->port = 3306;
  13.  
  14. $database = 'litebans';
  15.  
  16. $username = 'root';
  17. $password = '[redacted]';
  18.  
  19. // If you set a table prefix in config.yml, set it here as well
  20. $this->table_prefix = "litebans_";
  21.  
  22. // Supported drivers: mysql, pgsql
  23. $driver = 'mysql';
  24.  
  25. // Server name, shown on the main page and on the header
  26. $this->name = 'LiteBans';
  27.  
  28. // Clicking on the header name will send you to this address.
  29. $this->name_link = '#';
  30.  
  31. // Show inactive bans? Removed bans will show (Unbanned), mutes will show (Unmuted), warnings will show (Expired).
  32. $this->show_inactive_bans = true;
  33.  
  34. // Show pager? This allows users to page through the list of bans.
  35. $this->show_pager = true;
  36.  
  37. // Amount of bans/mutes/warnings to show on each page
  38. $this->limit_per_page = 10;
  39.  
  40. // The server console will be identified by any of these names.
  41. // It will be given a standard name and avatar image.
  42. $this->console_aliases = array(
  43. "CONSOLE", "Console",
  44. );
  45. $this->console_name = "Console";
  46. $this->console_image = "inc/img/console.png";
  47.  
  48. // Avatar images for all players will be fetched from this URL.
  49. // Examples:
  50. /* 'https://cravatar.eu/avatar/$UUID/25'
  51. * 'https://crafatar.com/avatars/$UUID?size=25'
  52. * 'https://minotar.net/avatar/$NAME/25'
  53. */
  54. $this->avatar_source = 'https://crafatar.com/avatars/$UUID?size=25';
  55.  
  56. // If enabled, names will be shown below avatars instead of being shown next to them.
  57. $this->avatar_names_below = true;
  58.  
  59. // If enabled, the total amount of bans, mutes, warnings, and kicks will be shown next to the buttons in the header.
  60. $this->header_show_totals = true;
  61.  
  62. // The date format can be changed here.
  63. // https://secure.php.net/manual/en/function.strftime.php
  64. // Example output of default format: July 2, 2015, 09:19; August 4, 2016, 18:37
  65. $this->date_format = '%B %d, %Y, %H:%M';
  66.  
  67. // https://secure.php.net/manual/en/timezones.php
  68. $timezone = "UTC";
  69.  
  70. // Enable PHP error reporting.
  71. $this->error_reporting = true;
  72.  
  73. // Enable error pages.
  74. $this->error_pages = true;
  75.  
  76. $this->date_month_translations = null;
  77.  
  78. /*
  79. $this->date_month_translations = array(
  80. "January" => "Month 1",
  81. "February" => "Month 2",
  82. "March" => "Month 3",
  83. "April" => "Month 4",
  84. "May" => "Month 5",
  85. "June" => "Month 6",
  86. "July" => "Month 7",
  87. "August" => "Month 8",
  88. "September" => "Month 9",
  89. "October" => "Month 10",
  90. "November" => "Month 11",
  91. "December" => "Month 12",
  92. );
  93. */
  94.  
  95. /*** End of configuration ***/
  96.  
  97.  
  98. /** Don't modify anything here unless you know what you're doing **/
  99.  
  100. if ($this->error_reporting) {
  101. error_reporting(E_ALL);
  102. ini_set("display_errors", 1);
  103. }
  104.  
  105. $this->active_query = "";
  106.  
  107. if ($driver === "pgsql") {
  108. Settings::$TRUE = "B'1'";
  109. Settings::$FALSE = "B'0'";
  110. }
  111.  
  112. if (!$this->show_inactive_bans) {
  113. $this->active_query = "WHERE active=" . Settings::$TRUE;
  114. }
  115.  
  116.  
  117. // test strftime
  118.  
  119. date_default_timezone_set("UTC"); // temporarily set UTC timezone for testing purposes
  120.  
  121. $fail = false;
  122. $test = strftime($this->date_format, 0);
  123. if ($test == false) {
  124. ob_start();
  125. var_dump($test);
  126. $testdump = ob_get_clean();
  127. echo("Error: date_format test failed. strftime(\"" . $this->date_format . "\",0) returned " . $testdump);
  128. $fail = true;
  129. }
  130.  
  131. $test = strftime("%Y-%m-%d %H:%M", 0);
  132. if ($test !== "1970-01-01 00:00") {
  133. ob_start();
  134. var_dump($test);
  135. $testdump = ob_get_clean();
  136. echo("Assertion failed: strftime(\"%Y-%m-%d %H:%M\",0) != \"1970-01-01 00:00\"<br>");
  137. echo("Actual result: " . $testdump);
  138. $fail = true;
  139. }
  140.  
  141. if ($fail === true) {
  142. die;
  143. }
  144.  
  145. date_default_timezone_set($timezone); // set configured timezone
  146.  
  147. $table_prefix = $this->table_prefix;
  148.  
  149. // Internal table names, do not translate.
  150. $this->table = array(
  151. 'bans' => "${table_prefix}bans",
  152. 'mutes' => "${table_prefix}mutes",
  153. 'warnings' => "${table_prefix}warnings",
  154. 'kicks' => "${table_prefix}kicks",
  155. 'history' => "${table_prefix}history",
  156. 'servers' => "${table_prefix}servers",
  157. );
  158.  
  159. $this->driver = $driver;
  160. if ($connect) {
  161. if ($username === "" && $password === "") {
  162. $this->redirect("error/unconfigured.php");
  163. }
  164. $host = $this->host;
  165. $port = $this->port;
  166.  
  167. $dsn = "$driver:dbname=$database;host=$host;port=$port";
  168. if ($driver === 'mysql') {
  169. $dsn .= ';charset=utf8';
  170. }
  171.  
  172. $options = array(
  173. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  174. PDO::ATTR_EMULATE_PREPARES => false,
  175. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
  176. );
  177.  
  178. try {
  179. $this->conn = new PDO($dsn, $username, $password, $options);
  180.  
  181. $st = $this->conn->query("SELECT * FROM " . $this->table['servers'] . " LIMIT 1;");
  182. $st->fetch();
  183. $st->closeCursor();
  184. } catch (PDOException $e) {
  185. Settings::handle_error($this, $e);
  186. }
  187. if ($driver === 'pgsql') {
  188. $this->conn->query("SET NAMES 'UTF8';");
  189. }
  190. }
  191. }
  192.  
  193.  
  194. /**
  195. * @param $settings Settings
  196. * @param $e Exception
  197. */
  198. static function handle_error($settings, $e) {
  199. $message = $e->getMessage();
  200. if ($settings->error_pages) {
  201. if (strstr($message, "Access denied for user")) {
  202. if ($settings->error_reporting) {
  203. $settings->redirect("error/access-denied.php?error=" . base64_encode($message));
  204. } else {
  205. $settings->redirect("error/access-denied.php");
  206. }
  207. }
  208. if (strstr($message, "Base table or view not found:")) {
  209. $settings->redirect("error/tables-not-found.php");
  210. }
  211. if (strstr($message, "Unknown column")) {
  212. $settings->redirect("error/outdated-plugin.php");
  213. }
  214. }
  215. if ($settings->error_reporting === false) {
  216. die("Database error");
  217. }
  218. die('Database error: ' . $message);
  219. }
  220.  
  221.  
  222. function redirect($url, $showtext = true) {
  223. if ($showtext === true) {
  224. echo "<a href=\"$url\">Redirecting...</a>";
  225. }
  226. echo "<script data-cfasync=\"false\" type=\"text/javascript\">document.location=\"$url\";</script>";
  227. die;
  228. }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement