From e9d3a1e6796d450ab00a6a6d95b8ace53b7f93fd Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Fri, 1 Nov 2019 17:13:40 +0100 Subject: we now support curling the form without getting all of the HTML in response --- form.cgi | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'form.cgi') diff --git a/form.cgi b/form.cgi index e10386d..4e3f9d3 100755 --- a/form.cgi +++ b/form.cgi @@ -7,17 +7,11 @@ use warnings; use CGI; use DBI; -my $q = CGI->new; # create CGI object +my $q = CGI->new; # create CGI object -print $q->header(-charset=>'utf-8'); -print < - - PURL - - -HTML +my $results; my $user = scalar $ENV{'REMOTE_USER'}; +my $form = scalar $q->param('form'); # If form has already been submitted if ($q->param('url')) { @@ -38,7 +32,7 @@ if ($q->param('url')) { # Check if short exists. If it does, generate a new one. while (my $url = $dbh->selectrow_array($query, undef, $short)) { - print "Your short exists. Generating new.
\n"; + $results .= "Your short exists. Generating new.
\n"; $short = genshort(); last; } @@ -50,25 +44,41 @@ if ($q->param('url')) { $dbh->disconnect(); - my $proto = $ENV{'HTTPS'} eq "on" ? 'https://' : 'http://'; + my $proto = $ENV{'HTTPS'} eq "on" ? 'https://' : 'http://'; # http/https my $shortURL = $proto . $ENV{'SERVER_NAME'} . '/' . $short; - print "URL: $url
\n"; - print "Shortened to: $shortURL
\n"; - print "
\n"; + $results .= "URL: $url
\n"; + $results .= "Shortened to: $shortURL
\n"; + $results .= "
\n"; + + # Change results if we are not submitting via the form + $results = $form eq "html" ? $results : $shortURL . "\n"; } -# print form -print <header(-charset=>'utf-8'); + print $results; +} else { # if we used the form + # print form + print $q->header(-charset=>'utf-8'); + print < + + PURL + + + $results
Username: $user
URL to shorten:
Custom short:
+
-FORM +HTML +} exit(0); -- cgit v1.2.3