Add Static Devices, Timeout and UniFi Port Directive
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "Util/clipp.h"
|
||||
#include "Util/Device.h"
|
||||
#include "Util/INIh.h"
|
||||
#include "Util/Logger.h"
|
||||
#include "UniFi/Device.h"
|
||||
@@ -62,13 +64,60 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
std::string target = iniReader.Get("PresenceDetection", "Target", "");
|
||||
if (target.empty())
|
||||
throw std::runtime_error("Target directive missing in ini file.");
|
||||
|
||||
bool unifi = iniReader.GetBoolean("PresenceDetection", "UniFi", false);
|
||||
|
||||
bool bluetooth = iniReader.GetBoolean("PresenceDetection", "Bluetooth", false);
|
||||
|
||||
std::vector<PresenceDetection::Util::Device> devices;
|
||||
|
||||
auto sections = iniReader.Sections();
|
||||
for (auto section : sections)
|
||||
{
|
||||
if (section != "PresenceDetection" &&
|
||||
section != "UniFi" &&
|
||||
section != "Bluetooth")
|
||||
{
|
||||
std::string WifiMac = iniReader.Get(section, "WifiMac", "");
|
||||
std::string BluetoothMac = iniReader.Get(section, "BluetoothMac", "");
|
||||
|
||||
if (WifiMac.empty() && BluetoothMac.empty())
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << section << ": No Wifi or Bluetooth Mac address defined" << std::endl;
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
auto device = PresenceDetection::Util::Device(WifiMac, BluetoothMac);
|
||||
|
||||
std::string OnlineURL = iniReader.Get(section, "OnlineURL", "");
|
||||
if (!OnlineURL.empty())
|
||||
device.SetOnlineURL(OnlineURL);
|
||||
|
||||
std::string WifiOnlineURL = iniReader.Get(section, "WifiOnlineURL", "");
|
||||
if (!WifiOnlineURL.empty())
|
||||
device.SetWifiOnlineURL(WifiOnlineURL);
|
||||
|
||||
std::string BluetoothOnlineURL = iniReader.Get(section, "BluetoothOnlineURL", "");
|
||||
if (!BluetoothOnlineURL.empty())
|
||||
device.SetBluetoothOnlineURL(BluetoothOnlineURL);
|
||||
|
||||
std::string OfflineURL = iniReader.Get(section, "OfflineURL", "");
|
||||
if (!OfflineURL.empty())
|
||||
device.SetOfflineURL(OfflineURL);
|
||||
|
||||
std::string WifiOfflineURL = iniReader.Get(section, "WifiOfflineURL", "");
|
||||
if (!WifiOfflineURL.empty())
|
||||
device.SetWifiOfflineURL(WifiOfflineURL);
|
||||
|
||||
std::string BluetoothOfflineURL = iniReader.Get(section, "BluetoothOfflineURL", "");
|
||||
if (!BluetoothOfflineURL.empty())
|
||||
device.SetBluetoothOfflineURL(BluetoothOfflineURL);
|
||||
|
||||
devices.push_back(device);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<PresenceDetection::UniFi::Device> pUniFiDevice;
|
||||
if (unifi)
|
||||
{
|
||||
@@ -76,6 +125,8 @@ int main(int argc, char** argv)
|
||||
if (hostname.empty())
|
||||
throw std::runtime_error("UniFi Hostname directive missing in ini file.");
|
||||
|
||||
int port = iniReader.GetInteger("UniFi", "Port", 8443);
|
||||
|
||||
std::string username = iniReader.Get("UniFi", "Username", "");
|
||||
if (username.empty())
|
||||
throw std::runtime_error("UniFi Username directive missing in ini file.");
|
||||
@@ -88,21 +139,21 @@ int main(int argc, char** argv)
|
||||
if (cookiefile.empty())
|
||||
throw std::runtime_error("UniFi CookieFile directive missing in ini file.");
|
||||
|
||||
std::string inventoryURL = iniReader.Get("UniFi", "Inventory", "");
|
||||
if (inventoryURL.empty())
|
||||
throw std::runtime_error("UniFi Inventory directive missing in ini file.");
|
||||
int timeout = iniReader.GetInteger("UniFi", "Timeout", 150);
|
||||
|
||||
pUniFiDevice = std::make_shared<PresenceDetection::UniFi::Device>(hostname, username, password, cookiefile, inventoryURL, target);
|
||||
std::string inventoryURL = iniReader.Get("UniFi", "Inventory", "");
|
||||
|
||||
pUniFiDevice = std::make_shared<PresenceDetection::UniFi::Device>(hostname, port, username, password, cookiefile, timeout, inventoryURL, target, devices);
|
||||
}
|
||||
|
||||
std::shared_ptr<PresenceDetection::Bluetooth::Device> pBluetoothDevice;
|
||||
if (bluetooth)
|
||||
{
|
||||
std::string inventoryURL = iniReader.Get("Bluetooth", "Inventory", "");
|
||||
if (inventoryURL.empty())
|
||||
throw std::runtime_error("Bluetooth Inventory directive missing in ini file.");
|
||||
int timeout = iniReader.GetInteger("Bluetooth", "Timeout", 150);
|
||||
|
||||
pBluetoothDevice = std::make_shared<PresenceDetection::Bluetooth::Device>(inventoryURL, target);
|
||||
std::string inventoryURL = iniReader.Get("Bluetooth", "Inventory", "");
|
||||
|
||||
pBluetoothDevice = std::make_shared<PresenceDetection::Bluetooth::Device>(timeout, inventoryURL, target, devices);
|
||||
}
|
||||
|
||||
sigset_t wset;
|
||||
|
||||
Reference in New Issue
Block a user