changes to ysf db support

pull/1/head
Tom Early 5 years ago
parent 3c8b4ab763
commit fefb1be1d0

@ -196,8 +196,8 @@ USE ${ysfdbname};
CREATE TABLE IF NOT EXISTS ysfnodes (
callsign VARCHAR(7) PRIMARY KEY,
password VARCHAR(255) NOT NULL,
txfreq INT NOT NULL DEFAULT 446500000,
rxfreq INT NOT NULL DEFAULT 446500000,
txfreq INT NOT NULL DEFAULT 445500000,
rxfreq INT NOT NULL DEFAULT 445500000,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE USER IF NOT EXISTS '${ysfdbuser}'@'localhost' IDENTIFIED BY '${ysfdbpw}';

@ -78,11 +78,18 @@ void CYsfNodeDir::Thread()
while (keep_running)
{
// Wait YSFNODEDB_REFRESH_RATE minutes
for (int i=0; i<30*YSFNODEDB_REFRESH_RATE && keep_running; i++)
for (int i=0; keep_running && (i < 30*YSFNODEDB_REFRESH_RATE); i++)
{
CTimePoint::TaskSleepFor(2000);
#if YSF_DB_SUPPORT==true
if (keep_running && (0 == i % 450))
{
ReadDb(); // update from the db every 15 minutes
}
#endif
}
// have lists files changed ?
if ( NeedReload() )
if (keep_running && NeedReload())
{
Reload();
}
@ -100,7 +107,7 @@ bool CYsfNodeDir::Reload(void)
if ( LoadContent(&buffer) )
{
Lock();
ok = RefreshContent(buffer) && ReadDb();
ok = RefreshContent(buffer);
Unlock();
}
return ok;
@ -126,10 +133,9 @@ bool CYsfNodeDir::FindFrequencies(const CCallsign &callsign, uint32 *txfreq, uin
}
}
bool CYsfNodeDir::ReadDb()
{
#if YSF_DB_SUPPORT==true
bool rval = false;
void CYsfNodeDir::ReadDb()
{
MYSQL *con = mysql_init(NULL);
if (con)
{
@ -140,7 +146,6 @@ bool CYsfNodeDir::ReadDb()
MYSQL_RES *result = mysql_store_result(con);
if (result)
{
rval = true;
std::cout << "Adding " << mysql_num_rows(result) << " registered YSF stations from table " << YSF_DB_NAME << std::endl;
MYSQL_ROW row;
@ -148,8 +153,7 @@ bool CYsfNodeDir::ReadDb()
{
CCallsign cs(row[0]);
CYsfNode node(atoi(row[1]), atoi(row[2]));
std::pair<CCallsign, CYsfNode> pair(cs, node);
insert(pair);
m_map[cs] = node;
}
mysql_free_result(result);
@ -172,11 +176,7 @@ bool CYsfNodeDir::ReadDb()
}
else
{
std::cerr << "Could not init mysql." << std::endl;
return false;
std::cerr << "Could not init mysql." << std::endl;;
}
return rval;
#else
return true;
#endif
}
#endif

@ -84,7 +84,9 @@ protected:
// reload helpers
bool Reload(void);
virtual bool NeedReload(void) { return false; }
bool ReadDb(void);
#if YSF_DB_SUPPORT==true;
void ReadDb(void);
#endif
//bool IsValidDmrid(const char *);

@ -137,8 +137,8 @@
#define YSF_PORT 42000 // UDP port
#define YSF_KEEPALIVE_PERIOD 3 // in seconds
#define YSF_KEEPALIVE_TIMEOUT (YSF_KEEPALIVE_PERIOD*10) // in seconds
#define YSF_DEFAULT_NODE_TX_FREQ 446500000 // in Hz
#define YSF_DEFAULT_NODE_RX_FREQ 446500000 // in Hz
#define YSF_DEFAULT_NODE_TX_FREQ 445500000 // in Hz
#define YSF_DEFAULT_NODE_RX_FREQ 445500000 // in Hz
// the following two defines are now in configure.h
// #define YSF_AUTOLINK_ENABLE 0 // 1 = enable, 0 = disable auto-link
// #define YSF_AUTOLINK_MODULE 'B' // module for client to auto-link to

@ -59,9 +59,10 @@ if ($stmt = mysqli_prepare($link, $sql)) {
</div>
<div class="wrapper">
<h2>Hot-Spot Frequencies Summary</h2>
<p>Hot-spot Callsign: <?php echo $_SESSION["callsign"]; ?></p>
<p>Hot-spot Callsign: <?php echo htmlspecialchars($_SESSION["callsign"]); ?></p>
<p>Transmit Frequency: <?php echo $txfreq; ?> MHz</p>
<p>Receive Frequency: <?php echo $rxfreq; ?> MHz</p>
<p>It can take up to 15 minutes for the frequency data to be available to the reflector. Please be patient.</p>
</div>
<p>
<a href="frequency.php" class="btn btn-primary">Reset Frequencies</a>

@ -57,7 +57,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check input errors before updating the database
if (empty($txfreq_err) && empty($rxfreq_err)) {
// Prepare an update statement
$sql = "UPDATE users SET txfreq = ?, rxfreq = ? WHERE callsign = ?";
$sql = "UPDATE ysfnodes SET txfreq = ?, rxfreq = ? WHERE callsign = ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters

@ -78,7 +78,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($callsign_err) && empty($password_err) && empty($confirm_password_err)) {
// Prepare an insert statement
$sql = "INSERT INTO users (callsign, password) VALUES (?, ?)";
$sql = "INSERT INTO ysfnodes (callsign, password) VALUES (?, ?)";
if ($stmt = mysqli_prepare($link, $sql)) {
// Bind variables to the prepared statement as parameters

@ -40,7 +40,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check input errors before updating the database
if (empty($new_password_err) && empty($confirm_password_err)) {
// Prepare an update statement
$sql = "UPDATE users SET password = ? WHERE callsign = ?";
$sql = "UPDATE ysfnodes SET password = ? WHERE callsign = ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters

Loading…
Cancel
Save

Powered by TurnKey Linux.