diff --git a/.codecov.yml b/.codecov.yml
index ed045f9..c96b484 100755
--- a/.codecov.yml
+++ b/.codecov.yml
@@ -5,14 +5,7 @@ coverage:
default: false # Disable the default status that measures entire project, it seems to have trouble finding commits to compare against
notify:
-
- # Slack
slack:
default:
- url: secret:oCrBaxCGOkkOw2lS8/j3rPngZhcRXh9kN9XjSbMDM8zfskRv9qc8nLHsPE4nQ2IDMtCwU79dp/0olPDYjP8n3PaekRE0bq7jtZOyoyn2yRdojOLWGjfA4gyPI0bYApdTQPvFCeetsDg/7KKp/7lUcwryhtVoj2CwwvPi+rftVVQ=
-
- # Gitter
- gitter:
- default:
- url: secret:aSildbzaxigSAte00r9azncZLwEIV7p2EO84VSBsfAlwMvJwML0bzZn7CvEsHpYQm5MB1nYX4bYBJRHSlVQ9lo2XReDo2nilR5RVklbKC6caorVgOd4UzrIOnIghF1e6
+ url: secret:KUlue5nEd+KPP27k+9VunKrC5dPIIl6BZcLRMy0zeoYp9Fa0oGZTynRPiebbYvxfQwHvLC9tZhY88Pkimjgs9WTH+31inFKwAxCQXNid7xe8aUlTgPdn6fyNar3ZLGiKZZiW1EOJPal4ivV0rcnskn91JpS+Cw56rmvLfYZhSvs=
\ No newline at end of file
diff --git a/.env.example b/.env.example
index 6243fec..b85fe98 100755
--- a/.env.example
+++ b/.env.example
@@ -1,10 +1,10 @@
-# Development config options example for Slackemon
+# Development config options example for Slackémon
# Alessandro Pezzè / Tim Malone / May 2017
-# Set these as environment variables, or, if running in development environment, copy this file to .env
-# and set them here. You will need to set APP_ENV as an environment variable to 'development' for this
-# to be read.
+# Set these as environment variables, or, if running in a development environment, copy this file to .env
+# and set them here. If you're not using Docker Compose, you will need to set APP_ENV as an environment
+# variable to 'development' for this file to be read by PHP dotenv.
###################### REQUIRED VARIABLES ######################
@@ -25,7 +25,8 @@ SLACKEMON_INBOUND_URL=https://example.com/slackemon/
# Set a random token that cron.php will check for before running.
# REQUIRED: When running cron over the web eg. `cron.php?token=XXXXX` - protects from being invoked by someone else.
-# NOT REQUIRED: When you run cron.php from within your environment eg. `/usr/local/bin/php /var/www/html/cron.php`.
+# NOT REQUIRED: When you run cron.php from within your environment eg. `/usr/local/bin/php /var/www/html/cron.php` or
+# over the web on a local network (eg. in our Docker Compose set up).
SLACKEMON_CRON_TOKEN=XXXXXXXXXXXXXXXXXXXX
###################### OPTIONAL VARIABLES ######################
@@ -35,12 +36,12 @@ SLACKEMON_OPENWEATHERMAP_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Configure the data cache/store.
# Local is generally recommended, unless of course you're hosting on a service with a ephemeral filesystem.
-# The data cache cannot be disabled - it is required to run Slackemon.
+# The data cache cannot be disabled - it is required to run Slackémon.
-# 'aws', 'local' or 'postgres' (AWS is not recommended)
+# 'aws', 'local' or 'postgres' (AWS is not recommended for this option; S3 is not best for regularly changing data)
SLACKEMON_DATA_STORE_METHOD=local
-# 'aws' or 'local'
+# 'aws' or 'local' (when AWS is used, a backup local cache will be kept to reduce costs - great for ephemeral filesystems)
SLACKEMON_DATA_CACHE_METHOD=local
# Local data folder for use if 'local' is set for either of the above options
@@ -52,9 +53,9 @@ SLACKEMON_DATA_FOLDER=.data
SLACKEMON_DATA_BUCKET=xxxxxxxxxxxxxxx
# Configure the image cache - two methods are supported; either local, or via an AWS S3 bucket (or you can disable).
-# You should use the AWS option unless you are hosting Slackemon on a suitably fast server/connection.
+# You should use the AWS option unless you are hosting Slackémon on a suitably fast server/connection.
# Please do NOT disable the image cache unless doing so for a short time for testing - otherwise it will cause unfair
-# load for the external resources that Slackemon uses.
+# load for the external media resources that Slackémon uses.
# 'aws', 'local', or 'disabled'
SLACKEMON_IMAGE_CACHE_METHOD=local
@@ -68,12 +69,16 @@ SLACKEMON_IMAGE_CACHE_BUCKET=xxxxxxxxxxxxxxx
# Postgres access details.
# Only required if using 'postgres' for the data store above.
-# The format is postgres://username:password@host:port/database_name
-SLACKEMON_DATABASE_URL=postgres://postgres:password@172.17.0.2:5432/slackemon
+# Docker Compose format:
+POSTGRES_USER=slackemon_user
+POSTGRES_PASSWORD=slackemon_password
+POSTGRES_DB=slackemon_db
+# Alternative Postgres URL format if not using Docker Compose (uncomment to use; overrides the above):
+#SLACKEMON_DATABASE_URL=postgres://username:password@host:5432/database_name
# AWS access details.
# Only required if using 'aws' for either the data cache or image cache above.
-# 'us-east-1' is recommended for the region, as it is the same region Slack uses!
+# 'us-east-1' is recommended for the region, as it is the same region Slack uses and they'll be the ones requesting!
SLACKEMON_AWS_ID=XXXXXXXXXXXXXXXXXXXX
SLACKEMON_AWS_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SLACKEMON_AWS_REGION=us-east-1
diff --git a/.gitignore b/.gitignore
index 7cb2ebf..464ed08 100755
--- a/.gitignore
+++ b/.gitignore
@@ -7,4 +7,5 @@
/tests/logs
error_log
phpcs.xml
-phpunit.xml
\ No newline at end of file
+phpunit.xml
+docker-compose.override.yml
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 09a36a3..e458f66 100755
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,21 +32,14 @@ after_success:
- travis_retry php vendor/bin/codacycoverage clover tests/logs/clover.xml
notifications:
-
- # Slack
slack:
rooms:
- - secure: m2inJu16LhMQbAu8Z3gBwxuNU6emCDzIHObtmtoPS8ZevlJRfQj5Qi9EQSB4/AN1277aKg6kGi5B7cobaxWla5kWe6NCGKxFcpo099mZ3gB6sTPttz1E8XZbaEzast2oN+kRuiylJ7/XApiUfthrERpoeV9nBoGuuzTpfTNAzBT3ocC4wmNLDuT/UycBuN8uTgbU92CsKf41LP7m4IsOgCF7sC/tt2RogQNwfHoSjbsSSdn2FZdkA4n+hJRxz689z+Re4RCKzaZxJSoIFTn1ViNXyTOQF10brHrFBPKnqDfH0bC0rIC7RIaZ6s3rFrT/kb+AcScaHDbfS6tnC4Tl2TQtY4dUArIEstFIAgt9932TBRKsRdWO4m3nsRXbpKhLj6eVpC+ggVzsDFZ6QC6RBoO6v/XJyTyjwCHXOXWWXGrBqmKq3vz+71QO4j+CG2zGx/BPAVS45qx2nit/kXvCKifU66CuRvmejDz9aDpyRAZhnB/S7WJvXj9iCa6pgj+xreUm3Nif/ZGgyDEzdJCRQzwEP+nB0vxHX3yzraW25AUWahYLkAH1wKh39bc9YBFWzHsvcHX7sJZfJq9ZFpnbF33g4KdtRVqtRj//D32MTs9vzYFUNnqyJK5P5F94Kf78ZsGqIVt3q1Rw8jUCNVbDSHnBY1F0+JotT9eOU1ijadk=
+ - secure: p3dH7L5CFpk6lrmb7aiHVKwEl8Qpua+Mp3n09rYTE5LhTMaLHczzjqjatNrcyt4GMKSzpJI4axxZ3QXe8KCnl3rr6JwfEHR4jvS4TZbchKFuRfgwF54RMXbUtHfy9fK78LeAo6eQoBliEuDo9Qgk1GTOMtmBv9gOoYRgo3o5sgAAPhF8soD4daNJ70vIwUgZ3bGN7/KTMPweDuNfERJM9w/OrLtYuNKwFPNGSHHkONR5Y5H2lGZtxw9/kZxtvounAFQHwMZfuZpyPSqrqfK8xxJLumTdTrmb14JNm1o4MWelErBHXLmDcTJvJ03mRvEswxbFIePMSZjA913pFZkdR7uWzFo0Z5RRAi3LG9P5s+7UnQDnUxJIaXWYli9j8ikTuPOHXneiYmn4aGvHATvOA+MJ6EDNA1H1dwJ1PSfsFCeNWtvQ1Lt4hfA04GKQxIKoinakj23OmcUKK8eOW7zL3lu6pt1q8J61t33z+Oz/0Vf9i1ebFPNaKTv9M2sMHDLlFstx44WgGihUXhrhudT+1Kc580cYKiXumj8BQeMf9sjfZcn92iDyCk6cYHXdaLNvUqZzQKHAmFEUp/PL7mHd6+EKPz+AzPahfPhfQ3Wainy4woDjLagsODYGOlGicdoAe3SO2LvQO8fiLA7Ew3qGidxQFYOVJoGJgNjewRn9+ZY=
template:
- "Build <%{build_url}|#%{build_number}> (<%{compare_url}|%{commit}>) of %{repository}:%{branch} by %{author}"
- "%{result} in %{duration}"
- "(%{commit_message})"
- # Gitter
- webhooks:
- urls:
- - secure: bao71OyTzuN3rKR9XG+shHqwlSnjTKE7ZlAHspvUa3wMdiL0ttotpgday5OVfiYFT8DSvirmy+nMC2vCUZLuSM8umq5XJDqMjdjW3Cv+BQ+11/4pxGri7d3XHpbVUItdivCbldU3ma22iTh1Q7sTw3FhwQBDyezXUqvhwbwEVrMks3vMETr9vb99AbRfXn3PGcHYz7F1Ki3JnKnV18ZyH81qmt/pFZvpcqfsePTcuObON3iYSXbUHdOws/qUKFDCurg3NpZLRbwKdxfUnrbMV11OuZTTPtR8poVHFeSf4RpR1vrbS+QKFc5KXOuWe7CkDa7KEgZPRnprtfZWI7ageoS1EBLdbJEndRHbqpJpuYo1X1s9/hvh55cnSzC/zJCz4hMwMS5I0iMx2PGainZswXuER+RdTC3iOnzXdS9JoshsOqL1s9hBwMw5b5Ozj44vr6ySrHKN9cltFf6FhPZAwapKZK97hnOaGiJHHmcHQHSC6SJyS4m0nm8rRYRg2wTKsyKKnpRt6DA8xb+5f7D+7N3kI0PfHpLK+wYgr+HULf13Uz66A5gh+ScKsvyjxQOnLeHOwNOOwyD4SPrxzriGTyTN/hCfnILSH1fEF3r/mqPjGr/O6CvGT/RrHgUpfhghTf9S5u5HkUft+d+U+aim5RXpF9WP8IuGPRXzNCPT1ZI=
-
env:
global:
# Codacy code coverage
diff --git a/Dockerfile b/Dockerfile
index c28c5b6..2fe420c 100755
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,44 +1,26 @@
-FROM php:7.0-apache
+FROM php:7.0-fpm-alpine
LABEL maintainer "tdmalone@gmail.com"
-COPY . /var/www/html
-WORKDIR /var/www/html
+ENV PROJECT_ROOT /slackemon
-# Create a user
-RUN useradd -ms /bin/bash slackemon
+COPY . $PROJECT_ROOT
+WORKDIR $PROJECT_ROOT
-# Assign it to www-data
-RUN usermod -a -G www-data slackemon
-
-# Assign public_html to www-data
-RUN chown -R www-data:www-data /var/www/html
-
-# Change permission to only user and group www-data
-RUN chmod -R 774 /var/www/html
+RUN addgroup -g 1000 slackemon && \
+ adduser -u 1000 -G slackemon -s /bin/sh -D slackemon && \
+ chown -R slackemon:slackemon $PROJECT_ROOT && \
+ chmod -R 774 $PROJECT_ROOT
# Install git and zip, used by Composer; cron, nano, vim and finally postgres functions for PHP7
-RUN apt-get update && apt-get install git zlib1g-dev cron nano vim libpq-dev -y && \
+RUN apk --no-cache add git zlib-dev nano vim postgresql-dev && \
docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql && \
docker-php-ext-install zip pdo pdo_pgsql pgsql
-# Install the Composer package manager
+# Install Composer package manager
RUN curl -s http://getcomposer.org/installer | php
USER slackemon
-# Install dependencies as non-root
+# Install dependencies
RUN php composer.phar install
-
-# Separate container vendor from local vendor
-VOLUME /var/www/html/vendor
-
-# Use root to start the server
-USER root
-
-# Set up the cron job every minute, with the correct environment
-# then, start apache2 in foreground (https://github.com/docker-library/php/blob/76a1c5ca161f1ed6aafb2c2d26f83ec17360bc68/7.1/apache/Dockerfile#L205)
-CMD printenv > /etc/environment && \
- echo "* * * * * /usr/local/bin/php /var/www/html/cron.php" | crontab - && \
- cron && \
- apache2-foreground
diff --git a/README.md b/README.md
index 985e5fe..258d32b 100755
--- a/README.md
+++ b/README.md
@@ -1,9 +1,8 @@
# Slackémon
+[](https://twitter.com/slackemon)
[](https://github.com/tdmalone/slackemon/releases)
-[](https://gitter.im/slackemon/Lobby)
-[](https://github.com/tdmalone/slackemon/blob/master/LICENSE)
-[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Ftdmalone%2Fslackemon?ref=badge_shield)
+[](https://join.slack.com/playslackemon/shared_invite/MTk4Nzc5MTc0MDk2LTE0OTc3NTAwODgtNmU4MDZkZDU0MA)
[](https://travis-ci.org/tdmalone/slackemon)
[](https://ci.appveyor.com/project/TimMalone/slackemon)
[](https://hub.docker.com/r/tdmalone/slackemon/builds/)
@@ -54,8 +53,8 @@ Scroll down for more setup options
Setup of Slackémon is _not_ quick. This may be worked on further in the future. For now, there are quite a few steps!
1. Download/clone/etc. the contents of this repository, and put it on a web server somewhere that runs PHP7.
- * [Download ZIP](https://github.com/tdmalone/slackemon/archive/master.zip)
- * Clone with Git: `git clone https://github.com/tdmalone/slackemon.git`
+ * [Download ZIP](https://github.com/tdmalone/slackemon/archive/master.zip) or clone with Git: `git clone https://github.com/tdmalone/slackemon.git`
+ * You may need to install depdendencies as well by running `composer install`. If you don't have Composer, [get it here](https://getcomposer.org/download/) first. If you're not going to be developing Slackémon, you can speed up the install of depdendencies by instead running `composer install --no-dev`.
* Install with Composer: `composer require tdmalone/slackemon`
* [Deploy with Docker](https://github.com/tdmalone/slackemon/wiki/Installing-with-Docker)
* [Deploy with Heroku](https://github.com/tdmalone/slackemon/wiki/Installing-on-Heroku)
@@ -114,6 +113,9 @@ Last but not least, this project would never have happened without the extensive
## License
+[](https://github.com/tdmalone/slackemon/blob/master/LICENSE)
+[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Ftdmalone%2Fslackemon?ref=badge_shield)
+
Slackémon - Catch and battle Pokémon with your teammates on Slack
Copyright (C) 2016-2017, [Tim Malone](https://github.com/tdmalone) and contributors.
diff --git a/appveyor.yml b/appveyor.yml
index b4a835d..4f68e59 100755
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -28,16 +28,7 @@ notifications:
# Slack
- provider: Slack
incoming_webhook:
- secure: Z/sBH2RXNief0BVgo2cazy1KoJMgpA0dZup/E2NMKM9Z40bWyoIK0+yRRJ8HFRxZCNGS+Kri7epYUWDb4QZ8QZHOBKyREESninj1ZM2YT3U=
+ secure: Z/sBH2RXNief0BVgo2cazy1KoJMgpA0dZup/E2NMKM+cf3UbAFbkr+xk36cbCO5b0FLCE0QYdZFT6zCvGut/yftF6Ja6yEIkWqF6RNdzqyg=
on_build_success: true
on_build_failure: true
on_build_status_changed: true
-
- # Gitter
- # Currently configured in AppVeyor interface, as secure vars for webhook URLs are not supported yet
- #- provider: Webhook
- # url:
- # secure: /2tAaEmW+de0UbUmtpuQTWfzeiLuKfsUVjzDDMK0kKNkUlFSmH6Ik1/mRpHrhBiUn8SvsDlYSehnSHEFEbN4HQ==
- # on_build_success: true
- # on_build_failure: true
- # on_build_status_changed: true
\ No newline at end of file
diff --git a/config.php b/config.php
index 3bc0825..d4214f2 100755
--- a/config.php
+++ b/config.php
@@ -32,7 +32,18 @@
define( 'SLACKEMON_IMAGE_CACHE_FOLDER', getenv( 'SLACKEMON_IMAGE_CACHE_FOLDER' ) ?: '.image-cache' );
define( 'SLACKEMON_IMAGE_CACHE_BUCKET', getenv( 'SLACKEMON_IMAGE_CACHE_BUCKET' ) );
-define( 'SLACKEMON_DATABASE_URL', getenv( 'SLACKEMON_DATABASE_URL' ) ?: getenv( 'DATABASE_URL' ) );
+// Prefer SLACKEMON_DATABASE_URL, fallback to DATABASE_URL (Heroku) and then to POSTGRES_USER/PASSWORD/DB (Docker Compose)
+if ( getenv( 'SLACKEMON_DATABASE_URL' ) ) {
+ define( 'SLACKEMON_DATABASE_URL', getenv( 'SLACKEMON_DATABASE_URL' ) );
+} else if ( getenv( 'DATABASE_URL' ) ) {
+ define( 'SLACKEMON_DATABASE_URL', getenv( 'DATABASE_URL' ) );
+} else if ( getenv( 'POSTGRES_USER' ) && getenv( 'POSTGRES_PASSWORD' ) && getenv( 'POSTGRES_DB' ) ) {
+ define(
+ 'SLACKEMON_DATABASE_URL',
+ 'postgres://' . getenv( 'POSTGRES_USER' ) . ':' . getenv( 'POSTGRES_PASSWORD' ) .
+ '@database:5432/' . getenv( 'POSTGRES_DB' )
+ );
+}
define( 'SLACKEMON_AWS_ID', getenv( 'SLACKEMON_AWS_ID' ) );
define( 'SLACKEMON_AWS_SECRET', getenv( 'SLACKEMON_AWS_SECRET' ) );
diff --git a/cron.php b/cron.php
index 98b132a..b4a6727 100755
--- a/cron.php
+++ b/cron.php
@@ -9,9 +9,10 @@
define( 'SKIP_AUTH', true );
require_once( __DIR__ . '/lib/init.php' );
-// AUTH: Check if the cron token was set if running over the web.
+// AUTH: Check if the cron token was set - if running over the web from a non-local IP address.
if (
'cli' !== php_sapi_name() &&
+ ! slackemon_is_ip_private( $_SERVER['REMOTE_ADDR'] ) &&
( ! isset( $_REQUEST['token'] ) || SLACKEMON_CRON_TOKEN !== $_REQUEST['token'] )
) {
http_response_code( 403 );
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100755
index 0000000..5bf7f22
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,42 @@
+version: "2"
+services:
+ php:
+ image: tdmalone/slackemon
+ restart: always
+ volumes:
+ - ./:/slackemon
+ env_file:
+ - .env
+
+ webserver:
+ image: nginx:alpine
+ restart: always
+ ports:
+ - "80:80"
+ volumes:
+ - ./:/slackemon
+ - ./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf
+
+ database:
+ image: postgres:alpine
+ restart: always
+ expose:
+ - "5432"
+ volumes:
+ - db_data:/var/lib/postgresql/data
+ environment:
+ - PGDATA=/var/lib/postgresql/data/pgdata
+ env_file:
+ - .env
+
+ cronjob:
+ image: appropriate/curl
+ restart: always
+ volumes:
+ - ./etc/crond/root:/var/spool/cron/crontabs/root
+ command: crond -f
+
+# Local volume where to store data
+# in a persistent way
+volumes:
+ db_data:
diff --git a/etc/crond/root b/etc/crond/root
new file mode 100755
index 0000000..95aef4e
--- /dev/null
+++ b/etc/crond/root
@@ -0,0 +1 @@
+* * * * * curl webserver/cron.php
\ No newline at end of file
diff --git a/etc/nginx/default.conf b/etc/nginx/default.conf
new file mode 100755
index 0000000..350c976
--- /dev/null
+++ b/etc/nginx/default.conf
@@ -0,0 +1,22 @@
+server {
+ listen 80;
+ index index.php index.html;
+ server_name localhost;
+ error_log /var/log/nginx/error.log;
+ access_log /var/log/nginx/access.log;
+ root /slackemon;
+
+ location ~ /\. {
+ deny all;
+ }
+
+ location ~ \.php$ {
+ try_files $uri =404;
+ fastcgi_split_path_info ^(.+\.php)(/.+)$;
+ fastcgi_pass php:9000;
+ fastcgi_index index.php;
+ include fastcgi_params;
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+ fastcgi_param PATH_INFO $fastcgi_path_info;
+ }
+}
diff --git a/lib/functions.php b/lib/functions.php
index ea5837a..2ec6dbc 100755
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -83,7 +83,7 @@ function check_subcommands( $allowed_subcommands = [], $welcome_message = '' ) {
function slackemon_run_background_command( $path, $args, $additional_fields = [], $additional_fields_as_json = false ) {
// Build command URL
- $command_url = 'http://' . $_SERVER['SERVER_NAME'];
+ $command_url = 'http://' . $_SERVER['HTTP_HOST'];
$command_url .= 80 != $_SERVER['SERVER_PORT'] && 443 != $_SERVER['SERVER_PORT'] ? ':' . $_SERVER['SERVER_PORT'] : '';
$command_url .= str_replace( basename( $_SERVER['SCRIPT_NAME'] ), '', $_SERVER['SCRIPT_NAME'] );
$command_url .= $path;
@@ -153,7 +153,7 @@ function slackemon_run_background_command( $path, $args, $additional_fields = []
function slackemon_run_background_action( $path, $action, $callback_id ) {
// Build action URL
- $action_url = 'http://' . $_SERVER['SERVER_NAME'];
+ $action_url = 'http://' . $_SERVER['HTTP_HOST'];
$action_url .= 80 != $_SERVER['SERVER_PORT'] && 443 != $_SERVER['SERVER_PORT'] ? ':' . $_SERVER['SERVER_PORT'] : '';
$action_url .= str_replace( basename( $_SERVER['SCRIPT_NAME'] ), '', $_SERVER['SCRIPT_NAME'] );
$action_url .= $path;
@@ -221,4 +221,36 @@ function strtotitle( $title ) {
} // Function strtotitle
+/**
+ * Checks if an IP address is from a recognised private range.
+ *
+ * @link https://stackoverflow.com/a/13818126/1982136
+ */
+function slackemon_is_ip_private( $ip ) {
+
+ $private_ranges = [
+ '10.0.0.0|10.255.255.255', // Single class A network
+ '172.16.0.0|172.31.255.255', // 16 contiguous class B network
+ '192.168.0.0|192.168.255.255', // 256 contiguous class C network
+ '169.254.0.0|169.254.255.255', // Link-local address aka Automatic Private IP Addressing
+ '127.0.0.0|127.255.255.255' // Localhost
+ ];
+
+ $long_ip = ip2long( $ip );
+
+ if ( $long_ip && -1 !== $long_ip ) {
+
+ foreach ( $private_ranges as $range ) {
+ list ( $start, $end ) = explode( '|', $range );
+
+ if ( $long_ip >= ip2long( $start ) && $long_ip <= ip2long( $end ) ) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+
+} // Function slackemon_is_ip_private
+
// The end!
diff --git a/media/emoji/pikachu_bouncing.png b/media/emoji/pikachu_bounce.png
similarity index 100%
rename from media/emoji/pikachu_bouncing.png
rename to media/emoji/pikachu_bounce.png
diff --git a/media/emoji/pokeball-bounce.gif b/media/emoji/pokeball_bounce.gif
similarity index 100%
rename from media/emoji/pokeball-bounce.gif
rename to media/emoji/pokeball_bounce.gif
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index b2d60f5..d8d9ccf 100755
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -29,7 +29,7 @@
-
+
diff --git a/scripts/reset b/scripts/reset
index d90ddbf..27b4c44 100755
--- a/scripts/reset
+++ b/scripts/reset
@@ -1,17 +1,9 @@
#!/usr/bin/env bash
-# Run the stop script if our containers are running
-if [ 0 != `docker ps -qf "name=slackemon|postgres" | wc -l | tr -d '[:space:]'` ]; then
- `dirname $0`/stop
-fi
+# Resets and restarts the Slackemon environment in Docker Compose
+# YOU WILL LOSE ANY DATA STORED IN POSTGRES
-# 'rm' the containers if they exist already
-if [ 0 != `docker ps -aqf "name=slackemon|postgres" | wc -l | tr -d '[:space:]'` ]; then
- echo Removing containers...
- docker rm postgres
- docker rm slackemon
-fi
-
-echo Creating containers...
-docker run -de POSTGRES_PASSWORD=password -p 5432:5432 --name postgres postgres
-docker run -de APP_ENV=development -p 80:80 -v ${PWD}:/var/www/html -v /etc/localtime:/etc/localtime:ro --link postgres:postgres --name slackemon slackemon
+set -x # Output to stdout every command that is run
+docker-compose down # Stops and removes the Docker Compose containers
+docker volume rm slackemon_db_data # Remove Postgres data volume
+`dirname $0`/start # Run the start script
diff --git a/scripts/restart b/scripts/restart
new file mode 100755
index 0000000..33bfead
--- /dev/null
+++ b/scripts/restart
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+set -x # Output to stdout every command that is run
+`dirname $0`/stop # Run the stop script
+`dirname $0`/start # Run the start script
diff --git a/scripts/start b/scripts/start
index c256626..9f4c79f 100755
--- a/scripts/start
+++ b/scripts/start
@@ -1,11 +1,5 @@
#!/usr/bin/env bash
-# 'reset' the containers first if they don't exist yet
-if [ 0 == `docker ps -aqf "name=slackemon|postgres" | wc -l | tr -d '[:space:]'` ]; then
- echo Containers do not exist yet.
- `dirname $0`/reset
-else
- echo Starting containers...
- docker start postgres
- docker start slackemon
-fi
+set -x # Output to stdout every command that is run
+docker-compose up -d --remove-orphans # Start the Docker Compose containers detached from the
+ # current terminal, removing any previous containers
diff --git a/scripts/stop b/scripts/stop
index 34bb29d..5c0a7d5 100755
--- a/scripts/stop
+++ b/scripts/stop
@@ -1,10 +1,4 @@
#!/usr/bin/env bash
-if [ 0 == `docker ps -qf "name=slackemon|postgres" | wc -l | tr -d '[:space:]'` ]; then
- echo Containers are not running.
- exit
-fi
-
-echo Stopping containers...
-docker stop slackemon
-docker stop postgres
+set -x # Output to stdout every command that is run
+docker-compose stop # Stop the Docker Compose containers