Guest User

Untitled

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