Web Application for Docker

Web Application for Docker

Task:

This app will help the user to run all the docker commands of docker using webApp using JavaScript.

Solution:

for this task we need basic knowledge of html, css and javascript for the frontend, and for backend we need knowledge of CGI programming.

CGI:

CGI is a standard method used to generate dynamic content on web pages. CGI stands for Common Gateway Interface and provides an interface between the HTTP server and programs generating web content. These programs are better known as CGI scripts. They are written in a scripting language.


JavaScript is a scripting or programming language that allows you to implement complex features on web pages — every time a web page does more than just sit there and display static information for you to look at — displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc. — you can bet that JavaScript is probably involved. It is the third layer of the layer cake of standard web technologies, two of which HTML and CSS.

No alt text provided for this image
  • HTML is the markup language that we use to structure and give meaning to our web content, for example defining paragraphs, headings, and data tables, or embedding images and videos in the page.
  • CSS is a language of style rules that we use to apply styling to our HTML content, for example setting background colors and fonts, and laying out our content in multiple columns.
  • JavaScript is a scripting language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else. (Okay, not everything, but it is amazing what you can achieve with a few lines of JavaScript code.)

Now Let's go for the Setup-

github link: https://github.com/yashdwi05/javascript-docker.git

we need a webserver which can run our CGI code. so I used Apache httpd Server. and we can put our CGI code at by default location as /var/www/cgi-bin/ also for running CGI code webserver uses apache user so for specific task only provide limited power to apache user, so we can edit the sudo file for Privilege Escalation as below:

No alt text provided for this image

I have added apache user line to the file /etc/sudoers and now apache user can run docker commands only using CGI program.

now it's time to deploy CGI program at /var/wwww/cgi-bin/

No alt text provided for this image

This simple CGI code will retrieve vvalue from http and use as a command and give back the output.

now our next part is to create JavaScript Code to fetch the response after sending http request to cgi code.

No alt text provided for this image

Here in this JavaScript code we used AJAX to fetch response from server so function don't have to wait and we can proceed with other features.

in the next step I used html and css for providing frontend looks for the webapp and also javascript we can run using html language.

No alt text provided for this image

This is the frontend code we have and it will provide interface to run docker commands.

we have to put this code at /var/www/html/ to deploy the webapp. now we can access this app via url which everyone have different.

No alt text provided for this image

This one is the webui of the app and we can run commands using input box.

No alt text provided for this image
No alt text provided for this image

We can see WebApp is working great. and here I make this only for docker commands so other commands won't work here.

No alt text provided for this image

Here we can see even the most basic command other then docker it can't run, this is good for security perspective of the server.

Thanks for Reading!!

要查看或添加评论,请登录

Yash Dwivedi的更多文章

社区洞察

其他会员也浏览了