# Web Status Page



## Phishfry (Oct 31, 2022)

I would like to have a webpage display sysctl output for OneWire on my local network.

sysctl dev.ow_temp.0.temperature
sysctl dev.ow_temp.1.temperature
sysctl dev.ow_temp.2.temperature
sysctl dev.ow_temp.3.temperature

What are my options? I would like to use a lightweight solution.
lighttpd is my prefered server.

I see PHP has a shell_execute function.

I only want static content.
How to display shell command output in html?


----------



## W.hâ/t (Oct 31, 2022)

I am guessing you can't just write the html file from a shell.
I found this that looks pretty interesting. (lua)


----------



## Phishfry (Oct 31, 2022)

W.hâ/t said:


> I am guessing you can't just write the html file from a shell.


Yes that approach works. I see awk use some.

I don't know bash well but this sounds like what I want.








						A Web Server in 1 Line of Bash Code
					

For people who do a lot of work with command line tools or Bash code, having a Bash web server could be very handy. I was really amazed that in one line of Bash code I was able to create web server…




					funprojects.blog


----------



## richardtoohey2 (Oct 31, 2022)

Tcl and tclhttpd?  Might be too step a learning curve.

Can certainly do stuff like this with PHP, yes.  Or Python etc.


----------



## Jose (Oct 31, 2022)

I use net-mgmt/mrtg to monitor the CPU temperature and network bandwidth usage at my Openbsd firewall. I use SNMP for this, but MRTG can graph the output of arbitrary scripts, too:





						Stuff you can do quickly with MRTG (that has nothing to do with router traffic) - Zurgl
					

Most people know about MRTG as a tool to measure network traffic (though there are probably better alternatives these days), but did you know it's quite simple to configure it to measure many other things -- including some you've probably never thought of? For instance...



					zurgl.com


----------



## ralphbsz (Oct 31, 2022)

What you are writing is de-facto a CGI program. The lighttpd server supports those. Those can be written in many languages. I personally prefer Python, but I've also done Perl; PHP is sort of the industry standard. All of those languages have a functionality like "system" to run an arbitrary program. Some of them also allow you to do a sysctl directly, without invoking another program throught system().


----------



## Phishfry (Oct 31, 2022)

Just for a technical prelude I want to try to use csh instead of bash for a one line web server.
I am infatuated with the idea.
The most simple web server possible with a tool in base. Great way to learn from the bottom up.

I am not good at bash to csh conversion so please bear with me for this distraction.

My sources:








						simple-web-server.sh
					

GitHub Gist: instantly share code, notes, and snippets.




					gist.github.com
				





			Single Line Web Server With nc on FreeBSD
		









						How to make a webserver with netcat (nc)
					

The netcat tool nc can operate as a TCP client. Because HTTP works over TCP, nc can be used as an HTTP server! Because nc is a UNIX tool, we can use it to make custom web servers: servers which return any HTTP headers you want, servers which return the response very slowly, servers which return...




					jameshfisher.com


----------



## SirDice (Oct 31, 2022)

All you have to do is print '200 OK' and a couple of headers, then you can just print HTML. You can easily test this on the command line without using a webserver.


----------



## Phishfry (Oct 31, 2022)

I am using the sh interactive shell under tcsh.
This command almost works but I am missing the netcat -q flag in FreeBSD. 
Once I 'control-c' the command the webpage is filled.
`while true ; do { echo -e 'HTTP/1.1 200 OK\r\n' ; cat index.html ; } | nc -l 8080 ; done`


----------



## W.hâ/t (Oct 31, 2022)

```
IFS='
'
nc -lk [ip] [port] | while read line; do
    if [ "$line" = "GET HTTP/1.1"] #the get request
        while read unused; do :; done #clean request header
        print "HTTP/1.1 200 OK\r\n\r\n"
        printf "<html>temp1=%s.." $(sysctl -n hw... hw...)
    fi
done
```

Something of the sort should work fine (havn't tested).


----------



## W.hâ/t (Oct 31, 2022)

W.hâ/t said:


> ```
> IFS='
> '
> nc -lk [ip] [port] | while read line; do
> ...


Doesn't work at all. It's a snake that bite's his tail.. Post #6 is prefered unless you can manage to redirect to/from some fifo.


----------



## W.hâ/t (Oct 31, 2022)

```
[what@bsd]~> cat header.html serv.sh foot.html
HTTP/1.1 200
Server: nc
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html>
        <body>
#!/bin/sh

body()
{
        while read l; do
                echo "<p>$l</p>"
        done
}

while :; do
        sysctl dev.cpu | grep temperature | body > body.html
        cat header.html body.html foot.html | \
                nc -lN 8000
done
        </body>
</html>
```

Here we go. Somehow I didn't manage to make this work earlier.. Does the browser have some syntax check now?
It seems that getting a 'proper' html code helps a lot.

With the '-N' option the server stops after the client read the 'nc' buffer, which means that when you reload the page, the resulting html code will be the one generated when 'nc' was first issued or the page was last reloaded.


----------

