Linux Remote CLI Flutter Mobile App using python — CGI With Firebase Stream Builder. (Task 4)

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 access to the physical server to perform any operation on it.

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 a web server and displays either the received file or error message.

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 an extension. CGI, but you can keep your files with python extension .py as well.

<Directory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory><Directory "/var/www/cgi-bin">
Options All
#!/usr/bin/python3import cgi
import subprocess
output=subprocess.getoutput("sudo " +mydata.getvalue("x"))

GET and POST Methods

You must have come across many situations when you need to pass some information from your browser to the web server and ultimately to your CGI Program. Most frequently, the browser uses two methods two passes this information to a web server. These methods are GET Method and POST Method.

Passing Information using the 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 −

//mycmd filed will take the command name which we have to execute.To check the server ip address you can use ifconfig command.
sudo setenforce 0



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store