Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fecea17a9d | ||
|
|
03062e3de5 | ||
|
|
6652acdf14 | ||
|
|
1dfbec06e1 | ||
|
|
3e315f06ed | ||
|
|
2d42674e1a | ||
|
|
e4deab2072 | ||
|
|
c5ed5ef0e7 | ||
|
|
7268a4ea84 | ||
|
|
2cbc5ac441 | ||
|
|
058601d669 | ||
|
|
213c44a45a | ||
|
|
8b98cf2277 | ||
|
|
4c53b94588 | ||
|
|
a70e07be05 |
40
GUIDE.md
40
GUIDE.md
@@ -4,6 +4,7 @@
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Heroku](#heroku)
|
||||
- [Render](#render)
|
||||
- [Updating Your Configuration](#updating-your-configuration)
|
||||
- [Advanced Usage](#advanced-usage)
|
||||
* [Installation with SSL](#installation-with-ssl)
|
||||
@@ -12,15 +13,17 @@
|
||||
+ [Nginx](#nginx)
|
||||
* [Health Checks](#health-checks)
|
||||
* [Primary Key Integration](#primary-key-integration)
|
||||
* [Usage with Single-Page Applications](#usage-with-single-page-applications)
|
||||
+ [Troubleshooting](#troubleshooting)
|
||||
---
|
||||
|
||||
## Staying Updated
|
||||
|
||||
**If you install Shynet, you should strongly consider enabling notifications when new versions are released.** You can do this under the "Watch" tab on GitHub (above). This will ensure that you are notified when new versions are available, some of which may be security updates. (Shynet will never automatically update itself.)
|
||||
|
||||
## Installation
|
||||
|
||||
Installation of Shynet is easy! Follow the [Basic Installation](#basic-installation) guide below if you'd like to run Shynet over HTTP or if you are going to be running it over HTTPS through a reverse proxy. If you'd like to run Shynet over HTTPS without a reverse proxy, skip ahead to [Installation with SSL](#installation-with-ssl) instead.
|
||||
Installation of Shynet is easy! Follow the [Basic Installation](#basic-installation) guide or the [Basic Installation with Docker Compose](#basic-installation-with-docker-compose) below for a minimal installation, or if you are going to be running Shynet over HTTPS through a reverse proxy. If you'd like to run Shynet over HTTPS without a reverse proxy, skip ahead to [Installation with SSL](#installation-with-ssl) instead.
|
||||
|
||||
> **These commands assume Ubuntu.** If you're installing Shynet on a different platform, the process will be different.
|
||||
|
||||
@@ -48,6 +51,27 @@ Before continuing, please be sure to have the latest version of Docker installed
|
||||
|
||||
10. 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.
|
||||
|
||||
|
||||
### Basic Installation with Docker Compose
|
||||
|
||||
> Make sure you have `docker-compose` installed. If not, [install it](https://docs.docker.com/compose/install/)
|
||||
|
||||
1. Clone the repository.
|
||||
|
||||
2. Using [TEMPLATE.env](/TEMPLATE.env) as a template, confiure the environment for your Shynet instance and place the modified config in a file called `.env` in the root of the repository. Do _not_ change the port number at the end; you can set the public facing port in the next step.
|
||||
|
||||
3. On line 2 of the `nginx.conf` file located in the root of the repository, replace `example.com` with your hostname. Then, in the `docker-compose.yml` file, set the port number by replacing `8080` in line 38 ( `- 8080:80` ) with whatever local port you want to bind it to. For example, set the port number to `- 80:80` if you want your site will be available via HTTP (port 80) at `http://<your hostname>`.
|
||||
|
||||
4. Launch the Shynet server for the first time by running `docker-compose up -d`. If you get an error like "permission denied" or "Couldn't connect to Docker daemon", either prefix the command with `sudo` or add your user to the `docker` group.
|
||||
|
||||
5. Create an admin user by running `docker exec -it shynet_main ./manage.py registeradmin <your email>`. A temporary password will be printed to the console.
|
||||
|
||||
6. Set the hostname of your Shynet instance by running `docker exec -it shynet_main ./manage.py hostname <your public hostname>`, where `<your public hostname>` is the same as the hostname you set in step 3. This setting affects the URL that the tracking script sends its results to, so make sure it's correct. (Example hostnames: shynet.example.com or example.com:8000.)
|
||||
|
||||
7. Set the whitelabel of your Shynet instance by running `docker exec -it shynet_main ./manage.py whitelabel <whitelabel>`. While this setting doesn't affect any core operations of Shynet, it lets you rename Shynet to whatever you want. (Example whitelabels: "My Shynet Instance" or "Acme Analytics".)
|
||||
|
||||
Your site should now be accessible at `http://hostname:port`. Now you can follow steps 9-10 of the [Basic Installation](#basic-installation) guide above to get Shynet integrated on your sites.
|
||||
|
||||
## Heroku
|
||||
|
||||
You may wish to deploy Shynet on Heroku. Note that Heroku's free offerings (namely the free Postgres addon) are unlikely to support running any Shynet instance that records more than a few hundred requests per day — the database will quickly fill up. In most cases, the more cost-effective option for running Shynet is renting a VPS from a full cloud service provider. However, if you're sure Heroku is the right option for you, or you just want to try Shynet out, you can use the Quick Deploy button then follow the steps below.
|
||||
@@ -60,6 +84,20 @@ Once you deploy, you'll need to setup an admin user, whitelabel, and hostname be
|
||||
2. `heroku run --app=<your app> ./manage.py hostname <the hostname where you will run Shynet>`
|
||||
3. `heroku run --app=<your app> ./manage.py whitelabel "<your Shynet instance's name>"`
|
||||
|
||||
## Render
|
||||
|
||||
[Render](https://render.com) is a modern cloud platform to build and run all your apps and websites with free SSL, a global CDN, private networks and auto deploys from Git. To deploy Shynet, click the `Deploy to Render` button and follow the steps below.
|
||||
|
||||
[](https://render.com/deploy?repo=https://github.com/render-examples/shynet)
|
||||
|
||||
Once your deploy has completed, use the **Render Shell** to configure your app:
|
||||
|
||||
1. Set your email: `./manage.py registeradmin your-email@example.com`
|
||||
1. Add your onrender.com domain: `./manage.py hostname your-shynet-domain.onrender.com`
|
||||
1. Set your whitelabel: `./manage.py whitelabel "Your Shynet Instance Name"`
|
||||
|
||||
See the [Render docs](https://render.com/docs/deploy-shynet) for more information on deploying your application on Render.
|
||||
|
||||
---
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
version: '3'
|
||||
services:
|
||||
shynet:
|
||||
container_name: shynet_main
|
||||
image: milesmcc/shynet:latest
|
||||
restart: unless-stopped
|
||||
expose:
|
||||
@@ -16,6 +17,7 @@ services:
|
||||
depends_on:
|
||||
- db
|
||||
db:
|
||||
container_name: shynet_database
|
||||
image: postgres
|
||||
restart: always
|
||||
environment:
|
||||
@@ -26,6 +28,18 @@ services:
|
||||
- shynet_db:/var/lib/postgresql/data
|
||||
networks:
|
||||
- internal
|
||||
webserver:
|
||||
container_name: shynet_webserver
|
||||
image: nginx
|
||||
restart: always
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
ports:
|
||||
- 8080:80
|
||||
depends_on:
|
||||
- shynet
|
||||
networks:
|
||||
- internal
|
||||
volumes:
|
||||
shynet_db:
|
||||
networks:
|
||||
|
||||
19
nginx.conf
Normal file
19
nginx.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
server {
|
||||
server_name example.com;
|
||||
access_log /var/log/nginx/bin.access.log;
|
||||
error_log /var/log/nginx/bin.error.log error;
|
||||
|
||||
|
||||
location / {
|
||||
proxy_pass http://shynet:8080;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Protocol $scheme;
|
||||
proxy_set_header X-Url-Scheme $scheme;
|
||||
}
|
||||
listen 80;
|
||||
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
<nav class="flex w-full flex-wrap items-center justify-between" role="navigation" aria-label="pagination">
|
||||
<div class="w-full md:w-auto mb-2">
|
||||
{% if page.has_previous %}
|
||||
<a href="?page={{ page.previous_page_number }}{{url_parameters}}" class="button field w-auto mr-1">Previous</a>
|
||||
<a href="?page={{ page.previous_page_number }}{{url_parameters}}" class="button field bg-neutral-000 w-auto mr-1">Previous</a>
|
||||
{% else %}
|
||||
<a class="button field w-auto mr-1" disabled>Previous</a>
|
||||
<a class="button field bg-neutral-000 w-auto mr-1" disabled>Previous</a>
|
||||
{% endif %}
|
||||
{% if page.has_next %}
|
||||
<a href="?page={{ page.next_page_number }}{{url_parameters}}" class="button field w-auto">Next</a>
|
||||
<a href="?page={{ page.next_page_number }}{{url_parameters}}" class="button field bg-neutral-000 w-auto">Next</a>
|
||||
{% else %}
|
||||
<a class="button field w-auto" disabled>Next</a>
|
||||
<a class="button field bg-neutral-000 w-auto" disabled>Next</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
{% ifequal page.number pnum %}
|
||||
<li><a class="button field w-auto mx-1 text-white bg-neutral-700">{{ pnum }}</a></li>
|
||||
{% else %}
|
||||
<li><a class="button field w-auto mx-1" href="?page={{ pnum }}{{url_parameters}}">{{ pnum }}</a></li>
|
||||
<li><a class="button field bg-neutral-000 w-auto mx-1" href="?page={{ pnum }}{{url_parameters}}">{{ pnum }}</a></li>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
{% ifequal page.number pnum %}
|
||||
<li><a class="button field w-auto mx-1 text-white bg-neutral-700">{{ pnum }}</a></li>
|
||||
{% else %}
|
||||
<li><a class="button field w-auto mx-1" href="?page={{ pnum }}{{url_parameters}}">{{ pnum }}</a></li>
|
||||
<li><a class="button field bg-neutral-000 w-auto mx-1" href="?page={{ pnum }}{{url_parameters}}">{{ pnum }}</a></li>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
@@ -38,7 +38,7 @@
|
||||
{% ifequal page.number pnum %}
|
||||
<li><a class="button field w-auto mx-1 text-white bg-neutral-700">{{ pnum }}</a></li>
|
||||
{% else %}
|
||||
<li><a class="button field w-auto mx-1" href="?page={{ pnum }}{{url_parameters}}">{{ pnum }}</a></li>
|
||||
<li><a class="button field bg-neutral-000 w-auto mx-1" href="?page={{ pnum }}{{url_parameters}}">{{ pnum }}</a></li>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@@ -5,7 +5,7 @@ from urllib.parse import urlparse
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.http import Http404, HttpResponse, HttpResponseBadRequest
|
||||
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden
|
||||
from django.shortcuts import render, reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
@@ -53,9 +53,14 @@ class ValidateServiceOriginsMixin:
|
||||
|
||||
if origins != "*":
|
||||
remote_origin = request.META.get("HTTP_ORIGIN")
|
||||
origins = [origin.strip() for origin in origins.split(",")]
|
||||
if remote_origin is None and request.META.get("HTTP_REFERER") is not None:
|
||||
parsed = urlparse(request.META.get("HTTP_REFERER"))
|
||||
remote_origin = f"{parsed.scheme}://{parsed.netloc}".lower()
|
||||
origins = [origin.strip().lower() for origin in origins.split(",")]
|
||||
if remote_origin in origins:
|
||||
resp["Access-Control-Allow-Origin"] = remote_origin
|
||||
else:
|
||||
return HttpResponseForbidden()
|
||||
else:
|
||||
resp["Access-Control-Allow-Origin"] = "*"
|
||||
|
||||
@@ -87,7 +92,7 @@ class PixelView(ValidateServiceOriginsMixin, View):
|
||||
"R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
|
||||
)
|
||||
resp = HttpResponse(data, content_type="image/gif")
|
||||
resp["Cache-Control"] = "no-cache"
|
||||
resp["Cache-Control"] = "no-cache, no-store, must-revalidate"
|
||||
resp["Access-Control-Allow-Origin"] = "*"
|
||||
return resp
|
||||
|
||||
|
||||
@@ -20,6 +20,12 @@ class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
site = Site.objects.get(pk=settings.SITE_ID)
|
||||
site.domain = options.get("hostname")
|
||||
if options.get("hostname").lower().startswith("http"):
|
||||
self.stdout.write(
|
||||
self.style.WARNING(
|
||||
f"Warning: the hostname '{options.get('hostname')}' starts with `http`. You almost certainly don't want this. The hostname is supposed to be the raw domain name of your Shynet instance, without `http://` or `https://`. For example, if your Shynet instance will eventually be hosted at `https://analytics.example.com`, the hostname should be `analytics.example.com`."
|
||||
)
|
||||
)
|
||||
site.save()
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
|
||||
@@ -13,7 +13,7 @@ from core.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Internal command to perform startup sanity checks."
|
||||
help = "Internal command to perform startup checks."
|
||||
|
||||
def check_migrations(self):
|
||||
from django.db.migrations.executor import MigrationExecutor
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
{% block service_actions %}
|
||||
<div class="mr-2">{% include 'dashboard/includes/date_range.html' %}</div>
|
||||
<a href="{% url 'dashboard:service' object.uuid %}" class="button field ~neutral w-auto">Analytics →</a>
|
||||
<a href="{% url 'dashboard:service' object.uuid %}" class="button field ~neutral bg-neutral-000 w-auto">Analytics →</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block service_content %}
|
||||
|
||||
@@ -139,6 +139,9 @@ class ServiceSessionView(LoginRequiredMixin, PermissionRequiredMixin, DetailView
|
||||
context_object_name = "session"
|
||||
permission_required = "core.view_service"
|
||||
|
||||
def get_permission_object(self, **kwargs):
|
||||
return self.get_object().service
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data["object"] = get_object_or_404(Service, pk=self.kwargs.get("pk"))
|
||||
|
||||
@@ -18,7 +18,7 @@ import urllib.parse as urlparse
|
||||
from django.contrib.messages import constants as messages
|
||||
|
||||
# Increment on new releases
|
||||
VERSION = "v0.6.1"
|
||||
VERSION = "v0.6.3"
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
@@ -286,13 +286,13 @@ else:
|
||||
NPM_ROOT_PATH = "../"
|
||||
|
||||
NPM_FILE_PATTERNS = {
|
||||
"a17t": ["dist/a17t.css", "dist/tailwind.css"],
|
||||
"@fortawesome/fontawesome-free": ["js/all.min.js"],
|
||||
"apexcharts": ["dist/apexcharts.min.js"],
|
||||
"litepicker": ["dist/js/main.js"],
|
||||
"turbolinks": ["dist/turbolinks.js"],
|
||||
"stimulus": ["dist/stimulus.umd.js"],
|
||||
"inter-ui": ["Inter (web)/*"],
|
||||
"a17t": [os.path.join("dist", "a17t.css"), os.path.join("dist", "tailwind.css")],
|
||||
"apexcharts": [os.path.join("dist", "apexcharts.min.js")],
|
||||
"litepicker": [os.path.join("dist", "js", "main.js")],
|
||||
"turbolinks": [os.path.join("dist", "turbolinks.js")],
|
||||
"stimulus": [os.path.join("dist", "stimulus.umd.js")],
|
||||
"inter-ui": [os.path.join("Inter (web)", "*")],
|
||||
"@fortawesome": [os.path.join("fontawesome-free", "js", "all.min.js")],
|
||||
}
|
||||
|
||||
# Shynet
|
||||
|
||||
13
tests/js.html
Normal file
13
tests/js.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Pixel test</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="http://localhost:8000/ingress/9b2c4e2f-8d29-4418-82d4-b68e06795025/script.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -7,8 +7,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript><img src="http://localhost:8000/ingress/9b2c4e2f-8d29-4418-82d4-b68e06795025/pixel.gif"></noscript>
|
||||
<script src="http://localhost:8000/ingress/9b2c4e2f-8d29-4418-82d4-b68e06795025/script.js"></script>
|
||||
<img src="http://localhost:8000/ingress/9b2c4e2f-8d29-4418-82d4-b68e06795025/pixel.gif">
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user