Advertisement
Guest User

Untitled

a guest
May 8th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 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. // Server name, shown on the main page and on the header
  11. $this->name = 'PureMC';
  12.  
  13. // Clicking on the header name will send you to this address.
  14. $this->name_link = 'puremc.me/punishments';
  15.  
  16. // Database information
  17. $host = '216.52.148.69';
  18. $port = 3306;
  19.  
  20. $database = 'mc_535';
  21.  
  22. $username = 'mc_535';
  23. $password = 'db1fdf3ca2';
  24.  
  25. // If you set a table prefix in config.yml, set it here as well
  26. $table_prefix = "litebans_";
  27.  
  28. // Supported drivers: mysql, pgsql
  29. $driver = 'mysql';
  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://cravatar.eu/avatar/$UUID/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 of default: July 2, 2015, 9:19 PM
  65. $this->date_format = '%B %d, %Y, %l:%M %p';
  66. date_default_timezone_set("UTC");
  67.  
  68. // Enable PHP error reporting.
  69. $error_reporting = true;
  70.  
  71. // Enable error pages.
  72. $this->error_pages = true;
  73.  
  74. /*** End of configuration ***/
  75.  
  76.  
  77. /** Don't modify anything here unless you know what you're doing **/
  78.  
  79. if ($error_reporting) {
  80. error_reporting(E_ALL);
  81. ini_set("display_errors", 1);
  82. }
  83.  
  84. $this->table = array(
  85. 'bans' => "${table_prefix}bans",
  86. 'mutes' => "${table_prefix}mutes",
  87. 'warnings' => "${table_prefix}warnings",
  88. 'kicks' => "${table_prefix}kicks",
  89. 'history' => "${table_prefix}history",
  90. 'servers' => "${table_prefix}servers",
  91. );
  92.  
  93. $this->active_query = "";
  94.  
  95. if ($driver === "pgsql") {
  96. Settings::$TRUE = "B'1'";
  97. Settings::$FALSE = "B'0'";
  98. }
  99.  
  100. if (!$this->show_inactive_bans) {
  101. $this->active_query = "WHERE active=" . Settings::$TRUE;
  102. }
  103.  
  104. $this->driver = $driver;
  105. if ($connect) {
  106. if ($username === "" && $password === "") {
  107. $this->redirect("error/unconfigured.php");
  108. }
  109.  
  110. $dsn = "$driver:dbname=$database;host=$host;port=$port";
  111. if ($driver === 'mysql') {
  112. $dsn .= ';charset=utf8';
  113. }
  114.  
  115. $options = array(
  116. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  117. PDO::ATTR_EMULATE_PREPARES => false,
  118. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
  119. );
  120.  
  121. try {
  122. $this->conn = new PDO($dsn, $username, $password, $options);
  123.  
  124. $st = $this->conn->query("SELECT * FROM " . $this->table['servers'] . " LIMIT 1;");
  125. $st->fetch();
  126. } catch (PDOException $e) {
  127. Settings::handle_error($this, $e);
  128. }
  129. if ($driver === 'pgsql') {
  130. $this->conn->query("SET NAMES 'UTF8';");
  131. }
  132. }
  133. }
  134.  
  135.  
  136. /**
  137. * @param $settings Settings
  138. * @param $e Exception
  139. */
  140. static function handle_error($settings, $e) {
  141. $message = $e->getMessage();
  142. if ($settings->error_pages) {
  143. if (strstr($message, "Access denied for user")) {
  144. $settings->redirect("error/access-denied.php?error=" . base64_encode($message));
  145. }
  146. if (strstr($message, "Base table or view not found:")) {
  147. $settings->redirect("error/tables-not-found.php");
  148. }
  149. }
  150. die('Database error: ' . $message);
  151. }
  152.  
  153.  
  154. function redirect($url) {
  155. echo "<a href=\"$url\">Redirecting...</a>";
  156.  
  157. echo "<script type=\"text/javascript\">document.location=\"$url\";</script>";
  158.  
  159. die;
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement