Example #1
0
 public function rules()
 {
     return [[['name', 'domain_name'], 'filter', 'filter' => 'trim'], [['name'], FqdnValueValidator::className()], [['ip'], 'filter', 'filter' => function ($value) {
         return StringHelper::explode($value, ',', true, true);
     }, 'skipOnArray' => true], [['ip'], 'each', 'rule' => ['ip']], [['ip'], function ($attribute, $params) {
         if (!StringHelper::endsWith($this->name, $this->domain_name)) {
             $this->addError($attribute, Yii::t('hipanel:domain', 'To assign the IP, NS must be a child from main domain'));
         }
     }]];
 }
Example #2
0
 public function rules()
 {
     return [[['id', 'service_id', 'server_id'], 'integer'], [['name', 'domain', 'idn', 'type', 'fqdn', 'idn_fqdn', 'value', 'service', 'server'], 'safe'], [['is_system'], 'boolean'], [['ttl'], 'integer', 'min' => 60, 'max' => 86400, 'on' => ['create', 'update']], [['name'], DomainPartValidator::className(), 'when' => $this->buildRuleWhen(['srv', 'txt', 'cname'], true), 'whenClient' => $this->buildRuleWhenClient(['srv', 'txt', 'cname'], true), 'on' => ['create', 'update', 'delete']], [['name'], DomainPartValidator::className(), 'extended' => true, 'when' => $this->buildRuleWhen(['srv', 'txt', 'cname']), 'whenClient' => $this->buildRuleWhenClient(['srv', 'txt', 'cname']), 'on' => ['create', 'update', 'delete']], [['type'], 'in', 'range' => array_keys($this->getTypes()), 'on' => ['create', 'update']], [['value'], 'ip', 'ipv6' => false, 'when' => $this->buildRuleWhen('a'), 'whenClient' => $this->buildRuleWhenClient('a'), 'on' => ['create', 'update'], 'message' => Yii::t('hipanel:dns', '{attribute} must be a valid IP address.'), 'ipv6NotAllowed' => Yii::t('hipanel:dns', '{attribute} must not be an IPv6 address.')], [['value'], 'ip', 'ipv4' => false, 'when' => $this->buildRuleWhen('aaaa'), 'whenClient' => $this->buildRuleWhenClient('aaaa'), 'on' => ['create', 'update'], 'message' => Yii::t('hipanel:dns', '{attribute} must be a valid IP address.'), 'ipv4NotAllowed' => Yii::t('hipanel:dns', '{attribute} must be a valid IPv6 address.')], [['value'], 'email', 'when' => $this->buildRuleWhen('soa'), 'whenClient' => $this->buildRuleWhenClient('soa'), 'on' => ['create', 'update'], 'message' => Yii::t('hipanel:dns', '{attribute} is not a valid email address.')], [['value'], TxtValueValidator::className(), 'when' => $this->buildRuleWhen('txt'), 'whenClient' => $this->buildRuleWhenClient('txt'), 'on' => ['create', 'update']], [['value'], 'string', 'max' => 255, 'when' => $this->buildRuleWhen('txt'), 'whenClient' => $this->buildRuleWhenClient('txt'), 'on' => ['create', 'update']], [['value'], MxValueValidator::className(), 'when' => $this->buildRuleWhen('mx'), 'whenClient' => $this->buildRuleWhenClient('mx'), 'on' => ['create', 'update']], [['value'], FqdnValueValidator::className(), 'trimTrailingDot' => true, 'when' => $this->buildRuleWhen(['ns', 'cname']), 'whenClient' => $this->buildRuleWhenClient(['ns', 'cname']), 'on' => ['create', 'update']], [['value'], 'match', 'pattern' => '/[a-z]/i', 'message' => Yii::t('hipanel:dns', '{attribute} is not a valid domain name'), 'when' => $this->buildRuleWhen(['ns', 'mx', 'cname']), 'whenClient' => $this->buildRuleWhenClient(['ns', 'mx', 'cname']), 'on' => ['create', 'update']], [['value'], SrvValueValidator::className(), 'when' => $this->buildRuleWhen('srv'), 'whenClient' => $this->buildRuleWhenClient('srv'), 'on' => ['create', 'update'], 'message' => Yii::t('hipanel:dns', '{attribute} is invalid.')], [['no'], 'integer', 'on' => ['create', 'update']], [['value', 'type', 'ttl'], 'required', 'on' => ['create', 'update']], [['id'], 'required', 'on' => ['update', 'delete']], [['hdomain_id'], 'required', 'on' => ['create', 'update', 'delete']], [['status'], 'default', 'value' => 'deleted', 'when' => function ($model) {
         return $model->scenario === 'delete';
     }]];
 }
 /**
  * {@inheritdoc}
  */
 public function validateAttribute($model, $attribute)
 {
     $this->extractPriority($model, $attribute);
     parent::validateAttribute($model, $attribute);
 }