예제 #1
0
 public function set_blacklist()
 {
     $ip = Net::get_user_ip();
     $current_time = time();
     $node = $this->xml->xpath('/users/blacklist[@ip="' . utf8_encode($ip) . '"]');
     // IP dosen't exist
     if (empty($node)) {
         if (count($this->xml->users->blacklist) >= BLACKLIST_SAVED_REQUESTS) {
             unset($this->xml->users->blacklist[0]);
         }
         // Add the table
         $node = $this->xml->addChild('blacklist', '');
         // Add the key
         $node->addAttribute('ip', $ip);
         // Add the registers
         $node->addChild('date', $current_time);
         $node->addChild('fail_count', 1);
         error_log('Nibbleblog: Blacklist - New IP added - ' . $ip);
     } else {
         $date = $node[0]->getChild('date');
         $fail_count = $node[0]->getChild('fail_count');
         // The IP expired, so renewed
         if ($current_time > $date + BLACKLIST_TIME * 60) {
             $node[0]->setChild('date', $current_time);
             $node[0]->setChild('fail_count', 1);
             error_log('Nibbleblog: Blacklist - IP renewed because is expired - ' . $ip);
         } else {
             $fail_count += 1;
             $node[0]->setChild('fail_count', $fail_count);
             error_log('Nibbleblog: Blacklist - IP fail count(' . $fail_count . ') - ' . $ip);
         }
     }
     // Save the database
     return $this->savetofile();
 }
예제 #2
0
 public function add($category, $send_email, $args = array())
 {
     global $_LANG;
     if (count($this->xml->notification) >= NOTIFICATIONS_AMOUNT) {
         unset($this->xml->notification[0]);
     }
     // Email
     if ($send_email) {
         if ($category == 'session_fail') {
             // Subject
             $subject = $_LANG['LOGIN_FAILED_ATTEMPT'];
             // Message
             $message = Text::replace_assoc(array('{{BLOG_NAME}}' => $this->settings['name'], '{{USERNAME}}' => $args['username'], '{{PASSWORD}}' => $args['password'], '{{IP}}' => Net::get_user_ip()), $_LANG['EMAIL_NOTIFICATION_FAIL_LOGIN']);
         } elseif ($category == 'session_start') {
             // Subject
             $subject = $_LANG['NEW_SESSION_STARTED'];
             // Message
             $message = Text::replace_assoc(array('{{BLOG_NAME}}' => $this->settings['name'], '{{USERNAME}}' => $args['username'], '{{IP}}' => Net::get_user_ip()), $_LANG['EMAIL_NOTIFICATION_SESSION_STARTED']);
         } elseif ($category == 'comment') {
             // Subject
             $subject = $_LANG['YOU_HAVE_A_NEW_COMMENT'];
             // Message
             $message = Text::replace_assoc(array('{{BLOG_NAME}}' => $this->settings['name'], '{{COMMENT}}' => $args['comment'], '{{AUTHOR_NAME}}' => $args['author_name'], '{{AUTHOR_EMAIL}}' => $args['author_email'], '{{IP}}' => Net::get_user_ip()), $_LANG['EMAIL_NOTIFICATION_NEW_COMMENT']);
         }
         $sent = Email::send(array('from' => $this->settings['notification_email_from'], 'to' => $this->settings['notification_email_to'], 'subject' => $subject, 'message' => $message));
     } else {
         $sent = false;
     }
     // Encrypt the user IP
     include FILE_KEYS;
     $user_ip = Crypt::encrypt(Net::get_user_ip(), $_KEYS[0]);
     // Save the notification
     $node = $this->xml->addChild('notification');
     $node->addAttribute('category', $category);
     $node->addAttribute('mail', $sent);
     $node->addAttribute('ip', $user_ip);
     $node->addAttribute('date', Date::unixstamp());
     $this->savetofile();
     return true;
 }