Skip to content

Commit

Permalink
Move admins to YAML config
Browse files Browse the repository at this point in the history
  • Loading branch information
quackduck committed Apr 6, 2022
1 parent 58b2b91 commit 382708a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 47 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ slackAPI.txt*
adminPass.txt
*.gob
*.swp
log.txt
bans.json
devzat-data/log.txt
devzat-data/bans.json
allusers.json
iptables.sh
twitter-creds.json
twitter-creds.json.bak
devzat-config.yml
devzat-creds.yml
devzat-sshkey
admins.json
2 changes: 2 additions & 0 deletions Admin's Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This document is for those who want to manage a self-hosted Devzat server.
git clone https://github.com/quackduck/devzat
cd devzat
```
To compile Devzat, you will need to have Go installed with a minimum version of 1.17.

Now run `go install` to install the Devzat binary globally, or run `go build` to build and keep the binary in the working directory.

## Usage
Expand Down
17 changes: 0 additions & 17 deletions admins.json

This file was deleted.

4 changes: 2 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ func colorCMD(rest string, u *user) {

func adminsCMD(_ string, u *user) {
msg := "Admins: \n"
for i := range admins {
msg += admins[i] + ": " + i + " \n"
for i := range Config.Admins {
msg += Config.Admins[i] + ": " + i + " \n"
}
u.room.broadcast(devbot, msg)
}
Expand Down
11 changes: 6 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
)

type config struct {
Port int `yaml:"port"`
AltPort int `yaml:"alt_port"`
ProfilePort int `yaml:"profile_port"`
DataDir string `yaml:"data_dir"`
KeyFile string `yaml:"key_file"`
Port int `yaml:"port"`
AltPort int `yaml:"alt_port"`
ProfilePort int `yaml:"profile_port"`
DataDir string `yaml:"data_dir"`
KeyFile string `yaml:"key_file"`
Admins map[string]string `yaml:"admins"`

IntegrationConfig string `yaml:"integration_config"`
}
Expand Down
23 changes: 23 additions & 0 deletions devzat-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
port: 22
alt_port: 443
profile_port: 5555
data_dir: devzat-data
key_file: devzat-sshkey
integration_config: devzat-creds.yml
admins:
1eab2de20e41abed903ab2f22e7ff56dc059666dbe2ebbce07a8afeece8d0424: 'Shok: school'
7f0ee4cba8c8d886d654820c4ea09090dc12be00746b9a64b73faab3f83a85c6: 'Benjamin Smith: hackclub, github.com/Merlin04'
09db0042df8c48488e034cd03dfd30dc61a7db35cd7bb8964cd246b958adc1b9: 'Arcade Wise: hackclub, github.com/l3gacyb3ta'
12a9f108e7420460864de3d46610f722e69c80b2ac2fb1e2ada34aa952bbd73e: 'jmw: github.com/ciearius'
15a0a99e4ece5e7a169a0b7df8df87c7a7805207681df908f92052d3d4103287: 'Emma Trzupek: t0rchedf3rn (RHS)'
41fb7ecb8c216491cbe682f2a4c2964db6a9297f74ae48f0ec8bece1089ffec3: 'Leo, gh: GrandWasTaken, added cause idk'
111d1c193354309b040854a74aeb15c985d1fbe4390128dd035fe5407c71f2fd: 'elitedino: github.com/elitedino'
2433e7c03997d13f9117ded9e36cd2d23bddc4d588b8717c4619bedeb3b7e9ad: '@epic: github.com/TAG-Epic'
ac416b02c106e7407e8e53e74b40d96d6f7c11e365c285a8ab825c219f443dcd: 'Tommy Pujol: hackclub'
c90cf5ea8a9bf831a9024ecfd9876a7116a2382653a9ce84a6d80b4dcfa2f979: 'cole: github.com/ColeDrain'
d6acd2f5c5a8ef95563883032ef0b7c0239129b2d3672f964e5711b5016e05f5: 'Arkaeriit: github.com/Arkaeriit'
e9d47bb4522345d019086d0ed48da8ce491a491923a44c59fd6bfffe6ea73317: 'Arav Narula: twitter'
f5c7f9826b6e143f6e9c3920767680f503f259570f121138b2465bb2b052a85d: 'Ella Xu: hackclub'
f466ac6b6be43ba8efbac8406a34cf68f6843f2b79119a82726e4ad6e770ec7d: 'electronoob: electronoob.com'
ff7d1586cdecb9fbd9fcd4c9548522493c29172bc3121d746c83b28993bd723e: 'Ishan Goel: quackduck'

File renamed without changes.
22 changes: 2 additions & 20 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
_ "embed"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"math"
"math/rand"
Expand All @@ -20,26 +19,9 @@ import (
)

var (
art = getASCIIArt()
admins = getAdmins()
art = getASCIIArt()
)

func getAdmins() map[string]string {
data, err := ioutil.ReadFile(Config.DataDir + "/admins.json")
if err != nil {
fmt.Println("Error reading admins.json: " + err.Error() + ". Make an admins.json file to add admins.")
return nil
}
var adminsList map[string]string // id to info
err = json.Unmarshal(data, &adminsList)
if err != nil {
fmt.Println("Error in admins.json formatting.")
return nil
}
fmt.Println(adminsList)
return adminsList
}

func getASCIIArt() string {
b, _ := ioutil.ReadFile(Config.DataDir + "/art.txt")
if b == nil {
Expand Down Expand Up @@ -85,7 +67,7 @@ func autogenCommands(cmds []cmd) string {

// check if a user is an admin
func auth(u *user) bool {
_, ok := admins[u.id]
_, ok := Config.Admins[u.id]
return ok
}

Expand Down

0 comments on commit 382708a

Please sign in to comment.