inc/error.php
defbfa55
 <?php
c208bd90
 /*
 This file belongs to the Webinterface of schokokeks.org Hosting
 
cf54502a
 Written 2008-2018 by schokokeks.org Hosting, namely
c208bd90
   Bernd Wurst <bernd@schokokeks.org>
   Hanno Böck <hanno@schokokeks.org>
 
 To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
 
2626dd47
 You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
c208bd90
 http://creativecommons.org/publicdomain/zero/1.0/
 
 Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
 */
defbfa55
 
af8c8976
 require_once("inc/security.php");
 
defbfa55
 function system_failure($reason)
 {
2626dd47
     input_error($reason);
     show_page();
     die();
defbfa55
 }
 
 
 function input_error($reason)
 {
2626dd47
     global $input_error;
     if (!isset($input_error)) {
         $input_error = array();
     }
     array_push($input_error, $reason);
defbfa55
 }
 
 function warning($msg)
 {
2626dd47
     if (!isset($_SESSION['warning'])) {
         $_SESSION['warning'] = array();
     }
     array_push($_SESSION['warning'], $msg);
     $backtrace = debug_backtrace();
     DEBUG('WARNING:<br>'.$backtrace[0]['file'].':'.$backtrace[0]['line'].': '.$msg);
defbfa55
 }
 
 function success_msg($msg)
 {
2626dd47
     if (!isset($_SESSION['success_msg'])) {
         $_SESSION['success_msg'] = array();
     }
     array_push($_SESSION['success_msg'], $msg);
defbfa55
 }
 
 
90ff5748
 function we_have_an_error()
 {
2626dd47
     global $input_error;
90ff5748
 
2626dd47
     if (isset($input_error)) {
         return (count($input_error) > 0);
     } else {
         return 0;
     }
90ff5748
 }
 
 
d73051da
 function get_messages()
defbfa55
 {
2626dd47
     $messages = '';
     global $input_error;
     if (isset($input_error)) {
         $messages .= '<div class="error">
defbfa55
     <h3>Fehler</h3>
     <p>Folgende Fehler wurden festgestellt: </p>
     <ul>
     ';
2626dd47
         foreach ($input_error as $error) {
             $messages .= '<li>'.nl2br(filter_input_general($error))."</li>\n";
         }
         $messages .= '</ul>
defbfa55
     </div>';
2626dd47
     }
     if (isset($_SESSION['warning'])) {
         $messages .= '<div class="error">
defbfa55
     <ul>
     ';
2626dd47
         foreach ($_SESSION['warning'] as $msg) {
             $messages .= '<li>'.nl2br(filter_input_general($msg))."</li>\n";
         }
         $messages .= '</ul>
defbfa55
     </div>';
2626dd47
         unset($_SESSION['warning']);
     }
     if (isset($_SESSION['success_msg'])) {
         $messages .= '<div class="success">
defbfa55
     <ul>
     ';
2626dd47
         foreach ($_SESSION['success_msg'] as $msg) {
             $messages .= '<li>'.nl2br(filter_input_general($msg))."</li>\n";
         }
         $messages .= '</ul>
defbfa55
     </div>';
2626dd47
         unset($_SESSION['success_msg']);
     }
     return $messages;
defbfa55
 }
 
2626dd47
 function show_messages()
d73051da
 {
2626dd47
     echo get_messages();
d73051da
 }
defbfa55
 
 function require_role($roles)
 {
2626dd47
     if (! is_array($roles)) {
         $roles = array($roles);
29c4531a
     }
2626dd47
     $allow = false;
     foreach ($roles as $role) {
         if ($role & $_SESSION['role']) {
             $allow = true;
         }
     }
     if (! $allow) {
         if ($_SESSION['role'] == ROLE_ANONYMOUS) {
             login_screen();
         } else {
             $backtrace = debug_backtrace();
             DEBUG($backtrace[0]['file'].':'.$backtrace[0]['line'].': Current user does not have any of the required roles: '.implode(",", $roles));
             login_screen("Diese Seite können Sie mit Ihren aktuellen Zugriffsrechten nicht benutzen, bitte melden Sie sich mit den benötigten Zugriffsrechten an!");
         }
29c4531a
     }
defbfa55
 }
 
 
2626dd47
 function login_screen($why = null)
defbfa55
 {
385d4b22
     $failed = count_failed_logins();
     if ($failed > 5) {
         global $title;
         $title = '';
         system_failure("Zu viele fehlgeschlagenen Login-Versuche! Bitte warten Sie einige Minuten bis zum nächsten Versuch!");
     }
2626dd47
     if (! $why) {
         if (isset($_COOKIE['CLIENTCERT_AUTOLOGIN']) && $_COOKIE['CLIENTCERT_AUTOLOGIN'] == '1') {
             redirect("/certlogin/index.php?destination=".urlencode($_SERVER['REQUEST_URI']));
         }
     }
     require_once('inc/theme.php');
     if ($why) {
         warning($why);
     }
     show_page('login');
     die();
defbfa55
 }