Thursday, October 24, 2019

APCUPSD and Establishing a Browser Interface (CGI)

I have an American Power Conversion UPS. These power supplies can be manged through your computer either by the command line or through a browser interface. Getting the computer to communicate with the UPS through the command line was not difficult. Ubuntu directions here. What proved to be difficult was attempting to get the browser interface to work. It never did.

The inability to get the browser interface to work can be attributed to:
  1. The browser interface program "apcupsd-cgi" appears to be outdated in the Ubuntu repository. I was able to get, with much difficulty, other programs to work in the "/usr/lib/cgi-bin" directory. Which is good news in a way.
  2. The tutorials for installing the browser interface have left out crucial steps that must be taken prior to installing "apcupsd-cgi". This led to a lot of "why doesn't it work" anguish. Eventually, I was able to uncover these "missing" steps.
  3. Programs, overtime, are subject to revision. That is normal  However, at times these revisions may be incompatible with "old" tutorials. This was the case with my installed version of Apache2.
The first undisclosed hurdle to overcome (Point #2) is enabling the CGI module in Apache. How To Enable or Disable CGI Scripts in Apache 2.4. I was able to invoke the CGI module through issuing "sudo a2enmod cgi" at the command line.

The next undisclosed hurdle related to the file: "/etc/apache2/sites-available/000-default.conf". This file contained the link for designating the location of CGI files. See the sample script below. Warning. Do not copy the script below without reading Apache Tutorial: Dynamic Content with CGI. As I noted in Point #3, programs/tutorials change over time and the Apache tutorial is outdated by using "LoadModule", you need to use "sudo a2enmod cgi".

# --------------------------------------------------------
# https://httpd.apache.org/docs/2.4/howto/cgi.html   
  ScriptAlias "/cgi-bin/" "/usr/lib/cgi-bin/" 
 
<Directory "/usr/lib/cgi-bin">
   
    Options Indexes FollowSymLinks Includes ExecCGI
    AddHandler cgi-script .cgi .pl
    AllowOverride all
    Allow from all
    Require all granted
   
 
</Directory>   
# --------------------------------------------------------

Additionally, I recommend that you undertake an internet search on the terms used in the script sample above. The reason is that there is a lot of conflicting advice concerning which terms to use. The above example may work for me in Ubuntu 16.04, but it may not work for you. Who knows, there may yet be an undiscovered option that would get "apcupsd-cgi" to work.  Though I was never able to get "apcupsd-cgi" to work, I was able to enable CGI scripting. Which is good news in the end.

---------------------
PS: As an aside, you need to use HTML entities to prevent the "<" and ">" from being interpreted. Click here for more information on Common Gateway Interface (CGI).

No comments: