mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-11-29 16:50:13 +01:00
2020-10-16 Fred Gleason <fredg@paravelsystems.com>
* Modified the 'WebGet' service to supply a sane default filename for downloaded content. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
@@ -20476,3 +20476,6 @@
|
||||
* Removed the 'stationname' parameter from the
|
||||
'RDSettings::pathName()' method.
|
||||
* Removed the 'RDSettings::bytesPerSec()' method.
|
||||
2020-10-16 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Modified the 'WebGet' service to supply a sane default
|
||||
filename for downloaded content.
|
||||
|
||||
@@ -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 = *~\
|
||||
|
||||
@@ -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("<html>\n");
|
||||
printf(" <head>\n");
|
||||
printf(" <title>Rivendell Webget</title>\n");
|
||||
printf(" <script src=\"webget.js?%lu\" type=\"application/javascript\"></script>\n",t);
|
||||
printf(" <script src=\"utils.js?%lu\" type=\"application/javascript\"></script>\n",t);
|
||||
printf(" <script type=\"application/javascript\">\n");
|
||||
printf(" var preset_ids=new Array();\n");
|
||||
printf(" var preset_exts=new Array();\n");
|
||||
sql=QString("select ")+
|
||||
"ID,"+ // 00
|
||||
"FORMAT "+ // 01
|
||||
"from ENCODER_PRESETS order by ID";
|
||||
int count=0;
|
||||
q=new RDSqlQuery(sql);
|
||||
while(q->next()) {
|
||||
printf(" preset_ids[%d]=%d;\n",count,q->value(0).toInt());
|
||||
printf(" preset_exts[%d]='%s';\n",
|
||||
count,RDSettings::defaultExtension((RDSettings::Format)q->value(1).toUInt()).toUtf8().constData());
|
||||
count++;
|
||||
}
|
||||
delete q;
|
||||
printf(" </script>\n");
|
||||
printf(" </head>\n");
|
||||
printf(" <body>\n");
|
||||
printf(" <form method=\"post\" action=\"webget.cgi\" enctype=\"application/x-www-form-urlencoded\">\n");
|
||||
printf(" <table style=\"margin: auto;padding: 10px 0\" cellpadding=\"0\" cellspacing=\"5\" border=\"0\">\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td colspan=\"2\"><img src=\"logos/webget_logo.png\" border=\"0\"></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td colspan=\"2\"><strong>Get audio from Rivendell</strong></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr><td colspan=\"2\"><hr></td></tr>\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td style=\"text-align: right\">Cart Title:</td>\n");
|
||||
printf(" <td><input type=\"text\" name=\"title\" size=\"40\" maxlength=\"255\"></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr><td cellspan=\"2\"> </td></tr>\n");
|
||||
printf(" <table style=\"margin: auto;padding: 10px 0\" cellpadding=\"0\" cellspacing=\"5\" border=\"0\">\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td colspan=\"2\"><img src=\"logos/webget_logo.png\" border=\"0\"></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td colspan=\"2\"><strong>Get audio from Rivendell</strong></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr><td colspan=\"2\"><hr></td></tr>\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td style=\"text-align: right\">Cart Title:</td>\n");
|
||||
printf(" <td><input type=\"text\" id=\"title\" size=\"40\" maxlength=\"255\"></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr><td cellspan=\"2\"> </td></tr>\n");
|
||||
|
||||
printf(" <tr>\n");
|
||||
printf(" <td style=\"text-align: right\">Format:</td>\n");
|
||||
printf(" <td>\n");
|
||||
printf(" <select name=\"preset\" id=\"preset\">\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td style=\"text-align: right\">Format:</td>\n");
|
||||
printf(" <td>\n");
|
||||
printf(" <select id=\"preset\">\n");
|
||||
sql=QString("select ")+
|
||||
"ID,"+ // 00
|
||||
"NAME "+ // 01
|
||||
"from ENCODER_PRESETS order by NAME";
|
||||
q=new RDSqlQuery(sql);
|
||||
while(q->next()) {
|
||||
printf(" <option value=\"%u\">%s</option>\n",
|
||||
printf(" <option value=\"%u\">%s</option>\n",
|
||||
q->value(0).toUInt(),q->value(1).toString().toUtf8().constData());
|
||||
}
|
||||
delete q;
|
||||
printf(" </select>\n");
|
||||
printf(" </td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr><td cellspan=\"2\"> </td></tr>\n");
|
||||
printf(" <td style=\"text-align: right\">User Name:</td>\n");
|
||||
printf(" <td><input type=\"text\" size=\"32\" maxsize=\"255\" name=\"LOGIN_NAME\"></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td style=\"text-align: right\">Password:</td>\n");
|
||||
printf(" <td><input type=\"password\" size=\"32\" maxsize=\"32\" name=\"PASSWORD\"></td>\n");
|
||||
printf(" <tr><td cellspan=\"2\"> </td></tr>\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td> </td>\n");
|
||||
printf(" <td><input type=\"submit\" value=\"OK\"></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" </table>\n");
|
||||
printf(" </form>\n");
|
||||
printf(" </select>\n");
|
||||
printf(" </td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr><td cellspan=\"2\"> </td></tr>\n");
|
||||
printf(" <td style=\"text-align: right\">User Name:</td>\n");
|
||||
printf(" <td><input type=\"text\" size=\"32\" maxsize=\"255\" id=\"LOGIN_NAME\"></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td style=\"text-align: right\">Password:</td>\n");
|
||||
printf(" <td><input type=\"password\" size=\"32\" maxsize=\"32\" id=\"PASSWORD\"></td>\n");
|
||||
printf(" <tr><td cellspan=\"2\"> </td></tr>\n");
|
||||
printf(" <tr>\n");
|
||||
printf(" <td> </td>\n");
|
||||
printf(" <td><input type=\"button\" value=\"OK\" onclick=\"ProcessOkButton()\"></td>\n");
|
||||
printf(" </tr>\n");
|
||||
printf(" </table>\n");
|
||||
printf(" </body>\n");
|
||||
printf("</html>\n");
|
||||
}
|
||||
|
||||
104
web/webget/webget.js
Normal file
104
web/webget/webget.js
Normal file
@@ -0,0 +1,104 @@
|
||||
// webget.js
|
||||
//
|
||||
// (C) Copyright 2020 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.
|
||||
//
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user