mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-07-10 01:17:45 +02:00
2017-08-03 Fred Gleason <fredg@paravelsystems.com>
* Added an 'rlm_urlwrite' RLM in 'rlm/rlm_urlwrite.c'.
This commit is contained in:
parent
32186e0316
commit
1ac9a20c33
@ -15922,3 +15922,5 @@
|
||||
2017-08-02 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Refactored the algorithm for calculating web tickets in
|
||||
'web/rdxport/rdxport.cpp'.
|
||||
2017-08-03 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Added an 'rlm_urlwrite' RLM in 'rlm/rlm_urlwrite.c'.
|
||||
|
@ -51,6 +51,7 @@ EXTRA_DIST = my.cnf-master\
|
||||
rlm_tagstation.conf\
|
||||
rlm_twitter.conf\
|
||||
rlm_udp.conf\
|
||||
rlm_urlwrite.conf\
|
||||
rlm_walltime.conf\
|
||||
rlm_xds.conf\
|
||||
rlm_xmpad.conf
|
||||
|
74
conf/rlm_urlwrite.conf
Normal file
74
conf/rlm_urlwrite.conf
Normal file
@ -0,0 +1,74 @@
|
||||
; rlm_urlwrite.conf
|
||||
;
|
||||
; This is the sample configuration file for the 'rlm_urlwrite' RLM for
|
||||
; Rivendell, which can be used to send one or more files to a local or
|
||||
; remote system using Now & Next data.
|
||||
;
|
||||
; To enable this module, add it to the 'Loadable Modules' list in
|
||||
; RDAdmin->ManageHosts->RDAirPlay->ConfigureNow&Next. The 'Argument'
|
||||
; field should point to the location of this file.
|
||||
|
||||
; Section Header
|
||||
;
|
||||
; One section per file to be written should be configured, starting with
|
||||
; 'File1' and working up consecutively
|
||||
[Url1]
|
||||
|
||||
; Url
|
||||
;
|
||||
; The URL to which to send the file. The follow URL schemes are recognized:
|
||||
; file://
|
||||
; ftp://
|
||||
; http:// (uses the PUT method)
|
||||
; sftp://
|
||||
;
|
||||
Url=sftp://server.example.com/myfile.txt
|
||||
|
||||
; Username
|
||||
;
|
||||
; The username to be used when authenticating to the remote server.
|
||||
;
|
||||
Username=someuser
|
||||
|
||||
; Password
|
||||
;
|
||||
; The password to be used when authenticating to the remote server.
|
||||
Password=hackme
|
||||
|
||||
; Format String. The string to be sent each time RDAirPlay changes
|
||||
; play state, including any wildcards as placeholders for metadata values.
|
||||
;
|
||||
; The list of available wildcards can be found in the 'metadata_wildcards.txt'
|
||||
; file in the Rivendell documentation directory.
|
||||
;
|
||||
FormatString=NOW: %d(ddd MMM d hh:mm:ss yyyy): %t - %a\nNEXT: %D(ddd MMM d hh:mm:ss yyyy): %T - %A\n
|
||||
|
||||
; Encoding. Defines the set of escapes to be applied to the PAD fields.
|
||||
; The following options are available:
|
||||
;
|
||||
; 0 - Perform no character escaping.
|
||||
; 1 - "XML" escaping: Escape reserved characters as per XML-v1.0
|
||||
; 2 - "Web" escaping: Escape reserved characters as per RFC 2396 Section 2.4
|
||||
Encoding=0
|
||||
|
||||
; Log Selection
|
||||
;
|
||||
; Set the status for each log to 'Yes', 'No' or 'Onair' to indicate whether
|
||||
; state changes on that log should be output. If set to 'Onair', then
|
||||
; output will be generated only if RDAirPlays OnAir flag is active.
|
||||
MasterLog=Yes
|
||||
Aux1Log=Yes
|
||||
Aux2Log=Yes
|
||||
|
||||
|
||||
; Additional files can be written by adding new sections...
|
||||
;
|
||||
;[Url2]
|
||||
;Url=file:///home/rd/somefile.txt
|
||||
;Username=janedoe
|
||||
;Password=crackme
|
||||
;FormatString=%t by %a\r\n
|
||||
;Encoding=0
|
||||
;MasterLog=Yes
|
||||
;Aux1Log=No
|
||||
;Aux2Log=Onair
|
@ -423,6 +423,7 @@ rm -rf $RPM_BUILD_ROOT
|
||||
%doc conf/rlm_shoutcast1.conf
|
||||
%doc conf/rlm_spottrap.conf
|
||||
%doc conf/rlm_filewrite.conf
|
||||
%doc conf/rlm_urlwrite.conf
|
||||
%doc conf/rlm_spinitron_plus.conf
|
||||
%doc conf/rlm_tagstation.conf
|
||||
%doc docs/implemented_macros.txt
|
||||
|
@ -2,7 +2,7 @@
|
||||
##
|
||||
## An example Makefile for building Rivendell Loadable Modules
|
||||
##
|
||||
## (C) Copyright 2008-2013 Fred Gleason <fredg@paravelsystems.com>
|
||||
## (C) Copyright 2008-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 Library General Public License
|
||||
@ -20,6 +20,7 @@
|
||||
|
||||
OBJS = rlm_ando.rlm\
|
||||
rlm_facebook.rlm\
|
||||
rlm_filewrite.rlm\
|
||||
rlm_icecast2.rlm\
|
||||
rlm_inno713.rlm\
|
||||
rlm_liqcomp.rlm\
|
||||
@ -33,6 +34,7 @@ OBJS = rlm_ando.rlm\
|
||||
rlm_test.rlm\
|
||||
rlm_twitter.rlm\
|
||||
rlm_udp.rlm \
|
||||
rlm_urlwrite.rlm\
|
||||
rlm_walltime.rlm\
|
||||
rlm_xmpad.rlm
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
##
|
||||
## Automake.am for rivendell/rlm
|
||||
##
|
||||
## (C) Copyright 2008,2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
## (C) Copyright 2008,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
|
||||
@ -37,6 +37,7 @@ RLM_MODULES=rlm_ando.rlm\
|
||||
rlm_test.rlm\
|
||||
rlm_twitter.rlm\
|
||||
rlm_udp.rlm\
|
||||
rlm_urlwrite.rlm\
|
||||
rlm_walltime.rlm\
|
||||
rlm_xds.rlm\
|
||||
rlm_xmpad.rlm
|
||||
@ -76,6 +77,7 @@ EXTRA_DIST = Makefile-example\
|
||||
rlm_test.c\
|
||||
rlm_twitter.c\
|
||||
rlm_udp.c\
|
||||
rlm_urlwrite.c\
|
||||
rlm_walltime.c\
|
||||
rlm_xds.c\
|
||||
rlm_xmpad.c
|
||||
|
239
rlm/rlm_urlwrite.c
Normal file
239
rlm/rlm_urlwrite.c
Normal file
@ -0,0 +1,239 @@
|
||||
/* rlm_urlwrite.c
|
||||
*
|
||||
* (C) Copyright 2012 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 published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* This is a Rivendell Loadable Module. It uses Now&Next PAD data
|
||||
* to write to one or more file(s) on the local system specified in the
|
||||
* configuration file pointed to by the plugin argument.
|
||||
*
|
||||
* To compile this module, just do:
|
||||
*
|
||||
* gcc -shared -o rlm_urlwrite.rlm rlm_urlwrite.c
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rlm/rlm.h>
|
||||
|
||||
int rlm_urlwrite_devs;
|
||||
char *rlm_urlwrite_urls;
|
||||
char *rlm_urlwrite_usernames;
|
||||
char *rlm_urlwrite_passwords;
|
||||
char *rlm_urlwrite_formats;
|
||||
int *rlm_urlwrite_encodings;
|
||||
int *rlm_urlwrite_masters;
|
||||
int *rlm_urlwrite_aux1s;
|
||||
int *rlm_urlwrite_aux2s;
|
||||
|
||||
void rlm_urlwrite_ReplaceChar(char c,char *str,int pos)
|
||||
{
|
||||
int i;
|
||||
|
||||
str[pos]=c;
|
||||
for(i=pos+1;i<strlen(str);i++) {
|
||||
str[i]=str[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void rlm_urlwrite_ProcessString(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0;i<(strlen(str)-1);i++) {
|
||||
if(str[i]=='\\') {
|
||||
if(str[i+1]=='r') {
|
||||
rlm_urlwrite_ReplaceChar(13,str,i);
|
||||
}
|
||||
else {
|
||||
if(str[i+1]=='n') {
|
||||
rlm_urlwrite_ReplaceChar(10,str,i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int rlm_urlwrite_GetLogStatus(void *ptr,const char *arg,const char *section,
|
||||
const char *logname)
|
||||
{
|
||||
const char *tag=RLMGetStringValue(ptr,arg,section,logname,"");
|
||||
if(strcasecmp(tag,"yes")==0) {
|
||||
return 1;
|
||||
}
|
||||
if(strcasecmp(tag,"on")==0) {
|
||||
return 1;
|
||||
}
|
||||
if(strcasecmp(tag,"true")==0) {
|
||||
return 1;
|
||||
}
|
||||
if(strcasecmp(tag,"no")==0) {
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(tag,"off")==0) {
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(tag,"false")==0) {
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(tag,"onair")==0) {
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void rlm_urlwrite_RLMStart(void *ptr,const char *arg)
|
||||
{
|
||||
char url[256];
|
||||
char section[256];
|
||||
char errtext[256];
|
||||
int i=1;
|
||||
|
||||
rlm_urlwrite_devs=0;
|
||||
rlm_urlwrite_urls=NULL;
|
||||
rlm_urlwrite_usernames=NULL;
|
||||
rlm_urlwrite_passwords=NULL;
|
||||
rlm_urlwrite_formats=NULL;
|
||||
rlm_urlwrite_encodings=NULL;
|
||||
rlm_urlwrite_masters=NULL;
|
||||
rlm_urlwrite_aux1s=NULL;
|
||||
rlm_urlwrite_aux2s=NULL;
|
||||
|
||||
sprintf(section,"Url%d",i++);
|
||||
strncpy(url,RLMGetStringValue(ptr,arg,section,"Url",""),255);
|
||||
url[255]=0;
|
||||
if(strlen(url)==0) {
|
||||
RLMLog(ptr,LOG_WARNING,"rlm_urlwrite: no URLs specified");
|
||||
return;
|
||||
}
|
||||
while(strlen(url)>0) {
|
||||
rlm_urlwrite_urls=realloc(rlm_urlwrite_urls,
|
||||
(rlm_urlwrite_devs+1)*(rlm_urlwrite_devs+1)*256);
|
||||
strcpy(rlm_urlwrite_urls+256*rlm_urlwrite_devs,url);
|
||||
rlm_urlwrite_usernames=realloc(rlm_urlwrite_usernames,(rlm_urlwrite_devs+1)*256);
|
||||
strncpy(rlm_urlwrite_usernames+256*rlm_urlwrite_devs,
|
||||
RLMGetStringValue(ptr,arg,section,"Username",""),256);
|
||||
rlm_urlwrite_passwords=realloc(rlm_urlwrite_passwords,(rlm_urlwrite_devs+1)*256);
|
||||
strncpy(rlm_urlwrite_passwords+256*rlm_urlwrite_devs,
|
||||
RLMGetStringValue(ptr,arg,section,"Password",""),256);
|
||||
rlm_urlwrite_formats=realloc(rlm_urlwrite_formats,(rlm_urlwrite_devs+1)*8192);
|
||||
strncpy(rlm_urlwrite_formats+8192*rlm_urlwrite_devs,
|
||||
RLMGetStringValue(ptr,arg,section,"FormatString",""),8192);
|
||||
rlm_urlwrite_masters=realloc(rlm_urlwrite_masters,
|
||||
(rlm_urlwrite_devs+1)*sizeof(int));
|
||||
rlm_urlwrite_masters[rlm_urlwrite_devs]=
|
||||
rlm_urlwrite_GetLogStatus(ptr,arg,section,"MasterLog");
|
||||
|
||||
rlm_urlwrite_encodings=realloc(rlm_urlwrite_encodings,
|
||||
(rlm_urlwrite_devs+1)*sizeof(int));
|
||||
rlm_urlwrite_encodings[rlm_urlwrite_devs]=
|
||||
RLMGetIntegerValue(ptr,arg,section,"Encoding",RLM_ENCODE_NONE);
|
||||
rlm_urlwrite_aux1s=realloc(rlm_urlwrite_aux1s,
|
||||
(rlm_urlwrite_devs+1)*sizeof(int));
|
||||
rlm_urlwrite_aux1s[rlm_urlwrite_devs]=
|
||||
rlm_urlwrite_GetLogStatus(ptr,arg,section,"Aux1Log");
|
||||
rlm_urlwrite_aux2s=realloc(rlm_urlwrite_aux2s,
|
||||
(rlm_urlwrite_devs+1)*sizeof(int));
|
||||
rlm_urlwrite_aux2s[rlm_urlwrite_devs]=
|
||||
rlm_urlwrite_GetLogStatus(ptr,arg,section,"Aux2Log");
|
||||
sprintf(errtext,"rlm_urlwrite: configured URL \"%s\"",
|
||||
rlm_urlwrite_urls+256*rlm_urlwrite_devs);
|
||||
rlm_urlwrite_devs++;
|
||||
RLMLog(ptr,LOG_INFO,errtext);
|
||||
sprintf(section,"Url%d",i++);
|
||||
strncpy(url,RLMGetStringValue(ptr,arg,section,"Url",""),255);
|
||||
url[255]=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void rlm_urlwrite_RLMFree(void *ptr)
|
||||
{
|
||||
free(rlm_urlwrite_urls);
|
||||
free(rlm_urlwrite_usernames);
|
||||
free(rlm_urlwrite_passwords);
|
||||
free(rlm_urlwrite_formats);
|
||||
free(rlm_urlwrite_encodings);
|
||||
free(rlm_urlwrite_masters);
|
||||
free(rlm_urlwrite_aux1s);
|
||||
free(rlm_urlwrite_aux2s);
|
||||
}
|
||||
|
||||
|
||||
void rlm_urlwrite_RLMPadDataSent(void *ptr,const struct rlm_svc *svc,
|
||||
const struct rlm_log *log,
|
||||
const struct rlm_pad *now,
|
||||
const struct rlm_pad *next)
|
||||
{
|
||||
int i;
|
||||
int flag=0;
|
||||
char str[8192];
|
||||
char msg[1500];
|
||||
char account[1024];
|
||||
char tempfile[1024];
|
||||
FILE *f;
|
||||
|
||||
for(i=0;i<rlm_urlwrite_devs;i++) {
|
||||
switch(log->log_mach) {
|
||||
case 0:
|
||||
flag=rlm_urlwrite_masters[i];
|
||||
break;
|
||||
|
||||
case 1:
|
||||
flag=rlm_urlwrite_aux1s[i];
|
||||
break;
|
||||
|
||||
case 2:
|
||||
flag=rlm_urlwrite_aux2s[i];
|
||||
break;
|
||||
}
|
||||
if((flag==1)||((flag==2)&&(log->log_onair!=0))) {
|
||||
strncpy(str,RLMResolveNowNextEncoded(ptr,now,next,
|
||||
rlm_urlwrite_formats+8192*i,
|
||||
rlm_urlwrite_encodings[i]),8192);
|
||||
rlm_urlwrite_ProcessString(str);
|
||||
snprintf(account,1024,"%s:%s",rlm_urlwrite_usernames+256*i,
|
||||
rlm_urlwrite_passwords+256*i);
|
||||
snprintf(tempfile,1024,"/tmp/rlm_urlwrite_%d",i);
|
||||
f=fopen(tempfile,"w");
|
||||
if(f!=NULL) {
|
||||
snprintf(msg,1500,"rlm_urlwrite: sending pad update: \"%s\" to \"%s\"",
|
||||
str,rlm_urlwrite_urls+256*i);
|
||||
fprintf(f,"%s",str);
|
||||
fclose(f);
|
||||
if(fork()==0) {
|
||||
execlp("curl","curl","-s","-k","-u",account,"-T",tempfile,
|
||||
rlm_urlwrite_urls+256*i,(char *)NULL);
|
||||
RLMLog(ptr,LOG_WARNING,"rlm_urlwrite: unable to execute curl(1)");
|
||||
exit(0);
|
||||
}
|
||||
RLMLog(ptr,LOG_INFO,msg);
|
||||
}
|
||||
else {
|
||||
snprintf(msg,1500,"rlm_urlwrite: unable to open file \"%s\"",
|
||||
rlm_urlwrite_urls+256*i);
|
||||
RLMLog(ptr,LOG_WARNING,msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user