简体   繁体   中英

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... (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM