From d7a020c62de8174df50a9e565fbd0de449d7fdec Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Mon, 26 Jul 2021 10:41:11 -0700 Subject: [PATCH] Finishing FMS dash board --- openapi/ucentralfws.yaml | 21 ++++++++++++-- src/MicroService.h | 2 ++ src/Utils.cpp | 62 ++++++++++++++++++++++++++++++++++++++++ src/Utils.h | 3 ++ 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/openapi/ucentralfws.yaml b/openapi/ucentralfws.yaml index 53cda12..0c480d9 100644 --- a/openapi/ucentralfws.yaml +++ b/openapi/ucentralfws.yaml @@ -178,6 +178,14 @@ components: latest: type: boolean + FirmwareAgeDetailsList: + type: object + properties: + ages: + type: array + items: + $ref: '#/components/schemas/FirmwareAgeDetails' + DeviceConnectionInformation: type: object properties: @@ -579,13 +587,22 @@ paths: schema: type: string required: true + - in: query + description: Specify lits of serial numbers to retrive age for + name: select + schema: + type: string + example: select=serial1,serial2,serial4,serial5. + required: false responses: 200: description: The recommended latest version to update to. content: application/json: schema: - $ref: '#/components/schemas/FirmwareAgeDetails' + oneOf: + - $ref: '#/components/schemas/FirmwareAgeDetails' + - $ref: '#/components/schemas/FirmwareAgeDetailsList' 403: $ref: '#/components/responses/Unauthorized' 404: @@ -712,7 +729,7 @@ paths: enum: - version - times - required: true + required: true responses: 200: diff --git a/src/MicroService.h b/src/MicroService.h index 1174a19..7dd02e8 100644 --- a/src/MicroService.h +++ b/src/MicroService.h @@ -32,6 +32,8 @@ namespace uCentral { static const std::string uSERVICE_SECURITY{"ucentralsec"}; static const std::string uSERVICE_GATEWAY{"ucentralgw"}; static const std::string uSERVICE_FIRMWARE{ "ucentralfws"}; + static const std::string uSERVICE_TOPOLOGY{ "ucentraltopo"}; + static const std::string uSERVICE_PROVISIONING{ "ucentralprov"}; class MyErrorHandler : public Poco::ErrorHandler { public: diff --git a/src/Utils.cpp b/src/Utils.cpp index 8776f75..ee611cc 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -488,5 +488,67 @@ namespace uCentral::Utils { return Result; } + static bool cidr_match(const in_addr &addr, const in_addr &net, uint8_t bits) { + if (bits == 0) { + return true; + } + return !((addr.s_addr ^ net.s_addr) & htonl(0xFFFFFFFFu << (32 - bits))); + } + + static bool cidr6_match(const in6_addr &address, const in6_addr &network, uint8_t bits) { +#ifdef LINUX + const uint32_t *a = address.s6_addr32; + const uint32_t *n = network.s6_addr32; +#else + const uint32_t *a = address.__u6_addr.__u6_addr32; + const uint32_t *n = network.__u6_addr.__u6_addr32; +#endif + int bits_whole, bits_incomplete; + bits_whole = bits >> 5; // number of whole u32 + bits_incomplete = bits & 0x1F; // number of bits in incomplete u32 + if (bits_whole) { + if (memcmp(a, n, bits_whole << 2)!=0) { + return false; + } + } + if (bits_incomplete) { + uint32_t mask = htonl((0xFFFFFFFFu) << (32 - bits_incomplete)); + if ((a[bits_whole] ^ n[bits_whole]) & mask) { + return false; + } + } + return true; + } + + static bool ConvertStringToLong(const char *S, unsigned long &L) { + char *end; + L = std::strtol(S,&end,10); + return end != S; + } + + bool IPinRange(const std::string &Range, const Poco::Net::IPAddress &IP) { + Poco::StringTokenizer TimeTokens(Range,"/",Poco::StringTokenizer::TOK_TRIM); + + Poco::Net::IPAddress RangeIP; + if(Poco::Net::IPAddress::tryParse(TimeTokens[0],RangeIP)) { + if(TimeTokens.count()==2) { + if (RangeIP.family() == Poco::Net::IPAddress::IPv4) { + unsigned long MaskLength; + if (ConvertStringToLong(TimeTokens[1].c_str(), MaskLength)) { + return cidr_match(*static_cast(RangeIP.addr()), + *static_cast(IP.addr()), MaskLength); + } + } else if (RangeIP.family() == Poco::Net::IPAddress::IPv6) { + unsigned long MaskLength; + if (ConvertStringToLong(TimeTokens[1].c_str(), MaskLength)) { + return cidr6_match(*static_cast(RangeIP.addr()), + *static_cast(IP.addr()), MaskLength); + } + } + } + return false; + } + return false; + } } diff --git a/src/Utils.h b/src/Utils.h index 4745634..afffc72 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -13,6 +13,7 @@ #include #include "Poco/Net/NetworkInterface.h" +#include "Poco/Net/IPAddress.h" #include "Poco/String.h" #include "Poco/File.h" #include "uCentralTypes.h" @@ -70,5 +71,7 @@ namespace uCentral::Utils { [[nodiscard]] std::string BinaryFileToHexString( const Poco::File &F); [[nodiscard]] std::string SecondsToNiceText(uint64_t Seconds); + + [[nodiscard]] bool IPinRange(const std::string &Range, const Poco::Net::IPAddress &IP); } #endif // UCENTRALGW_UTILS_H