Skip to content

Commit

Permalink
Merge pull request #685 from henrywhitaker3/fix/680/last-x-days
Browse files Browse the repository at this point in the history
#680: Fix issue where the data would refresh before the react state had updated
  • Loading branch information
henrywhitaker3 authored Sep 10, 2021
2 parents 9fb573e + 283de67 commit 858dcc1
Show file tree
Hide file tree
Showing 16 changed files with 681 additions and 161,189 deletions.
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log

.vscode/

_ide_helper.php
.idea
.config
reports/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Speedtest Tracker

[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker?style=flat-square)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Stable?label=master&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Dev?label=dev&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.12.0-success?style=flat-square) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker?style=flat-square)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Stable?label=master&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Dev?label=dev&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.12.1-success?style=flat-square) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)

This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [Ookla's speedtest cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/AcceptEULACommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function __construct()
public function handle()
{
$this->info('Acceping EULA');
shell_exec(config('speedtest.home') . ' && timeout 3s ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr');
shell_exec(config('speedtest.home') . ' && timeout 10s ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr');
}
}
6 changes: 6 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"1.12.1": [
{
"description": "Fixed a bug where the latest X days widget would not update (#680)",
"link": "https://github.com/henrywhitaker3/Speedtest-Tracker/pull/680"
}
],
"1.12.0": [
{
"description": "Added InfluxDB intergation.",
Expand Down
6 changes: 3 additions & 3 deletions config/speedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
|--------------------------------------------------------------------------
*/

'version' => '1.12.0',
'version' => '1.12.1',

/*
|--------------------------------------------------------------------------
| Installation type
|--------------------------------------------------------------------------
*/

'install' => 'manual',
'install' => 'docker',

/*
|--------------------------------------------------------------------------
| Path for HOME variable
|--------------------------------------------------------------------------
*/

'home' => 'HOME=' . base_path() . DIRECTORY_SEPARATOR,
'home' => 'HOME=/config',

/*
|--------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM linuxserver/nginx
LABEL maintainer=henrywhitaker3@outlook.com

ENV arch='x86_64'

COPY docker/conf/ /
COPY . /site

EXPOSE 80 443

VOLUME ["/config"]
10 changes: 10 additions & 0 deletions docker/arm.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM linuxserver/nginx:arm32v7-latest
LABEL maintainer=henrywhitaker3@outlook.com

ENV arch='arm'

COPY conf/ /

EXPOSE 80 443

VOLUME ["/config"]
10 changes: 10 additions & 0 deletions docker/conf/defaults/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# do daily/weekly/monthly maintenance
# min hour day month weekday command
*/15 * * * * run-parts /etc/periodic/15min
0 * * * * run-parts /etc/periodic/hourly
0 2 * * * run-parts /etc/periodic/daily
0 3 * * 6 run-parts /etc/periodic/weekly
0 5 1 * * run-parts /etc/periodic/monthly
# speedtest cron
* * * * * php /config/www/artisan schedule:run >> /config/log/speedtest/cron.log
# */5 * * * * php /config/www/artisan queue:retry all >> /config/log/speedtest.cron.log
30 changes: 30 additions & 0 deletions docker/conf/defaults/default
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
server {
listen 80 default_server;

listen 443 ssl;

root /config/www/public;
index index.html index.htm index.php;

server_name _;

ssl_certificate /config/keys/cert.crt;
ssl_certificate_key /config/keys/cert.key;

client_max_body_size 0;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;

}
}
138 changes: 138 additions & 0 deletions docker/conf/etc/cont-init.d/50-speedtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/usr/bin/with-contenv bash
# # This script sets up the speedtest app

function eulaError()
{
echo "##################################################################################################################################"
echo "##################################################################################################################################"
echo "You haven't accepted the Ookla EULA. Please re-create the container with the environment variable 'OOKLA_EULA_GDPR' set to 'true'."
echo "##################################################################################################################################"
echo "##################################################################################################################################"
exit 1
}

# Do Ookla stuff
if [ -z ${OOKLA_EULA_GDPR+x} ]; then
eulaError
else
if [ $OOKLA_EULA_GDPR != "true" ]; then
eulaError
fi

if [ ! -f /config/www/app/Bin/speedtest ]; then
echo "Ookla GDPR and EULA accepted. Downloading Speedtest CLI."
cd /tmp
wget https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-$arch-linux.tgz -O speedtest.tgz > /dev/null
tar zxvf speedtest.tgz > /dev/null
cp speedtest /site/app/Bin/

HOME=/config && s6-setuidgid abc /site/artisan speedtest:eula > /dev/null
HOME=/root
else
HOME=/config && s6-setuidgid abc /config/www/artisan speedtest:eula > /dev/null
HOME=/root
fi
fi

# Copy site files to /config
echo "Copying latest site files to config"
cp -rfT /site/ /config/www/

# Check for DB
if [ ! -f /config/speed.db ]; then
echo "Database file not found! Creating empty database"
touch /config/speed.db
else
echo "Database file exists"
chown abc:abc /config/speed.db
fi

# Check for .env
if [ ! -f /config/www/.env ]; then
echo "Env file not found! Creating .env file"
cp /site/.env.example /config/www/.env
else
echo "Env file exists"
fi

if [ ! -f /config/www/.composer-time ]; then
echo 'Removing old packages'
rm -rf /config/www/vendor/
fi

echo 'Updating packages'
apk add composer
cd /config/www && composer install && echo date > /config/www/.composer-time

sed "s,DB_DATABASE=.*,DB_DATABASE=/config/speed.db," -i.bak /config/www/.env

echo "Running database migrations"
php /config/www/artisan migrate

# Check app key exists
if grep -E "APP_KEY=[0-9A-Za-z:+\/=]{1,}" /config/www/.env > /dev/null; then
echo "App key exists"
else
echo "Generating app key"
php /config/www/artisan key:generate
fi

# Check JWT secret exists
if grep -E "JWT_SECRET=[0-9A-Za-z:+\/=]{1,}" /config/www/.env > /dev/null ; then
echo "JWT secret exists"
else
echo "Generating JWT secret"
php /config/www/artisan jwt:secret
fi

if [ -z ${SLACK_WEBHOOK+x} ]; then
echo "Slack webhook is unset"
sed "s,SLACK_WEBHOOK=.*,SLACK_WEBHOOK=," -i.bak /config/www/.env
else
echo "Slack webhook set, updating db"
sed "s,SLACK_WEBHOOK=.*,SLACK_WEBHOOK=$SLACK_WEBHOOK," -i.bak /config/www/.env
php /config/www/artisan speedtest:slack $SLACK_WEBHOOK
fi

if [ -z ${TELEGRAM_BOT_TOKEN+x} ] && [ -z ${TELEGRAM_CHAT_ID+x} ]; then
echo "Telegram chat id and bot token unset"
sed "s,TELEGRAM_BOT_TOKEN=.*,TELEGRAM_BOT_TOKEN=," -i.bak /config/www/.env
sed "s,TELEGRAM_CHAT_ID=.*,TELEGRAM_CHAT_ID=," -i.bak /config/www/.env
else
echo "Telegram chat id and bot token set, updating .env"
sed "s,TELEGRAM_BOT_TOKEN=.*,TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN," -i.bak /config/www/.env
sed "s,TELEGRAM_CHAT_ID=.*,TELEGRAM_CHAT_ID=$TELEGRAM_CHAT_ID," -i.bak /config/www/.env
php /config/www/artisan speedtest:telegram --chat=$TELEGRAM_CHAT_ID --bot=$TELEGRAM_BOT_TOKEN
fi

if [ -z ${BASE_PATH+x} ]; then
echo "Base path is unset"
sed "s,BASE_PATH=.*,BASE_PATH=," -i.bak /config/www/.env
else
echo "Base path set, updating .env"
sed "s,BASE_PATH=.*,BASE_PATH=$BASE_PATH," -i.bak /config/www/.env
fi

if [ -z ${AUTH+x} ]; then
echo "AUTH variable not set. Disabling authentication"
php /config/www/artisan speedtest:auth --disable
else
if [ $AUTH == 'true' ]; then
echo "AUTH variable set. Enabling authentication"
php /config/www/artisan speedtest:auth --enable
else
echo "AUTH variable set, but not to 'true'. Disabling authentication"
php /config/www/artisan speedtest:auth --disable
fi
fi

echo "Clearing old jobs from queue"
php /config/www/artisan queue:clear

mkdir -p /config/log/speedtest

cp /defaults/crontab /etc/crontabs/root

chown -R abc:abc /config
chmod +x /config/www/app/Bin/speedtest
chmod -R 777 /config/www/storage/clockwork
Loading

0 comments on commit 858dcc1

Please sign in to comment.