Advertisement
Guest User

Untitled

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