 As I mentioned in last week's video, I quickly went over three different options for lightweight web browsers. Obviously, there are fuller ones out there such as Apache and others, but if you want a quick and simple setup for a web server with software that is probably already installed on your system, there are a few options. Today, we're going to be looking at Busybox's HTTPD. Again, Busybox is a shell environment that has a bunch of tools already built into it and it's on many systems and especially lighter weight systems. Last week I said it's on pretty much every system and then this week I went to do a tutorial using a Raspberry Pi as a setup and I go to use it and Busybox is not installed, although it's in the repositories, so forgive me for that little thing I said that wasn't really true but it will be on most systems and again especially lightweight systems which is probably what you're going to be using this on if you're going to use it. Now, I am logged into a Raspberry Pi here running Raspbian. It's a besides installing Vim in Busybox, it's the default install and I'm just SSH'd into it, so let's go ahead and start setting up a little web server. Now you can use any folder you want, I'm in the home directory for the user Pi right now. I'm going to make directory for all my web stuff, so I'm just going to create a directory, call it www but you can call it whatever you'd like and I'll move into that directory and I will use Vim or whatever text area you like. I'll create a index.html file and we'll create an extremely simple hello world file and we'll save that. Now we can use Busybox, let's real quick as I said I installed Busybox using the command sudo aptitude install Busybox if I could type today. That's the command, I already have it installed but if you didn't it takes like 10 or 15 seconds for it to download and install it. So I'm just going to kill that because I already have it installed. I'll clear the screen here and now that we have it installed let's check it out because Busybox can be compiled with different components but if you have a full version of Busybox it's going to have a lot of tools in it and if you just type Busybox it gives you all that information. You can see all these tools built into it and they're alphabetical so if we looked at h right here we have httpd so if you have that you're good to go. We can now set up our web server. I can just type in Busybox httpd and that's the command for that server and let's tell it well by default it's going to use the current directory and the current user and port 80. If I go to do that right now it's going to give me a permission denied and that's because most systems won't allow a regular user to use port 80. Now there's ways around this giving different users permission to use that but for this I'm just going to set up a different port. So I'm going to type in the same thing, Busybox httpd. I'm going to do stash-p and I'm just going to use a higher port. I'll just use 8080. I'll hit enter and our web server is now up and running on port 8080. If I do ifconfig I can see that the IP address for this server is 192.168.1.115. So if I go to my web browser and I type in that IP address along with colon 8080 or whatever port you choose you're good to go you can hit enter. If you have it running on port 80 you don't have to tell your web browser what port it is. So I'll hit enter there and right away it says hello world because it knows that there's an index file in there and it uses that index. Now if we were to rename or move that index file to, we'll just say my.html. It still exists but if we go up here and refresh it says file not found. So take into account as I said last week by default httpd is not going to create a directory index for you. Although you can do that with scripting which is something we'll get into possibly in the future but it will automatically look for an index or you can tell it forward slash and the name of the file my.html. There it is. So either use an index to point to different files or you give it the full URL and that's the same with pretty much all web servers unless you have it set up to give you a directory index. Now how do we kill our server? You notice that it's no longer running in the shell down here. Let me bring this up like this. It's by default busy boxes, httpd gets thrown into the background as a name and so it's running as a background process. If you type in ps, ux and hit enter, you can see right here that it's running. So I can grab its PID, its process ID and just type in kill and its process ID. And now it's killed. If I go back to my web browser here and I try refreshing, it's going to tell me that the web page is not available because the server is turned off. So that's one way that's, you know, the basic, basic functionality of this. You know, all we did, the only thing out of the defaults is that we changed the port. So let's give it another option here and let's do dash f and hit enter. What this does is it prevents it from going into the background. As you can see, we can no longer use the shell here because it's running. So I can go back to our web browser and hit f5 to refresh and there we go. We have our hello world file. So I will now come back down here and since it's running in this shell, I can hit control C to kill it and hit f5 up here. And you can see now it's gone because I killed it down there. So by default, it's going to go into the background and let's use the dash f option, which will keep it in the foreground, f for foreground. And in that case, you can just use control C to kill it. Now, another benefit of using the foreground is you can also add to that dash v, which gives it the verbose mode or I always have trolls saying that. Basically, it gives you a lot more output. So hit enter. And now if I hit f5 up here, you can see it tells me that we were connected. It tells what computer connected. So the server ends in 115, but it's saying here that the computer at 192.168.1.150 is connecting. And by default, you can see here response is 200. 200 means good output. So I mean it served up the web page OK. So every time I hit f5 up here, it's going to give us a little bit of output there. You also notice it's giving a port number here. Even though we're connecting to the server on port 8080, there's other interactions with other ports going on here, basically where it's returning stuff to. Not going to get into that too much. Just know that 200 means it's served up OK. 400, I forget what that means, but we all know what a 404 is. If I was to type in the name of a URL that does not exist and hit enter, you can see we get a 404 here. So you are getting some sort of output with that verbose turned on. So you can see real time if there's any problems. It's good for troubleshooting. Again, since we're in the foreground here, I can come back down here and hit Control C. And if I come back up here and hit f5, instead of getting a 404 error, we're going to get this web page is not available because the server is down. One more thing I'd like to go over today, and we are going to go over more stuff with HTTP in the coming weeks, is that, as I said, by default, it uses whatever directory you are in. So we want to be able to tell it what folder to use, sometimes in cases where we're not necessarily in that folder. Because if I was to go back to my home directory here and run that command, well, now it's running in that directory. And if I try up here, you can see I'm getting a file not found for that. But I'm also getting a file not found for my .html, because it's no longer looking in the proper directory. So how can we tell it to use a certain directory, regardless of where we are when we start Busybox? Well, we'll hit Control C to kill our server there. What we can do is we can do dash h and we can tell it, well, I want you to always run this folder here and give it whatever folder you want. So you can be in any directory on the system, run this, and it will always, this is the root directory for your web server. So I can come back up here, hit F5, and there's our hello world. So now these are just some very basic options we got over today. The three servers we're going to be looking at in the coming weeks. Busybox's HTTPD is my favorite by far, although there are some other benefits of some of the other options out there. But there's a lot more to this, and it's a nice little lightweight tool that, again, you probably already have installed on your system. If not, you will be able to install it. And again, a lot of devices, routers, phones, and things such as that nature, probably have a version of Busybox on it. And even if they don't have the HTTPD version in there, you can always compile your own and replace the one that's on that system, allowing you to run a basic web server on pretty much any device, as long as you can get a shell and root access, preferably in case you need to do some advanced stuff. So again, let's review Busybox, HTTPD, and then whatever ports you want. You need special permission if you want to just use port 80, which is the default web server port. Dash F is foreground. You can also do dash V along with that for verbose mode. And dash H is for your home or the root directory of the web server. So whatever you put after that will be the root directory for the web server. And that's it. I hope you enjoyed the tutorial. I hope you subscribe. Check out the video next week. If you like this topic, be sure to give the video a like. That helps me out and also allows me to know what you guys are enjoying. And as always, share the video. I would appreciate that. And please visit filmsbychrist.com. That's Chris of the K. There should be a link in the description to that. And it's, 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 metalx1000. OK, this is second part to looking at Busybox'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 language, you can run pretty much any program and output of that program as HTML to create GUIs for your whatever scripts. So again, we last week, we created a folder called www on my Raspberry Pi. I'm going to go into there and we have one file on there, which is an HTML file. Now by default, unless you tell it otherwise, you we're going to use another folder within what would be your web servers root folder, which is this folder here. And that folder will be a CGI dash 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 dash bin. And we're going to go into there. Actually, let's just use them and step going in there. And we'll just say inside that folder. Let's create a folder called my.sh. And we'll create a shell script. And I will say bin bash because I want to get bash script. Although, you know, make sure there is bash on your system. A lot of cases where you might be using busy boxes, HCTPD 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'll 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. OK, 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, port 8080. And we'll say foreground, make it 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, there's no index file. So it's going to 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.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 going to, again, use Vim as my text editor, but use whatever text editor you feel comfortable with. And before Hello World, before at the beginning of any script or program that you're running, you're going to want to type in echo. And we're going to say content dash type colon text HTML. This is telling the web browser, OK, this is a text HTML file. Without that, it doesn't know what to do with it. So 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 outputs. So we will save that, run our web server again, start up our web server, and 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 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 all we have to do is add a line break in there. So coming back down here and killing my server, I'm going to go and again, you can have two shells open. You don't have to kill the server each time. What I'm doing, I'm going to come in here and I can do this. I can say, put a tag for line break. Less than BR, greater than. I can save that, start up our server again, hit F5, and there they are on the two different lines. Now, the good thing about this is if we can also save room in our code and actually do all this 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, I'm going to 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. I 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 of 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, headers, whatever, just by adding tags. So let's say we wanted to add some sort of tag and make that date larger. We can make it a header tag, which isn't really necessarily the 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 colors, font size, different types of fonts, buttons, eye 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 in HTML documents. 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 uname-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 can, 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 another line. And that's it, that's it 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 gonna get any type of input, you definitely wanna be careful about that as with any server. And we may get into that to 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 Pi, which is a regular user. And has access to that user's files, among other things. So you probably wanna create a special user just for your web server. When you run something like Apache, it's actually running as a www-data user, or at least in that group. Cause the shell script is running out. 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. Now there are 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 U option, dash U, 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 again error, yeah. So no user group name Bob, but you would want to use that dash U to say, what user you will be starting busybox's HTTP 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 you a quick example of that is the distribution slit as, if I'm pronouncing that properly, I've talked about many times, it's a very lightweight user interface, and they have basically their control panel is a web interface using busybox, and it is running pretty short. Well, as some user would privilege is, since it's probably root or something along those lines, which sounds dangerous and can be, but what they do, and that's something I'll go over in a future tutorial, is setting it as a loopback 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 only 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 they're 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 a quick look. We're gonna be looking at more of HTTPD, busyboxes, 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 busybox itself is under a couple of 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 and I love the power of this tool. So I hope you enjoyed this. If you liked this video, give it a thumbs up so that I know that you enjoyed this topic. Be sure to visit my website filmsbychris.com. That's Chris the K. There should be a link in the description. As always, I hope that you have a great day. Okay. If you enjoy my tutorials and would like to see more, please think about contributing to my Patreon account at patreon.com forward slash metalx1000. Okay, we're continuing with our series on setting up simple web servers. And we've been looking at using busybox and it's built in HTTPD. And we're gonna continue looking at that. We're gonna actually work on permissions kind of on this little tutorial here with config files. We're going to create a config file that has the information for our server, including allow and denies and username and passwords. So let's go ahead and the server here, this Raspberry Pi that I'm logged into, I have set up a folder called www in my home directory of Pi. And we've been starting it up by saying busybox, HTTPD saying use busybox and it's built in tool HTTPD. And we're gonna say dash P and we're gonna give it a port, whatever port you want as long as that user has permission for that port, I'm gonna go 8080. We're gonna say F and V for force it to go into the foreground and give it lots of information using verbose mode. And then we wanna tell it dash H for whatever is gonna be the root directory of our web server, which in this case is home pi www. We'll hit enter there, our server is started. Let's bring up our web browser here, the IP address for my server. That's changed since last time. Sorry for recording these tutorials because I didn't set up a static IP for it, but I'm just gonna navigate to its IP address tell it colon 8080 because it's we're running on port 8080. And we don't have an index file if you've been following these tutorials, but we did create a file called my.html I'll hit enter. And there it is, it says hello world. You can see in our shell here that we have a response of 200, which means it's delivered up the file all right. Okay, so that's our basic example there. So let's come down here and control C to kill that. And what we're gonna do now is we're gonna start creating a config file. I'll say vim, I'll call it my.config This can be called wherever you want because we're gonna tell it in our command to look at that. So we'll create that. And we're gonna create a line here. The first line will say h colon and that's going to be whatever the root directory of our server is, which as we just stated was home pi www. So this will say no matter where we're starting, if we're looking at this config file, this will be the home directory that we're working in. And as you create a config file, you can comment outlines using a pound symbol, the number symbol, if you would like to comment something out instead of having to delete the line. So we'll save that and we'll run our last command, but instead of telling our home directory, what we're gonna do is we're gonna say C and we're gonna say the name of our config file. We'll hit enter here and we will bring up our web browser again and if I hit F5 now, you see it's served it up, no problem. It is working the same. So this way you can use a config file without having to give the home directory big whoopee. It's not a big deal. Things you wanna think about though at this point, if we kill our server here, is you may wanna give the full path of your config file, that way no matter where you are when you're starting it, it will find it okay, because it found out I put the name of the file because it's in the folder I'm in, but doing it like so, you can be in any folder on the system and it will use that config file again. If I F5 up here, it refreshed real quick. Hello world, you can see that it was served up and which computer was requesting that. So you also know who's accessing your server. Let's add to our config file here. We will vim my config and we'll add a line, we'll add two lines actually, A and D. A will be allow and D will be deny. So with D, we can say okay, I don't want, actually before we have this allow, we're gonna say 192.168.1.150. That's my computer that I'm working on now that I'm connecting to that server with. So we're saying deny that IP address. So that computer from that IP address will not be allowed to connect to this server. Alternatively, you can also say a asterisk symbol that says deny access to everybody. Don't let anybody connect to this server. Well, what good is that? Well, that's why we have this allow. So now you can give a list of IP addresses that you do wanna allow. So if you only want certain computers to be able to access this web server, you can use this allow. Now remember, in a lot of cases, people can fake IP addresses, but here's a case that we're going to use. We're gonna say 127.0.0.1 and that's itself. That's local host. If you're not familiar with servers and how they dish out IP addresses, 127.0.0.1 is set aside for yourself. That's how you loop back to yourself. Lots of times you might type into a browser local host to get that. And that's only if your computer is set up to redirect local host to that and that's your loop back device. In fact, if I save that, if I type in if config to look at my network settings, you see that you have this loop back device right here, LO and that's your local loop back and you can see right here, it's 127.0.0.1 and that's basically a virtual network device. So you're looping back to yourself without having to use your wifi or your ethernet. So even if you don't have those connected, you can still loop back to yourself. So going back to our config file, we're saying don't let anybody in unless it's this IP address. So what this is saying is only allow the server to connect to itself. And this again, as I mentioned briefly in previous tutorial, commonly used with a lot of application nowadays and it just allows you to run these web-based applications locally without having to access any network or external server you're connecting to yourself. So if I was to save this as like that and I was to run my command again using that config file and I was to come into here and I try refreshing this, it's gonna say give me an error of 403 forbidden and you can also see that down here. So you can have a list of, excuse me, of computers that are trying to access that are denied. So you can see if someone's constantly trying to connect. Now, so the server's up and running but denying everybody so I can't connect there just to show you that it is working. I'm going to open up another window here. So down here, this shell is also running on the same Raspberry Pi and I can use my W get command which should be on your system already. And I am going to say local host and I'm gonna say port 8080 and the name of the file I wanna look at is my HTML. And we're gonna say queue for quiet and dash capital O dash. So it's just gonna output that file. And as you can see, it did retrieve it because I am connecting from the server to itself. Now, if you have a problem doing this with local host which in some cases you might, you might have to put in the IP address of 127.0.0.1 and I'll hit enter and you can see it's served up okay. Now again, this server that we're running on, we know the IP address is 192.168.1.121 and if we hit enter now, ah, we didn't get it. Even though we're connecting from that server to itself just as we did in these two commands, it's actually not using that loopback device. It's actually using in this case, my ethernet port and it's going out and coming back in and it's set going whoa, whoa, we don't want this. So this is good using this, the local host or the loopback device should help prevent, I'm pretty sure about this, any packet sniffing because even if you were to say, oh, hey, allow this IP address, it's actually going out to the network and coming back in so anybody on your network could be sniffing that information using the loopback device. The only computer that can sniff that information is the server itself. So much more secure doing that way and again, it helps prevent people from, you know, booting you off the network and changing the IP address or something along those lines, theoretically possible. So that is denying service to all IPs except for the loopback device. Let's take it a step further and allow other people to connect but require usernames and passwords. So I'm going to control C here to kill that out, clear the screen and again, I'm going to go into my config file and I'm going to comment out these lines because I want to be able to connect from the computer on that right now to display this and what we're going to do here is we're going to say forward slash colon and we'll create a username, I'll say Bob, colon and we'll give it a password, we'll say my pass. What this is saying is root directory, user and password. So now if I save this, run our server using that config file and now try to refresh this, you can see it asks for a username and password and I will say what did I say, Bob and I said my pass, enter. And there we go, it's brought up the hello world because I typed in the proper username and password and it saves it so if I refresh, it's still doing that. So actually let's go back into our config file here real quick and change the password to my pass too. Save that, start up our server again now if I refresh, it asks again because the username and password is wrong. So I want to do something here just to demonstrate something I'm going to say Bob and I'm going to type in blah, blah, blah I'm just typing a bunch of stuff. It's not the correct password, I'm going to say login and you can see it gave a response of 401. You weren't able to access it, we didn't get 200 and you can see again it asks for the username and password. Now keep in mind if you're not using security keys as I'm not here, this is being transmitted in plain text which again, since I'm going across the network in this case, anybody on my network sniffing traffic can very easily get this username and password in which case if I was using the loop back which again would only work on the server itself, that would not be the case as far as I know. Because it's using the virtual loop back device rather than your ethernet port. So keep that in mind that even though you're using passwords here, everything is unencrypted and so everybody can see it. Now, speaking of which, another issue here is that our password is in plain text inside our config file and that's not good because if someone gets hold of that file now they know your password. So what we want to do is we want to use hash to hash out our password and we can do this and then if someone was to get access to the config file they could still use that hash to access the server but they still don't know your password so if you were to happen to use the same password on other machines, they won't be able to access those other machines, let's say you use the same password for your Google account, if they did get this hash whether they got it through packet sniffing or getting a hold of the config file they'll be able to access this server but they won't necessarily be able to access you got this stuff because they still don't know your password and even then we're still using hashes so anyway, let me get on to demonstrating that. So we have to generate a hash first. So let's go ahead, kill our server here and the HTTP and busybox has a built in function for doing this, so we're gonna say busybox HTTPD-M and then we're gonna in quotations give our passwords, so here we'll say, again we'll say my pass and we'll say my pass three to give it a new password, we'll hit enter and right there we have our hash. So now we get to go into our config file of them, my config and over here instead of the password you put the hash and then we save it, run our server again using that config file and hopefully we hit F5, we'll ask for the password again we'll say bob and we'll say my pass three enter and we logged in, so much better do that way and it takes one extra step, it's built into HTTPD you just have to generate it and replace it in the config file so that your passwords aren't sitting there in plain text. So also last thing I wanna go over in today's tutorial killing our server here, clearing the screen, going up here, let's clear the screen again, going into our config file again, we're saying slash here that's the root directory you don't have to password everything if you want a password a certain directory you can do so, so in this case I can say slash we'll call a folder private, so I'll do that and I'll make a directory called private and inside that directory I'll say privateindex.html and I'll just say this is my private stuff now if we run our server again using that config file I come up here and I hit F5, you notice it's served it up response 200, gave me my hello world up here without asking for a username and password if I was to try to go into my private directory though and hit enter privateindex.html, hmm oh, I know the problem, I created the folder inside the wrong folder, let's go ahead and make this full screen here, clear this out I created it in my home directory, let's move my private directory onto our server directory which is www, so I just created that in the wrong directory and we can now run our server busybox.htp using that config file, so again the problem was the private folder wasn't on our web server I created in the wrong directory but now that it's there, I can again hit F5 here and there is my private stuff, of course it didn't ask for the username and password because I've already entered it, so let's go ahead and do a better example where it actually asked for the username and password, we're going to say myconfig and I'm just gonna do a plain text password here just to move this along, I'm gonna say mypass4 save that, run our server and again if I go here to my.html, I can view that but if I try to go into the private folder it asks for username and password and I'll say bobmypass4 and there I can see this is my private stuff so things to remember, make sure you actually put the files you're trying to access inside your web server directory that's obviously very important, so that's it I hope that you learned something today, again busybox is on many, many systems out there I kind of said a couple of weeks ago that it's on pretty much every system and that's not true, well it's still on most systems especially again lightweight systems, routers, phones, other small devices and if you have one that has HTTPD installed on it compiled into it, you're all set for having a pretty full web server that can do a lot of things, again remember that it's running as the user that's starting it up unless you tell it otherwise so it has the permissions of that user so if you start it as root, your web server is now running as root and any of the script files it runs at was root, remember that unless you're using security keys, everything's unencrypted so even though you're using usernames and passwords if you're using something other than your loopback device anybody can sniff that traffic and get ahold of that information as well as everything that's being transmitted so I thank you as always for watching I ask that you visit filmsbychrist.com that's Chris the K, there should be a link in the description and as always I hope that you have a great day don't forget to like and subscribe okay, this is an introduction to filmsbychrist.com I'm Chris, that's Chris the K that's me right there, my daughter Ember and my wife Jennifer, we pretty much live in the swamps of Florida I'm a firefighter by day as well as by night we work long hours but that's not why you're here you're here about the videos I put up on YouTube these videos are mainly about computers and programming which means most of my videos look something like this and if that's what you're interested in, great if not, that's all right I do videos on other topics too such as video editing, special effects, photo editing 3D design and music creation if you are one of my viewers and you enjoy my videos my Patreon page is a place where you can go to help support my videos so I ask that you take the time to go to my Patreon page and look at different levels of rewards you can receive for different levels of backing there should be a link in the description of this video if you're watching it on YouTube otherwise you can visit patreon.com forward slash metalx1000 and I thank you for your time and your support have a great day wouldn't it be great if you had just a bunch of old cell phones lying around that you could make phone calls with them even better yet, not using a service out there just using the internet being able to talk to friends or family directly without even setting up a server well that's what we're gonna look at today look at this it's my EPC from like 12 years ago that cost me like five, six hundred bucks one gig of RAM, four gig solid state drive left in it, there used to be a second one for storage but right now I'm running off an SD card I just need a second computer that I can put up here for you to show you guys this thing runs very slow and it gets so hot which is part of the issues with it but today we're gonna be looking at LinFone so LinFone is a SIP application SIP so it's gonna allow you to make phone calls through the internet or through your network now normally you would set up a server or use a service somewhere that's a server but I'm gonna show you today that's very simple if you're on the same network to just directly connect to another computer without a server there's no encryption for this so you wanna be on a private network and stuff like that but this is very useful like sometimes my daughter's in a room we're playing a video game or something and I wanna be able to voice chat with her and there's lots of ways you can do that but this is super simple there's a GUI interface we're gonna look at today but if you guys like this topic I can show you a little bit more about it in the future I don't know a whole lot but I know the basics of setting up a server also connecting to clients outside of your system and there's also a complete shell based version of LinFone to where you can make calls, receive calls, answer calls, all that good stuff right in your terminal so let's go ahead and have a look I'm gonna be running a Debian based system here and let's go ahead and install LinFone so again I'm using a Debian based alive system here running off a flash drive it's anti-X which is just a lightweight Debian based distro and I'm just going to use wrong keyboard pseudo apt install LinFone Enter and then type in the password now again I'm using apt here which is a standard package manager for Debian based systems LinFone is gonna be on pretty much all your major Linux distribution so use whatever package manager whether it's a shell or a GUI package manager and just install LinFone once it's installed you can run it from the shell just by typing LinFone and hitting enter or of course you can go to your menus and select it from your applications so I'm gonna go to my menus here and on this particular one it's under applications it's under network I believe or internet for this distribution and LinFone and it will open up now the GUI opens up but it also puts an icon down in your system tray so if I was to close this GUI it's still gonna be running as a service down here and of course you can bring that up just by clicking on it and it brings the GUI back up so applications like this can get real advanced again if you have a server and it's actually hooked to a phone line you can actually make real phone calls to real cell phones or landlines through this protocol but we're just doing network to network so how does that work so basically when we're in here in the application your phone number is going to be your username at your IP address so on my desktop computer my name is MetalX1000 and my IP address on the local network is 192.168.1.155 so right here in this little bar I type in SIP colon MetalX1000 at 192.168.1.155 and it will show up here and I can choose to either make a video call make a regular call or even send text messages so right now I'm gonna click this call button and I have Lin phone running in the background on my desktop machine and when I click that button I get a phone call so this rings and this rings and then all I have to do is on my desktop click the pick up button and as long as you have your microphone and speaker set up properly you are now in a voice conversation now again there was a video option and there's also a texting option and again we're connecting directly if you go through a server you have an option to set up encryption and you'll have logins and passwords for users but I'm just connecting directly so there's no encryption and you can see that if you look at the application there's a red lock icon that is unlocked letting you know that basically anybody on your network can be hearing what you're saying obviously it's not just magic they're not just everybody's gonna all sudden hear what you're saying but if they're sniffing your network and SIP this is the same if you're in an office environment and you have a network of phones this is running on the same protocol in fact over a decade ago where I work they got network phones and they put them on the same network as all the other computers and I was able to sniff traffic and using wire shark I was able to hear both sides of the conversation would record them as separate wave files so that's something to think about but again I'm on a closed encrypted network with my family and this is just I'm using it to connect to my daughter's room sometimes to talk to her or my son if we're playing video games but you can set up a network a server with encryption and you can also set up an account elsewhere such as LinFone has a website where you can set up a free account now you can also get a LinFone app of course for an open source for your phone it's available in FDROID and you can do the same exact thing as long as you're on the same network you put in the IP address their username you know SIP colon username at an IP address and of course it puts it into your recent call history so you don't have to type that every time you can just go to your history also on your phone you can grant it access to your contacts and once it does that if you have a SIP information for them in their contacts you can use that to contact people and of course video I can show you the video the EPC here is so slow it's very jerky so it isn't a very good demonstration of that but if you're interested in this I can definitely do more on this topic later again setting up your own server which I just know enough to get a server up and running or accessing the lin phone creating an account on lin phone and getting that setup on your phone because it took me a little bit to figure that out how to do that it's not that hard although I recommend setting up your account on your computer because on the app on the phone it really wants you to enter a phone number to create an account but if you do it on your desktop or laptop you don't have to and then you can access it on your phone and also again video chat, texting and once you set up a server then you can link to this from outside your network but if you're going to do that you may also want to look into using a server such as lin phone so real quick as an example here so when you're running lin phone on an Android device it's going to be running in the background as a service there's a little icon up in your system tray here if that's what it's called on the phone I forget but I'm going to call myself from my desktop to my phone so I click that it comes up and it uses the ring tone that I use for my regular phone calls I can answer and then I can just talk and again we can do video and texting that way as well so a few more examples again here's my laptop here's my phone I'm going to call my phone from my desktop which is up here out of view so I'm going to call that my phone's going to ring I'm going to answer it so now I'm in a conversation that way now on the laptop I'm going to call my desktop and my desktop's ringing and I get this on the screen when I pick it up what's fun here if I switch my phone over speaker mode I'm on hold and it plays hold music for you which is pretty cool and of course you can do conference calling too so I'm going to click this button up here that says start conference call there's also a start open a conference which has a little text bubble but I'm going to do the one with the phone just like before I put in the username, at and their IP address and then I add them I redid that for my cell phone now I'll do that for the laptop that we're demoing things on and I'll have to do is click start and both my laptop and my phone are ringing I can answer here and I can answer here and now we are on a conference call you can also transfer calls and do everything that you would do you know with the stand oh the phone call is still going on okay I hung up on all three devices but yeah this is just like you know a phone you would have in an office and if you had a phone on your system you know on your network that is a SIP phone a voice over IP phone there's a good chance one that it's running Linux and it's using a SIP protocol so this is something very interesting to use it's something that I've played around it within the past but haven't really gotten into and I've just been playing around with it lately so if you're interested in more of this stuff I just showed a basic overview of some of the stuff you can do with the basic GUI I hope that all made sense to you but if you are interested I can again do the same thing using just shell which is nice because it's also helpful like if my daughter is on her computer I can log in and start up a Linux phone and answer it and start talking to her even if she doesn't answer even though she's just a room over and then also I can show the very basics of just getting a server up and running that's as far as I got is setting up a few accounts and logging in and then also setting up an account on a Linux phone that's free to set up an account and then you can like my kids both have cell phones that they use when we're on vacations mainly as cameras but if they're on Wi-Fi they can call me or text me which is pretty cool even though they don't have a cellular service that is using some of my old phones so let me know comment below let me know what parts of that sound interesting to you if this is something you're interested in and if a lot of people are interested in I will do some more videos on this so thanks for watching visit filmsbychrist.com that's Chris the K also check out my Patreon page patreon.com slash metalx1000 if you're looking to support me and as always I just hope that you have a great day okay here we are again with you looking down on me from up above today we're going to be looking at something similar to what I did a couple of weeks ago in a video we talked about Netcat or NC or NCAT slightly different things all kind of do the same thing but I mentioned a few times in that video and I've had a few comments asking about doing something like that encrypted which is what we're going to look at today but what we're going to use is called Socat which is basically kind of like Netcat but it has encryption options I'm going to show you some very basic aspects of it I do want to start off by saying is that a lot of what you may want to do at least for personal stuff if you want to do something secure across the network just use SSH SSHN you can transmit stuff you can do anything you want through SSH I understand there's going to be cases where you can't do that you don't want to create accounts for everybody you know if you're creating an app you just want it to be able to connect with encryption keys so we're going to look at some simple stuff today basically doing some similar stuff that we did last time we're going to get like a shell going remotely but let's go ahead and jump right in so yeah you're going to have to have Socat installed and we're also going to be using OpenSSL to generate some keys so use your package manager should be in your repositories and also the notes for all this are up on Payspin check out the links in the description I'm going to go over things fairly briefly here you know I'm going to do a lot of copy and pasting because it's a lot of typing but again the notes are in the description of this video now looking at the screen here I have two different machines here the top up here that says Fort is going to be our server and that's actually on my old ThinkPad that I do use as a server to backup files to which is on the other side of the room over there and then Chip the bottom part of the screen here is my local my new ThinkPad that I use as my main computer Fort and Chip are actually both references to Punisher Comics you may get those references you probably won't anyway here we go so first thing we need to do is generate keys for both our server and clients so up in our server here we're going to use OpenSSH we're going to use OpenSSH GenRSA that's the type of key we're going to be generating the output I'm going to just create a file in the current directory called server.key and it's going to be two hundred or two thousand forty eight bits okay um... you're going to want to store this somewhere on your system if you're going to use it more than once I'm just doing it in this temporary directory because I'm just doing it for this video uh... but create that generate it save it someplace that you're going to be able to access it okay now we're going to take that and we're going to generate a certificate with it again here we're going to require a new key so you can look at all the stuff in the man file basically we're saying create a key it's not going to expire for uh... three hundred sixty five three days so it's going to last for a long long time uh... and so we're going to take the key that we generated here and we're going to create the certificate boom now it's going to ask you a number of things you can leave all these blank except for one when I first tried doing this it messed me up because I skipped through all of them but what we want to do is we want to click through them you can again fill in this information you want until you get to common name you need to fill this out and it needs to either be the IP address of the machine you're generating the key on or the domain name whichever you're going to use to connect to it so uh... I'm just going to use the IP address which on my local network this one is one nine two dot one six eight dot one dot one fifty leave the email address blanks now I can list it out I have a key I have a certificate let's go ahead and from there what we're going to do is we're going to cap both those files into a new file so we have server key server certificate and we're going to put it in the uh... uh... PME file and these are all just plain text files so I can actually at this point cat out server dot PME and will actually show us the key I'll make it full screen here so we have our key our key our private key and our certificate okay I need to put that on the client machine as well so all I have to do in this case again I'll make that full screen I'll make my terminal now if I'm connected to SSH so I can transfer this file over but since it's not very long it's just plain text I'm going to copy it I'm going to come down here I'm going to say cat into server dot PME or PEM uh... and then I will paste that information in there and control the or you can use Vim or whatever text editor but I've shown you in the past that you can just use cat as text editor so now let me zoom back in here I have that file on my client down here at the bottom and I can cat it out as long as I copied everything properly it's good to go but now we also want to make sure that the permissions are set properly on this so we're going to use change mod six hundred on both our key and our PEM file PEM PEM file and this is just saying basically you don't want other people on the system to be able to read or edit this file uh... you don't want them to have access to it all and uh... so we're going to use six hundred which I believe will give you you know uh... read permission to it but it will uh... actually let's just list out here real quick uh... you have read write to it but it's not executable and no one else can read it so we generated our keys for the server we're gonna do the same exact thing for the client so here we go we're gonna generate the key now we're gonna generate the certificate this time i'm gonna call it uh... client key and client certificate again click through these and then when i get here i'll put in my IP address which is that okay and then we will cap those into this file we will then change the permissions for it and now i'm going to cat out that client PEM file there we go and since that's my local machine again i could zoom out and copy it or i can use something like x-clip so now it's in my clipboard and up here i can say cat into client dot PEM i can now paste that file and then i'll hit control D and you can even see just checking the last line of it i copy the right thing so i got that copied over we both have certificates now we're ready to roll we have certificates created and shared and sharing it's always the hardest part i don't know if i said this earlier in the video it's like how do you encrypt something and pass the key to somebody without somebody else getting it if you want everything to private i mean there's public and private keys but you need to share things at certain ways it's it's uh it can be confusing it can be difficult so i'm just sharing things through ssh here so when i'm transferring that stuff it's all encrypted anyway uh but yeah you have to transfer those somehow protected okay now we're going to start using so cat so so far all we've done is generate keys which can be used for lots of different things encrypting files encrypting anything right so we're going to use so cat and we're going to say open ssl because we're that's the type of key we're using uh and oh you know i'm copying the client's information into the server we don't want that we're going to say so cat open ssl dash listen we're going to give it a port here i'm just going to use four four three uh we're going to use reuse address at ipv4 and fork so reuse address just as basically if you read the man file it's telling you that the server is able to restart right away and fork will allow you to so basically when i connect it allows other clients to connect while i'm connected and when i disconnect the server keeps running okay now we're going to say the certificate for the the server the machine i'm on and the client okay and then here i'm just saying dash that means anything that comes in just show it to standard output so we'll display on the screen so we're just going to be sending messages back and forth so i'll start that up and now down here and again all this is in the notes in the description on pay spin i am going to again so cat open ssl now i just need to put in the ip address or domain name if i have a domain name for the server and 50 uh and the port number verify zero not really sure what that means i should look that up but that's just examples that i learned from that's what they did now again the certificate is going to be the one for the current machine and then the ca file is going to be the one for the server machine the remote machine and then again we're going to do just the dash saying standard outputs now i hit that now i can start typing stuff i can say hello and they can then up here it oops up here i can say hey buddy so we are messaging back and forth using encryption so these are all the commands once you have the keys generated these are the commands to start up a server and these are the commands to connect to that server if i come down here i can split this screen let me go ahead and copy and paste this exact same command down here just to show you i'm going to connect to the server again now i have two clients connected to the same server uh and i can say hey pal and that goes to the server uh okay control c to kill out of that and close this window now and kill that with control c but the server's still running but i'll come up here and hit control c so again that's what the fork does it allows it to keep running and allow multiple connections to the server uh okay so what else can we do with this there's lots of different options but uh you can have it execute a command when someone when a client connects and the output can go to that client so for example i can say ex ec so we're going to execute we're going to execute we're going to say bin date so we're saying when a client connects run the date command so if down here i run the same exact command i ran last time i connect it gives me the date and time of the server and then disconnects and the server is still running so i can run it again and get that date and time again so if you needed to synchronize the clocks there's better ways to synchronize your clocks between machines and most things are synchronized uh with the internet now but uh but yeah you can run any command so for example instead of the date command i can just say bash now you have yourself an encrypted remote shell so i can come up here same command for the client and now i can list and i can see the files in here i can type date it will show me the date i can do i don't know what other commands can i do uh if config there we go we got the if config of the server and you don't get the prompt and everything nice like you do if you ssh in but it's running those commands and outputting it to your screen here let's give one more example here uh so what i'm going to do here is i'm going to go back up to this first one where we're just excuse me passing information back and forth i can pipe stuff into my server so uh excuse me again uh i can pipe stuff into the client to go to the server is what i meant so we're going to do this so last time i showed you that uh i could i i think i wrote a uh little program in godot where it tracked my mouse cursor and sent that information well uh xcv if you're on a licks machine running xorg that will show you when you start that up you get this window and uh it will show you whatever keys you're pressing but also when you move the mouse it shows you the coordinates it shows you both the local within that window and also the um the total the the global so i actually have three monitors here so when i'm right here it's showing that uh my uh position is pretty far over uh but go ahead let's go ahead and clear that and what i'm going to do is i'm going to go back to this command here and i'm just going to pipe in xcv and i'm going to pipe that over to the server there something went wrong what did i do wrong here is the server running i didn't start the server there we go now we'll run it and now you can see when i'm doing it here it's sending it to the server up here so this is the server and as i'm moving all that information is being displayed on the server being sent to the server real time i mean instantly boom boom boom boom right uh control q to get out of that or whatever keys you use to close a window uh what i can also do is uh i can also since i'm piping this into stuff i can pipe it into something like grep and i can grep for root colon and i can do that now when i send it it's going to trim out some of that information so it's just giving the line and if i come down here it might be a little bit clearer it's just giving the line with the time and also you can see the coordinates of the mouse cursor something i did try to do uh that didn't work out so great if i came up here if i try to pipe this into cut and i say cut it's a little smaller uh with the colon dash f2 i was thinking that i'd be able to cut just this information here and it works but the cut command is obviously a little slow and there's probably a better option for this because when i do this it does work but you can see it's lagging it's like showing it in chunks and it's not instantaneous so there's gotta be a better way to do that but i'm just showing you that you can pipe things you know from the client into the server and then the output from the server into another process if you need to so yeah so that's so cat in a nutshell again uh check out the links in the description to everything i just did um and again for personal stuff if you're looking for security ssh is awesome for most things you know but so cat is great if you need to do these quick little application things across the network and you want to encrypt it it's just like netcat or ncat or nc but with encryption options you can also use it without the encryption options and it works kind of like netcat but one of the main reasons you would use it is for encryption and here we used open ssl again it supports other types of encryption as well but that's a very commonly used one i do thank you for watching please visit filmsbychrist.com that's chris of the k there is a link in the description and as always uh i hope that you have a great day well last week we were looking at uh setting up a very basic web server using python and uh one thing you couldn't do with that basic setup was have server side scripts running so they were going to be looking at the options they're built into python so if you have python on your system you should be able to do this uh that allow you to not only run a web server but to run a web server uh with server side scripts so first thing you do is you're going to have to create a cgi bin folder uh unless you're going to change the configuration by default all your server side scripts should go inside a folder called cgi bin if they're not in there then they're not going to execute as a as a server side script um so uh you would do make their cgi dash bin i have already created one of those and i've put a couple of scripts in there now to start our server up what we want to do is we want to start up python say dash m to load up the module and we'll say cgi http and this is case sensitive capital s server and also you want to tell it what port again certain ports will be blocked by certain uh by lower permission users so use port that your user is allowed to use i'll just say 8 000 here i'll hit enter and you can see server http on 00000 port 80 so it's running on this computer port i'm sorry port 8 000 now if we look at our web browser we can go to our web server again this is on the local machine so i can type in local host i can type in 127.0.0.1 i can type in um my uh local domain uh using the hostname.local or i can put in my ip address of course is running locally if you're going to be on outside of the local network you'll have to set up port forwarding uh but i know that my ip address is 192.168.1.150 for this current computer and as i said port 80 is what we're using so colon i'm sorry port 8 000 so we're using colon 8 000 so anyone on the local network should be able to type that into their server and they will get greeted with a directory list luckily just like the simple httpd server that python uses there is going to be a automatically generated uh list directory list if there's no index file and of course there's a cgi bin now if i try to click on the cgi bin it's going to give me an error it's not going to give you a directory output a directory list of what's in the cgi bin this is one of the main security things they're put into place because you don't necessarily want people viewing all your scripts because certain scripts may uh you basically just want to be careful with server side scripts because they're actually running on your machine they can manipulate things not only uh as far as the web server goes but could also manipulate things on your system so you want to be very careful using server side scripts so it's going to require you to directly go to a script you created let me open up a new shell here and go into my cgi bin and by the way when you run the server it's using the current directory as the root directory for your web server unless you tell it otherwise and again the cgi bin is where your scripts are going to be i've got a few in here a few bash scripts a couple of python scripts it does not matter what type of script or program it is as long as your computer can run it and you've given it permission to run so let's go ahead and have a look at this hello.sh we say that it's a bash script and we're going to do the output again you're going to have to tell it uh that the first line has to be content type and in this case text slash html and then you have an empty line after that before you start your code and here we're just going to echo out something simple but you could run any program that you want uh so here's a very basic example again if you're running this and for some reason you get this text output and not the actual script output it's because you this you might have put an extra line in there i'll give you an example of that but we have this this file is called hello.sh you have to make it executable with change mod i've already done that but i'll show you change mod plus x and the name of your script running these on your web server is same as running it on your current computer so if i was to run inside my shell here hello.sh you can see the output here first line is this then we have a blank line and then our html code which can be one line but it can be a whole web page as well so let's go ahead and run that up here so to run that up here all we have to now that it's in there and made executable is again the address of the server the port if it's not port 80 if it's port 80 your browser will default to that cgi bin and the name of the script we'll go ahead and hit enter and you can see we've got hello world we can look at the code for that which is just the text output there i can go into that script again and i can add another line i can say echo this is a test and i can give it more html tags if i want i'm not going to here i can save that and if i was to close this and refresh this page you can see now that text is right there but again we can also uh say give it a line break actually we'll give it a horizontal line break there and next i can just run a command if i wanted to list out the files in the current directory i can use the list command uh now do keep in mind that if you want line breaks and things such as that you're going to have to implement the html code for that so it will output the files in this folder um but not necessarily on the new line for each one but let's go ahead and refresh that and you can see the files in this folder um or actually it's giving the files in the main folder i did not expect that um but just keep in mind that things aren't going to be on the new lines you have to implement that you'll put this through a while loop if you want should be able to do something like um while read line do echo dollar sign line and we'll do a line break like that and that should now if i hit f5 put each thing out on new line if we look at the code you can see that they're all on new lines with line breaks again if we didn't have that we just had the list i refresh the code up here you can see everything's on a new line but because we're writing our interface in html you need to have those html codes for the new line very very basic html if you've worked with html before you understand this it's very simple i just wanted to point that out in case someone has never worked with html okay so that's a basic little script we have a lot of echo lines there let's go ahead and look at another script that i called hello2.sh and again the extension .sh means absolutely nothing to the computer just as it means nothing when you're working the shell it means nothing on the web server the extension means nothing the most important thing is of course to have your shebang line which is this first line here saying this is a bash script if you don't have that the the it's going to try to use the default shell which is going to be a problem in some cases with bash scripts if bash is not your your default but if you're using other programming languages like python which we'll get into a minute that's definitely gonna cause problems here's another example i use this dash e here so now i can put these new lines here so it's this is the same original code that we have before it's putting out this line of code and then it's going line break line break so it has an empty line and then it does our html code there so let me go ahead come up here i'll hit two so hello2.sh and you can see that is the output of this file so if you want to put all home online you can if it's something simple like that let's look at another example hello3.sh and here you can see that i am using cat and eof although this doesn't have to be eof eof stands for end of file if you want to have more than one you can label them different things basically what this is saying is everything between this eof until there is a new line that has nothing but eof on it print that out to the screen so i'm doing the same thing here uh you know the context type content type blank line hello world and then i'm also putting in a image here so definitely if you're going to output if you full html page you don't want to echo out each line you can cat it out like this so here's an example we can go three hit enter and there we go we have hello world and the image which is the code down here now things to be careful about if i do this and try running this page again you can see it outputs the text and not uh doesn't output it as an html file because it doesn't realize it's an html file because the first line has to be this followed by a blank line for an html file otherwise it thinks it's just a text file to display and so if you put an extra space in there like that or an extra blank line there like that or anything before that it's it's gonna not work right so if you're gonna be using the cat uh end of file it might be a good idea to pretty much always start your files off like this and that way if we refresh you can see it works no matter what you change inside this main portion of the document it's not going to screw that up so that's another pointer for you so we've worked with some bash scripts here if i list out here in our cga cgi file you can see that i have a couple of python scripts again the extension is for your knowledge not the computer it does not care what the extension is it cares about the shebang line and if i do within hello dot py you can see i have a very basic i have my shebang line which can be written in different ways but as long as you have it and it works on your system this is saying what type of environment to use basically the interpreter we're going to be using python and again if you're using a different version of python all depends on how your server's set up and again same thing i'm printing out the content type a blank line and then my code so html code saying hello world as a header so if i come in here and i change this to dot py hello dot py that's just again because that's the name of the file we'll hit enter you can see it says hello world now i have another python file in here called python two or hello two dot py just to show you similar to the cat and a file we're using three quotation marks here and three quotation marks here everything between that is going to be uh outputted as text so you don't have to do a different print line for each line of your html file if you're going to be generating html file with your server-side scripts so again i put my print line uh for the content type and the blank line these can be done on one line but you want to kind of i would advise doing that separate from the main portion of your web page just to prevent again if you accidentally put an extra line in there or an extra character or something it won't run properly so that's html or that's hello two dot py hit enter and there you go it's displaying an image it says hello world now again as i said it does not matter whether it's a bash file a python script pearl script and any type of script or any program that can run on your computer can be used as a server-side script and that's why you can use html as a GUI for any program and i'm going to show you an example of that um if i go back into my main uh folder here oh i also want to show you if we go back into our main folder here i have a python script here that's executable if i click that you can see it displays it as text it's not inside the cgi file so it's going to run like that um so your server-side scripts have to be inside that cgi bin file now i also have as you can see here a hello world file or a c code which is a very basic has a main function prints out the content type and a new line you can see i have two backslash ends there that's a new line and a blank line and i can print f hello world so what i can do i can come down here i can say gcc that's the compiler i use i can say hello dot c and i can say my output is cgi bin hello and again the extension doesn't matter i'm just going to say dot bin just so i know that that's a a binary file so i just compiled that and if i was to actually cat that out it's a bin uh so i cat out that file you can see it is a binary file it is ac file it is it is compiled so it doesn't matter whether it's a script or if it's a compiled program if it's inside the cgi folder and it has executable writes uh it can run uh so if i come up here and i go back into my cgi bin folder and i say forward slash hello dot bin again the extension the bin part means nothing it's just letting me know that's an executable file i can say dot exe it doesn't matter it's an elix system it's still compiled for linux and i'll hit enter and you can see it says hello from c because that's what the the code was again uh also the the content type that html uh and that blank line that that's for the output uh you don't even need that if you're just running the script let's say you're going to have some code that you want to access through your web server and it does something on the server and you're not going to have any output and that doesn't even really matter very much although you pretty much always have some sort output even if it's just script run complete or whatever um so i hope you enjoyed the tutorial please visit filmsbychrist.com that's chriswithak there should be a link in the description again this is using python as a web server let's go ahead and look at that main script also you can see there was output here every time we access to file just like when we ran servers before what files are being accessed 200 means it was served up properly uh and like if it's 404 you know it's not there 403 is um permissions issue i think that's that's what we were getting there and again the command is python-m and capital cgi https server so cgi http server case sensitive and then what port you want to run it on and when you run that whatever folder you're in it will be running as uh as that as the root directory for your web server and all your scripts will go inside a cgi bin cgi-bin folder uh and also you may be asking yourself let me go inside my cgi bin folder here i'll create a new file i'll call it um who dots i don't even have to put a dot i can say who again the extension doesn't matter and i'll say this is a bin bash script and i'll just say uname-a save that again i have to make it executable or it will not run and you also want to consider permissions to write the stuff you want to make sure that not everyone has permission to write to script files or even that folder because if someone somehow sees uh flaw in one of your scripts to where it can redirect it and write a new file to your cgi bin uh well it can create a new script uh that has the permissions as you're about to see see i did it again we call that who with no extension will hit enter and oh i forgot something you can see there's no output even if i control you to look at the uh the the source code there because we forgot our content type remember if we uh cat out one of our hello dot sh files you can see remember don't forget this i do that quite often if you get no output remember to have those lines so we'll say content type text.html text slash html then a blank line and then our command which can be anything we want we'll hit f5 up here to refresh and you can see that uh all the information about my uh my server here and also actually that's about my server i want to know about myself so let me go back into my profile here and i'll echo out a line break and then i'll just say who am i save that refresh it and you can see it's running as middle x1000 that's another thing to keep in mind that these scripts are running as whatever user you start the server as so if you start the server as root these scripts are going to run as root if you start them as a regular user it's going to have the permissions of that regular user meaning those scripts can modify any scripts that user can run so so right now you know if i write a script it can modify anything in my home directory in the temp directory hopefully my regular user doesn't have permission outside of my home directory beside the temp directory um so keep that in mind you may want to create a especially there's probably a user on your system called well i don't know if it's by default i know once you install something like Apache it's there uh but a www-data user uh that you may want to start your scripts as that user limiting their permissions endless maybe you're making a program that you want to be able to access an interface with certain users files maybe you're making some sort of media center and you want to be able to have permissions to to start up mplayer because a regular you know web user shouldn't have permission to interface with your GUI so all depending on what you're doing just trying to bring that up to keep it in mind security is important whenever you're doing server side scripts um and especially you know you're opening this up to people on your network uh so so password protect stuff be sure you have the right permissions on certain scripts and on certain folders you don't want someone overwriting a script file with their own information that's going to be doing nasty stuff that's just a little word of advice again thank you for watching please visit filmsbychrist.com that's chris the k there should be a link in the description i hope you're enjoying this series on servers and networks and of course next week we'll be continuing with a very basic look at another web server using netcat which you've probably seen before but i'm going to take it a step further than most people will show you so i hope you look forward to that and as always i hope that you have a great day okay this is an introduction to filmsbychrist.com i'm chris that's chris the k that's me right there my daughter ember and my wife jennifer we pretty much live in the swamps of florida i'm a firefighter by day as well as by night we work long hours but that's not why you're here you're here about the videos i put up on youtube these videos are mainly about computers and programming which means most of my videos look something like this and if that's what you're interested in great if not that's all right i do videos on other topics too such as video editing special effects photo editing 3d design and music creation if you are one of my viewers and you enjoy my videos my patreon page is a place where you can go to help support my videos so i asked that you take the time to go to my patreon page and look at different levels of rewards you can receive for different levels of backing there should be a link in the description of this video if you were watching it on youtube otherwise you can visit patreon.com forward slash metalx1000 and i thank you for your time and your support have a great day this month on filmsbychrist we're looking at networks and servers and although i'm going to go over everything i talked about in this video in more detail in future videos this first video is just to give you a taste and go over some basic tools we're going to be using in the coming weeks so we're going to be looking at setting up web servers now if you're going to be really setting up a web server i suggest using something like a patchy that's why i normally use it but there's a bunch of other web servers out there but there are some tools that are probably already on your system that will let you set up a simple web server quick and easy regardless of what version of linux you're running i'm going to talk about three tools a day and they're on almost every linux system out there uh two of them will probably be on even small things like routers and other small devices so first let's look at httpd from busybox busybox is a great tool that is on every version of linux you'll come across including android phones routers and even you know if you can get into the console on something like a tv or other type of device chances are busybox is going to be there and it's going to be the shell that's going to be being used now although busybox can be compiled with different components if you have a full version of busybox it has a bunch of built-in tools tools that you're used to having in the shell all built already into busybox what you need to do is first open up your shell and type in busybox this will give you a list of all commands that are available for your version of busybox and if you're lucky somewhere on that list which is alphabetical you should find one that says httpd if that's available then you're all set for setting up a web server all you have to do now is type in busybox httpd space-p and the port number you want to start a web server on this is the very basic function here and although there are some restrictions on many systems as far as what ports you can use if you're not root user if you're a standard user you should be able to use many of the higher ports that are available so you can type this command out and right away it will turn the folder that you're in into the main folder the root folder for your web server now be advised this is not going to be creating a directory list for you it's not going to be giving you a list of all the files and folders in that directory but if you type in the name of the file in the url you can guide yourself to it and of course if you guide yourself to an html file it will display that web file just like any other web server there are many other functions of this httpd in busybox but we'll go over that in a future video next up is python python comes with a built-in options for a very simple web server the command is as you can see at the bottom of the screen here for basic functionality and unlike the httpd in busybox this will generate a directory list for you so if you quickly want to share files and folders from your computer as a web server and offer up html files as a web server you can use python with this command and it will start up in the current directory and you can access it by going into your web browser typing in your ip address and the port number that you started on it has other functionality it will look at in the future video but this is another great option and although lighter systems such as routers and phones may not have python built-in by default pretty much every laptop and desktop linux system will most likely have python installed already lastly is a tool that is known as the networking swiss army knife netcat also known as nc now netcat is a networking swiss army knife of tools for network use and can do crazy things if you know what commands to use it can also be used as a very very basic html server web server for loading up files now it's definitely not nearly as powerful as the two that i previously talked about but in a pinch you can use netcat to serve up files and html files images and other stuff to a web browser it's very very basic but can be very useful and although you may not have a full version of netcat already installed on your system chances are as i said earlier you have busybox built in and busybox in many cases will have netcat built into it and although it's a slimmed down version of netcat you will still have netcat available so again on smaller devices that have busybox installed as their main shell as routers or phones and other devices netcat is available and to serve up a simple html file you can serve it up using this command here and again we'll look at that a little bit more in the future and how to make it a little more advanced and allow multiple connections because this particular command right here once connected netcat will finish out and you won't be able to connect again so it's like a one-time service unless you put it into a loop of some sort so be looking at that more in coming weeks so again these are basic options for setting up some very basic web servers and although they are not full featured web servers such as Apache they have many uses and chances are they are already on your Linux system so i thank you for watching i hope you subscribe so you don't miss the future videos and as always i hope that you have a great day and i hope that you visit filmsbychrist.com that's chris the k there should be a link in the description and as always have a great day okay today we're going to be looking at setting up a web server uh very quickly with python just default python what comes with python so if you have python on your system you should be good to go for setting up a quick web server and uh this first part you you've probably seen uh before if you've ever googled python web server it's the first thing comes up it's a simple HTTP server um so we're going to run python say dash m we're going to say simple and this is case sensitive http server so capital s capital http capital s and then whatever port you want to run it on so we'll say 800 here uh and i'll hit enter and it says serving htp on 00000 port 80 or sorry 8000 now here's my web browser let me refresh and look you can see there are two files now one of the advantages to this over the default setup for um busy box httpd which we've gone over previous weeks is that if there's no index file it is going to create a uh index file for you a directory list for you so you can see there's two files in the current directory which by the way when i start up the script it is running uh using the current folder so i'm going to want to run this in the folder i want and here's an example here's a picture i can click on and there's just a little civil png i threw in there that says films by chris.com which is a great website you should visit it and i can go back now let me control c a couple times down here in our shell window and kill that server so now if i come back up here hit f5 to refresh you can see the web this web page is not available because we shut down the server so let's create a html file so i'm going to them and i'll call it hello dot html and in here we'll create a very simple hello people yeah forward slash one so just give me some header tags there um and now we'll start up our server again hit f5 and now you can see that that file is there and if i click on it it displays it with the bold text because it's it's reading it as an html file now if i was to again kill our server here and move our hello html to be called index dot html and i was to go back here uh it's still showing it when i hit back page even though the server's down just because it's cached in the web browser if i hit f5 at this point you can see that the web server is down i'm going to start it up again running the same command python-m uh simple httpserver on port 80 and uh as you can see my web browser automatically updated once it realized the server was up and it says hello people the reason for that is if there's an index dot html file it's going to default to that rather than directory lists so now i can't view that list of files if i know the um the the name of one of those files i can say forward slash um what did i name that that image file well let's uh let's list here oh that's right fbk for films by chris.png so even though i can't get the directory list i can say fbk.png and still view that file but again if i go back to just localhost uh 8 000 here and hit enter it defaults that index file also i'm doing localhosts i'm connecting back to myself other options since i'm connecting back to myself can be um 127.0.0.1 which is the same as in most cases is doing uh um localhost so you can see that runs the same another option would be my current ip address on my local network if someone else on the local network wants to connect now if you're at a remote location you're going to have to set up port forwarding on your router to access it but locally i can say um 192.168.1.150 port 8 000 again because that's the i know that's the ip address of my system and that will work and another thing if i kill here this should work uh you can see the name of my host right here is grml i should be able to type in grml.local colon 8 000 hit enter and that didn't work just because i killed the server down here so let's go ahead restart the server and then refresh our page up here and you can see it works uh and so as long as your network's set up this way and most networks will do this and your computer set the right way and your browser knows how to resolve names uh you can use grml.localhost uh and again grml is the name of my host on my system here so when you're in your shell whatever's past your at symbol you should be able to access that computer while you're on that local network by using grml.local or that name and .local and the port name there so that's a few options there but now let's say i want to only be able to have a loopback connection loopback connection means well let me kill our server here let me maximize the screen here clear it if i type in if config you can see i have three network cards i got my wired ethernet card you have a lan card and you also have this loopback device this loopback connection is a virtual network device you can have no other network cards in this and you can have a loopback device and that just allows your computer to connect to itself without sending anything out through the network um and you can use this uh in many cases it's it's not uncommon to see applications using this to allow a program to use uh network services uh without having to go out to the network um and that way you can avoid you know one other people connecting to those services and also prevent uh ports or network sniffing from other devices obviously if someone's sniffing on this device and they're sniffing that device there's not much you can do about it um you have many problems then um but let's say you you wanted to set up a web interface um with maybe a form to fill out that saves stuff to a database and you want to use uh web services but you only want this computer to be able to connect to it you can use a loopback device so how can you use this python uh example to only access through loopback well yeah you're gonna have to write a little script it's a simple little script uh you can google this i've made it as simple as possible and i've put it on here i've called it server py uh and first line always with any script um you're gonna want to use your shebang line to tell your computer what interpreter to use if you're having issues and you come and ask me can you look at my code and you don't have that i'm going to yell at you i don't care do people write different ways and i and and and you can have different opinions on how you write it but make sure you have that shebang line saying this is a python script okay next we're gonna import a few modules our sys module and um and actually we don't need that sys module that was from something uh originally i was writing this and you could pass arguments to it i decided not to do that because i decided to keep the script as simple as possible so i don't think we need that sys module so the only module we need to import is base http server and from that we're going to use this simple http server which is what we were just using and we're going to uh and from that we're going to import this handler request now we're going to set a object a simple http request handler and set our server object to base uh http server and dot uh http server and we're going to use those further down here next we're going to create a variable that contains two bits of information the ip address and the port and since we're using this loop back ip address uh it will be able to loop back but not use those external ip addresses that they're connected to other network cards uh next what type of protocol uh version we're going to use we're going to use http one okay uh and then we're going to create this http object it's going to be a server using see this object up here we're going to pass it some information the server address which we've created up here with the port and we're going to say use this handler which handler well this one right up here that we imported up here we imported up here we used it up here in fact you can actually put this right in here but it's just shortening it here because we write it here in there anyway um and then this line here just says continue forever otherwise the script would run and close and no one would be able to connect this says as long as the script is running keep this process run process running so let me save that you'll want to make it executable change mod server.py or wherever you call it and we will run it i didn't set it to give any output by default when you start it up you can do that if you'd like now if i hit f5 up here hit enter you can see web page not available if i use the jrml local host if i try 192.168.1.150 port 8000 same thing but because those are using uh in this case my etho card because that's where i'm connected to the regular network with so it's using my actual network card but if i was to do local host that works and if i was to 127.0.0.1 that also works so that will prevent anyone else on the network from being able to access the server the only people who can access the server are the people that are on this machine uh yes you can tunnel through with ssh but but then you're doing that on purpose um so yes you can create applications and you can set them up so that only this computer has access to them now if i was to kill this and let's remove that index of html and start that server up again and refresh up here we're back to our directory list again you can see we have our image file here and we also have this server py file which is the the the process we're running here if i was to click on that you can see it displays it doesn't run it so can you create scripts that will run on the server side using python the answer is yes and that's what we're going to be looking into next week setting it up basically the same type of service but allowing scripts to run on the server end and that will definitely help you for creating applications um and you want to be able to do more advanced stuff you're going to want stuff to run on the server and and we'll go over that next week i hope you enjoyed this tutorial i hope you continue uh watching this series i hope you subscribe uh if you like these videos be sure to like them give them thumbs up and be sure to share them uh it really helps me when you share your videos gets me more viewers gets more interaction from people so if you enjoy these you know and you want to share them please do so and all as always visit filmsbychrist.com that's chris of the k there should be a link in the description and as always have a great day i've been looking at networks and servers and so far we've looked at busybox uh httpd we looked at uh creating our own access point uh with a computer and a wi-fi card we've also looked at using python to not only set up a web server but set up a web server that you have server side scripts on now we're looking at a very very very simple way to create a very very simple web server this is something you probably use in a pinch you wouldn't use actually as a web server it's probably something that uh you may have seen before it's very commonly used but i'm going to take it a step further than most examples do it's going to be using netcat uh which you can install in your system there's also a very basic version of it built into most versions of busybox it's a little more simple than uh it's not a full featured one but it's there and um it allows you to basically pipe a file or the output of some sort of program into uh as output for a web device um but lots of times well it it it's basically that one file it it pipes over into your web display your web browser and to access other files like let's say you want to have a web page with images in it is a little more well that's what we're going to look at after we look at the basics here so here we go let me make my font a little bit bigger here and we'll bring this down here so here we have a web browser i set up i already pointed it to my computer here again uh this is on my local network i know my ip address and i'm going to start server on port 800 because i know a regular user can use that port report 80 usually you need more permissions to so whatever permissions your user has and uh what i'm going to type here's i'm going to say nc or you can type out netcat either should work uh dash i and of course you need netcat installed so install that through your repositories um and i'm going to say so dash l means listen dash p means port i'm going to say 8 000 and uh then i'm also going to say dash q1 that one's kind of optional basically that's what i'm saying is after a second quit kill the connection because it shouldn't take more to to pipe out this simple display and you don't want the connection to stay open for some reason so this will be like hey after a second you know quit if if things aren't going right okay so we did that and that will listen on a port but not much is going to happen at this point because we need to give it some sort of information so let's go ahead and uh i'm going to split the screen here and i'm going to create a new web page i'm going to say vim uh embed dot html well no i'll just call this nc.html and in here i'll just say h1 hello from netcat i will save that file and what i'm going to do is i'm going to say okay take my nc.html file and that's going to be the output so with this web server you're not going to be able to like direct it to certain files someone connects on this port they're going to get the output of this file no matter what else they type in so here we go i'm going to hit enter to start that up up here i've already got the ip address and the port number put in and hit enter and you can see hello from netcat now if i come up here and i hit refresh we get web page not available again uh not available and if someone else tries to connect they're going to get the same thing because as you can see down here our server is no longer running um this one try to do okay uh so we need to put our our netcat into loop and there's different versions of netcat out there i've seen some commands that are supposed to do this built into netcat and they don't always work so i'm going to show you uh another way to do it we're going to say while true so we're just going to create a while loop in our shell here do and then we'll say netcat dash l for listen dash p for port eight thousand in this case dash q one and we'll pipe in our uh then c file or netcat file or html file we'll say done what's going to do is we're going to run that and up here i'll hit f5 and as you can see it says hello from netcat we get some output that our browser actually sent to netcat and you can see that it's still running so i can hit f5 again and f5 again and someone else can connect basically it's going to netcat sitting there waiting it's listening when someone connects it gives that information netcat stops running but our while loop starts it up again so that's that's one way to do it again this is not something you want to do for a commercial website this is something you do in a pinch okay so so that's working great uh i'm going to go ahead and control c does not seem to want to stop that so what i'm going to do is i am just going to close that shell so that's that's normally how i kill that you could also i guess use uh you know the kill command to kill the process uh okay so we've done that if i get up here refresh our servers down what happens if we want to display an image out to the web server well we can do that as well so let's go ahead and just again netcat-listen-port-8000-q1 and i'll redirect i have in this folder fbk.png it's the films by chris just basic png i'll hit enter the servers against listening i didn't put in the while loop just so i don't have to kill the shell each time here uh but i'm going to come up here and again i don't have to put in any file name because no matter what file name i put in there it's just going to output the same output on that port no matter what well my browser just automatically refreshed because it realized the server was back up but you can see it displayed wwe films by chris.com it's a png file it's basically just outputted that file so that's one way you can share images but how can you put an image into a web page so normally if we go back into our netcat html here i could do something like this uh i can say well let's put it on well i don't need to the line break those are header files okay anyway i can say img source equals and um films by chris whoops let me get my films by chris.png is the name of the file inside the folder we're at and that on a regular web page would work let's go ahead and save that close that run our server again here and up here hit f5 and that's because i typed in the wrong command down here i piped out the image again we want to pipe out and c.html now we run it refresh up here and you can see it says hello from netcat but our image is broke because netcat doesn't know how to serve up files other than the one we're redirecting into it with the less than symbol so how can we get a web page with images and other data in there when we're only able to pipe in this one file well you may or may not know this but you can embed images into an html file so instead of having html file and your images separate you can have them all built into the html file themselves in a plain text using base 64 i'm not going to get into too much about base 64 today base 64 is a great great thing it takes any binary file you have and will convert to plain text as key so you can transmit stuff if you ever looked at the raw data from an email if there's a attachment the attachment is sent to your email program in base 64 so what we have to do is we have to generate base 64 data for our image so first things first let's go into our netcat.html file and here instead of saying the name of the file because again netcat doesn't know what to do with that it's going oh you're looking for this i don't know how to serve that up because by the time we even look at that once it sends the one file netcat closes so we're going to say data colon image forward slash png this is saying okay the source of this image is going to be a data it's going to be an image it's going to be a png image in this case semi colon and we're going to say base 64 we're telling it okay use base 64 comma now we need to put the base 64 information which is going to be really really long probably on your system array you have base 64 installed if you type base 64 and the name of a file in this case films by chris dot png ffbk dot png we'd enter you can see it outputs all this plain text that is the image changed from a binary file into a plain ascii text which characters are readable to us but obviously it's we can't view that image look at that and go oh that's an image of this so we're going to copy and paste that's kind of long for me to highlight it also i have x clip installed if you don't it's in your repositories basically that's going to pipe that into my clipboard so boom right now i can go in now i can go and paste that into my you can also redirect it into a file if you want and then use that anyway i'm going to go into my my html file here hit i i'm going to center click here and give it a second if him is going oh okay that's a lot of data let's let's put all that here it's going to take a couple of seconds because it's an image there we go it's all in there i can now save that hit up arrow a few times so now we're going to run our command again netcat listen port eight thousand quit after one second redirect this image fire this html file which has the image built into it run that refresh up here and there we go we have our html content and the image of course you can do this throughout the page now remember now that html file that used to be the small little text file is now rather large if we actually list out all the files in this directory you can see that our films by chris dot png is 57 kilobytes not that big our html file is 76 kilobytes and um parts of that is because there is more data in there but also uh base 64 tends to be a little bit larger than the original little binary file but keep that in mind if you're putting large images in there it's your html file is going to get rather large i'm going to take longer to pipe it but and um but that is it and in fact if i was to open up in my web browser here i'm using chrome i'll hit f12 to bring up my little console here and i look at network on a regular web page if um let's go ahead and start our server up and up here i'll hit f5 to refresh you can see it it shows right here it doesn't say a file name it's saying okay it's transferring this data as an image and uh so keep that in mind it's not getting it from a separate file it's actually embedded in html file and most cases web servers websites you don't want to do that but if you ever needed that's actual bonus tip outside of this netcat tutorial you could send an html file to somebody as a single file with images if you ever wanted to i've never done that but you can so that is it uh a little quick look at base 64 there which is a great thing used a lot especially with html 5 for storing images created on canvas and stuff like that not getting into that today but um i hope that you learned something because again this this using netcat as a web server is a fairly common hack that people use to get a web server to share a file real quick as you saw you can share a file by piping the file or the html um but at the same time i thought i'd take it a step further in case you've already seen that and show you how you can embed those images in there so you can have a full web page if you wanted with images and and other data built in using base 64 so as always i hope that you enjoy the tutorial please visit my website filmsbychrist.com that's chris at the k it should be linked in the description if you like this video let me know by one giving this video a thumbs up two commenting below and let me know that you like it so that i know what topics people like and i know to do more and also it helps me out a lot if you share these videos you know wherever facebook google plus twitter share it get me more viewers i really appreciate that you know also if you want to support me you can support me at patreon.com forward slash middle x 1000 i appreciate that but if you can't afford to do that or for some reason you don't want to do that you can help me by sharing this video and 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 middle x 1000