Ejemplo n.º 1
0
 public function actionUpdate($new = false)
 {
     $model = $new === true ? new BannedIPModel() : BannedIPModel::model()->findByPk($_GET['id']);
     if (isset($model)) {
         $this->pageName = Yii::t('app', 'BANNED_IP');
         $this->breadcrumbs = array($this->pageName => Yii::app()->createUrl('admin/core/security'), $new === true ? Yii::t('app', 'CREATE', 1) : Yii::t('app', 'UPDATE', 1));
         if (isset($_POST['BannedIPModel'])) {
             $model->attributes = $_POST['BannedIPModel'];
             if ($model->validate()) {
                 $model->save();
                 $this->redirect(array('banlist'));
             }
         }
         $this->render('update', array('model' => $model));
     } else {
         throw new CHttpException(404);
     }
 }
Ejemplo n.º 2
0
 protected function verify_ip_ban()
 {
     $addresses = BannedIPModel::model()->cache(Yii::app()->controller->cacheTime)->findAll();
     $btime = BannedIPModel::bannedTime();
     $user_ipaddress = $this->userIP . '.';
     foreach ($addresses as $banned) {
         if (strpos($banned->ip_address, '*') === false and $banned->ip_address[strlen($banned->ip_address) - 1] != '.') {
             $banned->ip_address .= '.';
         }
         $banned_ip_regex = str_replace('\\*', '(.*)', preg_quote($banned->ip_address, '#'));
         if (preg_match('#^' . $banned_ip_regex . '#U', $user_ipaddress)) {
             if (time() < $banned->timetime || $banned->time == 0) {
                 $this->params = array('ip' => $this->userIP, 'reason' => $banned->reason, 'banned_time' => $btime[$banned->time], 'left_time' => CMS::purchased_time($banned->timetime));
                 return true;
             } else {
                 return false;
             }
         }
     }
     return false;
 }