Advertisement
GamemodeSurvival

HELPERS

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