Integrating Firebase & Linux Commands API using Flutter!

This blog explains the process of integrating Linux API with Firebase using Flutter. In this integration, any Linux command will be executed using Flutter App which will fetch the command output from Linux Webserver & store the output at the Firestore. The flutter app developed will also have the functionality to retrieve the data from the Firestore.

Harshit Dawar
4 min readSep 4, 2020
Source: AllTechsavvy

Ever thought of creating an application that provides you the capability to run the Linux commands from your mobile phone, store their output in Firestore(Google NoSQL Database) & can retrieve outputs of all those commands? How amazing it will be to create such an app, as it will provide ease & simplicity to your life. This blog aims to guide you with the complete process.

There are no pre-requisites for the complete practical. This blog covers every aspect of the practical, i.e. from creating a document in Firestore & creating an API, to connect them by flutter Application.

Setting Up Firestore:

To accomplish this part of the practical, follow the steps given below:

  1. Visit this link: Firebase
  2. Log in with the Google ID & Password. You will be landed on the screen below.
Firebase Page [Image by Author]

3. Click on the “Go to console” & then you will be landed on the Firebase homepage. Click on the button given below to add one project.

Firebase HomePage [Image by Author]

4. After that enter your project name as shown below, and follow the further steps to set up the project.

Image by Author!

After the project creation, you will be landed on a page as shown below.

Image by Author!

5. Now click on the Android Icon shown on the above page and follow the complete process, it will guide you to set up or connect your Flutter App to Firestore. For completion of this step, create one sample flutter app and follow the complete process till here.

Creating API

The API creation code is shown below. (This code will create one API which will help to run the Linux Commands using a webserver).

Note: For this API code to work, Apache webserver(httpd) has to be installed in your machine. To do the same, either follow the standard procedure or use my Ansible role to configure it if you have some knowledge of Ansible & using RedHat Linux. The link to my Ansible Role is given below.

API Code

API Code to run any Linux Command!

Write this code in a file, save it with “.py” extension in the folder “/var/www/cgi-bin”.

Make this file executable by running the command “chmod +x <filename>”.

Creating the Flutter App!

Flutter Code to Create an APP that is capable of connecting to API & Firebase!

Note: For the above code to work, add the following dependencies to your pubspec.yaml file.

Image by Author!

Congratulations on successfully building the limited edition rare project!

Example Outputs from this Project!

Running Date Command [Image by Author]!
The output of Data command [Image By Author]!
Data at Firestore [Image By Author]!
Running “ifconfig enp0s3" command [Image By Author]!
The output of “ifconfig enp0s3” command [Image By Author]!
Data at Firestore [Image By Author]!

I hope my article explains each and everything related to the topic with all the deep concepts and explanations. Thank you so much for investing your time in reading my blog & boosting your knowledge!

--

--

Harshit Dawar

AIOPS Engineer, have a demonstrated history of delivering large and complex projects. 14x Globally Certified. Rare & authentic content publisher.