[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#763582: Update: Apache2 now treating Python scripts the same way as CGI



On 10/1/2014 2:41 PM, Stefan Fritsch wrote:
severity 763582 normal
thanks

On Wednesday 01 October 2014 00:33:11, Leslie Rhorer wrote:
	Doing some research, I think I found the solution to the second
issue. I installed libapache2-mod-python, and now Apache treats the
same way as the other CGI scripts, but it still will not run any of
them, reportedly due to permissions issues.

In general, you can't expect a 2.2 configuration to work on 2.4
unchanged. See [1].
In addition, the old authorization directives
don't work well together with the new ones (which is used by the rest
of the configuration). I would recommend that you convert your
configuration to the new syntax (using Require). And increase the
loglevel to find out where the problems are.

[1] http://httpd.apache.org/docs/2.4/upgrading.html

I had already read through that document and implemented several different versions using Require, but while the exact nature of the issues changed, nothing allowed scripts to work. I converted back to tyhe defaul where there are any errors at all. When I try to load a script in a subdirectory of /var/www/cgi, it merely prints the text of the script on the screen. 'No errors. In fact, nothing at all in the error.log file with the loglevel set to info.

So, I started from scratch, and lets take one step at a time. I un-installed apache2 and then installed it back using apt-get. Then I re-installed libapache2-mod-python. There is an html file in /var/www called index.html. It seems to be working. All it is is a redirection to /var/www/cgi-bin/Thermostat/index.cgi:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd";>
<html>
<head>
<title>Redirecting example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="refresh" CONTENT="0; URL=/cgi-bin/Thermostat/index.cgi">

</head>
<body>
</body>
</html>

Here are the active parts of apache2.conf:
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel debug
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>
<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

sites-available/000-default.conf:
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

sites-available/default-ssl.conf:
<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost
                DocumentRoot /var/www/html
                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined
                SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>
                BrowserMatch "MSIE [2-6]" \
                                nokeepalive ssl-unclean-shutdown \
                                downgrade-1.0 force-response-1.0
                BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

        </VirtualHost>
</IfModule>

conf-available/serve-cgi-bin.conf:
<IfModule mod_alias.c>
        <IfModule mod_cgi.c>
                Define ENABLE_USR_LIB_CGI_BIN
        </IfModule>

        <IfModule mod_cgid.c>
                Define ENABLE_USR_LIB_CGI_BIN
        </IfModule>

        <IfDefine ENABLE_USR_LIB_CGI_BIN>
                ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
                <Directory "/usr/lib/cgi-bin">
                        AllowOverride None
                        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                        Require all granted
                </Directory>
        </IfDefine>
</IfModule>

/usr/lib/cgi-bin:
lrwxrwxrwx 1 root root 17 Mar  7  2014 /usr/lib/cgi-bin -> /var/www/cgi-bin/

error.log:
[Wed Oct 01 18:05:23.854746 2014] [:error] [pid 14953:tid 139821619898240] python_init: Python version mismatch, expected '2.7.5+', found '2.7.8'. [Wed Oct 01 18:05:23.854829 2014] [:error] [pid 14953:tid 139821619898240] python_init: Python executable found '/usr/bin/python'. [Wed Oct 01 18:05:23.854833 2014] [:error] [pid 14953:tid 139821619898240] python_init: Python path being used '/usr/lib/python2.7/:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload'. [Wed Oct 01 18:05:23.854842 2014] [:notice] [pid 14953:tid 139821619898240] mod_python: Creating 8 session mutexes based on 6 max processes and 25 max threads. [Wed Oct 01 18:05:23.854846 2014] [:notice] [pid 14953:tid 139821619898240] mod_python: using mutex_directory /tmp [Wed Oct 01 18:05:23.862333 2014] [mpm_event:notice] [pid 14953:tid 139821619898240] AH00489: Apache/2.4.10 (Debian) mod_python/3.3.1 Python/2.7.8 configured -- resuming normal operations [Wed Oct 01 18:05:23.862346 2014] [mpm_event:info] [pid 14953:tid 139821619898240] AH00490: Server built: Sep 21 2014 21:02:09 [Wed Oct 01 18:05:23.862368 2014] [core:notice] [pid 14953:tid 139821619898240] AH00094: Command line: '/usr/sbin/apache2' [Wed Oct 01 18:05:23.862605 2014] [mpm_event:debug] [pid 14956:tid 139821528577792] event.c(2009): AH02471: start_threads: Using epoll [Wed Oct 01 18:05:23.862846 2014] [mpm_event:debug] [pid 14957:tid 139821528577792] event.c(2009): AH02471: start_threads: Using epoll

When I put /192.168.1.50/ in the URL bar, I get a re-direction to 192.168.1.50/cgi-bin/Thermostat/index.cgi, and the following pops up on the screen:
#!/bin/bash
. /var/www/cgi-bin/Thermostat/header.sh

Tset(){
	MonthVar=3240000
	if [ $1 -lt 3 ];
	then
		RCost=$HCost
	else
		RCost=$CCost
	fi
	(( Dollars=tmvar * RCost / MonthVar ))
	(( Cents=(tmvar * RCost - Dollars * MonthVar ) * 100 / MonthVar ))

	if [ $Cents -lt 10 ];
	then
		Cents="0$Cents"
	fi

	(( TH=tmvar / 3600 ))
	(( TM=(tmvar - TH * 3600 ) / 60 ))

	if [ $TH -lt 10 ];
	then
		TH="0$TH"
	fi

	if [ $TM -lt 10 ];
	then
		TM="0$TM"
	fi
	Tout=$TH:$TM
}

NameWidth=140
ActWidth=100
TempWidth=65
TableWidth=$[ $NameWidth + $ActWidth + $TempWidth + 10 ]
ACNmWidth=210
ACStWidth=$[ $NameWidth + 2 * $TempWidth - ACNmWidth ]

Refresh=180

echo "Content-type: text/html"
echo ""
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
echo ""
echo "<HTML>"
echo "<HEAD>"
echo "<TITLE>Thermostat</TITLE>"
echo "<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">"
echo "<META HTTP-EQUIV=\"refresh\" content=\"$Refresh\">"
echo "<META HTTP-EQUIV=\"Pragma\" content=\"no-cache\">"

echo "</HEAD>"
echo "<body>"
...

	Feel free to take a look at fletchergeek.homelinux.net.  So now what?


Reply to: