Compare commits
14 Commits
v0.0.1
...
bbe70647d7
| Author | SHA1 | Date | |
|---|---|---|---|
|
bbe70647d7
|
|||
|
d6dffc0464
|
|||
|
fb9295c260
|
|||
|
c4ae4561e3
|
|||
|
2902624637
|
|||
|
5049796d07
|
|||
|
5efe4860fc
|
|||
|
499a7e348b
|
|||
|
ed94263050
|
|||
|
4841344d63
|
|||
|
3266dbafa9
|
|||
|
b56ece2216
|
|||
|
0383b47b8e
|
|||
|
afd5286ef5
|
@@ -1,6 +1,11 @@
|
|||||||
name: Build Docker
|
name: Build Docker
|
||||||
run-name: Build Docker Images
|
run-name: Build Docker Images
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
tags-ignore:
|
||||||
|
- '*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Build Master:
|
Build Master:
|
||||||
|
|||||||
@@ -7,10 +7,54 @@ on:
|
|||||||
- '*'
|
- '*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
TEST:
|
Build Master:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Print tag
|
- name: Install Docker
|
||||||
run: echo "tag=${GITHUB_REF#refs/tags/}"
|
run : |
|
||||||
|
apt-get install ca-certificates curl gnupg
|
||||||
|
install -m 0755 -d /etc/apt/keyrings
|
||||||
|
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||||
|
chmod a+r /etc/apt/keyrings/docker.gpg
|
||||||
|
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
apt-get update
|
||||||
|
apt-get install docker-ce-cli -y
|
||||||
|
- name: Build Docker image
|
||||||
|
run : |
|
||||||
|
cd master
|
||||||
|
echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin
|
||||||
|
tag=${GITHUB_REF#refs/tags/}
|
||||||
|
|
||||||
|
docker build -t hnshosting-master:release-$tag .
|
||||||
|
docker tag hnshosting-master:release-$tag git.woodburn.au/nathanwoodburn/hnshosting-master:release-$tag
|
||||||
|
docker push git.woodburn.au/nathanwoodburn/hnshosting-master:release-$tag
|
||||||
|
docker tag hnshosting-master:release-$tag git.woodburn.au/nathanwoodburn/hnshosting-master:release
|
||||||
|
docker push git.woodburn.au/nathanwoodburn/hnshosting-master:release
|
||||||
|
|
||||||
|
Build Bot:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Install Docker
|
||||||
|
run : |
|
||||||
|
apt-get install ca-certificates curl gnupg
|
||||||
|
install -m 0755 -d /etc/apt/keyrings
|
||||||
|
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||||
|
chmod a+r /etc/apt/keyrings/docker.gpg
|
||||||
|
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
apt-get update
|
||||||
|
apt-get install docker-ce-cli -y
|
||||||
|
- name: Build Docker image
|
||||||
|
run : |
|
||||||
|
cd discord-bot
|
||||||
|
echo "${{ secrets.DOCKERGIT_TOKEN }}" | docker login git.woodburn.au -u nathanwoodburn --password-stdin
|
||||||
|
tag=${GITHUB_REF#refs/tags/}
|
||||||
|
|
||||||
|
docker build -t hnshosting-bot:release-$tag .
|
||||||
|
docker tag hnshosting-bot:release-$tag git.woodburn.au/nathanwoodburn/hnshosting-bot:release-$tag
|
||||||
|
docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:release-$tag
|
||||||
|
docker tag hnshosting-bot:release-$tag git.woodburn.au/nathanwoodburn/hnshosting-bot:release
|
||||||
|
docker push git.woodburn.au/nathanwoodburn/hnshosting-bot:release
|
||||||
10
README.md
10
README.md
@@ -18,6 +18,10 @@ The bot will be used to provide an easier way to manage the master server.
|
|||||||
| Red Connections | Secured by VPN or over LAN ONLY. (NOT API SECURED) |
|
| Red Connections | Secured by VPN or over LAN ONLY. (NOT API SECURED) |
|
||||||
| Yellow Connections | HTTP/HTTPS public traffic |
|
| Yellow Connections | HTTP/HTTPS public traffic |
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- [x] Add new worker server to master server pool
|
||||||
|
- [x] Create wordpress site on random worker server
|
||||||
|
- [x] Optional Free mode (see Bot section)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -106,3 +110,9 @@ Docker install
|
|||||||
```sh
|
```sh
|
||||||
docker run -d -e MASTER_IP=<MASTER SERVER IP> -e DISCORD_TOKEN=<YOUR-BOT-TOKEN> -e LICENCE_KEY=your-api-key -e WORKER_KEY=your-api-key --name hnshosting-bot git.woodburn.au/nathanwoodburn/hnshosting-bot:latest
|
docker run -d -e MASTER_IP=<MASTER SERVER IP> -e DISCORD_TOKEN=<YOUR-BOT-TOKEN> -e LICENCE_KEY=your-api-key -e WORKER_KEY=your-api-key --name hnshosting-bot git.woodburn.au/nathanwoodburn/hnshosting-bot:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Enable the free mode by setting the following environment variable.
|
||||||
|
This will allow you to create a wordpress site without using a licence key using the /createsite command.
|
||||||
|
```
|
||||||
|
FREE_MODE: true
|
||||||
|
```
|
||||||
@@ -13,9 +13,14 @@ Master_Port = os.getenv('MASTER_PORT')
|
|||||||
if Master_Port == None:
|
if Master_Port == None:
|
||||||
Master_Port = "5000"
|
Master_Port = "5000"
|
||||||
|
|
||||||
FREE_LICENCE = os.getenv('FREE_LICENCE')
|
FREE_LICENCE = os.getenv('FREE_MODE')
|
||||||
if FREE_LICENCE == None:
|
if FREE_LICENCE == None:
|
||||||
FREE_LICENCE = False
|
FREE_LICENCE = False
|
||||||
|
else:
|
||||||
|
if FREE_LICENCE.lower() == "true":
|
||||||
|
FREE_LICENCE = True
|
||||||
|
else:
|
||||||
|
FREE_LICENCE = False
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
client = discord.Client(intents=intents)
|
client = discord.Client(intents=intents)
|
||||||
@@ -50,7 +55,6 @@ async def listworkers(ctx):
|
|||||||
@tree.command(name="licence", description="Gets a licence key")
|
@tree.command(name="licence", description="Gets a licence key")
|
||||||
async def license(ctx):
|
async def license(ctx):
|
||||||
if ctx.user.id != ADMINID:
|
if ctx.user.id != ADMINID:
|
||||||
if FREE_LICENCE == False: # If free licences are enabled then anyone can get a licence
|
|
||||||
await ctx.response.send_message("You do not have permission to use this command",ephemeral=True)
|
await ctx.response.send_message("You do not have permission to use this command",ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -65,7 +69,17 @@ async def license(ctx):
|
|||||||
await ctx.response.send_message(f"Error getting license\n" + r.text,ephemeral=True)
|
await ctx.response.send_message(f"Error getting license\n" + r.text,ephemeral=True)
|
||||||
|
|
||||||
@tree.command(name="createsite", description="Create a new WordPress site")
|
@tree.command(name="createsite", description="Create a new WordPress site")
|
||||||
async def createsite(ctx, domain: str, licence: str):
|
async def createsite(ctx, domain: str, licence: str = None):
|
||||||
|
if FREE_LICENCE == True: # If free licences are enabled then auto generate a licence
|
||||||
|
r = requests.post(f"http://{Master_IP}:{Master_Port}/add-licence",headers={"key":os.getenv('LICENCE_KEY')})
|
||||||
|
if r.status_code == 200:
|
||||||
|
json = r.json()
|
||||||
|
if json['success'] == "true":
|
||||||
|
licence = json['licence_key']
|
||||||
|
else:
|
||||||
|
await ctx.response.send_message(f"Error getting license\n" + json['error'])
|
||||||
|
return
|
||||||
|
|
||||||
r = requests.post(f"http://{Master_IP}:{Master_Port}/new-site?domain={domain}",headers={"key":licence})
|
r = requests.post(f"http://{Master_IP}:{Master_Port}/new-site?domain={domain}",headers={"key":licence})
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
json = r.json()
|
json = r.json()
|
||||||
|
|||||||
@@ -37,14 +37,22 @@ def new_site():
|
|||||||
|
|
||||||
# Verify both API key and domain exist
|
# Verify both API key and domain exist
|
||||||
if api_key == None:
|
if api_key == None:
|
||||||
return jsonify({'error': 'Missing API key', 'success': 'false'})
|
return jsonify({'error': 'No licence provided', 'success': 'false'})
|
||||||
|
|
||||||
if domain == None:
|
if domain == None:
|
||||||
return jsonify({'error': 'Missing domain', 'success': 'false'})
|
return jsonify({'error': 'Missing domain', 'success': 'false'})
|
||||||
|
|
||||||
# Check if API key is a valid site key
|
# Check if API key is a valid site key
|
||||||
if api_key not in open('/data/licence_key.txt', 'r').read():
|
key_file = open('/data/licence_key.txt', 'r')
|
||||||
return jsonify({'error': 'Invalid API key', 'success': 'false'})
|
valid_key = False
|
||||||
|
for line in key_file.readlines():
|
||||||
|
if api_key == line.strip('\n'):
|
||||||
|
valid_key = True
|
||||||
|
break
|
||||||
|
key_file.close()
|
||||||
|
if not valid_key:
|
||||||
|
return jsonify({'error': 'Invalid licence', 'success': 'false'})
|
||||||
|
|
||||||
|
|
||||||
# Check if domain already exists
|
# Check if domain already exists
|
||||||
if site_exists(domain):
|
if site_exists(domain):
|
||||||
|
|||||||
Reference in New Issue
Block a user