2013-10-23 16 views
5

Ich habe ein Problem beim Abrufen von Python-Skripten innerhalb von Lighttpd und cgi-bin. Ich habe ähnliche Probleme innerhalb von stackoverflow (d. H. Lighttpd and cgi python) und anderen Websites gefunden, aber keines betrifft vollständig meine Konfiguration. Ich kann das eigenständige Python-Skript ausführen, indem ich "python flash.py" ohne Probleme ausstelle.Python-Skripte mit Lighttpd und CGI ausführen

Ein wichtiger Punkt, der helfen könnte, dies zu lösen, ist die Tatsache, dass alles vor der Ausführung von "apt-get update" und "apt-get upgrade" funktionierte. Ich habe experimentiert, indem ich die Berechtigungen für bestimmte Dateien missbraucht habe und mit den Konfigurationsdateien herumgespielt habe, aber keiner davon hat geholfen.

Ich habe seitdem alles wieder in den Zustand zurückversetzt, in dem es gerade nach dem Ausführen der Updates war. Das ist Neuland für mich und ich bin einfach nicht gebildet genug, um etwas Offensichtliches zu finden. So wie es aussieht, hier ist meine aktuelle Konfiguration.

/etc/lighttpd/lighttpd.conf

server.modules = (
     "mod_access", 
     "mod_alias", 
     "mod_compress", 
     "mod_redirect", 
#  "mod_auth", 
#  "mod_rewrite", 
) 

server.document-root  = "/var/www" 
server.upload-dirs   = ("/var/cache/lighttpd/uploads") 
server.errorlog    = "/var/log/lighttpd/error.log" 
server.pid-file    = "/var/run/lighttpd.pid" 
server.username    = "www-data" 
server.groupname   = "www-data" 
server.port     = 80 


index-file.names   = ("index.php", "index.html", "index.lighttpd.html") 
url.access-deny    = ("~", ".inc") 
static-file.exclude-extensions = (".php", ".pl", ".fcgi") 

compress.cache-dir   = "/var/cache/lighttpd/compress/" 
compress.filetype   = ("application/javascript", "text/css", "text/html", "text/plain") 

# default listening port for IPv6 falls back to the IPv4 port 
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port 
include_shell "/usr/share/lighttpd/create-mime.assign.pl" 
include_shell "/usr/share/lighttpd/include-conf-enabled.pl" 

#auth.backend = "plain" 
#auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpwd" 

#auth.require = ("/var/www" => 
#(
#.method. => "basic", 
#.realm. => "Authentication required", 
#.require. => "user=admin" 
#) 
#) 

etc/lighttpd/conf-enabled/10-cgi.conf

# /usr/share/doc/lighttpd/cgi.txt 

server.modules += ("mod_cgi") 

$HTTP["url"] =~ "^/cgi-bin/" { 
     cgi.assign = (".py" => "/usr/bin/python") 
} 

## Warning this represents a security risk, as it allow to execute any file 
## with a .pl/.py even outside of /usr/lib/cgi-bin. 
# 
#cgi.assign  = (
#  ".pl" => "/usr/bin/perl", 
#  ".py" => "/usr/bin/python", 
#) 

/var/www/cgi-bin/Blitz. py

#Dog Treat Dispenser. Flash Code 
import RPIO 
import time 
import cgi 

FLASHER = 22 
#ADD CLICKER! 

RPIO.setup(FLASHER , RPIO.OUT) #Set FLASHER pin as OUTPUT 

for x in range(0, 5):     #Flash for 2 seconds 

     RPIO.output(FLASHER, True) 

     #ADD CLICKER SUBROUTINE 
     time.sleep(.500) 

     RPIO.output(FLASHER, False) 

     #ADD CLICKER SUBROUTINE 
     time.sleep(.500) 

# reset every channel that has been set up by this program, 
# and unexport interrupt gpio interfaces 
RPIO.cleanup() 

print "Content-Type: text/html" 
print "Location: http://10.143.141.164" 
print 
print "<html><head>" 
print "<title>Flash!</title>" 
print "</head>" 
print "<body>" 
print "<h1>Flash!</h1>" 
print "</body>" 
print "</html>" 

Nach einer Tonne Forschung, und nirgends zu bekommen, bin ich ratlos. Jede Hilfe, die Sie zur Verfügung stellen könnten, wäre sehr willkommen. Wenn es etwas gibt, was ich vermisst habe, lass es mich wissen und ich werde mein Bestes tun, um es dir zu bringen.

Vielen Dank!

Antwort

2

sollte diese Arbeit:

server.modules += ("mod_cgi") 

cgi.assign = (".pl" => "/usr/bin/perl", 
        ".py" => "/usr/bin/python") 

Welche Version von Python sind Sie? Haben Sie python3 aktualisiert und installiert? Wenn ja, müssen Sie auch python2 installieren und ändern /usr/bin/python zu /usr/bin/python2

Haben Sie Mimetypen für Python in Ihrem mimetypes.conf Dateien für Lighttpd? Es sollte so aussehen:

".py" => "text/x-python", 
".pyc" => "application/x-python-code", 
".pyo" => "application/x-python-code", 

Haben Sie die Fehlerprotokolle von Lighttpd überprüft, bevor Sie Änderungen vornehmen? Die Protokolle werden gespeichert in /var/log/lighttpd/error.log

Was ist das genaue Problem, das Sie haben? Versuchen die Dateien zu downloaden, wenn Sie zu dem Verzeichnis navigieren? Dies ist schwierig ohne weitere Informationen zu beheben.

0

OP-Skript in /var/www/cgi-bin/flash.py während auf meinem System (Ubuntu treuen) Nennungen setzen, habe ich Skripte im Verzeichnis /usr/lib/cgi-bin/script.py und greifen Sie über den Browser URL: http://localhost/cgi-bin/script.py

In anycase, landete ich auf diese Frage SO, während zu versuchen, cgi python-Skript Arbeit in lighttpd machen, damit diese Informationen als Referenz setzen - sonst @ Dolores Antwort sollte ausreichen - wieder in meinem Fall die Config war

$HTTP["remoteip"] =~ "127.0.0.1" {  
    alias.url += ("/cgi-bin/" => "/usr/lib/cgi-bin/") 
    $HTTP["url"] =~ "^/cgi-bin/" { 
    cgi.assign = (".sh" => "/bin/sh") 
    } 
} 

wie in /etc/lighttpd/conf-enabled/10-cgi.conf setzen, cgi-Modul ermöglicht cmd: lighty-enable-mod cgi und dann einen erneuten Laden von lighttpd mit cmd tun: /etc/init.d/lighttpd force-reload

Im Anschluss an die script.py:

import time 
print("Content-Type: text/html\n\n") # html markup follows 

timeStr = time.strftime("%c") # obtains current time 

htmlFormat = """ 
<html> 
<Title>The Time Now</Title> 
<body> 
<p>The current Central date and time is: {timeStr}</p> 
</body> 
</html> """ 

print(htmlFormat.format(**locals())) # see embedded %s^above