Skip to content

Commit

Permalink
added logging, updated readme and html template
Browse files Browse the repository at this point in the history
  • Loading branch information
gal committed Jun 19, 2022
1 parent 46b9488 commit 7d72b28
Show file tree
Hide file tree
Showing 19 changed files with 324 additions and 83 deletions.
Binary file added .assets/oauth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/welcome-message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ jobs:
&& sudo apt-get install -y git
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- uses: actions/checkout@v3
# fetch all history for all branches and tags, so that our `make` targets can get tags
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build the Docker image
run: docker build . --file Dockerfile
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/*.swp
whodis.exe
whodis
.env
servers
servers
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ RUN go mod download

COPY . .

# Get latest tag
RUN git describe --abbrev=0 > /version

RUN go install github.com/UCCNetsoc/whodis/cmd/whodis

CMD [ "go", "run", "*.go" ]
Expand All @@ -22,5 +25,6 @@ FROM alpine
WORKDIR /bin

COPY --from=dev /go/bin/whodis ./whodis
COPY --from=dev /version /version

CMD ["sh", "-c", "whodis -p"]
CMD ["sh", "-c", "export BOT_VERSION=$(cat /version) && whodis -p"]
67 changes: 66 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
# Whodis

Discord bot & API to both authenticate and authorize discord members
[![CI](https://github.com/UCCNetsoc/whodis/actions/workflows/main.yml/badge.svg)](https://github.com/UCCNetsoc/whodis/actions/workflows/main.yml) [![!Whodis Bot Invite link](https://img.shields.io/badge/Whodis-Bot%20Invite-9cf)](https://google.com)

A discord bot and API to authenticate Discord members as being UCC students.

## How it works

When a new user joins your _registration channel_, they will see a message from Whodis, welcoming them to the server, and prompts them to click a button to register.

<img src=".assets/welcome-message.png" alt="Welcome Message" height="150px" />

When they click the button, Whodis takes note of their Discord ID, and sends a message only they can see with a button, which will direct them to login page with their UCC Umail account as an option. After successfully choosing their Umail account, they will come to a landing page informing them of their successful authentication.

<img src="./.assets/oauth.png" height="350px" />

When they go back to Discord, they will have gained a role(s), giving them permission to see more of the server.

---

## How Do I Use this Bot on my Server?

A server member with Admin privileges can add the bot to their server by doing the following:

1. Invite Whodis to your Discord server.
2. Create the `@Member` role. Make this role able to access normal channels in your server.
3. Create a `#registration` and `#registration-help` channel. Make these channels incassessible by `@Member`, but allow moderators and `@everyone`. This way, only newly-joined users and moderators can see these channels.

> Note this will make it so all existing non-moderator members of your Discord server will either have to be manually given the `@Member` role, or authenticate with Whodis.
4. In the `#registration` channel, run the `/setup` command, and give the parameters you require.

| Parameter | Required | Description |
| ------------------- | --------- | ------------------------------------------------------------------------|
| `announce-channel` || The channel where new users are announc ed |
| `logging-channel` || The channel where logs are sent |
| `additional-role-1` || An additional role that can be given to new members, e.g. `@22/23` |
| `additional-role-2` || Another additional role that can be given to new members, e.g. `@newbies` |

---

## Need to use a different Mail Domain or want to self-host this Bot?

If you need to use a mail domain that isn't `umail.ucc.ie` you can fork this repo and use Docker to run the bot, providing a specific mail domain to use through environment variables.

To see all necessary environment variables, check [defaults.go](./config/defaults.go) (Environment variables will be in the form of UPPER_CASE).

---

## Privacy Concerns

Whodis and as such, Netsoc do not collect any personal information, as the bot and API are stateless. When a user clicks the first button, the following data is encoded into a new button:

- The User's Discord ID
- The Server's registered role, and an optional second role to give to newly-registered users.
- The server's Guild ID
- The server's welcome message Channel ID
- The server's moderator logging Channel ID

This data does not get stored on any database, and is encrypted on the backend, to stop a user tampering-with and gaining access to a role not intended for them to have.

**_Whodis does not store any Users' Discord ID or Umail address_**

---

## Help

If you have any questions or need help, please contact the Netsoc SysAdmins on [discord](https://discord.netsoc.co/), by email at [[email protected]](mailto:[email protected]), or [create an issue](https://github.com/UCCNetsoc/whodis/issues/new).
4 changes: 3 additions & 1 deletion cmd/whodis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ func main() {
log.WithError(err)
return
}

go api.InitAPI(s)

s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) {
log.Info("Bot is has registered handlers")
log.Info("Bot has registered handlers")
})
s.Open()
commands.RegisterSlashCommands(s)
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.7'

services:
bot:
build: .
container_name: whodis_local
ports:
- "8080:8080"
environment:
DISCORD_TOKEN: ${DISCORD_TOKEN}
DISCORD_APP_ID: ${DISCORD_APP_ID}
DISCORD_BOT_INVITE: ${DISCORD_BOT_INVITE}
API_URL: ${API_URL}
API_PORT: '8080'
API_SECRET: ${API_SECRET}
OAUTH_GOOGLE_ID: ${OAUTH_GOOGLE_ID}
OAUTH_GOOGLE_SECRET: ${OAUTH_GOOGLE_SECRET}
33 changes: 20 additions & 13 deletions internal/api/assets/result.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
font-size: 14px;
font-weight: 400;
font-family: Roboto, sans-serif !important;
color: #fff
color: #fff;
min-height: 100vh;
position: relative;
}

#header {
Expand All @@ -39,12 +41,12 @@
#content-body {
padding-top: 16px;
border-top: 1px solid #333;
color: gray;
color: #b9b9b9;
border-bottom: 1px solid #333
}

p {
max-width: 380px;
max-width: 400px;
margin: 0 auto;
padding: 16px;
}
Expand Down Expand Up @@ -87,6 +89,15 @@
a {
color: #fff
}

footer {
width: 100%;
position: absolute;
left: 0;
right: 0;
bottom: 0;
padding-bottom: 16px;
}
</style>
<script type="text/javascript">
function stopReload(){
Expand All @@ -109,20 +120,16 @@
<h1>Whodis Authentication Service</h1>
</div>
<div id="content-body">
<h2>{{.Type}}</h2>
<h2 id="status"><span>Success</span></h2>
<p style="color: white">{{.Message}}</p>
<p>Contact Netsoc SysAdmins on our <a href='http://discord.netsoc.co'>Discord</a> if you encounter any issues
<p>Contact Netsoc SysAdmins on our <a href='http://discord.netsoc.co'>Discord</a>, or <a href="https://github.com/UCCNetsoc/whodis/issues/new">create an issue</a> if you encounter any issues
</div>
<div style="
margin: 0 auto;
text-align: center;
padding-top: 16px;
font-size: 11px;
color: gray;
">
<footer>
<a target="_blank" href="https://discord.netsoc.co">Discord</a>
<span></span>
<a target="_blank" href="https://wiki.netsoc.co/en/services/terms-of-service">Terms of Service</a>
<a target="_blank" href="https://github.com/UCCNetsoc/whodis">Source Code</a>
<span></span>
<a target="_blank" href="https://github.com/UCCNetsoc/whodis/blob/master/README.md#privacy-concerns">Privacy Notice</a>
</div>
</body>
</html>
12 changes: 9 additions & 3 deletions internal/api/response.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
package api

import (
"html/template"
"net/http"

"github.com/Strum355/log"
)

type Resp struct {
Code int `json:"code"`
Type string `json:"type"`
Type template.HTML `json:"type"`
Message string `json:"message"`
Fields map[string]interface{} `json:"fields,omitempty"`
}

const (
successType = `<span style='color: limegreen'>Success</span>`
errorType = `<span style='color: red'>Error</span>`
)

func AccessErrorResponse(status int, message string, respErr error) *Resp {
if respErr != nil {
log.WithError(respErr).Error(message)
} else {
log.Error(message)
}
return &Resp{Code: status, Type: "Error", Message: message}
return &Resp{Code: status, Type: errorType, Message: message}
}

func AccessSuccessResponse(message string, uid string, gid string) *Resp {
fields := map[string]interface{}{"user": uid, "guild": gid}
log.WithFields(fields).Info(message)
return &Resp{Code: http.StatusOK, Type: "Success", Message: message, Fields: fields}
return &Resp{Code: http.StatusOK, Type: successType, Message: message, Fields: fields}
}
Loading

0 comments on commit 7d72b28

Please sign in to comment.