Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 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 = 'PvPCrush.eu';
  12.  
  13. // Clicking on the header name will send you to this address.
  14. $this->name_link = '#';
  15.  
  16. // Database information
  17. $host = '82.208.17.36';
  18. $port = 3306;
  19.  
  20. $database = '222334_mysql_db';
  21. $username = '222334_mysql_db';
  22. $password = 'Eclipse1122lolnew11';
  23.  
  24. // If you set a table prefix in config.yml, set it here as well
  25. $table_prefix = "litebans_";
  26.  
  27. // Supported drivers: mysql, pgsql
  28. $driver = 'mysql';
  29.  
  30. // Show inactive bans? Removed bans will show (Odbanovany), mutes will show (Unmutly), warnings will show (Expirovalo).
  31. $this->show_inactive_bans = true;
  32.  
  33. // Show pager? This allows users to page through the list of bans.
  34. $this->show_pager = true;
  35.  
  36. // Amount of bans/mutes/warnings to show on each page
  37. $this->limit_per_page = 10;
  38.  
  39. // The server console will be identified by any of these names.
  40. // It will be given a standard name and avatar image.
  41. $this->console_aliases = array(
  42. "CONSOLE", "Console",
  43. );
  44. $this->console_name = "Sever";
  45. $this->console_image = "inc/img/console.png";
  46.  
  47. // Avatar images for all players will be fetched from this URL.
  48. // Examples:
  49. /* 'https://cravatar.eu/avatar/$UUID/25'
  50. * 'https://crafatar.com/avatars/$UUID?size=25'
  51. * 'https://minotar.net/avatar/$NAME/25'
  52. */
  53. $this->avatar_source = 'https://crafatar.com/avatars/$UUID?size=25';
  54.  
  55. // If enabled, names will be shown below avatars instead of being shown next to them.
  56. $this->avatar_names_below = true;
  57.  
  58. // If enabled, the total amount of bans, mutes, warnings, and kicks will be shown next to the buttons in the header.
  59. $this->header_show_totals = true;
  60.  
  61. // The date format can be changed here.
  62. // https://secure.php.net/manual/en/function.strftime.php
  63. // Example of default: July 2, 2015, 9:19 PM
  64. $this->date_format = '%B %d, %Y, %l:%M %p';
  65. date_default_timezone_set("UTC");
  66.  
  67. // Enable PHP error reporting.
  68. $error_reporting = true;
  69.  
  70. // Enable error pages.
  71. $this->error_pages = true;
  72.  
  73. /*** End of configuration ***/
  74.  
  75.  
  76. /** Don't modify anything here unless you know what you're doing **/
  77.  
  78. if ($error_reporting) {
  79. error_reporting(E_ALL);
  80. ini_set("display_errors", 1);
  81. }
  82.  
  83. $this->table = array(
  84. 'bans' => "${table_prefix}bans",
  85. 'mutes' => "${table_prefix}mutes",
  86. 'warnings' => "${table_prefix}warnings",
  87. 'kicks' => "${table_prefix}kicks",
  88. 'history' => "${table_prefix}history",
  89. );
  90.  
  91. $this->active_query = "";
  92.  
  93. if ($driver === "pgsql") {
  94. Settings::$TRUE = "B'1'";
  95. Settings::$FALSE = "B'0'";
  96. }
  97.  
  98. if (!$this->show_inactive_bans) {
  99. $this->active_query = "WHERE active=" . Settings::$TRUE;
  100. }
  101.  
  102. $this->driver = $driver;
  103. if ($connect) {
  104. if ($username === "" && $password === "") {
  105. $this->redirect("error/unconfigured.php");
  106. }
  107.  
  108. $dsn = "$driver:dbname=$database;host=$host;port=$port";
  109. if ($driver === 'mysql') {
  110. $dsn .= ';charset=utf8';
  111. }
  112.  
  113. $options = array(
  114. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  115. PDO::ATTR_EMULATE_PREPARES => false,
  116. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
  117. );
  118.  
  119. try {
  120. $this->conn = new PDO($dsn, $username, $password, $options);
  121.  
  122. $st = $this->conn->query("SELECT * FROM " . $this->table['servers'] . " LIMIT 1;");
  123. $st->fetch();
  124. } catch (PDOException $e) {
  125. Settings::handle_error($this, $e);
  126. }
  127. if ($driver === 'pgsql') {
  128. $this->conn->query("SET NAMES 'UTF8';");
  129. }
  130. }
  131. }
  132.  
  133.  
  134. /**
  135. * @param $settings Settings
  136. * @param $e Exception
  137. */
  138. static function handle_error($settings, $e) {
  139. $message = $e->getMessage();
  140. if ($settings->error_pages) {
  141. if (strstr($message, "Access denied for user")) {
  142. $settings->redirect("error/access-denied.php?error=" . base64_encode($message));
  143. }
  144. if (strstr($message, "Base table or view not found:")) {
  145. $settings->redirect("error/tables-not-found.php");
  146. }
  147. }
  148. die('Database error: ' . $message);
  149. }
  150.  
  151.  
  152. function redirect($url) {
  153. echo "<a href=\"$url\">Redirecting...</a>";
  154.  
  155. echo "<script type=\"text/javascript\">document.location=\"$url\";</script>";
  156.  
  157. die;
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement