How To Build A Mobile App in Flutter Which Can Run Linux Commands And store The Data In Firebase .

Project setup with Firebase :

Navigate to the Firebase console and set up a new app.

🔰 Adding a new project ⤵️

🔰Specify a name for your project and click Continue. ⤵️

give a name

🔰Enable it then click Continue. ⤵️

🔰Choose default account then click Create Project. ⤵️

🔰 It will take some time ,Then your Firebase project will be set up. You can now click on Continue.

Configuring our Linux app to connect to Firebase :

In my case I’m going with android .

Fill out your app details.

  • You can get your app name from here
  • Then click Register app. Next, you will get a google-services.json file. Download this file and store it as instructed in doc.
  • Now you have to set your Firebase plugins in your app as instructed in doc.
web instructions

In Project :

Project-level build.gradle:

App-level build.gradle:

  • Add these Dependencies In your pubspec.yaml File in your app.
  1. http
  2. firebase
  3. firebase_core
  4. cloud_firestore
dependencies: 

http: ^0.12.2
firebase: ^7.3.1
firebase_core: ^0.5.0
cloud_firestore: ^0.14.0+2

Now in your Dart code, add all imports :

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:http/http.dart' as http;

you’ve now finished the app-specific setup.

  • configure Apache on RHEL 8 / CentOS 8 Linux :- click here
  • Create the web content directory which is /var/www/cgi-bin/ and place all your content in there.
>> cd /var/www/cgi-bin/
>> vim linuxapp.py

Inside linuxapp.py

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

Adding This API in our dart file.

check() async {
var url = "http://$ip/cgi-bin/all.py?x=$command";
var response = await http.get(url);
await firebase.collection("linux").add({
'ip': ip,
'command': command,
'output': "${response.body}",
});

Thank you for visiting me !! :)

Devops || MlOps || Flutter || Web Development || PYTHON || Data Science || AWS cloud || GCP || Azure