I want to run an index.cgi in my front end directory rather than an index.html. However the script does not run and only prints out the script in text. I am on running apache2 on ubuntu 18.04. What might I be doing wrong?
I'm implementing a login page with cgi. I was able to retrieve the login and password correctly, yet I am unsure of how to change to that user. I am using httpd apache.
After researching possible ways to do this, I've seen that suexec could be used to solve this issue but I'm a bit unclear on how to use it.
This is the cgi code I have:
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Form Example</title>'
echo '</head>'
echo '<body>'
echo "<form method=GET action=\"${SCRIPT}\">"\
'<table nowrap>'\
'<tr><td>Username</TD><TD><input type="text" name="val_x" size=12></td></tr>'\
'<tr><td>Password</td><td><input type="password" name="val_y" size=12 value=""></td>'\
'</tr></table>'
echo '<br><input type="submit" value="Login">'\
'</form>'
# Make sure we have been invoked properly.
if [ "$REQUEST_METHOD" != "GET" ]; then
echo "<hr>Script Error:"\
"<br>Usage error, cannot complete request, REQUEST_METHOD!=GET."\
"<br>Check your FORM declaration and be sure to use METHOD=\"GET\".<hr>"
exit 1
fi
# If no search arguments, exit gracefully now.
if [ -z "$QUERY_STRING" ]; then
exit 0
else
# No looping this time, just extract the data you are looking for with sed:
XX=`echo "$QUERY_STRING" | sed -n 's/^.*val_x=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
YY=`echo "$QUERY_STRING" | sed -n 's/^.*val_y=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
echo "val_x: " $XX
echo '<br>'
echo "val_y: " $YY
su $XX -p $YY #I know this is not the best way to login but I'm using it for testing purposes
echo ""
echo `whoami`
echo `pwd`
fi
echo '</body>'
echo '</html>'
exit 0
Whenever I try the "whoami" always returns apache.
This is the link where I've got part of the code: http://www.yolinux.com/TUTORIALS/BashShellCgi.html
.yml
apache:
build: apache/
links:
- php:phpfpm
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
volumes:
- ./public:/var/www
- ./apache/hosts:/etc/apache2/sites-enabled
- ./log:/var/log/apache2
ports:
- 8181:80
Vhost
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ScriptAlias /cgi-bin /var/www/reader_cgi.git/cgi-bin/
<Directory /var/www/reader_cgi.git/cgi-bin/>
Header set Access-Control-Allow-Origin "*"
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
index.cgi
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
print "Hello World";
error.log
[Thu Nov 28 10:14:04.040274 2019] [cgid:error] [pid 9:tid 140520978339584] [client 172.24.0.1:35584] End of script output before headers: index.cgi
I have an image created by a CGI script.. if you call the script directly it displays quite happily with.
Content-type: image/jpeg
However I need to embed this inside a page, and no matter what I try the browsers just display raw data. I've tried octet-stream, binary and a few other things to no avail.
#!/bin/bash
echo "Content-type: image/jpeg"
echo ""
/usr/bin/xearth -pos fixed/10/144.96 -shade -size 320/320 -gif |convert gif: jpeg:-
.
<!--#include file="head.shtml" -->
<!--#exec cgi="/cgi-bin/xearth.cgi" -->
<!--#include file="tail.shtml" -->
A
I'm running Apache2 on ubuntu 16.04,just installed it all fresh, and trying to run a CGI script on my site! I'm aware apache needs to be configured to run it. I've put my cgi-bin directory in var/www with:
sudo mkdir -p /var/www/cgi-bin/
then ran this (although not sure why!):
sudo chown $USER:www-data /var/www/cgi-bin/
Then added these to my apache.conf file:
ScriptAlias /cgi-bin/var/www/cgi-bin/
< Directory /var/www/cgi-bin/ >
Options ExecCGI <br>
AddHandler cgi-script cgi pl
< /Directory >
Essentially when I open my site, some javascript
runs jqueries ajax
with the CGI script as an argument, and well it's just not running! :(
Sorry for awful formatting of post etc. it's my first, and if anyone needs any other info/attachments please let me know, this is for a big deadline and i'm so close but so far!