first commit

This commit is contained in:
Johan Koke 2022-02-20 18:03:58 +00:00
commit 46c411b764
10 changed files with 379 additions and 0 deletions

11
.env.sample Normal file
View File

@ -0,0 +1,11 @@
mariadb_version=10.5
appname=youPHPtube
site_title=My tubes
fqdn=tube.domain.com
http_scheme=https
encoder_fqdn=encoder.domain.com
sql_user=avideo
sql_root_pass=changeme
sql_pass=passwordtobechanged
admin_email=my@email.com
admin_pass=changeme

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.env
*.env
db/app
db/enc
videos/
encoder/videos

49
app/Dockerfile Normal file
View File

@ -0,0 +1,49 @@
FROM php:7-apache
ENV DOMAIN localhost
ENV DOMAIN_PROTOCOL http
ENV SITE_TITLE AVideo
ENV ADMIN_PASSWORD password
ENV ADMIN_EMAIL webmaster@your.domain
ENV DB_HOST localhost
ENV DB_USER avideo
ENV DB_PASSWORD password
ENV DB_NAME avideo
ENV LANG en
ENV ENCODER https://encoder1.avideo.com/
ENV NFS_SERVER 192.168.1.45
ENV NFS_SHARE /mnt/biffa/youPHPtube
ENV PHP_MEMORY_LIMIT 2048M
ADD install.php /root/
ADD entrypoint.sh /usr/local/bin/
WORKDIR /var/www/html
RUN ln -snf /usr/share/zoneinfo/GMT /etc/localtime && echo 'Europe/London' > /etc/timezone \
&& apt-get update \
&& apt-get install apt-transport-https lsb-release logrotate git curl nano net-tools iputils-ping libzip-dev libpng-dev libjpeg-dev libfreetype6-dev libbz2-dev libxml2-dev libonig-dev libcurl4-openssl-dev ffmpeg -y --no-install-recommends \
&& docker-php-ext-configure gd --with-freetype=/usr/include --with-jpeg=/usr/include \
&& docker-php-ext-install -j$(nproc) bcmath xml mbstring curl mysqli gd zip \
&& rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* /root/.cache \
&& a2enmod rewrite \
&& echo "post_max_size = 10G\nupload_max_filesize = 10G" > $PHP_INI_DIR/conf.d/upload.ini \
&& echo "memory_limit = $PHP_MEMORY_LIMIT" > $PHP_INI_DIR/conf.d/memory.ini \
&& echo "max_execution_time = 72000" > $PHP_INI_DIR/conf.d/execution_time.ini \
&& service apache2 restart \
&& curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl \
&& chmod a+rx /usr/local/bin/youtube-dl \
&& git clone https://github.com/WWBN/AVideo.git \
&& mv AVideo/* . \
&& mv AVideo/.[!.]* . \
&& rm -rf AVideo \
&& chmod a+rx /usr/local/bin/entrypoint.sh \
&& mkdir videos \
# && apt-get install nfs-common \
# && echo "$NFS_SERVER:$NFS_SHARE /var/www/html/videos nfs rw,default 0 0" > /etc/fstab \
# && mount -t nfs $NFS_SERVER:$NFS_SHARE $WORKDIR/videos \
&& chmod 755 videos \
&& chown -R www-data:www-data /var/www/html
#COPY tw.php /var/www/html/locale/tw.php
VOLUME ["/var/www/html/videos"]
CMD ["entrypoint.sh"]

4
app/entrypoint.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
php /root/install.php
chown -R www-data:www-data /var/www/html
apache2-foreground

85
app/install.php Normal file
View File

@ -0,0 +1,85 @@
#!/usr/bin/php -q
<?php
$installationVersion = '11.5';
$p = getenv('DOMAIN_PROTOCOL') ?: 'http';
$d = getenv('DOMAIN') ?: 'localhost';
$s = getenv('SALT') ?: uniqid();
$dbh = getenv('DB_HOST') ?: 'mysql';
$dbu = getenv('DB_USER') ?: 'root';
$dbp = getenv('DB_PASSWORD') ?: 'dbpasswd';
$dbn = getenv('DB_NAME') ?: 'avideo';
$am = getenv('ADMIN_EMAIL');
$ap = getenv('ADMIN_PASSWORD');
$t = getenv('SITE_TITLE') ?: 'AVideo';
$l = getenv('LANG') ?: 'en';
$en = getenv('ENCODER') ?: 'https://encoder1.avideo.com/';
function encryptPassword($password)
{
return md5(hash('whirlpool', sha1($password.$s)));
}
$conn = @new mysqli($dbh, $dbu, $dbp, $dbn);
if ($conn->connect_error) {
$conn = new mysqli($dbh, $dbu, $dbp);
$sql = "CREATE DATABASE IF NOT EXISTS $dbn CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;";
$conn->query($sql);
$conn->select_db($dbn);
$lines = file('/var/www/html/install/database.sql');
$templine = '';
foreach ($lines as $line) {
if (substr($line, 0, 2) == '--' || $line == '') {
continue;
}
$templine .= $line;
if (substr(trim($line), -1, 1) == ';') {
$conn->query($templine);
$templine = '';
}
}
$conn->query('DELETE FROM users WHERE id = 1');
$sql = "INSERT INTO users (id, user, email, password, created, modified, isAdmin) VALUES (1, 'admin', '$am', '".md5($ap)."', now(), now(), true)";
$conn->query($sql);
$conn->query('DELETE FROM categories WHERE id = 1');
$sql = "INSERT INTO categories (id, name, clean_name, description, created, modified) VALUES (1, 'Default', 'default','', now(), now())";
$conn->query($sql);
$conn->query('DELETE FROM configurations WHERE id = 1');
$sql = "INSERT INTO configurations (id, video_resolution, users_id, version, webSiteTitle, language, contactEmail, encoderURL, created, modified) VALUES (1, '858:480', 1,'$installationVersion', '$t', '$l', '$am', '$en', now(), now())";
$conn->query($sql);
$sql = "INSERT INTO `plugins` VALUES (NULL, 'a06505bf-3570-4b1f-977a-fd0e5cab205d', 'active', now(), now(), '', 'Gallery', 'Gallery', '1.0');";
$conn->query($sql);
}
$conn->close();
$file = '/var/www/html/videos/configuration.php';
if (!file_exists($file)) {
$content = "<?php
\$global['configurationVersion'] = 3.1;
\$global['disableAdvancedConfigurations'] = 0;
\$global['videoStorageLimitMinutes'] = 0;
\$global['disableTimeFix'] = 0;
\$global['logfile'] = '/var/www/html/videos/avideo.log';
\$global['webSiteRootURL'] = '$p://$d/';
\$global['systemRootPath'] = '/var/www/html/';
\$global['salt'] = '$s';
\$global['disableTimeFix'] = 0;
\$global['enableDDOSprotection'] = 1;
\$global['ddosMaxConnections'] = 40;
\$global['ddosSecondTimeout'] = 5;
\$global['strictDDOSprotection'] = 0;
\$global['noDebug'] = 0;
\$global['webSiteRootPath'] = '$d';
\$mysqlHost = '$dbh';
\$mysqlPort = '3306';
\$mysqlUser = '$dbu';
\$mysqlPass = '$dbp';
\$mysqlDatabase = '$dbn';
/**
* Do NOT change from here
*/
require_once \$global['systemRootPath'].'objects/include_config.php';
";
$fp = fopen($file, 'wb');
fwrite($fp, $content);
fclose($fp);
}

103
docker-compose.yaml Normal file
View File

@ -0,0 +1,103 @@
version: '3'
services:
app:
build: ./app/.
container_name: ${appname}-app
restart: "unless-stopped"
# ports:
# - "80:80"
environment:
DB_HOST: db-app
# DB_MYSQL_PORT: 3306
DB_NAME: "youPHPtube"
DB_USER: "${sql_user}"
DB_PASSWORD: "${sql_pass}"
DOMAIN: "${fqdn}"
DOMAIN_PROTOCOL: "https"
ADMIN_EMAIL: "$admin_email}"
ADMIN_PASSWORD: "${admin_pass}"
SITE_TITLE: "${site_title}"
MAIN_LANGUAGE: "en_US"
ENCODER: "${encoder_fqdn}"
NFS_SERVER: "192.168.1.45"
NFS_SHARE: "/mnt/biffa/youPHPtube"
PHP_MEMORY_LIMIT: "2048M"
volumes:
- ./videos:/var/www/html/videos
env_file:
- ./production.env
depends_on:
- db-app
networks:
- proxy
encoder:
build: ./encoder/.
# image: jandieman/youPHPTubeEncoder
container_name: ${appname}-enc
environment:
DOMAIN: ${fqdn}
DOMAIN_PROTOCOL: ${http_scheme}
ADMIN_PASSWORD: ${admin_pass}
DB_HOST: db-enc
DB_USER: ${sql_user}
DB_PASSWORD: ${sql_pass}
PHP_MEMORY_LIMIT: 2048M
volumes:
- ./encoder/videos:/var/www/html/videos
# ports:
# - "8000:80"
restart: always
env_file:
- ./production.env
depends_on:
- db-enc
networks:
- proxy
db-app:
container_name: ${appname}-db-app
image: mariadb:${mariadb_version}
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- ./db/app:/var/lib/mysql:rw
environment:
MYSQL_ROOT_PASSWORD: "${sql_root_pass}"
MYSQL_PASSWORD: "${sql_pass}"
MYSQL_DATABASE: "youPHPtube"
MYSQL_USER: "${sql_user}"
# ports:
# - 3306:3306
env_file:
- ./production.env
networks:
- proxy
restart: always
db-enc:
container_name: ${appname}-db-enc
image: mariadb:${mariadb_version}
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- ./db/enc:/var/lib/mysql:rw
environment:
MYSQL_ROOT_PASSWORD: "${sql_root_pass}"
MYSQL_PASSWORD: "${sql_pass}"
MYSQL_DATABASE: "youPHPTubeEncoder"
MYSQL_USER: "${sql_user}"
# ports:
# - 3307:3306
env_file:
- ./production.env
networks:
- proxy
restart: always
networks:
proxy:
external: true

36
encoder/Dockerfile Normal file
View File

@ -0,0 +1,36 @@
FROM php:7-apache
ENV DOMAIN localhost
ENV DOMAIN_PROTOCOL http
ENV ADMIN_PASSWORD password
ENV DB_HOST mysql
ENV DB_USER avideo
ENV DB_PASSWORD password
ENV PHP_MEMORY_LIMIT 2048M
ADD install.php /root/
ADD entrypoint.sh /usr/local/bin/
WORKDIR /var/www/html
RUN apt-get update \
&& apt-get install -y wget git zip default-libmysqlclient-dev libbz2-dev libmemcached-dev libsasl2-dev libfreetype6-dev libicu-dev libjpeg-dev libmemcachedutil2 libpng-dev libxml2-dev mariadb-client ffmpeg libimage-exiftool-perl python3 curl python3-pip libzip-dev libonig-dev \
&& docker-php-ext-configure gd --with-freetype=/usr/include --with-jpeg=/usr/include \
&& docker-php-ext-install -j$(nproc) bcmath bz2 calendar exif gd gettext iconv intl mbstring mysqli opcache pdo_mysql zip \
&& rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* /root/.cache \
&& a2enmod rewrite \
&& service apache2 restart \
&& curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl \
&& chmod a+rx /usr/local/bin/youtube-dl \
&& pip3 install -U youtube-dl \
&& echo "post_max_size = 10G\nupload_max_filesize = 10G" > $PHP_INI_DIR/conf.d/upload.ini \
&& echo "memory_limit = $PHP_MEMORY_LIMIT" > $PHP_INI_DIR/conf.d/memory.ini \
&& echo "max_execution_time = 72000" > $PHP_INI_DIR/conf.d/execution_time.ini \
&& git clone https://github.com/WWBN/AVideo-Encoder.git \
&& mv AVideo-Encoder/* . \
&& mv AVideo-Encoder/.[!.]* . \
&& rm -rf AVideo-Encoder \
&& chmod a+rx /usr/local/bin/entrypoint.sh \
&& chown -R www-data:www-data /var/www/html
VOLUME ["/var/www/html/videos"]
CMD ["entrypoint.sh"]

4
encoder/entrypoint.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
php /root/install.php
chown -R www-data:www-data /var/www/html
apache2-foreground

65
encoder/install.php Normal file
View File

@ -0,0 +1,65 @@
#!/usr/bin/php -q
<?php
$installationVersion = '3.3';
$p = getenv('DOMAIN_PROTOCOL') ?: 'http';
$d = getenv('DOMAIN') ?: 'localhost';
$dbh = getenv('DB_HOST') ?: 'db-enc';
$dbu = getenv('DB_USER') ?: 'avideo';
$dbp = getenv('DB_PASSWORD');
$ap = getenv('ADMIN_PASSWORD');
$t = getenv('SITE_TITLE') ?: 'YouPHPtube';
$l = getenv('LANG') ?: 'en';
$en = getenv('ENCODER') ?: 'https://encoder1.avideo.com/';
$conn = @new mysqli($dbh, $dbu, $dbp, 'youPHPTubeEncoder');
if ($conn->connect_error) {
$conn = new mysqli($dbh, $dbu, $dbp);
$sql = 'CREATE DATABASE IF NOT EXISTS youPHPTubeEncoder CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;';
$conn->query($sql);
$conn->select_db('youPHPTubeEncoder');
$lines = file('/var/www/html/install/database.sql');
$templine = '';
foreach ($lines as $line) {
if (substr($line, 0, 2) == '--' || $line == '') {
continue;
}
$templine .= $line;
if (substr(trim($line), -1, 1) == ';') {
$conn->query($templine);
$templine = '';
}
}
$sql = "INSERT INTO streamers (siteURL, user, pass, priority, created, modified, isAdmin) VALUES ('$p://$d/', 'admin', '$ap', 1, now(), now(), 1)";
$conn->query($sql);
$sql = "INSERT INTO configurations (id, allowedStreamersURL, defaultPriority, version, created, modified) VALUES (1, '$p://$d/', '1', '$installationVersion', now(), now())";
$conn->query($sql);
}
$conn->close();
$file = '/var/www/html/videos/configuration.php';
if (!file_exists($file)) {
$content = "<?php
\$global['configurationVersion'] = 2;
\$global['webSiteRootURL'] = '$p://$d/';
\$global['systemRootPath'] = '/var/www/html/';
\$global['webSiteRootPath'] = '$d';
\$global['disableConfigurations'] = false;
\$global['disableBulkEncode'] = false;
\$global['disableImportVideo'] = false;
\$global['disableWebM'] = false;
\$mysqlHost = '$dbh';
\$mysqlPort = '3306';
\$mysqlUser = '$dbu';
\$mysqlPass = '$dbp';
\$mysqlDatabase = 'youPHPTubeEncoder';
\$global['allowed'] = array('mp4', 'avi', 'mov', 'flv', 'mp3', 'wav', 'm4v', 'webm', 'wmv', 'mpg', 'mpeg', 'f4v', 'm4v', 'm4a', 'm2p', 'rm', 'vob', 'mkv', '3gp');
/**
* Do NOT change from here
*/
require_once \$global['systemRootPath'].'objects/include_config.php';
";
$fp = fopen($file, 'wb');
fwrite($fp, $content);
fclose($fp);
}

16
nfs.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
server="192.168.1.45"
share="/mnt/evo/youPHPtube"
if [ $server = /dev/null ]; then
read -p "Enter your NFS server IP address: " server
fi
sudo showmount -e $server
if [ $share = /dev/null ]; then
read -p "Enter share from above: " share
fi
echo sudo mount -t nfs $server:$share videos/