DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2009-03-09 03:04:43

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

CGI Scripts and NUT UPS Web Interface

I'm attempting to utilize the CGI scripts included in with NUT (nut-2.2.2-3.tgz) with my lighttpd server. I believe I have the correct packages installed and configured correctly however no matter how I try the script (upsstats.cgi) doesn't output to the browser (Firefox). If the script is run as 'root' from a Putty session it returns the expected HTML code. If I enter "http://192.168.xxx.xxx/html" in my browsers URL line the index file launches and I can see the "Network UPS Menu". If either of the links in the menu is selected; nothing happens. I've checked system and lighttpd logs; no errors found. my set-up is as follows;

- DNS323
- ffp .5
- lighttpd-1.4.20-1.tgz
     - server.document-root = "/mnt/USB/ffp/lib/nut/"
     - server.username = "lighttpd"
     - server.groupname = "lighttpd"
     - cgi.assign = ( ".pl"  => "/mnt/USB/ffp/bin/perl",
                             ".cgi" => "mnt/USB/ffp/bin/perl" )

- neon-0.25.5-1.tgz
- perl-5.10-2.tgz
- db42-4.2.52-1.tgz
- openssl-0.9.8j-1.tgz
- uclibc-0.9.29-7.tgz

- Files found in the "/mnt/USB/ffp/etc/examples/nut" directory have been copied to the "/mnt/USB/ffp/etc/" directory and renamed without the ".sample" extension. File ownership is Robert:users. Rights are 660.

- The /ffp/etc/hosts.conf file contains the line MONITOR APC_UPS@DNS323_NAS "Back-UPS RS 900". File ownership is root:nut. Rights are set at 640.

-The /ffp/etc/upsset.conf file has been uncommented. File ownership is root:lighttpd. Rights are set to 640.

- Rights on CGI scripts in the /ffp/lib/nut/cgi-bin are set at 755. Rights on the folder are also set at 755.

I built a simple test script (hi.cgi) and placed it in the /ffp/lib/nut/cgi-bin directory. When accessed via the browser it returns the expected results; "Hello World"

I'm guessing that I'm missing something simple and would appreciate any ansight you may have to offer.


Bob Blackwell
Pickering, ON

Offline

 

#2 2009-03-09 10:08:38

fonz
Member / Developer
From: Berlin
Registered: 2007-02-06
Posts: 1716
Website

Re: CGI Scripts and NUT UPS Web Interface

rcblackwell wrote:

no matter how I try the script (upsstats.cgi) doesn't output to the browser

...

     - cgi.assign = ( ".pl"  => "/mnt/USB/ffp/bin/perl",
                             ".cgi" => "mnt/USB/ffp/bin/perl" )

Hi Bob,

I think the '.cgi' line is incorrect. It tells lighttpd to run *.cgi files through perl, but the nut *.cgi files aren't perl scripts:

Code:

# file /ffp/lib/nut/cgi-bin/*.cgi
/ffp/lib/nut/cgi-bin/upsimage.cgi: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), stripped
/ffp/lib/nut/cgi-bin/upsset.cgi:   ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), stripped
/ffp/lib/nut/cgi-bin/upsstats.cgi: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), stripped

According to the lighttpd docs ( http://redmine.lighttpd.net/projects/li … ocs:ModCGI ), the config should be

Code:

     - cgi.assign = ( ".pl"  => "/mnt/USB/ffp/bin/perl",
                             ".cgi" => "" )

There's also a subtle issue with the directory layout (index.html/header.html reference /cgi-bin/nut/*.cgi, not /cgi-bin/*.cgi). I'd recommend not to set the web server's document root to /ffp/lib/nut, but instead link the nut files into a more common layout. Assuming you have set document-root to /mnt/HD_a2/www/pages, then you can include the nut pages like this:

Code:

cd /mnt/HD_a2/www/pages
mkdir -p cgi-bin
ln -s /ffp/lib/nut/cgi-bin cgi-bin/nut
ln -s /ffp/lib/nut/html nut

Also note that you have configured your web server to run as user and group 'lighttpd'. If the cgi programs require root privileges, you might need to either change username/group for lighttpd.

Offline

 

#3 2009-03-11 02:06:48

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: CGI Scripts and NUT UPS Web Interface

fonz wrote:

I think the '.cgi' line is incorrect. It tells lighttpd to run *.cgi files through perl, but the nut *.cgi files aren't perl scripts:

You are correct. Changing lighttpd's configuration file as suggested corrected the problem.


fonz wrote:

Also note that you have configured your web server to run as user and group 'lighttpd'. If the cgi programs require root privileges, you might need to either change username/group for lighttpd.

Setting the web server's document root to /ffp/lib/nut works, I'm able to browse the index file then load the *.cgi scripts from links on the index.html page.

fonz wrote:

There's also a subtle issue with the directory layout (index.html/header.html reference /cgi-bin/nut/*.cgi, not /cgi-bin/*.cgi). I'd recommend not to set the web server's document root to /ffp/lib/nut, but instead link the nut files into a more common layout. Assuming you have set document-root to /mnt/HD_a2/www/pages, then you can include the nut pages like this:

Code:

cd /mnt/HD_a2/www/pages
mkdir -p cgi-bin
ln -s /ffp/lib/nut/cgi-bin cgi-bin/nut
ln -s /ffp/lib/nut/html nut

I like this idea and would like to implement it however I'm having a little trouble. With server.document-root = "/mnt/USB/www/pages/ the index.html page loads fine but when one of the two links on that page are selected a 404 error is returned. Looking at the index.html/header.html files I see reference to /cgi-bin/*.cgi, not /cgi-bin/nut/*.cgi thus I don't think there's a need to create the /mnt/HD_a2/www/pages/cgi-bin directory. I also think the the link to the cgi files would be created from the /mnt/HD_a2/www/pages/ directory using the command ln -s /ffp/lib/nut/cgi-bin cgi-bin. What are your thoughts?

With appreciation

Last edited by rcblackwell (2009-03-11 02:17:47)


Bob Blackwell
Pickering, ON

Offline

 

#4 2009-03-12 01:19:20

rcblackwell
Member
From: Pickering, ON
Registered: 2008-05-19
Posts: 204
Website

Re: CGI Scripts and NUT UPS Web Interface

rcblackwell wrote:

Looking at the index.html/header.html files I see reference to /cgi-bin/*.cgi, not /cgi-bin/nut/*.cgi thus I don't think there's a need to create the /mnt/HD_a2/www/pages/cgi-bin directory. I also think the the link to the cgi files would be created from the /mnt/HD_a2/www/pages/ directory using the command ln -s /ffp/lib/nut/cgi-bin cgi-bin.

Neat, I tried this and found that it worked!

Fonz: Thanks for pointing me in the right direction.


Bob Blackwell
Pickering, ON

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB