Integrating Javascript and python

Integrating Javascript and python

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

HTML

CSS

Screenshot (1261).png

JavaScript

Javascript: fdfd

Here's how it looks like on running.

Screenshot (1263).png

Screenshot (1265).png

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.

VirtualBox_Ansible Controller Redhat_25_06_2021_20_42_05.png

And here my python program

VirtualBox_Ansible Controller Redhat_25_06_2021_20_39_58.png

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

VirtualBox_Ansible Controller Redhat_25_06_2021_20_40_49.png

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.

command.png

output.png

Now we can even run the other programs and commands like Docker here for instance.

Screenshot (1257).png

Screenshot (1259).png

And here you can it has launched successfully.

VirtualBox_Ansible Controller Redhat_25_06_2021_20_43_31.png

That's it for this one. See you next time ....!!!

Did you find this article valuable?

Support Saurav Rana by becoming a sponsor. Any amount is appreciated!