Flesh out GLoom

I have documented GLoom's new RPC, how a plugin developer might create a plugin, and more. I have also created GLoomI, the included management interface for GLoom and added a LICENSE.
This commit is contained in:
Zoe
2025-01-07 19:33:08 +00:00
parent 3d6c4c72a7
commit 98c0f45ca8
18 changed files with 763 additions and 77 deletions

3
gloomi/README.md Normal file
View File

@@ -0,0 +1,3 @@
# GLoomI
GLoomI is the management Interface for GLoom. This plugin is responsible for managing GLoom's plugins and domains, and utilizes gloom's built in plugin system. It uses RPC to communicate with GLoom.

26
gloomi/go.mod Normal file
View File

@@ -0,0 +1,26 @@
module github.com/juls0730/gloomi
go 1.23.4
require github.com/gofiber/fiber/v3 v3.0.0-beta.4
require (
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/gofiber/schema v1.2.0 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
github.com/tinylib/msgp v1.2.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.58.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
)

42
gloomi/go.sum Normal file
View File

@@ -0,0 +1,42 @@
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/gofiber/fiber/v3 v3.0.0-beta.4 h1:KzDSavvhG7m81NIsmnu5l3ZDbVS4feCidl4xlIfu6V0=
github.com/gofiber/fiber/v3 v3.0.0-beta.4/go.mod h1:/WFUoHRkZEsGHyy2+fYcdqi109IVOFbVwxv1n1RU+kk=
github.com/gofiber/schema v1.2.0 h1:j+ZRrNnUa/0ZuWrn/6kAtAufEr4jCJ+JuTURAMxNSZg=
github.com/gofiber/schema v1.2.0/go.mod h1:YYwj01w3hVfaNjhtJzaqetymL56VW642YS3qZPhuE6c=
github.com/gofiber/utils/v2 v2.0.0-beta.7 h1:NnHFrRHvhrufPABdWajcKZejz9HnCWmT/asoxRsiEbQ=
github.com/gofiber/utils/v2 v2.0.0-beta.7/go.mod h1:J/M03s+HMdZdvhAeyh76xT72IfVqBzuz/OJkrMa7cwU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c h1:dAMKvw0MlJT1GshSTtih8C2gDs04w8dReiOGXrGLNoY=
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
github.com/tinylib/msgp v1.2.5 h1:WeQg1whrXRFiZusidTQqzETkRpGjFjcIhW6uqWH09po=
github.com/tinylib/msgp v1.2.5/go.mod h1:ykjzy2wzgrlvpDCRc4LA8UXy6D8bzMSuAF3WD57Gok0=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.58.0 h1:GGB2dWxSbEprU9j0iMJHgdKYJVDyjrOwF9RE59PbRuE=
github.com/valyala/fasthttp v1.58.0/go.mod h1:SYXvHHaFp7QZHGKSHmoMipInhrI5StHrhDTYVEjK/Kw=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=

108
gloomi/main.go Normal file
View File

@@ -0,0 +1,108 @@
package main
import (
"fmt"
"io"
"mime/multipart"
"net/rpc"
"strings"
"github.com/gofiber/fiber/v3"
)
type GLoomI struct {
client *rpc.Client
}
func (p *GLoomI) Init() error {
// Connect to the RPC server
client, err := rpc.Dial("tcp", "localhost:7143")
if err != nil {
return fmt.Errorf("failed to connect to Gloom RPC server: %w", err)
}
p.client = client
return nil
}
func (p *GLoomI) Name() string {
return "GLoomI"
}
type PluginData struct {
Name string `json:"name"`
Domains []string `json:"domains"`
}
func GetPlugins(client *rpc.Client) ([]PluginData, error) {
var plugins []PluginData
err := client.Call("GloomRPC.ListPlugins", struct{}{}, &plugins)
return plugins, err
}
func (p *GLoomI) RegisterRoutes(router fiber.Router) {
apiRouter := router.Group("/api")
{
apiRouter.Get("/plugins", func(c fiber.Ctx) error {
plugins, err := GetPlugins(p.client)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("Failed to list plugins: " + err.Error())
}
return c.Status(fiber.StatusOK).JSON(plugins)
})
type UploadRequest struct {
Domains string `form:"domains"`
}
apiRouter.Post("/plugins", func(c fiber.Ctx) error {
pluginUpload := new(UploadRequest)
if err := c.Bind().Form(pluginUpload); err != nil {
return c.Status(fiber.StatusBadRequest).SendString("Failed to bind form data: " + err.Error())
}
if pluginUpload.Domains == "" {
return c.Status(fiber.StatusBadRequest).SendString("No domains provided")
}
domains := make([]string, 0)
for _, domain := range strings.Split(pluginUpload.Domains, ",") {
domains = append(domains, strings.TrimSpace(domain))
}
var pluginFile *multipart.FileHeader
pluginFile, err := c.FormFile("plugin")
if err != nil {
return c.Status(fiber.StatusBadRequest).SendString("Failed to get plugin file: " + err.Error())
}
pluginData, err := pluginFile.Open()
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("Failed to open plugin file: " + err.Error())
}
var pluginUploadStruct struct {
Domains []string `json:"domains"`
Name string `json:"name"`
Data []byte `json:"data"`
}
pluginUploadStruct.Name = pluginFile.Filename
pluginUploadStruct.Domains = domains
pluginUploadStruct.Data, err = io.ReadAll(pluginData)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("Failed to read plugin file: " + err.Error())
}
err = p.client.Call("GloomRPC.UploadPlugin", pluginUploadStruct, nil)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("Failed to upload plugin: " + err.Error())
}
return c.Status(fiber.StatusOK).SendString("Plugin uploaded successfully")
})
}
}
// Exported symbol
var Plugin GLoomI

12
gloomi/zqdgr.config.json Normal file
View File

@@ -0,0 +1,12 @@
{
"name": "Go Project",
"version": "0.0.1",
"description": "Example description",
"author": "you",
"license": "BSL-1.0",
"scripts": {
"build": "go build -buildmode=plugin -o ../plugs/gloomi.so main.go"
},
"pattern": "**/*.go",
"excluded_dirs": []
}