Compare commits

..

24 Commits

Author SHA1 Message Date
32e66e46da more omit 2025-04-18 19:58:47 +02:00
9a6bf18774 more omit 2025-04-18 19:31:40 +02:00
c4acd30bfb More omitempty 2025-04-18 11:38:50 +02:00
3a991266a1 More omitempty 2025-04-18 11:35:19 +02:00
ad412ef42b More omitempty 2025-04-18 11:29:17 +02:00
e72621290e More omitempty 2025-04-18 11:19:41 +02:00
42434bf718 omitempty for NetworkIDs in destination 2025-04-18 11:17:01 +02:00
abe6ce09b2 omitempty for NetworkIDs in destination 2025-04-18 11:12:52 +02:00
d008cac359 typo 2025-04-17 11:57:05 +02:00
96cf5ac987 follow casing conventions 2025-04-17 10:35:49 +02:00
d83c354874 Missing field 2025-04-17 10:20:27 +02:00
861a985dd0 Remove some anonymous structs 2025-04-17 10:08:03 +02:00
e5b81b217f Create firewall policy 2025-04-17 02:11:29 +02:00
0e9e9cb8a3 Merge pull request #15 from vegardengen/14-support-firewall-zones
Support firewall zones
2025-04-14 12:39:39 +02:00
42d7f4131b Support firewall zones 2025-04-14 12:38:46 +02:00
be515d2e6f Merge pull request #13 from vegardengen/12-support-v2-network-api
Add do_versioned and make do wrap do_versioned
2025-04-14 12:35:44 +02:00
ec43083868 Add do_versioned and make do wrap do_versioned 2025-04-14 12:32:13 +02:00
babe9757a6 Merge pull request #11 from vegardengen/10-fix-module-name
Switch to my branch
2025-04-14 12:19:20 +02:00
225c79703f Switch to my branch 2025-04-14 12:17:32 +02:00
b0d58766fc Merge pull request #9 from vegardengen/8-fix-ipsec-lifetimes
Change ipsec lifetimes to int
2025-04-14 12:08:32 +02:00
8721daf90a Change ipsec lifetimes to int 2025-04-14 12:08:08 +02:00
14f0897119 Merge pull request #7 from vegardengen/6-update-to-90114
Update to network version 9.0.114
2025-04-14 12:04:17 +02:00
bce4a5bdfd Update to network version 9.0.114 2025-04-14 12:03:26 +02:00
appkins
73d68d5ac1 Update IPSecESPLifetime 2025-04-13 22:23:08 -05:00
25 changed files with 864 additions and 259 deletions

View File

@@ -139,7 +139,7 @@ func extractJSON(jarFile, fieldsDir string) error {
return fmt.Errorf("unable to open settings file: %w", err) return fmt.Errorf("unable to open settings file: %w", err)
} }
var settings map[string]interface{} var settings map[string]any
err = json.Unmarshal(settingsData, &settings) err = json.Unmarshal(settingsData, &settings)
if err != nil { if err != nil {
return fmt.Errorf("unable to unmarshal settings: %w", err) 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 { func (l *firmwareUpdateApiResponseEmbeddedFirmwareDataLink) UnmarshalJSON(j []byte) error {
var m map[string]interface{} var m map[string]any
err := json.Unmarshal(j, &m) err := json.Unmarshal(j, &m)
if err != nil { if err != nil {

View File

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

View File

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

View File

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

View File

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

141
unifi/firewall_policy.go Normal file
View File

@@ -0,0 +1,141 @@
package unifi
import (
"context"
"fmt"
)
type FirewallDestination struct {
IPGroupID string `json:"ip_group_id"`
IPs []string `json:"ips,omitempty"`
MatchOppositeIPs bool `json:"match_opposite_ips"`
MatchOppositePorts bool `json:"match_opposite_ports"`
MatchingTarget string `json:"matching_target"`
MatchingTargetType string `json:"matching_target_type"`
NetworkIDs [] string `json:"network_ids,omitempty"`
Port string `json:"port,omitempty"`
PortGroupID string `json:"port_group_id"`
PortMatchingType string `json:"port_matching_type"`
Regions []string `json:"regions,omitempty"`
ZoneID string `json:"zone_id"`
}
type FirewallSource struct {
ClientMacs []string `json:"client_macs,omitempty"`
IPs []string `json:"ips,omitempty"`
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,omitempty"`
MatchingTargetType string `json:"matching_target_type,omitempty"`
NetworkIDs []string `json:"network_ids,omitempty"`
Port string `json:"port,omitempty"`
PortMatchingType string `json:"port_matching_type,omitempty"`
ZoneID string `json:"zone_id,omitempty"`
}
type FirewallSchedule struct {
Mode string `json:"mode"`
DateStart string `json:"date_start,omitempty"`
DateEnd string `json:"date_end,omitempty"`
RepeatOnDays []string `json:"repeat_on_days"`
TimeAllDay bool `json:"time_all_day"`
TimeRangeStart string `json:"time_range_start,omitempty"`
TimeRangeEnd string `json:"time_range_end,omitempty"`
}
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 FirewallDestination `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,omitempty"`
MatchOppositeProtocol bool `json:"match_opposite_protocol"`
Name string `json:"name"`
OriginID string `json:"origin_id,omitempty"`
OriginType string `json:"origin_type,omitempty"`
Predefined bool `json:"predefined"`
Protocol string `json:"protocol"`
Schedule FirewallSchedule `json:"schedule"`
Source FirewallSource `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) CreateFirewallPolicy(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,7 +26,6 @@ type FirewallRule struct {
NoEdit bool `json:"attr_no_edit,omitempty"` NoEdit bool `json:"attr_no_edit,omitempty"`
Action string `json:"action,omitempty"` // drop|reject|accept Action string `json:"action,omitempty"` // drop|reject|accept
Contiguous bool `json:"contiguous"`
DstAddress string `json:"dst_address,omitempty"` DstAddress string `json:"dst_address,omitempty"`
DstAddressIPV6 string `json:"dst_address_ipv6,omitempty"` DstAddressIPV6 string `json:"dst_address_ipv6,omitempty"`
DstFirewallGroupIDs []string `json:"dst_firewallgroup_ids,omitempty"` // [\d\w]+ DstFirewallGroupIDs []string `json:"dst_firewallgroup_ids,omitempty"` // [\d\w]+
@@ -38,8 +37,6 @@ 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 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|^$ IPSec string `json:"ipsec"` // match-ipsec|match-none|^$
Logging bool `json:"logging"` 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} 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 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"` ProtocolMatchExcepted bool `json:"protocol_match_excepted"`
@@ -54,17 +51,10 @@ type FirewallRule struct {
SrcNetworkID string `json:"src_networkconf_id"` // [\d\w]+|^$ SrcNetworkID string `json:"src_networkconf_id"` // [\d\w]+|^$
SrcNetworkType string `json:"src_networkconf_type,omitempty"` // ADDRv4|NETv4 SrcNetworkType string `json:"src_networkconf_type,omitempty"` // ADDRv4|NETv4
SrcPort string `json:"src_port,omitempty"` 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"` StateEstablished bool `json:"state_established"`
StateInvalid bool `json:"state_invalid"` StateInvalid bool `json:"state_invalid"`
StateNew bool `json:"state_new"` StateNew bool `json:"state_new"`
StateRelated bool `json:"state_related"` 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 { func (dst *FirewallRule) UnmarshalJSON(b []byte) error {

View File

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

View File

@@ -75,15 +75,18 @@ 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} 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"` Enabled bool `json:"enabled"`
ExposedToSiteVPN bool `json:"exposed_to_site_vpn"` 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})$) GatewayDevice string `json:"gateway_device"` // (^$|^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$)
GatewayType string `json:"gateway_type,omitempty"` // default|switch GatewayType string `json:"gateway_type,omitempty"` // default|switch
IGMPFastleave bool `json:"igmp_fastleave"` 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|^$ 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]|^$ 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|^$ 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|^$
IGMPProxyDownstream bool `json:"igmp_proxy_downstream"` IGMPProxyDownstreamNetworkIDs []string `json:"igmp_proxy_downstream_networkconf_ids,omitempty"`
IGMPProxyFor string `json:"igmp_proxy_for,omitempty"` // all|some|none
IGMPProxyUpstream bool `json:"igmp_proxy_upstream"` IGMPProxyUpstream bool `json:"igmp_proxy_upstream"`
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])$|^$ IGMPQuerierSwitches []NetworkIGMPQuerierSwitches `json:"igmp_querier_switches,omitempty"`
IGMPSnooping bool `json:"igmp_snooping"` IGMPSnooping bool `json:"igmp_snooping"`
IGMPSupression bool `json:"igmp_supression"` IGMPSupression bool `json:"igmp_supression"`
IPSecDhGroup int `json:"ipsec_dh_group,omitempty"` // 2|5|14|15|16|19|20|21|25|26 IPSecDhGroup int `json:"ipsec_dh_group,omitempty"` // 2|5|14|15|16|19|20|21|25|26
@@ -126,13 +129,12 @@ type Network struct {
IPV6SettingPreference string `json:"ipv6_setting_preference,omitempty"` // auto|manual IPV6SettingPreference string `json:"ipv6_setting_preference,omitempty"` // auto|manual
IPV6SingleNetworkInterface string `json:"ipv6_single_network_interface,omitempty"` IPV6SingleNetworkInterface string `json:"ipv6_single_network_interface,omitempty"`
IPV6Subnet string `json:"ipv6_subnet,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 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)$ 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"` InterfaceMtuEnabled bool `json:"interface_mtu_enabled"`
InternetAccessEnabled bool `json:"internet_access_enabled"` InternetAccessEnabled bool `json:"internet_access_enabled"`
IsNAT bool `json:"is_nat"` IsNAT bool `json:"is_nat"`
L4TpAllowWeakCiphers bool `json:"l2tp_allow_weak_ciphers"` L2TpAllowWeakCiphers bool `json:"l2tp_allow_weak_ciphers"`
L2TpInterface string `json:"l2tp_interface,omitempty"` // wan|wan2 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])$ 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])$ 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])$
@@ -169,7 +171,8 @@ 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])$|^$ 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"` ReportWANEvent bool `json:"report_wan_event"`
RequireMschapv2 bool `json:"require_mschapv2"` 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]$|^$ 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"`
SettingPreference string `json:"setting_preference,omitempty"` // auto|manual SettingPreference string `json:"setting_preference,omitempty"` // auto|manual
SingleNetworkLan string `json:"single_network_lan,omitempty"` SingleNetworkLan string `json:"single_network_lan,omitempty"`
UidPolicyEnabled bool `json:"uid_policy_enabled"` UidPolicyEnabled bool `json:"uid_policy_enabled"`
@@ -193,7 +196,7 @@ type Network struct {
VPNClientDefaultRoute bool `json:"vpn_client_default_route"` VPNClientDefaultRoute bool `json:"vpn_client_default_route"`
VPNClientPullDNS bool `json:"vpn_client_pull_dns"` VPNClientPullDNS bool `json:"vpn_client_pull_dns"`
VPNProtocol string `json:"vpn_protocol,omitempty"` // TCP|UDP 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|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|sdwan-hub-spoke-tunnel|sdwan-mesh-tunnel|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)$ 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)$ 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] VrrpVrid int `json:"vrrp_vrid,omitempty"` // [1-9]|[1-9][0-9]
@@ -339,6 +342,27 @@ func (dst *Network) UnmarshalJSON(b []byte) error {
return nil 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 { 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])$|^$ 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])$ 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])$
@@ -422,7 +446,7 @@ func (c *Client) listNetwork(ctx context.Context, site string) ([]Network, error
if err != nil { if err != nil {
return nil, err return nil, err
} }
fmt.Printf("%+v",respBody.Data)
return respBody.Data, nil return respBody.Data, nil
} }

View File

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

View File

@@ -25,16 +25,23 @@ type RADIUSProfile struct {
NoDelete bool `json:"attr_no_delete,omitempty"` NoDelete bool `json:"attr_no_delete,omitempty"`
NoEdit bool `json:"attr_no_edit,omitempty"` NoEdit bool `json:"attr_no_edit,omitempty"`
AccountingEnabled bool `json:"accounting_enabled"` AccountingEnabled bool `json:"accounting_enabled"`
AcctServers []RADIUSProfileAcctServers `json:"acct_servers,omitempty"` AcctServers []RADIUSProfileAcctServers `json:"acct_servers,omitempty"`
AuthServers []RADIUSProfileAuthServers `json:"auth_servers,omitempty"` AuthServers []RADIUSProfileAuthServers `json:"auth_servers,omitempty"`
InterimUpdateEnabled bool `json:"interim_update_enabled"` 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)$ 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} Name string `json:"name,omitempty"` // .{1,128}
UseUsgAcctServer bool `json:"use_usg_acct_server"` TlsEnabled bool `json:"tls_enabled"`
UseUsgAuthServer bool `json:"use_usg_auth_server"` UseUsgAcctServer bool `json:"use_usg_acct_server"`
VLANEnabled bool `json:"vlan_enabled"` UseUsgAuthServer bool `json:"use_usg_auth_server"`
VLANWLANMode string `json:"vlan_wlan_mode,omitempty"` // disabled|optional|required 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"`
} }
func (dst *RADIUSProfile) UnmarshalJSON(b []byte) error { func (dst *RADIUSProfile) UnmarshalJSON(b []byte) error {
@@ -106,6 +113,27 @@ func (dst *RADIUSProfileAuthServers) UnmarshalJSON(b []byte) error {
return nil 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) { func (c *Client) listRADIUSProfile(ctx context.Context, site string) ([]RADIUSProfile, error) {
var respBody struct { var respBody struct {
Meta meta `json:"meta"` Meta meta `json:"meta"`

View File

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

View File

@@ -27,7 +27,7 @@ type SettingDashboard struct {
Key string `json:"key"` Key string `json:"key"`
LayoutPreference string `json:"layout_preference,omitempty"` // auto|custom LayoutPreference string `json:"layout_preference,omitempty"` // auto|manual
Widgets []SettingDashboardWidgets `json:"widgets,omitempty"` Widgets []SettingDashboardWidgets `json:"widgets,omitempty"`
} }
@@ -48,7 +48,8 @@ func (dst *SettingDashboard) UnmarshalJSON(b []byte) error {
} }
type SettingDashboardWidgets struct { type SettingDashboardWidgets struct {
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 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
} }
func (dst *SettingDashboardWidgets) UnmarshalJSON(b []byte) error { func (dst *SettingDashboardWidgets) UnmarshalJSON(b []byte) error {

View File

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

View File

@@ -29,16 +29,15 @@ type SettingIps struct {
AdBlockingConfigurations []SettingIpsAdBlockingConfigurations `json:"ad_blocking_configurations,omitempty"` AdBlockingConfigurations []SettingIpsAdBlockingConfigurations `json:"ad_blocking_configurations,omitempty"`
AdBlockingEnabled bool `json:"ad_blocking_enabled"` AdBlockingEnabled bool `json:"ad_blocking_enabled"`
AdvancedFilteringPreference string `json:"advanced_filtering_preference,omitempty"` // |auto|manual|disabled AdvancedFilteringPreference string `json:"advanced_filtering_preference,omitempty"` // |manual|disabled
DNSFiltering bool `json:"dns_filtering"` DNSFiltering bool `json:"dns_filtering"`
DNSFilters []SettingIpsDNSFilters `json:"dns_filters,omitempty"` 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-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 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
EnabledNetworks []string `json:"enabled_networks,omitempty"` EnabledNetworks []string `json:"enabled_networks,omitempty"`
Honeypot []SettingIpsHoneypot `json:"honeypot,omitempty"` Honeypot []SettingIpsHoneypot `json:"honeypot,omitempty"`
HoneypotEnabled bool `json:"honeypot_enabled"` HoneypotEnabled bool `json:"honeypot_enabled"`
IPsMode string `json:"ips_mode,omitempty"` // ids|ips|ipsInline|disabled IPsMode string `json:"ips_mode,omitempty"` // ids|ips|ipsInline|disabled
RestrictIPAddresses bool `json:"restrict_ip_addresses"` MemoryOptimized bool `json:"memory_optimized"`
RestrictTor bool `json:"restrict_tor"`
RestrictTorrents bool `json:"restrict_torrents"` RestrictTorrents bool `json:"restrict_torrents"`
Suppression SettingIpsSuppression `json:"suppression,omitempty"` Suppression SettingIpsSuppression `json:"suppression,omitempty"`
} }

110
unifi/setting_netflow.generated.go generated Normal file
View File

@@ -0,0 +1,110 @@
// 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
}

16
unifi/setting_netflow.go Normal file
View File

@@ -0,0 +1,16 @@
// 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,20 +27,21 @@ type SettingRadioAi struct {
Key string `json:"key"` Key string `json:"key"`
AutoAdjustChannelsToCountry bool `json:"auto_adjust_channels_to_country"` 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 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 ChannelsBlacklist []SettingRadioAiChannelsBlacklist `json:"channels_blacklist,omitempty"`
ChannelsNg []int `json:"channels_ng,omitempty"` // 1|2|3|4|5|6|7|8|9|10|11|12|13|14 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
CronExpr string `json:"cron_expr,omitempty"` ChannelsNg []int `json:"channels_ng,omitempty"` // 1|2|3|4|5|6|7|8|9|10|11|12|13|14
Default bool `json:"default"` CronExpr string `json:"cron_expr,omitempty"`
Enabled bool `json:"enabled"` Default bool `json:"default"`
ExcludeDevices []string `json:"exclude_devices,omitempty"` // ([0-9a-z]{2}:){5}[0-9a-z]{2} Enabled bool `json:"enabled"`
HtModesNa []int `json:"ht_modes_na,omitempty"` // ^(20|40|80|160)$ ExcludeDevices []string `json:"exclude_devices,omitempty"` // ([0-9a-z]{2}:){5}[0-9a-z]{2}
HtModesNg []int `json:"ht_modes_ng,omitempty"` // ^(20|40)$ HtModesNa []int `json:"ht_modes_na,omitempty"` // ^(20|40|80|160)$
Optimize []string `json:"optimize,omitempty"` // channel|power HtModesNg []int `json:"ht_modes_ng,omitempty"` // ^(20|40)$
Radios []string `json:"radios,omitempty"` // na|ng Optimize []string `json:"optimize,omitempty"` // channel|power
SettingPreference string `json:"setting_preference,omitempty"` // auto|manual Radios []string `json:"radios,omitempty"` // na|ng
UseXy bool `json:"useXY"` SettingPreference string `json:"setting_preference,omitempty"` // auto|manual
UseXy bool `json:"useXY"`
} }
func (dst *SettingRadioAi) UnmarshalJSON(b []byte) error { func (dst *SettingRadioAi) UnmarshalJSON(b []byte) error {
@@ -85,6 +86,33 @@ func (dst *SettingRadioAi) UnmarshalJSON(b []byte) error {
return nil 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) { func (c *Client) getSettingRadioAi(ctx context.Context, site string) (*SettingRadioAi, error) {
var respBody struct { var respBody struct {
Meta meta `json:"meta"` Meta meta `json:"meta"`

View File

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

View File

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

View File

@@ -190,11 +190,23 @@ func (c *Client) Login(ctx context.Context, user, pass string) error {
return nil return nil
} }
func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody interface{}, respBody interface{}) error { 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 {
// single threading requests, this is mostly to assist in CSRF token propagation // single threading requests, this is mostly to assist in CSRF token propagation
c.Lock() c.Lock()
defer c.Unlock() defer c.Unlock()
var apiPath string
if version == "V2" {
apiPath = c.apiV2Path
} else {
apiPath = c.apiPath
}
var ( var (
reqReader io.Reader reqReader io.Reader
err error err error
@@ -213,11 +225,7 @@ func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody int
return fmt.Errorf("unable to parse URL: %s %s %w", method, relativeURL, err) return fmt.Errorf("unable to parse URL: %s %s %w", method, relativeURL, err)
} }
if !strings.HasPrefix(relativeURL, "/") && !reqURL.IsAbs() { if !strings.HasPrefix(relativeURL, "/") && !reqURL.IsAbs() {
if strings.Contains(relativeURL, "firewall/zone") { reqURL.Path = path.Join(apiPath, reqURL.Path)
reqURL.Path = path.Join(c.apiV2Path, reqURL.Path)
} else {
reqURL.Path = path.Join(c.apiPath, reqURL.Path)
}
} }
url := c.baseURL.ResolveReference(reqURL) 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 return &user, nil
} }
func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]interface{}) ([]User, error) { func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]any) ([]User, error) {
reqBody := map[string]interface{}{} reqBody := map[string]any{}
for k, v := range data { for k, v := range data {
reqBody[k] = v reqBody[k] = v
@@ -94,7 +94,7 @@ func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]i
} }
func (c *Client) BlockUserByMAC(ctx context.Context, site, mac string) error { func (c *Client) BlockUserByMAC(ctx context.Context, site, mac string) error {
users, err := c.stamgr(ctx, site, "block-sta", map[string]interface{}{ users, err := c.stamgr(ctx, site, "block-sta", map[string]any{
"mac": mac, "mac": mac,
}) })
if err != nil { 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 { func (c *Client) UnblockUserByMAC(ctx context.Context, site, mac string) error {
users, err := c.stamgr(ctx, site, "unblock-sta", map[string]interface{}{ users, err := c.stamgr(ctx, site, "unblock-sta", map[string]any{
"mac": mac, "mac": mac,
}) })
if err != nil { 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 { func (c *Client) DeleteUserByMAC(ctx context.Context, site, mac string) error {
users, err := c.stamgr(ctx, site, "forget-sta", map[string]interface{}{ users, err := c.stamgr(ctx, site, "forget-sta", map[string]any{
"macs": []string{mac}, "macs": []string{mac},
}) })
if err != nil { 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 { func (c *Client) KickUserByMAC(ctx context.Context, site, mac string) error {
users, err := c.stamgr(ctx, site, "kick-sta", map[string]interface{}{ users, err := c.stamgr(ctx, site, "kick-sta", map[string]any{
"mac": mac, "mac": mac,
}) })
if err != nil { 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 { func (c *Client) OverrideUserFingerprint(ctx context.Context, site, mac string, devIdOveride int) error {
reqBody := map[string]interface{}{ reqBody := map[string]any{
"mac": mac, "mac": mac,
"dev_id_override": devIdOveride, "dev_id_override": devIdOveride,
"search_query": "", "search_query": "",

View File

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

230
unifi/wlan.generated.go generated
View File

@@ -41,11 +41,12 @@ 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])$|^$ 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"` ElementAdopt bool `json:"element_adopt"`
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
EnhancedIot bool `json:"enhanced_iot"`
FastRoamingEnabled bool `json:"fast_roaming_enabled"` 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)$ 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"` HideSSID bool `json:"hide_ssid"`
Hotspot2 WLANHotspot2 `json:"hotspot2,omitempty"`
Hotspot2ConfEnabled bool `json:"hotspot2conf_enabled"` Hotspot2ConfEnabled bool `json:"hotspot2conf_enabled"`
Hotspot2ConfID string `json:"hotspot2conf_id"`
IappEnabled bool `json:"iapp_enabled"` IappEnabled bool `json:"iapp_enabled"`
IsGuest bool `json:"is_guest"` IsGuest bool `json:"is_guest"`
L2Isolation bool `json:"l2_isolation"` L2Isolation bool `json:"l2_isolation"`
@@ -65,6 +66,8 @@ type WLAN struct {
Name string `json:"name,omitempty"` // .{1,32} Name string `json:"name,omitempty"` // .{1,32}
NameCombineEnabled bool `json:"name_combine_enabled"` NameCombineEnabled bool `json:"name_combine_enabled"`
NameCombineSuffix string `json:"name_combine_suffix,omitempty"` // .{0,8} 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"` NetworkID string `json:"networkconf_id"`
No2GhzOui bool `json:"no2ghz_oui"` No2GhzOui bool `json:"no2ghz_oui"`
OptimizeIotWifiConnectivity bool `json:"optimize_iot_wifi_connectivity"` OptimizeIotWifiConnectivity bool `json:"optimize_iot_wifi_connectivity"`
@@ -160,6 +163,188 @@ func (dst *WLAN) UnmarshalJSON(b []byte) error {
return nil 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 { type WLANPrivatePresharedKeys struct {
NetworkID string `json:"networkconf_id"` NetworkID string `json:"networkconf_id"`
Password string `json:"password,omitempty"` // [\x20-\x7E]{8,255} Password string `json:"password,omitempty"` // [\x20-\x7E]{8,255}
@@ -181,6 +366,27 @@ func (dst *WLANPrivatePresharedKeys) UnmarshalJSON(b []byte) error {
return nil 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 { type WLANSaePsk struct {
ID string `json:"id"` // .{0,128} ID string `json:"id"` // .{0,128}
MAC string `json:"mac,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$ MAC string `json:"mac,omitempty"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$
@@ -238,6 +444,28 @@ func (dst *WLANScheduleWithDuration) UnmarshalJSON(b []byte) error {
return nil 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) { func (c *Client) listWLAN(ctx context.Context, site string) ([]WLAN, error) {
var respBody struct { var respBody struct {
Meta meta `json:"meta"` Meta meta `json:"meta"`