// Code generated from ace.jar fields *.json files // DO NOT EDIT. package unifi import ( "context" "encoding/json" "fmt" ) // just to fix compile issues with the import var ( _ context.Context _ fmt.Formatter _ json.Marshaler ) type PortForward struct { ID string `json:"_id,omitempty"` SiteID string `json:"site_id,omitempty"` Hidden bool `json:"attr_hidden,omitempty"` HiddenID string `json:"attr_hidden_id,omitempty"` NoDelete bool `json:"attr_no_delete,omitempty"` NoEdit bool `json:"attr_no_edit,omitempty"` DestinationIP string `json:"destination_ip,omitempty"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^any$ DestinationIPs []PortForwardDestinationIPs `json:"destination_ips,omitempty"` DstPort string `json:"dst_port,omitempty"` // (([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])|([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])-([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5]))+(,([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])|,([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])-([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])){0,14} Enabled bool `json:"enabled"` Fwd string `json:"fwd,omitempty"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ FwdPort string `json:"fwd_port,omitempty"` // (([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])|([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])-([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5]))+(,([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])|,([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])-([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])){0,14} Log bool `json:"log"` Name string `json:"name,omitempty"` // .{1,128} PfwdInterface string `json:"pfwd_interface,omitempty"` // wan|wan2|both|all Proto string `json:"proto,omitempty"` // tcp_udp|tcp|udp Src string `json:"src,omitempty"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])-(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/([0-9]|[1-2][0-9]|3[0-2])$|^!(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^!(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])-(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^!(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/([0-9]|[1-2][0-9]|3[0-2])$|^any$ SrcFirewallGroupID string `json:"src_firewall_group_id"` SrcLimitingEnabled bool `json:"src_limiting_enabled"` SrcLimitingType string `json:"src_limiting_type,omitempty"` // ip|firewall_group } func (dst *PortForward) UnmarshalJSON(b []byte) error { type Alias PortForward aux := &struct { *Alias }{ Alias: (*Alias)(dst), } err := json.Unmarshal(b, &aux) if err != nil { return fmt.Errorf("unable to unmarshal alias: %w", err) } return nil } type PortForwardDestinationIPs struct { DestinationIP string `json:"destination_ip,omitempty"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^any$ Interface string `json:"interface,omitempty"` // wan|wan2 } func (dst *PortForwardDestinationIPs) UnmarshalJSON(b []byte) error { type Alias PortForwardDestinationIPs aux := &struct { *Alias }{ Alias: (*Alias)(dst), } err := json.Unmarshal(b, &aux) if err != nil { return fmt.Errorf("unable to unmarshal alias: %w", err) } return nil } func (c *Client) listPortForward(ctx context.Context, site string) ([]PortForward, error) { var respBody struct { Meta meta `json:"meta"` Data []PortForward `json:"data"` } err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portforward", site), nil, &respBody) if err != nil { return nil, err } return respBody.Data, nil } func (c *Client) getPortForward(ctx context.Context, site, id string) (*PortForward, error) { var respBody struct { Meta meta `json:"meta"` Data []PortForward `json:"data"` } err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portforward/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { return nil, &NotFoundError{} } d := respBody.Data[0] return &d, nil } func (c *Client) deletePortForward(ctx context.Context, site, id string) error { err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/portforward/%s", site, id), struct{}{}, nil) if err != nil { return err } return nil } func (c *Client) createPortForward(ctx context.Context, site string, d *PortForward) (*PortForward, error) { var respBody struct { Meta meta `json:"meta"` Data []PortForward `json:"data"` } err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/portforward", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { return nil, &NotFoundError{} } new := respBody.Data[0] return &new, nil } func (c *Client) updatePortForward(ctx context.Context, site string, d *PortForward) (*PortForward, error) { var respBody struct { Meta meta `json:"meta"` Data []PortForward `json:"data"` } err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/portforward/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { return nil, &NotFoundError{} } new := respBody.Data[0] return &new, nil }