Uhttpd and index.cgi problem

I can access my index.cgi script which is working flawlessly at ip/cgi-bin/index.cgi
when I access only by ip without providing full path its loading only luci web ui.

I tried few hours with different combinations and still cant make it work I renamed index.html in www/ to something else, then redirected to my own index.cgi didnt work.

It always wants to open luci web ui.

here is my uhttpd config.

config uhttpd 'main'
        list listen_http '0.0.0.0:80'
        list listen_http '[::]:80'
        option redirect_https '0'
        option home '/www'
        option rfc1918_filter '0'
        option max_requests '3'
        option max_connections '100'
        option cert '/etc/uhttpd.crt'
        option key '/etc/uhttpd.key'
        option cgi_prefix '/cgi-bin'
        option script_timeout '60'
        option network_timeout '30'
        option http_keepalive '20'
        option tcp_keepalive '1'
        option ubus_prefix '/ubus'
        option lua_prefix '/cgi-bin/luci=/usr/lib/lua/luci/sgi/uhttpd.lua'
        option no_dirlists '1'
        list interpreter '.sh=/bin/bash'
        list index_page 'index.cgi'

config cert 'defaults'
        option days '397'
        option key_type 'ec'
        option bits '2048'
        option ec_curve 'P-256'
        option country 'ZZ'
        option state 'Somewhere'
        option location 'Unknown'
        option commonname 'OpenWrt'


thanks.

ll /www

Then:
https://openwrt.org/docs/guide-user/services/webserver/uhttpd

Went thru the guide before opening this thread. Listing permissions wont help as i said i can access the script if i will provide direct link i.e. 192.168.0.2/cgi-bin/index.cgi

If there was a problem with permissions it would just download the file instead of executing.

As per my understanding index_page should try to find index.cgi first then search for defaults. I tried changing port to 8080 and creating separate config cgi_wan and limiting main to its defaults. Didnt work out either.

Override index.html with potato.html directing browser to your unauthenticated script.

same thing.



Check with wget what you are downloading, maybe site data needs wipe in browser.

plutus@plutus-inspiron3180:~$ wget --debug -O - --max-redirect=5 http://192.168.0.2
Setting --output-document (outputdocument) to -
Setting --max-redirect (maxredirect) to 5
DEBUG output created by Wget 1.21.4 on linux-gnu.

Reading HSTS entries from /home/plutus/.wget-hsts
URI encoding = ‘UTF-8’
--2024-12-14 17:48:40--  http://192.168.0.2/
Connecting to 192.168.0.2:80... connected.
Created socket 3.
Releasing 0x00005fafbaf8a560 (new refcount 0).
Deleting unused 0x00005fafbaf8a560.

---request begin---
GET / HTTP/1.1
Host: 192.168.0.2
User-Agent: Wget/1.21.4
Accept: */*
Accept-Encoding: identity
Connection: Keep-Alive

---request end---
HTTP request sent, awaiting response... 
---response begin---
HTTP/1.1 200 OK
Connection: Keep-Alive
Keep-Alive: timeout=20
ETag: "e77-2a0-675e08ea"
Last-Modified: Sat, 14 Dec 2024 22:38:34 GMT
Date: Sat, 14 Dec 2024 22:48:40 GMT
Content-Type: text/html
Content-Length: 672

---response end---
200 OK
Registered socket 3 for persistent reuse.
Length: 672 [text/html]
Saving to: ‘STDOUT’

-                                0%[                                                  ]       0  --.-KB/s               <!DOCTYPE html>
<html>
        <head>
                <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
                <meta http-equiv="Pragma" content="no-cache" />
                <meta http-equiv="Expires" content="0" />
                <meta http-equiv="Expires" content="Thu, 01 Jan 1970 00:00:00 GMT" />
                <meta http-equiv="refresh" content="0; URL=cgi-bin/index.cgi" />
                <style>
                        body { background: white; font-family: arial, helvetica, sans-serif; }
                        a { color: black; }

                        @media (prefers-color-scheme: dark) {
                                body { background: black; }
                                a { color: white; }
                        }
                </style>
        </head>
        <body>
                <a href="cgi-bin/index.cgi">LuCI - Lua Configuration Interface</a>
        </body>
</html>
-                              100%[=================================================>]     672  --.-KB/s    in 0s      

2024-12-14 17:48:40 (35.5 MB/s) - written to stdout [672/672]

its seems whatever I do with redirect it just doesnt care Have no idea from where its pulling luci if there is no explicit way to get it via this html which suppose to redirect.

Restart uhttpd?

didnt help. I`m running snapshot release but i doubt problem is in that because whole uhttpd is working except it just doesnt want to start my script when pointed to home directory i.e. www/ with cgi-bin/index.cgi its more than happy to work. My main web server is running on thttpd without any issues serving different cgi scripts. Decide to move to router small portion of scripts and ran into this issue. I was planning to separate access from WAN to index.cgi and from lan to luci as default but didnt even get that close.

may be something is missing or has a typo in my uhttpf config ? I went thru couple times couldnt find any typo but am not sure if I am missing something there which is conflicting .

Read the detached comment near indexpage, maybe try other option?

sorry cant get which comment are you referring to?
I`m wondering if problem can be reproduced with just making bash script like

#!/bin/bash
echo "Content-Type: text/html; charset=utf-8"
echo "Pragma: no-cache"
echo "Cache-Control: no-cache"
echo "Connection: Keep-Alive"
echo "Date: $(date -u +"%a, %d %b %Y %H:%M:%S GMT")"
echo "Keep-Alive: timeout=10, max=1000"
echo "Server: thttpd"
echo "X-Content-Type-Options: nosniff"
echo "X-Frame-Options: DENY"
echo "X-XSS-Protection: 1; mode=block"
echo ""
echo "<html><head></head><body>hello world</body></html>"
exit 0

and trying to execute by putting this script in index.cgi in www/ or www/cgi-bin/ .

Found a problem which corrected my cgi script running issues it was the line in config:


list interpreter '.sh=/bin/bash'

Because file is .cgi line should start with .cgi not .sh.

Now second problem is i cant make 2 configs for lan users and wan users it seems uhttpd wants to work only with 1 config in config file.

config uhttpd ‘main’

list listen_http '192.168.0.1:8080'

option home '/www'

………
config uhttpd ‘other’

list listen_http '0.0.0.0:80'

option home '/www/other'

I.e. want users from wan to access and be in www/other jail and users from lan access luci when pointing to 8080 port and be in www/ jail.

I even limit access to luci via my main router where all firewall and port forwarding rules are taking place and allowed only 80 port to be forwarded and still didnt help.

Is it possible to do? As per tiny tutorial on openwrt its possible but cant make it work so far.