Task3- Linux Remote CLI Flutter Mobile App

Akash Mittal
4 min readOct 20, 2020
Demo of app

Linux CLI(Command Line Interface) Mobile App using Firebase, Redhat, Linux Flutter Integration. Welcome to my Demonstration Project article based on Linux Remote CLI Flutter Mobile App.

This is a demonstration project, based on the development of Linux Remote CLI Flutter application using the Integration of Google firebase (firestore to store the response) and Redhat Linux using Python — CGI Programming.

Task 3: Flutter App Development.

1. Create an app that can run any Linux command using API

2. Output will be saved in Firestore.

3. From Firestore, 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.

In this project article, we will learn how to make an app from which we can perform any Linux command remotely from our mobile.

What is CGI?

The Common Gateway Interface, or CGI, is a standard for external gateway programs to interface with information servers such as HTTP servers.

Web Browsing

To understand the concept of CGI, let us see what happens when we click a hyperlink to browse a particular web page or URL.

  • 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.

To know more about cgi-programming refer to this link :

Web Server Support and Configuration 😄

Before you proceed with CGI Programming, make sure that your Web Server supports CGI and it is configured to handle CGI Programs. All the CGI Programs to be executed by the HTTP server are kept in a pre-configured directory. This directory is called CGI Directory and by convention, it is named as /var/www/cgi-bin. By convention, CGI files have extension as. cgi, but you can keep your files with python extension .py as well.

By default, the Linux server is configured to run only the scripts in the cgi-bin directory in /var/www. If you want to specify any other directory to run your CGI scripts, comment the following lines in the httpd.conf file −

<Directory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

<Directory "/var/www/cgi-bin">
Options All
</Directory>

This file is kept in /var/www/cgi-bin directory and it has the following content. Before running your CGI program, make sure you have to change the mode of the file using chmod 755 linux.py UNIX command to make the file executable.

#!/usr/bin/python3
import cgi
import subprocess
print("content-type:text/html")
print()
mydata=cgi.FieldStorage()
output=subprocess.getoutput("sudo " +mydata.getvalue("x"))
print(output)

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.84.130/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.

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:

sudo setenforce 0

Basic Linux CLI Commands

Example of Linux CLI commands

Note- Use CLI commands with great attention!!! Wrong use can easily delete files or destroy your computer system completely.

Demo of App

Thank you for reading the article hope you liked it. Github Link for the full code- https://github.com/akashmittal18/FlutterRedhatFirebaseIntegration

--

--