Using TXT CivetWeb server as general web server (part 1B)

1 Introduction

(c) 2020 C. ing. Van Leeuwen Btw. for TesCaWeb, Enschede Netherlands
version 1.1.3

1.1 Notes & assumption:

you have already experiences with the use of the standard TXT web server for access the public TXT data area:
ID= TXT,
PSW=xxxx (the actual TXT id , TXTxxxx )).

Note 1:
Part 1A describes the original web site on port 80 and the nes one on port 8081 with two different CivetWeb executables.
Part 1B describes the original web site and the user web site in the same web root directory.

1.2 Introduction

Since firmware 4.5.1 there is a web server present on the TXT, a CivetWeb server.

  1. Is this web server also usable as general-purpose web server and can we transfer the TXT in a nice web server?
  2. Is the pre-installed Civetweb server all the functionally?
  3. What is this functionality?
  4. Is it possible to use this web server to interact with the TXT actuator and sensor functionality?
  5. Is it possible to integrate the Civetweb functionality in RoboPro SLI extensions?

In this blog I will show you that it is possible to make use of this CIvetweb server as a more general web server. Also that it will be possible to use CGI to access the fischertechnik actuators and sensors. This CGI could be a Python script or a compiled C/C++ CGI.

The pre-installed Civetweb server (v1.12) has a limited functionality. However it is possible to replace this version with a full-functional Civetweb version or use a second executable.

It is also possible to integrate the embedded version of the CivetWeb server in a RoboPro SLI extension or a local C/C++ program.

2 What is available and what tools are needed?

2.1 Setting up the development environment

To explorer the CivetWeb server functionality you will need al least the next two tools on your development system.

2.2 Set the root password on the TXT

You will need root-access to modify a TXT system file.
Log remote to the TXT with the ssh-client (putty) with:
ID=ROBOPro,
PSW=ROBOPro,
The root password can be set with the command:

 sudo /usr/sbin/new_root_password.sh 60 

After 1 min waiting time, the new root password will show up on the TXT screen for 2 min.
You will see something like this: SNSQARAWMAQYYRLF. Copy it for later.
Now you are able to start a second ssh-client with:
ID=root,
PSW=<your new root PSW>
Warning: Work only as root when you really need this, otherwise work as ROBOPro.

3 CivetWeb: where on the TXT?

A limited version of CivetWeb (V1.12) is present on the TXT.
Where to find the CivetWeb data maps:

  • /usr/bin/civetweb
    This is the executable.
  • /etc/int.d/civetweb_txt
    This is the command (cmd) file used by the TXT menu for starting and stopping the TXT Civetweb as daemon.
    The PID id is 1738:
#!/bin/sh
start() {
		printf "Starting civetweb: "
		start-stop-daemon -S -q -m -b -p /var/run/civetweb.pid \
			--exec /usr/bin/civetweb /etc/civetweb.conf
		[ $? = 0 ] && echo "OK" || echo "FAIL"
}
stop() {
		printf "Stopping civetweb: "
		start-stop-daemon -K -q -p /var/run/civetweb.pid
		[ $? = 0 ] && echo "OK" || echo "FAIL"
}
restart() {
		stop
		start
}
case "$1" in
start)
	start
	;;
stop)
	stop
	;;
restart|reload)
	restart
	;;
*)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
	esac
	exit $?
  • • /etc/civetweb.conf (root permissions are needed to change)
    Note 1: port 80 can only be used in combination with the start by the daemon (needs to run under the root account).
    Note 2:
# Civetweb web server configuration file. 
# For detailed description of every option, visit 
# https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md 
# Lines starting with '#' and empty lines are ignored. 
# To make a change, remove leading '#', modify option's value, 
# save this file and then restart Civetweb.
document_root /var/www
listening_ports 80
hide_files_patterns .*|TxtControlMain|libs|run.sh|ROBOPro
url_rewrite_patterns /txt=/opt/knobloch
put_delete_auth_file /var/www/.htpasswd
authentication_domain TXTController.local
run_as_user ROBOPro
  • /var/www (for the web pages) (root permissions are needed to change)

How to get the information about the installed CivetWeb server?

The actual configuration option for the Civetweb can be make visible with the ssh-terminal:
There are two options to gain information about the installed executable.

Using username "ROBOPro".
ROBOPro@192.168.10.161's password:
_____ _____     _         _
| ___|_   _|   | |___   _| |_
| |_   | |_____| __ \ \/ / __|
| _|   | |_____| |_  > < | |_
|_|    |_|      \__/_/ \_\\__|
Welcome to FT-txt
$ cd usr
$ /usr/bin/civetweb -?
and
$ /usr/bin/civetweb -I

Furthermore you will find here some more information.

  • General Civetweb information can be found here.
  • The description of the configuration option can be found here.

How to modified the CivetWeb for general use?

There are more options to create a more general web server.

  1. Make changes to the configuration of the actual installation. The changes need to make under the root account. But the www document root will be accessible under the normal ROBOPro account.
  2. Start a second instance of the Civetweb server that is working under a different port (not 80).

Modify the actual installation.

Under the ROBOPro account :

  • Create a map wwwroot in the public data area: /opt/knobloch/Data/wwwroot/
  • Copy the content from /var/www/ to this wwwroot map. With this you can keep the original functionality.
  • Optional.
    Copy the executable civetweb from /usr/bin/ to /opt/knobloch/
    Take care of the right permissions (755).
  • Copy the file /etc/civetweb.conf to /opt/knobloch
  • Modify the civetweb.conf
    For all available the options, see here.
    Which options are available depends on the civetweb compilation.
# Civetweb web server configuration file. 
# For detailed description of every option, visit 
# https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md 
# Lines starting with '#' and empty lines are ignored. 
# To make a change, remove leading '#', modify option's value, 
# save this file and then restart Civetweb.
document_root /opt/knobloch/Data/wwwroot
listening_ports 80
hide_files_patterns .*|TxtControlMain|libs|run.sh|ROBOPro|civetweb|civetweb.conf
url_rewrite_patterns /txt=/opt/knobloch
put_delete_auth_file /var/www/.htpasswd
authentication_domain TXTController.local
run_as_user ROBOPro

How to change the deamon start up command file?

For changing the start up command file you will need to logon as root.
And go to the /etc/int.d/civetweb_txt.
Make a copy of the original one!

  • Change the directory for the configuration file: /opt/knobloch
    line 5:
    --exec /usr/bin/civetweb /opt/knobloch/civetweb.conf
  • Optional:
    Change the directory for the executable file: /opt/knobloch
    line 5
    --exec /opt/knobloch/civetweb /opt/knobloch/civetweb.conf
    This optional, you can also use the installed version in it original directory. But this enable the possibility to replace the civetweb executable with a new one under the ROBOPro account.
#!/bin/sh
start() {
		printf "Starting civetweb: "
		start-stop-daemon -S -q -m -b -p /var/run/civetweb.pid \
			--exec /usr/bin/civetweb /opt/knobloch/civetweb.conf
		[ $? = 0 ] && echo "OK" || echo "FAIL"
}
stop() {
		printf "Stopping civetweb: "
		start-stop-daemon -K -q -p /var/run/civetweb.pid
		[ $? = 0 ] && echo "OK" || echo "FAIL"
}
restart() {
		stop
		start
}
case "$1" in
start)
	start
	;;
stop)
	stop
	;;
restart|reload)
	restart
	;;
*)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
	esac
	exit $?

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *