From 435ecf9d6f665d0f9842c69913c8f346f18c9287 Mon Sep 17 00:00:00 2001 From: Paul Tyng Date: Fri, 10 Jan 2020 14:31:12 -0500 Subject: [PATCH] Initial version Extracted from paultyng/terraform-provider-unifi@ef25893f14578a8f45c395c59ff8b41945802c02 --- LICENSE | 373 ++++++++++++++++ README.md | 9 + fields/5.12.35/Account.json | 9 + fields/5.12.35/BroadcastGroup.json | 4 + fields/5.12.35/ChannelPlan.json | 35 ++ fields/5.12.35/Dashboard.json | 12 + fields/5.12.35/Device.json | 133 ++++++ fields/5.12.35/DhcpOption.json | 8 + fields/5.12.35/DpiApp.json | 10 + fields/5.12.35/DpiGroup.json | 5 + fields/5.12.35/DynamicDNS.json | 10 + fields/5.12.35/FirewallGroup.json | 5 + fields/5.12.35/FirewallRule.json | 48 +++ fields/5.12.35/HeatMap.json | 6 + fields/5.12.35/HeatMapPoint.json | 7 + fields/5.12.35/Hotspot2Conf.json | 122 ++++++ fields/5.12.35/HotspotOp.json | 5 + fields/5.12.35/HotspotPackage.json | 31 ++ fields/5.12.35/Map.json | 15 + fields/5.12.35/MediaFile.json | 3 + fields/5.12.35/NetworkConf.json | 139 ++++++ fields/5.12.35/PortConf.json | 35 ++ fields/5.12.35/PortForward.json | 11 + fields/5.12.35/RadiusProfile.json | 20 + fields/5.12.35/Routing.json | 11 + fields/5.12.35/ScheduleTask.json | 14 + fields/5.12.35/Setting.json | 408 ++++++++++++++++++ fields/5.12.35/SettingAutoSpeedtest.json | 4 + fields/5.12.35/SettingBaresip.json | 6 + fields/5.12.35/SettingBroadcast.json | 8 + fields/5.12.35/SettingConnectivity.json | 8 + fields/5.12.35/SettingCountry.json | 3 + fields/5.12.35/SettingDpi.json | 4 + fields/5.12.35/SettingElementAdopt.json | 5 + fields/5.12.35/SettingGuestAccess.json | 94 ++++ fields/5.12.35/SettingIps.json | 51 +++ fields/5.12.35/SettingLcm.json | 7 + fields/5.12.35/SettingLocale.json | 3 + fields/5.12.35/SettingMgmt.json | 19 + .../5.12.35/SettingNetworkOptimization.json | 3 + fields/5.12.35/SettingNtp.json | 6 + fields/5.12.35/SettingPorta.json | 3 + .../5.12.35/SettingProviderCapabilities.json | 5 + fields/5.12.35/SettingRadioAi.json | 27 ++ fields/5.12.35/SettingRadius.json | 10 + fields/5.12.35/SettingRsyslogd.json | 11 + fields/5.12.35/SettingSnmp.json | 7 + fields/5.12.35/SettingSuperCloudaccess.json | 9 + fields/5.12.35/SettingSuperEvents.json | 3 + fields/5.12.35/SettingSuperFwupdate.json | 5 + fields/5.12.35/SettingSuperIdentity.json | 4 + fields/5.12.35/SettingSuperMail.json | 3 + fields/5.12.35/SettingSuperMgmt.json | 49 +++ fields/5.12.35/SettingSuperSdn.json | 14 + fields/5.12.35/SettingSuperSmtp.json | 11 + fields/5.12.35/SettingUsg.json | 57 +++ fields/5.12.35/SettingUsw.json | 3 + fields/5.12.35/SpatialRecord.json | 11 + fields/5.12.35/Tag.json | 4 + fields/5.12.35/User.json | 12 + fields/5.12.35/UserGroup.json | 5 + fields/5.12.35/VirtualDevice.json | 8 + fields/5.12.35/Wall.json | 9 + fields/5.12.35/WlanConf.json | 61 +++ fields/5.12.35/WlanGroup.json | 10 + fields/getjson.sh | 16 + fields/main.go | 377 ++++++++++++++++ fields/main_test.go | 47 ++ fields/settings.sh | 10 + go.mod | 5 + go.sum | 2 + unifi/account.generated.go | 110 +++++ unifi/broadcast_group.generated.go | 105 +++++ unifi/dhcp_option.generated.go | 108 +++++ unifi/dpi_app.generated.go | 111 +++++ unifi/dpi_group.generated.go | 106 +++++ unifi/dynamic_dns.generated.go | 111 +++++ unifi/firewall_group.generated.go | 106 +++++ unifi/firewall_group.go | 21 + unifi/firewall_rule.generated.go | 142 ++++++ unifi/firewall_rule.go | 21 + unifi/heat_map.generated.go | 107 +++++ unifi/heat_map_point.generated.go | 108 +++++ unifi/hotspot_op.generated.go | 106 +++++ unifi/hotspot_package.generated.go | 132 ++++++ unifi/map.generated.go | 116 +++++ unifi/media_file.generated.go | 104 +++++ unifi/network.generated.go | 239 ++++++++++ unifi/network.go | 57 +++ unifi/port_conf.generated.go | 136 ++++++ unifi/port_forward.generated.go | 112 +++++ unifi/port_forward.go | 21 + unifi/routing.generated.go | 111 +++++ unifi/setting.go | 118 +++++ unifi/setting_auto_speedtest.generated.go | 24 ++ unifi/setting_baresip.generated.go | 26 ++ unifi/setting_broadcast.generated.go | 28 ++ unifi/setting_connectivity.generated.go | 28 ++ unifi/setting_country.generated.go | 23 + unifi/setting_dpi.generated.go | 24 ++ unifi/setting_element_adopt.generated.go | 25 ++ unifi/setting_guest_access.generated.go | 110 +++++ unifi/setting_lcm.generated.go | 27 ++ unifi/setting_locale.generated.go | 23 + unifi/setting_mgmt.generated.go | 37 ++ .../setting_network_optimization.generated.go | 23 + unifi/setting_ntp.generated.go | 26 ++ unifi/setting_porta.generated.go | 23 + ...setting_provider_capabilities.generated.go | 25 ++ unifi/setting_radio_ai.generated.go | 33 ++ unifi/setting_radius.generated.go | 30 ++ unifi/setting_rsyslogd.generated.go | 31 ++ unifi/setting_snmp.generated.go | 27 ++ unifi/setting_super_cloudaccess.generated.go | 29 ++ unifi/setting_super_events.generated.go | 23 + unifi/setting_super_fwupdate.generated.go | 25 ++ unifi/setting_super_identity.generated.go | 24 ++ unifi/setting_super_mail.generated.go | 23 + unifi/setting_super_mgmt.generated.go | 67 +++ unifi/setting_super_sdn.generated.go | 32 ++ unifi/setting_super_smtp.generated.go | 31 ++ unifi/setting_usg.generated.go | 77 ++++ unifi/setting_usw.generated.go | 23 + unifi/sites.go | 29 ++ unifi/tag.generated.go | 105 +++++ unifi/unifi.go | 145 +++++++ unifi/user.generated.go | 113 +++++ unifi/user.go | 138 ++++++ unifi/user_group.generated.go | 106 +++++ unifi/user_group.go | 21 + unifi/virtual_device.generated.go | 109 +++++ unifi/wlan.generated.go | 162 +++++++ unifi/wlan.go | 52 +++ unifi/wlan_group.generated.go | 110 +++++ unifi/wlan_group.go | 21 + 135 files changed, 6973 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 fields/5.12.35/Account.json create mode 100644 fields/5.12.35/BroadcastGroup.json create mode 100644 fields/5.12.35/ChannelPlan.json create mode 100644 fields/5.12.35/Dashboard.json create mode 100644 fields/5.12.35/Device.json create mode 100644 fields/5.12.35/DhcpOption.json create mode 100644 fields/5.12.35/DpiApp.json create mode 100644 fields/5.12.35/DpiGroup.json create mode 100644 fields/5.12.35/DynamicDNS.json create mode 100644 fields/5.12.35/FirewallGroup.json create mode 100644 fields/5.12.35/FirewallRule.json create mode 100644 fields/5.12.35/HeatMap.json create mode 100644 fields/5.12.35/HeatMapPoint.json create mode 100644 fields/5.12.35/Hotspot2Conf.json create mode 100644 fields/5.12.35/HotspotOp.json create mode 100644 fields/5.12.35/HotspotPackage.json create mode 100644 fields/5.12.35/Map.json create mode 100644 fields/5.12.35/MediaFile.json create mode 100644 fields/5.12.35/NetworkConf.json create mode 100644 fields/5.12.35/PortConf.json create mode 100644 fields/5.12.35/PortForward.json create mode 100644 fields/5.12.35/RadiusProfile.json create mode 100644 fields/5.12.35/Routing.json create mode 100644 fields/5.12.35/ScheduleTask.json create mode 100644 fields/5.12.35/Setting.json create mode 100644 fields/5.12.35/SettingAutoSpeedtest.json create mode 100644 fields/5.12.35/SettingBaresip.json create mode 100644 fields/5.12.35/SettingBroadcast.json create mode 100644 fields/5.12.35/SettingConnectivity.json create mode 100644 fields/5.12.35/SettingCountry.json create mode 100644 fields/5.12.35/SettingDpi.json create mode 100644 fields/5.12.35/SettingElementAdopt.json create mode 100644 fields/5.12.35/SettingGuestAccess.json create mode 100644 fields/5.12.35/SettingIps.json create mode 100644 fields/5.12.35/SettingLcm.json create mode 100644 fields/5.12.35/SettingLocale.json create mode 100644 fields/5.12.35/SettingMgmt.json create mode 100644 fields/5.12.35/SettingNetworkOptimization.json create mode 100644 fields/5.12.35/SettingNtp.json create mode 100644 fields/5.12.35/SettingPorta.json create mode 100644 fields/5.12.35/SettingProviderCapabilities.json create mode 100644 fields/5.12.35/SettingRadioAi.json create mode 100644 fields/5.12.35/SettingRadius.json create mode 100644 fields/5.12.35/SettingRsyslogd.json create mode 100644 fields/5.12.35/SettingSnmp.json create mode 100644 fields/5.12.35/SettingSuperCloudaccess.json create mode 100644 fields/5.12.35/SettingSuperEvents.json create mode 100644 fields/5.12.35/SettingSuperFwupdate.json create mode 100644 fields/5.12.35/SettingSuperIdentity.json create mode 100644 fields/5.12.35/SettingSuperMail.json create mode 100644 fields/5.12.35/SettingSuperMgmt.json create mode 100644 fields/5.12.35/SettingSuperSdn.json create mode 100644 fields/5.12.35/SettingSuperSmtp.json create mode 100644 fields/5.12.35/SettingUsg.json create mode 100644 fields/5.12.35/SettingUsw.json create mode 100644 fields/5.12.35/SpatialRecord.json create mode 100644 fields/5.12.35/Tag.json create mode 100644 fields/5.12.35/User.json create mode 100644 fields/5.12.35/UserGroup.json create mode 100644 fields/5.12.35/VirtualDevice.json create mode 100644 fields/5.12.35/Wall.json create mode 100644 fields/5.12.35/WlanConf.json create mode 100644 fields/5.12.35/WlanGroup.json create mode 100644 fields/getjson.sh create mode 100644 fields/main.go create mode 100644 fields/main_test.go create mode 100644 fields/settings.sh create mode 100644 go.mod create mode 100644 go.sum create mode 100644 unifi/account.generated.go create mode 100644 unifi/broadcast_group.generated.go create mode 100644 unifi/dhcp_option.generated.go create mode 100644 unifi/dpi_app.generated.go create mode 100644 unifi/dpi_group.generated.go create mode 100644 unifi/dynamic_dns.generated.go create mode 100644 unifi/firewall_group.generated.go create mode 100644 unifi/firewall_group.go create mode 100644 unifi/firewall_rule.generated.go create mode 100644 unifi/firewall_rule.go create mode 100644 unifi/heat_map.generated.go create mode 100644 unifi/heat_map_point.generated.go create mode 100644 unifi/hotspot_op.generated.go create mode 100644 unifi/hotspot_package.generated.go create mode 100644 unifi/map.generated.go create mode 100644 unifi/media_file.generated.go create mode 100644 unifi/network.generated.go create mode 100644 unifi/network.go create mode 100644 unifi/port_conf.generated.go create mode 100644 unifi/port_forward.generated.go create mode 100644 unifi/port_forward.go create mode 100644 unifi/routing.generated.go create mode 100644 unifi/setting.go create mode 100644 unifi/setting_auto_speedtest.generated.go create mode 100644 unifi/setting_baresip.generated.go create mode 100644 unifi/setting_broadcast.generated.go create mode 100644 unifi/setting_connectivity.generated.go create mode 100644 unifi/setting_country.generated.go create mode 100644 unifi/setting_dpi.generated.go create mode 100644 unifi/setting_element_adopt.generated.go create mode 100644 unifi/setting_guest_access.generated.go create mode 100644 unifi/setting_lcm.generated.go create mode 100644 unifi/setting_locale.generated.go create mode 100644 unifi/setting_mgmt.generated.go create mode 100644 unifi/setting_network_optimization.generated.go create mode 100644 unifi/setting_ntp.generated.go create mode 100644 unifi/setting_porta.generated.go create mode 100644 unifi/setting_provider_capabilities.generated.go create mode 100644 unifi/setting_radio_ai.generated.go create mode 100644 unifi/setting_radius.generated.go create mode 100644 unifi/setting_rsyslogd.generated.go create mode 100644 unifi/setting_snmp.generated.go create mode 100644 unifi/setting_super_cloudaccess.generated.go create mode 100644 unifi/setting_super_events.generated.go create mode 100644 unifi/setting_super_fwupdate.generated.go create mode 100644 unifi/setting_super_identity.generated.go create mode 100644 unifi/setting_super_mail.generated.go create mode 100644 unifi/setting_super_mgmt.generated.go create mode 100644 unifi/setting_super_sdn.generated.go create mode 100644 unifi/setting_super_smtp.generated.go create mode 100644 unifi/setting_usg.generated.go create mode 100644 unifi/setting_usw.generated.go create mode 100644 unifi/sites.go create mode 100644 unifi/tag.generated.go create mode 100644 unifi/unifi.go create mode 100644 unifi/user.generated.go create mode 100644 unifi/user.go create mode 100644 unifi/user_group.generated.go create mode 100644 unifi/user_group.go create mode 100644 unifi/virtual_device.generated.go create mode 100644 unifi/wlan.generated.go create mode 100644 unifi/wlan.go create mode 100644 unifi/wlan_group.generated.go create mode 100644 unifi/wlan_group.go diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a612ad9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/README.md b/README.md new file mode 100644 index 0000000..40fd283 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Unifi Go SDK + +## Note on Code Generation + +The data models and basic REST methods are "generated" from JSON files in the JAR that show all fields and the associated regex/validation information. + +This is kind of gross, I wanted to switch to using the java classes in the jar like scala2go but the jar is obfuscated and I couldn't find a way to extract that information from anywhere else. Maybe it exists somewhere in the web UI, but I was unable to find it in there in a way that was extractable in a practical way. + +Still planning to dig through the bits some more later on. diff --git a/fields/5.12.35/Account.json b/fields/5.12.35/Account.json new file mode 100644 index 0000000..9f104aa --- /dev/null +++ b/fields/5.12.35/Account.json @@ -0,0 +1,9 @@ +{ + "name": "^[^\"' ]+$", + "x_password": "", + "vlan": "[2-9]|[1-9][0-9]{1,2}|[1-3][0-9]{3}|400[0-9]|^$", + "ip":"^(([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])$|^$", + "tunnel_config_type": "vpn|802.1x|custom", + "tunnel_type": "[1-9]|1[0-3]|^$", + "tunnel_medium_type": "[1-9]|1[0-5]|^$" +} diff --git a/fields/5.12.35/BroadcastGroup.json b/fields/5.12.35/BroadcastGroup.json new file mode 100644 index 0000000..677d265 --- /dev/null +++ b/fields/5.12.35/BroadcastGroup.json @@ -0,0 +1,4 @@ +{ + "name": "", + "member_table": [""] +} diff --git a/fields/5.12.35/ChannelPlan.json b/fields/5.12.35/ChannelPlan.json new file mode 100644 index 0000000..a790643 --- /dev/null +++ b/fields/5.12.35/ChannelPlan.json @@ -0,0 +1,35 @@ +{ + "conf_source": "manual|radio-ai", + "date": "^$|^(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])Z?$", + "fitness": "^[0-9]+\\.?[0-9]*$", + "note": ".{0,1024}", + "radio": "na|ng|ng\\+na", + "radio_table": [{ + "device_mac": "^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$", + "name": "[a-z]*[0-9]*", + "channel": "[0-9]|[1][0-4]|16|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|183|184|185|187|188|189|192|196|auto", + "backup_channel": "[0-9]|[1][0-4]|16|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|183|184|185|187|188|189|192|196|auto", + "width": "20|40|80|160", + "tx_power": "[\\d]+|auto", + "tx_power_mode": "auto|medium|high|low|custom" + }], + "satisfaction_table": [{ + "device_mac": "^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$", + "satisfaction": "^[0-9]+\\.?[0-9]*$" + }], + "site_blacklisted_channels": [{ + "channel": "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|183|184|185|187|188|189|192|196", + "timestamp": "[1-9][0-9]{12}" + }], + "ap_blacklisted_channels": [{ + "mac": "^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$", + "channel": "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|183|184|185|187|188|189|192|196", + "timestamp": "[1-9][0-9]{12}" + }], + "coupling": [{ + "source": "^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}).*$", + "target": "^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}).*$", + "rssi": "-?[0-9]{1,3}" + }], + "satisfaction": "^[0-9]+\\.?[0-9]*$" +} diff --git a/fields/5.12.35/Dashboard.json b/fields/5.12.35/Dashboard.json new file mode 100644 index 0000000..eb5bc1f --- /dev/null +++ b/fields/5.12.35/Dashboard.json @@ -0,0 +1,12 @@ +{ + "name": "", + "desc": "", + "is_public": "true|false", + "controller_version": "", + "modules":[{ + "id": "", + "module_id": "", + "config": "", + "restrictions": "" + }] +} diff --git a/fields/5.12.35/Device.json b/fields/5.12.35/Device.json new file mode 100644 index 0000000..a9bbbad --- /dev/null +++ b/fields/5.12.35/Device.json @@ -0,0 +1,133 @@ +{ + "name": ".{1,128}", + "x": "", + "y": "", + "heightInMeters": "^([-]?[\\d]+[.]?[\\d]*)$", + "locked": "true|false", + "map_id": "", + "disabled": "true|false", + "led_override": "default|on|off", + "led_override_color": "^#(?:[0-9a-fA-F]{3}){1,2}$", + "led_override_color_brightness": "^[0-9][0-9]?$|^100$", + "outdoor_mode_override": "default|on|off", + "mesh_sta_vap_enabled": "true|false", + "config_network": { + "bonding_enabled": "true|false", + "type": "dhcp|static", + "ip": "^(([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])$", + "netmask": "^((128|192|224|240|248|252|254)\\.0\\.0\\.0)|(255\\.(((0|128|192|224|240|248|252|254)\\.0\\.0)|(255\\.(((0|128|192|224|240|248|252|254)\\.0)|255\\.(0|128|192|224|240|248|252|254)))))$", + "gateway": "^(([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])$|^$", + "dns1": "^(([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-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$|^$", + "dns2": "^(([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-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$|^$", + "dnssuffix": "" + }, + "radio_table": [{ + "radio": "ng|na|ad", + "channel": "[0-9]|[1][0-4]|4.5|16|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|183|184|185|187|188|189|192|196|auto", + "backup_channel": "[0-9]|[1][0-4]|16|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|183|184|185|187|188|189|192|196|auto", + "ht": "20|40|80|160|1080|2160", + "tx_power_mode": "auto|medium|high|low|custom", + "tx_power": "[\\d]+|auto", + "min_rssi_enabled": "true|false", + "min_rssi": "^-([1-9]|[1-8][0-9]|9[0-4])$", + "name": "", + "hard_noise_floor_enabled": "true|false", + "sens_level_enabled": "true|false", + "sens_level": "^-([5-8][0-9]|90)$", + "antenna_gain": "^-?([0-9]|[1-9][0-9])", + "antenna_id": "-1|[0-9]", + "wlangroup_id": "[\\d\\w]+", + "vwire_enabled":"true|false" + }], + "wlan_overrides": [{ + "enabled":"true|false", + "name":".{1,32}", + "name_combine_enabled":"true|false", + "name_combine_suffix":".{0,8}", + "vlan":"[2-9]|[1-9][0-9]{1,2}|[1-3][0-9]{3}|40[0-8][0-9]|409[0-5]|^$", + "vlan_enabled":"true|false", + "x_passphrase": "[\\x20-\\x7E]{8,63}|[0-9a-fA-F]{64}", + "wlan_id":"[\\d\\w]+", + "radio":"ng|na", + "radio_name":"" + }], + "ethernet_overrides": [{ + "ifname": "eth[0-9]{1,2}", + "networkgroup": "LAN[2-8]?|WAN[2]?" + }], + "jumboframe_enabled": "true|false", + "flowctrl_enabled": "true|false", + "stp_version": "stp|rstp|disabled", + "stp_priority": "0|4096|8192|12288|16384|20480|24576|28672|32768|36864|40960|45056|49152|53248|57344|61440", + "dot1x_portctrl_enabled": "true|false", + "dot1x_fallback_networkconf_id": "[\\d\\w]+|", + "radiusprofile_id": "", + "atf_enabled": "true|false", + "bandsteering_mode": "off|equal|prefer_5g", + "dpi_enabled": "true|false", + "resetbtn_enabled": "on|off", + "mgmt_network_id": "[\\d\\w]+", + "switch_vlan_enabled": "false|true", + "port_overrides": [{ + "port_idx":"[1-9]|[1-4][0-9]|5[0-2]", + "name":".{0,128}", + "op_mode":"switch|mirror|aggregate", + "autoneg":"true|false", + "speed":"10|100|1000|2500|5000|10000|20000|25000|40000|50000|100000", + "full_duplex":"true|false", + "poe_mode":"auto|pasv24|passthrough|off", + "isolation":"true|false", + "dot1x_ctrl":"auto|force_authorized|force_unauthorized|mac_based|multi_host", + "stormctrl_type": "level|rate", + "stormctrl_ucast_enabled": "true|false", + "stormctrl_ucast_level": "[0-9]|[1-9][0-9]|100", + "stormctrl_ucast_rate": "[0-9]|[1-9][0-9]{1,6}|1[0-3][0-9]{6}|14[0-7][0-9]{5}|148[0-7][0-9]{4}|14880000", + "stormctrl_mcast_enabled": "true|false", + "stormctrl_mcast_level": "[0-9]|[1-9][0-9]|100", + "stormctrl_mcast_rate": "[0-9]|[1-9][0-9]{1,6}|1[0-3][0-9]{6}|14[0-7][0-9]{5}|148[0-7][0-9]{4}|14880000", + "stormctrl_bcast_enabled": "true|false", + "stormctrl_bcast_level": "[0-9]|[1-9][0-9]|100", + "stormctrl_bcast_rate": "[0-9]|[1-9][0-9]{1,6}|1[0-3][0-9]{6}|14[0-7][0-9]{5}|148[0-7][0-9]{4}|14880000", + "priority_queue1_level": "[0-9]|[1-9][0-9]|100", + "priority_queue2_level": "[0-9]|[1-9][0-9]|100", + "priority_queue3_level": "[0-9]|[1-9][0-9]|100", + "priority_queue4_level": "[0-9]|[1-9][0-9]|100", + "portconf_id":"[\\d\\w]+", + "mirror_port_idx":"[1-9]|[1-4][0-9]|5[0-2]", + "lldpmed_enabled": "true|false", + "lldpmed_notify_enabled": "true|false", + "stp_port_mode": "true|false", + "egress_rate_limit_kbps_enabled": "true|false", + "egress_rate_limit_kbps": "6[4-9]|[7-9][0-9]|[1-9][0-9]{2,6}", + "aggregate_num_ports":"[2-4]", + "port_security_enabled": "true|false", + "port_security_mac_address": ["^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$"] + }], + "power_source_ctrl_enabled": "true|false", + "power_source_ctrl": "auto|8023af|8023at|8023bt-type3|8023bt-type4|pasv24|poe-injector|ac|adapter|dc|rps", + "snmp_location": ".{0,255}", + "snmp_contact": ".{0,255}", + "baresip_enabled": "true|false", + "baresip_extension": "^\\+?[a-zA-Z0-9_.\\-!~*'()]*", + "baresip_auth_user": "^\\+?[a-zA-Z0-9_.\\-!~*'()]*", + "x_baresip_password": "^[a-zA-Z0-9_.\\-!~*'()]*", + "volume": "[0-9]|[1-9][0-9]|100", + "lte_ext_ant": "true|false", + "lte_poe": "true|false", + "lte_soft_limit": "\\d+", + "lcm_brightness_override": "true|false", + "lcm_brightness": "[1-9]|[1-9][0-9]|100", + "lcm_idle_timeout_override": "true|false", + "lcm_idle_timeout": "[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", + "rps_override": { + "power_management_mode": "dynamic|static", + "rps_port_table": [{ + "port_idx": "[1-6]", + "name": ".{0,32}", + "port_mode":"auto|force_active|manual|disabled" + }] + }, + "lcm_tracker_seed": ".{0,50}", + "lcm_tracker_enabled": "true|false", + "ubb_pair_name": ".{1,128}" +} diff --git a/fields/5.12.35/DhcpOption.json b/fields/5.12.35/DhcpOption.json new file mode 100644 index 0000000..63f9c8d --- /dev/null +++ b/fields/5.12.35/DhcpOption.json @@ -0,0 +1,8 @@ +{ + "type": "^(boolean|hexarray|integer|ipaddress|macaddress|text)$", + "code": "^(?!(?:15|42|43|44|51|66|67|252)$)([7-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])$", + "name": "^[A-Za-z0-9-_]{1,25}$", + "signed": "^(true|false)$", + "width": "^(8|16|32)$" +} + diff --git a/fields/5.12.35/DpiApp.json b/fields/5.12.35/DpiApp.json new file mode 100644 index 0000000..55760c2 --- /dev/null +++ b/fields/5.12.35/DpiApp.json @@ -0,0 +1,10 @@ +{ + "name": ".{1,128}", + "enabled": "false|true", + "apps": [ "[0-9]{1,8}" ], + "cats": [ "[0-9]{1,3}" ], + "blocked": "false|true", + "log": "false|true", + "qos_rate_max_up": "-1|[2-9]|[1-9][0-9]{1,4}|100000|10[0-1][0-9]{3}|102[0-3][0-9]{2}|102400", + "qos_rate_max_down": "-1|[2-9]|[1-9][0-9]{1,4}|100000|10[0-1][0-9]{3}|102[0-3][0-9]{2}|102400" +} diff --git a/fields/5.12.35/DpiGroup.json b/fields/5.12.35/DpiGroup.json new file mode 100644 index 0000000..de915a1 --- /dev/null +++ b/fields/5.12.35/DpiGroup.json @@ -0,0 +1,5 @@ +{ + "name":".{1,128}", + "enabled": "false|true", + "dpiapp_ids": [ "[\\d\\w]+" ] +} diff --git a/fields/5.12.35/DynamicDNS.json b/fields/5.12.35/DynamicDNS.json new file mode 100644 index 0000000..b866f64 --- /dev/null +++ b/fields/5.12.35/DynamicDNS.json @@ -0,0 +1,10 @@ +{ + "interface": "wan|wan2", + "service": "afraid|changeip|cloudflare|dnspark|dslreports|dyndns|easydns|googledomains|namecheap|noip|sitelutions|zoneedit|custom", + "custom_service": "^[^\"' ]+$", + "host_name": "^[^\"' ]+$", + "login": "^[^\"' ]+$", + "x_password": "^[^\"' ]+$", + "server": "^[^\"' ]+$|^$", + "options": ["^[^\"' ]+$"] +} diff --git a/fields/5.12.35/FirewallGroup.json b/fields/5.12.35/FirewallGroup.json new file mode 100644 index 0000000..a148c69 --- /dev/null +++ b/fields/5.12.35/FirewallGroup.json @@ -0,0 +1,5 @@ +{ + "name": ".{1,64}", + "group_type": "address-group|port-group|ipv6-address-group", + "group_members": [ "" ] +} diff --git a/fields/5.12.35/FirewallRule.json b/fields/5.12.35/FirewallRule.json new file mode 100644 index 0000000..f3add04 --- /dev/null +++ b/fields/5.12.35/FirewallRule.json @@ -0,0 +1,48 @@ +{ + "name": ".{1,128}", + "ruleset": "WAN_IN|WAN_OUT|WAN_LOCAL|LAN_IN|LAN_OUT|LAN_LOCAL|GUEST_IN|GUEST_OUT|GUEST_LOCAL|WANv6_IN|WANv6_OUT|WANv6_LOCAL|LANv6_IN|LANv6_OUT|LANv6_LOCAL|GUESTv6_IN|GUESTv6_OUT|GUESTv6_LOCAL", + "rule_index": "2[0-9]{3}|4[0-9]{3}", + + "enabled": "true|false", + "action": "drop|reject|accept", + "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_v6": "^$|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])|ah|all|dccp|eigrp|esp|gre|icmpv6|ipcomp|ipv6|ipv6-frag|ipv6-icmp|ipv6-nonxt|ipv6-opts|ipv6-route|isis|l2tp|manet|mobility-header|mpls-in-ip|ospf|pim|rsvp|sctp|shim6|tcp|tcp_udp|udp|vrrp", + "protocol_match_excepted": "false|true", + + "state_established": "false|true", + "state_invalid": "false|true", + "state_new": "false|true", + "state_related": "false|true", + + "ipsec": "match-ipsec|match-none|^$", + "icmp_typename" : "^$|communication-prohibited|destination-unreachable|echo-reply|echo-request|fragmentation-needed|host-precedence-violation|host-prohibited|host-redirect|host-unknown|host-unreachable|ip-header-bad|network-prohibited|network-redirect|network-unknown|network-unreachable|parameter-problem|port-unreachable|protocol-unreachable|redirect|required-option-missing|router-advertisement|router-solicitation|source-route-failed|timestamp-reply|timestamp-request|TOS-host-redirect|TOS-host-unreachable|TOS-network-redirect|TOS-network-unreachable|ttl-exceeded|ttl-zero-during-reassembly|ttl-zero-during-transit", + "icmpv6_typename" : "^$|address-unreachable|bad-header|communication-prohibited|destination-unreachable|echo-reply|echo-request|neighbor-advertisement|neighbor-solicitation|no-route|packet-too-big|parameter-problem|port-unreachable|redirect|router-advertisement|router-solicitation|time-exceeded|ttl-zero-during-reassembly|ttl-zero-during-transit|unknown-header-type|unknown-option", + + "dst_address": "", + "dst_address_ipv6": "", + "dst_port": "", + "dst_firewallgroup_ids": [ "[\\d\\w]+" ], + "dst_networkconf_id": "[\\d\\w]+|^$", + "dst_networkconf_type": "ADDRv4|NETv4", + + "src_address": "", + "src_address_ipv6": "", + "src_port": "", + "src_firewallgroup_ids": [ "[\\d\\w]+" ], + "src_networkconf_id": "[\\d\\w]+|^$", + "src_networkconf_type": "ADDRv4|NETv4", + "src_mac_address": "^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$|^$", + + "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])$", + "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])$", + "starttime": "^$|^(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9])$", + "stoptime": "^$|^(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9])$", + "monthdays": "^$|^(([1-9]|[12][0-9]|3[01])(,([1-9]|[12][0-9]|3[01])){0,30})$", + "monthdays_negate": "false|true", + "weekdays": "^$|^((Mon|Tue|Wed|Thu|Fri|Sat|Sun)(,(Mon|Tue|Wed|Thu|Fri|Sat|Sun)){0,6})$", + "weekdays_negate": "false|true", + "utc": "false|true", + "contiguous": "false|true", + + "logging": "false|true" +} diff --git a/fields/5.12.35/HeatMap.json b/fields/5.12.35/HeatMap.json new file mode 100644 index 0000000..eaa6021 --- /dev/null +++ b/fields/5.12.35/HeatMap.json @@ -0,0 +1,6 @@ +{ + "map_id": "", + "type": "download|upload", + "name": ".*[^\\s]+.*", + "description": "" +} diff --git a/fields/5.12.35/HeatMapPoint.json b/fields/5.12.35/HeatMapPoint.json new file mode 100644 index 0000000..f119f69 --- /dev/null +++ b/fields/5.12.35/HeatMapPoint.json @@ -0,0 +1,7 @@ +{ + "heatmap_id": "", + "x": "[-+]?[0-9]*\\.?[0-9]+", + "y": "[-+]?[0-9]*\\.?[0-9]+", + "upload_speed": "[-+]?[0-9]*\\.?[0-9]+", + "download_speed": "[-+]?[0-9]*\\.?[0-9]+" +} diff --git a/fields/5.12.35/Hotspot2Conf.json b/fields/5.12.35/Hotspot2Conf.json new file mode 100644 index 0000000..653b33e --- /dev/null +++ b/fields/5.12.35/Hotspot2Conf.json @@ -0,0 +1,122 @@ +{ + "name": ".{1,128}", + "venue_name": [ + { + "language": "[a-z]{3}", + "name": ".{1,128}" + } + ], + "venue_group": "0|1|2|3|4|5|6|7|8|9|10|11", + "venue_type": "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15", + "network_type": "0|1|2|3|4|5|14|15", + "network_access_internet": "true|false", + "network_access_asra": "true|false", + "network_access_esr": "true|false", + "network_access_uesa": "true|false", + "hessid": "^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$|^$", + "disable_dgaf": "true|false", + "deauth_req_timeout" : "[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", + "osu_ssid": "", + "nai_realm_list": [ + { + "name": ".{1,128}", + "status": "true|false", + "encoding": "0|1", + "eap_method": "13|21|18|23|50", + "auth_ids": "", + "auth_vals": "" + } + ], + "domain_name_list": [".{1,128}"], + "roaming_consortium_list": [ + { + "name": ".{1,128}", + "oid": ".{1,128}" + } + ], + "cellular_network_list": [ + { + "name": ".{1,128}", + "mcc": "[0-9]{3}", + "mnc": "[0-9]{3}" + } + ], + "friendly_name" : [ + { + "language": "[a-z]{3}", + "text": ".{1,128}" + } + ], + "t_c_filename" : ".{1,256}", + "t_c_timestamp" : "[0-9]{1,12}", + "icons" : [ + { + "name" : ".{1,256}", + "width": "[0-9]{1,8}", + "height": "[0-9]{1,8}", + "media": ".{1,256}", + "language": "[a-z]{3}", + "filename": ".{1,256}", + "data": "", + "size": "[0-9]{1,8}" + } + ], + "metrics_status" : "true|false", + "metrics_info" : "[0-9A-Fa-f]{1,2}", + "metrics_downlink_speed": "[0-9]{1,10}", + "metrics_uplink_speed": "[0-9]{1,10}", + "metrics_downlink_load": "[0-9]{1,3}", + "metrics_uplink_load": "[0-9]{1,3}", + "metrics_measurement": "[0-9]{1,5}", + "capab" : [ + { + "protocol" : "icmp|tcp_udp|tcp|udp", + "port": "(([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])|([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])-([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5]))+(,([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])|,([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])-([1-9][0-9]{0,3}|[1-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-4][0-9]{2}|[6][5][5][0-2][0-9]|[6][5][5][3][0-5])){0,14}", + "status" : "closed|open|unknown" + } + ], + "osu" : [ + { + "server_uri": "", + "friendly_name" : [ + { + "language": "[a-z]{3}", + "text": ".{1,128}" + } + ], + "description" : [ + { + "language": "[a-z]{3}", + "text": ".{1,128}" + } + ], + "nai" : "", + "nai2" : "", + "operating_class" : "[0-9A-Fa-f]{12}", + "method_soap_xml_spp": "true|false", + "method_oma_dm": "true|false", + "icon" : [ + { + "name": ".{1,128}" + } + ] + } + ], + "proxy_arp" : "true|false", + "ap_isolate" : "true|false", + "p2p" : "true|false", + "gas_comeback_delay" : "[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]|300", + "qos_map_status" : "true|false", + "qos_map_exceptions" : [ + { + "dcsp" : "[0-9]{1,2}", + "up" : "[0-7]" + } + ], + "qos_map_dcsp" : [ + { + "low" : "[0-9]{1,3}", + "high" : "[0-9]{1,3}" + } + ] +} diff --git a/fields/5.12.35/HotspotOp.json b/fields/5.12.35/HotspotOp.json new file mode 100644 index 0000000..aa464df --- /dev/null +++ b/fields/5.12.35/HotspotOp.json @@ -0,0 +1,5 @@ +{ + "name": ".{1,256}", + "x_password": ".{1,256}", + "note": "" +} diff --git a/fields/5.12.35/HotspotPackage.json b/fields/5.12.35/HotspotPackage.json new file mode 100644 index 0000000..840ae4a --- /dev/null +++ b/fields/5.12.35/HotspotPackage.json @@ -0,0 +1,31 @@ +{ + "name": "", + "charged_as": "", + "amount": "^([\\d]+[.]?[\\d]*)$", + "currency": "[A-Z]{3}", + "hours": "[\\d]+", + "trial_reset": "^([\\d]+[.]?[\\d]*)$|^$", + "limit_overwrite": "true|false", + "limit_up": "[\\d]+|^$", + "limit_down": "[\\d]+|^$", + "limit_quota": "[\\d]+|^$", + "index": "[\\d]+", + "custom_payment_fields_enabled": "true|false", + "payment_fields_address_enabled": "true|false", + "payment_fields_address_required": "true|false", + "payment_fields_city_enabled": "true|false", + "payment_fields_city_required": "true|false", + "payment_fields_country_enabled": "true|false", + "payment_fields_country_required": "true|false", + "payment_fields_country_default": "", + "payment_fields_email_enabled": "true|false", + "payment_fields_email_required": "true|false", + "payment_fields_first_name_enabled": "true|false", + "payment_fields_first_name_required": "true|false", + "payment_fields_last_name_enabled": "true|false", + "payment_fields_last_name_required": "true|false", + "payment_fields_state_enabled": "true|false", + "payment_fields_state_required": "true|false", + "payment_fields_zip_enabled": "true|false", + "payment_fields_zip_required": "true|false" +} diff --git a/fields/5.12.35/Map.json b/fields/5.12.35/Map.json new file mode 100644 index 0000000..0fa5c6d --- /dev/null +++ b/fields/5.12.35/Map.json @@ -0,0 +1,15 @@ +{ + "name": "", + "mapTypeId": "satellite|roadmap|hybrid|terrain", + "tilt": "[\\d]+", + "type": "designerMap|imageMap|googleMap", + "upp": "^([\\d]+[.]?[\\d]*)$", + "unit": "m|f", + "lat": "^([-]?[\\d]+[.]?[\\d]*([eE][-+]?[\\d]+)?)$", + "lng": "^([-]?[\\d]+[.]?[\\d]*([eE][-+]?[\\d]+)?)$", + "selected": "true|false", + "zoom": "[\\d]+", + "offset_top": "^([-]?[\\d]+[.]?[\\d]*)$", + "offset_left": "^([-]?[\\d]+[.]?[\\d]*)$", + "opacity": "^(0(\\.[\\d]{1,2})?|1)$|^$" +} diff --git a/fields/5.12.35/MediaFile.json b/fields/5.12.35/MediaFile.json new file mode 100644 index 0000000..7c98cf6 --- /dev/null +++ b/fields/5.12.35/MediaFile.json @@ -0,0 +1,3 @@ +{ + "name": "" +} diff --git a/fields/5.12.35/NetworkConf.json b/fields/5.12.35/NetworkConf.json new file mode 100644 index 0000000..6befb19 --- /dev/null +++ b/fields/5.12.35/NetworkConf.json @@ -0,0 +1,139 @@ +{ + "name": ".{1,128}", + "enabled": "true|false", + "purpose": "corporate|guest|remote-user-vpn|site-vpn|vlan-only|vpn-client|wan", + "vpn_type": "auto|ipsec-vpn|openvpn-vpn|pptp-client|l2tp-server|pptp-server", + "vlan_enabled": "false|true", + "vlan": "[2-9]|[1-9][0-9]{1,2}|[1-3][0-9]{3}|400[0-9]|^$", + "priority": "[1-4]", + "igmp_snooping": "true|false", + "igmp_fastleave": "true|false", + "igmp_supression": "true|false", + "igmp_maxresponse": "[1-9]|1[0-9]|2[0-5]|^$", + "igmp_mcrtrexpiretime": "[0-9]|[1-9][0-9]{1,2}|[1-2][0-9]{3}|3[0-5][0-9]{2}|3600|^$", + "igmp_groupmembership": "[2-9]|[1-9][0-9]{1,2}|[1-2][0-9]{3}|3[0-5][0-9]{2}|3600|^$", + "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])$|^$", + "ip_subnet": "^(([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)$", + "ipv6_subnet": "", + + "ipv6_interface_type": "static|pd|none", + "ipv6_pd_interface": "wan|wan2", + "ipv6_pd_prefixid": "^$|[a-fA-F0-9]{1,4}", + "ipv6_ra_enabled": "false|true", + "ipv6_ra_priority": "high|medium|low", + "ipv6_ra_valid_lifetime": "^([0-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|[1-8][0-9]{4}|9[0-8][0-9]{3}|99[0-8][0-9]{2}|999[0-8][0-9]|9999[0-9]|[1-8][0-9]{5}|9[0-8][0-9]{4}|99[0-8][0-9]{3}|999[0-8][0-9]{2}|9999[0-8][0-9]|99999[0-9]|[1-8][0-9]{6}|9[0-8][0-9]{5}|99[0-8][0-9]{4}|999[0-8][0-9]{3}|9999[0-8][0-9]{2}|99999[0-8][0-9]|999999[0-9]|[12][0-9]{7}|30[0-9]{6}|31[0-4][0-9]{5}|315[0-2][0-9]{4}|3153[0-5][0-9]{3}|31536000)$|^$", + "ipv6_ra_preferred_lifetime": "^([0-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|[1-8][0-9]{4}|9[0-8][0-9]{3}|99[0-8][0-9]{2}|999[0-8][0-9]|9999[0-9]|[1-8][0-9]{5}|9[0-8][0-9]{4}|99[0-8][0-9]{3}|999[0-8][0-9]{2}|9999[0-8][0-9]|99999[0-9]|[1-8][0-9]{6}|9[0-8][0-9]{5}|99[0-8][0-9]{4}|999[0-8][0-9]{3}|9999[0-8][0-9]{2}|99999[0-8][0-9]|999999[0-9]|[12][0-9]{7}|30[0-9]{6}|31[0-4][0-9]{5}|315[0-2][0-9]{4}|3153[0-5][0-9]{3}|31536000)$|^$", + "ipv6_pd_start": "", + "ipv6_pd_stop": "", + "domain_name": "(?=^.{3,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(? 1 { + return "", "", false, fmt.Errorf("unknown validation %#v", validation) + } + elementType, elementComment, _, err := typeFromValidation(validation[0]) + if err != nil { + return "", "", false, err + } + return fmt.Sprintf("[]%s", elementType), elementComment, true, nil + case string: + comment := validation + normalized := normalizeValidation(validation) + allowEmpty := strings.HasSuffix(validation, "|^$") || strings.HasPrefix(validation, "^$|") + switch { + case normalized == "falsetrue" || normalized == "truefalse": + return "bool", "", false, nil + default: + if _, err := strconv.ParseFloat(normalized, 64); err == nil { + if normalized == "09" || normalized == "09.09" { + comment = "" + } + + if strings.Contains(normalized, ".") { + if strings.Contains(validation, "\\.){3}") { + break + } + + return "float64", comment, true, nil + } + + return "int", comment, true, nil + } + } + if validation != "" && normalized != "" { + fmt.Printf("normalize %q to %q\n", validation, normalized) + } + return "string", validation, !allowEmpty, nil + } + return "", "", false, fmt.Errorf("unable to determine type from validation %q", validation) +} + +func generateField(name string, validation interface{}) (string, error) { + field := strcase.ToCamel(name) + field = cleanName(field, fieldReps) + fieldType, comment, omitempty, err := typeFromValidation(validation) + if err != nil { + return "", err + } + + comment = strings.TrimSpace(fmt.Sprintf("// %s", comment)) + if comment == "//" { + comment = "" + } + + if fieldType == "string" && strings.HasSuffix(field, "ID") { + omitempty = false + } + + omitemptyCode := "" + if omitempty { + omitemptyCode = ",omitempty" + } + + return fmt.Sprintf("\t%s %s `json:\"%s%s\"` %s", field, fieldType, name, omitemptyCode, comment), nil +} diff --git a/fields/main_test.go b/fields/main_test.go new file mode 100644 index 0000000..28a924c --- /dev/null +++ b/fields/main_test.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "testing" +) + +func TestTypeFromValidation(t *testing.T) { + for i, c := range []struct { + expectedType string + expectedComment string + expectedOmitEmpty bool + validation interface{} + }{ + {"string", "", true, ""}, + {"string", "default|custom", true, "default|custom"}, + {"string", ".{0,32}", true, ".{0,32}"}, + {"string", "^(([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])$|^$", false, "^(([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])$|^$"}, + + {"int", "^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^$", false, "^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^$"}, + {"int", "", true, "^[0-9]*$"}, + + {"float64", "", true, "[-+]?[0-9]*\\.?[0-9]+"}, + // this one is really an error as the . is not escaped + {"float64", "", true, "^([-]?[\\d]+[.]?[\\d]*)$"}, + {"float64", "", true, "^([\\d]+[.]?[\\d]*)$"}, + + {"bool", "", false, "false|true"}, + {"bool", "", false, "true|false"}, + } { + t.Run(fmt.Sprintf("%d %s %s", i, c.expectedType, c.validation), func(t *testing.T) { + actualType, actualComment, actualOmitEmpty, err := typeFromValidation(c.validation) + if err != nil { + t.Fatal(err) + } + if actualType != c.expectedType { + t.Fatalf("expected type %q got %q", c.expectedType, actualType) + } + if actualComment != c.expectedComment { + t.Fatalf("expected comment %q got %q", c.expectedComment, actualComment) + } + if actualOmitEmpty != c.expectedOmitEmpty { + t.Fatalf("expected omitempty %t got %t", c.expectedOmitEmpty, actualOmitEmpty) + } + }) + } +} diff --git a/fields/settings.sh b/fields/settings.sh new file mode 100644 index 0000000..d1ce3e2 --- /dev/null +++ b/fields/settings.sh @@ -0,0 +1,10 @@ +#! /bin/bash + +ver="5.12.35" +keys=$(jq -r keys[] "$ver/Setting.json") + +while IFS= read -r key; do + fn="$(echo $key | sed -r 's/(^|_)([a-z])/\U\2/g')" + echo "... $key $fn ..." + jq ".$key" "$ver/Setting.json" >> "$ver/Setting$fn.json" +done <<< "$keys" \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b97e218 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/paultyng/go-unifi + +go 1.12 + +require github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e4d62d5 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 h1:VHgatEHNcBFEB7inlalqfNqw65aNkM1lGX2yt3NmbS8= +github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= diff --git a/unifi/account.generated.go b/unifi/account.generated.go new file mode 100644 index 0000000..7466cac --- /dev/null +++ b/unifi/account.generated.go @@ -0,0 +1,110 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type Account 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"` + + IP string `json:"ip"` // ^(([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"` // ^[^"' ]+$ + 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 (c *Client) listAccount(site string) ([]Account, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []Account `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/account", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getAccount(site, id string) (*Account, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []Account `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/account/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteAccount(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/account/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createAccount(site string, d *Account) (*Account, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []Account `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/account", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateAccount(site string, d *Account) (*Account, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []Account `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/account/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/broadcast_group.generated.go b/unifi/broadcast_group.generated.go new file mode 100644 index 0000000..43260a8 --- /dev/null +++ b/unifi/broadcast_group.generated.go @@ -0,0 +1,105 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type BroadcastGroup 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"` + + MemberTable []string `json:"member_table,omitempty"` + Name string `json:"name,omitempty"` +} + +func (c *Client) listBroadcastGroup(site string) ([]BroadcastGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []BroadcastGroup `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/broadcastgroup", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getBroadcastGroup(site, id string) (*BroadcastGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []BroadcastGroup `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteBroadcastGroup(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createBroadcastGroup(site string, d *BroadcastGroup) (*BroadcastGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []BroadcastGroup `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/broadcastgroup", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateBroadcastGroup(site string, d *BroadcastGroup) (*BroadcastGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []BroadcastGroup `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/dhcp_option.generated.go b/unifi/dhcp_option.generated.go new file mode 100644 index 0000000..34fade6 --- /dev/null +++ b/unifi/dhcp_option.generated.go @@ -0,0 +1,108 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type DHCPOption 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"` + + Code string `json:"code,omitempty"` // ^(?!(?:15|42|43|44|51|66|67|252)$)([7-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])$ + Name string `json:"name,omitempty"` // ^[A-Za-z0-9-_]{1,25}$ + Signed bool `json:"signed"` + Type string `json:"type,omitempty"` // ^(boolean|hexarray|integer|ipaddress|macaddress|text)$ + Width int `json:"width,omitempty"` // ^(8|16|32)$ +} + +func (c *Client) listDHCPOption(site string) ([]DHCPOption, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DHCPOption `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/dhcpoption", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getDHCPOption(site, id string) (*DHCPOption, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DHCPOption `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteDHCPOption(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createDHCPOption(site string, d *DHCPOption) (*DHCPOption, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DHCPOption `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/dhcpoption", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateDHCPOption(site string, d *DHCPOption) (*DHCPOption, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DHCPOption `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/dpi_app.generated.go b/unifi/dpi_app.generated.go new file mode 100644 index 0000000..5048e8a --- /dev/null +++ b/unifi/dpi_app.generated.go @@ -0,0 +1,111 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type DpiApp 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"` + + Apps []int `json:"apps,omitempty"` + Blocked bool `json:"blocked"` + Cats []int `json:"cats,omitempty"` + Enabled bool `json:"enabled"` + Log bool `json:"log"` + Name string `json:"name,omitempty"` // .{1,128} + QOSRateMaxDown int `json:"qos_rate_max_down,omitempty"` // -1|[2-9]|[1-9][0-9]{1,4}|100000|10[0-1][0-9]{3}|102[0-3][0-9]{2}|102400 + QOSRateMaxUp int `json:"qos_rate_max_up,omitempty"` // -1|[2-9]|[1-9][0-9]{1,4}|100000|10[0-1][0-9]{3}|102[0-3][0-9]{2}|102400 +} + +func (c *Client) listDpiApp(site string) ([]DpiApp, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DpiApp `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/dpiapp", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getDpiApp(site, id string) (*DpiApp, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DpiApp `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteDpiApp(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createDpiApp(site string, d *DpiApp) (*DpiApp, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DpiApp `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/dpiapp", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateDpiApp(site string, d *DpiApp) (*DpiApp, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DpiApp `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/dpi_group.generated.go b/unifi/dpi_group.generated.go new file mode 100644 index 0000000..68b0cb0 --- /dev/null +++ b/unifi/dpi_group.generated.go @@ -0,0 +1,106 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type DpiGroup 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"` + + DPIappIDs []string `json:"dpiapp_ids,omitempty"` // [\d\w]+ + Enabled bool `json:"enabled"` + Name string `json:"name,omitempty"` // .{1,128} +} + +func (c *Client) listDpiGroup(site string) ([]DpiGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DpiGroup `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/dpigroup", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getDpiGroup(site, id string) (*DpiGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DpiGroup `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteDpiGroup(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createDpiGroup(site string, d *DpiGroup) (*DpiGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DpiGroup `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/dpigroup", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateDpiGroup(site string, d *DpiGroup) (*DpiGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DpiGroup `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/dynamic_dns.generated.go b/unifi/dynamic_dns.generated.go new file mode 100644 index 0000000..d8523f0 --- /dev/null +++ b/unifi/dynamic_dns.generated.go @@ -0,0 +1,111 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type DynamicDNS 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"` + + CustomService string `json:"custom_service,omitempty"` // ^[^"' ]+$ + HostName string `json:"host_name,omitempty"` // ^[^"' ]+$ + Interface string `json:"interface,omitempty"` // wan|wan2 + Login string `json:"login,omitempty"` // ^[^"' ]+$ + Options []string `json:"options,omitempty"` // ^[^"' ]+$ + Server string `json:"server"` // ^[^"' ]+$|^$ + Service string `json:"service,omitempty"` // afraid|changeip|cloudflare|dnspark|dslreports|dyndns|easydns|googledomains|namecheap|noip|sitelutions|zoneedit|custom + XPassword string `json:"x_password,omitempty"` // ^[^"' ]+$ +} + +func (c *Client) listDynamicDNS(site string) ([]DynamicDNS, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DynamicDNS `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/dynamicdns", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getDynamicDNS(site, id string) (*DynamicDNS, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DynamicDNS `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteDynamicDNS(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createDynamicDNS(site string, d *DynamicDNS) (*DynamicDNS, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DynamicDNS `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/dynamicdns", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateDynamicDNS(site string, d *DynamicDNS) (*DynamicDNS, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []DynamicDNS `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/firewall_group.generated.go b/unifi/firewall_group.generated.go new file mode 100644 index 0000000..a104603 --- /dev/null +++ b/unifi/firewall_group.generated.go @@ -0,0 +1,106 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type FirewallGroup 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"` + + GroupMembers []string `json:"group_members,omitempty"` + GroupType string `json:"group_type,omitempty"` // address-group|port-group|ipv6-address-group + Name string `json:"name,omitempty"` // .{1,64} +} + +func (c *Client) listFirewallGroup(site string) ([]FirewallGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []FirewallGroup `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/firewallgroup", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getFirewallGroup(site, id string) (*FirewallGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []FirewallGroup `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteFirewallGroup(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createFirewallGroup(site string, d *FirewallGroup) (*FirewallGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []FirewallGroup `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/firewallgroup", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateFirewallGroup(site string, d *FirewallGroup) (*FirewallGroup, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []FirewallGroup `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/firewall_group.go b/unifi/firewall_group.go new file mode 100644 index 0000000..75a1a42 --- /dev/null +++ b/unifi/firewall_group.go @@ -0,0 +1,21 @@ +package unifi + +func (c *Client) ListFirewallGroup(site string) ([]FirewallGroup, error) { + return c.listFirewallGroup(site) +} + +func (c *Client) GetFirewallGroup(site, id string) (*FirewallGroup, error) { + return c.getFirewallGroup(site, id) +} + +func (c *Client) DeleteFirewallGroup(site, id string) error { + return c.deleteFirewallGroup(site, id) +} + +func (c *Client) CreateFirewallGroup(site string, d *FirewallGroup) (*FirewallGroup, error) { + return c.createFirewallGroup(site, d) +} + +func (c *Client) UpdateFirewallGroup(site string, d *FirewallGroup) (*FirewallGroup, error) { + return c.updateFirewallGroup(site, d) +} diff --git a/unifi/firewall_rule.generated.go b/unifi/firewall_rule.generated.go new file mode 100644 index 0000000..07e9fbf --- /dev/null +++ b/unifi/firewall_rule.generated.go @@ -0,0 +1,142 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type FirewallRule 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"` + + 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]+ + DstNetworkconfID string `json:"dst_networkconf_id"` // [\d\w]+|^$ + DstNetworkconfType string `json:"dst_networkconf_type,omitempty"` // ADDRv4|NETv4 + DstPort string `json:"dst_port,omitempty"` + Enabled bool `json:"enabled"` + IcmpTypename string `json:"icmp_typename"` // ^$|communication-prohibited|destination-unreachable|echo-reply|echo-request|fragmentation-needed|host-precedence-violation|host-prohibited|host-redirect|host-unknown|host-unreachable|ip-header-bad|network-prohibited|network-redirect|network-unknown|network-unreachable|parameter-problem|port-unreachable|protocol-unreachable|redirect|required-option-missing|router-advertisement|router-solicitation|source-route-failed|timestamp-reply|timestamp-request|TOS-host-redirect|TOS-host-unreachable|TOS-network-redirect|TOS-network-unreachable|ttl-exceeded|ttl-zero-during-reassembly|ttl-zero-during-transit + Icmpv6Typename string `json:"icmpv6_typename"` // ^$|address-unreachable|bad-header|communication-prohibited|destination-unreachable|echo-reply|echo-request|neighbor-advertisement|neighbor-solicitation|no-route|packet-too-big|parameter-problem|port-unreachable|redirect|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"` + ProtocolV6 string `json:"protocol_v6"` // ^$|([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])|ah|all|dccp|eigrp|esp|gre|icmpv6|ipcomp|ipv6|ipv6-frag|ipv6-icmp|ipv6-nonxt|ipv6-opts|ipv6-route|isis|l2tp|manet|mobility-header|mpls-in-ip|ospf|pim|rsvp|sctp|shim6|tcp|tcp_udp|udp|vrrp + RuleIndex int `json:"rule_index,omitempty"` // 2[0-9]{3}|4[0-9]{3} + Ruleset string `json:"ruleset,omitempty"` // WAN_IN|WAN_OUT|WAN_LOCAL|LAN_IN|LAN_OUT|LAN_LOCAL|GUEST_IN|GUEST_OUT|GUEST_LOCAL|WANv6_IN|WANv6_OUT|WANv6_LOCAL|LANv6_IN|LANv6_OUT|LANv6_LOCAL|GUESTv6_IN|GUESTv6_OUT|GUESTv6_LOCAL + SrcAddress string `json:"src_address,omitempty"` + SrcAddressIPV6 string `json:"src_address_ipv6,omitempty"` + SrcFirewallgroupIDs []string `json:"src_firewallgroup_ids,omitempty"` // [\d\w]+ + SrcMACAddress string `json:"src_mac_address"` // ^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$|^$ + SrcNetworkconfID string `json:"src_networkconf_id"` // [\d\w]+|^$ + SrcNetworkconfType 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 (c *Client) listFirewallRule(site string) ([]FirewallRule, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []FirewallRule `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/firewallrule", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getFirewallRule(site, id string) (*FirewallRule, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []FirewallRule `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteFirewallRule(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createFirewallRule(site string, d *FirewallRule) (*FirewallRule, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []FirewallRule `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/firewallrule", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateFirewallRule(site string, d *FirewallRule) (*FirewallRule, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []FirewallRule `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/firewall_rule.go b/unifi/firewall_rule.go new file mode 100644 index 0000000..d0877a2 --- /dev/null +++ b/unifi/firewall_rule.go @@ -0,0 +1,21 @@ +package unifi + +func (c *Client) ListFirewallRule(site string) ([]FirewallRule, error) { + return c.listFirewallRule(site) +} + +func (c *Client) GetFirewallRule(site, id string) (*FirewallRule, error) { + return c.getFirewallRule(site, id) +} + +func (c *Client) DeleteFirewallRule(site, id string) error { + return c.deleteFirewallRule(site, id) +} + +func (c *Client) CreateFirewallRule(site string, d *FirewallRule) (*FirewallRule, error) { + return c.createFirewallRule(site, d) +} + +func (c *Client) UpdateFirewallRule(site string, d *FirewallRule) (*FirewallRule, error) { + return c.updateFirewallRule(site, d) +} diff --git a/unifi/heat_map.generated.go b/unifi/heat_map.generated.go new file mode 100644 index 0000000..4949dd4 --- /dev/null +++ b/unifi/heat_map.generated.go @@ -0,0 +1,107 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type HeatMap 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"` + + Description string `json:"description,omitempty"` + MapID string `json:"map_id"` + Name string `json:"name,omitempty"` // .*[^\s]+.* + Type string `json:"type,omitempty"` // download|upload +} + +func (c *Client) listHeatMap(site string) ([]HeatMap, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HeatMap `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/heatmap", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getHeatMap(site, id string) (*HeatMap, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HeatMap `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteHeatMap(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createHeatMap(site string, d *HeatMap) (*HeatMap, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HeatMap `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/heatmap", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateHeatMap(site string, d *HeatMap) (*HeatMap, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HeatMap `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/heatmap/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/heat_map_point.generated.go b/unifi/heat_map_point.generated.go new file mode 100644 index 0000000..666a0c0 --- /dev/null +++ b/unifi/heat_map_point.generated.go @@ -0,0 +1,108 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type HeatMapPoint 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"` + + DownloadSpeed float64 `json:"download_speed,omitempty"` + HeatmapID string `json:"heatmap_id"` + UploadSpeed float64 `json:"upload_speed,omitempty"` + X float64 `json:"x,omitempty"` + Y float64 `json:"y,omitempty"` +} + +func (c *Client) listHeatMapPoint(site string) ([]HeatMapPoint, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HeatMapPoint `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/heatmappoint", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getHeatMapPoint(site, id string) (*HeatMapPoint, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HeatMapPoint `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteHeatMapPoint(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createHeatMapPoint(site string, d *HeatMapPoint) (*HeatMapPoint, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HeatMapPoint `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/heatmappoint", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateHeatMapPoint(site string, d *HeatMapPoint) (*HeatMapPoint, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HeatMapPoint `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/hotspot_op.generated.go b/unifi/hotspot_op.generated.go new file mode 100644 index 0000000..50fa991 --- /dev/null +++ b/unifi/hotspot_op.generated.go @@ -0,0 +1,106 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type HotspotOp 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"` + + Name string `json:"name,omitempty"` // .{1,256} + Note string `json:"note,omitempty"` + XPassword string `json:"x_password,omitempty"` // .{1,256} +} + +func (c *Client) listHotspotOp(site string) ([]HotspotOp, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HotspotOp `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/hotspotop", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getHotspotOp(site, id string) (*HotspotOp, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HotspotOp `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteHotspotOp(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createHotspotOp(site string, d *HotspotOp) (*HotspotOp, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HotspotOp `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/hotspotop", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateHotspotOp(site string, d *HotspotOp) (*HotspotOp, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HotspotOp `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/hotspot_package.generated.go b/unifi/hotspot_package.generated.go new file mode 100644 index 0000000..01c6209 --- /dev/null +++ b/unifi/hotspot_package.generated.go @@ -0,0 +1,132 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type HotspotPackage 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"` + + Amount float64 `json:"amount,omitempty"` + ChargedAs string `json:"charged_as,omitempty"` + Currency string `json:"currency,omitempty"` // [A-Z]{3} + CustomPaymentFieldsEnabled bool `json:"custom_payment_fields_enabled"` + Hours int `json:"hours,omitempty"` + Index int `json:"index,omitempty"` + LimitDown int `json:"limit_down,omitempty"` + LimitOverwrite bool `json:"limit_overwrite"` + LimitQuota int `json:"limit_quota,omitempty"` + LimitUp int `json:"limit_up,omitempty"` + Name string `json:"name,omitempty"` + PaymentFieldsAddressEnabled bool `json:"payment_fields_address_enabled"` + PaymentFieldsAddressRequired bool `json:"payment_fields_address_required"` + PaymentFieldsCityEnabled bool `json:"payment_fields_city_enabled"` + PaymentFieldsCityRequired bool `json:"payment_fields_city_required"` + PaymentFieldsCountryDefault string `json:"payment_fields_country_default,omitempty"` + PaymentFieldsCountryEnabled bool `json:"payment_fields_country_enabled"` + PaymentFieldsCountryRequired bool `json:"payment_fields_country_required"` + PaymentFieldsEmailEnabled bool `json:"payment_fields_email_enabled"` + PaymentFieldsEmailRequired bool `json:"payment_fields_email_required"` + PaymentFieldsFirstNameEnabled bool `json:"payment_fields_first_name_enabled"` + PaymentFieldsFirstNameRequired bool `json:"payment_fields_first_name_required"` + PaymentFieldsLastNameEnabled bool `json:"payment_fields_last_name_enabled"` + PaymentFieldsLastNameRequired bool `json:"payment_fields_last_name_required"` + PaymentFieldsStateEnabled bool `json:"payment_fields_state_enabled"` + PaymentFieldsStateRequired bool `json:"payment_fields_state_required"` + PaymentFieldsZipEnabled bool `json:"payment_fields_zip_enabled"` + PaymentFieldsZipRequired bool `json:"payment_fields_zip_required"` + TrialReset float64 `json:"trial_reset,omitempty"` +} + +func (c *Client) listHotspotPackage(site string) ([]HotspotPackage, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HotspotPackage `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/hotspotpackage", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getHotspotPackage(site, id string) (*HotspotPackage, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HotspotPackage `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteHotspotPackage(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createHotspotPackage(site string, d *HotspotPackage) (*HotspotPackage, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HotspotPackage `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/hotspotpackage", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateHotspotPackage(site string, d *HotspotPackage) (*HotspotPackage, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []HotspotPackage `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/map.generated.go b/unifi/map.generated.go new file mode 100644 index 0000000..401eee6 --- /dev/null +++ b/unifi/map.generated.go @@ -0,0 +1,116 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type Map 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"` + + Lat string `json:"lat,omitempty"` // ^([-]?[\d]+[.]?[\d]*([eE][-+]?[\d]+)?)$ + Lng string `json:"lng,omitempty"` // ^([-]?[\d]+[.]?[\d]*([eE][-+]?[\d]+)?)$ + MapTypeID string `json:"mapTypeId"` // satellite|roadmap|hybrid|terrain + Name string `json:"name,omitempty"` + OffsetLeft float64 `json:"offset_left,omitempty"` + OffsetTop float64 `json:"offset_top,omitempty"` + Opacity float64 `json:"opacity,omitempty"` // ^(0(\.[\d]{1,2})?|1)$|^$ + Selected bool `json:"selected"` + Tilt int `json:"tilt,omitempty"` + Type string `json:"type,omitempty"` // designerMap|imageMap|googleMap + Unit string `json:"unit,omitempty"` // m|f + Upp float64 `json:"upp,omitempty"` + Zoom int `json:"zoom,omitempty"` +} + +func (c *Client) listMap(site string) ([]Map, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []Map `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/map", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getMap(site, id string) (*Map, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []Map `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/map/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteMap(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/map/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createMap(site string, d *Map) (*Map, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []Map `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/map", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateMap(site string, d *Map) (*Map, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []Map `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/map/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/media_file.generated.go b/unifi/media_file.generated.go new file mode 100644 index 0000000..77a67c4 --- /dev/null +++ b/unifi/media_file.generated.go @@ -0,0 +1,104 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type MediaFile 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"` + + Name string `json:"name,omitempty"` +} + +func (c *Client) listMediaFile(site string) ([]MediaFile, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []MediaFile `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/mediafile", site), nil, &respBody) + if err != nil { + return nil, err + } + + return respBody.Data, nil +} + +func (c *Client) getMediaFile(site, id string) (*MediaFile, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []MediaFile `json:"data"` + } + + err := c.do("GET", fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), nil, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + d := respBody.Data[0] + return &d, nil +} + +func (c *Client) deleteMediaFile(site, id string) error { + err := c.do("DELETE", fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), struct{}{}, nil) + if err != nil { + return err + } + return nil +} + +func (c *Client) createMediaFile(site string, d *MediaFile) (*MediaFile, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []MediaFile `json:"data"` + } + + err := c.do("POST", fmt.Sprintf("s/%s/rest/mediafile", site), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} + +func (c *Client) updateMediaFile(site string, d *MediaFile) (*MediaFile, error) { + var respBody struct { + Meta meta `json:"meta"` + Data []MediaFile `json:"data"` + } + + err := c.do("PUT", fmt.Sprintf("s/%s/rest/mediafile/%s", site, d.ID), d, &respBody) + if err != nil { + return nil, err + } + + if len(respBody.Data) != 1 { + return nil, &NotFoundError{} + } + + new := respBody.Data[0] + + return &new, nil +} diff --git a/unifi/network.generated.go b/unifi/network.generated.go new file mode 100644 index 0000000..8dc4d3e --- /dev/null +++ b/unifi/network.generated.go @@ -0,0 +1,239 @@ +// Code generated from ace.jar fields *.json files +// DO NOT EDIT. + +package unifi + +import ( + "fmt" +) + +// just to fix compile issues with the import +var _ fmt.Formatter + +type Network 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"` + + DHCPRelayEnabled bool `json:"dhcp_relay_enabled"` + DHCPDBootEnabled bool `json:"dhcpd_boot_enabled"` + DHCPDBootFilename string `json:"dhcpd_boot_filename,omitempty"` // .{1,256} + DHCPDBootServer string `json:"dhcpd_boot_server"` // ^(([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])$|^$|(?=^.{3,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?