 Okay, this is second part to looking at Busy's Box's HTTPD web server. I hope that you watched last week's video or we said just a basic server today. We're actually going to start working with server-side scripting. So if you want to create certain scripts such as bash scripts or Python scripts or really any scripting or even languages that aren't scripting languages, you can run pretty much any program and output the output of that program as HTML to create GUIs for your whatever scripts. So again, last week we created a folder called www on my Raspberry Pi. I'm going to go into there and we have one file in there which is an HTML file. Now by default, unless you tell it otherwise, we're going to use another folder within what would be your web server's root folder which is this folder here and that folder will be a CGI-bin and that's where you'll place any server-side scripts. Now you can change this in a configuration file which we will talk about in a future video but by default all your scripts can go in there so CGI-bin and we're going to go into there, actually let's just use Vim and it's going in there and we'll just say inside that folder let's create a folder called my.sh and let's create a shell script and I will say bin bash because I want to be a bash script although you know make sure there is bash on your system. A lot of cases where you might be using busy boxes HTTPD will be on lighter weight systems such as ARM devices, phones and routers which could have bash on them a lot of times they don't so you may want to use the standard sh which in this particular case is not going to make a difference so I'll just do that but you can use bash or whatever script interpreter you want just as long as it's installed on the system. Now let's go ahead and say echo and again we'll say hello world now save that and we will make it executable by changing mod plus x so now it's executable I can run that script right here in my shell and you can see it outputs hello world okay great so you think at this point oh I'll just go in and run that on my server so we'll start up the server like we did last time with busybox HTTPD whatever port in this case for 8080 and we'll say foreground make a verbose and we'll say the home directory is the current directory we're in but it's nice to have that there in case we're accidentally in a different directory we can hit enter and at this point I can go to my web browser I can type in the IP address of my server and if I hit enter we're gonna get you know there's no index file so it's gonna say 404 error there but what I can say at this point is forward slash CGI dash bin forward slash and the name of our script which I already forgot I think it's my dot sh we'll hit enter and you realize there's no output and no errors why is that well although our script is running it didn't output everything that the web browser is looking for so what we need to do is we need to give just two commands at the beginning of our script so let's go ahead and kill our web server down here and go back into our script so I'm gonna again use Vim as my text there but use whatever text there you feel comfortable with and before hello world before at the beginning of any script or program that you're running you're gonna want to type in echo and we're gonna say content dash type colon text HTML this is telling the web browser you know okay this is a text HTML file without that doesn't know what to do with it so it's it's not going to be displaying it properly and then echo with nothing there just two quotes because it needs to have the web browser is looking for this and then an empty line and then after that it will start printing out whatever output the script output so we will save that run our web server again start up our web server I'll come up here and hit f5 and there we go we have hello world so it's working great so control C to kill our server and I'll Vim back into our script and I'll add another line I'll say echo this is a test now if I was to run this script from our shell here everything looks good it outputs you know our our content type and the empty line that it needs after that and then we have our hello world and test now those of you who are familiar with HTML even a little bit you probably know what's already going to be wrong with this when you run this is that HTML web browsers HTML by default ignores white spaces and new lines it has tags for that sort of thing so if we come up here and hit f5 it outputs the information it says hello world and this is a test but all on one line rather than two lines and if we look at the source code inside our web browser you can see it is two lines it's just not designed to be displayed like that in a web browser so what all we have to do is add a line break in there so coming back down here and killing my server and go and again you can have two shells open you don't have to kill the server each time that's just what I'm doing I'm gonna come in here and I can do this I can say put a tag for line break you know less than BR greater than I can save that start up our server again hit f5 and there they are on this two different lines now the thing about this is if we can also you know save room in our code and actually do all this whoops in one command doing it like this will I'll do the same thing so see I'm refreshing and it's outputting the same so let's now start running some actual commands besides just an echo command so I kill our server here and go Vim into our shell script here and I will add in let's say we want to display the date and I can just say date because that's the date command will probably want to put a new line or how about a horizontal break in here so we'll say HR which will give us a horizontal line break okay so we'll do that and oops and we will now bring up our web browser again start up our web server f5 that and we got hello world this is a test and we got the date output there and so again you can generate any type of HTML you want you can create buttons you know headers whatever just by adding tags let's say we wanted to to add some sort of tag and make that that date larger we can make it a header tag which isn't really necessary best way to do that but it's what I'm going to do so what I can do here is I can say okay echo h1 tag and then after the date command I can say echo or slash close the h1 tag save that start our server up refresh up here and there you can see the date is larger now so again any type of HTML output which can be you know colors font size different types of fonts buttons I frames tables cells any of that stuff so you can create any type of HTML GUI for any type of program or script this way because you can call you can run any type of script or call any type of binary file that you have permission for right here and just remember to put your new lines where you need them and format it as you would an HTML document so let's control C to kill that and go ahead and here again and we'll say okay date and let's say we want to know a little bit more about the system we can say you name dash a and again if we run this script from the shell we get the output you know we have the HTML tags here and of course you could I'm manually putting the HTML tags there are cases where you'll generate them based on the output of your script but right here you can see the output gives the date and time and we also have information on the system itself which will be displayed up here once I run our web server again using the same command and we'll hit F5 up here and there we go we have this now we didn't have to put a new line break because headers the h1 tag already puts a new line break so that automatically is on the line and that's it that's it for for basic scripts but as you can see you can run anything and again well I want to point out that this actually that isn't just it I do need to explain something very important about this one if any of your scripts are going to get any type of input you definitely want to be careful about that as with any server and we may get into that probably in a future tutorial but remember that when I'm starting busy backbox as I am right here it's running as whatever user is starting the server so in this particular case it's running it as pie which is a regular user and has access to that users files among other things so you probably want to create a special user just for your web server when you run something like a patch it's actually running as a www-data user at least in that group because the shell script is running at so if you were to run this script let's say you were to use sudo or run login as root it will be running with those privileges which could be very bad if you're allowing you input and in most cases should not be allowed another certain cases where you will actually be doing that but you'll take other safety precautions but the way you tell it you either run it as that user or you can use the dash you option dash you and then type in the user name so user let's say the user name was Bob I don't have a Bob user on here so probably an area so no no user group name Bob but you would want to use that dash you to say what user you will be starting busy boxes HTTP D as but without that it's starting as whatever user is starting up that server which it can be useful in certain cases especially if you're gonna be creating user interfaces for your system I gave a quick example of that is the distribution slit as fun pronouncing that properly I've talked about many a time is a very lightweight user interface and they have basically their control panel is a web interface using busy box and it is running pretty short well as some user would privileges since it's probably route or something along those lines which sounds dangerous and can be but you know what they do and as something I'll go over in a future toriel is setting it as a loop back only meaning the only person that will be able to access the web server is the computer itself so you definitely would still have a concern of users on the system gaining access to something in that particular case although it's hopefully we password protected but no other computer should be able to connect to the server in that case that's something I'll go over in a future tutorial and that's a very common used technique is to start up a web server for a lot of programs and apps nowadays you just don't really realize that you think that their local apps which they are but they're actually running through a web server either like this or something designed by the developers themselves so that's quick look we're gonna be looking at more of HTTP D busy boxes a web server here in the coming weeks and I hope that you're enjoying these tutorials and again this very very lightweight small but still a very powerful web server and it and busy box itself is under a couple megabytes it isn't very big at all and this is just a small part of it and again already on probably your phone or router in many cases and other devices like that and I love lightweight things I love playing around I love the power of this tool so I hope you enjoyed this if you like this video give it a thumbs up so that I know that you enjoyed this topic be sure to visit my website filmsbychrist.com that's Chris the K there should be a link in the description as always I hope that you have a great day if you enjoy my tutorials and would like to see more please think about contributing to my patreon account at patreon.com forward slash metal x 1000