Ejemplo n.º 1
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return FingerprintBan the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = FingerprintBan::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 2
0
 public function actionSetFingerprintBad()
 {
     if (empty($_POST)) {
         $this->redirect(Yii::app()->request->urlReferrer);
     }
     $fb = new FingerprintBan();
     $fb->attributes = $_POST['FingerprintBan'];
     if (isset($_POST['delete'])) {
         $cnt = FingerprintBan::model()->deleteAllByAttributes(array('type' => $fb->type, 'value' => $fb->value));
         if ($cnt) {
             Yii::app()->user->setFlash('success', Yii::t('test', 'Удалена {n} запись| Удалено {n} записи | Удалено {n} записей', $cnt));
         } else {
             Yii::app()->user->setFlash('error', "Подходящих записей не найдено");
         }
         $this->redirect(Yii::app()->request->urlReferrer);
     }
     $fb->time_start = time();
     if (isset($_POST['ban'])) {
         $fb->status_bad = Anketa::BAD_STATUS_BAN;
     } else {
         if (isset($_POST['clone'])) {
             $fb->status_bad = Anketa::BAD_STATUS_CLONE;
         } else {
             die('NO VALID STATUS');
         }
     }
     if ($fb->save()) {
         $txt = $fb->status_bad == Anketa::BAD_STATUS_BAN ? ' Бан ' : ' Клон ';
         $txt .= $fb->isNewRecord ? ' добавлен ' : ' обновлен ';
         Yii::app()->user->setFlash('success', $txt);
     } else {
         $txt = '';
         foreach ($fb->getErrors() as $error) {
             $txt .= print_r($error, true) . '<br>';
         }
         Yii::app()->user->setFlash('error', $txt);
     }
     $this->redirect(Yii::app()->request->urlReferrer);
 }
Ejemplo n.º 3
0
 public function checkClone()
 {
     if ($this->getAccountType() == Anketa::ACCOUNT_PREMIUM) {
         return;
     }
     // премиум(?)
     if ($this->status_bad) {
         return;
     }
     // уже клон/бан или снятый клон/бан
     static $wasHere = 0;
     if ($this->id == Yii::app()->user->id) {
         Yii::log($this->id . ' fp=' . Yii::app()->user->getState('AnketaFingerprint') . ' | ' . $_SERVER['REQUEST_URI'], CLogger::LEVEL_INFO, 'checkClone');
     }
     $status_bad = self::BAD_STATUS_NONE;
     foreach ($this->findClones() as $clone) {
         /** @var $clone Anketa */
         if ($this->first_visit <= $clone->first_visit) {
             // если анкета зарегистрирована раньше клона
             continue;
         }
         if ($clone->status_bad == self::BAD_STATUS_BAN) {
             $status_bad = self::BAD_STATUS_BAN;
         } else {
             $status_bad = self::BAD_STATUS_CLONE;
         }
         Yii::log('bad_status ' . $status_bad . ' ' . $this->id . ' <- ' . $clone->id, CLogger::LEVEL_INFO, 'ban');
     }
     if ($status_bad == self::BAD_STATUS_NONE) {
         if ($this->findEtagClones()) {
             foreach ($this->findEtagClones() as $clone) {
                 /** @var $clone Anketa */
                 if ($this->first_visit <= $clone->first_visit) {
                     // если анкета зарегистрирована раньше клона
                     continue;
                 }
                 if ($clone->status_bad == self::BAD_STATUS_BAN) {
                     $status_bad = self::BAD_STATUS_BAN;
                 } else {
                     $status_bad = self::BAD_STATUS_CLONE;
                 }
                 Yii::log('bad_status ' . $status_bad . ' ' . $this->id . ' <- Etag ' . $clone->id, CLogger::LEVEL_INFO, 'ban');
             }
         }
     }
     if ($status_bad == self::BAD_STATUS_NONE) {
         if ($this->id == Yii::app()->user->id) {
             $attributes = array();
             $attributes[] = array('type' => FingerprintBan::TYPE_IP, 'value' => $_SERVER['REMOTE_ADDR']);
             if (Yii::app()->user->getState('FingerprintChecked', 0) === false) {
                 $wasHere++;
             }
             if ($fp = Yii::app()->user->getState('AnketaFingerprint')) {
                 if ($fp = AnketaFingerprint::model()->findByPk($fp)) {
                     // бан по fingerprints
                     foreach (FingerprintBan::$types as $k => $v) {
                         $attributes[] = array('type' => $v, 'value' => md5($fp->{$k}));
                     }
                 }
             }
             foreach ($attributes as $k => $v) {
                 if ($fb = FingerprintBan::model()->findByAttributes($v)) {
                     $status_bad = $fb->status_bad;
                     break;
                 }
             }
             if ($status_bad != self::BAD_STATUS_NONE) {
                 Yii::log('bad_status ' . $status_bad . ' ' . $this->id . ' <- ' . FingerprintBan::$typesText[$fb->type] . ' ' . $fb->value . ' ', CLogger::LEVEL_INFO, 'ban');
             }
             if ($fp || !$wasHere) {
                 Yii::app()->user->setState('FingerprintChecked', 1);
             } else {
                 Yii::app()->user->setState('FingerprintChecked', false);
             }
         }
     }
     // За клонов до введения оплаты не блокируем.
     if ($status_bad == self::BAD_STATUS_CLONE) {
         $status_bad = self::BAD_STATUS_NONE;
     }
     // авторазбан при входе
     if ($status_bad != self::BAD_STATUS_NONE) {
         if ($this->totalPaid > 0) {
             $status_bad = self::BAD_STATUS_PAID;
         }
     }
     $this->setBad($status_bad);
     if ($status_bad & 1) {
         $this->trialReset();
     }
 }