Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6978bbd03e | ||
|
|
d88f61b281 | ||
|
|
c84dac6b01 | ||
|
|
abe37800ec | ||
|
|
8aef1f0dc7 | ||
|
|
1c01c27326 | ||
|
|
a766c1eaa2 | ||
|
|
a457c2be7b | ||
|
|
6a5ce6ddb9 | ||
|
|
bd88617dc5 | ||
|
|
77f1fbc2cc | ||
|
|
0a0f76d84e | ||
|
|
364ec655a0 | ||
|
|
9fe79c9f23 | ||
|
|
446d672004 | ||
|
|
fe1cb39bc5 | ||
|
|
4737aa1295 | ||
|
|
77871dd56a | ||
|
|
1a0fe6e304 | ||
|
|
26778f0219 | ||
|
|
a210e23bb3 | ||
|
|
34e698e309 | ||
|
|
f33e0e342c | ||
|
|
dfb78b3669 | ||
|
|
5d26ab292b | ||
|
|
837f939de1 | ||
|
|
725496cc0f | ||
|
|
6fa67f0531 | ||
|
|
9b9d70f711 | ||
|
|
c896a4c150 | ||
|
|
bb1860b5c8 | ||
|
|
653594ca48 | ||
|
|
73dad4cb6b | ||
|
|
dd6a9d1eaf | ||
|
|
3c74331a74 | ||
|
|
7bfcb1caff | ||
|
|
0a3441428a | ||
|
|
c41e999028 | ||
|
|
1a9d57ed0c | ||
|
|
d2c930fa17 | ||
|
|
f8d33cbc4d | ||
|
|
2d85a23a20 | ||
|
|
36de929577 | ||
|
|
23f1fdbb3f | ||
|
|
ee99218f2a | ||
|
|
d5e6be7cba |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -109,6 +109,9 @@ venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
Vagrantfile
|
||||
.vagrant
|
||||
ubuntu-xenial-16.04-cloudimg-console.log
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
@@ -131,3 +134,5 @@ dmypy.json
|
||||
# Secrets & env
|
||||
secrets.yml
|
||||
.vscode
|
||||
.DS_Store
|
||||
compiledstatic/
|
||||
76
CODE_OF_CONDUCT.md
Normal file
76
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at shynet@sendmiles.email. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see
|
||||
https://www.contributor-covenant.org/faq
|
||||
50
Dockerfile
50
Dockerfile
@@ -1,33 +1,35 @@
|
||||
FROM python:3
|
||||
FROM python:3-alpine
|
||||
|
||||
# Getting things ready
|
||||
WORKDIR /usr/src/shynet
|
||||
COPY Pipfile.lock Pipfile ./
|
||||
|
||||
RUN apt update
|
||||
RUN apt install -y gettext
|
||||
|
||||
# URL from https://github.com/shlinkio/shlink/issues/596 :)
|
||||
RUN curl "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=G4Lm0C60yJsnkdPi&suffix=tar.gz" | tar -xvz -C /tmp
|
||||
RUN curl "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=G4Lm0C60yJsnkdPi&suffix=tar.gz" | tar -xvz -C /tmp
|
||||
RUN mv /tmp/GeoLite2*/*.mmdb /etc
|
||||
|
||||
RUN pip install pipenv
|
||||
COPY Pipfile.lock ./
|
||||
COPY Pipfile ./
|
||||
RUN pipenv install --system --deploy
|
||||
|
||||
COPY shynet .
|
||||
RUN python manage.py collectstatic --noinput
|
||||
RUN python manage.py compilemessages
|
||||
|
||||
# Install dependencies & configure machine
|
||||
ARG GF_UID="500"
|
||||
ARG GF_GID="500"
|
||||
RUN apk update && \
|
||||
apk add gettext curl bash && \
|
||||
# URL from https://github.com/shlinkio/shlink/issues/596 :)
|
||||
curl "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=G4Lm0C60yJsnkdPi&suffix=tar.gz" | tar -xvz -C /tmp && \
|
||||
curl "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=G4Lm0C60yJsnkdPi&suffix=tar.gz" | tar -xvz -C /tmp && \
|
||||
mv /tmp/GeoLite2*/*.mmdb /etc && \
|
||||
apk del curl && \
|
||||
apk add --no-cache postgresql-libs && \
|
||||
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev && \
|
||||
pip install pipenv && \
|
||||
pipenv install --system --deploy && \
|
||||
apk --purge del .build-deps && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
rm /var/cache/apk/* && \
|
||||
addgroup --system -g $GF_GID appgroup && \
|
||||
adduser appuser --system --uid $GF_UID -G appgroup
|
||||
|
||||
# add group & user
|
||||
RUN groupadd -r -g $GF_GID appgroup && \
|
||||
useradd appuser -r -u $GF_UID -g appgroup
|
||||
# Install Shynet
|
||||
COPY shynet .
|
||||
RUN python manage.py collectstatic --noinput && \
|
||||
python manage.py compilemessages
|
||||
|
||||
# Launch
|
||||
USER appuser
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD [ "./webserver.sh" ]
|
||||
ENTRYPOINT [ "./entrypoint.sh" ]
|
||||
|
||||
231
GUIDE.md
231
GUIDE.md
@@ -1,19 +1,17 @@
|
||||
# Getting Started
|
||||
# Usage Guide
|
||||
|
||||
## Table of Contents
|
||||
|
||||
* [Installation](#installation)
|
||||
* [Basic Installation](#basic-installation)
|
||||
- [Installation](#installation)
|
||||
- [Updating Your Configuration](#updating-your-configuration)
|
||||
- [Enhancements](#enhancements)
|
||||
* [Installation with SSL](#installation-with-ssl)
|
||||
<!--
|
||||
* Usage
|
||||
* Adding Shynet tracking to your first website
|
||||
* Adding a new website
|
||||
* Adding a new administrator
|
||||
* Setting up a reverse proxy
|
||||
* Cloudflare
|
||||
* nginx
|
||||
-->
|
||||
* [Configuring a Reverse Proxy](#configuring-a-reverse-proxy)
|
||||
+ [Cloudflare](#cloudflare)
|
||||
+ [Nginx](#nginx)
|
||||
+ [Troubleshooting](#troubleshooting)
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -27,81 +25,40 @@ Before continuing, please be sure to have the latest version of Docker installed
|
||||
|
||||
1. Pull the latest version of Shynet using `docker pull milesmcc/shynet:latest`. If you don't have Docker installed, [install it](https://docs.docker.com/get-docker/).
|
||||
|
||||
2. Have a PostgreSQL server ready to go. This can be on the same machine as the deployment, or elsewhere. You'll just need a username, password, host, and port (default is `5432`). (For info on how to setup a PostgreSQL server on Ubuntu, follow [this guide](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04)).
|
||||
2. Have a PostgreSQL server ready to go. This can be on the same machine as the deployment, or elsewhere. You'll just need a username, password, host, and port. (For info on how to setup a PostgreSQL server on Ubuntu, follow [this guide](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04)).
|
||||
|
||||
3. Configure an environment file for Shynet. (For example, create a file called `.env`.) Be sure to swap out the variables below with the correct values for your setup. (The comments refer to the lines that follow. Note that Docker is weird with quotes, so it tends to be better to omit them from your env file.)
|
||||
3. Configure an environment file for Shynet, using [this file](/TEMPLATE.env) as a template. (This file is typically named `.env`.) Make sure you set the database settings, or Shynet won't be able to run.
|
||||
|
||||
```
|
||||
# Database
|
||||
DB_NAME=<your db name>
|
||||
DB_USER=<your db user>
|
||||
DB_PASSWORD=<your db user password>
|
||||
DB_HOST=<your db host>
|
||||
DB_PORT=<your db port>
|
||||
4. Launch the Shynet server by running `docker run --env-file=<your env file> milesmcc/shynet:latest`. Watch the output of the script; if it's the first run, you'll see a temporary password printed that you can use to log in. You may need to bind Docker's port 8080 (where Shynet runs) to your local port 80 (http); this can be done using the flag `-p 80:8080` after `run`.
|
||||
|
||||
# General Django settings
|
||||
DJANGO_SECRET_KEY=<your Django secret key; just a random string>
|
||||
# Don't leak error details to visitors, very important
|
||||
DEBUG=False
|
||||
# Unless you are using an external Celery task queue, make sure this
|
||||
# is set to True.
|
||||
CELERY_TASK_ALWAYS_EAGER=True
|
||||
# For better security, set this to your deployment's domain. Comma separated.
|
||||
ALLOWED_HOSTS=*
|
||||
# Set to True (capitalized) if you want people to be able to sign up for your Shynet instance (not recommended)
|
||||
SIGNUPS_ENABLED=False
|
||||
# Change as required
|
||||
TIME_ZONE=America/New_York
|
||||
# Set to "False" if you will not be serving content over HTTPS
|
||||
SCRIPT_USE_HTTPS=True
|
||||
```
|
||||
5. Visit your service's homepage, and verify everything looks right! You should see a login prompt. Log in with the credentials from step 4. You'll probably be prompted to "confirm your email"—if you haven't set up an email server, the confirmation email will be printed to the console instead.
|
||||
|
||||
For more advanced deployments, you may consider adding the following settings to your environment file. **The following settings are optional, and not required for simple deployments.**
|
||||
6. Create a service by clicking "+ Create Service" in the top right hand corner. Fill out the options as appropriate. Once you're done, press "create" and you'll be redirected to your new service's analytics page.
|
||||
|
||||
```env
|
||||
# Email settings
|
||||
EMAIL_HOST_USER=<your SMTP email user>
|
||||
EMAIL_HOST_PASSWORD=<your SMTP email password>
|
||||
EMAIL_HOST=<your SMTP email hostname>
|
||||
SERVER_EMAIL=Shynet <noreply@shynet.example.com>
|
||||
7. Finally, click on "Manage" in the top right of the service's page to get the tracking script code. Inject this script on all pages you'd like the service to track.
|
||||
|
||||
# Redis and queue settings; not necessary for single-instance deployments
|
||||
REDIS_CACHE_LOCATION=redis://redis.default.svc.cluster.local/0
|
||||
# If set, make sure CELERY_TASK_ALWAYS_EAGER is False
|
||||
CELERY_BROKER_URL=redis://redis.default.svc.cluster.local/1
|
||||
## Updating Your Configuration
|
||||
|
||||
# Other Shynet settings
|
||||
# How frequently should the monitoring script "phone home" (in ms)?
|
||||
SCRIPT_HEARTBEAT_FREQUENCY=5000
|
||||
# Should only superusers (admins) be able to create services? This is helpful
|
||||
# when you'd like to invite others to your Shynet instance but don't want
|
||||
# them to be able to create services of their own.
|
||||
ONLY_SUPERUSERS_CREATE=False
|
||||
```
|
||||
When you first setup Shynet, you set a number of environment variables that determine first-run initialization settings (these variables start with `SHYNET_`). Once they're first set, though, changing them won't have any effect. Be sure to run the following commands in the same way that you deploy Shynet (i.e., linked to the same database).
|
||||
|
||||
4. Setup the Shynet database by running `docker run --env-file=<your env file> milesmcc/shynet:latest python manage.py migrate`.
|
||||
* Create an admin account by running `docker run --env-file=<your env file> milesmcc/shynet:latest python manage.py registeradmin <your email>`. The command will print a temporary password that you'll be able to use to log in.
|
||||
|
||||
5. Create your admin account by running `docker run --env-file=<your env file> milesmcc/shynet:latest python manage.py registeradmin <your email>`. The command will print a temporary password that you'll be able to use to log in.
|
||||
* Configure Shynet's hostname (e.g. `shynet.example.com` or `localhost:8000`) by running `docker run --env-file=<your env file> milesmcc/shynet:latest python manage.py hostname "<your hostname>"`. This doesn't affect Shynet's bind port; instead, it determines what hostname to inject into the tracking script. (So you'll want to use the "user-facing" hostname here.)
|
||||
|
||||
6. Configure Shynet's hostname (e.g. `shynet.example.com` or `localhost:8000`) by running `docker run --env-file=<your env file> milesmcc/shynet:latest python manage.py hostname "<your hostname>"`. This doesn't affect Shynet's bind port; instead, it determines what hostname to inject into the tracking script. (So you'll want to use the "user-facing" hostname here.)
|
||||
* Name your Shynet instance by running `docker run --env-file=<your env file> milesmcc/shynet:latest python manage.py whitelabel "<your instance name>"`. This could be something like "My Shynet Server" or "Acme Analytics"—whatever suits you.
|
||||
|
||||
7. Name your Shynet instance by running `docker run --env-file=<your env file> milesmcc/shynet:latest python manage.py whitelabel "<your instance name>"`. This could be something like "My Shynet Server" or "Acme Analytics"—whatever suits you.
|
||||
---
|
||||
|
||||
8. Launch the Shynet server by running `docker run --env-file=<your env file> milesmcc/shynet:latest`. You may need to bind Docker's port 8080 (where Shynet runs) to your local port 80 (http); this can be done using the flag `-p 80:8080` after `run`.
|
||||
## Enhancements
|
||||
|
||||
9. Visit your service's homepage, and verify everything looks right! You should see a login prompt. Log in with the credentials from step 5. You'll probably be prompted to "confirm your email"—if you haven't set up an email server, the confirmation email will be printed to the console instead.
|
||||
|
||||
10. Create a service by clicking "+ Create Service" in the top right hand corner. Fill out the options as appropriate. Once you're done, press "create" and you'll be redirected to your new service's analytics page.
|
||||
|
||||
11. Finally, click on "Manage" in the top right of the service's page to get the tracking script code. Inject this script on all pages you'd like the service to track.
|
||||
|
||||
### Installation with SSL
|
||||
|
||||
If you are going to be running Shynet through a reverse proxy, please use the [Basic Installation](#basic-installation) guide instead.
|
||||
If you are going to be running Shynet through a reverse proxy, please see [Configuring a Reverse Proxy](#configuring-a-reverse-proxy) instead.
|
||||
|
||||
0. We'll be cloning this into the home directory to make this installation easier, so run `cd ~/` if you need to.
|
||||
|
||||
1. Instead of pulling from Docker, we will be pulling from GitHub and building in Docker so that we may easily add SSL certificates. You will want to run `git clone https://github.com/milesmcc/shynet.git` to clone the GitHub repo to your computer.
|
||||
1. Instead of pulling from Docker, we will be pulling from GitHub and building using Docker in order to easily add SSL certificates. You will want to run `git clone https://github.com/milesmcc/shynet.git` to clone the GitHub repo to your current working directory.
|
||||
|
||||
2. To install `certbot` follow [the guide here](https://certbot.eff.org/instructions) or follow along below
|
||||
* Ubuntu 18.04
|
||||
@@ -113,7 +70,7 @@ If you are going to be running Shynet through a reverse proxy, please use the [B
|
||||
* `sudo apt-get install certbot`
|
||||
|
||||
3. Run `sudo certbot certonly --standalone` and follow the instructions to generate your SSL certificate.
|
||||
* If you registering it to a domain name like `example.com`, please be sure to point your DNS records to your server before running `certbot`.
|
||||
* If you registering the certificate to a domain name like `example.com`, please be sure to point your DNS records to your current server before running `certbot`.
|
||||
|
||||
4. We are going to move the SSL certificates to the Shynet repo with with command below. Replace `<domain>` with the domain name you used in step 3.
|
||||
* `cp /etc/letsencrypt/live/<domain>/{cert,privkey}.pem ~/shynet/shynet/`
|
||||
@@ -123,77 +80,107 @@ If you are going to be running Shynet through a reverse proxy, please use the [B
|
||||
* `mv ~/shynet/shynet/ssl.webserver.sh ~/shynet/shynet/webserver.sh`
|
||||
|
||||
6. Now we build the image!
|
||||
* `docker image build shynet -t milesmcc/shynet:latest-ssl`
|
||||
* `docker image build shynet -t shynet-ssl:latest`
|
||||
|
||||
7. Have a PostgreSQL server ready to go. This can be on the same machine as the deployment, or elsewhere. You'll just need a username, password, host, and port (default is `5432`). (For info on how to setup a PostgreSQL server on Ubuntu, follow [this guide](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04)).
|
||||
|
||||
8. Configure an environment file for Shynet. (For example, create a file called `.env`.) Be sure to swap out the variables below with the correct values for your setup. (The comments refer to the lines that follow. Note that Docker is weird with quotes, so it tends to be better to omit them from your env file.)
|
||||
8. Follow the [Basic Installation](#basic-installation) guide with just one modification: in step #4, change the local bind port from `80` to `443`, and use `shynet-ssl:latest` as your Docker image instead of `milesmcc/shynet:latest`.
|
||||
|
||||
```
|
||||
# Database
|
||||
DB_NAME=<your db name>
|
||||
DB_USER=<your db user>
|
||||
DB_PASSWORD=<your db user password>
|
||||
DB_HOST=<your db host>
|
||||
DB_PORT=<your db port>
|
||||
### Configuring a Reverse Proxy
|
||||
|
||||
# General Django settings
|
||||
DJANGO_SECRET_KEY=<your Django secret key; just a random string>
|
||||
# Don't leak error details to visitors, very important
|
||||
DEBUG=False
|
||||
# Unless you are using an external Celery task queue, make sure this
|
||||
# is set to True.
|
||||
CELERY_TASK_ALWAYS_EAGER=True
|
||||
# For better security, set this to your deployment's domain. Comma separated.
|
||||
ALLOWED_HOSTS=*
|
||||
# Set to True (capitalized) if you want people to be able to sign up for your Shynet instance (not recommended)
|
||||
SIGNUPS_ENABLED=False
|
||||
# Change as required
|
||||
TIME_ZONE=America/New_York
|
||||
# Set to "False" if you will not be serving content over HTTPS
|
||||
SCRIPT_USE_HTTPS=True
|
||||
```
|
||||
A reverse proxy has many benefits. It can be used for DDoS protection, caching files to reduce server load, routing HTTPS and/or HTTP connections, hosting multiple services on a single server, [and more](https://www.cloudflare.com/learning/cdn/glossary/reverse-proxy/)!
|
||||
|
||||
For more advanced deployments, you may consider adding the following settings to your environment file. **The following settings are optional, and not required for simple deployments.**
|
||||
#### Cloudflare
|
||||
|
||||
```env
|
||||
# Email settings
|
||||
EMAIL_HOST_USER=<your SMTP email user>
|
||||
EMAIL_HOST_PASSWORD=<your SMTP email password>
|
||||
EMAIL_HOST=<your SMTP email hostname>
|
||||
SERVER_EMAIL=Shynet <noreply@shynet.example.com>
|
||||
[Cloudflare](https://www.cloudflare.com/) is a great reverse proxy option. It's free, automatically configures HTTPs, offers out-of-the-box security features, provides DNS, and requires minimal setup.
|
||||
|
||||
# Redis and queue settings; not necessary for single-instance deployments
|
||||
REDIS_CACHE_LOCATION=redis://redis.default.svc.cluster.local/0
|
||||
# If set, make sure CELERY_TASK_ALWAYS_EAGER is False
|
||||
CELERY_BROKER_URL=redis://redis.default.svc.cluster.local/1
|
||||
1. Follow Cloudflare's [getting started guide](https://support.cloudflare.com/hc/en-us/articles/201720164-Creating-a-Cloudflare-account-and-adding-a-website).
|
||||
|
||||
2. After setting up Cloudflare, here are a few things you should consider doing:
|
||||
* Under the `SSL` Tab > `Overview` > Change your `SSL/TLS Encryption Mode` to `Flexible`
|
||||
* The following will block your admin panel from anyone who isn't on your IP address. This is optional, but great for security.
|
||||
* Under the `Firewall` tab > `Overview` > `+ Create Firewall Rule`:
|
||||
* Name: `Admin Panel Restriction`
|
||||
* Field: `URI Path`
|
||||
* Operator: `equals`
|
||||
* Value: `/admin`
|
||||
* Click `AND`
|
||||
* Field: `IP Address`
|
||||
* Operator: `does not equal`
|
||||
* Value: `<your public IP address>`
|
||||
* Then: `Block`
|
||||
|
||||
# Other Shynet settings
|
||||
# How frequently should the monitoring script "phone home" (in ms)?
|
||||
SCRIPT_HEARTBEAT_FREQUENCY=5000
|
||||
# Should only superusers (admins) be able to create services? This is helpful
|
||||
# when you'd like to invite others to your Shynet instance but don't want
|
||||
# them to be able to create services of their own.
|
||||
ONLY_SUPERUSERS_CREATE=False
|
||||
```
|
||||
#### Nginx
|
||||
|
||||
9. Setup the Shynet database by running `docker run --env-file=<your env file> milesmcc/shynet:latest-ssl python manage.py migrate`.
|
||||
Nginx is a self hosted, highly configurable webserver. Nginx can be configured to run as a reverse proxy on either the same machine or a remote machine.
|
||||
|
||||
10. Create your admin account by running `docker run --env-file=<your env file> milesmcc/shynet:latest-ssl python manage.py registeradmin <your email>`. The command will print a temporary password that you'll be able to use to log in.
|
||||
> **These commands assume Ubuntu.** If you're installing Nginx on a different platform, the process will be different.
|
||||
|
||||
11. Configure Shynet's hostname (e.g. `shynet.example.com` or `localhost:8000`) by running `docker run --env-file=<your env file> milesmcc/shynet:latest-ssl python manage.py hostname "<your hostname>"`. This doesn't affect Shynet's bind port; instead, it determines what hostname to inject into the tracking script. (So you'll want to use the "user-facing" hostname here.)
|
||||
0. Before starting, shut down your Docker containers (if any are running)
|
||||
* Run `docker container ls` to find the container ID
|
||||
* Run `docker stop <container id from the last step>`
|
||||
|
||||
12. Name your Shynet instance by running `docker run --env-file=<your env file> milesmcc/shynet:latest-ssl python manage.py whitelabel "<your instance name>"`. This could be something like "My Shynet Server" or "Acme Analytics"—whatever suits you.
|
||||
1. Update your packages and install Nginx
|
||||
* `sudo apt-get update`
|
||||
* `sudo apt-get install nginx`
|
||||
|
||||
13. Launch the Shynet server by running `docker run --env-file=<your env file> milesmcc/shynet:latest-ssl`. You may need to bind Docker's port 8080 (where Shynet runs) to your local port 443 (https); this can be done using the flag `-p 443:8080` after `run`.
|
||||
2. Disable the default Nginx placeholder
|
||||
* `sudo unlink /etc/nginx/sites-enabled/default`
|
||||
|
||||
14. Visit your service's homepage using `https://`, and verify everything looks right! You should see a login prompt. Log in with the credentials from step 10. You'll probably be prompted to "confirm your email"—if you haven't set up an email server, the confirmation email will be printed to the console instead.
|
||||
3. Create the Nginx reverse proxy config file
|
||||
* `cd /etc/nginx/sites-available/`
|
||||
* `vi reverse-proxy.conf` or `nano reverse-proxy.conf`
|
||||
* Paste the following configuration into that file:
|
||||
|
||||
15. Create a service by clicking "+ Create Service" in the top right hand corner. Fill out the options as appropriate. Once you're done, press "create" and you'll be redirected to your new service's analytics page.
|
||||
```nginx
|
||||
# Know what you're pasting! Read the Reference!
|
||||
# Reference: https://nginx.org/en/docs/
|
||||
server {
|
||||
listen 80;
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:8080;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
16. Finally, click on "Manage" in the top right of the service's page to get the tracking script code. Inject this script on all pages you'd like the service to track.
|
||||
* Save and exit the text editor
|
||||
* `:wq` for vi
|
||||
* `ctrl+x` then `y` for nano
|
||||
* Link Nginx's `sites-enabled` to read the new config
|
||||
* `sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf`
|
||||
* Make sure the config is working
|
||||
* `service nginx configtest`
|
||||
* `service nginx restart`
|
||||
|
||||
4. Restart your Docker image, but this time use `8080` as the local bind port, as that's where we configured Nginx to look
|
||||
* `cd ~/`
|
||||
* `docker run -p 8080:8080 --env-file=<your env file> milesmcc/shynet:latest`
|
||||
|
||||
5. Finally, time to test!
|
||||
* Go to `http://<your site>/admin`
|
||||
|
||||
6. If everything is working as expected, please read through some of the following links below to customize Nginx
|
||||
* [How to add SSL/HTTPS to Nginx (Ubuntu 18.04)](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04)
|
||||
* [How to add SSL/HTTPS to Nginx (Ubuntu 16.04)](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04)
|
||||
* [Nginx Documentation](https://nginx.org/en/docs/)
|
||||
|
||||
---
|
||||
|
||||
**Next steps:** while out of the scope of this short guide, next steps include setting up Shynet behind a reverse proxy (be it your own [Nginx server](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/) or [Cloudflare](https://cloudflare.com)), making it run in the background, and integrating it on your sites. Integration instructions are available on each service's management page.
|
||||
## Troubleshooting
|
||||
|
||||
Here are solutions for some common issues. If your situation isn't described here or the solution didn't work, feel free to [create an issue](https://github.com/milesmcc/shynet/issues/new) (but be sure to check for duplicate issues first).
|
||||
|
||||
#### The admin panel works, but no page views are showing up!
|
||||
|
||||
* If you are running a single Shynet webserver instance (i.e., you followed the default installation instructions), verify that you haven't set `CELERY_TASK_ALWAYS_EAGER` to `False` in your environment file.
|
||||
* Verify that your cache is properly configured. In single-instance deployments, this means making sure that you haven't set any `REDIS_*` or `CELERY_*` environment variables (those are for more advanced deployments; you'll just want the defaults).
|
||||
* If your service is configured to respect Do Not Track (under "Advanced Settings"), verify that your browser isn't sending the `DNT=1` header with your requests (or temporarily disable DNT support in Shynet while testing). Sometimes, an adblocker or privacy browser extension will add this header to requests unexpectedly.
|
||||
|
||||
#### Shynet isn't linking different pageviews from the same visitor into a single session!
|
||||
|
||||
* Verify that your cache is properly configured. (See #2 above.) In multi-instance deployments, it's critical that all webservers are using the _same_ cache—so make sure you configure a Redis cache if you're using a non-default installation.
|
||||
* This can happen between Shynet restarts if you're not using an external cache provider (like Redis).
|
||||
|
||||
#### I changed the `SHYNET_WHITELABEL`/`SHYNET_HOST` environment variable, but nothing happened!
|
||||
|
||||
* Those values only affect how your Shynet instance is setup on first run; once it's configured, they have no effect. See [updating your configuration](#updating-your-configuration) for help on how to update your configuration.
|
||||
|
||||
1
Pipfile
1
Pipfile
@@ -23,6 +23,7 @@ psycopg2-binary = "*"
|
||||
redis = "*"
|
||||
django-redis-cache = "*"
|
||||
pycountry = "*"
|
||||
ipaddress = "*"
|
||||
|
||||
[pipenv]
|
||||
allow_prereleases = true
|
||||
|
||||
88
Pipfile.lock
generated
88
Pipfile.lock
generated
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "2cd3e33ea333a40476d2030b6be66826e93c3a4de67032655061725835c92f09"
|
||||
"sha256": "75fe7f0efbc05d6bc32c5ccaa08d3d619bf925682ca5eaffa728e74d0e8e5f66"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {},
|
||||
@@ -59,18 +59,18 @@
|
||||
},
|
||||
"defusedxml": {
|
||||
"hashes": [
|
||||
"sha256:6687150770438374ab581bb7a1b327a847dd9c5749e396102de3fad4e8a3ef93",
|
||||
"sha256:f684034d135af4c6cbb949b8a4d2ed61634515257a67299e5f940fbaa34377f5"
|
||||
"sha256:8ede8ba04cf5bf7999e1492fa77df545db83717f52c5eab625f97228ebd539bf",
|
||||
"sha256:aa621655d72cdd30f57073893b96cd0c3831a85b08b8e4954531bdac47e3e8c8"
|
||||
],
|
||||
"version": "==0.6.0"
|
||||
"version": "==0.7.0rc1"
|
||||
},
|
||||
"django": {
|
||||
"hashes": [
|
||||
"sha256:642d8eceab321ca743ae71e0f985ff8fdca59f07aab3a9fb362c617d23e33a76",
|
||||
"sha256:d4666c2edefa38c5ede0ec1655424c56dc47ceb04b6d8d62a7eac09db89545c1"
|
||||
"sha256:051ba55d42daa3eeda3944a8e4df2bc96d4c62f94316dea217248a22563c3621",
|
||||
"sha256:9aaa6a09678e1b8f0d98a948c56482eac3e3dd2ddbfb8de70a868135ef3b5e01"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==3.0.5"
|
||||
"version": "==3.0.6"
|
||||
},
|
||||
"django-allauth": {
|
||||
"hashes": [
|
||||
@@ -125,6 +125,14 @@
|
||||
],
|
||||
"version": "==2.9"
|
||||
},
|
||||
"ipaddress": {
|
||||
"hashes": [
|
||||
"sha256:6e0f4a39e66cb5bb9a137b00276a2eff74f93b71dcbdad6f10ff7df9d3557fcc",
|
||||
"sha256:b7f8e0369580bb4a24d5ba1d7cc29660a4a6987763faf1d8a8046830e020e7e2"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.0.23"
|
||||
},
|
||||
"kombu": {
|
||||
"hashes": [
|
||||
"sha256:2d1cda774126a044d91a7ff5fa6d09edf99f46924ab332a810760fe6740e9b76",
|
||||
@@ -134,9 +142,9 @@
|
||||
},
|
||||
"maxminddb": {
|
||||
"hashes": [
|
||||
"sha256:d0ce131d901eb11669996b49a59f410efd3da2c6dbe2c0094fe2fef8d85b6336"
|
||||
"sha256:f4d28823d9ca23323d113dc7af8db2087aa4f657fafc64ff8f7a8afda871425b"
|
||||
],
|
||||
"version": "==1.5.2"
|
||||
"version": "==1.5.4"
|
||||
},
|
||||
"oauthlib": {
|
||||
"hashes": [
|
||||
@@ -197,10 +205,10 @@
|
||||
},
|
||||
"pytz": {
|
||||
"hashes": [
|
||||
"sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d",
|
||||
"sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be"
|
||||
"sha256:a494d53b6d39c3c6e44c3bec237336e14305e4f29bbf800b599253057fbb79ed",
|
||||
"sha256:c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048"
|
||||
],
|
||||
"version": "==2019.3"
|
||||
"version": "==2020.1"
|
||||
},
|
||||
"pyyaml": {
|
||||
"hashes": [
|
||||
@@ -221,11 +229,11 @@
|
||||
},
|
||||
"redis": {
|
||||
"hashes": [
|
||||
"sha256:0dcfb335921b88a850d461dc255ff4708294943322bd55de6cfd68972490ca1f",
|
||||
"sha256:b205cffd05ebfd0a468db74f0eedbff8df1a7bfc47521516ade4692991bb0833"
|
||||
"sha256:174101a3ce04560d716616290bb40e0a2af45d5844c8bd474c23fc5c52e7a46a",
|
||||
"sha256:7378105cd8ea20c4edc49f028581e830c01ad5f00be851def0f4bc616a83cd89"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==3.4.1"
|
||||
"version": "==3.5.0"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
@@ -326,10 +334,10 @@
|
||||
},
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:8a18b4ea89d8820c5d0c7da8a64b2c324b4dabb695804dbfea19b9be9d88c0cc",
|
||||
"sha256:e345d143d80bf5ee7534056164e5e112ea5e22716bbb1ce727941f4c8b471b9a"
|
||||
"sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a",
|
||||
"sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"
|
||||
],
|
||||
"version": "==7.1.1"
|
||||
"version": "==7.1.2"
|
||||
},
|
||||
"pathspec": {
|
||||
"hashes": [
|
||||
@@ -340,29 +348,29 @@
|
||||
},
|
||||
"regex": {
|
||||
"hashes": [
|
||||
"sha256:08119f707f0ebf2da60d2f24c2f39ca616277bb67ef6c92b72cbf90cbe3a556b",
|
||||
"sha256:0ce9537396d8f556bcfc317c65b6a0705320701e5ce511f05fc04421ba05b8a8",
|
||||
"sha256:1cbe0fa0b7f673400eb29e9ef41d4f53638f65f9a2143854de6b1ce2899185c3",
|
||||
"sha256:2294f8b70e058a2553cd009df003a20802ef75b3c629506be20687df0908177e",
|
||||
"sha256:23069d9c07e115537f37270d1d5faea3e0bdded8279081c4d4d607a2ad393683",
|
||||
"sha256:24f4f4062eb16c5bbfff6a22312e8eab92c2c99c51a02e39b4eae54ce8255cd1",
|
||||
"sha256:295badf61a51add2d428a46b8580309c520d8b26e769868b922750cf3ce67142",
|
||||
"sha256:2a3bf8b48f8e37c3a40bb3f854bf0121c194e69a650b209628d951190b862de3",
|
||||
"sha256:4385f12aa289d79419fede43f979e372f527892ac44a541b5446617e4406c468",
|
||||
"sha256:5635cd1ed0a12b4c42cce18a8d2fb53ff13ff537f09de5fd791e97de27b6400e",
|
||||
"sha256:5bfed051dbff32fd8945eccca70f5e22b55e4148d2a8a45141a3b053d6455ae3",
|
||||
"sha256:7e1037073b1b7053ee74c3c6c0ada80f3501ec29d5f46e42669378eae6d4405a",
|
||||
"sha256:90742c6ff121a9c5b261b9b215cb476eea97df98ea82037ec8ac95d1be7a034f",
|
||||
"sha256:a58dd45cb865be0ce1d5ecc4cfc85cd8c6867bea66733623e54bd95131f473b6",
|
||||
"sha256:c087bff162158536387c53647411db09b6ee3f9603c334c90943e97b1052a156",
|
||||
"sha256:c162a21e0da33eb3d31a3ac17a51db5e634fc347f650d271f0305d96601dc15b",
|
||||
"sha256:c9423a150d3a4fc0f3f2aae897a59919acd293f4cb397429b120a5fcd96ea3db",
|
||||
"sha256:ccccdd84912875e34c5ad2d06e1989d890d43af6c2242c6fcfa51556997af6cd",
|
||||
"sha256:e91ba11da11cf770f389e47c3f5c30473e6d85e06d7fd9dcba0017d2867aab4a",
|
||||
"sha256:ea4adf02d23b437684cd388d557bf76e3afa72f7fed5bbc013482cc00c816948",
|
||||
"sha256:fb95debbd1a824b2c4376932f2216cc186912e389bdb0e27147778cf6acb3f89"
|
||||
"sha256:021a0ae4d2baeeb60a3014805a2096cb329bd6d9f30669b7ad0da51a9cb73349",
|
||||
"sha256:04d6e948ef34d3eac133bedc0098364a9e635a7914f050edb61272d2ddae3608",
|
||||
"sha256:099568b372bda492be09c4f291b398475587d49937c659824f891182df728cdf",
|
||||
"sha256:0ff50843535593ee93acab662663cb2f52af8e31c3f525f630f1dc6156247938",
|
||||
"sha256:1b17bf37c2aefc4cac8436971fe6ee52542ae4225cfc7762017f7e97a63ca998",
|
||||
"sha256:1e2255ae938a36e9bd7db3b93618796d90c07e5f64dd6a6750c55f51f8b76918",
|
||||
"sha256:2bc6a17a7fa8afd33c02d51b6f417fc271538990297167f68a98cae1c9e5c945",
|
||||
"sha256:3ab5e41c4ed7cd4fa426c50add2892eb0f04ae4e73162155cd668257d02259dd",
|
||||
"sha256:3b059e2476b327b9794c792c855aa05531a3f3044737e455d283c7539bd7534d",
|
||||
"sha256:4df91094ced6f53e71f695c909d9bad1cca8761d96fd9f23db12245b5521136e",
|
||||
"sha256:5493a02c1882d2acaaf17be81a3b65408ff541c922bfd002535c5f148aa29f74",
|
||||
"sha256:5b741ecc3ad3e463d2ba32dce512b412c319993c1bb3d999be49e6092a769fb2",
|
||||
"sha256:652ab4836cd5531d64a34403c00ada4077bb91112e8bcdae933e2eae232cf4a8",
|
||||
"sha256:669a8d46764a09f198f2e91fc0d5acdac8e6b620376757a04682846ae28879c4",
|
||||
"sha256:73a10404867b835f1b8a64253e4621908f0d71150eb4e97ab2e7e441b53e9451",
|
||||
"sha256:7ce4a213a96d6c25eeae2f7d60d4dad89ac2b8134ec3e69db9bc522e2c0f9388",
|
||||
"sha256:8127ca2bf9539d6a64d03686fd9e789e8c194fc19af49b69b081f8c7e6ecb1bc",
|
||||
"sha256:b5b5b2e95f761a88d4c93691716ce01dc55f288a153face1654f868a8034f494",
|
||||
"sha256:b7c9f65524ff06bf70c945cd8d8d1fd90853e27ccf86026af2afb4d9a63d06b1",
|
||||
"sha256:f7f2f4226db6acd1da228adf433c5c3792858474e49d80668ea82ac87cf74a03",
|
||||
"sha256:fa09da4af4e5b15c0e8b4986a083f3fd159302ea115a6cc0649cd163435538b8"
|
||||
],
|
||||
"version": "==2020.4.4"
|
||||
"version": "==2020.5.7"
|
||||
},
|
||||
"toml": {
|
||||
"hashes": [
|
||||
|
||||
22
README.md
22
README.md
@@ -8,7 +8,7 @@
|
||||
<br>
|
||||
<strong><a href="#installation">Getting started »</a></strong>
|
||||
</p>
|
||||
<p align="center"><a href="#screenshots">Screenshots</a> • <a href="#features">Features</a> • <a href="#roadmap">Roadmap</a></p>
|
||||
<p align="center"><a href="#screenshots">Screenshots</a> • <a href="#features">Features</a> • <a href="https://github.com/milesmcc/a17t">Design</a></p>
|
||||
</p>
|
||||
|
||||
<br>
|
||||
@@ -39,6 +39,8 @@ _A real service page, where you can see higher-level details about a site._
|
||||
|
||||
Not shown: management view, session view, full service view. (You'll need to install Shynet for yourself to see those!)
|
||||
|
||||
> **Shynet is built using [a17t](https://github.com/milesmcc/a17t),** an atomic design library. Customization and extension is simple; [learn more about a17t](https://github.com/milesmcc/a17t).
|
||||
|
||||
## Features
|
||||
|
||||
#### Architecture
|
||||
@@ -91,7 +93,8 @@ Shynet is pretty simple, but there are a few key terms you need to know in order
|
||||
|
||||
## Installation
|
||||
|
||||
You can find installation instructions in the [Getting Started Guide](GUIDE.md#installation).
|
||||
You can find intructions on getting started and usage in the [Usage Guide](GUIDE.md#installation). Out of the box, we support deploying via a simple
|
||||
Docker container, docker-compose, or Kubernetes (see [kubernetes](/kubernetes)).
|
||||
|
||||
## FAQ
|
||||
|
||||
@@ -99,16 +102,13 @@ You can find installation instructions in the [Getting Started Guide](GUIDE.md#i
|
||||
|
||||
**Is this GDPR compliant?** It depends on how you use it. If you're worried about GDPR, you should talk to a lawyer about your particular data collection practices. I'm not a lawyer. (And this isn't legal advice.)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Having trouble with Shynet? Check out the [troubleshooting guide](GUIDE.md#troubleshooting), or [create an issue](https://github.com/milesmcc/shynet/issues/new) if you think you found a bug in Shynet itself (or have a feature suggestion).
|
||||
|
||||
## Roadmap
|
||||
|
||||
The following features are planned:
|
||||
|
||||
* **Rollups** (aggregate old data to save space)
|
||||
* **Anomaly detection** (get email alerts when you get a traffic spike or dip)
|
||||
* **Interactive traffic heatmap** (see where in the world your visitors are coming from)
|
||||
* **Better collaboration interface** (the current interface is... a draft)
|
||||
* **Data deletion tool** (easily prune user data by specifying an ID or IP)
|
||||
* **Differential privacy** (explore and share your data without revealing any personal information)
|
||||
To see the upcoming planned features, check out the repository's [roadmap project](https://github.com/milesmcc/shynet/projects/1). Upcoming features include data aggregation through rollups, anomaly detection, detailed data exports, two-factor authentication, and a data deletion tool.
|
||||
|
||||
## In the Wild
|
||||
|
||||
@@ -116,7 +116,7 @@ These sites use Shynet to monitor usage without violating visitors' privacy: [Po
|
||||
|
||||
## Contributing
|
||||
|
||||
Are you interested in contributing to Shynet? Just send a pull request! Maybe once the project matures there will be more detailed contribution guidelines, but for now just send the code this way. Just know that by contributing, you agree to share all of your contributions under the same license as the project (see [LICENSE](LICENSE)).
|
||||
Are you interested in contributing to Shynet? Just send a pull request! Maybe once the project matures there will be more detailed contribution guidelines, but for now just send the code this way and we'll make sure it meets our standards together. Just know that by contributing, you agree to share all of your contributions under the same license as the project (see [LICENSE](LICENSE)). And always be sure to follow the [Code of Conduct](https://github.com/milesmcc/shynet/blob/master/CODE_OF_CONDUCT.md).
|
||||
|
||||
## License
|
||||
|
||||
|
||||
68
TEMPLATE.env
Normal file
68
TEMPLATE.env
Normal file
@@ -0,0 +1,68 @@
|
||||
# This file shows all of the environment variables you can
|
||||
# set to configure Shynet, as well as information about their
|
||||
# effects. Make a copy of this file to configure your deployment.
|
||||
|
||||
# Database settings (PostgreSQL)
|
||||
DB_NAME=shynet_db
|
||||
DB_USER=shynet_db_user
|
||||
DB_PASSWORD=shynet_db_user_password
|
||||
DB_HOST=db
|
||||
DB_PORT=5432
|
||||
|
||||
# Email settings (optional)
|
||||
EMAIL_HOST_USER=example
|
||||
EMAIL_HOST_PASSWORD=example_password
|
||||
EMAIL_HOST=smtp.example.com
|
||||
SERVER_EMAIL=<Shynet> noreply@shynet.example.com
|
||||
|
||||
# General Django settings
|
||||
DJANGO_SECRET_KEY=random_string
|
||||
|
||||
# For better security, set this to your deployment's domain. Comma separated.
|
||||
ALLOWED_HOSTS=*
|
||||
|
||||
# Set to True (capitalized) if you want people to be able to sign up for your Shynet instance (not recommended)
|
||||
SIGNUPS_ENABLED=False
|
||||
|
||||
# The timezone of the admin panel. Affects how dates are displayed.
|
||||
TIME_ZONE=America/New_York
|
||||
|
||||
# Set to "False" if you will not be serving content over HTTPS
|
||||
SCRIPT_USE_HTTPS=True
|
||||
|
||||
# How frequently should the monitoring script "phone home" (in ms)?
|
||||
SCRIPT_HEARTBEAT_FREQUENCY=5000
|
||||
|
||||
# How much time can elapse between requests from the same user before a new
|
||||
# session is created, in seconds?
|
||||
SESSION_MEMORY_TIMEOUT=1800
|
||||
|
||||
# Should only superusers (admins) be able to create services? This is helpful
|
||||
# when you'd like to invite others to your Shynet instance but don't want
|
||||
# them to be able to create services of their own.
|
||||
ONLY_SUPERUSERS_CREATE=True
|
||||
|
||||
# Whether to perform checks and setup at startup, including applying unapplied
|
||||
# migrations. For most setups, the recommended value is True. Defaults to True.
|
||||
# Will skip only if value is False.
|
||||
PERFORM_CHECKS_AND_SETUP=True
|
||||
|
||||
# Your admin user's email. A temporary password will be printed
|
||||
# to the console on first run.
|
||||
SHYNET_ADMIN_EMAIL=you@example.com
|
||||
|
||||
# The domain on which you'll be hosting Shynet.
|
||||
SHYNET_HOST=shynet.example.com
|
||||
|
||||
# What you'd like to call your Shynet instance.
|
||||
SHYNET_WHITELABEL=My Shynet Instance
|
||||
|
||||
# Redis, queue, and parellization settings; not necessary for single-instance deployments.
|
||||
# Don't uncomment these unless you know what you are doing!
|
||||
# NUM_WORKERS=1
|
||||
# Make sure you set a REDIS_CACHE_LOCATION if you have more than one frontend worker/instance.
|
||||
# REDIS_CACHE_LOCATION=redis://redis.default.svc.cluster.local/0
|
||||
# If CELERY_BROKER_URL is set, make sure CELERY_TASK_ALWAYS_EAGER is False and
|
||||
# that you have a separate queue consumer running somewhere via `celeryworker.sh`.
|
||||
# CELERY_TASK_ALWAYS_EAGER=False
|
||||
# CELERY_BROKER_URL=redis://redis.default.svc.cluster.local/1
|
||||
32
docker-compose.yml
Normal file
32
docker-compose.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
version: '3'
|
||||
services:
|
||||
shynet:
|
||||
image: milesmcc/shynet:latest
|
||||
restart: unless-stopped
|
||||
expose:
|
||||
- 8080
|
||||
env_file:
|
||||
# Create a file called '.env' if it doesn't already exist.
|
||||
# You can use `TEMPLATE.env` as a guide.
|
||||
- .env
|
||||
environment:
|
||||
- DB_HOST=db
|
||||
networks:
|
||||
- internal
|
||||
depends_on:
|
||||
- db
|
||||
db:
|
||||
image: postgres
|
||||
restart: always
|
||||
environment:
|
||||
- "POSTGRES_USER=${DB_USER}"
|
||||
- "POSTGRES_PASSWORD=${DB_PASSWORD}"
|
||||
- "POSTGRES_DB=${DB_NAME}"
|
||||
volumes:
|
||||
- shynet_db:/var/lib/postgresql/data
|
||||
networks:
|
||||
- internal
|
||||
volumes:
|
||||
shynet_db:
|
||||
networks:
|
||||
internal:
|
||||
@@ -16,13 +16,12 @@ spec:
|
||||
app: "shynet-webserver"
|
||||
spec:
|
||||
containers:
|
||||
- name: "covideo-webserver"
|
||||
- name: "shynet-webserver"
|
||||
image: "milesmcc/shynet:latest"
|
||||
command: ["./webserver.sh"]
|
||||
imagePullPolicy: Always
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: django-settings
|
||||
name: shynet-settings
|
||||
---
|
||||
apiVersion: "apps/v1"
|
||||
kind: "Deployment"
|
||||
@@ -42,43 +41,43 @@ spec:
|
||||
app: "shynet-celeryworker"
|
||||
spec:
|
||||
containers:
|
||||
- name: "covideo-celeryworker"
|
||||
- name: "shynet-celeryworker"
|
||||
image: "milesmcc/shynet:latest"
|
||||
command: ["./celeryworker.sh"]
|
||||
imagePullPolicy: Always
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: django-settings
|
||||
name: shynet-settings
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: redis
|
||||
name: shynet-redis
|
||||
spec:
|
||||
ports:
|
||||
- port: 6379
|
||||
name: redis
|
||||
clusterIP: None
|
||||
selector:
|
||||
app: redis
|
||||
app: shynet-redis
|
||||
---
|
||||
apiVersion: apps/v1beta2
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: redis
|
||||
name: shynet-redis
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: redis
|
||||
serviceName: redis
|
||||
app: shynet-redis
|
||||
serviceName: shynet-redis
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: redis
|
||||
app: shynet-redis
|
||||
spec:
|
||||
containers:
|
||||
- name: redis
|
||||
- name: shynet-redis
|
||||
image: redis:latest
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: django-settings
|
||||
name: shynet-settings
|
||||
type: Opaque
|
||||
stringData:
|
||||
# Django settings
|
||||
@@ -12,8 +12,8 @@ stringData:
|
||||
TIME_ZONE: "America/New_York"
|
||||
|
||||
# Redis configuration (if you use the default Kubernetes config, this will work)
|
||||
REDIS_CACHE_LOCATION: "redis://redis.default.svc.cluster.local/0"
|
||||
CELERY_BROKER_URL: "redis://redis.default.svc.cluster.local/1"
|
||||
REDIS_CACHE_LOCATION: "redis://shynet-redis.default.svc.cluster.local/0"
|
||||
CELERY_BROKER_URL: "redis://shynet-redis.default.svc.cluster.local/1"
|
||||
|
||||
# PostgreSQL settings
|
||||
DB_NAME: ""
|
||||
|
||||
18
shynet/analytics/migrations/0003_auto_20200502_1227.py
Normal file
18
shynet/analytics/migrations/0003_auto_20200502_1227.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.5 on 2020-05-02 16:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("analytics", "0002_auto_20200415_1742"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="session",
|
||||
name="ip",
|
||||
field=models.GenericIPAddressField(db_index=True, null=True),
|
||||
),
|
||||
]
|
||||
@@ -39,7 +39,7 @@ class Session(models.Model):
|
||||
default="OTHER",
|
||||
)
|
||||
os = models.TextField()
|
||||
ip = models.GenericIPAddressField(db_index=True)
|
||||
ip = models.GenericIPAddressField(db_index=True, null=True)
|
||||
|
||||
# GeoIP data
|
||||
asn = models.TextField(blank=True)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import ipaddress
|
||||
import json
|
||||
import logging
|
||||
from hashlib import sha1
|
||||
|
||||
import geoip2.database
|
||||
import user_agents
|
||||
@@ -59,29 +61,41 @@ def ingress_request(
|
||||
if dnt and service.respect_dnt:
|
||||
return
|
||||
|
||||
ip_data = _geoip2_lookup(ip)
|
||||
log.debug(f"Found geoip2 data")
|
||||
try:
|
||||
remote_ip = ipaddress.ip_network(ip)
|
||||
for ignored_network in service.get_ignored_networks():
|
||||
if ignored_network.supernet_of(remote_ip):
|
||||
return
|
||||
except ValueError as e:
|
||||
log.exception(e)
|
||||
|
||||
# Validate payload
|
||||
if payload.get("loadTime", 1) <= 0:
|
||||
payload["loadTime"] = None
|
||||
|
||||
# Create or update session
|
||||
session = (
|
||||
Session.objects.filter(
|
||||
service=service,
|
||||
last_seen__gt=timezone.now() - timezone.timedelta(minutes=10),
|
||||
ip=ip,
|
||||
user_agent=user_agent,
|
||||
).first()
|
||||
# We used to check for identifiers, but that can cause issues when people
|
||||
# re-open the page in a new tab, for example. It's better to match sessions
|
||||
# solely based on IP and user agent.
|
||||
association_id_hash = sha1()
|
||||
association_id_hash.update(str(ip).encode("utf-8"))
|
||||
association_id_hash.update(str(user_agent).encode("utf-8"))
|
||||
session_cache_path = (
|
||||
f"session_association_{service.pk}_{association_id_hash.hexdigest()}"
|
||||
)
|
||||
|
||||
# Create or update session
|
||||
session = None
|
||||
if cache.get(session_cache_path) is not None:
|
||||
cache.touch(session_cache_path, settings.SESSION_MEMORY_TIMEOUT)
|
||||
session = Session.objects.filter(
|
||||
pk=cache.get(session_cache_path), service=service
|
||||
).first()
|
||||
if session is None:
|
||||
log.debug("Cannot link to existing session; creating a new one...")
|
||||
ua = user_agents.parse(user_agent)
|
||||
initial = True
|
||||
|
||||
log.debug("Cannot link to existing session; creating a new one...")
|
||||
|
||||
ip_data = _geoip2_lookup(ip)
|
||||
log.debug(f"Found geoip2 data...")
|
||||
|
||||
ua = user_agents.parse(user_agent)
|
||||
device_type = "OTHER"
|
||||
if (
|
||||
ua.is_bot
|
||||
@@ -98,7 +112,7 @@ def ingress_request(
|
||||
device_type = "DESKTOP"
|
||||
session = Session.objects.create(
|
||||
service=service,
|
||||
ip=ip,
|
||||
ip=ip if service.collect_ips else None,
|
||||
user_agent=user_agent,
|
||||
identifier=identifier.strip(),
|
||||
browser=ua.browser.family or "",
|
||||
@@ -111,9 +125,14 @@ def ingress_request(
|
||||
latitude=ip_data.get("latitude"),
|
||||
time_zone=ip_data.get("time_zone", ""),
|
||||
)
|
||||
cache.set(
|
||||
session_cache_path, session.pk, timeout=settings.SESSION_MEMORY_TIMEOUT
|
||||
)
|
||||
else:
|
||||
log.debug("Updating old session with new data...")
|
||||
initial = False
|
||||
|
||||
log.debug("Updating old session with new data...")
|
||||
|
||||
# Update last seen time
|
||||
session.last_seen = timezone.now()
|
||||
if session.identifier == "" and identifier.strip() != "":
|
||||
@@ -124,9 +143,10 @@ def ingress_request(
|
||||
idempotency = payload.get("idempotency")
|
||||
idempotency_path = f"hit_idempotency_{idempotency}"
|
||||
hit = None
|
||||
|
||||
if idempotency is not None:
|
||||
if cache.get(idempotency_path) is not None:
|
||||
cache.touch(idempotency_path, 10 * 60)
|
||||
cache.touch(idempotency_path, settings.SESSION_MEMORY_TIMEOUT)
|
||||
hit = Hit.objects.filter(
|
||||
pk=cache.get(idempotency_path), session=session
|
||||
).first()
|
||||
@@ -137,6 +157,7 @@ def ingress_request(
|
||||
hit.heartbeats += 1
|
||||
hit.last_seen = timezone.now()
|
||||
hit.save()
|
||||
|
||||
if hit is None:
|
||||
log.debug("Hit is a page load; creating new hit...")
|
||||
# There is no existing hit; create a new one
|
||||
@@ -153,7 +174,9 @@ def ingress_request(
|
||||
)
|
||||
# Set idempotency (if applicable)
|
||||
if idempotency is not None:
|
||||
cache.set(idempotency_path, hit.pk, timeout=10 * 60)
|
||||
cache.set(
|
||||
idempotency_path, hit.pk, timeout=settings.SESSION_MEMORY_TIMEOUT
|
||||
)
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
raise e
|
||||
|
||||
@@ -3,7 +3,8 @@ import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.http import HttpResponse
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.http import Http404, HttpResponse, HttpResponseBadRequest
|
||||
from django.shortcuts import render, reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
@@ -36,13 +37,37 @@ def ingress(request, service_uuid, identifier, tracker, payload):
|
||||
)
|
||||
|
||||
|
||||
class PixelView(View):
|
||||
class ValidateServiceOriginsMixin:
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
try:
|
||||
service_uuid = self.kwargs.get("service_uuid")
|
||||
origins = cache.get(f"service_origins_{service_uuid}")
|
||||
|
||||
if origins is None:
|
||||
service = Service.objects.get(uuid=service_uuid)
|
||||
origins = service.origins
|
||||
cache.set(f"service_origins_{service_uuid}", origins, timeout=3600)
|
||||
|
||||
resp = super().dispatch(request, *args, **kwargs)
|
||||
resp["Access-Control-Allow-Origin"] = origins
|
||||
resp["Access-Control-Allow-Methods"] = "GET,HEAD,OPTIONS,POST"
|
||||
resp[
|
||||
"Access-Control-Allow-Headers"
|
||||
] = "Origin, X-Requested-With, Content-Type, Accept, Authorization, Referer"
|
||||
return resp
|
||||
except Service.DoesNotExist:
|
||||
raise Http404()
|
||||
except ValidationError:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
|
||||
class PixelView(ValidateServiceOriginsMixin, View):
|
||||
# Fallback view to serve an unobtrusive 1x1 transparent tracking pixel for browsers with
|
||||
# JavaScript disabled.
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
def get(self, *args, **kwargs):
|
||||
# Extract primary data
|
||||
ingress(
|
||||
request,
|
||||
self.request,
|
||||
self.kwargs.get("service_uuid"),
|
||||
self.kwargs.get("identifier", ""),
|
||||
"PIXEL",
|
||||
@@ -59,23 +84,7 @@ class PixelView(View):
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name="dispatch")
|
||||
class ScriptView(View):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
service_uuid = self.kwargs.get("service_uuid")
|
||||
origins = cache.get(f"service_origins_{service_uuid}")
|
||||
if origins is None:
|
||||
service = Service.objects.get(uuid=service_uuid)
|
||||
origins = service.origins
|
||||
cache.set(f"service_origins_{service_uuid}", origins, timeout=3600)
|
||||
|
||||
resp = super().dispatch(request, *args, **kwargs)
|
||||
resp["Access-Control-Allow-Origin"] = origins
|
||||
resp["Access-Control-Allow-Methods"] = "GET,HEAD,OPTIONS,POST"
|
||||
resp[
|
||||
"Access-Control-Allow-Headers"
|
||||
] = "Origin, X-Requested-With, Content-Type, Accept, Authorization, Referer"
|
||||
return resp
|
||||
|
||||
class ScriptView(ValidateServiceOriginsMixin, View):
|
||||
def get(self, *args, **kwargs):
|
||||
protocol = "https" if settings.SCRIPT_USE_HTTPS else "http"
|
||||
endpoint = (
|
||||
|
||||
56
shynet/core/management/commands/startup_checks.py
Normal file
56
shynet/core/management/commands/startup_checks.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import traceback
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import DEFAULT_DB_ALIAS, connections
|
||||
from django.db.utils import ConnectionHandler, OperationalError
|
||||
from django.utils.crypto import get_random_string
|
||||
|
||||
from core.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Internal command to perform startup sanity checks."
|
||||
|
||||
def check_migrations(self):
|
||||
from django.db.migrations.executor import MigrationExecutor
|
||||
|
||||
try:
|
||||
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
|
||||
except OperationalError:
|
||||
# DB_NAME database not found?
|
||||
return True
|
||||
except ImproperlyConfigured:
|
||||
# No databases are configured (or the dummy one)
|
||||
return True
|
||||
|
||||
if executor.migration_plan(executor.loader.graph.leaf_nodes()):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def handle(self, *args, **options):
|
||||
migration = self.check_migrations()
|
||||
|
||||
admin, hostname, whitelabel = [True] * 3
|
||||
if not migration:
|
||||
admin = not User.objects.all().exists()
|
||||
hostname = (
|
||||
not Site.objects.filter(domain__isnull=False)
|
||||
.exclude(domain__exact="")
|
||||
.exclude(domain__exact="example.com")
|
||||
.exists()
|
||||
)
|
||||
whitelabel = (
|
||||
not Site.objects.filter(name__isnull=False)
|
||||
.exclude(name__exact="")
|
||||
.exclude(name__exact="example.com")
|
||||
.exists()
|
||||
)
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f"{migration} {admin} {hostname} {whitelabel}")
|
||||
)
|
||||
18
shynet/core/migrations/0004_service_collect_ips.py
Normal file
18
shynet/core/migrations/0004_service_collect_ips.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.5 on 2020-05-02 16:22
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("core", "0003_service_respect_dnt"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="service",
|
||||
name="collect_ips",
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
||||
22
shynet/core/migrations/0005_service_ignored_ips.py
Normal file
22
shynet/core/migrations/0005_service_ignored_ips.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 3.0.6 on 2020-05-07 20:28
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
import core.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("core", "0004_service_collect_ips"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="service",
|
||||
name="ignored_ips",
|
||||
field=models.TextField(
|
||||
blank=True, default="", validators=[core.models._validate_network_list]
|
||||
),
|
||||
),
|
||||
]
|
||||
22
shynet/core/migrations/0006_service_hide_referrer_regex.py
Normal file
22
shynet/core/migrations/0006_service_hide_referrer_regex.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 3.0.6 on 2020-05-07 21:23
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
import core.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("core", "0005_service_ignored_ips"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="service",
|
||||
name="hide_referrer_regex",
|
||||
field=models.TextField(
|
||||
blank=True, default="", validators=[core.models._validate_regex]
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -1,8 +1,11 @@
|
||||
import ipaddress
|
||||
import json
|
||||
import re
|
||||
import uuid
|
||||
|
||||
from django.apps import apps
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.db.models.functions import TruncDate
|
||||
from django.db.utils import NotSupportedError
|
||||
@@ -14,6 +17,26 @@ def _default_uuid():
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
def _validate_network_list(networks: str):
|
||||
try:
|
||||
_parse_network_list(networks)
|
||||
except ValueError as e:
|
||||
raise ValidationError(str(e))
|
||||
|
||||
|
||||
def _validate_regex(regex: str):
|
||||
try:
|
||||
re.compile(regex)
|
||||
except re.error:
|
||||
raise ValidationError(f"'{regex}' is not valid RegEx")
|
||||
|
||||
|
||||
def _parse_network_list(networks: str):
|
||||
if len(networks.strip()) == 0:
|
||||
return []
|
||||
return [ipaddress.ip_network(network.strip()) for network in networks.split(",")]
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
username = models.TextField(default=_default_uuid, unique=True)
|
||||
email = models.EmailField(unique=True)
|
||||
@@ -42,6 +65,13 @@ class Service(models.Model):
|
||||
max_length=2, choices=SERVICE_STATUSES, default=ACTIVE, db_index=True
|
||||
)
|
||||
respect_dnt = models.BooleanField(default=True)
|
||||
collect_ips = models.BooleanField(default=True)
|
||||
ignored_ips = models.TextField(
|
||||
default="", blank=True, validators=[_validate_network_list]
|
||||
)
|
||||
hide_referrer_regex = models.TextField(
|
||||
default="", blank=True, validators=[_validate_regex]
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ["name", "uuid"]
|
||||
@@ -49,6 +79,21 @@ class Service(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_ignored_networks(self):
|
||||
return _parse_network_list(self.ignored_ips)
|
||||
|
||||
def get_ignored_referrer_regex(self):
|
||||
if len(self.hide_referrer_regex.strip()) == 0:
|
||||
return re.compile(r".^") # matches nothing
|
||||
else:
|
||||
try:
|
||||
return re.compile(self.hide_referrer_regex)
|
||||
except re.error:
|
||||
# Regexes are validated in the form, but this is an important
|
||||
# fallback to prevent form validation and malformed source
|
||||
# data from causing all service pages to error
|
||||
return re.compile(r".^")
|
||||
|
||||
def get_daily_stats(self):
|
||||
return self.get_core_stats(
|
||||
start_time=timezone.now() - timezone.timedelta(days=1)
|
||||
@@ -95,12 +140,17 @@ class Service(models.Model):
|
||||
.order_by("-count")
|
||||
)
|
||||
|
||||
referrers = (
|
||||
referrer_ignore = self.get_ignored_referrer_regex()
|
||||
referrers = [
|
||||
referrer
|
||||
for referrer in (
|
||||
hits.filter(initial=True)
|
||||
.values("referrer")
|
||||
.annotate(count=models.Count("referrer"))
|
||||
.order_by("-count")
|
||||
)
|
||||
if not referrer_ignore.match(referrer["referrer"])
|
||||
]
|
||||
|
||||
countries = (
|
||||
sessions.values("country")
|
||||
@@ -130,12 +180,6 @@ class Service(models.Model):
|
||||
.order_by("-count")
|
||||
)
|
||||
|
||||
device_types = (
|
||||
sessions.values("device_type")
|
||||
.annotate(count=models.Count("device_type"))
|
||||
.order_by("-count")
|
||||
)
|
||||
|
||||
avg_load_time = hits.aggregate(load_time__avg=models.Avg("load_time"))[
|
||||
"load_time__avg"
|
||||
]
|
||||
|
||||
@@ -8,15 +8,30 @@ from core.models import Service, User
|
||||
class ServiceForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Service
|
||||
fields = ["name", "link", "respect_dnt", "origins", "collaborators"]
|
||||
fields = [
|
||||
"name",
|
||||
"link",
|
||||
"respect_dnt",
|
||||
"collect_ips",
|
||||
"ignored_ips",
|
||||
"hide_referrer_regex",
|
||||
"origins",
|
||||
"collaborators",
|
||||
]
|
||||
widgets = {
|
||||
"name": forms.TextInput(),
|
||||
"origins": forms.TextInput(),
|
||||
"ignored_ips": forms.TextInput(),
|
||||
"respect_dnt": forms.RadioSelect(choices=[(True, "Yes"), (False, "No")]),
|
||||
"collect_ips": forms.RadioSelect(choices=[(True, "Yes"), (False, "No")]),
|
||||
"hide_referrer_regex": forms.TextInput(),
|
||||
}
|
||||
labels = {
|
||||
"origins": "Allowed Hostnames",
|
||||
"respect_dnt": "Respect DNT",
|
||||
"collect_ips": "Collect IP addresses",
|
||||
"ignored_ips": "Ignored IP addresses",
|
||||
"hide_referrer_regex": "Hide specific referrers",
|
||||
}
|
||||
help_texts = {
|
||||
"name": _("What should the service be called?"),
|
||||
@@ -25,6 +40,9 @@ class ServiceForm(forms.ModelForm):
|
||||
"At what hostnames does the service operate? This sets CORS headers, so use '*' if you're not sure (or don't care)."
|
||||
),
|
||||
"respect_dnt": "Should visitors who have enabled <a href='https://en.wikipedia.org/wiki/Do_Not_Track'>Do Not Track</a> be excluded from all data?",
|
||||
"collect_ips": "Should individual IP addresses be collected? IP metadata (location, host, etc) will still be collected.",
|
||||
"ignored_ips": "A comma-separated list of IP addresses or IP ranges (IPv4 and IPv6) to exclude from tracking (e.g., '192.168.0.2, 127.0.0.1/32').",
|
||||
"hide_referrer_regex": "Any referrers that match this <a href='https://regexr.com/'>RegEx</a> will not be listed in the referrer summary. Sessions will still be tracked normally. No effect if left blank.",
|
||||
}
|
||||
|
||||
collaborators = forms.CharField(
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
<body class="bg-gray-200 min-h-full">
|
||||
{% block body %}
|
||||
|
||||
<section class="max-w-screen-xl mx-auto px-4 md:px-0 py-4 md:py-12 md:flex">
|
||||
<aside class="mb-8 md:w-2/12 md:pr-6 relative flex flex-wrap md:block justify-between items-center">
|
||||
<section class="max-w-screen-xl mx-auto px-4 py-4 md:py-12 md:flex">
|
||||
<aside class="mb-8 md:w-2/12 md:pr-6 relative flex flex-wrap md:block justify-between items-center overflow-x-hidden">
|
||||
<a class="icon ~urge ml-2 md:ml-6 md:mb-8 md:mt-3" href="{% url 'dashboard:dashboard' %}">
|
||||
<i class="fas fa-binoculars fa-3x text-purple-600 hidden md:block"></i>
|
||||
<i class="fas fa-binoculars fa-2x text-purple-600 md:hidden"></i>
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
{{form.link|a17t}}
|
||||
{{form.collaborators|a17t}}
|
||||
|
||||
<details class="p-4 border rounded">
|
||||
<details {% if form.errors %}open{% endif %}>
|
||||
<summary class="cursor-pointer text-sm">Advanced settings</summary>
|
||||
<hr class="sep h-4">
|
||||
{{form.respect_dnt|a17t}}
|
||||
{{form.collect_ips|a17t}}
|
||||
{{form.ignored_ips|a17t}}
|
||||
{{form.hide_referrer_regex|a17t}}
|
||||
{{form.origins|a17t}}
|
||||
</details>
|
||||
@@ -60,7 +60,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<p>IP</p>
|
||||
<p class="label" title="{{session.ip}}">{{session.ip|truncatechars:"16"}}</p>
|
||||
<p class="label" title="{{session.ip}}">{{session.ip|default:"Not Collected"|truncatechars:"16"}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
<p>Place the following snippet at the end of the <code><body></code> tag on any page you'd like to track.</p>
|
||||
<div class="card ~neutral !high font-mono text-sm">
|
||||
{% filter force_escape %}<noscript><img
|
||||
src="//{{request.site.domain}}{% url 'ingress:endpoint_pixel' object.uuid %}"></noscript>
|
||||
<script src="//{{request.site.domain}}{% url 'ingress:endpoint_script' object.uuid %}"></script>
|
||||
src="{{script_protocol}}{{request.site.domain}}{% url 'ingress:endpoint_pixel' object.uuid %}"></noscript>
|
||||
<script src="{{script_protocol}}{{request.site.domain}}{% url 'ingress:endpoint_script' object.uuid %}"></script>
|
||||
{% endfilter %}
|
||||
</div>
|
||||
<hr class="sep h-4">
|
||||
|
||||
@@ -81,11 +81,11 @@ def percent_change_display(start, end):
|
||||
|
||||
return SafeString(direction + pct_change)
|
||||
|
||||
|
||||
@register.inclusion_tag("dashboard/includes/sidebar_footer.html")
|
||||
def sidebar_footer():
|
||||
return {
|
||||
"version": settings.VERSION
|
||||
}
|
||||
return {"version": settings.VERSION}
|
||||
|
||||
|
||||
@register.inclusion_tag("dashboard/includes/stat_comparison.html")
|
||||
def compare(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.cache import cache
|
||||
@@ -85,6 +86,11 @@ class ServiceUpdateView(
|
||||
)
|
||||
return resp
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
data = super().get_context_data(*args, **kwargs)
|
||||
data["script_protocol"] = "https://" if settings.SCRIPT_USE_HTTPS else "http://"
|
||||
return data
|
||||
|
||||
|
||||
class ServiceDeleteView(
|
||||
LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageMixin, DeleteView
|
||||
|
||||
7
shynet/entrypoint.sh
Executable file
7
shynet/entrypoint.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ ! $PERFORM_CHECKS_AND_SETUP == False ]]; then
|
||||
./startup_checks.sh
|
||||
fi
|
||||
|
||||
./webserver.sh
|
||||
@@ -14,7 +14,7 @@ import os
|
||||
from django.contrib.messages import constants as messages
|
||||
|
||||
# Increment on new releases
|
||||
VERSION = "v0.2.1"
|
||||
VERSION = "v0.4.0"
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
@@ -27,7 +27,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", "onlyusethisindev")
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = os.getenv("DEBUG", "True") == "True"
|
||||
DEBUG = os.getenv("DEBUG", "False") == "True"
|
||||
|
||||
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "*").split(",")
|
||||
|
||||
@@ -214,7 +214,7 @@ SITE_ID = 1
|
||||
|
||||
# Celery
|
||||
|
||||
CELERY_TASK_ALWAYS_EAGER = os.getenv("CELERY_TASK_ALWAYS_EAGER", "False") == "True"
|
||||
CELERY_TASK_ALWAYS_EAGER = os.getenv("CELERY_TASK_ALWAYS_EAGER", "True") == "True"
|
||||
|
||||
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL")
|
||||
CELERY_REDIS_SOCKET_TIMEOUT = 15
|
||||
@@ -261,3 +261,7 @@ SCRIPT_USE_HTTPS = os.getenv("SCRIPT_USE_HTTPS", "True") == "True"
|
||||
# How frequently should the tracking script "phone home" with a heartbeat, in
|
||||
# milliseconds?
|
||||
SCRIPT_HEARTBEAT_FREQUENCY = int(os.getenv("SCRIPT_HEARTBEAT_FREQUENCY", "5000"))
|
||||
|
||||
# How much time can elapse between requests from the same user before a new
|
||||
# session is created, in seconds?
|
||||
SESSION_MEMORY_TIMEOUT = int(os.getenv("SESSION_MEMORY_TIMEOUT", "1800"))
|
||||
|
||||
2
shynet/ssl.webserver.sh
Normal file → Executable file
2
shynet/ssl.webserver.sh
Normal file → Executable file
@@ -4,7 +4,7 @@
|
||||
echo Launching Shynet web server...
|
||||
exec gunicorn shynet.wsgi:application \
|
||||
--bind 0.0.0.0:8080 \
|
||||
--workers 3 \
|
||||
--workers ${NUM_WORKERS:-1} \
|
||||
--timeout 100 \
|
||||
--certfile=cert.pem \
|
||||
--keyfile=privkey.pem
|
||||
45
shynet/startup_checks.sh
Executable file
45
shynet/startup_checks.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# Check if setup is necessary, do setup as needed
|
||||
echo "Performing startup checks..."
|
||||
sanity_results=( $(./manage.py startup_checks) )
|
||||
if [[ ${sanity_results[0]} == True ]]; then
|
||||
echo "Running migrations (setting up DB)..."
|
||||
{
|
||||
./manage.py migrate && echo "Migrations complete!"
|
||||
} || {
|
||||
echo "Migrations failed, exiting" && exit 1
|
||||
}
|
||||
else
|
||||
echo "Database is ready to go."
|
||||
fi
|
||||
if [[ -n $SHYNET_ADMIN_EMAIL && ${sanity_results[1]} == True ]]; then
|
||||
echo "Creating an admin user..."
|
||||
{
|
||||
temppwd=$( ./manage.py registeradmin $SHYNET_ADMIN_EMAIL ) && echo "Admin user ($SHYNET_ADMIN_EMAIL) created! Password: $temppwd"
|
||||
} || {
|
||||
echo "Failed to create admin, exiting" & exit 1
|
||||
}
|
||||
else
|
||||
echo "Making no changes to admin user."
|
||||
fi
|
||||
if [[ -n $SHYNET_HOST && ${sanity_results[2]} == True ]]; then
|
||||
echo "Setting hostname..."
|
||||
{
|
||||
./manage.py hostname $SHYNET_HOST && echo "Hostname set to $SHYNET_HOST!"
|
||||
} || {
|
||||
echo "Failed setting hostname, exiting" & exit 1
|
||||
}
|
||||
else
|
||||
echo "Making no changes to hostname."
|
||||
fi
|
||||
if [[ -n $SHYNET_WHITELABEL && ${sanity_results[3]} == True ]]; then
|
||||
echo "Setting whitelabel..."
|
||||
{
|
||||
./manage.py whitelabel $SHYNET_WHITELABEL && echo "Whitelabel set! Whitelabel: $SHYNET_WHITELABEL"
|
||||
} || {
|
||||
echo "Failed to set whitelabel, exiting" & exit 1
|
||||
}
|
||||
else
|
||||
echo "Making no changes to whitelabel."
|
||||
fi
|
||||
echo "Startup checks complete!"
|
||||
@@ -1,8 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Start Gunicorn processes
|
||||
echo Launching Shynet web server...
|
||||
exec gunicorn shynet.wsgi:application \
|
||||
--bind 0.0.0.0:8080 \
|
||||
--workers 3 \
|
||||
--workers ${NUM_WORKERS:-1} \
|
||||
--timeout 100
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<body>
|
||||
<noscript><img src="//localhost:8000/ingress/test_uuid/pixel.gif"></noscript>
|
||||
<script src="//localhost:8000/ingress/test_uuid/script.js"></script>
|
||||
<script src="//localhost:8000/ingress/66015ce4-c69d-40fb-be8f-5535538d795e/script.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user