Advertisement
Guest User

WEBCONFIG

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