Beispiel #1
0
 /**
 checks access rules
 */
 private function checkAccessRules($rules, $action)
 {
     foreach ($rules as $rule) {
         if ($rule[0] == 'deny') {
             $result = false;
         } elseif ($rule[0] == 'allow') {
             $result = true;
         } else {
             throw new MVCException('Unknown rule: ' . $rule[0]);
         }
         if (!isset($rule[self::USERS]) || $rule[self::USERS] == '*' || $rule[self::USERS] == '@' && Auth::isLoggedin()) {
             if (!isset($rule['actions']) || in_array($action, $rule['actions'])) {
                 return $result;
             }
         }
     }
     return false;
 }
Beispiel #2
0
 public function handleException($route, \Exception $e)
 {
     $reg = Registry::getInstance();
     $t = $reg->twig->loadTemplate('error.tpl');
     $c = array();
     $c['route'] = $route;
     $c['type'] = get_class($e);
     $c['msg'] = $e->getMessage();
     $trace = $e->getTrace();
     foreach ($trace as $key => $entry) {
         $file = file_get_contents($entry['file']);
         $lines = explode("\n", $file);
         $start = $entry['line'] - 5;
         $end = $entry['line'] + 5;
         $trace[$key]['lines'] = array();
         if ($start < 0) {
             $start = 0;
         }
         if ($end > count($lines)) {
             $end = count($lines);
         }
         for ($i = $start; $i < $end; ++$i) {
             $trace[$key]['lines'][$i] = str_replace(array("\t", ' '), array('&nbsp;&nbsp;&nbsp;', '&nbsp;'), $lines[$i]);
         }
     }
     $c['trace'] = $trace;
     $out = $t->render($c);
     if (Auth::isLoggedin()) {
         $userid = Auth::$profile->id;
     } else {
         $userid = 0;
     }
     if (!DEBUG) {
         DB::query("INSERT into errorlog(time,message,user_id) values(now(),'" . DB::escape($out) . "',{$userid})");
         if (isset($reg->admin_email)) {
             $ms = new MailService('smtp.gmail.com', 465, '*****@*****.**', 'edderkop');
             $ms->send_mail($reg->admin_email, '*****@*****.**', 'Error occured', '', $out);
         }
     }
     echo $out;
 }