Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.54 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 = 'it_IT.utf8';
  9.  
  10. // Database information
  11. $this->host = 'localhost';
  12. $this->port = 3306;
  13.  
  14. $database = 'litebans';
  15.  
  16. $username = 'litebans';
  17. $password = 'PWD';
  18.  
  19. // If you set a table prefix in config.yml, set it here as well
  20. $this->table_prefix = "lb_";
  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 = 'BindCraft';
  27.  
  28. // Clicking on the header name will send you to this address.
  29. $this->name_link = '#';
  30.  
  31. // Show server scope column?
  32. $this->show_server_scope = true;
  33.  
  34. // Show inactive bans? Removed bans will show (Unbanned), mutes will show (Unmuted), warnings will show (Expired).
  35. $this->show_inactive_bans = true;
  36.  
  37. // Show silent bans?
  38. $this->show_silent_bans = true;
  39.  
  40. // Show pager? This allows users to page through the list of bans.
  41. $this->show_pager = true;
  42.  
  43. // Amount of bans/mutes/warnings to show on each page
  44. $this->limit_per_page = 10;
  45.  
  46. // The server console will be identified by any of these names.
  47. // It will be given a standard name and avatar image.
  48. $this->console_aliases = array(
  49. "CONSOLE", "Console",
  50. );
  51. $this->console_name = "Console";
  52. $this->console_image = "inc/img/console.png";
  53.  
  54. // Avatar images for all players will be fetched from this URL.
  55. // Examples:
  56. // 'https://cravatar.eu/avatar/{uuid}/25'
  57. // 'https://crafatar.com/avatars/{uuid}?size=25'
  58. // 'https://minotar.net/avatar/{uuid}/25'
  59. $this->avatar_source = 'https://crafatar.com/avatars/{uuid}?size=25';
  60.  
  61. // `avatar_source_offline_mode` controls where avatars for offline-mode players are fetched from.
  62. // Offline-mode UUIDs are substituted for player names unless the `avatar_allow_offline_mode_uuids` option is enabled.
  63. // (This is done because avatar sources generally serve the default "Steve" avatar for *all* offline-mode UUIDs, including those of premium players)
  64. // Crafatar no longer supports names, so it cannot be used as an offline-mode player-name avatar source as of 2018-02-16 (https://crafatar.com/#meta-usernames)
  65. // Since "skins.minecraft.net" is no longer available, this could pose a problem for other avatar sources as well.
  66. $this->avatar_source_offline_mode = 'https://minotar.net/avatar/{name}/25';
  67.  
  68. // If enabled, names will be shown below avatars instead of being shown next to them.
  69. $this->avatar_names_below = true;
  70.  
  71. // If enabled, offline-mode UUIDs will be requested from avatar_source instead of player names.
  72. $this->avatar_allow_offline_mode_uuids = false;
  73.  
  74. // If enabled, the total amount of bans, mutes, warnings, and kicks will be shown next to the buttons in the header.
  75. $this->header_show_totals = true;
  76.  
  77. // The date format can be changed here.
  78. // https://secure.php.net/manual/en/function.strftime.php
  79. // Example output of default format: July 2, 2015, 09:19; August 4, 2016, 18:37
  80. $this->date_format = '%B %d, %Y, %H:%M';
  81.  
  82. // https://secure.php.net/manual/en/timezones.php
  83. $timezone = "UTC";
  84.  
  85. // Enable PHP error reporting.
  86. $this->error_reporting = true;
  87.  
  88. // Enable error pages.
  89. $this->error_pages = true;
  90.  
  91. $this->date_month_translations = null;
  92.  
  93. // If your system locale doesn't automatically translate month names, you can set them manually here.
  94. // Change "if (false)" to "if (true)" for this to take effect.
  95. // X=>Y, X is replaced with Y. E.g. "January"=>"Januari"
  96. if (false) {
  97. $this->date_month_translations = array(
  98. "January" => "Month 1",
  99. "February" => "Month 2",
  100. "March" => "Month 3",
  101. "April" => "Month 4",
  102. "May" => "Month 5",
  103. "June" => "Month 6",
  104. "July" => "Month 7",
  105. "August" => "Month 8",
  106. "September" => "Month 9",
  107. "October" => "Month 10",
  108. "November" => "Month 11",
  109. "December" => "Month 12",
  110. );
  111. }
  112.  
  113.  
  114. /*** End of configuration ***/
  115.  
  116.  
  117. /** Don't modify anything here unless you know what you're doing **/
  118.  
  119. if ($this->error_reporting) {
  120. error_reporting(E_ALL);
  121. ini_set("display_errors", 1);
  122. }
  123.  
  124. $this->active_query = "";
  125.  
  126. if ($driver === "pgsql") {
  127. Settings::$TRUE = "B'1'";
  128. Settings::$FALSE = "B'0'";
  129. }
  130.  
  131. if (!$this->show_inactive_bans) {
  132. $this->active_query = self::append_query($this->active_query, "active=" . Settings::$TRUE);
  133. }
  134.  
  135. if (!$this->show_silent_bans) {
  136. $this->active_query = self::append_query($this->active_query, "silent=" . Settings::$FALSE);
  137. }
  138.  
  139. $this->test_strftime();
  140.  
  141. date_default_timezone_set($timezone); // set configured timezone
  142.  
  143. $table_prefix = $this->table_prefix;
  144.  
  145. // Internal table names, do not translate.
  146. $this->table = array(
  147. 'bans' => "${table_prefix}bans",
  148. 'mutes' => "${table_prefix}mutes",
  149. 'warnings' => "${table_prefix}warnings",
  150. 'kicks' => "${table_prefix}kicks",
  151. 'history' => "${table_prefix}history",
  152. 'servers' => "${table_prefix}servers",
  153. 'config' => "${table_prefix}config",
  154. );
  155.  
  156. $this->driver = $driver;
  157. if ($connect) {
  158. if ($username === "" && $password === "") {
  159. $this->redirect("error/unconfigured.php");
  160. }
  161. $host = $this->host;
  162. $port = $this->port;
  163.  
  164. $dsn = "$driver:dbname=$database;host=$host;port=$port";
  165. if ($driver === 'mysql') {
  166. $dsn .= ';charset=utf8';
  167. }
  168.  
  169. $options = array(
  170. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  171. PDO::ATTR_EMULATE_PREPARES => false,
  172. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
  173. );
  174.  
  175. try {
  176. $this->conn = new PDO($dsn, $username, $password, $options);
  177.  
  178. $st = $this->conn->query("SELECT * FROM " . $this->table['config'] . " LIMIT 1;");
  179. $st->fetch();
  180. $st->closeCursor();
  181. } catch (PDOException $e) {
  182. Settings::handle_error($this, $e);
  183. }
  184. if ($driver === 'pgsql') {
  185. $this->conn->query("SET NAMES 'UTF8';");
  186. }
  187. }
  188. }
  189.  
  190. static function append_query($existing, $new) {
  191. if ($existing !== "") {
  192. return "$existing AND $new";
  193. }
  194. return "WHERE $new";
  195. }
  196.  
  197. /**
  198. * @param $settings Settings
  199. * @param $e Exception
  200. */
  201. static function handle_error($settings, $e) {
  202. $message = $e->getMessage();
  203. if ($settings->error_pages) {
  204. if (strstr($message, "Access denied for user")) {
  205. if ($settings->error_reporting) {
  206. $settings->redirect("error/access-denied.php?error=" . base64_encode($message));
  207. } else {
  208. $settings->redirect("error/access-denied.php");
  209. }
  210. }
  211. if (strstr($message, "Base table or view not found:")) {
  212. $settings->redirect("error/tables-not-found.php");
  213. }
  214. if (strstr($message, "Unknown column")) {
  215. $settings->redirect("error/outdated-plugin.php");
  216. }
  217. }
  218. if ($settings->error_reporting === false) {
  219. die("Database error");
  220. }
  221. die('Database error: ' . $message);
  222. }
  223.  
  224.  
  225. function redirect($url, $showtext = true) {
  226. if ($showtext === true) {
  227. echo "<a href=\"$url\">Redirecting...</a>";
  228. }
  229. echo "<script data-cfasync=\"false\" type=\"text/javascript\">document.location=\"$url\";</script>";
  230. die;
  231. }
  232.  
  233. private function test_strftime() {
  234. // If you modify this function, you may get an "Assertion failed" error.
  235. date_default_timezone_set("UTC"); // temporarily set UTC timezone for testing purposes
  236.  
  237. $fail = false;
  238. $test = strftime($this->date_format, 0);
  239. if ($test == false) {
  240. ob_start();
  241. var_dump($test);
  242. $testdump = ob_get_clean();
  243. echo("Error: date_format test failed. strftime(\"" . $this->date_format . "\",0) returned " . $testdump);
  244. $fail = true;
  245. }
  246.  
  247. $test = strftime("%Y-%m-%d %H:%M", 0);
  248. if ($test !== "1970-01-01 00:00") {
  249. ob_start();
  250. var_dump($test);
  251. $testdump = ob_get_clean();
  252. echo("Assertion failed: strftime(\"%Y-%m-%d %H:%M\",0) != \"1970-01-01 00:00\"<br>");
  253. echo("Actual result: " . $testdump);
  254. $fail = true;
  255. }
  256.  
  257. if ($fail === true) {
  258. die;
  259. }
  260. }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement