Advertisement
Guest User

Untitled

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