diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..0870063 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,26 @@ +version: "2" +checks: + argument-count: + config: + threshold: 5 + complex-logic: + config: + threshold: 4 + file-lines: + config: + threshold: 350 + method-complexity: + config: + threshold: 5 + method-count: + config: + threshold: 20 + method-lines: + config: + threshold: 60 + nested-control-flow: + config: + threshold: 4 + return-statements: + config: + threshold: 4 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 35aea6a..2c95f53 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,7 @@ stages: - prepare - build - test + - packaging - deploy cache: @@ -11,7 +12,6 @@ cache: - node_modules/ include: - - template: SAST.gitlab-ci.yml - template: Code-Quality.gitlab-ci.yml variables: @@ -52,6 +52,24 @@ coverage: - ./coverage/cobertura-coverage.xml needs: ["prepare"] +package_debian: + stage: packaging + image: debian + script: + - cd deb + - mkdir -p "./OpenMediaCenter/var/www/openmediacenter/videos/" + - mkdir -p "./OpenMediaCenter/tmp/" + - cp -r ../build/* ./OpenMediaCenter/var/www/openmediacenter/ + - cp -r ../api ./OpenMediaCenter/var/www/openmediacenter/ + - cp ../database.sql ./OpenMediaCenter/tmp/openmediacenter.sql + - chmod -R 0775 * + - dpkg-deb --build OpenMediaCenter + - mv OpenMediaCenter.deb OpenMediaCenter-0.1_amd64.deb + artifacts: + paths: + - deb/OpenMediaCenter-0.1_amd64.deb + needs: ["build"] + deploy_test1: stage: deploy image: luki42/alpineopenssh:latest diff --git a/api/src/Database.php b/api/src/Database.php index bbea467..a159bda 100644 --- a/api/src/Database.php +++ b/api/src/Database.php @@ -6,13 +6,13 @@ * Class with all neccessary stuff for the Database connections. */ class Database { - private static ?Database $instance = null; - private mysqli $conn; + private static $instance = null; + private $conn; - private string $servername = "192.168.0.30"; - private string $username = "root"; - private string $password = "1qayxsw2"; - private string $dbname = "mediacenter"; + private $servername = "127.0.0.1"; + private $username = "mediacenteruser"; + private $password = "mediapassword"; + private $dbname = "mediacenter"; // The db connection is established in the private constructor. private function __construct() { diff --git a/api/src/SSettings.php b/api/src/SSettings.php index 97b3c41..a527811 100644 --- a/api/src/SSettings.php +++ b/api/src/SSettings.php @@ -5,7 +5,7 @@ * class handling all Settings used by php scripts */ class SSettings { - private ?Database $database; + private $database; /** * SSettings constructor. diff --git a/api/src/handlers/RequestBase.php b/api/src/handlers/RequestBase.php index 25f3d6d..0b07358 100644 --- a/api/src/handlers/RequestBase.php +++ b/api/src/handlers/RequestBase.php @@ -2,8 +2,8 @@ require_once 'src/Database.php'; abstract class RequestBase { - protected mysqli $conn; - private array $actions = array(); + protected $conn; + private $actions = array(); /** * adds a new action handler to the current api file diff --git a/api/src/handlers/Video.php b/api/src/handlers/Video.php index aef836f..abc21d8 100755 --- a/api/src/handlers/Video.php +++ b/api/src/handlers/Video.php @@ -7,7 +7,7 @@ require_once 'RequestBase.php'; * backend for all interactions with videoloads and receiving of video infos */ class Video extends RequestBase { - private string $videopath; + private $videopath; public function __construct() { $settings = new SSettings(); diff --git a/database.sql b/database.sql index b48cb20..e633d44 100644 --- a/database.sql +++ b/database.sql @@ -30,16 +30,14 @@ create table if not exists video_tags on delete cascade ); -create table settings +create table if not exists settings ( - id enum(1) NOT NULL default 0, video_path varchar(255) null, episode_path varchar(255) null, password varchar(32) default '-1' null, mediacenter_name varchar(32) default 'OpenMediaCenter' null, TMDB_grabbing tinyint null, DarkMode tinyint default 0 null - PRIMARY KEY (id) ); INSERT INTO tags (tag_id, tag_name) diff --git a/deb/OpenMediaCenter/DEBIAN/control b/deb/OpenMediaCenter/DEBIAN/control new file mode 100755 index 0000000..dd2c53f --- /dev/null +++ b/deb/OpenMediaCenter/DEBIAN/control @@ -0,0 +1,10 @@ +Package: OpenMediaCenter +Version: 0.1 +Depends: nginx, php-fpm, php-mysqli, mariadb-server +Section: web +Priority: optional +Architecture: all +Essential: no +Installed-Size: 1024 +Maintainer: heili.eu +Description: OpenMediaCenter diff --git a/deb/OpenMediaCenter/DEBIAN/postinst b/deb/OpenMediaCenter/DEBIAN/postinst new file mode 100755 index 0000000..efd22fc --- /dev/null +++ b/deb/OpenMediaCenter/DEBIAN/postinst @@ -0,0 +1,21 @@ +#!/bin/bash +# enable nginx site +ln -s /etc/nginx/sites-available/OpenMediaCenter.conf /etc/nginx/sites-enabled/OpenMediaCenter.conf + +# link general socket to current one +ln -s /var/run/php/php*-fpm.sock /var/run/php-fpm.sock + +# setup database +mysql -uroot -pPASS -e "CREATE DATABASE IF NOT EXISTS mediacenter;" +mysql -uroot -pPASS -e "CREATE USER IF NOT EXISTS 'mediacenteruser'@'localhost' IDENTIFIED BY 'mediapassword';" +mysql -uroot -pPASS -e "GRANT ALL PRIVILEGES ON mediacenter . * TO 'mediacenteruser'@'localhost';" +mysql -u mediacenteruser -pmediapassword mediacenter < /tmp/openmediacenter.sql + +# removed unused sql style file +rm /tmp/openmediacenter.sql + +# correct user rights +chown -R www-data:www-data /var/www/openmediacenter + +# restart services +systemctl restart nginx diff --git a/deb/OpenMediaCenter/DEBIAN/preinst b/deb/OpenMediaCenter/DEBIAN/preinst new file mode 100644 index 0000000..2518099 --- /dev/null +++ b/deb/OpenMediaCenter/DEBIAN/preinst @@ -0,0 +1,4 @@ +#!/bin/bash +#preset db password +debconf-set-selections <<< 'mariadb-server-10.0 mysql-server/root_password password PASS' +debconf-set-selections <<< 'mariadb-server-10.0 mysql-server/root_password_again password PASS' diff --git a/deb/OpenMediaCenter/etc/nginx/sites-available/OpenMediaCenter.conf b/deb/OpenMediaCenter/etc/nginx/sites-available/OpenMediaCenter.conf new file mode 100755 index 0000000..38b2a38 --- /dev/null +++ b/deb/OpenMediaCenter/etc/nginx/sites-available/OpenMediaCenter.conf @@ -0,0 +1,21 @@ +server { + listen 8080 default_server; + listen [::]:8080 default_server; + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + + fastcgi_pass unix:/var/run/php-fpm.sock; + } + + root /var/www/openmediacenter; + + index index.html; + + access_log /var/log/nginx/openmediacenter.access.log; + error_log /var/log/nginx/openmediacenter.error.log; + + location / { + try_files $uri $uri/ =404; + } +}