/** * Finds the Domain model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Domain the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Domain::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function IPCheck($domain) { // lookup NS records $dns = \dns_get_record($domain, DNS_A); //grab domain id $domain_id = \app\models\Domain::findOne(['domain' => $domain])->domain_id; // retrieve last stored records $prev_record = (new \yii\db\Query())->select(['record_value'])->from(['domain_record'])->where(['domain_id' => $domain_id, 'record_type' => 'IP'])->all(); $prev = []; foreach ($prev_record as $re) { $prev[] = $re['record_value']; } // prepare dns records array $record = []; foreach ($dns as $ns) { $record[] = $ns['ip']; } //detect record differences $diff = array_diff($record, $prev); if (!empty($diff)) { $q = new \app\models\MailQueue(); $q->domain_id = $domain_id; $q->message = ''; $q->save(); } // clear old record \app\models\DomainRecord::deleteAll(['domain_id' => $domain_id, 'record_type' => 'IP']); // Insert new records foreach ($record as $key => $value) { $model = new \app\models\DomainRecord(); $model->domain_id = $domain_id; $model->record_type = 'IP'; $model->record_value = $value; $model->last_checked = new \yii\db\Expression('now()'); $model->save(); } }