server_ip_add not working by API

Discussion in 'ISPConfig 3 Priority Support' started by WHO, Dec 14, 2017.

  1. WHO

    WHO New Member HowtoForge Supporter

    Always getting "ip_error_wrong" (IP is correct).
    Reason: $_POST['ip_type'] is empty (***) , but it is in the $params array

    function check_server_ip($field_name, $field_value, $validator) {
    if($_POST['ip_type'] == 'IPv4') {
    if(!filter_var($field_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    return $this->get_error($validator['errmsg']);
    }
    } elseif ($_POST['ip_type'] == 'IPv6') {
    if(!filter_var($field_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
    return $this->get_error($validator['errmsg']);
    }
    } else return $this->get_error($validator['errmsg']); (***)
    }

    Is it a bug or has to be done something special, in the api call ?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

  3. WHO

    WHO New Member HowtoForge Supporter

  4. florian030

    florian030 ISPConfig Developer ISPConfig Developer

    As a quick workaround, you can change function check_server_ip in interface/lib/classes/validate_server.inc.php to:
    Code:
    function check_server_ip($field_name, $field_value, $validator) {
      if(isset($_POST)) {
        if($_POST['ip_type'] == 'IPv4') {
          if(!filter_var($field_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4, FILTER_FLAG_IPV6)) {
            return $this->get_error($validator['errmsg']);
          }
        } elseif ($_POST['ip_type'] == 'IPv6') {
          if(!filter_var($field_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
            return $this->get_error($validator['errmsg']);
          }
        }
      } else {
        if(!filter_var($field_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && !filter_var($field_value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
          return $this->get_error($validator['errmsg']);
      }
    }
    
    This will not run different validators for the given ip. it just checks, if the ip is valid or not
     
    till likes this.
  5. florian030

    florian030 ISPConfig Developer ISPConfig Developer

Share This Page