diff --git a/ChangeLog b/ChangeLog index 488ee15c..c0b765ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20476,3 +20476,6 @@ * Removed the 'stationname' parameter from the 'RDSettings::pathName()' method. * Removed the 'RDSettings::bytesPerSec()' method. +2020-10-16 Fred Gleason + * Modified the 'WebGet' service to supply a sane default + filename for downloaded content. diff --git a/web/webget/Makefile.am b/web/webget/Makefile.am index 722417fd..9173a3cd 100644 --- a/web/webget/Makefile.am +++ b/web/webget/Makefile.am @@ -27,10 +27,14 @@ moc_%.cpp: %.h install-exec-local: mkdir -p $(DESTDIR)@libexecdir@ + cp webget.js $(DESTDIR)@libexecdir@/ install-exec-hook: if test -z $(DESTDIR) ; then chown root $(DESTDIR)$(libexecdir)/webget.cgi ; chmod 4755 $(DESTDIR)$(libexecdir)/webget.cgi ; fi +uninstall-local: + rm -f $(DESTDIR)@libexecdir@/webget.js + libexec_PROGRAMS = webget.cgi dist_webget_cgi_SOURCES = webget.cpp webget.h @@ -39,6 +43,8 @@ nodist_webget_cgi_SOURCES = moc_webget.cpp webget_cgi_LDADD = @LIB_RDLIBS@ -lsndfile @LIBVORBIS@ @QT4_LIBS@ @MUSICBRAINZ_LIBS@ -lQt3Support +EXTRA_DIST = webget.js + CLEANFILES = *~\ moc_* MAINTAINERCLEANFILES = *~\ diff --git a/web/webget/webget.cpp b/web/webget/webget.cpp index 6685fc4d..5312595b 100644 --- a/web/webget/webget.cpp +++ b/web/webget/webget.cpp @@ -111,7 +111,7 @@ MainObject::MainObject(QObject *parent) // if(!Authenticate()) { printf("Content-type: text/html\n"); - printf("Status: 400\n"); + printf("Status: 401\n"); printf("\n"); printf("Invalid User name or Password!\n"); Exit(0); @@ -165,7 +165,7 @@ void MainObject::ripcConnectedData(bool state) delete q; if(cartnum==0) { printf("Content-type: text/html\n"); - printf("Status: 400\n"); + printf("Status: 404\n"); printf("\n"); printf("No such cart!\n"); Exit(0); @@ -300,60 +300,78 @@ void MainObject::ServeForm() { QString sql; RDSqlQuery *q=NULL; + time_t t=time(NULL); printf("Content-type: text/html\n\n"); printf("\n"); printf(" \n"); printf(" Rivendell Webget\n"); + printf(" \n",t); + printf(" \n",t); + printf(" \n"); printf(" \n"); printf(" \n"); - printf("
\n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); + printf("
Get audio from Rivendell

Cart Title:
 
\n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); + printf(" \n"); + printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf(" \n"); - printf("
Get audio from Rivendell

Cart Title:
 
Format:\n"); - printf("
Format:\n"); + printf(" \n"); - printf("
 
User Name:
Password:
 
 
\n"); - printf("
\n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf("  \n"); + printf(" User Name:\n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf(" Password:\n"); + printf(" \n"); + printf("  \n"); + printf(" \n"); + printf("  \n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); printf(" \n"); printf("\n"); } diff --git a/web/webget/webget.js b/web/webget/webget.js new file mode 100644 index 00000000..cf36a965 --- /dev/null +++ b/web/webget/webget.js @@ -0,0 +1,104 @@ +// webget.js +// +// (C) Copyright 2020 Fred Gleason +// +// 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. +// + +function Id(id) +{ + return document.getElementById(id); +} + + +function MakePost() +{ + var sep=MakeMimeSeparator(); + form=sep+"\r\n"; + + form+=AddMimePart('title',Id('title').value,sep,false); + form+=AddMimePart('preset',Id('preset').value,sep,false); + form+=AddMimePart('LOGIN_NAME',Id('LOGIN_NAME').value,sep,false); + form+=AddMimePart('PASSWORD',Id('PASSWORD').value,sep,true); + + return form; +} + + +function ProcessOkButton() +{ + SendForm(MakePost(),"webget.cgi"); +} + + +function SendForm(form,url) +{ + var http=GetXMLHttpRequest(); + if(http==null) { + return; + } + + // + // Send the form + // + http.open("POST",url,true); + http.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); + http.responseType='blob'; + http.send(form); + + // + // Process the response + // + http.onload=function(e) { + if(this.status==200) { + var blob=new Blob([this.response], + {type: http.getResponseHeader('content-type')}); + let a=document.createElement('a'); + a.style='display: none'; + document.body.appendChild(a); + let url=window.URL.createObjectURL(blob); + a.href=url; + a.download=Id('title').value+'.'+FileExtension(Id('preset').value); + a.click(); + window.URL.revokeObjectURL(url); + } + else { + if(this.status==401) { + alert('Invalid User Name or Password!'); + } + else { + if(this.status=404) { + alert('No cart with that name found!'); + } + else { + alert('Unable to access WebGet [response code: '+ + http.status+']!'); + } + } + } + } +} + + +function FileExtension(prof_id) +{ + for(id in preset_ids) { + if(preset_ids[id]==prof_id) { + return preset_exts[id]; + } + } + + return 'dat'; +} +