public function actionDeleteIp($ip_address)
 {
     $model = Ipaddress::model()->findByAttributes(array('ip_address' => $ip_address));
     if ($model) {
         $model->delete();
     } else {
         throw new CHttpException(404, "Can't find IP Address in the database");
     }
 }
 /**
  * Generates temporary file that has the new htaccess configuration
  * @return string Returns path of generated file containing the htaccess configuration
  */
 public function generateFile()
 {
     $rowTemplate = " allow from %s";
     $generatedRowsArr = array();
     $generatedRowsStr = '';
     $generatedHtAccessConfStr = '';
     Yii::trace('retrieving all ip address', 'dev_trace');
     $allIpAddressesMdls = Ipaddress::model()->findAll();
     foreach ($allIpAddressesMdls as $currentIpAddressMdl) {
         $generatedRowsArr[] = sprintf($rowTemplate, $currentIpAddressMdl->ip_address);
     }
     $generatedRowsStr = implode(PHP_EOL, $generatedRowsArr);
     Yii::trace('generating htaccess configuration string', 'dev_trace');
     $generatedHtAccessConfStr = sprintf($this->getHtaccessTemplate(), $generatedRowsStr);
     Yii::trace('creating and writing the configuration string to temporary file', 'dev_trace');
     $tempFileLoc = tempnam(sys_get_temp_dir(), 'htaccess');
     file_put_contents($tempFileLoc, $generatedHtAccessConfStr);
     Yii::trace('return generated temporary file', 'dev_trace');
     return $tempFileLoc;
 }
 public function actionAllow($ip)
 {
     $model = Ipaddress::model()->findByAttributes(array('ip_address' => $ip));
     if ($model) {
         $model->status = Ipaddress::IP_ADDRESS_STATUS_WHITELIST;
         if ($model->update()) {
             Yii::app()->user->setFlash("success", "IP Address {$ip} is now allowed");
         } else {
             Yii::app()->user->setFlash("error", CHtml::errorSummary($model));
         }
         $this->redirect($this->createAbsoluteUrl("site/index"));
     } else {
         throw new CHttpException(404, "Sorry ip address {$ip} doesn't exists");
     }
 }