Hi there! Today we are going to make a web-based terminal to run the commands with the help of javascript and python as backend. So let's get into it.
What is Javascript?
JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive. Where HTML and CSS are languages that give structure and style to web pages, JavaScript gives web pages interactive elements that engage a user.
The program on the remote server sends information to the client (i.e. the user's machine) and the software on the client-side reads the information and renders output on the screen.
Where does python fit into this?
The program on a remote server that I talked about just above is where python comes into the picture. So the client will input the command into the web page and then the program at the backend which is written in python will get the request and process it and give back the response to the front-end which will then be shown to the user.
Our Setup
So for this demo I have used Linux as my VM and in it, I have installed an apache webserver and python code to handle and process the requests and in the front end, I have used basic HTML, CSS, and Javascript to send requests and show response.
Let's Start
First, let's take a look at our front-end part. Here's what it looks like.
HTML
CSS
JavaScript
Here's how it looks like on running.
Now let's see our backend. As I already told I have installed apache as a web server and I have it up and running already.
And here my python program
Also here we need to give apache the permission in /etc/sudoers to run the commands as sudo user as Linux follows the principle of least privilege and thus by default does not allow such permissions
Now our setup is complete and what is left is for us to test the setup now. Here's what happens when I run the commands.
Now we can even run the other programs and commands like Docker here for instance.
And here you can it has launched successfully.
That's it for this one. See you next time ....!!!