Advertisement
Guest User

Untitled

a guest
Jul 5th, 2016
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 52.57 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  *
  5.  * © 2016 shorttag - https://breadfish.de/index.php?user/16770-shorttag/
  6.  * Alle Rechte liegen bei shorttag.
  7.  * Nutzungsrechte eingeräumt bis: 15.07.2016 23:59 Uhr
  8.  *
  9.  */
  10.  
  11. ini_set('display_errors', 0);
  12. session_start();
  13.  
  14. require '../vendor/autoload.php';
  15. require 'captcha.php';
  16. require 'libraries/TeamSpeak3/TeamSpeak3.php';
  17.  
  18. $app = new \Slim\Slim();
  19. $app->view = new \Slim\Views\Twig();
  20. $app->view->setTemplatesDirectory("../Mini/view");
  21. $twig = $app->view()->getEnvironment();
  22. $twig->addExtension(new Twig_Extensions_Extension_Text());
  23. $csrfs = "6YN0kH65nTUb71vxTk0WUsUfBMORdyxana1xHXtVHdWF5h2OsTBdbljDYXk1mH2AITXgHh1elOJgWCVemminyrQme1erz7R7RFeoM6tXK24wvPBH2JVr0BD5tImSG4QnzUBbQUZqNTN9yeGrNrIET";
  24. $session = "m4CGpnkcIk1TUBUrUFLtkiFS06u7GQBTL4p0hz2PKUzumjM7PnqZwWHmS2kpJM8kGnaNN3tnNSIZ2kWIydyU066JYhYyTWIpaJ3NCn1f6z5YJSw8WUSMQPlFXa3GXCWXbQBD3sJZSFOsnbq9W9MDP";
  25. $faillogins = "oFrc537KHTfMdzijer7CYYlS7xsYm5ABBSDwMA6jjcWnC4wGmt8aijTfGc4S7ukycNVOeSYoULBmGYSShRTp0CvwEqfBKp0N3Ls7thleSNrpBa7JRQZHjl4NBaecp5PjG8g0fs5Y6mdxma73RXB08";
  26. $usession = $_SESSION[$session];
  27. if (!isset($_SESSION[$faillogins])) {
  28.     $_SESSION[$faillogins] = 0;
  29. }
  30.  
  31. /* * ***************************************** THE CONFIGS ****************************************************** */
  32.  
  33. // Configs for mode "development" (Slim's default), see the GitHub readme for details on setting the environment
  34. $app->configureMode('development', function () use ($app) {
  35.     $app->config(array(
  36.         'debug' => true,
  37.         'database' => array(
  38.             'db_host' => 'localhost',
  39.             'db_port' => '',
  40.             'db_name' => 'dayofinfection',
  41.             'db_user' => 'dayofinfection',
  42.             'db_pass' => 'ENTFERNT'
  43.         )
  44.     ));
  45. });
  46.  
  47. // Configs for mode "production"
  48. $app->configureMode('production', function () use ($app) {
  49.     $app->config(array(
  50.         'debug' => false,
  51.         'database' => array(
  52.             'db_host' => 'localhost',
  53.             'db_port' => '',
  54.             'db_name' => 'dayofinfection',
  55.             'db_user' => 'dayofinfection',
  56.             'db_pass' => 'ENTFERNT'
  57.         )
  58.     ));
  59. });
  60.  
  61. /* * ****************************************** THE MODEL ******************************************************* */
  62.  
  63. $model = new \Mini\Model\Model($app->config('database'));
  64. if (isset($_SESSION[$session])) {
  65.     if (!$model->existUserID($usession)) {
  66.         session_destroy();
  67.         session_unset();
  68.     }
  69. }
  70. if (isset($_SESSION[$session])) {
  71.     global $model, $usession;
  72.     $model->updateUserActivity($usession);
  73.     $user = array(
  74.         "loggedin" => true,
  75.         "name" => $model->getAccountDetail("name", $usession),
  76.         "admin" => $model->getAccountDetail("adminlevel", $usession),
  77.         "lastactivity" => $model->getAccountDetail("last_cp_activity", $usession),
  78.         "id" => $model->getAccountDetail("id", $usession),
  79.         "pns" => $model->getUnreadedPNS($usession),
  80.         "notifications" => $model->countUserNotifications($usession),
  81.         "skin" => $model->getAccountDetail("skin", $usession),
  82.         "ts3uid" => $model->getAccountDetail("ts3uid", $usession),
  83.         "beta" => $model->getAccountDetail("beta", $usession)
  84.     );
  85. } else {
  86.     global $model;
  87.     $user = array(
  88.         "loggedin" => false
  89.     );
  90. }
  91.  
  92. $function = new \Twig_SimpleFunction("getAccountDetail", function ($id, $detail) {
  93.     global $model;
  94.     return $model->getAccountDetail($id, $detail);
  95. });
  96. $twig->addFunction($function);
  97. $function = new \Twig_SimpleFunction("parseText", function ($text) {
  98.     $text = strip_tags($text);
  99.     $basic_bbcode = array(
  100.         '[b]', '[/b]',
  101.         '[i]', '[/i]',
  102.         '[u]', '[/u]',
  103.         '&#10;',
  104.     );
  105.     $basic_html = array(
  106.         '<strong>', '</strong>',
  107.         '<i>', '</i>',
  108.         '<u>', '</u>',
  109.         '<br/>',
  110.     );
  111.     $tmp = str_replace('<div class="embed-responsive embed-responsive-16by9">&nbsp;</div>', "", $text);
  112.     $tmp = str_replace($basic_bbcode, $basic_html, $text);
  113.     return $tmp;
  114. });
  115. $twig->addFunction($function);
  116. $function = new \Twig_SimpleFunction("renderPN", function ($text) {
  117.     $text = strip_tags($text);
  118.     $basic_bbcode = array(
  119.         '[b]', '[/b]',
  120.         '[i]', '[/i]',
  121.         '[u]', '[/u]',
  122.         '[img]', '[/img]',
  123.     );
  124.     $basic_html = array(
  125.         '<strong>', '</strong>',
  126.         '<i>', '</i>',
  127.         '<u>', '</u>',
  128.         '<img src="', '" class="img-responsive" />'
  129.     );
  130.     $tmp = str_replace($basic_bbcode, $basic_html, $text);
  131.     $tmp = str_replace('<div class="embed-responsive embed-responsive-16by9">&nbsp;</div>', "", $tmp);
  132.     return nl2br($tmp);
  133. });
  134. $twig->addFunction($function);
  135.  
  136. $function = new \Twig_SimpleFunction("ReadMore", function ($string) {
  137.     global $model;
  138.     $count = strpos($string, '[ more ]');
  139.     if ($count === false) {
  140.         return str_replace("http://i.imgur.com", "https://i.imgur.com", $model->showBBcodes($string));
  141.     } else {
  142.         $text = substr($string, 0, $count);
  143.         $string = $model->showBBcodes($text) . '<hr/><strong>Um mehr zu erfahren, klicke auf "Mehr lesen".</strong>';
  144.         return str_replace("http://i.imgur.com", "https://i.imgur.com", $string);
  145.     }
  146. });
  147. $twig->addFunction($function);
  148.  
  149. $function = new \Twig_SimpleFunction("replaceMore", function ($string) {
  150.     global $model;
  151.     $string = str_replace("[ more ]", "", $model->showBBcodes($string));
  152.     return str_replace("http://i.imgur.com", "https://i.imgur.com", $string);
  153. });
  154. $twig->addFunction($function);
  155. $function = new \Twig_SimpleFunction("renderKommentar", function ($text) {
  156.     $text = strip_tags($text);
  157.     $basic_bbcode = array(
  158.         '[b]', '[/b]',
  159.         '[i]', '[/i]',
  160.         '[u]', '[/u]',
  161.     );
  162.     $basic_html = array(
  163.         '<strong>', '</strong>',
  164.         '<i>', '</i>',
  165.         '<u>', '</u>',
  166.     );
  167.     $tmp = str_replace($basic_bbcode, $basic_html, $text);
  168.     $tmp = str_replace('<div class="embed-responsive embed-responsive-16by9">&nbsp;</div>', "", $tmp);
  169.     $tmp = str_replace('http://', "https://", $tmp);
  170.     return nl2br($tmp);
  171. });
  172. $twig->addFunction($function);
  173. $function = new \Twig_SimpleFunction("commentCount", function ($string) {
  174.     global $model;
  175.     return $model->getNewsCommentAmount($string);
  176. });
  177. $twig->addFunction($function);
  178. $function = new \Twig_SimpleFunction("getTimestampUserOnline", function () {
  179.     return time() - 900;
  180. });
  181. $twig->addFunction($function);
  182. $function = new \Twig_SimpleFunction("hasCriticalAlert", function ($userid) {
  183.     global $model;
  184.     return $model->hasCriticalAlert($userid);
  185. });
  186. $twig->addFunction($function);
  187. $function = new \Twig_SimpleFunction("getTimestamp", function () {
  188.     return time();
  189. });
  190. $twig->addFunction($function);
  191. $function = new \Twig_SimpleFunction("countBeta", function () {
  192.     global $model;
  193.     return $model->countBeta();
  194. });
  195. $twig->addFunction($function);
  196. $function = new \Twig_SimpleFunction("getBetaStatus", function ($id) {
  197.     global $model;
  198.     if ($model->getStatusFromBeta($id) == "0") {
  199.         return "Bewerbung ausstehend";
  200.     }
  201.     if ($model->getStatusFromBeta($id) == "1") {
  202.         return "Angenommen - Wir kontaktieren dich";
  203.     }
  204.     if ($model->getStatusFromBeta($id) == "2") {
  205.         return "Abgelehnt - Tut uns leid";
  206.     }
  207. });
  208. $twig->addFunction($function);
  209. $function = new \Twig_SimpleFunction("countOpenTickets", function () {
  210.     global $model;
  211.     return $model->countOpenTickets();
  212. });
  213. $twig->addFunction($function);
  214. $function = new \Twig_SimpleFunction("getTicketCategoryName", function ($id) {
  215.     global $model;
  216.     return $model->getTicketCategoryName($id);
  217. });
  218. $twig->addFunction($function);
  219. $function = new \Twig_SimpleFunction("getTicketAnswersCount", function ($id) {
  220.     global $model;
  221.     return $model->getTicketAnswersCount($id);
  222. });
  223. $twig->addFunction($function);
  224. $function = new \Twig_SimpleFunction("getPlayerReports", function () {
  225.     global $model;
  226.     return $model->getPlayerReports();
  227. });
  228. $twig->addFunction($function);
  229. $function = new \Twig_SimpleFunction("RenderBBCode", function ($text) {
  230.     global $model;
  231.     return $model->showBBcodes($text);
  232. });
  233. $twig->addFunction($function);
  234. $function = new \Twig_SimpleFunction("isSecure", function () {
  235.     global $model;
  236.     return $model->isSecure();
  237. });
  238. $twig->addFunction($function);
  239. $function = new \Twig_SimpleFunction("getURL", function () {
  240.     global $model;
  241.     return $model->getURL();
  242. });
  243. $twig->addFunction($function);
  244. $function = new \Twig_SimpleFunction("getBrowserName", function ($user_agent) {
  245.     global $model;
  246.     return $model->get_browser_name($user_agent);
  247. });
  248. $twig->addFunction($function);
  249. $function = new \Twig_SimpleFunction("getUserAgent", function () {
  250.     return $_SERVER['HTTP_USER_AGENT'];
  251. });
  252. $twig->addFunction($function);
  253. $function = new \Twig_SimpleFunction("sizeof", function ($array) {
  254.     return sizeof($array);
  255. });
  256. $twig->addFunction($function);
  257. $function = new \Twig_SimpleFunction("getAllUsers", function () {
  258.     global $model;
  259.     return $model->getAllUsersOrderByTimestamp();
  260. });
  261. $twig->addFunction($function);
  262. $function = new \Twig_SimpleFunction("getNewestMember", function () {
  263.     global $model;
  264.     return $model->getNewestMember();
  265. });
  266. $twig->addFunction($function);
  267. $function = new \Twig_SimpleFunction("isUserBeta", function ($id) {
  268.     global $model;
  269.     return $model->isUserBeta($id);
  270. });
  271. $twig->addFunction($function);
  272. /* * ********************************** THE ROUTES / CONTROLLERS ************************************************ */
  273.  
  274. // GET request on homepage, simply show the view template index.twig
  275. $app->get('/', function () use ($app) {
  276.     getChecks();
  277.     global $user, $model;
  278.     $app->render('index.twig', array(
  279.         "title" => "Startseite",
  280.         "page" => "index",
  281.         "user" => $user,
  282.         "news" => $model->getAllNews()
  283.     ));
  284. });
  285. $app->get('/nutzungsbedingungen', function () use ($app) {
  286.     getChecks();
  287.     global $user, $model;
  288.     $app->render('nutzung.twig', array(
  289.         "title" => "Nutzungsbedingungen",
  290.         "page" => "nutzungsbedingungen",
  291.         "user" => $user
  292.     ));
  293. });
  294. $app->get('/launcher', function () use ($app) {
  295.     getChecks();
  296.     global $user;
  297.     $app->render('launcher.twig', array(
  298.         "title" => "Launcher",
  299.         "page" => "launcher",
  300.         "user" => $user
  301.     ));
  302. });
  303. $app->get('/launcher/whitelist', function () use ($app) {
  304.     getChecks();
  305.     global $user, $model;
  306.     $app->render('mod_whitelist.twig', array(
  307.         "title" => "Erlaubte Modifikationen",
  308.         "page" => "launcher",
  309.         "user" => $user,
  310.         "mods" => $model->getMods()
  311.     ));
  312. });
  313. $app->get('/team', function () use ($app) {
  314.     getChecks();
  315.     global $user, $model;
  316.     $app->render('team.twig', array(
  317.         "title" => "Teammitglieder",
  318.         "page" => "team",
  319.         "team" => $model->getTeam(),
  320.         "user" => $user,
  321.         "counts" => $model->countTeamMembers()
  322.     ));
  323. });
  324. $app->get('/mitglieder/:seite', function ($seite) use ($app) {
  325.     getChecks();
  326.     global $user, $model;
  327.     if ($seite > $model->getMemberPages()) {
  328.         $app->redirect("/mitglieder/1");
  329.         exit;
  330.     }
  331.     $app->render('mitglieder.twig', array(
  332.         "title" => "Mitglieder",
  333.         "page" => "team",
  334.         "team" => $model->getMitgliederPage($seite),
  335.         "user" => $user,
  336.         "pages" => $model->getMemberPages(),
  337.         "page" => $seite,
  338.         "countmember" => $model->countMembers()
  339.     ));
  340. });
  341. $app->get('/betaliste', function () use ($app) {
  342.     getChecks();
  343.     global $user, $model;
  344.     $app->render('betaliste.twig', array(
  345.         "title" => "Closed Beta Teilnehmer",
  346.         "page" => "team",
  347.         "team" => $model->getBetaUser(),
  348.         "user" => $user
  349.     ));
  350. });
  351. $app->get('/stats', function () use ($app) {
  352.     getChecks();
  353.     global $user, $model;
  354.     $app->render('stats.twig', array(
  355.         "title" => "Statistiken",
  356.         "page" => "stats",
  357.         "user" => $user,
  358.         "online" => $model->getIGOnlineUser(),
  359.         "count" => $model->countIGUsers()
  360.     ));
  361. });
  362. $app->get('/imprint', function () use ($app) {
  363.     getChecks();
  364.     global $user;
  365.     $app->render('imprint.twig', array(
  366.         "title" => "Impressum",
  367.         "page" => "imprint",
  368.         "user" => $user
  369.     ));
  370. });
  371. $app->get('/privacy', function () use ($app) {
  372.     getChecks();
  373.     global $user;
  374.     $app->render('privacy.twig', array(
  375.         "title" => "Datenschutz",
  376.         "page" => "privacy",
  377.         "user" => $user
  378.     ));
  379. });
  380. $app->get('/beta', function () use ($app) {
  381.     getChecks();
  382.     global $user;
  383.     if ($user["loggedin"]) {
  384.         $app->render('beta.twig', array(
  385.             "title" => "Beta Anmeldung",
  386.             "page" => "beta",
  387.             "user" => $user
  388.         ));
  389.     } else {
  390.         $app->redirect("/");
  391.     }
  392. });
  393. $app->get('/profil/:id', function ($name) use ($app) {
  394.     getChecks();
  395.     global $user, $model;
  396.  
  397.     if ($model->existUser($name)) {
  398.         $usertmp = $model->getUserDataByName($name);
  399.         $app->render('user.twig', array(
  400.             "title" => "Profil von " . $usertmp->name,
  401.             "page" => "privacy",
  402.             "user" => $user,
  403.             "mitglied" => $usertmp
  404.         ));
  405.     } else {
  406.         $app->redirect("/");
  407.     }
  408. });
  409. $app->group('/support', function() use ($app, $model) {
  410.     $app->get('/list', function () use ($app) {
  411.         getChecks();
  412.         global $user, $model;
  413.         if ($user["loggedin"] == true) {
  414.             $app->render('support/list.twig', array(
  415.                 "title" => "Meine Tickets",
  416.                 "page" => "support",
  417.                 "user" => $user,
  418.                 "tickets" => $model->getUserTickets($user["id"])
  419.             ));
  420.         } else {
  421.             $app->redirect("/");
  422.         }
  423.     });
  424.     $app->get('/read/:id', function ($id) use ($app) {
  425.         getChecks();
  426.         global $user, $model, $csrfs;
  427.         if ($user["loggedin"] == true) {
  428.             if ($model->existTicket($id)) {
  429.                 $ticket = $model->getUserTicket($id);
  430.                 if ($ticket["0"]->userid == $user["id"] || $user["admin"] > 0) {
  431.                     $csrf = $_SESSION[$csrfs] = $model->generateRandomString(64) . rand() . $model->generateRandomString();
  432.                     $app->render('support/read.twig', array(
  433.                         "title" => "Ticket #" . $ticket["0"]->id,
  434.                         "page" => "support",
  435.                         "user" => $user,
  436.                         "ticket" => $ticket["0"],
  437.                         "antworten" => $model->getTicketAnswers($id),
  438.                         "csrf" => $csrf
  439.                     ));
  440.                 } else {
  441.                     $app->redirect("/");
  442.                 }
  443.             } else {
  444.                 $app->redirect("/");
  445.             }
  446.         } else {
  447.             $app->redirect("/");
  448.         }
  449.     });
  450.     $app->get('/close/:id', function ($id) use ($app) {
  451.         getChecks();
  452.         global $user, $model, $csrfs;
  453.         if ($user["loggedin"] == true) {
  454.             if ($model->existTicket($id)) {
  455.                 $ticket = $model->getUserTicket($id);
  456.                 if ($ticket["0"]->userid == $user["id"] || $user["admin"] > 0) {
  457.                     $model->closeTicket($id);
  458.                     $app->redirect("/support/read/$id");
  459.                 } else {
  460.                     $app->redirect("/");
  461.                 }
  462.             } else {
  463.                 $app->redirect("/");
  464.             }
  465.         } else {
  466.             $app->redirect("/");
  467.         }
  468.     });
  469.     $app->get('/new', function () use ($app) {
  470.         getChecks();
  471.         global $user, $model, $csrfs;
  472.         if ($user["loggedin"] == true) {
  473.             $csrf = $_SESSION[$csrfs] = $model->generateRandomString(64) . rand() . $model->generateRandomString();
  474.             $app->render('support/new.twig', array(
  475.                 "title" => "Neues Ticket erstellen",
  476.                 "page" => "support",
  477.                 "user" => $user,
  478.                 "csrf" => $csrf,
  479.                 "kategorien" => $model->getKategorien()
  480.             ));
  481.         } else {
  482.             $app->redirect("/");
  483.         }
  484.     });
  485.     $app->post('/addAnswer', function () use ($app) {
  486.         global $user, $app, $model, $usession, $csrfs;
  487.         if (!$user["loggedin"])
  488.             die("Bitte logge dich ein.");
  489.  
  490.         $id = $_POST["id"];
  491.         $csrf = $_POST["csrf"];
  492.         $content = $_POST['content'];
  493.         $error = "";
  494.  
  495.         if ($_SESSION[$csrfs] != $csrf) {
  496.             $error = $error . '<br/>&bull; Dein CSRF-Token ist ungültig - Bitte lade die Seite neu';
  497.         }
  498.         if (!$model->existTicket($id)) {
  499.             $error = $error . '<br/>&bull; Dieses Ticket gibt es nicht';
  500.         } else {
  501.             $ticket = $model->getUserTicket($id);
  502.             if ($ticket["0"]->userid != $user["id"] && $user["admin"] == "0") {
  503.                 $error = $error . '<br/>&bull; Dieses Ticket hast du nicht erstellt';
  504.             }
  505.         }
  506.  
  507.         if (strlen($content) < 12) {
  508.             $error = $error . '<br/>&bull; Bitte schreibe einen längeren Text';
  509.         }
  510.         if (strlen($content) > 65530) {
  511.             $error = $error . '<br/>&bull; Bitte schreibe deinen Text etwas kürzer';
  512.         }
  513.  
  514.         if ($error == "") {
  515.             if ($user["id"] != $ticket["0"]->userid) {
  516.                 $model->addNotification($ticket["0"]->userid, 1, 'Du hast eine neue Antwort zu deinem Ticket <a href="/support/read/' . $ticket["0"]->id . '" class="profil">(Ticket öffnen)</a>.');
  517.             }
  518.             $model->ticketAnswer($user["id"], $ticket["0"]->id, $content);
  519.             echo '<div class="alert alert-success">Deine Antwort wurde gespeichert!</div>';
  520.             echo '<meta http-equiv="refresh" content="1; URL=/support/read/' . $ticket["0"]->id . '">';
  521.             echo '<script>$("#submit").hide();</script>';
  522.         } else {
  523.             echo '<div class="alert alert-danger"><strong>Folgende Fehler sind aufgetreten:</strong>' . $error . '</div>';
  524.         }
  525.     });
  526.     $app->post('/addTicket', function () use ($app) {
  527.         global $user, $app, $model, $usession, $csrfs;
  528.         if (!$user["loggedin"])
  529.             die("Bitte logge dich ein.");
  530.  
  531.         $csrf = $_POST["csrf"];
  532.         $content = $_POST['content'];
  533.         $category = $_POST['category'];
  534.         $cname = $_POST['cname'];
  535.         $error = "";
  536.         $cid = -1;
  537.  
  538.         if ($_SESSION[$csrfs] != $csrf) {
  539.             $error = $error . '<br/>&bull; Dein CSRF-Token ist ungültig - Bitte lade die Seite neu';
  540.         }
  541.  
  542.         if (strlen($content) < 12) {
  543.             $error = $error . '<br/>&bull; Bitte schreibe einen längeren Text';
  544.         }
  545.         if (strlen($content) > 65530) {
  546.             $error = $error . '<br/>&bull; Bitte schreibe deinen Text etwas kürzer';
  547.         }
  548.         if (!$model->existTicketCategory($category)) {
  549.             $error = $error . '<br/>&bull; Diese Kategorie gibt es nicht';
  550.         }
  551.         if ($category == "6") {
  552.             if (!$model->existUser($cname)) {
  553.                 $error = $error . '<br/>&bull; Der vermutete Cheater ist hier nicht registriert';
  554.             } else {
  555.                 $cid = $model->getIDByName($cname);
  556.             }
  557.         }
  558.  
  559.         if ($error == "") {
  560.             $model->addTicket($user["id"], $category, $content, $cid);
  561.             echo '<div class="alert alert-success">Dein Ticket wurde erstellt!</div>';
  562.             echo '<script>$("#submit").hide();</script>';
  563.             echo '<script>window.setTimeout(function() { window.location.href = "/support/list"; }, 1000);</script>';
  564.         } else {
  565.             echo '<div class="alert alert-danger"><strong>Folgende Fehler sind aufgetreten:</strong>' . $error . '</div>';
  566.         }
  567.     });
  568. });
  569. $app->group('/admincenter', function () use ($app, $model) {
  570.     $app->get('/beta', function () use ($app) {
  571.         getChecks();
  572.         global $user, $model;
  573.  
  574.         if ($user["loggedin"] == true) {
  575.             if ($user["admin"] > 0) {
  576.                 $app->render('admincenter/beta.twig', array(
  577.                     "title" => "Beta Anmeldungen",
  578.                     "page" => "admincenter",
  579.                     "user" => $user,
  580.                     "anmeldungen" => $model->getBeta(),
  581.                 ));
  582.             } else {
  583.                 $app->redirect("/");
  584.             }
  585.         } else {
  586.             $app->redirect("/");
  587.         }
  588.     });
  589.     $app->get('/tickets', function () use ($app) {
  590.         getChecks();
  591.         global $user, $model;
  592.  
  593.         if ($user["loggedin"] == true) {
  594.             if ($user["admin"] > 0) {
  595.                 $app->render('admincenter/ticket_list.twig', array(
  596.                     "title" => "Offene Tickets",
  597.                     "page" => "admincenter",
  598.                     "user" => $user,
  599.                     "tickets" => $model->getOpenTickets(),
  600.                 ));
  601.             } else {
  602.                 $app->redirect("/");
  603.             }
  604.         } else {
  605.             $app->redirect("/");
  606.         }
  607.     });
  608.     $app->post('/registerBeta', function () use ($app) {
  609.         global $user, $app, $model;
  610.         if (!$user["loggedin"])
  611.             die("Bitte logge dich ein.");
  612.  
  613.         if (!$model->isUserBeta($user["id"])) {
  614.             echo '<div class="alert alert-success">Du hast dich erfolgreich für die Closed Beta eingeschrieben!</div>';
  615.             echo '<script>$("#anmeldung").hide();</script>';
  616.             $model->addBeta($user["id"]);
  617.         }
  618.     });
  619. });
  620. $app->group('/notifications', function () use ($app, $model) {
  621.     $app->get('/list', function () use ($app) {
  622.         getChecks();
  623.         global $user, $model;
  624.  
  625.         if ($user["loggedin"] == true) {
  626.             $app->render('notifications/list.twig', array(
  627.                 "title" => "Übersicht",
  628.                 "page" => "notifications",
  629.                 "user" => $user,
  630.                 "list" => $model->getUserNotifications($user["id"]),
  631.             ));
  632.         } else {
  633.             $app->redirect("/");
  634.         }
  635.     });
  636.     $app->get('/delete/:code', function ($id) use ($app) {
  637.         getChecks();
  638.         global $user, $model;
  639.  
  640.         if ($user["loggedin"] == true) {
  641.             if ($model->existNotification($id)) {
  642.                 if ($model->notificationOwner($id) == $user["id"]) {
  643.                     $model->deleteNotification($id);
  644.                     $app->redirect("/notifications/list");
  645.                 } else {
  646.                     $app->redirect("/");
  647.                 }
  648.             } else {
  649.                 $app->redirect("/");
  650.             }
  651.         } else {
  652.             $app->redirect("/");
  653.         }
  654.     });
  655. });
  656.  
  657. $app->group('/pn', function () use ($app, $model) {
  658.     $app->get('/list', function () use ($app) {
  659.         getChecks();
  660.         global $user, $model, $csrfs;
  661.  
  662.         if ($user["loggedin"] == true) {
  663.             $csrf = $_SESSION[$csrfs] = $model->generateRandomString(64) . rand() . $model->generateRandomString();
  664.             $app->render('pn/list.twig', array(
  665.                 "title" => "Übersicht",
  666.                 "page" => "pn",
  667.                 "user" => $user,
  668.                 "csrf" => $csrf,
  669.                 "empfangen" => $model->getUserPNS($user["id"]),
  670.                 "gesendet" => $model->getUserSendetPNS($user["id"]),
  671.                 "to" => "",
  672.                 "pnsused" => $model->countUsedPNS($user["id"]),
  673.                 "maxpns" => $model->userMaxPNS($user["id"])
  674.             ));
  675.         } else {
  676.             $app->redirect("/");
  677.         }
  678.     });
  679.     $app->get('/list/:to', function ($to) use ($app) {
  680.         getChecks();
  681.         global $user, $model, $csrfs;
  682.  
  683.         if ($user["loggedin"] == true) {
  684.             $csrf = $_SESSION[$csrfs] = $model->generateRandomString(64) . rand() . $model->generateRandomString();
  685.             $app->render('pn/list.twig', array(
  686.                 "title" => "Übersicht",
  687.                 "page" => "pn",
  688.                 "user" => $user,
  689.                 "csrf" => $csrf,
  690.                 "empfangen" => $model->getUserPNS($user["id"]),
  691.                 "gesendet" => $model->getUserSendetPNS($user["id"]),
  692.                 "to" => $to,
  693.                 "pnsused" => $model->countUsedPNS($user["id"]),
  694.                 "maxpns" => $model->userMaxPNS($user["id"])
  695.             ));
  696.         } else {
  697.             $app->redirect("/");
  698.         }
  699.     });
  700.     $app->get('/read/:code', function ($id) use ($app) {
  701.         getChecks();
  702.         global $user, $model, $csrfs;
  703.  
  704.         if ($user["loggedin"] == true) {
  705.             if (!$model->existPN($id)) {
  706.                 $app->redirect("/");
  707.             }
  708.             $message = $model->getUserPN($id);
  709.             if ($message["0"]->toid != $user["id"] && $message["0"]->fromid != $user["id"]) {
  710.                 $app->redirect("/");
  711.             }
  712.             if ($message["0"]->toid == $user["id"]) {
  713.                 $model->markPNasReaded($message["0"]->id);
  714.             }
  715.  
  716.             if ($model->amountUserPNAnswer($id) > 0) {
  717.                 $answer = $model->getUserPNAnswer($id);
  718.             } else {
  719.                 $answer = array();
  720.             }
  721.             $app->render('pn/read.twig', array(
  722.                 "title" => $message["0"]->subject,
  723.                 "page" => "pn",
  724.                 "user" => $user,
  725.                 "empfangen" => $message,
  726.                 "antworten" => $answer
  727.             ));
  728.         } else {
  729.             $app->redirect("/");
  730.         }
  731.     });
  732.     $app->get('/close/:code', function ($id) use ($app) {
  733.         getChecks();
  734.         global $user, $model, $csrfs;
  735.  
  736.         if ($user["loggedin"] == true) {
  737.             if (!$model->existPN($id)) {
  738.                 $app->redirect("/");
  739.             }
  740.             $message = $model->getUserPN($id);
  741.             if ($message["0"]->toid != $user["id"] && $message["0"]->fromid != $user["id"]) {
  742.                 $app->redirect("/");
  743.             } else {
  744.                 $model->closePN($id);
  745.                 $app->redirect("/pn/read/$id");
  746.             }
  747.         } else {
  748.             $app->redirect("/");
  749.         }
  750.     });
  751.     /* $app->get('/delete/:code', function ($id) use ($app) {
  752.       global $user, $model, $csrfs;
  753.  
  754.       if ($user["loggedin"] == true) {
  755.       if (!$model->existPN($id)) {
  756.       $app->redirect("/");
  757.       }
  758.       $message = $model->getUserPN($id);
  759.       if ($message["0"]->toid != $user["id"] && $message["0"]->fromid != $user["id"]) {
  760.       $app->redirect("/");
  761.       } else {
  762.       $model->deletePN($id);
  763.       $app->redirect("/pn/read/$id");
  764.       }
  765.       } else {
  766.       $app->redirect("/");
  767.       }
  768.       }); */
  769.     $app->post('/newPN', function () use ($app) {
  770.         global $user, $app, $model, $csrfs;
  771.         if (!$user["loggedin"])
  772.             die("Bitte logge dich ein.");
  773.  
  774.         $error = "";
  775.         $to = strip_tags($_POST["to"]);
  776.         $subj = strip_tags($_POST["subj"]);
  777.         $text = strip_tags($_POST["content"]);
  778.         $hinw = strip_tags($_POST["hinw"]);
  779.         $toid = -1;
  780.         if ($_SESSION[$csrfs] != $_POST["csrf"]) {
  781.             $error = $error . '<br/>&bull; Dein CSRF-Token ist ungültig - Bitte lade die Seite neu';
  782.         }
  783.         if (!$model->existUser($to)) {
  784.             $error = $error . '<br/>&bull; Der Benutzer "' . $to . '" ist hier nicht registriert';
  785.         } else {
  786.             $toid = intval($model->getIDByName($to));
  787.         }
  788.         if (!isset($subj) || str_replace(" ", "", $subj) == "") {
  789.             $error = $error . '<br/>&bull; Du musst einen Betreff angeben';
  790.         }
  791.         if (strlen($subj) > 32) {
  792.             $error = $error . '<br/>&bull; Der Betreff darf nur max. 32 Zeichen lang sein';
  793.         }
  794.         if (!isset($text) || str_replace(" ", "", $text) == "" || strlen($text) < 16) {
  795.             $error = $error . '<br/>&bull; Du musst einen längeren Text schreiben';
  796.         }
  797.         if (strlen($text) > 65530) {
  798.             $error = $error . '<br/>&bull; Dein Text ist zu lang (' . strlen($text) . ' Zeichen von maximal 65530 Zeichen)';
  799.         }
  800.         if ($hinw != "true") {
  801.             $error = $error . '<br/>&bull; Du musst bestätigen, dass diese PN keine Support-Anfrage ist';
  802.         }
  803.         if ($toid != -1) {
  804.             if (!$model->canUserGetPNS($toid)) {
  805.                 $error = $error . '<br/>&bull; ' . $to . ' möchte keine privaten Nachrichten erhalten';
  806.             }
  807.         }
  808.         if ($user["id"] == $toid) {
  809.             $error = $error . '<br/>&bull; Du kannst dir nicht selbst eine Nachricht schreiben';
  810.         }
  811.         if ($error == "") {
  812.             $model->newPN($user["id"], $to, $subj, $text);
  813.             echo '<div class="alert alert-success">Deine Nachricht wurde erfolgreich an ' . $to . ' gesendet!</div>';
  814.             echo '<script>$("#pnform").get(0).reset();</script>';
  815.         } else {
  816.             echo '<div class="alert alert-danger"><strong>Folgende Fehler sind aufgetreten:</strong>' . $error . '</div>';
  817.         }
  818.     });
  819.  
  820.     $app->post('/reply', function () use ($app) {
  821.         global $user, $app, $model, $csrfs;
  822.         if (!$user["loggedin"])
  823.             die("Bitte logge dich ein.");
  824.  
  825.         $error = "";
  826.         $content = strip_tags($_POST["content"]);
  827.         $pnid = strip_tags($_POST["id"]);
  828.  
  829.         $pn = $model->getUserPN($pnid);
  830.         if ($pn["0"]->closed == 1) {
  831.             $error = $error . '<br/>&bull; Diese Nachricht wurde geschlossen';
  832.         }
  833.  
  834.         if ($pn["0"]->toid != $user["id"] && $pn["0"]->fromid != $user["id"]) {
  835.             $error = $error . '<br/>&bull; Die PN ist nicht von dir oder war nicht an dich gerichtet';
  836.         }
  837.         if (!isset($content) || str_replace(" ", "", $content) == "" || strlen($content) < 4) {
  838.             $error = $error . '<br/>&bull; Du musst einen längeren Text schreiben';
  839.         }
  840.  
  841.         if ($user["id"] == $pn["0"]->toid) {
  842.             if (!$model->canUserGetPNS($pn["0"]->fromid)) {
  843.                 $error = $error . '<br/>&bull; ' . $model->getAccountDetail("name", $pn["0"]->fromid) . ' möchte keine privaten Nachrichten erhalten';
  844.             }
  845.         } else {
  846.             if (!$model->canUserGetPNS($pn["0"]->toid)) {
  847.                 $error = $error . '<br/>&bull; ' . $model->getAccountDetail("name", $pn["0"]->toid) . ' möchte keine privaten Nachrichten erhalten';
  848.             }
  849.         }
  850.  
  851.         if ($error == "") {
  852.             if ($user["id"] == $pn["0"]->toid) {
  853.                 $model->answerPN($pnid, $content, $user["id"], $pn["0"]->fromid);
  854.                 echo '<div class="alert alert-success">Deine Antwort wurde an ' . $model->getAccountDetail("name", $pn["0"]->fromid) . ' gesendet!</div>';
  855.                 $model->addNotification($pn["0"]->fromid, 1, 'Du hast eine neue Antwort von ' . $model->getAccountDetail("name", $user["id"]) . ' zu der PN <a href="/pn/read/' . $pn["0"]->id . '" class="profil">"' . $pn["0"]->subject . '"</a>');
  856.             } else {
  857.                 $model->answerPN($pnid, $content, $pn["0"]->fromid, $pn["0"]->toid);
  858.                 echo '<div class="alert alert-success">Deine Antwort wurde an ' . $model->getAccountDetail("name", $pn["0"]->toid) . ' gesendet!</div>';
  859.                 $model->addNotification($pn["0"]->toid, 1, 'Du hast eine neue Antwort von ' . $model->getAccountDetail("name", $pn["0"]->fromid) . ' zu der PN <a href="/pn/read/' . $pn["0"]->id . '" class="profil">"' . $pn["0"]->subject . '"</a>');
  860.             }
  861.             echo '<meta http-equiv="refresh" content="1; URL=/pn/read/' . $pn["0"]->id . '">';
  862.             echo '<script>$("#submit").hide();</script>';
  863.         } else {
  864.             echo '<div class="alert alert-danger"><strong>Folgende Fehler sind aufgetreten:</strong>' . $error . '</div>';
  865.         }
  866.     });
  867. });
  868.  
  869. $app->group('/api', function () use ($app, $model) {
  870.  
  871.     $app->get('/servername', function () use ($app) {
  872.         echo "Unbekannt";
  873.     });
  874.     $app->get('/players', function () use ($app) {
  875.         echo "Unbekannt / Unbekannt";
  876.     });
  877.     $app->get('/online', function () use ($app) {
  878.         echo "offline";
  879.     });
  880. });
  881.  
  882. $app->group('/news', function () use ($app, $model) {
  883.     $app->get('/create', function () use ($app) {
  884.         getChecks();
  885.         global $user;
  886.         if (!$user["loggedin"])
  887.             die("Bitte logge dich ein.");
  888.  
  889.         if ($user["admin"] == "4" || $user["admin"] == "3") {
  890.             $app->render('news/create.twig', array(
  891.                 "title" => "News erstellen",
  892.                 "page" => "news_create",
  893.                 "user" => $user
  894.             ));
  895.         } else {
  896.             $app->redirect("/");
  897.         }
  898.     });
  899.     $app->get('/edit/:id', function ($id) use ($app) {
  900.         getChecks();
  901.         global $user, $model;
  902.         if (!$user["loggedin"])
  903.             die("Bitte logge dich ein.");
  904.  
  905.         if ($user["admin"] == "4" || $user["admin"] == "3") {
  906.             if ($model->existNews($id)) {
  907.                 $app->render('news/edit.twig', array(
  908.                     "title" => "News bearbeiten",
  909.                     "page" => "news_edit",
  910.                     "user" => $user,
  911.                     "article" => $model->getNews($id)
  912.                 ));
  913.             } else {
  914.                 $app->redirect("/");
  915.             }
  916.         } else {
  917.             $app->redirect("/");
  918.         }
  919.     });
  920.     $app->get('/delete/:id', function ($id) use ($app) {
  921.         getChecks();
  922.         global $user, $model;
  923.         if (!$user["loggedin"])
  924.             die("Bitte logge dich ein.");
  925.  
  926.         if ($user["admin"] == "4" || $user["admin"] == "3") {
  927.             if ($model->existNews($id)) {
  928.                 $model->deleteNews($id);
  929.                 $app->redirect("/");
  930.             } else {
  931.                 $app->redirect("/");
  932.             }
  933.         } else {
  934.             $app->redirect("/");
  935.         }
  936.     });
  937.     $app->get('/comment/delete/:id', function ($id) use ($app) {
  938.         getChecks();
  939.         global $user, $model;
  940.         if (!$user["loggedin"])
  941.             die("Bitte logge dich ein.");
  942.  
  943.         if ($user["admin"] > 0) {
  944.             if ($model->existComment($id)) {
  945.                 $comment = $model->getCommentByID($id); #
  946.                $model->deleteComment($id);
  947.                 $app->redirect("/news/read/" . $comment["0"]->news_id);
  948.             } else {
  949.                 $app->redirect("/");
  950.             }
  951.         } else {
  952.             $app->redirect("/");
  953.         }
  954.     });
  955.     $app->get('/read/:id', function ($id) use ($app) {
  956.         getChecks();
  957.         global $user, $model, $csrfs;
  958.         $csrf = $_SESSION[$csrfs] = $model->generateRandomString(64) . rand() . $model->generateRandomString();
  959.         if ($model->existNews($id)) {
  960.             $news = $model->getNews($id);
  961.             $app->render('news/read.twig', array(
  962.                 "title" => $news["0"]->head,
  963.                 "page" => "news_read",
  964.                 "user" => $user,
  965.                 "article" => $news,
  966.                 "commentcount" => $model->getNewsCommentAmount($id),
  967.                 "csrf" => $csrf,
  968.                 "comments" => $model->getNewsComments($id)
  969.             ));
  970.         } else {
  971.             $app->redirect("/");
  972.         }
  973.     });
  974.     $app->post('/checkNews', function () use ($app) {
  975.         global $user, $app, $model, $usession;
  976.         if (!$user["loggedin"])
  977.             die("Bitte logge dich ein.");
  978.  
  979.         if ($user["admin"] == "4" || $user["admin"] == "3") {
  980.             echo '<div class="alert alert-success">News veröffentlicht!</div>';
  981.             echo "<script>$('#submit').hide();</script>";
  982.             $model->addNews($usession, $_POST["title"], strip_tags($_POST["content"]), time());
  983.         }
  984.     });
  985.     $app->post('/previewNews', function () use ($app) {
  986.         global $user, $app, $model, $usession;
  987.         if (!$user["loggedin"])
  988.             die("Bitte logge dich ein.");
  989.  
  990.         if ($user["admin"] == "4" || $user["admin"] == "3") {
  991.             echo $model->showBBcodes($_POST["content"]) . "<hr>";
  992.         }
  993.     });
  994.     $app->post('/updateNews', function () use ($app) {
  995.         global $user, $app, $model, $usession;
  996.         if (!$user["loggedin"])
  997.             die("Bitte logge dich ein.");
  998.  
  999.         if ($user["admin"] == "4" || $user["admin"] == "3") {
  1000.             if ($model->existNews($_POST["id"])) {
  1001.                 echo '<div class="alert alert-success">News veröffentlicht!</div>';
  1002.                 $model->updateNews($_POST["title"], strip_tags($_POST["content"]), $_POST["id"]);
  1003.             } else {
  1004.                 echo '<div class="alert alert-success">Nichts manipulieren...</div>';
  1005.             }
  1006.         }
  1007.     });
  1008.     $app->post('/addComment', function () use ($app) {
  1009.         global $user, $app, $model, $usession, $csrfs;
  1010.         if (!$user["loggedin"])
  1011.             die("Bitte logge dich ein.");
  1012.  
  1013.         if ($model->existNews(strip_tags($_POST["id"]))) {
  1014.             if ($_SESSION[$csrfs] != $_POST["csrf"]) {
  1015.                 echo '<div class="alert alert-danger">Dein CSRF-Token ist ungültig! Bitte lade die Seite neu.</div>';
  1016.             } else {
  1017.                 if ($model->getUserLastCommentTime($user["id"]) > 5) {
  1018.                     if (strlen(strip_tags($_POST["content"])) < 16 || strlen(strip_tags($_POST["content"])) > 2048) {
  1019.                         echo '<div class="alert alert-danger">Dein Kommentar muss mind. 16 Zeichen enthalten, darf aber nicht länger als 2048 Zeichen sein. Du verwendest ' . strlen(strip_tags($_POST["content"])) . ' Zeichen.</div>';
  1020.                     } else {
  1021.                         echo '<script>location.reload();</script>';
  1022.                         $model->addComment($usession, strip_tags($_POST["content"]), time(), strip_tags($_POST["id"]));
  1023.                         echo '<meta http-equiv="refresh" content="0; URL=/news/read/' . strip_tags($_POST["id"]) . '">';
  1024.                     }
  1025.                 } else {
  1026.                     echo '<div class="alert alert-danger">Du kannst nur alle 5 Minuten ein Kommentar schreiben.</div>';
  1027.                 }
  1028.             }
  1029.         } else {
  1030.             echo '<div class="alert alert-danger">Nichts manipulieren...</div>';
  1031.         }
  1032.     });
  1033. });
  1034.  
  1035. $app->group('/account', function () use ($app, $model) {
  1036.     $app->get('/settings', function () use ($app) {
  1037.         getChecks();
  1038.         global $user, $app, $session, $model, $csrfs;
  1039.         if (!$user["loggedin"])
  1040.             $app->redirect("/");
  1041.  
  1042.         $csrf = $_SESSION[$csrfs] = $model->generateRandomString(64) . rand() . $model->generateRandomString();
  1043.         $app->render('account/settings.twig', array(
  1044.             "title" => "Einstellungen",
  1045.             "page" => "settings",
  1046.             "user" => $user,
  1047.             "csrf" => $csrf
  1048.         ));
  1049.     });
  1050.     $app->get('/login', function () use ($app) {
  1051.         getChecks();
  1052.         global $user, $app;
  1053.         if ($user["loggedin"])
  1054.             $app->redirect("/");
  1055.  
  1056.         $app->render('account/login.twig', array(
  1057.             "title" => "Login",
  1058.             "page" => "login",
  1059.             "user" => $user
  1060.         ));
  1061.     });
  1062.     $app->get('/register', function () use ($app) {
  1063.         getChecks();
  1064.         global $user, $app;
  1065.         if ($user["loggedin"])
  1066.             $app->redirect("/");
  1067.  
  1068.         $kc_o = new KeyCAPTCHA_CLASS();
  1069.  
  1070.         $app->render('account/register.twig', array(
  1071.             "title" => "Registrierung",
  1072.             "page" => "register",
  1073.             "user" => $user,
  1074.             "captcha" => $kc_o->render_js()
  1075.         ));
  1076.     });
  1077.     $app->get('/logout', function () use ($app) {
  1078.         getChecks();
  1079.         global $user, $app;
  1080.         if (!$user["loggedin"])
  1081.             $app->redirect("/");
  1082.  
  1083.         session_unset();
  1084.         session_destroy();
  1085.         $app->redirect("/");
  1086.     });
  1087.     $app->post('/checkLogin', function () use ($app) {
  1088.         global $user, $app, $model, $session, $faillogins;
  1089.         if ($user["loggedin"])
  1090.             die("Bereits eingeloggt. Bitte unterlasse manuelle Post-Requests.");
  1091.  
  1092.         if ($model->isIPCPBanned($model->getClientIP())) {
  1093.             echo '<div class="alert alert-danger">Du wurdest 15 Minuten wegen fehlerhaften Login-Versuchen gesperrt.</div>';
  1094.         } else {
  1095.             if ($model->existUser($_POST["username"])) {
  1096.                 $array = $model->getUserDataByName($_POST["username"]);
  1097.                 if ($model->getAccountDetail("cpban", $array->id) == 1 || $model->getAccountDetail("cpban", $array->id) > time()) {
  1098.                     $app->render('baninfo_clean.twig', array(
  1099.                         "title" => "Account gesperrt",
  1100.                         "page" => "pn",
  1101.                         "user" => $user,
  1102.                         "bangrund" => $model->getAccountDetail("cpban_grund", $array->id),
  1103.                         "dauer" => $model->getAccountDetail("cpban", $array->id),
  1104.                         "name" => $array->name
  1105.                     ));
  1106.                     echo '<script>$("#login").hide();</script>';
  1107.                     exit;
  1108.                 }
  1109.                 $salt = $array->salt;
  1110.                 $pass = $array->password;
  1111.                 $id = $array->id;
  1112.                 $tmppass = strtoupper(md5($salt . $_POST["passwort"])); //salt+klartextpw md5'en
  1113.                 if (strlen($_POST["passwort"]) <= 4 || str_replace(" ", "", $_POST["passwort"]) == "") {
  1114.                     echo '<div class="alert alert-danger">Du hast das Passwort vergessen oder es ist zu kurz.</div>';
  1115.                     exit;
  1116.                 }
  1117.                 if (strlen($_POST["passwort"]) > 23) {
  1118.                     echo '<div class="alert alert-danger">Das Passwort ist zu lang.</div>';
  1119.                     exit;
  1120.                 }
  1121.                 if ($tmppass == $pass) {
  1122.                     $_SESSION[$faillogins] = 0;
  1123.                     echo '<script>location.reload();</script>';
  1124.                     echo '<div class="alert alert-success">Du hast dich erfolgreich eingeloggt, ' . $array->name . '.</div>';
  1125.                     echo "<script>$('#submit').hide();</script>";
  1126.                     $_SESSION[$session] = $id;
  1127.                 } else {
  1128.                     $_SESSION[$faillogins] = $_SESSION[$faillogins] + 1;
  1129.                     if ($_SESSION[$faillogins] >= 3) {
  1130.                         $model->addCPBan($model->getClientIP(), 900);
  1131.                     }
  1132.                     $ip = $model->getClientIP();
  1133.                     $teile = explode(".", $ip);
  1134.                     $ip = $teile[0] . "." . $teile[1] . "." . $teile[2] . ".*";
  1135.                     $model->addNotification($id, 2, 'Ein User mit der IP <code>' . $ip . '</code> wollte sich in deinen Account einloggen.');
  1136.                     echo '<div class="alert alert-danger">Benutzername und/oder Passwort falsch.</div>';
  1137.                 }
  1138.             } else {
  1139.                 echo '<div class="alert alert-danger">Benutzername und/oder Passwort falsch.</div>';
  1140.             }
  1141.         }
  1142.     });
  1143.     $app->post('/setTeamspeak', function () use ($app) {
  1144.         global $user, $app, $model;
  1145.         $ts = TeamSpeak3::factory("serverquery://serveradmin:o8tmbXfht11fN5lLeitJ0lpxg@127.0.0.1:10011/?server_port=9987&nickname=Day-of-Infection");
  1146.         $method = $_POST["method"];
  1147.         if ($method == "add") {
  1148.             $props = array(
  1149.                 "client_description" => "Name: " . $user["name"]
  1150.             );
  1151.             $uid = strip_tags($_POST["uid"]);
  1152.             if ($model->isTSUIDInUsage($uid) > 0) {
  1153.                 echo '<br/><div class="alert alert-danger">Diese Eindeutige ID ist schon registriert.</div>';
  1154.                 exit;
  1155.             }
  1156.             Try {
  1157.                 $client = $ts->clientFindDb($uid, true);
  1158.             } catch (Exception $exx) {
  1159.                 echo '<br/><div class="alert alert-danger">Du musst auf dem TeamSpeak Server online sein.</div>';
  1160.                 exit;
  1161.             }
  1162.             if ($user["admin"] == "4") {
  1163.                 $ts->serverGroupClientAdd(15, $client[0]);
  1164.             }
  1165.             if ($user["admin"] == "3") {
  1166.                 $ts->serverGroupClientAdd(16, $client[0]);
  1167.             }
  1168.             if ($user["admin"] == "2") {
  1169.                 $ts->serverGroupClientAdd(12, $client[0]);
  1170.             }
  1171.             if ($user["admin"] == "1") {
  1172.                 $ts->serverGroupClientAdd(13, $client[0]);
  1173.             }
  1174.             if ($user["admin"] == "0") {
  1175.                 $ts->serverGroupClientAdd(7, $client[0]);
  1176.             }
  1177.             $ts->clientmodifydb($client, $props);
  1178.             $model->updateTeamspeak($uid, $user["id"]);
  1179.             echo '<br/><div class="alert alert-success">Du hast deinen Account erfolgreich mit dem TeamSpeak Server verknüpft.</div>';
  1180.         }
  1181.         if ($method == "remove") {
  1182.             $fehler = false;
  1183.             Try {
  1184.                 $props = array(
  1185.                     "client_description" => ""
  1186.                 );
  1187.  
  1188.                 $client = $ts->clientFindDb($user["ts3uid"], true);
  1189.                 foreach ($ts->serverGroupGetById(7)->clientList() as $clients) {
  1190.                     if ($clients["client_unique_identifier"] == $user["ts3uid"]) {
  1191.                         $ts->serverGroupClientDel(7, $client[0]);
  1192.                     }
  1193.                 }
  1194.                 foreach ($ts->serverGroupGetById(13)->clientList() as $clients) {
  1195.                     if ($clients["client_unique_identifier"] == $user["ts3uid"]) {
  1196.                         $ts->serverGroupClientDel(13, $client[0]);
  1197.                     }
  1198.                 }
  1199.                 foreach ($ts->serverGroupGetById(12)->clientList() as $clients) {
  1200.                     if ($clients["client_unique_identifier"] == $user["ts3uid"]) {
  1201.                         $ts->serverGroupClientDel(12, $client[0]);
  1202.                     }
  1203.                 }
  1204.                 foreach ($ts->serverGroupGetById(16)->clientList() as $clients) {
  1205.                     if ($clients["client_unique_identifier"] == $user["ts3uid"]) {
  1206.                         $ts->serverGroupClientDel(16, $client[0]);
  1207.                     }
  1208.                 }
  1209.                 foreach ($ts->serverGroupGetById(15)->clientList() as $clients) {
  1210.                     if ($clients["client_unique_identifier"] == $user["ts3uid"]) {
  1211.                         $ts->serverGroupClientDel(15, $client[0]);
  1212.                     }
  1213.                 }
  1214.             } catch (Exception $ex) {
  1215.                 echo '<br/><div class="alert alert-danger">Folgender Fehler ist aufgetreten: ' . $ex->getMessage() . '</div>';
  1216.                 exit;
  1217.             }
  1218.             if ($fehler == false) {
  1219.                 $ts->clientmodifydb($client[0], $props);
  1220.                 $model->updateTeamspeak("", $user["id"]);
  1221.                 echo '<br/><div class="alert alert-success">Die Rechte von der UID ' . $user["ts3uid"] . ' wurden entfernt.</div>';
  1222.             }
  1223.         }
  1224.     });
  1225.     $app->post('/saveSettings', function () use ($app) {
  1226.         global $user, $app, $model, $session, $csrfs, $usession;
  1227.         if (!$user["loggedin"])
  1228.             die('<div class="alert alert-danger">Du bist nicht (mehr) eingeloggt.</div>');
  1229.  
  1230.         $error = "";
  1231.         $profil_visible = strip_tags($_POST["visible"]);
  1232.         $getpns = strip_tags($_POST["pns"]);
  1233.         $newpw = strip_tags($_POST["newpw"]);
  1234.         $newpwwdh = strip_tags($_POST["newpwwdh"]);
  1235.  
  1236.         if ($_SESSION[$csrfs] != $_POST["csrf"]) {
  1237.             $error = $error . "<br/>&bull; Dein CSRF-Token ist ungültig! Bitte lade die Seite neu.";
  1238.         }
  1239.  
  1240.         if ($profil_visible > 1 || $profil_visible < 0) {
  1241.             $error = $error . "<br/>&bull; Ungültige Value";
  1242.         }
  1243.         if ($getpns > 1 || $getpns < 0) {
  1244.             $error = $error . "<br/>&bull; Ungültige Value";
  1245.         }
  1246.         if (isset($newpw) && strlen($newpw) >= 1) {
  1247.             if ($newpw != $newpwwdh) {
  1248.                 $error = $error . "<br/>&bull; Die angegebenen Passwörter sind nicht gleich";
  1249.             }
  1250.             if (strlen($newpw) < 4 || strlen($newpwwdh) > 16) {
  1251.                 $error = $error . "<br/>&bull; Das Passwort muss mind. 4 Zeichen und max. 16 Zeichen enthalten";
  1252.             }
  1253.         }
  1254.         if ($error == "") {
  1255.             $model->saveSettings($usession, $profil_visible, $getpns);
  1256.             echo '<div class="alert alert-success" id="sefa">Deine Einstellungen wurden gespeichert!</div>';
  1257.             echo '<script>$("#sefa").fadeOut(2500);</script>';
  1258.             if (isset($newpw) && strlen($newpw) >= 1) {
  1259.                 $model->setNewPW($user["id"], $newpw);
  1260.                 echo '<div class="alert alert-success">Dein neues Passwort lautet: <code>' . $newpw . '</code><br/>Du wurdest automatisch ausgeloggt.</div>';
  1261.                 session_unset();
  1262.                 session_destroy();
  1263.             }
  1264.         } else {
  1265.             echo '<div class="alert alert-danger"><strong>Folgende Fehler sind aufgetreten:</strong>' . $error . '</div>';
  1266.         }
  1267.     });
  1268.     $app->post('/checkRegister', function () use ($app) {
  1269.         global $user, $app, $model, $session;
  1270.         if ($user["loggedin"])
  1271.             die("Bereits eingeloggt. Bitte unterlasse manuelle Post-Requests.");
  1272.  
  1273.         $regfail = "";
  1274.         $username = strip_tags($_POST["username"]);
  1275.         $username = str_replace(" ", "", $username);
  1276.  
  1277.         $email = strip_tags($_POST["mail"]);
  1278.         $pass = strip_tags($_POST["passwort"]);
  1279.  
  1280.         if ($model->existUser($username)) {
  1281.             $regfail = $regfail . "<br/>&bull; Diesen Benutzer gibt es bereits";
  1282.         }
  1283.  
  1284.         if (!filter_var($email, FILTER_VALIDATE_EMAIL) === true) {
  1285.             $regfail = $regfail . "<br/>&bull; Die angegebene E-Mail ist ungültig";
  1286.         } else {
  1287.             if ($model->existMail($email)) {
  1288.                 $regfail = $regfail . "<br/>&bull; Die angegebene E-Mail wird schon verwendet";
  1289.             }
  1290.  
  1291.             $domain = explode("@", $email);
  1292.             $ch = curl_init();
  1293.             curl_setopt($ch, CURLOPT_URL, 'http://www.mogelmail.de/q/' . $domain[1]);
  1294.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1295.             curl_setopt($ch, CURLOPT_TIMEOUT, '3');
  1296.             $content = trim(curl_exec($ch));
  1297.             curl_close($ch);
  1298.             if ($content == "1") {
  1299.                 $regfail = $regfail . "<br/>&bull; Bitte verwende keine Trash-Mail";
  1300.             }
  1301.         }
  1302.         if (isset($username)) {
  1303.             if (strlen($username) < 4) {
  1304.                 $regfail = $regfail . "<br/>&bull; Dein Name muss mindestens 4 Zeichen enthalten";
  1305.             }
  1306.             if (strlen($username) > 23) {
  1307.                 $regfail = $regfail . "<br/>&bull; Bitte halte deinen Namen etwas kürzer";
  1308.             }
  1309.         } else {
  1310.             $regfail = $regfail . "<br/>&bull; Du musst einen Usernamen eingeben";
  1311.         }
  1312.         if (isset($pass)) {
  1313.             if (strlen($pass) < 6) {
  1314.                 $regfail = $regfail . "<br/>&bull; Dein Passwort muss mind. 6 Zeichen enthalten";
  1315.             }
  1316.             if (strlen($pass) > 23) {
  1317.                 $regfail = $regfail . "<br/>&bull; Bitte Passwort darf maximal 23 Zeichen enthalten";
  1318.             }
  1319.         } else {
  1320.             $regfail = $regfail . "<br/>&bull; Du musst ein Passwort eingeben";
  1321.         }
  1322.  
  1323.         $kc_o = new KeyCAPTCHA_CLASS();
  1324.         if (!$kc_o->check_result($_POST['capcode'])) {
  1325.             $regfail = $regfail . "<br/>&bull; Das angegebene Captcha ist falsch";
  1326.         }
  1327.  
  1328.         if ($regfail == "") {
  1329.             //die('<div class="alert alert-warning">Die Registrierung ist erst ab dem 10.06.16 ab 15 Uhr freigeschaltet.</div>');
  1330.             $model->addUser($username, $email, $pass);
  1331.             echo '<div class="alert alert-success"><i class="fa fa-check-circle-o" aria-hidden="true"></i> Willkommen auf Day of Infection, ' . $username . '.</div>';
  1332.             echo "<script>$('#submit').hide();</script>;";
  1333.         } else {
  1334.             echo '<div class="alert alert-danger">';
  1335.             echo '<strong>Folgende Fehler sind aufgetreten:</strong>' . $regfail;
  1336.             echo '</div>';
  1337.         }
  1338.     });
  1339. });
  1340.  
  1341. /* * ***************************************** RUN THE APP ****************************************************** */
  1342. function getChecks() {
  1343.     global $session, $model, $usession, $app, $user;
  1344.     if (isset($_SESSION[$session])) {
  1345.         if ($model->getAccountDetail("cpban", $usession) == 1 || $model->getAccountDetail("cpban", $usession) > time()) {
  1346.             $app->render('baninfo.twig', array(
  1347.                 "title" => "Account gesperrt",
  1348.                 "page" => "pn",
  1349.                 "user" => $user,
  1350.                 "bangrund" => $model->getAccountDetail("cpban_grund", $usession),
  1351.                 "dauer" => $model->getAccountDetail("cpban", $usession)
  1352.             ));
  1353.             session_unset();
  1354.             session_destroy();
  1355.             exit;
  1356.         }
  1357.     }
  1358. }
  1359.  
  1360. $app->notFound(function () {
  1361.     global $app;
  1362.     $app->redirect("/");
  1363. });
  1364. $app->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement