Compare commits

..

21 Commits

Author SHA1 Message Date
f85fe28c53 Merge branch '2-create-firewall-zone-api' 2025-04-13 15:36:23 +02:00
82702848f9 fix 2025-04-13 15:35:58 +02:00
c52743effa Merge branch '2-create-firewall-zone-api' 2025-04-13 15:26:49 +02:00
b079790183 reverse test 2025-04-13 15:26:35 +02:00
bae6a964eb Merge branch '2-create-firewall-zone-api' 2025-04-13 15:20:31 +02:00
bab50ebfc4 Unifi API v2 2025-04-13 15:20:13 +02:00
8035772f71 Merge branch '2-create-firewall-zone-api' 2025-04-13 13:25:26 +02:00
92ec48f4e7 fix 2025-04-13 13:25:14 +02:00
6f78447552 Merge pull request #5 from vegardengen/2-create-firewall-zone-api
fix
2025-04-13 13:20:43 +02:00
898bd842fc fix 2025-04-13 13:19:42 +02:00
4786c4dd6a Merge pull request #4 from vegardengen/2-create-firewall-zone-api
fixes
2025-04-13 12:50:24 +02:00
a37a5c45c3 fixes 2025-04-13 12:49:28 +02:00
27d358911a Merge pull request #3 from vegardengen/2-create-firewall-zone-api
Add minimal firewall zone API
2025-04-13 12:20:59 +02:00
ab3b625a72 Add minimal firewall zone API 2025-04-13 12:14:11 +02:00
8e97d8acec IPSec lifetimes are ints 2025-04-08 15:36:14 +02:00
5f1c56bd42 debug 2025-03-20 22:26:14 +01:00
8cb283ef91 ffix 2025-03-19 23:28:54 +01:00
2869909c3f fix 2025-03-19 19:44:37 +01:00
854771b7e6 fix 2025-03-19 19:05:56 +01:00
681ebde3db redeclare repo 2025-03-19 19:02:10 +01:00
e28d4d754e create IPV6Subnets 2025-03-19 19:00:17 +01:00
25 changed files with 259 additions and 857 deletions

View File

@@ -139,7 +139,7 @@ func extractJSON(jarFile, fieldsDir string) error {
return fmt.Errorf("unable to open settings file: %w", err)
}
var settings map[string]any
var settings map[string]interface{}
err = json.Unmarshal(settingsData, &settings)
if err != nil {
return fmt.Errorf("unable to unmarshal settings: %w", err)

View File

@@ -54,7 +54,7 @@ func (l firmwareUpdateApiResponseEmbeddedFirmwareDataLink) MarshalJSON() ([]byte
}
func (l *firmwareUpdateApiResponseEmbeddedFirmwareDataLink) UnmarshalJSON(j []byte) error {
var m map[string]any
var m map[string]interface{}
err := json.Unmarshal(j, &m)
if err != nil {

View File

@@ -482,7 +482,7 @@ func (r *Resource) IsSetting() bool {
return strings.HasPrefix(r.StructName, "Setting")
}
func (r *Resource) processFields(fields map[string]any) {
func (r *Resource) processFields(fields map[string]interface{}) {
t := r.Types[r.StructName]
for name, validation := range fields {
fieldInfo, err := r.fieldInfoFromValidation(name, validation)
@@ -494,7 +494,7 @@ func (r *Resource) processFields(fields map[string]any) {
}
}
func (r *Resource) fieldInfoFromValidation(name string, validation any) (*FieldInfo, error) {
func (r *Resource) fieldInfoFromValidation(name string, validation interface{}) (*FieldInfo, error) {
fieldName := strcase.ToCamel(name)
fieldName = cleanName(fieldName, fieldReps)
@@ -502,7 +502,7 @@ func (r *Resource) fieldInfoFromValidation(name string, validation any) (*FieldI
var fieldInfo *FieldInfo
switch validation := validation.(type) {
case []any:
case []interface{}:
if len(validation) == 0 {
fieldInfo = NewFieldInfo(fieldName, name, "string", "", false, true, "")
err := r.FieldProcessor(fieldName, fieldInfo)
@@ -523,7 +523,7 @@ func (r *Resource) fieldInfoFromValidation(name string, validation any) (*FieldI
err = r.FieldProcessor(fieldName, fieldInfo)
return fieldInfo, err
case map[string]any:
case map[string]interface{}:
typeName := r.StructName + fieldName
result := NewFieldInfo(fieldName, name, typeName, "", true, false, "")
@@ -587,7 +587,7 @@ func (r *Resource) fieldInfoFromValidation(name string, validation any) (*FieldI
}
func (r *Resource) processJSON(b []byte) error {
var fields map[string]any
var fields map[string]interface{}
err := json.Unmarshal(b, &fields)
if err != nil {
return err

View File

@@ -12,7 +12,7 @@ func TestFieldInfoFromValidation(t *testing.T) {
expectedType string
expectedComment string
expectedOmitEmpty bool
validation any
validation interface{}
}{
{"string", "", true, ""},
{"string", "default|custom", true, "default|custom"},

View File

@@ -25,16 +25,14 @@ type Account struct {
NoDelete bool `json:"attr_no_delete,omitempty"`
NoEdit bool `json:"attr_no_edit,omitempty"`
FilterIDs []string `json:"filter_ids,omitempty"`
IP string `json:"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])$|^$
Name string `json:"name,omitempty"` // ^[^"' ]+$
NetworkID string `json:"networkconf_id,omitempty"`
TunnelConfigType string `json:"tunnel_config_type,omitempty"` // vpn|802.1x|custom
TunnelMediumType int `json:"tunnel_medium_type,omitempty"` // [1-9]|1[0-5]|^$
TunnelType int `json:"tunnel_type,omitempty"` // [1-9]|1[0-3]|^$
UlpUserID string `json:"ulp_user_id"`
VLAN int `json:"vlan,omitempty"` // [2-9]|[1-9][0-9]{1,2}|[1-3][0-9]{3}|400[0-9]|^$
XPassword string `json:"x_password,omitempty"`
IP string `json:"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])$|^$
Name string `json:"name,omitempty"` // ^[^"' ]+$
NetworkID string `json:"networkconf_id,omitempty"`
TunnelConfigType string `json:"tunnel_config_type,omitempty"` // vpn|802.1x|custom
TunnelMediumType int `json:"tunnel_medium_type,omitempty"` // [1-9]|1[0-5]|^$
TunnelType int `json:"tunnel_type,omitempty"` // [1-9]|1[0-3]|^$
VLAN int `json:"vlan,omitempty"` // [2-9]|[1-9][0-9]{1,2}|[1-3][0-9]{3}|400[0-9]|^$
XPassword string `json:"x_password,omitempty"`
}
func (dst *Account) UnmarshalJSON(b []byte) error {

View File

@@ -27,88 +27,85 @@ type Device struct {
MAC string `json:"mac,omitempty"`
Adopted bool `json:"adopted"`
AfcEnabled bool `json:"afc_enabled,omitempty"`
AtfEnabled bool `json:"atf_enabled,omitempty"`
BandsteeringMode string `json:"bandsteering_mode,omitempty"` // off|equal|prefer_5g
BaresipAuthUser string `json:"baresip_auth_user,omitempty"` // ^\+?[a-zA-Z0-9_.\-!~*'()]*
BaresipEnabled bool `json:"baresip_enabled,omitempty"`
BaresipExtension string `json:"baresip_extension,omitempty"` // ^\+?[a-zA-Z0-9_.\-!~*'()]*
ConfigNetwork DeviceConfigNetwork `json:"config_network,omitempty"`
DPIEnabled bool `json:"dpi_enabled,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Dot1XFallbackNetworkID string `json:"dot1x_fallback_networkconf_id,omitempty"` // [\d\w]+|
Dot1XPortctrlEnabled bool `json:"dot1x_portctrl_enabled,omitempty"`
EtherLighting DeviceEtherLighting `json:"ether_lighting,omitempty"`
EthernetOverrides []DeviceEthernetOverrides `json:"ethernet_overrides,omitempty"`
FlowctrlEnabled bool `json:"flowctrl_enabled,omitempty"`
GatewayVrrpMode string `json:"gateway_vrrp_mode,omitempty"` // primary|secondary
GatewayVrrpPriority int `json:"gateway_vrrp_priority,omitempty"` // [1-9][0-9]|[1-9][0-9][0-9]
GreenApEnabled bool `json:"green_ap_enabled,omitempty"`
HeightInMeters float64 `json:"heightInMeters,omitempty"`
Hostname string `json:"hostname,omitempty"` // .{1,128}
JumboframeEnabled bool `json:"jumboframe_enabled,omitempty"`
LcmBrightness int `json:"lcm_brightness,omitempty"` // [1-9]|[1-9][0-9]|100
LcmBrightnessOverride bool `json:"lcm_brightness_override,omitempty"`
LcmIDleTimeout int `json:"lcm_idle_timeout,omitempty"` // [1-9][0-9]|[1-9][0-9][0-9]|[1-2][0-9][0-9][0-9]|3[0-5][0-9][0-9]|3600
LcmIDleTimeoutOverride bool `json:"lcm_idle_timeout_override,omitempty"`
LcmNightModeBegins string `json:"lcm_night_mode_begins,omitempty"` // (^$)|(^(0[1-9])|(1[0-9])|(2[0-3])):([0-5][0-9]$)
LcmNightModeEnds string `json:"lcm_night_mode_ends,omitempty"` // (^$)|(^(0[1-9])|(1[0-9])|(2[0-3])):([0-5][0-9]$)
LcmOrientationOverride int `json:"lcm_orientation_override,omitempty"` // 0|90|180|270
LcmSettingsRestrictedAccess bool `json:"lcm_settings_restricted_access,omitempty"`
LcmTrackerEnabled bool `json:"lcm_tracker_enabled,omitempty"`
LcmTrackerSeed string `json:"lcm_tracker_seed,omitempty"` // .{0,50}
LedOverride string `json:"led_override,omitempty"` // default|on|off
LedOverrideColor string `json:"led_override_color,omitempty"` // ^#(?:[0-9a-fA-F]{3}){1,2}$
LedOverrideColorBrightness int `json:"led_override_color_brightness,omitempty"` // ^[0-9][0-9]?$|^100$
Locked bool `json:"locked,omitempty"`
LowpfmodeOverride bool `json:"lowpfmode_override,omitempty"`
LteApn string `json:"lte_apn,omitempty"` // .{1,128}
LteAuthType string `json:"lte_auth_type,omitempty"` // PAP|CHAP|PAP-CHAP|NONE
LteDataLimitEnabled bool `json:"lte_data_limit_enabled,omitempty"`
LteDataWarningEnabled bool `json:"lte_data_warning_enabled,omitempty"`
LteExtAnt bool `json:"lte_ext_ant,omitempty"`
LteHardLimit int `json:"lte_hard_limit,omitempty"`
LtePassword string `json:"lte_password,omitempty"`
LtePoe bool `json:"lte_poe,omitempty"`
LteRoamingAllowed bool `json:"lte_roaming_allowed,omitempty"`
LteSimPin int `json:"lte_sim_pin,omitempty"`
LteSoftLimit int `json:"lte_soft_limit,omitempty"`
LteUsername string `json:"lte_username,omitempty"`
MapID string `json:"map_id,omitempty"`
MeshStaVapEnabled bool `json:"mesh_sta_vap_enabled,omitempty"`
MgmtNetworkID string `json:"mgmt_network_id,omitempty"` // [\d\w]+
Model string `json:"model,omitempty"`
Name string `json:"name,omitempty"` // .{0,128}
OutdoorModeOverride string `json:"outdoor_mode_override,omitempty"` // default|on|off
OutletEnabled bool `json:"outlet_enabled,omitempty"`
OutletOverrides []DeviceOutletOverrides `json:"outlet_overrides,omitempty"`
OutletPowerCycleEnabled bool `json:"outlet_power_cycle_enabled,omitempty"`
PeerToPeerMode string `json:"peer_to_peer_mode,omitempty"` // ap|sta
PoeMode string `json:"poe_mode,omitempty"` // auto|pasv24|passthrough|off
PortOverrides []DevicePortOverrides `json:"port_overrides"`
PowerSourceCtrl string `json:"power_source_ctrl,omitempty"` // auto|8023af|8023at|8023bt-type3|8023bt-type4|pasv24|poe-injector|ac|adapter|dc|rps
PowerSourceCtrlBudget int `json:"power_source_ctrl_budget,omitempty"` // [0-9]|[1-9][0-9]|[1-9][0-9][0-9]
PowerSourceCtrlEnabled bool `json:"power_source_ctrl_enabled,omitempty"`
PtmpApMAC string `json:"ptmp_ap_mac,omitempty"` // ^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$
PtpApMAC string `json:"ptp_ap_mac,omitempty"` // ^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$
RADIUSProfileID string `json:"radiusprofile_id,omitempty"`
RadioTable []DeviceRadioTable `json:"radio_table,omitempty"`
ResetbtnEnabled string `json:"resetbtn_enabled,omitempty"` // on|off
RpsOverride DeviceRpsOverride `json:"rps_override,omitempty"`
SnmpContact string `json:"snmp_contact,omitempty"` // .{0,255}
SnmpLocation string `json:"snmp_location,omitempty"` // .{0,255}
State DeviceState `json:"state"`
StationMode string `json:"station_mode,omitempty"` // ptp|ptmp|wifi
StpPriority string `json:"stp_priority,omitempty"` // 0|4096|8192|12288|16384|20480|24576|28672|32768|36864|40960|45056|49152|53248|57344|61440
StpVersion string `json:"stp_version,omitempty"` // stp|rstp|disabled
SwitchVLANEnabled bool `json:"switch_vlan_enabled,omitempty"`
Type string `json:"type,omitempty"`
UbbPairName string `json:"ubb_pair_name,omitempty"` // .{1,128}
Volume int `json:"volume,omitempty"` // [0-9]|[1-9][0-9]|100
X float64 `json:"x,omitempty"`
XBaresipPassword string `json:"x_baresip_password,omitempty"` // ^[a-zA-Z0-9_.\-!~*'()]*
Y float64 `json:"y,omitempty"`
Adopted bool `json:"adopted"`
AtfEnabled bool `json:"atf_enabled,omitempty"`
BandsteeringMode string `json:"bandsteering_mode,omitempty"` // off|equal|prefer_5g
BaresipAuthUser string `json:"baresip_auth_user,omitempty"` // ^\+?[a-zA-Z0-9_.\-!~*'()]*
BaresipEnabled bool `json:"baresip_enabled,omitempty"`
BaresipExtension string `json:"baresip_extension,omitempty"` // ^\+?[a-zA-Z0-9_.\-!~*'()]*
ConfigNetwork DeviceConfigNetwork `json:"config_network,omitempty"`
ConnectedBatteryOverrides []DeviceConnectedBatteryOverrides `json:"connected_battery_overrides,omitempty"`
DPIEnabled bool `json:"dpi_enabled,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Dot1XFallbackNetworkID string `json:"dot1x_fallback_networkconf_id,omitempty"` // [\d\w]+|
Dot1XPortctrlEnabled bool `json:"dot1x_portctrl_enabled,omitempty"`
EtherLighting DeviceEtherLighting `json:"ether_lighting,omitempty"`
EthernetOverrides []DeviceEthernetOverrides `json:"ethernet_overrides,omitempty"`
FlowctrlEnabled bool `json:"flowctrl_enabled,omitempty"`
GatewayVrrpMode string `json:"gateway_vrrp_mode,omitempty"` // primary|secondary
GatewayVrrpPriority int `json:"gateway_vrrp_priority,omitempty"` // [1-9][0-9]|[1-9][0-9][0-9]
HeightInMeters float64 `json:"heightInMeters,omitempty"`
Hostname string `json:"hostname,omitempty"` // .{1,128}
JumboframeEnabled bool `json:"jumboframe_enabled,omitempty"`
LcmBrightness int `json:"lcm_brightness,omitempty"` // [1-9]|[1-9][0-9]|100
LcmBrightnessOverride bool `json:"lcm_brightness_override,omitempty"`
LcmIDleTimeout int `json:"lcm_idle_timeout,omitempty"` // [1-9][0-9]|[1-9][0-9][0-9]|[1-2][0-9][0-9][0-9]|3[0-5][0-9][0-9]|3600
LcmIDleTimeoutOverride bool `json:"lcm_idle_timeout_override,omitempty"`
LcmNightModeBegins string `json:"lcm_night_mode_begins,omitempty"` // (^$)|(^(0[1-9])|(1[0-9])|(2[0-3])):([0-5][0-9]$)
LcmNightModeEnds string `json:"lcm_night_mode_ends,omitempty"` // (^$)|(^(0[1-9])|(1[0-9])|(2[0-3])):([0-5][0-9]$)
LcmSettingsRestrictedAccess bool `json:"lcm_settings_restricted_access,omitempty"`
LcmTrackerEnabled bool `json:"lcm_tracker_enabled,omitempty"`
LcmTrackerSeed string `json:"lcm_tracker_seed,omitempty"` // .{0,50}
LedOverride string `json:"led_override,omitempty"` // default|on|off
LedOverrideColor string `json:"led_override_color,omitempty"` // ^#(?:[0-9a-fA-F]{3}){1,2}$
LedOverrideColorBrightness int `json:"led_override_color_brightness,omitempty"` // ^[0-9][0-9]?$|^100$
Locked bool `json:"locked,omitempty"`
LowpfmodeOverride bool `json:"lowpfmode_override,omitempty"`
LteApn string `json:"lte_apn,omitempty"` // .{1,128}
LteAuthType string `json:"lte_auth_type,omitempty"` // PAP|CHAP|PAP-CHAP|NONE
LteDataLimitEnabled bool `json:"lte_data_limit_enabled,omitempty"`
LteDataWarningEnabled bool `json:"lte_data_warning_enabled,omitempty"`
LteExtAnt bool `json:"lte_ext_ant,omitempty"`
LteHardLimit int `json:"lte_hard_limit,omitempty"`
LtePassword string `json:"lte_password,omitempty"`
LtePoe bool `json:"lte_poe,omitempty"`
LteRoamingAllowed bool `json:"lte_roaming_allowed,omitempty"`
LteSimPin int `json:"lte_sim_pin,omitempty"`
LteSoftLimit int `json:"lte_soft_limit,omitempty"`
LteUsername string `json:"lte_username,omitempty"`
MapID string `json:"map_id,omitempty"`
MeshStaVapEnabled bool `json:"mesh_sta_vap_enabled,omitempty"`
MgmtNetworkID string `json:"mgmt_network_id,omitempty"` // [\d\w]+
Model string `json:"model,omitempty"`
Name string `json:"name,omitempty"` // .{0,128}
OutdoorModeOverride string `json:"outdoor_mode_override,omitempty"` // default|on|off
OutletEnabled bool `json:"outlet_enabled,omitempty"`
OutletOverrides []DeviceOutletOverrides `json:"outlet_overrides,omitempty"`
OutletPowerCycleEnabled bool `json:"outlet_power_cycle_enabled,omitempty"`
PeerToPeerMode string `json:"peer_to_peer_mode,omitempty"` // ap|sta
PoeMode string `json:"poe_mode,omitempty"` // auto|pasv24|passthrough|off
PortOverrides []DevicePortOverrides `json:"port_overrides"`
PowerSourceCtrl string `json:"power_source_ctrl,omitempty"` // auto|8023af|8023at|8023bt-type3|8023bt-type4|pasv24|poe-injector|ac|adapter|dc|rps
PowerSourceCtrlBudget int `json:"power_source_ctrl_budget,omitempty"` // [0-9]|[1-9][0-9]|[1-9][0-9][0-9]
PowerSourceCtrlEnabled bool `json:"power_source_ctrl_enabled,omitempty"`
RADIUSProfileID string `json:"radiusprofile_id,omitempty"`
RadioTable []DeviceRadioTable `json:"radio_table,omitempty"`
ResetbtnEnabled string `json:"resetbtn_enabled,omitempty"` // on|off
RpsOverride DeviceRpsOverride `json:"rps_override,omitempty"`
SnmpContact string `json:"snmp_contact,omitempty"` // .{0,255}
SnmpLocation string `json:"snmp_location,omitempty"` // .{0,255}
State DeviceState `json:"state"`
StpPriority string `json:"stp_priority,omitempty"` // 0|4096|8192|12288|16384|20480|24576|28672|32768|36864|40960|45056|49152|53248|57344|61440
StpVersion string `json:"stp_version,omitempty"` // stp|rstp|disabled
SwitchVLANEnabled bool `json:"switch_vlan_enabled,omitempty"`
Type string `json:"type,omitempty"`
UbbPairName string `json:"ubb_pair_name,omitempty"` // .{1,128}
Volume int `json:"volume,omitempty"` // [0-9]|[1-9][0-9]|100
X float64 `json:"x,omitempty"`
XBaresipPassword string `json:"x_baresip_password,omitempty"` // ^[a-zA-Z0-9_.\-!~*'()]*
Y float64 `json:"y,omitempty"`
PortTable []PortTable `json:"port_table,omitempty"`
}
func (dst *Device) UnmarshalJSON(b []byte) error {
@@ -117,7 +114,6 @@ func (dst *Device) UnmarshalJSON(b []byte) error {
GatewayVrrpPriority emptyStringInt `json:"gateway_vrrp_priority"`
LcmBrightness emptyStringInt `json:"lcm_brightness"`
LcmIDleTimeout emptyStringInt `json:"lcm_idle_timeout"`
LcmOrientationOverride emptyStringInt `json:"lcm_orientation_override"`
LedOverrideColorBrightness emptyStringInt `json:"led_override_color_brightness"`
LteExtAnt booleanishString `json:"lte_ext_ant"`
LteHardLimit emptyStringInt `json:"lte_hard_limit"`
@@ -140,7 +136,6 @@ func (dst *Device) UnmarshalJSON(b []byte) error {
dst.GatewayVrrpPriority = int(aux.GatewayVrrpPriority)
dst.LcmBrightness = int(aux.LcmBrightness)
dst.LcmIDleTimeout = int(aux.LcmIDleTimeout)
dst.LcmOrientationOverride = int(aux.LcmOrientationOverride)
dst.LedOverrideColorBrightness = int(aux.LedOverrideColorBrightness)
dst.LteExtAnt = bool(aux.LteExtAnt)
dst.LteHardLimit = int(aux.LteHardLimit)
@@ -181,10 +176,29 @@ func (dst *DeviceConfigNetwork) UnmarshalJSON(b []byte) error {
return nil
}
type DeviceConnectedBatteryOverrides struct {
MAC string `json:"mac,omitempty"` // ^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$
}
func (dst *DeviceConnectedBatteryOverrides) UnmarshalJSON(b []byte) error {
type Alias DeviceConnectedBatteryOverrides
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 DeviceEtherLighting struct {
Behavior string `json:"behavior,omitempty"` // breath|steady
Brightness int `json:"brightness,omitempty"` // [1-9]|[1-9][0-9]|100
LedMode string `json:"led_mode,omitempty"` // standard|etherlighting
Mode string `json:"mode,omitempty"` // speed|network
}
@@ -268,13 +282,12 @@ type DevicePortOverrides struct {
Isolation bool `json:"isolation,omitempty"`
LldpmedEnabled bool `json:"lldpmed_enabled,omitempty"`
LldpmedNotifyEnabled bool `json:"lldpmed_notify_enabled,omitempty"`
MirrorPortIDX int `json:"mirror_port_idx,omitempty"` // [1-9]|[1-4][0-9]|5[0-6]
MulticastRouterNetworkIDs []string `json:"multicast_router_networkconf_ids,omitempty"`
MirrorPortIDX int `json:"mirror_port_idx,omitempty"` // [1-9]|[1-4][0-9]|5[0-2]
NATiveNetworkID string `json:"native_networkconf_id,omitempty"`
Name string `json:"name,omitempty"` // .{0,128}
OpMode string `json:"op_mode,omitempty"` // switch|mirror|aggregate
PoeMode string `json:"poe_mode,omitempty"` // auto|pasv24|passthrough|off
PortIDX int `json:"port_idx,omitempty"` // [1-9]|[1-4][0-9]|5[0-6]
PortIDX int `json:"port_idx,omitempty"` // [1-9]|[1-4][0-9]|5[0-2]
PortKeepaliveEnabled bool `json:"port_keepalive_enabled,omitempty"`
PortProfileID string `json:"portconf_id,omitempty"` // [\d\w]+
PortSecurityEnabled bool `json:"port_security_enabled,omitempty"`
@@ -299,6 +312,8 @@ type DevicePortOverrides struct {
StpPortMode bool `json:"stp_port_mode,omitempty"`
TaggedVLANMgmt string `json:"tagged_vlan_mgmt,omitempty"` // auto|block_all|custom
VoiceNetworkID string `json:"voice_networkconf_id,omitempty"`
PortPoe *bool `json:"port_poe,omitempty"`
}
func (dst *DevicePortOverrides) UnmarshalJSON(b []byte) error {

View File

@@ -1,134 +0,0 @@
package unifi
import (
"context"
"fmt"
)
type FirewallPolicy struct {
ID string `json:"_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"`
Action string `json:"action"`
ConnectionStateType string `json:"connection_state_type"`
ConnectionStates []string `json:"connection_states"`
CreateAllowRespond bool `json:"create_allow_respond"`
Description string `json:"description"`
Destination struct {
IPGroupID string `json:"ip_group_id"`
Ips []string `json:"ips"`
MatchOppositeIps bool `json:"match_opposite_ips"`
MatchOppositePorts bool `json:"match_opposite_ports"`
MatchingTarget string `json:"matching_target"`
NetworkIDs [] string `json:"network_ids"`
Port string `json:"port"`
PortGroupID string `json:"port_group_id"`
PortMatchingType string `json:"port_matching_type"`
Regions []string `json:"regions"`
ZoneID string `json:"zone_id"`
} `json:"destination"`
Enabled bool `json:"enabled"`
IcmpTypename string `json:"icmp_typename"`
IcmpV6Typename string `json:"icmp_v6_typename"`
Index int64 `json:"index"`
IPVersion string `json:"ip_version"`
Logging bool `json:"logging"`
MatchIPSec bool `json:"match_ip_sec"`
MatchIPSecType string `json:"match_ip_sec_type"`
MatchOppositeProtocol bool `json:"match_opposite_protocol"`
Name string `json:"name"`
OriginID string `json:"origin_id"`
OriginType string `json:"origin_type"`
Predefined bool `json:"predefined"`
Protocol string `json:"protocol"`
Schedule struct {
Mode string `json:"mode"`
DateStart string `json:"date_start"`
DateEnd string `json:"date_end"`
RepeatOnDays []string `json:"repeat_on_days"`
TimeAllDay bool `json:"time_all_day"`
TimeRangeStart string `json:"time_range_start"`
TimeRangeEnd string `json:"time_range_end"`
} `json:"schedule"`
Source struct {
ClientMacs []string `json:"client_macs"`
Ips []string `json:"ips"`
MatchMac bool `json:"match_mac"`
MatchOppositeIps bool `json:"match_opposite_ips"`
MatchOppositeNetworks bool `json:"match_opposite_networks"`
MatchOppositePorts bool `json:"match_opposite_ports"`
MatchingTarget string `json:"matching_target"`
MatchingTargetType string `json:"matching_target_type"`
NetworkIDs []string `json:"network_ids"`
Port string `json:"port"`
PortMatchingType string `json:"port_matching_type"`
ZoneID string `json:"zone_id"`
} `json:"source"`
// Role string `json:"role"`
}
func (c *Client) ListFirewallPolicy(ctx context.Context, site string) ([]FirewallPolicy, error) {
var respBody []FirewallPolicy
err := c.do_versioned(ctx, "V2", "GET", fmt.Sprintf("site/%s/firewall-policies", site), nil, &respBody)
if err != nil {
return nil, err
}
return respBody, nil
}
func (c *Client) GetFirewallPolicy(ctx context.Context, site, id string) (*FirewallPolicy, error) {
var respBody FirewallPolicy
err := c.do_versioned(ctx, "V2", "GET", fmt.Sprintf("site/%s/firewall-policies/%s", site,id), nil, &respBody)
if err != nil {
return nil, &NotFoundError{}
}
new := respBody
return &new, nil
}
func (c *Client) DeleteFirewallPolicy(ctx context.Context, site, id string) error {
var respBody FirewallPolicy
err := c.do_versioned(ctx, "V2", "DELETE", fmt.Sprintf("site/%s/firewall-policies/%s", site, id), nil, &respBody)
if err != nil {
return err
}
return nil
}
func (c *Client) CreaateFirewallPolicy(ctx context.Context, site string, d *FirewallPolicy) (*FirewallPolicy, error) {
var respBody FirewallPolicy
err := c.do_versioned(ctx, "V2", "POST", fmt.Sprintf("site/%s/firewall-policies", site), d, &respBody)
if err != nil {
return nil, err
}
new := respBody
return &new, nil
}
func (c *Client) UpdateFirewallPolicy(ctx context.Context, site string, d *FirewallPolicy) (*FirewallPolicy, error) {
var respBody FirewallPolicy
err := c.do_versioned(ctx, "V2", "PUT", fmt.Sprintf("site/%s/firewall-policies/%s", site, d.ID), d, &respBody)
if err != nil {
return nil, err
}
new := respBody
return &new, nil
}

View File

@@ -26,6 +26,7 @@ type FirewallRule struct {
NoEdit bool `json:"attr_no_edit,omitempty"`
Action string `json:"action,omitempty"` // drop|reject|accept
Contiguous bool `json:"contiguous"`
DstAddress string `json:"dst_address,omitempty"`
DstAddressIPV6 string `json:"dst_address_ipv6,omitempty"`
DstFirewallGroupIDs []string `json:"dst_firewallgroup_ids,omitempty"` // [\d\w]+
@@ -37,6 +38,8 @@ type FirewallRule struct {
ICMPv6Typename string `json:"icmpv6_typename"` // ^$|address-unreachable|bad-header|beyond-scope|communication-prohibited|destination-unreachable|echo-reply|echo-request|failed-policy|neighbor-advertisement|neighbor-solicitation|no-route|packet-too-big|parameter-problem|port-unreachable|redirect|reject-route|router-advertisement|router-solicitation|time-exceeded|ttl-zero-during-reassembly|ttl-zero-during-transit|unknown-header-type|unknown-option
IPSec string `json:"ipsec"` // match-ipsec|match-none|^$
Logging bool `json:"logging"`
MonthDays string `json:"monthdays"` // ^$|^(([1-9]|[12][0-9]|3[01])(,([1-9]|[12][0-9]|3[01])){0,30})$
MonthDaysNegate bool `json:"monthdays_negate"`
Name string `json:"name,omitempty"` // .{1,128}
Protocol string `json:"protocol"` // ^$|all|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])|tcp_udp|ah|ax.25|dccp|ddp|egp|eigrp|encap|esp|etherip|fc|ggp|gre|hip|hmp|icmp|idpr-cmtp|idrp|igmp|igp|ip|ipcomp|ipencap|ipip|ipv6|ipv6-frag|ipv6-icmp|ipv6-nonxt|ipv6-opts|ipv6-route|isis|iso-tp4|l2tp|manet|mobility-header|mpls-in-ip|ospf|pim|pup|rdp|rohc|rspf|rsvp|sctp|shim6|skip|st|tcp|udp|udplite|vmtp|vrrp|wesp|xns-idp|xtp
ProtocolMatchExcepted bool `json:"protocol_match_excepted"`
@@ -51,10 +54,17 @@ type FirewallRule struct {
SrcNetworkID string `json:"src_networkconf_id"` // [\d\w]+|^$
SrcNetworkType string `json:"src_networkconf_type,omitempty"` // ADDRv4|NETv4
SrcPort string `json:"src_port,omitempty"`
StartDate string `json:"startdate"` // ^$|^(20[0-9]{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9])$
StartTime string `json:"starttime"` // ^$|^(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9])$
StateEstablished bool `json:"state_established"`
StateInvalid bool `json:"state_invalid"`
StateNew bool `json:"state_new"`
StateRelated bool `json:"state_related"`
StopDate string `json:"stopdate"` // ^$|^(20[0-9]{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9])$
StopTime string `json:"stoptime"` // ^$|^(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9])$
UTC bool `json:"utc"`
Weekdays string `json:"weekdays"` // ^$|^((Mon|Tue|Wed|Thu|Fri|Sat|Sun)(,(Mon|Tue|Wed|Thu|Fri|Sat|Sun)){0,6})$
WeekdaysNegate bool `json:"weekdays_negate"`
}
func (dst *FirewallRule) UnmarshalJSON(b []byte) error {

View File

@@ -14,22 +14,25 @@ type FirewallZone struct {
// NoEdit bool `json:"attr_no_edit,omitempty"`
Name string `json:"name"`
DefaultZone bool `json:"default_zone,omitempty"`
NetworkIDs []string `json:"network_ids,omitempty"`
ZoneKey string `json:"zone_key,omitempty"`
Description string `json:"desc"`
DefaultZone bool `json:default_zone,omitempty`
NetworkIDs []string `json:network_ids,omitempty`
// Role string `json:"role"`
}
func (c *Client) ListFirewallZones(ctx context.Context, site string) ([]FirewallZone, error) {
var respBody []FirewallZone
var respBody struct {
Meta meta `json:"meta"`
Data []FirewallZone `json:"data"`
}
err := c.do_versioned(ctx, "V2", "GET", fmt.Sprintf("site/%s/firewall/zone", site), nil, &respBody)
err := c.do(ctx, "GET", fmt.Sprintf("site/%s/firewall/zone", site), nil, &respBody)
if err != nil {
return nil, err
}
return respBody, nil
return respBody.Data, nil
}
func (c *Client) GetFirewallZone(ctx context.Context, site, id string) (*FirewallZone, error) {

View File

@@ -75,18 +75,15 @@ type Network struct {
DomainName string `json:"domain_name"` // (?=^.{3,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)|^$|[a-zA-Z0-9-]{1,63}
Enabled bool `json:"enabled"`
ExposedToSiteVPN bool `json:"exposed_to_site_vpn"`
FirewallZoneID string `json:"firewall_zone_id"`
GatewayDevice string `json:"gateway_device"` // (^$|^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$)
GatewayType string `json:"gateway_type,omitempty"` // default|switch
IGMPFastleave bool `json:"igmp_fastleave"`
IGMPForwardUnknownMulticast bool `json:"igmp_forward_unknown_multicast"`
IGMPGroupmembership int `json:"igmp_groupmembership,omitempty"` // [2-9]|[1-9][0-9]{1,2}|[1-2][0-9]{3}|3[0-5][0-9]{2}|3600|^$
IGMPMaxresponse int `json:"igmp_maxresponse,omitempty"` // [1-9]|1[0-9]|2[0-5]|^$
IGMPMcrtrexpiretime int `json:"igmp_mcrtrexpiretime,omitempty"` // [0-9]|[1-9][0-9]{1,2}|[1-2][0-9]{3}|3[0-5][0-9]{2}|3600|^$
IGMPProxyDownstreamNetworkIDs []string `json:"igmp_proxy_downstream_networkconf_ids,omitempty"`
IGMPProxyFor string `json:"igmp_proxy_for,omitempty"` // all|some|none
IGMPProxyDownstream bool `json:"igmp_proxy_downstream"`
IGMPProxyUpstream bool `json:"igmp_proxy_upstream"`
IGMPQuerierSwitches []NetworkIGMPQuerierSwitches `json:"igmp_querier_switches,omitempty"`
IGMPQuerier string `json:"igmp_querier"` // ^(([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])$|^$
IGMPSnooping bool `json:"igmp_snooping"`
IGMPSupression bool `json:"igmp_supression"`
IPSecDhGroup int `json:"ipsec_dh_group,omitempty"` // 2|5|14|15|16|19|20|21|25|26
@@ -129,12 +126,13 @@ type Network struct {
IPV6SettingPreference string `json:"ipv6_setting_preference,omitempty"` // auto|manual
IPV6SingleNetworkInterface string `json:"ipv6_single_network_interface,omitempty"`
IPV6Subnet string `json:"ipv6_subnet,omitempty"`
IPV6Subnets []string `json:"ipv6_subnets,omitempty"`
IPV6WANDelegationType string `json:"ipv6_wan_delegation_type,omitempty"` // pd|single_network|none
InterfaceMtu int `json:"interface_mtu,omitempty"` // ^(6[89]|[7-9][0-9]|[1-9][0-9]{2,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|65500)$
InterfaceMtuEnabled bool `json:"interface_mtu_enabled"`
InternetAccessEnabled bool `json:"internet_access_enabled"`
IsNAT bool `json:"is_nat"`
L2TpAllowWeakCiphers bool `json:"l2tp_allow_weak_ciphers"`
L4TpAllowWeakCiphers bool `json:"l2tp_allow_weak_ciphers"`
L2TpInterface string `json:"l2tp_interface,omitempty"` // wan|wan2
L2TpLocalWANIP string `json:"l2tp_local_wan_ip,omitempty"` // ^any$|^(([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])$
LocalPort int `json:"local_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])$
@@ -171,8 +169,7 @@ type Network struct {
RemoteVPNSubnets []string `json:"remote_vpn_subnets,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])\/([1-9]|[1-2][0-9]|3[0-2])$|^$
ReportWANEvent bool `json:"report_wan_event"`
RequireMschapv2 bool `json:"require_mschapv2"`
RouteDistance int `json:"route_distance,omitempty"` // ^[1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]$|^$
SdwanRemoteSiteID string `json:"sdwan_remote_site_id"`
RouteDistance int `json:"route_distance,omitempty"` // ^[1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]$|^$
SettingPreference string `json:"setting_preference,omitempty"` // auto|manual
SingleNetworkLan string `json:"single_network_lan,omitempty"`
UidPolicyEnabled bool `json:"uid_policy_enabled"`
@@ -196,7 +193,7 @@ type Network struct {
VPNClientDefaultRoute bool `json:"vpn_client_default_route"`
VPNClientPullDNS bool `json:"vpn_client_pull_dns"`
VPNProtocol string `json:"vpn_protocol,omitempty"` // TCP|UDP
VPNType string `json:"vpn_type,omitempty"` // auto|ipsec-vpn|openvpn-client|openvpn-server|openvpn-vpn|pptp-client|l2tp-server|pptp-server|sdwan-hub-spoke-tunnel|sdwan-mesh-tunnel|uid-server|wireguard-server|wireguard-client
VPNType string `json:"vpn_type,omitempty"` // auto|ipsec-vpn|openvpn-client|openvpn-server|openvpn-vpn|pptp-client|l2tp-server|pptp-server|uid-server|wireguard-server|wireguard-client
VrrpIPSubnetGw1 string `json:"vrrp_ip_subnet_gw1,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])\/([1-9]|[1-2][0-9]|30)$
VrrpIPSubnetGw2 string `json:"vrrp_ip_subnet_gw2,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])\/([1-9]|[1-2][0-9]|30)$
VrrpVrid int `json:"vrrp_vrid,omitempty"` // [1-9]|[1-9][0-9]
@@ -342,27 +339,6 @@ func (dst *Network) UnmarshalJSON(b []byte) error {
return nil
}
type NetworkIGMPQuerierSwitches struct {
QuerierAddress string `json:"querier_address"` // ^(([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])$|^$
SwitchMAC string `json:"switch_mac,omitempty"` // ^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$
}
func (dst *NetworkIGMPQuerierSwitches) UnmarshalJSON(b []byte) error {
type Alias NetworkIGMPQuerierSwitches
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 NetworkNATOutboundIPAddresses struct {
IPAddress string `json:"ip_address"` // ^(([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])$|^$
IPAddressPool []string `json:"ip_address_pool,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])$
@@ -446,7 +422,7 @@ func (c *Client) listNetwork(ctx context.Context, site string) ([]Network, error
if err != nil {
return nil, err
}
fmt.Printf("%+v",respBody.Data)
return respBody.Data, nil
}

View File

@@ -37,7 +37,6 @@ type PortProfile struct {
Isolation bool `json:"isolation"`
LldpmedEnabled bool `json:"lldpmed_enabled"`
LldpmedNotifyEnabled bool `json:"lldpmed_notify_enabled"`
MulticastRouterNetworkIDs []string `json:"multicast_router_networkconf_ids,omitempty"`
NATiveNetworkID string `json:"native_networkconf_id"`
Name string `json:"name,omitempty"`
OpMode string `json:"op_mode,omitempty"` // switch

View File

@@ -25,23 +25,16 @@ type RADIUSProfile struct {
NoDelete bool `json:"attr_no_delete,omitempty"`
NoEdit bool `json:"attr_no_edit,omitempty"`
AccountingEnabled bool `json:"accounting_enabled"`
AcctServers []RADIUSProfileAcctServers `json:"acct_servers,omitempty"`
AuthServers []RADIUSProfileAuthServers `json:"auth_servers,omitempty"`
InterimUpdateEnabled bool `json:"interim_update_enabled"`
InterimUpdateInterval int `json:"interim_update_interval,omitempty"` // ^([6-9][0-9]|[1-9][0-9]{2,3}|[1-7][0-9]{4}|8[0-5][0-9]{3}|86[0-3][0-9][0-9]|86400)$
Name string `json:"name,omitempty"` // .{1,128}
TlsEnabled bool `json:"tls_enabled"`
UseUsgAcctServer bool `json:"use_usg_acct_server"`
UseUsgAuthServer bool `json:"use_usg_auth_server"`
VLANEnabled bool `json:"vlan_enabled"`
VLANWLANMode string `json:"vlan_wlan_mode,omitempty"` // disabled|optional|required
XCaCrts []RADIUSProfileXCaCrts `json:"x_ca_crts,omitempty"`
XClientCrt string `json:"x_client_crt,omitempty"`
XClientCrtFilename string `json:"x_client_crt_filename,omitempty"`
XClientPrivateKey string `json:"x_client_private_key,omitempty"`
XClientPrivateKeyFilename string `json:"x_client_private_key_filename,omitempty"`
XClientPrivateKeyPassword string `json:"x_client_private_key_password,omitempty"`
AccountingEnabled bool `json:"accounting_enabled"`
AcctServers []RADIUSProfileAcctServers `json:"acct_servers,omitempty"`
AuthServers []RADIUSProfileAuthServers `json:"auth_servers,omitempty"`
InterimUpdateEnabled bool `json:"interim_update_enabled"`
InterimUpdateInterval int `json:"interim_update_interval,omitempty"` // ^([6-9][0-9]|[1-9][0-9]{2,3}|[1-7][0-9]{4}|8[0-5][0-9]{3}|86[0-3][0-9][0-9]|86400)$
Name string `json:"name,omitempty"` // .{1,128}
UseUsgAcctServer bool `json:"use_usg_acct_server"`
UseUsgAuthServer bool `json:"use_usg_auth_server"`
VLANEnabled bool `json:"vlan_enabled"`
VLANWLANMode string `json:"vlan_wlan_mode,omitempty"` // disabled|optional|required
}
func (dst *RADIUSProfile) UnmarshalJSON(b []byte) error {
@@ -113,27 +106,6 @@ func (dst *RADIUSProfileAuthServers) UnmarshalJSON(b []byte) error {
return nil
}
type RADIUSProfileXCaCrts struct {
Filename string `json:"filename,omitempty"`
XCaCrt string `json:"x_ca_crt,omitempty"`
}
func (dst *RADIUSProfileXCaCrts) UnmarshalJSON(b []byte) error {
type Alias RADIUSProfileXCaCrts
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) listRADIUSProfile(ctx context.Context, site string) ([]RADIUSProfile, error) {
var respBody struct {
Meta meta `json:"meta"`

View File

@@ -12,7 +12,7 @@ type Setting struct {
Key string `json:"key"`
}
func (s *Setting) newFields() (any, error) {
func (s *Setting) newFields() (interface{}, error) {
switch s.Key {
case "auto_speedtest":
return &SettingAutoSpeedtest{}, nil
@@ -79,7 +79,7 @@ func (s *Setting) newFields() (any, error) {
return nil, fmt.Errorf("unexpected key %q", s.Key)
}
func (c *Client) GetSetting(ctx context.Context, site, key string) (*Setting, any, error) {
func (c *Client) GetSetting(ctx context.Context, site, key string) (*Setting, interface{}, error) {
var respBody struct {
Meta meta `json:"meta"`
Data []json.RawMessage `json:"data"`

View File

@@ -27,7 +27,7 @@ type SettingDashboard struct {
Key string `json:"key"`
LayoutPreference string `json:"layout_preference,omitempty"` // auto|manual
LayoutPreference string `json:"layout_preference,omitempty"` // auto|custom
Widgets []SettingDashboardWidgets `json:"widgets,omitempty"`
}
@@ -48,8 +48,7 @@ func (dst *SettingDashboard) UnmarshalJSON(b []byte) error {
}
type SettingDashboardWidgets struct {
Enabled bool `json:"enabled"`
Name string `json:"name,omitempty"` // cybersecure|traffic_identification|wifi_technology|wifi_channels|wifi_client_experience|wifi_tx_retries|most_active_apps_aps_clients|most_active_apps_clients|most_active_aps_clients|most_active_apps_aps|most_active_apps|v2_most_active_aps|v2_most_active_clients|wifi_connectivity|ap_radio_density
Name string `json:"name,omitempty"` // traffic_identification|connection_types|wifi_technology|most_active_clients|most_active_aps|meshing|network_activity|wireless_experience|internet|wifi_activity|wifi_channels|wifi_client_experience|wifi_tx_retries|admin_activity|device_client_count|server_ip
}
func (dst *SettingDashboardWidgets) UnmarshalJSON(b []byte) error {

View File

@@ -27,9 +27,8 @@ type SettingDoh struct {
Key string `json:"key"`
CustomServers []SettingDohCustomServers `json:"custom_servers,omitempty"`
ServerNames []string `json:"server_names,omitempty"`
State string `json:"state,omitempty"` // off|auto|manual|custom
ServerNames []string `json:"server_names,omitempty"`
State string `json:"state,omitempty"` // off|auto|manual
}
func (dst *SettingDoh) UnmarshalJSON(b []byte) error {
@@ -48,28 +47,6 @@ func (dst *SettingDoh) UnmarshalJSON(b []byte) error {
return nil
}
type SettingDohCustomServers struct {
Enabled bool `json:"enabled"`
SdnsStamp string `json:"sdns_stamp,omitempty"`
ServerName string `json:"server_name,omitempty"`
}
func (dst *SettingDohCustomServers) UnmarshalJSON(b []byte) error {
type Alias SettingDohCustomServers
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) getSettingDoh(ctx context.Context, site string) (*SettingDoh, error) {
var respBody struct {
Meta meta `json:"meta"`

View File

@@ -29,15 +29,16 @@ type SettingIps struct {
AdBlockingConfigurations []SettingIpsAdBlockingConfigurations `json:"ad_blocking_configurations,omitempty"`
AdBlockingEnabled bool `json:"ad_blocking_enabled"`
AdvancedFilteringPreference string `json:"advanced_filtering_preference,omitempty"` // |manual|disabled
AdvancedFilteringPreference string `json:"advanced_filtering_preference,omitempty"` // |auto|manual|disabled
DNSFiltering bool `json:"dns_filtering"`
DNSFilters []SettingIpsDNSFilters `json:"dns_filters,omitempty"`
EnabledCategories []string `json:"enabled_categories,omitempty"` // emerging-activex|emerging-attackresponse|botcc|emerging-chat|ciarmy|compromised|emerging-dns|emerging-dos|dshield|emerging-exploit|emerging-ftp|emerging-games|emerging-icmp|emerging-icmpinfo|emerging-imap|emerging-inappropriate|emerging-info|emerging-malware|emerging-misc|emerging-mobile|emerging-netbios|emerging-p2p|emerging-policy|emerging-pop3|emerging-rpc|emerging-scada|emerging-scan|emerging-shellcode|emerging-smtp|emerging-snmp|emerging-sql|emerging-telnet|emerging-tftp|tor|emerging-useragent|emerging-voip|emerging-webapps|emerging-webclient|emerging-webserver|emerging-worm|exploit-kit|adware-pup|botcc-portgrouped|phishing|threatview-cs-c2|3coresec|chat|coinminer|current-events|drop|hunting|icmp-info|inappropriate|info|ja3|policy|scada|dark-web-blocker-list|malicious-hosts
EnabledCategories []string `json:"enabled_categories,omitempty"` // emerging-activex|emerging-attackresponse|botcc|emerging-chat|ciarmy|compromised|emerging-dns|emerging-dos|dshield|emerging-exploit|emerging-ftp|emerging-games|emerging-icmp|emerging-icmpinfo|emerging-imap|emerging-inappropriate|emerging-info|emerging-malware|emerging-misc|emerging-mobile|emerging-netbios|emerging-p2p|emerging-policy|emerging-pop3|emerging-rpc|emerging-scada|emerging-scan|emerging-shellcode|emerging-smtp|emerging-snmp|emerging-sql|emerging-telnet|emerging-tftp|tor|emerging-trojan|emerging-useragent|emerging-voip|emerging-webapps|emerging-webclient|emerging-webserver|emerging-worm|exploit-kit|adware-pup|botcc-portgrouped|phishing|threatview-cs-c2|3coresec|chat|coinminer|current-events|drop|hunting|icmp-info|inappropriate|info|ja3|policy|scada
EnabledNetworks []string `json:"enabled_networks,omitempty"`
Honeypot []SettingIpsHoneypot `json:"honeypot,omitempty"`
HoneypotEnabled bool `json:"honeypot_enabled"`
IPsMode string `json:"ips_mode,omitempty"` // ids|ips|ipsInline|disabled
MemoryOptimized bool `json:"memory_optimized"`
RestrictIPAddresses bool `json:"restrict_ip_addresses"`
RestrictTor bool `json:"restrict_tor"`
RestrictTorrents bool `json:"restrict_torrents"`
Suppression SettingIpsSuppression `json:"suppression,omitempty"`
}

View File

@@ -1,110 +0,0 @@
// 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 SettingNetflow 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"`
Key string `json:"key"`
AutoEngineIDEnabled bool `json:"auto_engine_id_enabled"`
Enabled bool `json:"enabled"`
EngineID int `json:"engine_id,omitempty"` // ^$|[1-9][0-9]*
ExportFrequency int `json:"export_frequency,omitempty"`
NetworkIDs []string `json:"network_ids,omitempty"`
Port int `json:"port,omitempty"` // 102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{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]
RefreshRate int `json:"refresh_rate,omitempty"`
SamplingMode string `json:"sampling_mode,omitempty"` // off|hash|random|deterministic
SamplingRate int `json:"sampling_rate,omitempty"` // [2-9]|[1-9][0-9]{1,3}|1[0-5][0-9]{3}|16[0-2][0-9]{2}|163[0-7][0-9]|1638[0-3]|^$
Server string `json:"server,omitempty"` // .{0,252}[^\.]$
Version int `json:"version,omitempty"` // 5|9|10
}
func (dst *SettingNetflow) UnmarshalJSON(b []byte) error {
type Alias SettingNetflow
aux := &struct {
EngineID emptyStringInt `json:"engine_id"`
ExportFrequency emptyStringInt `json:"export_frequency"`
Port emptyStringInt `json:"port"`
RefreshRate emptyStringInt `json:"refresh_rate"`
SamplingRate emptyStringInt `json:"sampling_rate"`
Version emptyStringInt `json:"version"`
*Alias
}{
Alias: (*Alias)(dst),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return fmt.Errorf("unable to unmarshal alias: %w", err)
}
dst.EngineID = int(aux.EngineID)
dst.ExportFrequency = int(aux.ExportFrequency)
dst.Port = int(aux.Port)
dst.RefreshRate = int(aux.RefreshRate)
dst.SamplingRate = int(aux.SamplingRate)
dst.Version = int(aux.Version)
return nil
}
func (c *Client) getSettingNetflow(ctx context.Context, site string) (*SettingNetflow, error) {
var respBody struct {
Meta meta `json:"meta"`
Data []SettingNetflow `json:"data"`
}
err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/netflow", site), 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) updateSettingNetflow(ctx context.Context, site string, d *SettingNetflow) (*SettingNetflow, error) {
var respBody struct {
Meta meta `json:"meta"`
Data []SettingNetflow `json:"data"`
}
d.Key = "netflow"
err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/netflow", site), d, &respBody)
if err != nil {
return nil, err
}
if len(respBody.Data) != 1 {
return nil, &NotFoundError{}
}
new := respBody.Data[0]
return &new, nil
}

View File

@@ -1,16 +0,0 @@
// Code generated from ace.jar fields *.json files
// DO NOT EDIT.
package unifi
import (
"context"
)
func (c *Client) GetSettingNetflow(ctx context.Context, site string) (*SettingNetflow, error) {
return c.getSettingNetflow(ctx, site)
}
func (c *Client) UpdateSettingNetflow(ctx context.Context, site string, d *SettingNetflow) (*SettingNetflow, error) {
return c.updateSettingNetflow(ctx, site, d)
}

View File

@@ -27,21 +27,20 @@ type SettingRadioAi struct {
Key string `json:"key"`
AutoAdjustChannelsToCountry bool `json:"auto_adjust_channels_to_country"`
Channels6E []int `json:"channels_6e,omitempty"` // [1-9]|[1-2][0-9]|3[3-9]|[4-5][0-9]|6[0-1]|6[5-9]|[7-8][0-9]|9[0-3]|9[7-9]|1[0-1][0-9]|12[0-5]|129|1[3-4][0-9]|15[0-7]|16[1-9]|1[7-8][0-9]|19[3-9]|2[0-1][0-9]|22[0-1]|22[5-9]|233
ChannelsBlacklist []SettingRadioAiChannelsBlacklist `json:"channels_blacklist,omitempty"`
ChannelsNa []int `json:"channels_na,omitempty"` // 34|36|38|40|42|44|46|48|52|56|60|64|100|104|108|112|116|120|124|128|132|136|140|144|149|153|157|161|165|169
ChannelsNg []int `json:"channels_ng,omitempty"` // 1|2|3|4|5|6|7|8|9|10|11|12|13|14
CronExpr string `json:"cron_expr,omitempty"`
Default bool `json:"default"`
Enabled bool `json:"enabled"`
ExcludeDevices []string `json:"exclude_devices,omitempty"` // ([0-9a-z]{2}:){5}[0-9a-z]{2}
HtModesNa []int `json:"ht_modes_na,omitempty"` // ^(20|40|80|160)$
HtModesNg []int `json:"ht_modes_ng,omitempty"` // ^(20|40)$
Optimize []string `json:"optimize,omitempty"` // channel|power
Radios []string `json:"radios,omitempty"` // na|ng
SettingPreference string `json:"setting_preference,omitempty"` // auto|manual
UseXy bool `json:"useXY"`
AutoAdjustChannelsToCountry bool `json:"auto_adjust_channels_to_country"`
Channels6E []int `json:"channels_6e,omitempty"` // [1-9]|[1-2][0-9]|3[3-9]|[4-5][0-9]|6[0-1]|6[5-9]|[7-8][0-9]|9[0-3]|9[7-9]|1[0-1][0-9]|12[0-5]|129|1[3-4][0-9]|15[0-7]|16[1-9]|1[7-8][0-9]|19[3-9]|2[0-1][0-9]|22[0-1]|22[5-9]|233
ChannelsNa []int `json:"channels_na,omitempty"` // 34|36|38|40|42|44|46|48|52|56|60|64|100|104|108|112|116|120|124|128|132|136|140|144|149|153|157|161|165|169
ChannelsNg []int `json:"channels_ng,omitempty"` // 1|2|3|4|5|6|7|8|9|10|11|12|13|14
CronExpr string `json:"cron_expr,omitempty"`
Default bool `json:"default"`
Enabled bool `json:"enabled"`
ExcludeDevices []string `json:"exclude_devices,omitempty"` // ([0-9a-z]{2}:){5}[0-9a-z]{2}
HtModesNa []int `json:"ht_modes_na,omitempty"` // ^(20|40|80|160)$
HtModesNg []int `json:"ht_modes_ng,omitempty"` // ^(20|40)$
Optimize []string `json:"optimize,omitempty"` // channel|power
Radios []string `json:"radios,omitempty"` // na|ng
SettingPreference string `json:"setting_preference,omitempty"` // auto|manual
UseXy bool `json:"useXY"`
}
func (dst *SettingRadioAi) UnmarshalJSON(b []byte) error {
@@ -86,33 +85,6 @@ func (dst *SettingRadioAi) UnmarshalJSON(b []byte) error {
return nil
}
type SettingRadioAiChannelsBlacklist struct {
Channel int `json:"channel,omitempty"` // [1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-9]|2[0-1][0-9]|22[0-1]|22[5-9]|233
ChannelWidth int `json:"channel_width,omitempty"` // 20|40|80|160|240|320
Radio string `json:"radio,omitempty"` // na|ng|6e
}
func (dst *SettingRadioAiChannelsBlacklist) UnmarshalJSON(b []byte) error {
type Alias SettingRadioAiChannelsBlacklist
aux := &struct {
Channel emptyStringInt `json:"channel"`
ChannelWidth emptyStringInt `json:"channel_width"`
*Alias
}{
Alias: (*Alias)(dst),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return fmt.Errorf("unable to unmarshal alias: %w", err)
}
dst.Channel = int(aux.Channel)
dst.ChannelWidth = int(aux.ChannelWidth)
return nil
}
func (c *Client) getSettingRadioAi(ctx context.Context, site string) (*SettingRadioAi, error) {
var respBody struct {
Meta meta `json:"meta"`

View File

@@ -27,17 +27,15 @@ type SettingRsyslogd struct {
Key string `json:"key"`
Contents []string `json:"contents,omitempty"` // device|client|firewall_default_policy|triggers|updates|admin_activity|critical|security_detections|vpn
Debug bool `json:"debug"`
Enabled bool `json:"enabled"`
IP string `json:"ip,omitempty"`
LogAllContents bool `json:"log_all_contents"`
NetconsoleEnabled bool `json:"netconsole_enabled"`
NetconsoleHost string `json:"netconsole_host,omitempty"`
NetconsolePort int `json:"netconsole_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]
Port int `json:"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]
ThisController bool `json:"this_controller"`
ThisControllerEncryptedOnly bool `json:"this_controller_encrypted_only"`
Debug bool `json:"debug"`
Enabled bool `json:"enabled"`
IP string `json:"ip,omitempty"`
NetconsoleEnabled bool `json:"netconsole_enabled"`
NetconsoleHost string `json:"netconsole_host,omitempty"`
NetconsolePort int `json:"netconsole_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]
Port int `json:"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]
ThisController bool `json:"this_controller"`
ThisControllerEncryptedOnly bool `json:"this_controller_encrypted_only"`
}
func (dst *SettingRsyslogd) UnmarshalJSON(b []byte) error {

View File

@@ -27,61 +27,62 @@ type SettingUsg struct {
Key string `json:"key"`
ArpCacheBaseReachable int `json:"arp_cache_base_reachable,omitempty"` // ^$|^[1-9]{1}[0-9]{0,4}$
ArpCacheTimeout string `json:"arp_cache_timeout,omitempty"` // normal|min-dhcp-lease|custom
BroadcastPing bool `json:"broadcast_ping"`
DHCPDHostfileUpdate bool `json:"dhcpd_hostfile_update"`
DHCPDUseDNSmasq bool `json:"dhcpd_use_dnsmasq"`
DHCPRelayAgentsPackets string `json:"dhcp_relay_agents_packets"` // append|discard|forward|replace|^$
DHCPRelayHopCount int `json:"dhcp_relay_hop_count,omitempty"` // ([1-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])|^$
DHCPRelayMaxSize int `json:"dhcp_relay_max_size,omitempty"` // (6[4-9]|[7-9][0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|1[0-3][0-9]{2}|1400)|^$
DHCPRelayPort int `json:"dhcp_relay_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]|^$
DHCPRelayServer1 string `json:"dhcp_relay_server_1"` // ^(([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])$|^$
DHCPRelayServer2 string `json:"dhcp_relay_server_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])$|^$
DHCPRelayServer3 string `json:"dhcp_relay_server_3"` // ^(([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])$|^$
DHCPRelayServer4 string `json:"dhcp_relay_server_4"` // ^(([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])$|^$
DHCPRelayServer5 string `json:"dhcp_relay_server_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])$|^$
DNSVerification SettingUsgDNSVerification `json:"dns_verification,omitempty"`
DNSmasqAllServers bool `json:"dnsmasq_all_servers"`
EchoServer string `json:"echo_server,omitempty"` // [^\"\' ]{1,255}
FtpModule bool `json:"ftp_module"`
GeoIPFilteringBlock string `json:"geo_ip_filtering_block,omitempty"` // block|allow
GeoIPFilteringCountries string `json:"geo_ip_filtering_countries,omitempty"` // ^([A-Z]{2})?(,[A-Z]{2}){0,149}$
GeoIPFilteringEnabled bool `json:"geo_ip_filtering_enabled"`
GeoIPFilteringTrafficDirection string `json:"geo_ip_filtering_traffic_direction,omitempty"` // ^(both|ingress|egress)$
GreModule bool `json:"gre_module"`
H323Module bool `json:"h323_module"`
ICMPTimeout int `json:"icmp_timeout,omitempty"`
LldpEnableAll bool `json:"lldp_enable_all"`
MdnsEnabled bool `json:"mdns_enabled"`
MssClamp string `json:"mss_clamp,omitempty"` // auto|custom|disabled
MssClampMss int `json:"mss_clamp_mss,omitempty"` // [1-9][0-9]{2,3}
OffloadAccounting bool `json:"offload_accounting"`
OffloadL2Blocking bool `json:"offload_l2_blocking"`
OffloadSch bool `json:"offload_sch"`
OtherTimeout int `json:"other_timeout,omitempty"`
PptpModule bool `json:"pptp_module"`
ReceiveRedirects bool `json:"receive_redirects"`
SendRedirects bool `json:"send_redirects"`
SipModule bool `json:"sip_module"`
SynCookies bool `json:"syn_cookies"`
TCPCloseTimeout int `json:"tcp_close_timeout,omitempty"`
TCPCloseWaitTimeout int `json:"tcp_close_wait_timeout,omitempty"`
TCPEstablishedTimeout int `json:"tcp_established_timeout,omitempty"`
TCPFinWaitTimeout int `json:"tcp_fin_wait_timeout,omitempty"`
TCPLastAckTimeout int `json:"tcp_last_ack_timeout,omitempty"`
TCPSynRecvTimeout int `json:"tcp_syn_recv_timeout,omitempty"`
TCPSynSentTimeout int `json:"tcp_syn_sent_timeout,omitempty"`
TCPTimeWaitTimeout int `json:"tcp_time_wait_timeout,omitempty"`
TFTPModule bool `json:"tftp_module"`
TimeoutSettingPreference string `json:"timeout_setting_preference,omitempty"` // auto|manual
UDPOtherTimeout int `json:"udp_other_timeout,omitempty"`
UDPStreamTimeout int `json:"udp_stream_timeout,omitempty"`
UnbindWANMonitors bool `json:"unbind_wan_monitors"`
UpnpEnabled bool `json:"upnp_enabled"`
UpnpNATPmpEnabled bool `json:"upnp_nat_pmp_enabled"`
UpnpSecureMode bool `json:"upnp_secure_mode"`
UpnpWANInterface string `json:"upnp_wan_interface,omitempty"` // WAN|WAN2
ArpCacheBaseReachable int `json:"arp_cache_base_reachable,omitempty"` // ^$|^[1-9]{1}[0-9]{0,4}$
ArpCacheTimeout string `json:"arp_cache_timeout,omitempty"` // normal|min-dhcp-lease|custom
BroadcastPing bool `json:"broadcast_ping"`
DHCPDHostfileUpdate bool `json:"dhcpd_hostfile_update"`
DHCPDUseDNSmasq bool `json:"dhcpd_use_dnsmasq"`
DHCPRelayAgentsPackets string `json:"dhcp_relay_agents_packets"` // append|discard|forward|replace|^$
DHCPRelayHopCount int `json:"dhcp_relay_hop_count,omitempty"` // ([1-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])|^$
DHCPRelayMaxSize int `json:"dhcp_relay_max_size,omitempty"` // (6[4-9]|[7-9][0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|1[0-3][0-9]{2}|1400)|^$
DHCPRelayPort int `json:"dhcp_relay_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]|^$
DHCPRelayServer1 string `json:"dhcp_relay_server_1"` // ^(([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])$|^$
DHCPRelayServer2 string `json:"dhcp_relay_server_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])$|^$
DHCPRelayServer3 string `json:"dhcp_relay_server_3"` // ^(([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])$|^$
DHCPRelayServer4 string `json:"dhcp_relay_server_4"` // ^(([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])$|^$
DHCPRelayServer5 string `json:"dhcp_relay_server_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])$|^$
DNSmasqAllServers bool `json:"dnsmasq_all_servers"`
EchoServer string `json:"echo_server,omitempty"` // [^\"\' ]{1,255}
FirewallGuestDefaultLog bool `json:"firewall_guest_default_log"`
FirewallLanDefaultLog bool `json:"firewall_lan_default_log"`
FirewallWANDefaultLog bool `json:"firewall_wan_default_log"`
FtpModule bool `json:"ftp_module"`
GeoIPFilteringBlock string `json:"geo_ip_filtering_block,omitempty"` // block|allow
GeoIPFilteringCountries string `json:"geo_ip_filtering_countries,omitempty"` // ^([A-Z]{2})?(,[A-Z]{2}){0,149}$
GeoIPFilteringEnabled bool `json:"geo_ip_filtering_enabled"`
GeoIPFilteringTrafficDirection string `json:"geo_ip_filtering_traffic_direction,omitempty"` // ^(both|ingress|egress)$
GreModule bool `json:"gre_module"`
H323Module bool `json:"h323_module"`
ICMPTimeout int `json:"icmp_timeout,omitempty"`
LldpEnableAll bool `json:"lldp_enable_all"`
MdnsEnabled bool `json:"mdns_enabled"`
MssClamp string `json:"mss_clamp,omitempty"` // auto|custom|disabled
MssClampMss int `json:"mss_clamp_mss,omitempty"` // [1-9][0-9]{2,3}
OffloadAccounting bool `json:"offload_accounting"`
OffloadL2Blocking bool `json:"offload_l2_blocking"`
OffloadSch bool `json:"offload_sch"`
OtherTimeout int `json:"other_timeout,omitempty"`
PptpModule bool `json:"pptp_module"`
ReceiveRedirects bool `json:"receive_redirects"`
SendRedirects bool `json:"send_redirects"`
SipModule bool `json:"sip_module"`
SynCookies bool `json:"syn_cookies"`
TCPCloseTimeout int `json:"tcp_close_timeout,omitempty"`
TCPCloseWaitTimeout int `json:"tcp_close_wait_timeout,omitempty"`
TCPEstablishedTimeout int `json:"tcp_established_timeout,omitempty"`
TCPFinWaitTimeout int `json:"tcp_fin_wait_timeout,omitempty"`
TCPLastAckTimeout int `json:"tcp_last_ack_timeout,omitempty"`
TCPSynRecvTimeout int `json:"tcp_syn_recv_timeout,omitempty"`
TCPSynSentTimeout int `json:"tcp_syn_sent_timeout,omitempty"`
TCPTimeWaitTimeout int `json:"tcp_time_wait_timeout,omitempty"`
TFTPModule bool `json:"tftp_module"`
TimeoutSettingPreference string `json:"timeout_setting_preference,omitempty"` // auto|manual
UDPOtherTimeout int `json:"udp_other_timeout,omitempty"`
UDPStreamTimeout int `json:"udp_stream_timeout,omitempty"`
UpnpEnabled bool `json:"upnp_enabled"`
UpnpNATPmpEnabled bool `json:"upnp_nat_pmp_enabled"`
UpnpSecureMode bool `json:"upnp_secure_mode"`
UpnpWANInterface string `json:"upnp_wan_interface,omitempty"` // WAN|WAN2
}
func (dst *SettingUsg) UnmarshalJSON(b []byte) error {
@@ -135,29 +136,6 @@ func (dst *SettingUsg) UnmarshalJSON(b []byte) error {
return nil
}
type SettingUsgDNSVerification struct {
Domain string `json:"domain,omitempty"`
PrimaryDNSServer string `json:"primary_dns_server,omitempty"`
SecondaryDNSServer string `json:"secondary_dns_server,omitempty"`
SettingPreference string `json:"setting_preference,omitempty"` // auto|manual
}
func (dst *SettingUsgDNSVerification) UnmarshalJSON(b []byte) error {
type Alias SettingUsgDNSVerification
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) getSettingUsg(ctx context.Context, site string) (*SettingUsg, error) {
var respBody struct {
Meta meta `json:"meta"`

View File

@@ -190,23 +190,11 @@ func (c *Client) Login(ctx context.Context, user, pass string) error {
return nil
}
func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody any, respBody any) error {
return c.do_versioned(ctx, "V1", method, relativeURL, reqBody, respBody)
}
func (c *Client) do_versioned(ctx context.Context, version, method, relativeURL string, reqBody any, respBody any) error {
func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody interface{}, respBody interface{}) error {
// single threading requests, this is mostly to assist in CSRF token propagation
c.Lock()
defer c.Unlock()
var apiPath string
if version == "V2" {
apiPath = c.apiV2Path
} else {
apiPath = c.apiPath
}
var (
reqReader io.Reader
err error
@@ -225,7 +213,11 @@ func (c *Client) do_versioned(ctx context.Context, version, method, relativeURL
return fmt.Errorf("unable to parse URL: %s %s %w", method, relativeURL, err)
}
if !strings.HasPrefix(relativeURL, "/") && !reqURL.IsAbs() {
reqURL.Path = path.Join(apiPath, reqURL.Path)
if strings.Contains(relativeURL, "firewall/zone") {
reqURL.Path = path.Join(c.apiV2Path, reqURL.Path)
} else {
reqURL.Path = path.Join(c.apiPath, reqURL.Path)
}
}
url := c.baseURL.ResolveReference(reqURL)

View File

@@ -71,8 +71,8 @@ func (c *Client) CreateUser(ctx context.Context, site string, d *User) (*User, e
return &user, nil
}
func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]any) ([]User, error) {
reqBody := map[string]any{}
func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]interface{}) ([]User, error) {
reqBody := map[string]interface{}{}
for k, v := range data {
reqBody[k] = v
@@ -94,7 +94,7 @@ func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]a
}
func (c *Client) BlockUserByMAC(ctx context.Context, site, mac string) error {
users, err := c.stamgr(ctx, site, "block-sta", map[string]any{
users, err := c.stamgr(ctx, site, "block-sta", map[string]interface{}{
"mac": mac,
})
if err != nil {
@@ -107,7 +107,7 @@ func (c *Client) BlockUserByMAC(ctx context.Context, site, mac string) error {
}
func (c *Client) UnblockUserByMAC(ctx context.Context, site, mac string) error {
users, err := c.stamgr(ctx, site, "unblock-sta", map[string]any{
users, err := c.stamgr(ctx, site, "unblock-sta", map[string]interface{}{
"mac": mac,
})
if err != nil {
@@ -120,7 +120,7 @@ func (c *Client) UnblockUserByMAC(ctx context.Context, site, mac string) error {
}
func (c *Client) DeleteUserByMAC(ctx context.Context, site, mac string) error {
users, err := c.stamgr(ctx, site, "forget-sta", map[string]any{
users, err := c.stamgr(ctx, site, "forget-sta", map[string]interface{}{
"macs": []string{mac},
})
if err != nil {
@@ -133,7 +133,7 @@ func (c *Client) DeleteUserByMAC(ctx context.Context, site, mac string) error {
}
func (c *Client) KickUserByMAC(ctx context.Context, site, mac string) error {
users, err := c.stamgr(ctx, site, "kick-sta", map[string]any{
users, err := c.stamgr(ctx, site, "kick-sta", map[string]interface{}{
"mac": mac,
})
if err != nil {
@@ -146,7 +146,7 @@ func (c *Client) KickUserByMAC(ctx context.Context, site, mac string) error {
}
func (c *Client) OverrideUserFingerprint(ctx context.Context, site, mac string, devIdOveride int) error {
reqBody := map[string]any{
reqBody := map[string]interface{}{
"mac": mac,
"dev_id_override": devIdOveride,
"search_query": "",

View File

@@ -2,4 +2,4 @@
package unifi
const UnifiVersion = "9.0.114"
const UnifiVersion = "8.3.32"

230
unifi/wlan.generated.go generated
View File

@@ -41,12 +41,11 @@ type WLAN struct {
DTIMNg int `json:"dtim_ng,omitempty"` // ^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^$
ElementAdopt bool `json:"element_adopt"`
Enabled bool `json:"enabled"`
EnhancedIot bool `json:"enhanced_iot"`
FastRoamingEnabled bool `json:"fast_roaming_enabled"`
GroupRekey int `json:"group_rekey,omitempty"` // ^(0|[6-9][0-9]|[1-9][0-9]{2,3}|[1-7][0-9]{4}|8[0-5][0-9]{3}|86[0-3][0-9][0-9]|86400)$
HideSSID bool `json:"hide_ssid"`
Hotspot2 WLANHotspot2 `json:"hotspot2,omitempty"`
Hotspot2ConfEnabled bool `json:"hotspot2conf_enabled"`
Hotspot2ConfID string `json:"hotspot2conf_id"`
IappEnabled bool `json:"iapp_enabled"`
IsGuest bool `json:"is_guest"`
L2Isolation bool `json:"l2_isolation"`
@@ -66,8 +65,6 @@ type WLAN struct {
Name string `json:"name,omitempty"` // .{1,32}
NameCombineEnabled bool `json:"name_combine_enabled"`
NameCombineSuffix string `json:"name_combine_suffix,omitempty"` // .{0,8}
NasIDentifier string `json:"nas_identifier,omitempty"` // .{0,48}
NasIDentifierType string `json:"nas_identifier_type,omitempty"` // ap_name|ap_mac|bssid|site_name|custom
NetworkID string `json:"networkconf_id"`
No2GhzOui bool `json:"no2ghz_oui"`
OptimizeIotWifiConnectivity bool `json:"optimize_iot_wifi_connectivity"`
@@ -163,188 +160,6 @@ func (dst *WLAN) UnmarshalJSON(b []byte) error {
return nil
}
type WLANCapab struct {
Port int `json:"port,omitempty"` // ^(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])|$
Protocol string `json:"protocol,omitempty"` // icmp|tcp_udp|tcp|udp|esp
Status string `json:"status,omitempty"` // closed|open|unknown
}
func (dst *WLANCapab) UnmarshalJSON(b []byte) error {
type Alias WLANCapab
aux := &struct {
Port emptyStringInt `json:"port"`
*Alias
}{
Alias: (*Alias)(dst),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return fmt.Errorf("unable to unmarshal alias: %w", err)
}
dst.Port = int(aux.Port)
return nil
}
type WLANCellularNetworkList struct {
CountryCode int `json:"country_code,omitempty"` // [1-9]{1}[0-9]{0,3}
Mcc int `json:"mcc,omitempty"`
Mnc int `json:"mnc,omitempty"`
Name string `json:"name,omitempty"` // .{1,128}
}
func (dst *WLANCellularNetworkList) UnmarshalJSON(b []byte) error {
type Alias WLANCellularNetworkList
aux := &struct {
CountryCode emptyStringInt `json:"country_code"`
Mcc emptyStringInt `json:"mcc"`
Mnc emptyStringInt `json:"mnc"`
*Alias
}{
Alias: (*Alias)(dst),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return fmt.Errorf("unable to unmarshal alias: %w", err)
}
dst.CountryCode = int(aux.CountryCode)
dst.Mcc = int(aux.Mcc)
dst.Mnc = int(aux.Mnc)
return nil
}
type WLANFriendlyName struct {
Language string `json:"language,omitempty"` // [a-z]{3}
Text string `json:"text,omitempty"` // .{1,128}
}
func (dst *WLANFriendlyName) UnmarshalJSON(b []byte) error {
type Alias WLANFriendlyName
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 WLANHotspot2 struct {
Capab []WLANCapab `json:"capab,omitempty"`
CellularNetworkList []WLANCellularNetworkList `json:"cellular_network_list,omitempty"`
DomainNameList []string `json:"domain_name_list,omitempty"` // .{1,128}
FriendlyName []WLANFriendlyName `json:"friendly_name,omitempty"`
IPaddrTypeAvailV4 int `json:"ipaddr_type_avail_v4,omitempty"` // 0|1|2|3|4|5|6|7
IPaddrTypeAvailV6 int `json:"ipaddr_type_avail_v6,omitempty"` // 0|1|2
MetricsDownlinkLoad int `json:"metrics_downlink_load,omitempty"`
MetricsDownlinkLoadSet bool `json:"metrics_downlink_load_set"`
MetricsDownlinkSpeed int `json:"metrics_downlink_speed,omitempty"`
MetricsDownlinkSpeedSet bool `json:"metrics_downlink_speed_set"`
MetricsInfoAtCapacity bool `json:"metrics_info_at_capacity"`
MetricsInfoLinkStatus string `json:"metrics_info_link_status,omitempty"` // up|down|test
MetricsInfoSymmetric bool `json:"metrics_info_symmetric"`
MetricsMeasurement int `json:"metrics_measurement,omitempty"`
MetricsMeasurementSet bool `json:"metrics_measurement_set"`
MetricsStatus bool `json:"metrics_status"`
MetricsUplinkLoad int `json:"metrics_uplink_load,omitempty"`
MetricsUplinkLoadSet bool `json:"metrics_uplink_load_set"`
MetricsUplinkSpeed int `json:"metrics_uplink_speed,omitempty"`
MetricsUplinkSpeedSet bool `json:"metrics_uplink_speed_set"`
NaiRealmList []WLANNaiRealmList `json:"nai_realm_list,omitempty"`
NetworkType int `json:"network_type,omitempty"` // 0|1|2|3|4|5|14|15
RoamingConsortiumList []WLANRoamingConsortiumList `json:"roaming_consortium_list,omitempty"`
VenueGroup int `json:"venue_group,omitempty"` // 0|1|2|3|4|5|6|7|8|9|10|11
VenueName []WLANVenueName `json:"venue_name,omitempty"`
VenueType int `json:"venue_type,omitempty"` // 0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15
}
func (dst *WLANHotspot2) UnmarshalJSON(b []byte) error {
type Alias WLANHotspot2
aux := &struct {
IPaddrTypeAvailV4 emptyStringInt `json:"ipaddr_type_avail_v4"`
IPaddrTypeAvailV6 emptyStringInt `json:"ipaddr_type_avail_v6"`
MetricsDownlinkLoad emptyStringInt `json:"metrics_downlink_load"`
MetricsDownlinkSpeed emptyStringInt `json:"metrics_downlink_speed"`
MetricsMeasurement emptyStringInt `json:"metrics_measurement"`
MetricsUplinkLoad emptyStringInt `json:"metrics_uplink_load"`
MetricsUplinkSpeed emptyStringInt `json:"metrics_uplink_speed"`
NetworkType emptyStringInt `json:"network_type"`
VenueGroup emptyStringInt `json:"venue_group"`
VenueType emptyStringInt `json:"venue_type"`
*Alias
}{
Alias: (*Alias)(dst),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return fmt.Errorf("unable to unmarshal alias: %w", err)
}
dst.IPaddrTypeAvailV4 = int(aux.IPaddrTypeAvailV4)
dst.IPaddrTypeAvailV6 = int(aux.IPaddrTypeAvailV6)
dst.MetricsDownlinkLoad = int(aux.MetricsDownlinkLoad)
dst.MetricsDownlinkSpeed = int(aux.MetricsDownlinkSpeed)
dst.MetricsMeasurement = int(aux.MetricsMeasurement)
dst.MetricsUplinkLoad = int(aux.MetricsUplinkLoad)
dst.MetricsUplinkSpeed = int(aux.MetricsUplinkSpeed)
dst.NetworkType = int(aux.NetworkType)
dst.VenueGroup = int(aux.VenueGroup)
dst.VenueType = int(aux.VenueType)
return nil
}
type WLANNaiRealmList struct {
AuthIDs []int `json:"auth_ids,omitempty"` // 0|1|2|3|4|5
AuthVals []int `json:"auth_vals,omitempty"` // 0|1|2|3|4|5|6|7|8|9|10
EapMethod int `json:"eap_method,omitempty"` // 13|21|18|23|50
Encoding int `json:"encoding,omitempty"` // 0|1
Name string `json:"name,omitempty"` // .{1,128}
Status bool `json:"status"`
}
func (dst *WLANNaiRealmList) UnmarshalJSON(b []byte) error {
type Alias WLANNaiRealmList
aux := &struct {
AuthIDs []emptyStringInt `json:"auth_ids"`
AuthVals []emptyStringInt `json:"auth_vals"`
EapMethod emptyStringInt `json:"eap_method"`
Encoding emptyStringInt `json:"encoding"`
*Alias
}{
Alias: (*Alias)(dst),
}
err := json.Unmarshal(b, &aux)
if err != nil {
return fmt.Errorf("unable to unmarshal alias: %w", err)
}
dst.AuthIDs = make([]int, len(aux.AuthIDs))
for i, v := range aux.AuthIDs {
dst.AuthIDs[i] = int(v)
}
dst.AuthVals = make([]int, len(aux.AuthVals))
for i, v := range aux.AuthVals {
dst.AuthVals[i] = int(v)
}
dst.EapMethod = int(aux.EapMethod)
dst.Encoding = int(aux.Encoding)
return nil
}
type WLANPrivatePresharedKeys struct {
NetworkID string `json:"networkconf_id"`
Password string `json:"password,omitempty"` // [\x20-\x7E]{8,255}
@@ -366,27 +181,6 @@ func (dst *WLANPrivatePresharedKeys) UnmarshalJSON(b []byte) error {
return nil
}
type WLANRoamingConsortiumList struct {
Name string `json:"name,omitempty"` // .{1,128}
Oid string `json:"oid,omitempty"` // .{1,128}
}
func (dst *WLANRoamingConsortiumList) UnmarshalJSON(b []byte) error {
type Alias WLANRoamingConsortiumList
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 WLANSaePsk struct {
ID string `json:"id"` // .{0,128}
MAC string `json:"mac,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$
@@ -444,28 +238,6 @@ func (dst *WLANScheduleWithDuration) UnmarshalJSON(b []byte) error {
return nil
}
type WLANVenueName struct {
Language string `json:"language,omitempty"` // [a-z]{0,3}
Name string `json:"name,omitempty"`
Url string `json:"url,omitempty"`
}
func (dst *WLANVenueName) UnmarshalJSON(b []byte) error {
type Alias WLANVenueName
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) listWLAN(ctx context.Context, site string) ([]WLAN, error) {
var respBody struct {
Meta meta `json:"meta"`