Finishing FMS dash board

This commit is contained in:
stephb9959
2021-07-26 10:41:11 -07:00
parent a463f3ca0d
commit d7a020c62d
4 changed files with 86 additions and 2 deletions

View File

@@ -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:

View File

@@ -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:

View File

@@ -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<const in_addr *>(RangeIP.addr()),
*static_cast<const in_addr *>(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<const in6_addr *>(RangeIP.addr()),
*static_cast<const in6_addr *>(IP.addr()), MaskLength);
}
}
}
return false;
}
return false;
}
}

View File

@@ -13,6 +13,7 @@
#include <string>
#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