mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-04-10 14:58:21 +02:00
2017-10-14 Fred Gleason <fredg@paravelsystems.com>
* Implemented a 'NewHostIpAddress=' parameter in the [Provisioning] section of rd.conf(5).
This commit is contained in:
parent
a5861283c9
commit
2381fb89ff
@ -16099,3 +16099,6 @@
|
||||
2017-10-14 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Implemented resolution of date wildcards for the RLM 'Path' and
|
||||
'Argument' parameters.
|
||||
2017-10-14 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Implemented a 'NewHostIpAddress=' parameter in the [Provisioning]
|
||||
section of rd.conf(5).
|
||||
|
@ -591,7 +591,7 @@ void MainObject::InitProvisioning() const
|
||||
"NAME=\""+RDEscapeString(rd_config->stationName())+"\"";
|
||||
q=new RDSqlQuery(sql);
|
||||
if(!q->first()) {
|
||||
if(RDStation::create(rd_config->stationName(),&err_msg,rd_config->provisioningHostTemplate())) {
|
||||
if(RDStation::create(rd_config->stationName(),&err_msg,rd_config->provisioningHostTemplate(),rd_config->provisioningHostIpAddress())) {
|
||||
syslog(LOG_INFO,"created new host entry \"%s\"",
|
||||
(const char *)rd_config->stationName());
|
||||
}
|
||||
|
@ -36,9 +36,12 @@ XportHostname=
|
||||
[Provisioning]
|
||||
; If CreateHost=Yes, a Host entry will be automatically created in the DB
|
||||
; when the 'rivendell' system service is started, using the Host definition
|
||||
; specified in NewHostTemplate= as the template.
|
||||
; specified in NewHostTemplate= as the template. The new host entry will be
|
||||
; assigned the IP address bound to the network interface specified by
|
||||
; NewHostIpAddress= ('lo' by default).
|
||||
CreateHost=No
|
||||
NewHostTemplate=some_host_entry
|
||||
NewHostIpAddress=lo
|
||||
|
||||
; If CreateService=Yes, a Service entry will be automatically created in the DB
|
||||
; when the 'rivendell' system service is started, using the Service definition
|
||||
|
@ -23,6 +23,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/ioctl.h>
|
||||
#endif // WIN32
|
||||
|
||||
#include <qmessagebox.h>
|
||||
@ -261,6 +265,12 @@ QString RDConfig::provisioningHostTemplate() const
|
||||
}
|
||||
|
||||
|
||||
QHostAddress RDConfig::provisioningHostIpAddress() const
|
||||
{
|
||||
return conf_provisioning_host_ip_address;
|
||||
}
|
||||
|
||||
|
||||
bool RDConfig::provisioningCreateService() const
|
||||
{
|
||||
return conf_provisioning_create_service;
|
||||
@ -450,6 +460,7 @@ void RDConfig::load()
|
||||
char sname[256];
|
||||
QString client;
|
||||
QString facility;
|
||||
QString iface;
|
||||
#ifndef WIN32
|
||||
struct passwd *user;
|
||||
struct group *groups;
|
||||
@ -489,6 +500,7 @@ void RDConfig::load()
|
||||
profile->boolValue("Provisioning","CreateHost");
|
||||
conf_provisioning_host_template=
|
||||
profile->stringValue("Provisioning","NewHostTemplate");
|
||||
iface=profile->stringValue("Provisioning","NewHostIpAddress","lo");
|
||||
conf_provisioning_create_service=
|
||||
profile->boolValue("Provisioning","CreateService");
|
||||
conf_provisioning_service_template=
|
||||
@ -566,6 +578,33 @@ void RDConfig::load()
|
||||
conf_destinations.push_back(dest);
|
||||
}
|
||||
delete profile;
|
||||
|
||||
//
|
||||
// Resolve Interface Address
|
||||
//
|
||||
int sock=-1;
|
||||
|
||||
if((sock=socket(PF_INET,SOCK_DGRAM,IPPROTO_IP))<0) {
|
||||
return;
|
||||
}
|
||||
#ifndef WIN32
|
||||
struct ifreq ifr;
|
||||
int index=0;
|
||||
|
||||
memset(&ifr,0,sizeof(ifr));
|
||||
index=1;
|
||||
ifr.ifr_ifindex=index;
|
||||
while(ioctl(sock,SIOCGIFNAME,&ifr)==0) {
|
||||
if(ifr.ifr_name==iface) {
|
||||
if(ioctl(sock,SIOCGIFADDR,&ifr)==0) {
|
||||
struct sockaddr_in sa=*(sockaddr_in *)(&ifr.ifr_addr);
|
||||
conf_provisioning_host_ip_address.setAddress(ntohl(sa.sin_addr.s_addr));
|
||||
}
|
||||
}
|
||||
ifr.ifr_ifindex=++index;
|
||||
}
|
||||
close(sock);
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
|
||||
@ -595,6 +634,7 @@ void RDConfig::clear()
|
||||
conf_log_xload_debug_data=false;
|
||||
conf_provisioning_create_host=false;
|
||||
conf_provisioning_host_template="";
|
||||
conf_provisioning_host_ip_address.setAddress("127.0.0.2");
|
||||
conf_provisioning_create_service=false;
|
||||
conf_provisioning_service_template="";
|
||||
conf_alsa_period_quantity=RD_ALSA_DEFAULT_PERIOD_QUANTITY;
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// A container class for a Rivendell Base Configuration
|
||||
//
|
||||
// (C) Copyright 2002-2004,2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2002-2004,2016-2017 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -28,6 +28,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <qhostaddress.h>
|
||||
#include <qstring.h>
|
||||
|
||||
#include <rd.h>
|
||||
@ -67,6 +68,7 @@ class RDConfig
|
||||
void log(const QString &module,LogPriority prio,const QString &msg);
|
||||
bool provisioningCreateHost() const;
|
||||
QString provisioningHostTemplate() const;
|
||||
QHostAddress provisioningHostIpAddress() const;
|
||||
bool provisioningCreateService() const;
|
||||
QString provisioningServiceTemplate() const;
|
||||
int alsaPeriodQuantity() const;
|
||||
@ -127,6 +129,7 @@ class RDConfig
|
||||
QString conf_log_pattern;
|
||||
bool conf_provisioning_create_host;
|
||||
QString conf_provisioning_host_template;
|
||||
QHostAddress conf_provisioning_host_ip_address;
|
||||
bool conf_provisioning_create_service;
|
||||
QString conf_provisioning_service_template;
|
||||
bool conf_log_xload_debug_data;
|
||||
|
@ -664,15 +664,21 @@ void RDStation::setCardOutputs(int cardnum,int outputs) const
|
||||
|
||||
|
||||
bool RDStation::create(const QString &name,QString *err_msg,
|
||||
const QString &exemplar)
|
||||
const QString &exemplar,const QHostAddress &hostaddr)
|
||||
{
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
RDSqlQuery *q1;
|
||||
QHostAddress addr=hostaddr;
|
||||
|
||||
if(addr.isNull()) {
|
||||
addr.setAddress("127.0.0.1");
|
||||
}
|
||||
|
||||
if(exemplar.isEmpty()) { // Create Blank Host Config
|
||||
sql=QString("insert into STATIONS set ")+
|
||||
"NAME=\""+RDEscapeString(name)+"\","+
|
||||
"IPV4_ADDRESS=\""+RDEscapeString(addr.toString())+"\","+
|
||||
"DESCRIPTION=\"Workstation "+RDEscapeString(name)+"\","+
|
||||
"USER_NAME=\"user\","+
|
||||
"DEFAULT_NAME=\"user\"";
|
||||
@ -755,6 +761,7 @@ bool RDStation::create(const QString &name,QString *err_msg,
|
||||
if(q->first()) {
|
||||
sql=QString("insert into STATIONS set ")+
|
||||
"NAME=\""+RDEscapeString(name)+"\","+
|
||||
"IPV4_ADDRESS=\""+RDEscapeString(addr.toString())+"\","+
|
||||
"DESCRIPTION=\""+RDEscapeString("Workstation "+name)+"\","+
|
||||
"USER_NAME=\""+RDEscapeString(q->value(0).toString())+"\","+
|
||||
"DEFAULT_NAME=\""+RDEscapeString(q->value(0).toString())+"\","+
|
||||
|
@ -132,7 +132,8 @@ class RDStation
|
||||
int cardOutputs(int cardnum) const;
|
||||
void setCardOutputs(int cardnum,int outputs) const;
|
||||
static bool create(const QString &name,QString *err_msg,
|
||||
const QString &exemplar="");
|
||||
const QString &exemplar="",
|
||||
const QHostAddress &hostaddr=QHostAddress());
|
||||
static void remove(const QString &name);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user