perl script not executed in one three virtual hosts configured the same - linux

I have three virtual hosts on apache2 web server.
Two of them use perl scripts that are working perfectly.
The third I just created with EXACTLY THE SAME configuration concerning the ScriptAlias directive
Number one: working
ScriptAlias /cgi-bin/ "/www/old/uep/cgi-bin/"
Number two: working
ScriptAlias /cgi-bin/ "/www/cssm/formulaire/cgi-bin/"
Number three: not working
(the perl script is about to be downloaded instead of being executed as the two others)
ScriptAlias /cgi-bin/ "/www/cssm/juin2019/cgi-bin/"
All the hosts are configured the same, all the scripts have sufficient rights to be executed, but only the last can not be executed.
Checked logs: no errors, the access log file indicates GET concerning the script with .pl extension and with execution permission.
Emptied the browser cache (everything).
Kompared the three involved .conf files in /etc/apache2/vhosts.d
All of the three .conf files are the same, with no difference but the path and the error/access log names.
I use the following settings in the three .conf files concerning the main directory
Options Indexes FollowSymLinks
IndexOptions +Charset=UTF-8 NameWidth=*
I don't use symbolic links in the path.
In the HTML file I use a FORM for one of the two site that are working, and a direct link /cgi-bin/forum.pl for the other working site.
NOT WORKING:
192.168.0.4 - - [02/Apr/2019:19:32:54 +0200] "GET /cgi-bin/examenjuin.pl HTTP/1.1" 304 - "http://www.examenjuin2019.cssm/" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
WORKING:
192.168.0.4 - - [02/Apr/2019:19:51:38 +0200] "GET /cgi-bin/forum.pl HTTP/1.1" 200 2209 "http://www.uepsoundsystem.dezordi.world/" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
Can not understand why two perl scripts in different folders with exactly the same permissions are working and this one can't...

If it is not your script producing the 304 status code, it is your server configuration.
On Apache, play around with mod_cache settings to prevent your server from sending them.

Related

Running a CGI script on Yosemite/Apache from another computer

I am trying to run a simple cgi script which resides on my iMac (Yosemite installed) from a Windows 10 computer.
Here is the say_test01 script (note that I tried with .cgi at the end but it also didn't work)
#!/bin/bash
echo -e "Content-type: text/html\n"
cat << junk
<html>
<head>
<title>
saying
</title>
</head>
<body>
junk
#-----------------------
osascript -e "set volume 8"
say -v Whisper This is just wrong!
osascript -e "set volume 4"
say -v Whisper This is OK!
#-----------------------
cat << junk
</body>
</html>
junk
On the iMac I am running Apache v2.4.16.
On the iMac, from the terminal, I can enter ./say_test01 and I can hear the voice say the phrase.
Again, on the iMac, but from a browser, when I enter the localhost/cgi-bin/say_test01 all I see are the contents of the file.
I understand, from reading other threads, that this is because the system doesn't know which application is associated with this file.
When I run from a browser on my Win10 PC the command 192.168.1.55/cgi-bin/saysomething I either see the contents of the file displayed or I get the error message "This site can't be reached".
So I am looking for some help in figuring this out...
In the httpd.conf here are some excerpts:
These lines have the '#' removed:
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule cgi_module libexec/apache2/mod_cgi.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule alias_module libexec/apache2/mod_alias.so
Here is the Directory section:
<Directory "/Library/WebServer/CGI-Executables">
AddHandler cgi-script .cgi
Options FollowSymLinks +ExecCGI
AllowOverride None
Require all granted
</Directory>
And finally this line has the '#' removed
Include /private/etc/apache2/extra/httpd-userdir.conf
In the httpd-userdir.conf file, the following line has the '#' removed
Include /private/etc/apache2/users/*.conf
In the /etc/apache2/users directory I have the file Name.conf which has the following code
<Directory "/Users/Name/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
I have not touched the virtual host file because I don't think (?) it applies here.
My ultimate goal is to pass parameters from another computer (raspberry pi) perhaps using python code to a cgi script so that the iMac can 'say' what I want... (e.g. today's weather, lights have just turned on...etc)
Any suggestions on how I can get this working?
Edit:
Using the suggestion of looking at the error log I saw that my httpd.conf had an error. The line Options FollowSymLinks +ExecCGI gave me an error message saying that I needed to have the '+' in front of all options or no options! So I changed the line to Options +FollowSymLinks +ExecCGI. It now works well.
I now send a http GET statement from my ISY994i (Insteon controller) to the Raspberry pi3. On the pi I have setup a HTTPServer which waits for the GET statement. Once received, it triggers a python script on the pi which parses a weather xml file (which I previously created for my iRule app, using wunderground.com as the source) and extracts the current day's weather forecast, which is a text descriptive paragraph; it then re-formats the text forecast so that the iMac can say it properly; and finally, using urllib2, it triggers the iMac to 'say' the weather. I am still encountering a problem, on the pi, setting up the HTTPServer to run automatically on a reboot but it works well when I start it manually. I will open a new question to get help resolving this.
The first thing to point out is that scripts run through the web server are unlikely to have permissions to make things happen like having the computer speak. The web server user won't have permission to access that part of the system. You would be better off doing this through ssh.
However, in order to get you being able to run scripts through the web server, as asked, here goes:
You need to add the .cgi extension to your script. You have your handler set up for the .cgi extension:
AddHandler cgi-script .cgi
So it's only going to work for scripts that have that extension. Currently you have none. I know you say you tried it, but it's definitely not going to work without it. So put it back in, and see if it works now. If it doesn't, don't take it off again. It's needed. Let me know how you get on.

Apache server 2.4.7

While I am running my first program in Apache /2.4.7 (ubuntu) it shows error as Follows:
Not Found The requested URL /hello was not found on this server. Apache/2.4.7 (Ubuntu) Server at 127.0.0.1 Port 80.
I tried changing apache2.conf as below:
Options ExecCGI Indexes
FollowSymLinks <------
AllowOverride None
Require all granted
AddHandler cgi-script .py <--------
Still not able execute my program ?
Thanks
Based on the little info provided, there are a couple things to try:
Seems like you are trying to load a Python script, so include the extension of the script filename in the URL. As in: http://127.0.0.1/hello.py
Check for owner and permissions for the script. Does Apache have access to execute them?

Apache 2.2 403 Forbidden when accessing .sh file

My linux apache 2.2 server is giving a 403 when serving a .sh script file. The file is intended to be downloaded and linked to via a simple href:
Click to Download
Clicking yields a 403.
The apache error log displays:
==> mysever.com-error_log <==
[Fri Dec 18 20:04:29 2015] [error] [client xx.xx.xx.xx] client denied by server configuration: /var/www/html/downloads/test.sh, referer: http://www.myserver.com/downloads/test.html
If I copy the file to one with a different extension even like .exe it lets me download it. So it doesn't appear to be a permissions issue.
I tried changing how apache treats the file by adding to httpd.conf and a .htaccess in the same directory:
AddType text/plain .sh
No luck.
I tried with no luck adding these options to the apache directory
Options Indexes FollowSymLinks Includes ExecCGI
Very weird. Any suggestions?
It's possible that ModSecurity is blocking the request because of the .sh extension.
You can also try adding the following to your .htaccess:
<Files ~ "\.sh$">
Order allow,deny
Allow from all
</Files>

Apache configuration error 403

I have followed this tutorial to configure http apache server:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Managing_Confined_Services/chap-Managing_Confined_Services-The_Apache_HTTP_Server.html
When I connected using
telnet localhost 12345
GET / HTTP/1.0
I got an error
HTTP/1.1 403 Forbidden
and the default html of apache was listed below too.
I tried to configure the
/etc/httpd/conf/httpd.conf
adding
<Directory "/var/www/html">
Order allow,deny
Allow from all
Require all granted
</Directory>
and also ran
chmod -R o+x /var/www/html
and I'm still getting the same error. How do I proceed?
Do you have a file called index.html inside /var/www/html/ directory?
I would also suggest to check access and error logs files under /var/log/httpd directory

403 Forbidden on PHPMyAdmin in Puppy Linux

I have installed XAMPP in TahrPup. I need this for a class, but being the only one who runs Linux I can't get help from others in class or the instructor.
I'm getting a 403 Forbidden error accessing 127.0.0.1/phpmyadmin/ and localhost/phpmyadmin, or even just trying to access 127.0.0.1 and localhost.
Version: XAMPP for Linux 5.6.3-0
I did check that Apache and MySQL and stuff is started (running xampp start).
I have tried based on other answers editing httpd-xampp.conf under <LocationMatch ... to say
Order deny,allow
Deny from all
Allow from ::1 127.0.0.0/8
Allow from all
And in httpd.conf it says
<Directory "/opt/lampp/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
... this was already the configuration, and most answers said to change it -to- this, which it already was.
I can post config files if needed. I'm just to the point of not knowing where to start anymore.
As stated here:
Why can't I access Xampp's phpmyadmin on localhost? Access is forbidden.
The lines
Order allow,deny
Allow from all
needed to be removed. Okay.

Resources