database complete for gateway map

pull/14/head
Tom Early 6 years ago
parent b3d8314627
commit 05d01f44a0

@ -29,6 +29,7 @@
#include <netdb.h> #include <netdb.h>
#include "DPlusAuthenticator.h" #include "DPlusAuthenticator.h"
#include "Utilities.h"
CDPlusAuthenticator::CDPlusAuthenticator(const std::string &loginCallsign, const std::string &address) : CDPlusAuthenticator::CDPlusAuthenticator(const std::string &loginCallsign, const std::string &address) :
m_loginCallsign(loginCallsign), m_loginCallsign(loginCallsign),
@ -36,25 +37,25 @@ m_address(address)
{ {
assert(loginCallsign.size()); assert(loginCallsign.size());
Trim(m_loginCallsign); trim(m_loginCallsign);
} }
CDPlusAuthenticator::~CDPlusAuthenticator() CDPlusAuthenticator::~CDPlusAuthenticator()
{ {
} }
bool CDPlusAuthenticator::Process(CQnetDB &db, const bool reflectors, const bool repeaters) int CDPlusAuthenticator::Process(CQnetDB &db, const bool reflectors, const bool repeaters)
// return true if everything went okay // return true if everything went okay
{ {
int result = client.Open(m_address, AF_UNSPEC, "20001"); int result = client.Open(m_address, AF_UNSPEC, "20001");
if (result) { if (result) {
fprintf(stderr, "DPlus Authorization failed: %s\n", gai_strerror(result)); fprintf(stderr, "DPlus Authorization failed: %s\n", gai_strerror(result));
return true; return 0;
} }
return authenticate(db, reflectors, repeaters); return authenticate(db, reflectors, repeaters);
} }
bool CDPlusAuthenticator::authenticate(CQnetDB &db, const bool reflectors, const bool repeaters) int CDPlusAuthenticator::authenticate(CQnetDB &db, const bool reflectors, const bool repeaters)
{ {
unsigned char* buffer = new unsigned char[4096U]; unsigned char* buffer = new unsigned char[4096U];
::memset(buffer, ' ', 56U); ::memset(buffer, ' ', 56U);
@ -73,11 +74,11 @@ bool CDPlusAuthenticator::authenticate(CQnetDB &db, const bool reflectors, const
fprintf(stderr, "ERROR: could not write opening phrase\n"); fprintf(stderr, "ERROR: could not write opening phrase\n");
client.Close(); client.Close();
delete[] buffer; delete[] buffer;
return true; return 0;
} }
int ret = client.ReadExact(buffer, 2U); int ret = client.ReadExact(buffer, 2U);
unsigned int returned = 0; unsigned int rval = 0;
while (ret == 2) { while (ret == 2) {
unsigned int len = (buffer[1U] & 0x0FU) * 256U + buffer[0U]; unsigned int len = (buffer[1U] & 0x0FU) * 256U + buffer[0U];
@ -85,20 +86,20 @@ bool CDPlusAuthenticator::authenticate(CQnetDB &db, const bool reflectors, const
ret = client.ReadExact(buffer + 2U, len - 2U); ret = client.ReadExact(buffer + 2U, len - 2U);
if (0 > ret) { if (0 > ret) {
fprintf(stderr, "Problem reading line, it returned %d\n", errno); fprintf(stderr, "Problem reading line, it returned %d\n", errno);
return true; return rval;
} }
if ((buffer[1U] & 0xC0U) != 0xC0U || buffer[2U] != 0x01U) { if ((buffer[1U] & 0xC0U) != 0xC0U || buffer[2U] != 0x01U) {
fprintf(stderr, "Invalid packet received from 20001\n"); fprintf(stderr, "Invalid packet received from 20001\n");
return true; return rval;
} }
for (unsigned int i = 8U; (i + 25U) < len; i += 26U) { for (unsigned int i = 8U; (i + 25U) < len; i += 26U) {
std::string address((char *)(buffer + i)); std::string address((char *)(buffer + i));
std::string name((char *)(buffer + i + 16U)); std::string name((char *)(buffer + i + 16U));
Trim(address); trim(address);
Trim(name); trim(name);
name.resize(6, ' '); name.resize(6, ' ');
// Get the active flag // Get the active flag
@ -106,7 +107,7 @@ bool CDPlusAuthenticator::authenticate(CQnetDB &db, const bool reflectors, const
// An empty name or IP address or an inactive gateway/reflector is not added // An empty name or IP address or an inactive gateway/reflector is not added
if (address.size()>0U && name.size()>0U && active) { if (address.size()>0U && name.size()>0U && active) {
returned++; rval++;
if (reflectors && 0==name.compare(0, 3, "REF")) if (reflectors && 0==name.compare(0, 3, "REF"))
db.UpdateGW(name.c_str(), address.c_str(), 20001); db.UpdateGW(name.c_str(), address.c_str(), 20001);
else if (repeaters && name.compare(0, 3, "REF")) else if (repeaters && name.compare(0, 3, "REF"))
@ -118,22 +119,9 @@ bool CDPlusAuthenticator::authenticate(CQnetDB &db, const bool reflectors, const
} }
printf("Probably authorized DPlus on %s using callsign %s\n", m_address.c_str(), m_loginCallsign.c_str()); printf("Probably authorized DPlus on %s using callsign %s\n", m_address.c_str(), m_loginCallsign.c_str());
printf("%s returned %u systems\n", m_address.c_str(), returned);
client.Close(); client.Close();
delete[] buffer; delete[] buffer;
return false; return rval;
}
void CDPlusAuthenticator::Trim(std::string &s)
{
auto it = s.begin();
while (it!=s.end() && isspace(*it))
s.erase(it);
auto rit = s.rbegin();
while (rit!=s.rend() && isspace(*rit)) {
s.resize(s.size() - 1);
rit = s.rbegin();
}
} }

@ -30,13 +30,12 @@ public:
CDPlusAuthenticator(const std::string &loginCallsign, const std::string &address); CDPlusAuthenticator(const std::string &loginCallsign, const std::string &address);
~CDPlusAuthenticator(); ~CDPlusAuthenticator();
bool Process(CQnetDB &qn, const bool reflectors, const bool repeaters); int Process(CQnetDB &qn, const bool reflectors, const bool repeaters);
private: private:
std::string m_loginCallsign; std::string m_loginCallsign;
std::string m_address; std::string m_address;
CTCPReaderWriterClient client; CTCPReaderWriterClient client;
void Trim(std::string &s); int authenticate(CQnetDB &db, const bool reflectors, const bool repeaters);
bool authenticate(CQnetDB &db, const bool reflectors, const bool repeaters);
}; };

@ -262,7 +262,7 @@ void CQnetDB::ClearGW()
} }
} }
static int countcallback(void *count, int argc, char **argv, char **azColName) { static int countcallback(void *count, int /*argc*/, char **argv, char **/*azColName*/) {
auto c = (int *)count; auto c = (int *)count;
*c = atoi(argv[0]); *c = atoi(argv[0]);
return 0; return 0;
@ -271,7 +271,7 @@ static int countcallback(void *count, int argc, char **argv, char **azColName) {
int CQnetDB::Count(const char *table) int CQnetDB::Count(const char *table)
{ {
if (NULL == db) if (NULL == db)
return; return 0;
std::string sql("SELECT COUNT(*) FROM "); std::string sql("SELECT COUNT(*) FROM ");
sql.append(table); sql.append(table);

@ -54,7 +54,7 @@
#define CFG_DIR "/usr/local/etc" #define CFG_DIR "/usr/local/etc"
#endif #endif
const std::string GW_VERSION("QnetGateway-409"); const std::string GW_VERSION("QnetGateway-415");
static std::atomic<bool> keep_running(true); static std::atomic<bool> keep_running(true);

@ -54,7 +54,7 @@
#include "QnetLink.h" #include "QnetLink.h"
#include "Utilities.h" #include "Utilities.h"
#define LINK_VERSION "QnetLink-409" #define LINK_VERSION "QnetLink-415"
#ifndef BIN_DIR #ifndef BIN_DIR
#define BIN_DIR "/usr/local/bin" #define BIN_DIR "/usr/local/bin"
#endif #endif
@ -290,17 +290,21 @@ void CQnetLink::RptrAckThread(char *arg)
} }
/* Open text file of repeaters, reflectors */ /* Open text file of repeaters, reflectors */
bool CQnetLink::load_gwys(const std::string &filename) void CQnetLink::LoadGateways(const std::string &filename)
{ {
const std::string website("auth.dstargateway.org");
int dplus = 0;
// DPlus Authenticate // DPlus Authenticate
if (dplus_authorize && !dplus_priority) { if (dplus_authorize && !dplus_priority) {
CDPlusAuthenticator auth(login_call, std::string("auth.dstargateway.org")); CDPlusAuthenticator auth(login_call, std::string(website.c_str()));
if (auth.Process(qnDB, dplus_reflectors, dplus_repeaters)) dplus = auth.Process(qnDB, dplus_reflectors, dplus_repeaters);
if (0 == dplus)
fprintf(stdout, "DPlus Authorization failed.\n"); fprintf(stdout, "DPlus Authorization failed.\n");
else else
fprintf(stderr, "DPlus Authorization complete!\n"); fprintf(stderr, "DPlus Authorization complete!\n");
} }
int count = 0;
std::ifstream hostfile(filename); std::ifstream hostfile(filename);
if (hostfile.is_open()) { if (hostfile.is_open()) {
std::string line; std::string line;
@ -312,25 +316,31 @@ bool CQnetLink::load_gwys(const std::string &filename)
unsigned short port; unsigned short port;
iss >> host >> address >> port; iss >> host >> address >> port;
qnDB.UpdateGW(host.c_str(), address.c_str(), port); qnDB.UpdateGW(host.c_str(), address.c_str(), port);
count++;
} }
} }
hostfile.close(); hostfile.close();
} }
if (dplus_authorize) {
if (! dplus_priority)
printf("#Gateways: %s=%d %s=%d Total=%d\n", website.c_str(), dplus, filename.c_str(), count, qnDB.Count("GATEWAYS"));
} else {
printf("#Gateways: %s=%d\n", filename.c_str(), count);
}
// DPlus Authenticate // DPlus Authenticate
if (dplus_authorize && dplus_priority) { if (dplus_authorize && dplus_priority) {
CDPlusAuthenticator auth(login_call, std::string("auth.dstargateway.org")); CDPlusAuthenticator auth(login_call, std::string(website.c_str()));
if (auth.Process(qnDB, dplus_reflectors, dplus_repeaters)) dplus = auth.Process(qnDB, dplus_reflectors, dplus_repeaters);
if (0 == dplus) {
printf("#Gateways: %s=%d\n", filename.c_str(), count);
fprintf(stdout, "DPlus Authorization failed.\n"); fprintf(stdout, "DPlus Authorization failed.\n");
else } else {
fprintf(stderr, "DPlus Authorization completed!\n"); fprintf(stderr, "DPlus Authorization completed!\n");
printf("#Gateways %s=%d %s=%d Total=%d\n", filename.c_str(), count, website.c_str(), dplus, qnDB.Count("GATEWAYS"));
}
} }
auto count = qnDB.Count("GATEWAYS");
if (count)
printf("Loaded %d gateways from %s%s\n", count, filename.c_str(), dplus_authorize ? " and auth.dstargateway.org" : "");
return true;
} }
/* compute checksum */ /* compute checksum */
@ -423,7 +433,7 @@ void CQnetLink::PrintCallsigns(const std::string &key, const std::set<std::strin
} }
/* process configuration file */ /* process configuration file */
bool CQnetLink::read_config(const char *cfgFile) bool CQnetLink::ReadConfig(const char *cfgFile)
{ {
CQnetConfigure cfg; CQnetConfigure cfg;
const std::string estr; // an empty string const std::string estr; // an empty string
@ -2747,7 +2757,7 @@ void CQnetLink::Process()
} }
else if (0==memcmp(dsvt.hdr.urcall, " F", CALL_SIZE) && admin.find(call)!=admin.end()) { // only ADMIN can reload gwys.txt else if (0==memcmp(dsvt.hdr.urcall, " F", CALL_SIZE) && admin.find(call)!=admin.end()) { // only ADMIN can reload gwys.txt
qnDB.ClearGW(); qnDB.ClearGW();
load_gwys(gwys); LoadGateways(gwys);
} }
} }
@ -3259,7 +3269,7 @@ bool CQnetLink::Init(const char *cfgfile)
brd_from_rptr_idx = 0; brd_from_rptr_idx = 0;
/* process configuration file */ /* process configuration file */
if (read_config(cfgfile)) { if (ReadConfig(cfgfile)) {
printf("Failed to process config file %s\n", cfgfile); printf("Failed to process config file %s\n", cfgfile);
return true; return true;
} }
@ -3270,9 +3280,7 @@ bool CQnetLink::Init(const char *cfgfile)
if (qnDB.Open(fname.c_str())) if (qnDB.Open(fname.c_str()))
return true; return true;
/* Open DB */ LoadGateways(gwys);
if (!load_gwys(gwys))
return true;
/* create our server */ /* create our server */
if (!srv_open()) { if (!srv_open()) {

@ -86,9 +86,9 @@ private:
void ToUpper(std::string &s); void ToUpper(std::string &s);
void UnpackCallsigns(const std::string &str, std::set<std::string> &set, const std::string &delimiters = ","); void UnpackCallsigns(const std::string &str, std::set<std::string> &set, const std::string &delimiters = ",");
void PrintCallsigns(const std::string &key, const std::set<std::string> &set); void PrintCallsigns(const std::string &key, const std::set<std::string> &set);
bool load_gwys(const std::string &filename); void LoadGateways(const std::string &filename);
void calcPFCS(unsigned char *packet, int len); void calcPFCS(unsigned char *packet, int len);
bool read_config(const char *); bool ReadConfig(const char *);
bool srv_open(); bool srv_open();
void srv_close(); void srv_close();
static void sigCatch(int signum); static void sigCatch(int signum);

@ -1,5 +1,5 @@
# #
# Copyright (c) 2019 by Thomas A. Early N7TAE # Copyright (c) 2019-2020 by Thomas A. Early N7TAE
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by

Loading…
Cancel
Save

Powered by TurnKey Linux.