Skip to content

LiquidGalaxyLAB/lg-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LG Control Server 🚀

The LG Control Server is a powerful and intuitive Node.js-based application for managing Liquid Galaxy (LG) systems via SSH. It offers a robust REST API to handle various LG operations, from visualizations to system management.

View Swagger API Docs


📝 Table of Contents

  1. Getting Started
  2. Project Structure
  3. How to Run
  4. Adding a New Command
  5. Endpoints
  6. License
  7. Contributors

🚀 Getting Started

Installation

  1. Clone the repository:

    git clone https://github.com/LiquidGalaxyLAB/lg-server.git
    cd lg-server
  2. Install dependencies:

    npm install
  3. Set up HTTPS with mkcert:
    Install mkcert (follow this guide) and generate your SSL certificates:

    mkcert -install  
    mkcert localhost <ip_address>
    • Create a certs folder in the project root and place the generated .key and .pem files there.
    • Learn more. Rename them to cert.pem and key.pem as shown in the article.
  4. Install RootCA.pem on your device:

    Find the RootCA.pem location:

    mkcert CAROOT

    Send the RootCA.pem file to your Android or iOS device, rename it with a .crt extension, and install it.


🚧 Project Structure

  • app.js: Entry point of the application.
  • server.js: Configures middleware, routes, and starts the server.
  • routers/: Defines API routes.
  • controllers/: Contains logic to handle API requests.
  • services/: Implements SSH interactions and reusable logic.

▶️ How to Run

  1. Start the server:

    npm run dev
  2. Verify the server is running by hitting the health check endpoint:

    curl http://localhost:8000/ping

    Expected Response:

    { "message": "pong@@" }

➕ Adding a New Command

Step 1: Create a Service Function

  1. In the services/ directory, add a new function:

    export const newCommandService = async (ip, port, username, password, command) => {  
        const client = new Client();  
        try {  
            await connectSSH(client, { ip, port: parseInt(port, 10), username, password });  
            const result = await executeCommand(client, command);  
            console.log("Command result:", result);  
            return result;  
        } catch (error) {  
            console.error("Error during SSH operations:", error);  
            return { success: false, message: error.message };  
        } finally {  
            client.end();  
        }  
    };  

Step 2: Add a Controller Method

  1. In controllers/, add the logic to handle the new command:

    newCommand = async (req, res) => {  
        const { ip, port, username, password, command } = req.body;  
        const response = await newCommandService(ip, port, username, password, command);  
        return res.status(200).json(response);  
    };  

Step 3: Define the Route

  1. Add a route in routers/index.js:

    router.route("/new-command").post(lgConnectionController.newCommand);  

Step 4: Test the Endpoint

  1. Use curl or Postman to test:

    curl -X POST http://localhost:8000/api/new-command \  
    -H "Content-Type: application/json" \  
    -d '{  
        "ip": "192.168.x.x",  
        "port": "22",  
        "username": "your-username",  
        "password": "your-password",  
        "command": "your-command"  
    }'  

🌐 Endpoints

Core Endpoints

Endpoint Method Description
/ping GET Health check endpoint.
/api/execute-orbit POST Executes an orbit command.
/api/clean-visualization POST Cleans LG visualizations.
/api/clean-logos POST Removes LG logos.
/api/relaunch-lg POST Relaunches the LG system.
/api/reboot-lg POST Reboots the LG system.
/api/stop-orbit POST Stops orbit visualization.
/api/clean-balloon POST Cleans balloon visualizations.
/api/new-command POST Executes a custom command.

📓 License

This project is licensed under the MIT License.


🤝 Contributors

Contributors

Backend Developer

The backend is developed by Lovely Sehotra.

Frontend Designer

Designed by Mentor Yash.

About

A liquid galaxy web server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published