{"id":467,"date":"2020-10-30T21:00:34","date_gmt":"2020-10-30T20:00:34","guid":{"rendered":"http:\/\/tescaweb.nl\/Carel\/?p=467"},"modified":"2022-01-26T14:26:29","modified_gmt":"2022-01-26T13:26:29","slug":"using-txt-civetweb-server-as-general-web-server-part-1b","status":"publish","type":"post","link":"http:\/\/tescaweb.nl\/Carel\/?p=467","title":{"rendered":"Using TXT CivetWeb server as general web server (part 1B)"},"content":{"rendered":"\n<h2>1 Introduction<\/h2>\n\n\n\n<p>(c) 2020 C. ing. Van Leeuwen Btw.  for TesCaWeb, Enschede Netherlands<br>version 1.1.3 <\/p>\n\n\n\n<h3>1.1 Notes &amp; assumption:<\/h3>\n\n\n\n<p>you have already experiences with the use of the standard TXT web server for access the public TXT data area:<br>ID= TXT,<br>PSW=xxxx (the actual TXT id , TXTxxxx )).<br><br><strong>Note 1:<\/strong><br>Part 1A describes the original web site on port 80 and the nes one on port 8081 with two different CivetWeb executables.<br>Part 1B describes the original web site and the user web site in the same web root directory.<\/p>\n\n\n\n<h3>1.2 Introduction<\/h3>\n\n\n\n<p>Since firmware 4.5.1 there is a web server present on the TXT, a CivetWeb server.<\/p>\n\n\n\n<ol><li>Is this web server also usable as general-purpose web server and can we transfer the TXT in a nice web server?<\/li><li>Is the pre-installed Civetweb server all the functionally?<\/li><li>What is this functionality?<\/li><li>Is it possible to use this web server to interact with the TXT actuator and sensor functionality?<\/li><li>Is it possible to integrate the Civetweb functionality in RoboPro SLI extensions?<\/li><\/ol>\n\n\n\n<p>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.<br><br>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.<br><br>It is also possible to integrate the embedded version of the CivetWeb server in a RoboPro SLI extension or a local C\/C++ program.<\/p>\n\n\n\n<h2>2  What is available and what tools are needed?<\/h2>\n\n\n\n<h3>2.1 Setting up the development environment<\/h3>\n\n\n\n<p>To explorer the CivetWeb server functionality you will need al least the next two tools on your development system.<\/p>\n\n\n\n<ul><li>Install a ssh-client on the developing system, for example: <a rel=\"noreferrer noopener\" aria-label=\"PUTTY (opent in een nieuwe tab)\" href=\"https:\/\/www.puttygen.com\/download-putty\" target=\"_blank\">PUTTY<\/a>.<\/li><li>Install a ssh-FTP client on the developing system, for example <a rel=\"noreferrer noopener\" aria-label=\"FileZilla (opent in een nieuwe tab)\" href=\"https:\/\/filezilla-project.org\/\" target=\"_blank\">FileZilla<\/a>.<\/li><li>Also a recent version of Eclipse EDT (2020-9) with a Linaro tool chain and MS Visual Studio 2019 could be very helpful. <br>See also:  <a rel=\"noreferrer noopener\" aria-label=\" information about setting up the Eclipse EDT developing environment (opent in een nieuwe tab)\" href=\"https:\/\/github.com\/fischertechnik\/txt_demo_ROBOPro_SLI\/blob\/master\/README.md#for-the-developer\" target=\"_blank\"> information about setting up the Eclipse EDT developing environment<\/a> (cross compiling).<\/li><\/ul>\n\n\n\n<h3>2.2 Set the root password on the TXT<\/h3>\n\n\n\n<p>You will need root-access to modify a TXT system file.<br>Log remote to the TXT with the ssh-client (putty) with: <br>ID=<strong>ROBOPro<\/strong>, <br>PSW=<strong>ROBOPro<\/strong>, <br>The root password can be set with the command:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;languageLabel&quot;:&quot;file&quot;,&quot;fileName&quot;:&quot;Console&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;modeName&quot;:&quot;shell&quot;}\"> sudo \/usr\/sbin\/new_root_password.sh 60 <\/pre><\/div>\n\n\n\n<p>After 1 min waiting time, the new root password will show up on the TXT screen for 2 min. <br>You will see something like this: SNSQARAWMAQYYRLF. Copy it for later.<br>Now you are able to start a second ssh-client with: <br>ID=<strong>root<\/strong>, <br>PSW=<strong>&lt;your new root PSW&gt;<\/strong><br><strong>Warning: Work only as root when you really need this, otherwise work as ROBOPro.<\/strong><\/p>\n\n\n\n<h2> 3  CivetWeb: where on the TXT?<\/h2>\n\n\n\n<p> A limited version of CivetWeb (V1.12) is present on the TXT.<br> Where to find the CivetWeb data maps:<\/p>\n\n\n\n<ul><li><code>\/usr\/bin\/civetweb<\/code> <br>This is the executable.<\/li><li><code>\/etc\/int.d\/civetweb_txt<\/code><br>This is the command (cmd) file used by the TXT menu for starting and stopping the TXT Civetweb as <a rel=\"noreferrer noopener\" aria-label=\"daemon (opent in een nieuwe tab)\" href=\"https:\/\/askubuntu.com\/questions\/192058\/what-is-technical-difference-between-daemon-service-and-process\" target=\"_blank\">daemon<\/a>. <br>The PID id is 1738:<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;languageLabel&quot;:&quot;file&quot;,&quot;fileName&quot;:&quot; civetweb_txt&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">#!\/bin\/sh\nstart() {\n\t\tprintf &quot;Starting civetweb: &quot;\n\t\tstart-stop-daemon -S -q -m -b -p \/var\/run\/civetweb.pid \\\n\t\t\t--exec \/usr\/bin\/civetweb \/etc\/civetweb.conf\n\t\t[ $? = 0 ] &amp;&amp; echo &quot;OK&quot; || echo &quot;FAIL&quot;\n}\nstop() {\n\t\tprintf &quot;Stopping civetweb: &quot;\n\t\tstart-stop-daemon -K -q -p \/var\/run\/civetweb.pid\n\t\t[ $? = 0 ] &amp;&amp; echo &quot;OK&quot; || echo &quot;FAIL&quot;\n}\nrestart() {\n\t\tstop\n\t\tstart\n}\ncase &quot;$1&quot; in\nstart)\n\tstart\n\t;;\nstop)\n\tstop\n\t;;\nrestart|reload)\n\trestart\n\t;;\n*)\n\techo &quot;Usage: $0 {start|stop|restart}&quot;\n\texit 1\n\tesac\n\texit $?<\/pre><\/div>\n\n\n\n<ul><li> \u2022 \/etc\/civetweb.conf (root permissions are needed to change) <br>   Note 1: port 80 can only be used in combination with the start by the daemon (needs to run under the root account). <br>   Note 2: <\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;languageLabel&quot;:&quot;file&quot;,&quot;fileName&quot;:&quot;civetweb.conf original&quot;,&quot;language&quot;:&quot;HTML&quot;,&quot;modeName&quot;:&quot;html&quot;}\"># Civetweb web server configuration file. \n# For detailed description of every option, visit \n# https:\/\/github.com\/civetweb\/civetweb\/blob\/master\/docs\/UserManual.md \n# Lines starting with '#' and empty lines are ignored. \n# To make a change, remove leading '#', modify option's value, \n# save this file and then restart Civetweb.\ndocument_root \/var\/www\nlistening_ports 80\nhide_files_patterns .*|TxtControlMain|libs|run.sh|ROBOPro\nurl_rewrite_patterns \/txt=\/opt\/knobloch\nput_delete_auth_file \/var\/www\/.htpasswd\nauthentication_domain TXTController.local\nrun_as_user ROBOPro<\/pre><\/div>\n\n\n\n<ul><li>\/var\/www (for the web pages) (root permissions are needed to change)<br><img class=\"wp-image-408\" style=\"width: 600px;\" src=\"http:\/\/tescaweb.nl\/Carel\/wp-content\/uploads\/2020\/10\/TXT_web_01.jpg\" alt=\"\"><\/li><li><\/li><\/ul>\n\n\n\n<h2>How to get the information about the installed CivetWeb server?<\/h2>\n\n\n\n<p> The actual configuration option for the Civetweb can be make visible with the ssh-terminal:<br>There are two options to gain information about the installed executable.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;languageLabel&quot;:&quot;file&quot;,&quot;fileName&quot;:&quot;screen&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">Using username &quot;ROBOPro&quot;.\nROBOPro@192.168.10.161's password:\n_____ _____     _         _\n| ___|_   _|   | |___   _| |_\n| |_   | |_____| __ \\ \\\/ \/ __|\n| _|   | |_____| |_  &gt; &lt; | |_\n|_|    |_|      \\__\/_\/ \\_\\\\__|\nWelcome to FT-txt\n$ cd usr\n$ \/usr\/bin\/civetweb -?\nand\n$ \/usr\/bin\/civetweb -I\n<\/pre><\/div>\n\n\n\n<p>Furthermore  you will find here some more information.<\/p>\n\n\n\n<ul><li> General Civetweb information can be found <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/civetweb\/civetweb\" target=\"_blank\">here<\/a>. <\/li><li>The description of the configuration option can be found<a rel=\"noreferrer noopener\" aria-label=\" here (opent in een nieuwe tab)\" href=\"https:\/\/github.com\/civetweb\/civetweb\/blob\/master\/docs\/UserManual.md\" target=\"_blank\"> here<\/a>.<\/li><\/ul>\n\n\n\n<h2>How to modified the CivetWeb for general use?<\/h2>\n\n\n\n<p> There are more options to create a more general web server.<\/p>\n\n\n\n<ol><li>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.<\/li><li>Start a second instance of the Civetweb server that is working under a different port (not 80).<\/li><\/ol>\n\n\n\n<h3> Modify the actual installation.<\/h3>\n\n\n\n<p><strong> Under the ROBOPro account :<\/strong><\/p>\n\n\n\n<ul><li> Create a map <em>wwwroot<\/em> in the public data area: <code>\/opt\/knobloch\/Data\/wwwroot\/<\/code><\/li><li> Copy the content from <code>\/var\/www\/<\/code> to this <code>wwwroot<\/code> map. With this you can keep the original functionality.<\/li><li> Optional.<br>Copy the executable civetweb from <strong><code>\/usr\/bin\/<\/code><\/strong> to <strong><code>\/opt\/knobloch\/ <\/code><\/strong><br>Take care of the right permissions (755).<\/li><li>Copy the file <code>\/etc\/civetweb.conf<\/code> to<code> \/opt\/knobloch<\/code><\/li><li>Modify the <code>civetweb.conf<\/code> <br>For all available the options, <a rel=\"noreferrer noopener\" aria-label=\"see here (opent in een nieuwe tab)\" href=\"https:\/\/github.com\/civetweb\/civetweb\/blob\/master\/docs\/UserManual.md\" target=\"_blank\">see here<\/a>.<br>Which options are available depends on the civetweb compilation.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;languageLabel&quot;:&quot;file&quot;,&quot;fileName&quot;:&quot;  \/opt\/knobloch\/c&lt;strong&gt;ivetweb.conf&lt;\/strong&gt;  &quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;modeName&quot;:&quot;shell&quot;}\"># Civetweb web server configuration file. \n# For detailed description of every option, visit \n# https:\/\/github.com\/civetweb\/civetweb\/blob\/master\/docs\/UserManual.md \n# Lines starting with '#' and empty lines are ignored. \n# To make a change, remove leading '#', modify option's value, \n# save this file and then restart Civetweb.\ndocument_root \/opt\/knobloch\/Data\/wwwroot\nlistening_ports 80\nhide_files_patterns .*|TxtControlMain|libs|run.sh|ROBOPro|civetweb|civetweb.conf\nurl_rewrite_patterns \/txt=\/opt\/knobloch\nput_delete_auth_file \/var\/www\/.htpasswd\nauthentication_domain TXTController.local\nrun_as_user ROBOPro<\/pre><\/div>\n\n\n\n<h4> How to change the deamon start up command file?<\/h4>\n\n\n\n<p>For changing the start up command file you will need to logon as root. <br>And go to the <code>\/etc\/int.d\/civetweb_txt<\/code>.<br>Make a copy of the original one!<\/p>\n\n\n\n<ul><li>Change the directory for the configuration file: <code>\/opt\/knobloch<\/code><br>line 5:<br><code>--exec \/usr\/bin\/civetweb <\/code><strong><em><code>\/opt\/knobloch<\/code><\/em><\/strong><code>\/civetweb.conf<\/code><\/li><li>Optional: <br>Change the directory for the executable file: <code>\/opt\/knobloch<\/code><br>line 5<br><code>--exec  &lt;strong&gt;&lt;em&gt;\/opt\/knobloch&lt;\/em&gt;&lt;\/strong&gt;\/civetweb \/opt\/knobloch\/civetweb.conf<\/code> <br>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. <\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;languageLabel&quot;:&quot;file&quot;,&quot;fileName&quot;:&quot;civetweb_txt (modified)&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">#!\/bin\/sh\nstart() {\n\t\tprintf &quot;Starting civetweb: &quot;\n\t\tstart-stop-daemon -S -q -m -b -p \/var\/run\/civetweb.pid \\\n\t\t\t--exec \/usr\/bin\/civetweb \/opt\/knobloch\/civetweb.conf\n\t\t[ $? = 0 ] &amp;&amp; echo &quot;OK&quot; || echo &quot;FAIL&quot;\n}\nstop() {\n\t\tprintf &quot;Stopping civetweb: &quot;\n\t\tstart-stop-daemon -K -q -p \/var\/run\/civetweb.pid\n\t\t[ $? = 0 ] &amp;&amp; echo &quot;OK&quot; || echo &quot;FAIL&quot;\n}\nrestart() {\n\t\tstop\n\t\tstart\n}\ncase &quot;$1&quot; in\nstart)\n\tstart\n\t;;\nstop)\n\tstop\n\t;;\nrestart|reload)\n\trestart\n\t;;\n*)\n\techo &quot;Usage: $0 {start|stop|restart}&quot;\n\texit 1\n\tesac\n\texit $?<\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I describe in this post how the on the TXT-controller installed CivetWeb server could be used as normal general purpose web server and can also interact with the actuators and sensor. In this post will be describe how this can be implemented by modifying some files on the TXT. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"categories":[12,6,11,7],"tags":[51,14,49,16,50,46,52,47,17,45],"post_folder":[],"_links":{"self":[{"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/posts\/467"}],"collection":[{"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=467"}],"version-history":[{"count":1,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":795,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions\/795"}],"wp:attachment":[{"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467"},{"taxonomy":"post_folder","embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Fpost_folder&post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}