Skip to content

Commit

Permalink
Added script to set initial admin account
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie- committed Sep 16, 2018
1 parent 5174415 commit 091b368
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN git clone https://github.com/Jamie-/ctf-flag-tracker.git /opt/tracker/
# Setup app
RUN cd /opt/tracker && make setup && make depends
RUN mkdir -p /srv/tracker
RUN ln -s /opt/tracker/setadmin.sh /usr/bin/setadmin

EXPOSE 8080
VOLUME "/srv/tracker"
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ wget https://raw.githubusercontent.com/Jamie-/ctf-flag-tracker/master/config.sam
docker run --name=tracker --restart=always -p8080:8080 -v /srv/docker/tracker:/srv/tracker -d tracker
```

6. Create initial database:
6. Create initial admin user:
Visit the app in your browser and create an account `http://<ip_address>:8080/register`
After creating an account, grant it admin priviledges as below
```
docker exec -it tracker /bin/bash
# cd /opt/tracker
# make init-db
$ docker exec -it tracker /bin/bash
# setadmin <username>
# exit
```
28 changes: 28 additions & 0 deletions setadmin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
tracker_path="/opt/tracker"
if [ -f "$tracker_path/venv/bin/python3" ]; then
$("$tracker_path/venv/bin/python3" <<EOF
import os
os.chdir('$tracker_path')
import tracker
with tracker.app.app_context():
u = tracker.user.get_user('$1')
u.set_admin(True)
EOF
)
RES=$?
else
$("./venv/bin/python3" <<EOF
import tracker
with tracker.app.app_context():
u = tracker.user.get_user('$1')
u.set_admin(True)
EOF
)
RES=$?
fi
if [ "$RES" -eq 0 ]; then
echo "Set admin privs for $1"
else
echo "Failed to set admin privs for $1"
fi

0 comments on commit 091b368

Please sign in to comment.