private function buildHtAccessString() { /* build htaccess header string*/ $htaccessStr = <<<EOL # index file can be index.php, home.php, default.php etc. # Rewrite engine RewriteEngine On # condition with escaping special chars RewriteCond \$1 !^(index\\.php|robots\\.txt|favicon\\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\$ claimdatastorage/index.php/\$1 [L,QSA]\t Order allow,deny EOL; /*get all ip address*/ $allIpAddresses = Ip::model()->findAll(); foreach ($allIpAddresses as $currentIpAddress) { $tempIpaddress = $currentIpAddress->ip_address; /*append ip addreeeses*/ $htaccessStr = $htaccessStr . <<<EOL Allow from {$tempIpaddress} EOL; } /*build htaccess footer*/ $htaccessStr = $htaccessStr . <<<EOL Deny from all EOL; return $htaccessStr; }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { $criteria = new CDbCriteria(); $criteria->compare('ip_address', $_SERVER['REMOTE_ADDR']); $inRecord = Ip::model()->exists($criteria); if (!$inRecord) { throw new CHttpException(404, 'Page doesnt exist'); } else { $this->redirect(array('accounts/index')); } }
protected function preFilter($filterChain) { $verdict = true; $criteriaSettings = new CDbCriteria(); $criteriaSettings->compare("setting_key", "enabled"); $criteriaSettings->compare("setting_value", "true"); $ipBlockFeatureisEnabled = Settings::model()->exists($criteriaSettings); $ipAddress = Yii::app()->request->getUserHostAddress(); $criteria = new CDbCriteria(); $criteria->compare("ip_address", $ipAddress); $ipExists = Ip::model()->exists($criteria); if (!$ipExists && $ipBlockFeatureisEnabled) { throw new CHttpException(403, "You are unauthorized to access this site"); $verdict = false; } return $verdict; }
/** * 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 Ip the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Ip::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }