/**
  * Utility method that deletes selected failures
  */
 private function __delete()
 {
     if (isset($_POST['ip']) && is_array($_POST['ip'])) {
         try {
             foreach ($_POST['ip'] as $ip => $value) {
                 ABF::instance()->unregisterFailure($ip);
             }
             $this->pageAlert(__('Failures remove successfuly'), Alert::SUCCESS);
         } catch (Exception $e) {
             $this->pageAlert(__('Error') . ': ' . $e->getMessage(), Alert::ERROR);
         }
     }
 }
Пример #2
0
 private function __unban($hash)
 {
     ABF::instance()->unregisterFailure($hash);
 }
 /**
  * Quick utility function to make a input field+label
  * @param string $settingName
  * @param string $textKey
  */
 public static function generateField($settingName, $textKey, $hasErrors, $errors, $type = 'text')
 {
     $inputText = ABF::instance()->getConfigVal($settingName);
     $inputAttr = array();
     switch ($type) {
         case 'checkbox':
             if ($inputText == 'on') {
                 $inputAttr['checked'] = 'checked';
             }
             $inputText = '';
             break;
     }
     // create the label and the input field
     $label = Widget::Label();
     $label->setAttribute('class', 'column');
     $input = Widget::Input('settings[' . ABF::SETTING_GROUP . '][' . $settingName . ']', (string) $inputText, $type, $inputAttr);
     // set the input into the label
     if ($type == 'checkbox') {
         // put input first
         $label->setValue($input->generate() . ' ' . __($textKey));
     } else {
         $label->setValue(__($textKey) . ' ' . $input->generate());
     }
     // error management
     if ($hasErrors && isset($errors[$settingName])) {
         $label = Widget::Error($label, $errors[$settingName]);
     }
     return $label;
 }
 /**
  * Delegate handle that saves the preferences
  * Saves settings and cleans the database acconding to the new settings
  * @param array $context
  */
 public function save(&$context)
 {
     ABF::instance()->setConfigVal($context, $this->errors, ABF::SETTING_LENGTH, false);
     ABF::instance()->setConfigVal($context, $this->errors, ABF::SETTING_FAILED_COUNT, false);
     ABF::instance()->setConfigVal($context, $this->errors, ABF::SETTING_GL_DURATION, false);
     ABF::instance()->setConfigVal($context, $this->errors, ABF::SETTING_GL_THRESHOLD, true);
     ABF::instance()->setConfigVal($context, $this->errors, ABF::SETTING_AUTO_UNBAN, false, 'checkbox');
     ABF::instance()->setConfigVal($context, $this->errors, ABF::SETTING_RESTRICT_ACCESS, true, 'checkbox');
     if (!$this->hasErrors()) {
         // clean old entry after save, since this may affects some banned IP
         ABF::instance()->removeExpiredEntries();
     }
 }