From eeb356f5cf520008cdee7332659fc8a915654dc1 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 8 Dec 2020 13:46:19 -0500 Subject: [PATCH] 2020-12-08 Fred Gleason * Fixed a bug in the 'Webget' service that caused it to automatically unique-ify the title even when 'Auto-Correct Duplicate Cart Titles' in rdadmin(1) was unchecked. Signed-off-by: Fred Gleason --- ChangeLog | 4 +++ web/webget/webget.cpp | 72 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ee3437f..31ee5d85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20660,3 +20660,7 @@ Configuration' dialog in rdadmin(1) in the Operations Guide. 2020-11-29 Fred Gleason * Incremented the package version to 3.4.1int7. +2020-12-08 Fred Gleason + * Fixed a bug in the 'Webget' service that caused it to automatically + unique-ify the title even when 'Auto-Correct Duplicate Cart Titles' + in rdadmin(1) was unchecked. diff --git a/web/webget/webget.cpp b/web/webget/webget.cpp index 09ef6331..7283f575 100644 --- a/web/webget/webget.cpp +++ b/web/webget/webget.cpp @@ -33,6 +33,8 @@ #include #include +#include +#include #include #include "webget.h" @@ -341,6 +343,14 @@ void MainObject::GetAudio() void MainObject::PutAudio() { + QString sql; + RDSqlQuery *q=NULL; + QString err_msg; + RDGroup *group; + + // + // Verify permissions + // if(!rda->user()->createCarts()) { rda->syslog(LOG_WARNING,"user \"%s\" lacks CreateCarts permission", rda->user()->name().toUtf8().constData()); @@ -356,6 +366,9 @@ void MainObject::PutAudio() Exit(0); } + // + // Get user values + // QString group_name; if(!webget_post->getValue("group",&group_name)) { rda->syslog(LOG_WARNING,"missing \"group\" in put submission"); @@ -371,6 +384,14 @@ void MainObject::PutAudio() ServeLogin(403); Exit(0); } + group=new RDGroup(group_name); + if(!group->exists()) { + rda->syslog(LOG_WARNING,"group \"%s\" does not exist", + group_name.toUtf8().constData()); + rda->logAuthenticationFailure(webget_post->clientAddress()); + ServeLogin(403); + Exit(0); + } QString filename; if(!webget_post->getValue("filename",&filename)) { @@ -387,6 +408,52 @@ void MainObject::PutAudio() Exit(0); } + // + // Generate Title + // + QStringList f0=filename.split("/",QString::SkipEmptyParts); + QStringList f1=f0.last().split(".",QString::KeepEmptyParts); + QString short_name=f0.last(); + f1.removeLast(); + QString title=f1.join("."); + + // + // Validate title uniqueness + // + if((!rda->system()->allowDuplicateCartTitles())&& + (!rda->system()->fixDuplicateCartTitles())) { + sql=QString("select ")+ + "NUMBER "+ // 00 + "from CART where "+ + "TITLE=\""+RDEscapeString(title)+"\""; + q=new RDSqlQuery(sql); + if(q->first()) { + QString body; + body+="Rivendell File Import Report\n"; + body+="\n"; + body+="IMPORT FAILED!\n"; + body+="\n"; + body+="Filename: "+short_name+"\n"; + body+="Submitted by: "+rda->user()->emailContact()+"\n"; + body+="Group: "+group_name+"\n"; + body+="Reason: Title exists\n"; + rda->syslog(LOG_WARNING, + "failed import of file \"%s\" from \"%s\" at %s, title already exists", + short_name.toUtf8().constData(), + rda->user()->name().toUtf8().constData(), + webget_post->clientAddress().toString().toUtf8().constData()); + RDSendMail(&err_msg,tr("Rivendell import FAILURE for file: ")+short_name, + body,rda->system()->originEmailAddress(), + group->notifyEmailAddress()); + TextExit(tr("Audio import failed: title already exists!"),400, + LINE_NUMBER); + } + delete q; + } + + // + // Import audio + // QStringList args; args.push_back(QString("--ticket=")+webget_ticket+":"+ @@ -397,6 +464,7 @@ void MainObject::PutAudio() args.push_back("--to-mono"); } args.push_back("--output-pattern=Added cart %n [%t]"); + args.push_back("--set-string-title="+title); args.push_back(group_name); args.push_back(filename); QProcess *proc=new QProcess(this); @@ -447,8 +515,8 @@ void MainObject::PutAudio() } QString resultstr=proc->readAllStandardOutput(); - rda->syslog(LOG_INFO,"%s from user %s at %s", - resultstr.toUtf8().constData(), + rda->syslog(LOG_INFO,"%s from user \"%s\" at %s", + resultstr.trimmed().toUtf8().constData(), rda->user()->name().toUtf8().constData(), webget_post->clientAddress().toString().toUtf8().constData()); TextExit(resultstr.toUtf8().constData(),200,LINE_NUMBER);