Spotbweb by @woutercoppens

This commit is contained in:
Alexandre
2022-01-22 19:13:57 +01:00
parent a9e3743628
commit 8051670f16
25 changed files with 855 additions and 1 deletions

View File

@@ -0,0 +1,112 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: spotweb
# This file validates config and creates the database
# ==============================================================================
declare host
declare username
declare password
declare port
declare dbname
if bashio::config.has_value 'remote_mysql_host'; then
if ! bashio::config.has_value 'remote_mysql_database'; then
bashio::exit.nok \
"Remote database has been specified but no database is configured"
fi
if ! bashio::config.has_value 'remote_mysql_username'; then
bashio::exit.nok \
"Remote database has been specified but no username is configured"
fi
if ! bashio::config.has_value 'remote_mysql_password'; then
bashio::log.fatal \
"Remote database has been specified but no password is configured"
fi
if ! bashio::config.exists 'remote_mysql_port'; then
bashio::exit.nok \
"Remote database has been specified but no port is configured"
fi
host=$(bashio::config "remote_mysql_host")
password=$(bashio::config "remote_mysql_password")
port=$(bashio::config "remote_mysql_port")
username=$(bashio::config "remote_mysql_username")
dbname=$(bashio::config "remote_mysql_database")
else
# Require MySQL service to be available
if ! bashio::services.available mysql; then
bashio::log.fatal \
"Local database access should be provided by the MariaDB addon"
bashio::exit.nok \
"Please ensure it is installed and started"
fi
dbname="spotweb"
host=$(bashio::services mysql "host")
port=$(bashio::services mysql "port")
username=$(bashio::services mysql "username")
password=$(bashio::services mysql "password")
# password='spotweb'
# username='spotweb'
bashio::log.warning "Spotweb is using the Maria DB addon"
bashio::log.warning "Please ensure this is included in your backups"
bashio::log.warning "Uninstalling the MariaDB addon will remove any data"
fi
# write db config file for spotweb
{
echo "<?php"
echo "\$dbsettings['engine'] = 'pdo_mysql';"
echo "\$dbsettings['host'] = '${host}';"
echo "\$dbsettings['dbname'] = '${dbname}';"
echo "\$dbsettings['user'] = '${username}';"
echo "\$dbsettings['pass'] = '${password}';"
echo "\$dbsettings['port'] = '${port}';"
} > /app/dbsettings.inc.php
# cat /app/dbsettings.inc.php
# wait for mysql server to be available
until nc -z -v -w30 $host $port
do
bashio::log.info "Waiting for database connection at host '${host}:${port}'..."
sleep 2
done
# Check if database already exists
RESULT=`mysql -u "${username}" -p"${password}" -h "${host}" -P "${port}" --skip-column-names -e "SHOW DATABASES LIKE '${dbname}'"`
if [ "$RESULT" == "$dbname" ]; then
# database already exists, do healthcheck with upgrade-db
bashio::log.info "Existing database, checking health with upgrade-db...."
s6-setuidgid nginx php8 /app/bin/upgrade-db.php>/dev/null
else
# database does not yet exist
bashio::log.info "Creating database with default settings...."
mysql \
-u "${username}" -p"${password}" \
-h "${host}" -P "${port}" \
-e "CREATE DATABASE ${dbname};"
# init database with default values
s6-setuidgid nginx php8 /app/bin/upgrade-db.php
# set systemtype to public (as we're behind ingress)
s6-setuidgid nginx php8 /app/bin/upgrade-db.php --set-systemtype public
# we also set some sane default settings
mysql \
-u "${username}" -p"${password}" \
-h "${host}" -P "${port}" \
-D "${dbname}" \
-e "REPLACE INTO usergroups(userid, groupid) VALUES (1, 2); \
REPLACE INTO usergroups(userid, groupid) VALUES (1, 3); \
REPLACE INTO usergroups(userid, groupid) VALUES (1, 4); \
REPLACE INTO usergroups(userid, groupid) VALUES (1, 5); \
UPDATE usersettings SET otherprefs='a:27:{s:17:\"template_specific\";a:1:{s:6:\"we1rdo\";a:1:{s:15:\"example_setting\";i:1;}}s:7:\"perpage\";i:25;s:15:\"date_formatting\";s:5:\"human\";s:15:\"normal_template\";s:6:\"we1rdo\";s:15:\"mobile_template\";s:6:\"we1rdo\";s:15:\"tablet_template\";s:6:\"we1rdo\";s:14:\"count_newspots\";s:2:\"on\";s:17:\"mouseover_subcats\";s:2:\"on\";s:13:\"keep_seenlist\";s:2:\"on\";s:15:\"auto_markasread\";s:2:\"on\";s:17:\"keep_downloadlist\";s:2:\"on\";s:14:\"keep_watchlist\";s:2:\"on\";s:17:\"nzb_search_engine\";s:8:\"nzbindex\";s:13:\"show_filesize\";s:2:\"on\";s:16:\"show_reportcount\";s:2:\"on\";s:19:\"minimum_reportcount\";s:1:\"1\";s:14:\"show_nzbbutton\";s:2:\"on\";s:13:\"show_multinzb\";s:2:\"on\";s:9:\"customcss\";s:0:\"\";s:18:\"newspotdefault_tag\";s:9:\"anonymous\";s:19:\"newspotdefault_body\";s:0:\"\";s:13:\"user_language\";s:5:\"en_US\";s:12:\"show_avatars\";s:2:\"on\";s:27:\"usemailaddress_for_gravatar\";b:1;s:11:\"nzbhandling\";a:7:{s:6:\"action\";s:6:\"nzbget\";s:9:\"local_dir\";s:4:\"/tmp\";s:14:\"prepare_action\";s:5:\"merge\";s:7:\"command\";s:0:\"\";s:7:\"sabnzbd\";a:4:{s:3:\"url\";s:0:\"\";s:6:\"apikey\";s:0:\"\";s:8:\"username\";s:0:\"\";s:8:\"password\";s:0:\"\";}s:6:\"nzbget\";a:6:{s:4:\"host\";s:28:\"addon_62c7908d_nzbget_docker\";s:4:\"port\";s:5:\"46836\";s:3:\"ssl\";s:0:\"\";s:8:\"username\";s:6:\"nzbget\";s:8:\"password\";s:0:\"\";s:7:\"timeout\";s:2:\"30\";}s:9:\"nzbvortex\";a:3:{s:4:\"host\";s:0:\"\";s:4:\"port\";s:0:\"\";s:6:\"apikey\";s:0:\"\";}}s:13:\"notifications\";a:6:{s:6:\"boxcar\";a:3:{s:5:\"email\";s:0:\"\";s:7:\"enabled\";b:0;s:6:\"events\";a:7:{s:17:\"watchlist_handled\";b:0;s:11:\"nzb_handled\";b:0;s:18:\"retriever_finished\";b:0;s:13:\"report_posted\";b:0;s:11:\"spot_posted\";b:0;s:10:\"user_added\";b:0;s:19:\"newspots_for_filter\";b:0;}}s:5:\"growl\";a:4:{s:4:\"host\";s:0:\"\";s:8:\"password\";s:0:\"\";s:7:\"enabled\";b:0;s:6:\"events\";a:7:{s:17:\"watchlist_handled\";b:0;s:11:\"nzb_handled\";b:0;s:18:\"retriever_finished\";b:0;s:13:\"report_posted\";b:0;s:11:\"spot_posted\";b:0;s:10:\"user_added\";b:0;s:19:\"newspots_for_filter\";b:0;}}s:3:\"nma\";a:3:{s:3:\"api\";s:0:\"\";s:7:\"enabled\";b:0;s:6:\"events\";a:7:{s:17:\"watchlist_handled\";b:0;s:11:\"nzb_handled\";b:0;s:18:\"retriever_finished\";b:0;s:13:\"report_posted\";b:0;s:11:\"spot_posted\";b:0;s:10:\"user_added\";b:0;s:19:\"newspots_for_filter\";b:0;}}s:5:\"prowl\";a:3:{s:6:\"apikey\";s:0:\"\";s:7:\"enabled\";b:0;s:6:\"events\";a:7:{s:17:\"watchlist_handled\";b:0;s:11:\"nzb_handled\";b:0;s:18:\"retriever_finished\";b:0;s:13:\"report_posted\";b:0;s:11:\"spot_posted\";b:0;s:10:\"user_added\";b:0;s:19:\"newspots_for_filter\";b:0;}}s:7:\"twitter\";a:7:{s:11:\"screen_name\";s:0:\"\";s:13:\"request_token\";s:0:\"\";s:20:\"request_token_secret\";s:0:\"\";s:12:\"access_token\";s:0:\"\";s:19:\"access_token_secret\";s:0:\"\";s:7:\"enabled\";b:0;s:6:\"events\";a:7:{s:17:\"watchlist_handled\";b:0;s:11:\"nzb_handled\";b:0;s:18:\"retriever_finished\";b:0;s:13:\"report_posted\";b:0;s:11:\"spot_posted\";b:0;s:10:\"user_added\";b:0;s:19:\"newspots_for_filter\";b:0;}}s:5:\"email\";a:2:{s:7:\"enabled\";b:0;s:6:\"events\";a:7:{s:17:\"watchlist_handled\";b:0;s:11:\"nzb_handled\";b:0;s:18:\"retriever_finished\";b:0;s:13:\"report_posted\";b:0;s:11:\"spot_posted\";b:0;s:10:\"user_added\";b:0;s:19:\"newspots_for_filter\";b:0;}}}s:16:\"defaultsortfield\";s:0:\"\";}' WHERE 1;"
fi

View File

@@ -0,0 +1,3 @@
/app/cache true nginx:nginx 0644 0755
/var/tmp/nginx true nginx:nginx 0644 0755
/var/lib/nginx true nginx:nginx 0644 0755

View File

@@ -0,0 +1,96 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
font/woff woff;
font/woff2 woff2;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}

View File

@@ -0,0 +1,63 @@
# Run nginx in foreground.
daemon off;
# This is run inside Docker.
user nginx;
# Pid storage location.
pid /var/run/nginx.pid;
# Set number of worker processes.
worker_processes 1;
# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;
# Write error log to the add-on log.
error_log /proc/1/fd/1 error;
# Load allowed environment vars
env SUPERVISOR_TOKEN;
# Load dynamic modules.
include /etc/nginx/modules/*.conf;
# Max num of simultaneous connections by a worker process.
events {
worker_connections 1024;
}
http {
include /etc/nginx/includes/mime.types;
log_format homeassistant '[$time_local] $status '
'$http_x_forwarded_for($remote_addr) '
'$http_x_ingress_path '
'$request ($http_user_agent)';
access_log off;
client_max_body_size 100m;
default_type application/octet-stream;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
keepalive_timeout 2;
sendfile on;
server_tokens off;
tcp_nodelay on;
tcp_nopush on;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
map $http_x_forwarded_proto $fastcgi_https {
default off;
"~https" on;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
include /etc/nginx/servers/*.conf;
}

View File

@@ -0,0 +1,37 @@
server {
listen 8099 default_server;
root /dev/null;
server_name $hostname;
# server params
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
# proxy params
proxy_http_version 1.1;
proxy_ignore_client_abort off;
proxy_read_timeout 86400s;
proxy_redirect off;
proxy_send_timeout 86400s;
proxy_max_temp_file_size 0;
proxy_set_header Accept-Encoding "";
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Uri $http_x_ingress_path;
proxy_set_header X-SSL true;
location / {
allow 172.30.32.2;
deny all;
proxy_pass http://127.0.0.1:80;
}
}

View File

@@ -0,0 +1,44 @@
server {
listen 80 default_server;
root /app;
index index.php;
# Make site accessible from http://localhost/
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /api {
rewrite ^/api/?$ /index.php?page=newznabapi last;
}
error_page 404 /404.html;
# pass the PHP scripts to FastCGI server listening on socket
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_buffers 32 4k;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
expires 5d;
}
# deny access to . files, for security
#
location ~ /\. {
log_not_found off;
deny all;
}
}

View File

@@ -0,0 +1,6 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Runs the hourly task to update spots
# ==============================================================================
s6-setuidgid nginx php8 /app/retrieve.php

View File

@@ -0,0 +1,12 @@
[opcache]
opcache.enable=1
opcache.enable_cli=1
; 0 means it will check on every request
; 0 is irrelevant if opcache.validate_timestamps=0 which is desirable in production
opcache.revalidate_freq=0
opcache.validate_timestamps=1
opcache.max_accelerated_files=10000
opcache.memory_consumption=192
opcache.max_wasted_percentage=10
opcache.interned_strings_buffer=16
opcache.fast_shutdown=1

View File

@@ -0,0 +1,6 @@
; Make sure _ENV is populated to use it in spotweb database settings
variables_order = "EGPCS"
date.timezone = Europe/Amsterdam
memory_limit = 1G

View File

@@ -0,0 +1,18 @@
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 1024
;pm.status_path = /status
; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/1
clear_env = no

View File

@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv sh
/usr/sbin/crond -f -S -l 0

View File

@@ -0,0 +1,9 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Home Assistant Community Add-on: spotweb
# Take down the S6 supervision tree when Nginx fails
# ==============================================================================
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }
s6-svscanctl -t /var/run/s6/services

View File

@@ -0,0 +1,12 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: spotweb
# Runs the Nginx daemon
# ==============================================================================
# Wait for PHP-FPM to become available
bashio::net.wait_for 9000
bashio::log.info "Starting NGinx..."
nginx -c /etc/nginx/nginx.conf

View File

@@ -0,0 +1,9 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Home Assistant Community Add-on: Bookstack
# Take down the S6 supervision tree when PHP FPM fails
# ==============================================================================
if -n { s6-test $# -ne 0 }
if -n { s6-test ${1} -eq 256 }
s6-svscanctl -t /var/run/s6/services

View File

@@ -0,0 +1,6 @@
#!/usr/bin/with-contenv bashio
bashio::log.info "Starting PHP-FPM..."
#/usr/sbin/php-fpm8 -F
exec php-fpm8 --nodaemonize