TASK-3 Linux Remote CLI Flutter App
Linux CLI Mobile App using Firebase, Redhat, Linux Flutter Integration.
This is a demonstration project article based on Linux Remote CLI Flutter Mobile App using the integration of Google firebase(to store response) and Redhat Linux using python based CGI programming.
Task 3:- Flutter App Development
Objective : 1.Create an app that can run any linux command using API(Application programming interface).
2. Output will be saved in Firebase Firestore.
3. From Fire store, get this output and print on the screen.
What is the Command line?
The Linux command line is a text interface to your computer. Often referred to as the shell, terminal, console, prompt, or various other names, it can give the appearance of being complex and confusing to use. To access the Command line of any Linux system we must have an access to the physical server to perform any operation on it.
What is CGI ?
CGI (Common Gateway Interface) is a standard way of running programs from a Web server. Often, CGI programs are used to generate pages dynamically or to perform some other action when someone fills out an HTML form and clicks the submit button.
Web Browsing
To understand the concept of CGI, first we have to learn what happens when we click on a hyperlink to browse a particular webpage.
- Your browser contacts the HTTP web server and demands for the URL, i.e., filename.
- Web Server parses the URL and looks for the filename. If it finds that file then sends it back to the browser, otherwise sends an error message indicating that you requested a wrong file.
- Web browser takes the response from the webserver and displays either the received file or error message.
It is possible to execute a program and whatever the program outputs is sent back for your browser to display instead of sending back the file in a certain directory when requested in HTTP server.
Python provides methods to run shell commands, giving us the same functionality of those shell scripts. Learning how to run shell commands in python opens a opportunity to automate computer tasks. Therefore we are using python language instead of shell scripts for automation.
Web Server Configuration and Support
Before we move further into CGI programming, make sure that your Web Server supports CGI and it is configured to handle CGI Programs.
Static pages are stored in /var/www/html and dynamic pages such as this CGI are stored in /var/www/cgi-bin. By convention, CGI files have extension as. cgi, but you can keep your files with python extension .py as well.
Before running your CGI program, make sure you have change mode of file using chmod 755 linux.py UNIX command to make file executable.
The below file is kept in /var/www/cgi-bin directory and it has following content. Before running your CGI program, make sure you have change mode of file using chmod 755 linux.py UNIX command to make file executable.
You can learn about cgi and subprocess module from here.
GET and POST Methods
You must have come across many situations when you need to pass some information from your browser to the webserver and ultimately to your CGI Program. Most frequently, the browser uses two methods to pass this information to a web server. These methods are GET Method and POST Method.
Passing Information using GET method
The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the? character as follows −
"http://192.168.1.6/cgi-bin/docker.py?x=${mycmd}";http://<serverIP>/cgi-bin/pythonfile.py?x=${mycmd}
//mycmd filed will take the command name which we have to execute.To check the server ip address you can use ifconfig command.
The GET method is the default method to pass information from browser to web server and it produces a long string that appears in your browser’s Location:box. Never use GET method if you have password or other sensitive information to pass to the server.
Note: Before you can access the server remotely you need to set firewall To know more about firewall refer this link.
for this tutorial purpose i had disabled my firewall : To disable the firewall use command : systemctl stop firewalld.
Now Check SELinux Status:
The SELinux service is enabled by default on CentOS and most other RHEL-based systems. However, this might not be the case for your system.
Start by checking the status of SELinux on your system with the command:
sestatus
To disable SELinux temporarily, type in the following command in the terminal:
Now We will able to Perform Command operation on Linux remotely using http :
Now we will make an simple Interface flutter app to perform Linux commands.
To know how to Connect Firebase Firebase Storage Refer This article: https://firebase.flutter.dev/docs/firestore/usage/
Demo of the app:
The firebase console:-
Thank you for reading the article hope you liked it .