Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Merge develop into events-rewrite #302

Open
wants to merge 31 commits into
base: events-rewrite
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
79cf8a6
feat: email templates & SMTP
tnix100 Aug 18, 2024
27181fc
add ed25519 signing (not used for anything yet)
tnix100 Aug 20, 2024
b62a544
feat: default emojis list
tnix100 Aug 23, 2024
173a64a
fix: register /emojis blueprint
tnix100 Aug 23, 2024
0900599
fix: don't add an extra .json
tnix100 Aug 23, 2024
c7b3801
Merge branch 'develop' into tnix-emails
tnix100 Aug 23, 2024
74704b8
fix: add 'error: false' to /emojis (#297)
tnix100 Aug 23, 2024
d54ec93
feat: simpler signed tokens implementation
tnix100 Aug 23, 2024
5a1657e
feat: sessions and hmac tokens
tnix100 Aug 25, 2024
e5a7704
switch from IPHub to IP-API
tnix100 Aug 25, 2024
b1a7446
set expiration for sessions and fix some other problems with sessions
tnix100 Aug 26, 2024
b8932d2
fix: register /emojis blueprint
tnix100 Aug 23, 2024
544719c
fix: don't add an extra .json
tnix100 Aug 23, 2024
3cf8adf
fix: add 'error: false' to /emojis (#297)
tnix100 Aug 23, 2024
5c436bd
switch from IPHub to IP-API
tnix100 Aug 25, 2024
987f962
add email tickets
tnix100 Aug 26, 2024
092c086
Add files via upload
tnix100 Sep 1, 2024
91c07b3
Add files via upload
tnix100 Sep 1, 2024
a23e1dc
Update email templates
tnix100 Sep 9, 2024
16a92d8
update security alert email template
tnix100 Sep 9, 2024
86e8d37
update kick function in cl3
tnix100 Sep 9, 2024
aa7c986
update cl3 kick to async
tnix100 Sep 9, 2024
6c9d4c8
finish emails
tnix100 Sep 9, 2024
7d01006
add back account restoration
tnix100 Sep 9, 2024
441dcf2
Merge branch 'develop' into tnix-emails
tnix100 Sep 9, 2024
2f8ebca
make sure an email address cannot be used more than once
tnix100 Sep 9, 2024
d316337
add usersv0 indexes for emails
tnix100 Sep 9, 2024
792c26f
add the ability to remove email addresses
tnix100 Sep 10, 2024
69176d2
Merge pull request #293 from meower-media/tnix-emails
tnix100 Sep 10, 2024
f313ffb
Update SECURITY.md to fix link (#303)
Finley224 Sep 29, 2024
a0b542e
continue rewrite
tnix100 Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ MONGO_URI=mongodb://127.0.0.1:27017
MONGO_DB=meowerserver
REDIS_URI=redis://127.0.0.1:6379/0
REAL_IP_HEADER=
IPHUB_KEY=
CL3_HOST="0.0.0.0"
CL3_PORT=3000
API_HOST="0.0.0.0"
Expand All @@ -12,9 +11,24 @@ API_ROOT=
INTERNAL_API_ENDPOINT="http://127.0.0.1:3001" # used for proxying CL3 commands
INTERNAL_API_TOKEN="" # used for authenticating internal API requests (gives access to any account, meant to be used by CL3)

SENTRY_DSN=

CAPTCHA_SITEKEY=
CAPTCHA_SECRET=

EMAIL_SMTP_HOST=
EMAIL_SMTP_PORT=
EMAIL_SMTP_TLS=
EMAIL_SMTP_USERNAME=
EMAIL_SMTP_PASSWORD=
EMAIL_FROM_NAME=
EMAIL_FROM_ADDRESS=
EMAIL_PLATFORM_NAME="Meower"
EMAIL_PLATFORM_LOGO=""
EMAIL_PLATFORM_BRAND="Meower Media"
EMAIL_PLATFORM_FRONTEND="https://meower.org"
EMAIL_PLATFORM_SUPPORT="[email protected]"

GRPC_AUTH_ADDRESS="0.0.0.0:5000"
GRPC_AUTH_TOKEN=

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ jobs:

- name: Build and push images
run: |
cd python
IMAGE_NAME=ghcr.io/${{ github.repository }}
docker buildx build --push -t $IMAGE_NAME:${{ env.SHORT_SHA }} .
1 change: 1 addition & 0 deletions .github/workflows/publish-latest-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ jobs:

- name: Build and push images
run: |
cd python
IMAGE_NAME=ghcr.io/${{ github.repository }}
docker buildx build --push -t $IMAGE_NAME:latest .
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
__pycache__/

# Cloudflared windows executable
*.exe
*.env

*.json

*.env
.idea/
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@

![](./branding/server%20banner.svg)
# Server
Official source code of the Meower server, written in Python. Powered by CloudLink.

## Running
```py
git clone https://github.com/meower-media/server.git --recursive
cd Meower-Server
cd Meower-Server
pip install -r requirements.txt

cp .env.example .env

# edit env files

python3 main.py
```
the go stuff, in cmd/* and pkg/* has no security features, so be careful!!!

## API docs
See [the autogenerated documentation](https://api.meower.org/docs) and the [Meower documentation](https://docs.meower.org)
this branch is the subject of a major rewrite
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Security Policy
Meower Media thanks you for taking time to help make Meower a safer place. Meower Media takes the security of all products and services seriously, including all open source repositories managed via our Github organization, [meower-media-co](https://github.com/meower-media-co).
Meower Media thanks you for taking time to help make Meower a safer place. Meower Media takes the security of all products and services seriously, including all open source repositories managed via our Github organization, [meower-media](https://github.com/meower-media).

## Version support
As of Feb. 7th, 2023, the currently deployed server version is built upon Cloudlink 3.
Expand All @@ -12,4 +12,4 @@ As of Feb. 7th, 2023, the currently deployed server version is built upon Cloudl
If you believe that your data on any Meower Media products/services has been compromised, please contact an administrator of Meower Media directly, or contact [email protected] immediately. From which, Meower Media will review your report in a timely fashion, and determine suitable course of action.

## Reporting a security vulnerability
If you believe you have discovered a security vulnerability, please report it to Meower Media through coordinated disclosure. To report a security vulnerability, [please do so here](https://github.com/meower-media-co/Meower-Server/security/advisories/new). If you have questions about whether an issue is a security vulnerability, please contact Meower Media at [email protected].
If you believe you have discovered a security vulnerability, please report it to Meower Media through coordinated disclosure. To report a security vulnerability, [please do so here](https://github.com/meower-media/Meower-Server/security/advisories/new). If you have questions about whether an issue is a security vulnerability, please contact Meower Media at [email protected].
33 changes: 33 additions & 0 deletions cmd/events/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"log"
"os"

"github.com/getsentry/sentry-go"
"github.com/joho/godotenv"
"github.com/meower-media/server/pkg/api/events"
)

func main() {
// Load dotenv
godotenv.Load()

// Initialise Sentry
sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("EVENTS_SENTRY_DSN"),
})

// Get expose address
exposeAddr := os.Getenv("EVENTS_ADDRESS")
if exposeAddr == "" {
exposeAddr = ":3000"
}

// Create & run server
server := events.NewServer()
err := server.Run(exposeAddr)
if err != nil {
log.Fatalln(err)
}
}
93 changes: 49 additions & 44 deletions main.py → cmd/legacy/main.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
# Load .env file
from dotenv import load_dotenv
load_dotenv()

import asyncio
import os
import uvicorn

from threading import Thread

from cloudlink import CloudlinkServer
from supporter import Supporter
from security import background_tasks_loop
from grpc_auth import service as grpc_auth
from rest_api import app as rest_api


if __name__ == "__main__":
# Create Cloudlink server
cl = CloudlinkServer()

# Create Supporter class
supporter = Supporter(cl)
cl.supporter = supporter

# Start background tasks loop
Thread(target=background_tasks_loop, daemon=True).start()

# Start gRPC services
Thread(target=grpc_auth.serve, daemon=True).start()

# Initialise REST API
rest_api.cl = cl
rest_api.supporter = supporter

# Start REST API
Thread(target=uvicorn.run, args=(rest_api,), kwargs={
"host": os.getenv("API_HOST", "0.0.0.0"),
"port": int(os.getenv("API_PORT", 3001)),
"root_path": os.getenv("API_ROOT", "")
}, daemon=True).start()

# Start Cloudlink server
asyncio.run(cl.run(host=os.getenv("CL3_HOST", "0.0.0.0"), port=int(os.getenv("CL3_PORT", 3000))))
# Load .env file
from dotenv import load_dotenv
load_dotenv()

import os, sys, asyncio, uvicorn, sentry_sdk
from threading import Thread

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../pkg/legacy')))

from cloudlink import CloudlinkServer
from supporter import Supporter
from security import background_tasks_loop
from grpc_auth import service as grpc_auth
from rest_api import app as rest_api
from events import events


if __name__ == "__main__":
# Initialise Sentry (uses SENTRY_DSN env var)
sentry_sdk.init()

# Create Cloudlink server
cl = CloudlinkServer()

# Create Supporter class
supporter = Supporter(cl)
cl.supporter = supporter

events.add_supporter(supporter)

# Start background tasks loop
Thread(target=background_tasks_loop, daemon=True).start()

# Start gRPC services
Thread(target=grpc_auth.serve, daemon=True).start()

# Initialise REST API
rest_api.cl = cl
rest_api.supporter = supporter

# Start REST API
#Thread(target=uvicorn.run, args=(rest_api,), kwargs={
# "host": os.getenv("API_HOST", "0.0.0.0"),
# "port": int(os.getenv("API_PORT", 3001)),
# "root_path": os.getenv("API_ROOT", "")
#}, daemon=True).start()

# Start Cloudlink server
asyncio.run(cl.run(host=os.getenv("CL3_HOST", "0.0.0.0"), port=int(os.getenv("CL3_PORT", 3000))))
63 changes: 63 additions & 0 deletions cmd/rest/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"log"
"net/http"
"os"
"time"

"github.com/getsentry/sentry-go"
"github.com/joho/godotenv"
"github.com/meower-media/server/pkg/api/rest"
"github.com/meower-media/server/pkg/db"
"github.com/meower-media/server/pkg/emails"
"github.com/meower-media/server/pkg/meowid"
"github.com/meower-media/server/pkg/rdb"
"github.com/meower-media/server/pkg/users"
)

func main() {
// Load dotenv
godotenv.Load()

// Init Sentry
if err := sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("SENTRY_DSN"),
}); err != nil {
panic(err)
}

// Init MeowID
if err := meowid.Init(os.Getenv("NODE_ID")); err != nil {
panic(err)
}

// Init MongoDB
if err := db.Init(os.Getenv("MONGO_URI"), os.Getenv("MONGO_DB")); err != nil {
panic(err)
}

// Init Redis
if err := rdb.Init(os.Getenv("REDIS_URI")); err != nil {
panic(err)
}

// Init token signing keys
if err := users.InitTokenSigningKeys(); err != nil {
panic(err)
}

// Send test email
emails.SendEmail("verify", "Tnix", "[email protected]", "abc123")

// Serve HTTP router
port := os.Getenv("HTTP_PORT")
if port == "" {
port = "3000"
}
log.Println("Serving HTTP server on :" + port)
http.ListenAndServe(":"+port, rest.Router())

// Wait for Sentry events to flush
sentry.Flush(time.Second * 5)
}
41 changes: 41 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module github.com/meower-media/server

go 1.22.5

require (
github.com/getsentry/sentry-go v0.28.1
github.com/go-chi/chi/v5 v5.1.0
github.com/go-playground/validator/v10 v10.11.1
github.com/gorilla/websocket v1.5.3
github.com/joho/godotenv v1.5.1
github.com/pquerna/otp v1.4.0
github.com/redis/go-redis/v9 v9.6.1
github.com/rs/cors v1.11.1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/vmihailenco/msgpack/v5 v5.3.5
github.com/yl2chen/cidranger v1.0.2
go.mongodb.org/mongo-driver v1.16.1
golang.org/x/crypto v0.22.0
gopkg.in/mail.v2 v2.3.1
)

require (
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
)
Loading
Loading