From bb4e16f4d37ee9cd7981428074e73b8130f9497b Mon Sep 17 00:00:00 2001 From: cbrherms Date: Tue, 30 May 2017 00:09:50 +0100 Subject: [PATCH 01/30] Fix user and database init --- docker-entrypoint.sh | 8 ++++++-- sql/framework.sql | 4 ---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4a1f6a77..95c63c72 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -15,7 +15,7 @@ check_port() { } _mysql() { - mysql -u "${MYSQL_ROOT_USER}" -p"${MYSQL_ROOT_PASSWORD}" -h "${MYSQL_HOST}" $@ + mysql -u "${MYSQL_ROOT_USER}" -p"${MYSQL_ROOT_PASSWORD}" -h "${MYSQL_HOST}" "$@" } echo -n "Waiting for MYSQL server..." @@ -25,12 +25,16 @@ do done echo 'Done!' -tables_check="select count(*) from information_schema.tables where table_schema='API' and table_name='${MYSQL_DATABASE}';" +tables_check="select count(*) from information_schema.tables where table_schema='${MYSQL_DATABASE}' and table_name='API';" tables_num=$(mysql -N -s -u "${MYSQL_ROOT_USER}" -p"${MYSQL_ROOT_PASSWORD}" -h "${MYSQL_HOST}" -e "${tables_check}") if [[ "${tables_num}" -eq "0" ]] then # install stuff if not installed + _mysql -e "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" + _mysql -e "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" + _mysql -e "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'%';" + _mysql -e "FLUSH PRIVILEGES;" _mysql --database "$MYSQL_DATABASE" < "${SHIN_BIN_DIR}/sql/framework.sql" _mysql --database "$MYSQL_DATABASE" < "${SHIN_BIN_DIR}/sql/default_data.sql" sed -i 's/"user": "majesticflame"/"user": "'"${MYSQL_USER}"'"/g' "$SHIN_BIN_DIR/conf.json" diff --git a/sql/framework.sql b/sql/framework.sql index 59cf8e6f..ab7d9f93 100644 --- a/sql/framework.sql +++ b/sql/framework.sql @@ -10,10 +10,6 @@ /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; --- Dumping database structure for ccio -CREATE DATABASE IF NOT EXISTS `ccio` /*!40100 DEFAULT CHARACTER SET utf8 */; -USE `ccio`; - -- Dumping structure for table ccio.API CREATE TABLE IF NOT EXISTS `API` ( From ed19f9c0fba5a870aab4280b73de4380a5ef766d Mon Sep 17 00:00:00 2001 From: cbrherms Date: Wed, 31 May 2017 01:54:23 +0100 Subject: [PATCH 02/30] docker-entrypoint.sh EOL fix Fixes issue on windows with docker-compose reading docker-entrypoint.sh incorrectly due to CRLF line endings --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..2984f43f --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +docker-entrypoint.sh text eol=lf \ No newline at end of file From aeb7d917910c8cee87c5e07397f47f39443939be Mon Sep 17 00:00:00 2001 From: cbrherms Date: Wed, 31 May 2017 02:01:07 +0100 Subject: [PATCH 03/30] Split framework.sql - Split framework.sql into database.sql and tables.sql - Modified installers for new sql files - Modified docker-entryfile.sh for new tables.sql --- .gitattributes | 2 +- INSTALL/centos.sh | 3 ++- INSTALL/ubuntu.sh | 3 ++- docker-entrypoint.sh | 4 ++-- sql/database.sql | 20 ++++++++++++++++++++ sql/{framework.sql => tables.sql} | 0 6 files changed, 27 insertions(+), 5 deletions(-) mode change 100755 => 100644 docker-entrypoint.sh create mode 100644 sql/database.sql rename sql/{framework.sql => tables.sql} (100%) diff --git a/.gitattributes b/.gitattributes index 2984f43f..90e49117 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -docker-entrypoint.sh text eol=lf \ No newline at end of file +docker-entrypoint.sh text eol=lf diff --git a/INSTALL/centos.sh b/INSTALL/centos.sh index acb87438..01f37c59 100644 --- a/INSTALL/centos.sh +++ b/INSTALL/centos.sh @@ -24,7 +24,8 @@ echo "What is your SQL Password?" echo "**You set this just a few moments ago if MySQL was installed during this installer." read sqlpass mysql -u root -p$sqlpass -e "source sql/user.sql" || true -mysql -u root -p$sqlpass -e "source sql/framework.sql" || true +mysql -u root -p$sqlpass -e "source sql/database.sql" || true +mysql -u root -p$sqlpass --database ccio -e "source sql/tables.sql" || true mysql -u root -p$sqlpass --database ccio -e "source sql/default_data.sql" || true echo "Shinobi - Install NPM Libraries" npm install diff --git a/INSTALL/ubuntu.sh b/INSTALL/ubuntu.sh index 80eac24b..e85fde1c 100644 --- a/INSTALL/ubuntu.sh +++ b/INSTALL/ubuntu.sh @@ -25,7 +25,8 @@ chmod -R 755 . echo "=============" echo "Shinobi - Database Installation" mysql -u root -p$sqlpass -e "source sql/user.sql" || true -mysql -u root -p$sqlpass -e "source sql/framework.sql" || true +mysql -u root -p$sqlpass -e "source sql/database.sql" || true +mysql -u root -p$sqlpass --database ccio -e "source sql/tables.sql" || true mysql -u root -p$sqlpass --database ccio -e "source sql/default_data.sql" || true echo "=============" echo "Shinobi - Install NPM Libraries" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh old mode 100755 new mode 100644 index 95c63c72..00a73a1a --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -35,7 +35,7 @@ then _mysql -e "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" _mysql -e "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'%';" _mysql -e "FLUSH PRIVILEGES;" - _mysql --database "$MYSQL_DATABASE" < "${SHIN_BIN_DIR}/sql/framework.sql" + _mysql --database "$MYSQL_DATABASE" < "${SHIN_BIN_DIR}/sql/tables.sql" _mysql --database "$MYSQL_DATABASE" < "${SHIN_BIN_DIR}/sql/default_data.sql" sed -i 's/"user": "majesticflame"/"user": "'"${MYSQL_USER}"'"/g' "$SHIN_BIN_DIR/conf.json" sed -i 's/"password": ""/"password": "'"${MYSQL_PASSWORD}"'"/g' "$SHIN_BIN_DIR/conf.json" @@ -47,4 +47,4 @@ fi pm2 start "${SHIN_BIN_DIR}/cron.js" pm2 start "${SHIN_BIN_DIR}/camera.js" # pm2 start "${SHIN_BIN_DIR}/plugins/motion/shinobi-motion.js" -pm2 logs +pm2 logs \ No newline at end of file diff --git a/sql/database.sql b/sql/database.sql new file mode 100644 index 00000000..23a15b08 --- /dev/null +++ b/sql/database.sql @@ -0,0 +1,20 @@ +-- -------------------------------------------------------- +-- Host: 192.168.88.58 +-- Server version: 5.7.17-0ubuntu0.16.04.1 - (Ubuntu) +-- Server OS: Linux +-- HeidiSQL Version: 9.3.0.4984 +-- -------------------------------------------------------- + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET NAMES utf8mb4 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; + +-- Dumping database structure for ccio +CREATE DATABASE IF NOT EXISTS `ccio` /*!40100 DEFAULT CHARACTER SET utf8 */; +USE `ccio`; + +-- Data exporting was unselected. +/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; +/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; \ No newline at end of file diff --git a/sql/framework.sql b/sql/tables.sql similarity index 100% rename from sql/framework.sql rename to sql/tables.sql From 779d7863e69c157425c51d80b5198ef120aa4159 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Fri, 2 Jun 2017 02:05:43 +0100 Subject: [PATCH 04/30] Update nodejs NodeJS updated to v8.0 --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4e04e087..9748ed9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,10 +10,11 @@ ENV MYSQL_HOST="shinobi-db" \ MYSQL_PASSWORD="shinobi" RUN apt update \ - && apt install --no-install-recommends -y ffmpeg nodejs npm libav-tools \ + && apt install -y curl \ + && curl -sL https://deb.nodesource.com/setup_8.x | bash \ + && apt install --no-install-recommends -y ffmpeg nodejs libav-tools \ wget mysql-client \ && rm -rf /var/lib/apt/lists/* \ - && ln -s /usr/bin/nodejs /usr/bin/node \ && cp /opt/shinobi/conf.sample.json /opt/shinobi/conf.json \ && cp /opt/shinobi/super.sample.json /opt/shinobi/super.json \ && npm install \ From b266eb9132d97bdfdf2ac6d94af87c959318ba01 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Fri, 2 Jun 2017 02:18:40 +0100 Subject: [PATCH 05/30] Update docker-compose for persistence - Using local volumes for database persistence, avoids potential permission issues with host folders - changed to mariadb - moved conf.json sed commands outside of the database creation IF statement to allow persistence through container destruction --- docker-compose.yml | 15 ++++++++++++--- docker-entrypoint.sh | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index fd5c47da..a50918e7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: build: context: . depends_on: - - mysql + - database restart: always environment: - MYSQL_HOST=shinobi-db @@ -15,11 +15,20 @@ services: - MYSQL_ROOT_PASSWORD=rootpass ports: - "8080:8080" - mysql: - image: mysql:8 + volumes: + - ./videos:/opt/shinobi/videos + database: container_name: shinobi-db + image: mariadb + restart: always environment: - MYSQL_DATABASE=shinobi - MYSQL_ROOT_PASSWORD=rootpass - MYSQL_USER=shinobi - MYSQL_PASSWORD=shinobi_pass + volumes: + - dbdata:/var/lib/mysql +volumes: +## persistent data volume for mysql data + dbdata: + driver: local diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 00a73a1a..2dd57812 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -37,12 +37,12 @@ then _mysql -e "FLUSH PRIVILEGES;" _mysql --database "$MYSQL_DATABASE" < "${SHIN_BIN_DIR}/sql/tables.sql" _mysql --database "$MYSQL_DATABASE" < "${SHIN_BIN_DIR}/sql/default_data.sql" + npm cache clean -f && npm install -g n && n stable +fi sed -i 's/"user": "majesticflame"/"user": "'"${MYSQL_USER}"'"/g' "$SHIN_BIN_DIR/conf.json" sed -i 's/"password": ""/"password": "'"${MYSQL_PASSWORD}"'"/g' "$SHIN_BIN_DIR/conf.json" sed -i 's/"host": "127.0.0.1"/"host": "'"${MYSQL_HOST}"'"/g' "$SHIN_BIN_DIR/conf.json" sed -i 's/"database": "ccio"/"database": "'"${MYSQL_DATABASE}"'"/g' "$SHIN_BIN_DIR/conf.json" - npm cache clean -f && npm install -g n && n stable -fi pm2 start "${SHIN_BIN_DIR}/cron.js" pm2 start "${SHIN_BIN_DIR}/camera.js" From bdc2c15bde7b7a6bafccb736b7e45a6fc8326344 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sat, 3 Jun 2017 00:35:48 +0100 Subject: [PATCH 06/30] Rebase using jrottenberg/ffmpeg Basing off ubuntu 16.04 with ffmpeg 3.x precomiled within. --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9748ed9d..97b386e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:xenial +FROM jrottenberg/ffmpeg:ubuntu COPY . /opt/shinobi WORKDIR /opt/shinobi @@ -12,7 +12,7 @@ ENV MYSQL_HOST="shinobi-db" \ RUN apt update \ && apt install -y curl \ && curl -sL https://deb.nodesource.com/setup_8.x | bash \ - && apt install --no-install-recommends -y ffmpeg nodejs libav-tools \ + && apt install --no-install-recommends -y nodejs libav-tools \ wget mysql-client \ && rm -rf /var/lib/apt/lists/* \ && cp /opt/shinobi/conf.sample.json /opt/shinobi/conf.json \ @@ -20,7 +20,7 @@ RUN apt update \ && npm install \ && npm install pm2 -g \ && chmod +x ./docker-entrypoint.sh - # && cp /opt/shinobi/plugins/motion/conf.sample.json /opt/shinobi/plugins/motion/conf.json +# && cp /opt/shinobi/plugins/motion/conf.sample.json /opt/shinobi/plugins/motion/conf.json VOLUME ["/opt/shinobi/videos"] EXPOSE 8080 From f73a31b0bfba2de391d6442df7118bb81667ae51 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sat, 3 Jun 2017 02:47:04 +0100 Subject: [PATCH 07/30] Add motion dependancies and enable on run --- Dockerfile | 8 +++++--- docker-entrypoint.sh | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 97b386e9..6b64acde 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,14 +13,16 @@ RUN apt update \ && apt install -y curl \ && curl -sL https://deb.nodesource.com/setup_8.x | bash \ && apt install --no-install-recommends -y nodejs libav-tools \ - wget mysql-client \ + wget mysql-client libcairo2-dev libjpeg-dev libpango1.0-dev \ + libgif-dev build-essential g++ \ && rm -rf /var/lib/apt/lists/* \ && cp /opt/shinobi/conf.sample.json /opt/shinobi/conf.json \ && cp /opt/shinobi/super.sample.json /opt/shinobi/super.json \ && npm install \ && npm install pm2 -g \ - && chmod +x ./docker-entrypoint.sh -# && cp /opt/shinobi/plugins/motion/conf.sample.json /opt/shinobi/plugins/motion/conf.json + && npm install canvas \ + && chmod +x ./docker-entrypoint.sh \ + && cp /opt/shinobi/plugins/motion/conf.sample.json /opt/shinobi/plugins/motion/conf.json VOLUME ["/opt/shinobi/videos"] EXPOSE 8080 diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2dd57812..d8843b5c 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -46,5 +46,5 @@ fi pm2 start "${SHIN_BIN_DIR}/cron.js" pm2 start "${SHIN_BIN_DIR}/camera.js" -# pm2 start "${SHIN_BIN_DIR}/plugins/motion/shinobi-motion.js" +pm2 start "${SHIN_BIN_DIR}/plugins/motion/shinobi-motion.js" pm2 logs \ No newline at end of file From a9044d8524ec47ff994b18143792e1112e45ca5d Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sat, 3 Jun 2017 04:11:34 +0100 Subject: [PATCH 08/30] Add Timezone variable Takes usual TZ format --- Dockerfile | 3 ++- docker-compose.yml | 2 ++ docker-entrypoint.sh | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6b64acde..a60669c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ ENV MYSQL_HOST="shinobi-db" \ MYSQL_ROOT_USER="root" \ MYSQL_ROOT_PASSWORD="rootpass" \ MYSQL_USER="ccio" \ - MYSQL_PASSWORD="shinobi" + MYSQL_PASSWORD="shinobi" \ + TIMEZONE="UTC" RUN apt update \ && apt install -y curl \ diff --git a/docker-compose.yml b/docker-compose.yml index a50918e7..2522474a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,8 @@ services: - MYSQL_USER=shinobi - MYSQL_PASSWORD=shinobi_pass - MYSQL_ROOT_PASSWORD=rootpass +## Timezone - eg Europe/London + - TIMEZONE=UTC ports: - "8080:8080" volumes: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index d8843b5c..c99a593d 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -7,6 +7,7 @@ MYSQL_ROOT_USER="${MYSQL_ROOT_USER:-root}" MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-rootpass}" MYSQL_USER="${MYSQL_USER:-ccio}" MYSQL_PASSWORD="${MYSQL_PASSWORD:-shinobi}" +TIMEZONE="${TIMEZONE:-UTC}" cd "$SHIN_BIN_DIR" || exit 9 @@ -18,6 +19,10 @@ _mysql() { mysql -u "${MYSQL_ROOT_USER}" -p"${MYSQL_ROOT_PASSWORD}" -h "${MYSQL_HOST}" "$@" } +echo "${TIMEZONE}" > /etc/timezone +rm /etc/localtime +dpkg-reconfigure -f noninteractive tzdata + echo -n "Waiting for MYSQL server..." while ! check_port "$MYSQL_HOST" 3306 do From bd3b8cc3398301078742ed34afbfa4bc2a58864e Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sat, 3 Jun 2017 18:41:15 +0100 Subject: [PATCH 09/30] Standardize docker-compose ENV vars --- docker-compose.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a50918e7..ba319a0e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,8 +10,8 @@ services: environment: - MYSQL_HOST=shinobi-db - MYSQL_DATABASE=shinobi - - MYSQL_USER=shinobi - - MYSQL_PASSWORD=shinobi_pass + - MYSQL_USER=ccio + - MYSQL_PASSWORD=shinobi - MYSQL_ROOT_PASSWORD=rootpass ports: - "8080:8080" @@ -22,10 +22,7 @@ services: image: mariadb restart: always environment: - - MYSQL_DATABASE=shinobi - MYSQL_ROOT_PASSWORD=rootpass - - MYSQL_USER=shinobi - - MYSQL_PASSWORD=shinobi_pass volumes: - dbdata:/var/lib/mysql volumes: From db90a02e3f911b30cd403ccb59b505f9d0bb9659 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sat, 3 Jun 2017 18:42:58 +0100 Subject: [PATCH 10/30] Standardize docker-compose ENV vars --- docker-compose.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2522474a..952cd2dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: environment: - MYSQL_HOST=shinobi-db - MYSQL_DATABASE=shinobi - - MYSQL_USER=shinobi + - MYSQL_USER=ccio - MYSQL_PASSWORD=shinobi_pass - MYSQL_ROOT_PASSWORD=rootpass ## Timezone - eg Europe/London @@ -24,10 +24,7 @@ services: image: mariadb restart: always environment: - - MYSQL_DATABASE=shinobi - MYSQL_ROOT_PASSWORD=rootpass - - MYSQL_USER=shinobi - - MYSQL_PASSWORD=shinobi_pass volumes: - dbdata:/var/lib/mysql volumes: From 45acd53bc4288e2bf9f1f89eef87036b59517a12 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Fri, 9 Jun 2017 22:38:56 +0100 Subject: [PATCH 11/30] Re-add mysql server - kitematic friendly Added mysql server for local option (can still use remote server) Added mysql data vol --- .gitignore | 1 + Dockerfile | 12 +++++++++--- docker-entrypoint.sh | 4 +++- sql/tables.sql | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 664dc68e..c14e59ee 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ web.old .DS_Store .vagrant conf.json +super.json \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a60669c4..f1412f2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM jrottenberg/ffmpeg:ubuntu COPY . /opt/shinobi WORKDIR /opt/shinobi -ENV MYSQL_HOST="shinobi-db" \ +ENV MYSQL_HOST="127.0.0.1" \ MYSQL_DATABASE="shinobi" \ MYSQL_ROOT_USER="root" \ MYSQL_ROOT_PASSWORD="rootpass" \ @@ -11,11 +11,15 @@ ENV MYSQL_HOST="shinobi-db" \ TIMEZONE="UTC" RUN apt update \ - && apt install -y curl \ + && echo mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD | debconf-set-selections \ + && echo mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD | debconf-set-selections \ + && apt-get install -y mysql-server mysql-client libmysqlclient-dev \ + && apt install -y curl \ && curl -sL https://deb.nodesource.com/setup_8.x | bash \ && apt install --no-install-recommends -y nodejs libav-tools \ - wget mysql-client libcairo2-dev libjpeg-dev libpango1.0-dev \ + wget libcairo2-dev libjpeg-dev libpango1.0-dev \ libgif-dev build-essential g++ \ + && apt clean \ && rm -rf /var/lib/apt/lists/* \ && cp /opt/shinobi/conf.sample.json /opt/shinobi/conf.json \ && cp /opt/shinobi/super.sample.json /opt/shinobi/super.json \ @@ -26,5 +30,7 @@ RUN apt update \ && cp /opt/shinobi/plugins/motion/conf.sample.json /opt/shinobi/plugins/motion/conf.json VOLUME ["/opt/shinobi/videos"] +VOLUME ["/var/lib/mysql"] EXPOSE 8080 +EXPOSE 3306 ENTRYPOINT ./docker-entrypoint.sh diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index c99a593d..4cb7bf0d 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash SHIN_BIN_DIR=/opt/shinobi -MYSQL_HOST="${MYSQL_HOST:-shinobi-db}" +MYSQL_HOST="${MYSQL_HOST:-127.0.0.1}" MYSQL_DATABASE="${MYSQL_DATABASE:-shinobi}" MYSQL_ROOT_USER="${MYSQL_ROOT_USER:-root}" MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-rootpass}" @@ -11,6 +11,8 @@ TIMEZONE="${TIMEZONE:-UTC}" cd "$SHIN_BIN_DIR" || exit 9 +service mysql start + check_port() { timeout 3 bash -c "/dev/null } diff --git a/sql/tables.sql b/sql/tables.sql index ab7d9f93..d396b6f8 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -61,7 +61,7 @@ CREATE TABLE IF NOT EXISTS `Monitors` ( `path` varchar(100) DEFAULT '/', `port` int(8) DEFAULT '80', `fps` int(8) DEFAULT '1', - `mode` enum('stop','start','record','mrecord') DEFAULT 'stop', + `mode` varchar(15) DEFAULT NULL, `width` int(11) DEFAULT '640', `height` int(11) DEFAULT '360' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 5ee90310fd7e06afaad3e55e1de14c434fba6eda Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sun, 11 Jun 2017 19:14:46 +0100 Subject: [PATCH 12/30] Fix mysql persistence --- Dockerfile | 1 + docker-entrypoint.sh | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f1412f2e..1961ebbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,6 +28,7 @@ RUN apt update \ && npm install canvas \ && chmod +x ./docker-entrypoint.sh \ && cp /opt/shinobi/plugins/motion/conf.sample.json /opt/shinobi/plugins/motion/conf.json +RUN sed -i -e"s/^user\s*=\s*mysql/user = root/" /etc/mysql/mysql.conf.d/mysqld.cnf VOLUME ["/opt/shinobi/videos"] VOLUME ["/var/lib/mysql"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4cb7bf0d..1e87903f 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -11,7 +11,13 @@ TIMEZONE="${TIMEZONE:-UTC}" cd "$SHIN_BIN_DIR" || exit 9 -service mysql start +echo -n "Initialising database if it doesn't exist..." + +if [ ! -f /var/lib/mysql/ibdata1 ]; then + mysqld --initialize +fi + +/usr/bin/mysqld_safe check_port() { timeout 3 bash -c "/dev/null @@ -25,7 +31,7 @@ echo "${TIMEZONE}" > /etc/timezone rm /etc/localtime dpkg-reconfigure -f noninteractive tzdata -echo -n "Waiting for MYSQL server..." +echo -n "Waiting for MYSQL server port..." while ! check_port "$MYSQL_HOST" 3306 do : From f8ecee004ecf43bf687cab7f5536a8049e170ac3 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sun, 11 Jun 2017 20:00:49 +0100 Subject: [PATCH 13/30] Fix missing /var/run/mysqld --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1961ebbc..33a8626f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,9 @@ RUN apt update \ && npm install pm2 -g \ && npm install canvas \ && chmod +x ./docker-entrypoint.sh \ - && cp /opt/shinobi/plugins/motion/conf.sample.json /opt/shinobi/plugins/motion/conf.json + && cp /opt/shinobi/plugins/motion/conf.sample.json /opt/shinobi/plugins/motion/conf.json \ + && mkdir -p /var/run/mysqld \ + && chown root:root /var/run/mysqld RUN sed -i -e"s/^user\s*=\s*mysql/user = root/" /etc/mysql/mysql.conf.d/mysqld.cnf VOLUME ["/opt/shinobi/videos"] From 495606444029e6a55da57ce47f9effafee583764 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sun, 11 Jun 2017 21:16:14 +0100 Subject: [PATCH 14/30] Background the mysqld_safe script --- docker-entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 1e87903f..3bfde118 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -17,7 +17,8 @@ if [ ! -f /var/lib/mysql/ibdata1 ]; then mysqld --initialize fi -/usr/bin/mysqld_safe +echo -n "Starting mysql server..." +/usr/bin/mysqld_safe > /dev/null 2>&1 & check_port() { timeout 3 bash -c "/dev/null From f7e126b3c55043611d429438e6046f6d4eab13ec Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sun, 11 Jun 2017 21:53:55 +0100 Subject: [PATCH 15/30] Add local mysql-server check & init --- docker-entrypoint.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 3bfde118..052a4212 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -11,14 +11,20 @@ TIMEZONE="${TIMEZONE:-UTC}" cd "$SHIN_BIN_DIR" || exit 9 -echo -n "Initialising database if it doesn't exist..." - -if [ ! -f /var/lib/mysql/ibdata1 ]; then +if [ $MYSQL_HOST == "127.0.0.1"] && [ ! -f /var/lib/mysql/ibdata1 ]; then +echo -n "local database doesn't exist if it doesn't exist..." mysqld --initialize -fi + + /usr/bin/mysqld_safe & + sleep 10s -echo -n "Starting mysql server..." -/usr/bin/mysqld_safe > /dev/null 2>&1 & + echo "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'rootpass' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql + + killall mysqld + sleep 10s + echo -n "Starting mysql server..." + /usr/bin/mysqld_safe > /dev/null 2>&1 & +fi check_port() { timeout 3 bash -c "/dev/null From 65046994f9e976fce13417b4dea840882d964ece Mon Sep 17 00:00:00 2001 From: cbrherms Date: Sun, 11 Jun 2017 22:35:30 +0100 Subject: [PATCH 16/30] Variable quotes and echo info --- docker-entrypoint.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 052a4212..4af191fa 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -11,8 +11,9 @@ TIMEZONE="${TIMEZONE:-UTC}" cd "$SHIN_BIN_DIR" || exit 9 -if [ $MYSQL_HOST == "127.0.0.1"] && [ ! -f /var/lib/mysql/ibdata1 ]; then -echo -n "local database doesn't exist if it doesn't exist..." +if [ "$MYSQL_HOST" == "127.0.0.1" ] && [ ! -f /var/lib/mysql/ibdata1 ]; then +echo -n "Local database doesn't exist, initializing..." +echo -n "Please wait, this may take a while" mysqld --initialize /usr/bin/mysqld_safe & @@ -21,10 +22,10 @@ echo -n "local database doesn't exist if it doesn't exist..." echo "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'rootpass' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql killall mysqld - sleep 10s + sleep 5s +fi echo -n "Starting mysql server..." /usr/bin/mysqld_safe > /dev/null 2>&1 & -fi check_port() { timeout 3 bash -c "/dev/null From c0eb705771c31e655d11e704824006ad909cc5fa Mon Sep 17 00:00:00 2001 From: cbrherms Date: Mon, 12 Jun 2017 00:39:25 +0100 Subject: [PATCH 17/30] Fix external mysql data files --- Dockerfile | 3 ++- docker-entrypoint.sh | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 33a8626f..83930e34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,8 @@ RUN apt update \ && cp /opt/shinobi/plugins/motion/conf.sample.json /opt/shinobi/plugins/motion/conf.json \ && mkdir -p /var/run/mysqld \ && chown root:root /var/run/mysqld -RUN sed -i -e"s/^user\s*=\s*mysql/user = root/" /etc/mysql/mysql.conf.d/mysqld.cnf +RUN sed -i -e"s/^user\s*=\s*mysql/user = root/" /etc/mysql/mysql.conf.d/mysqld.cnf \ + && sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf VOLUME ["/opt/shinobi/videos"] VOLUME ["/var/lib/mysql"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4af191fa..e96aec71 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -12,14 +12,16 @@ TIMEZONE="${TIMEZONE:-UTC}" cd "$SHIN_BIN_DIR" || exit 9 if [ "$MYSQL_HOST" == "127.0.0.1" ] && [ ! -f /var/lib/mysql/ibdata1 ]; then -echo -n "Local database doesn't exist, initializing..." -echo -n "Please wait, this may take a while" + echo -n "Local database doesn't exist, initializing..." + echo -n "Please wait, this may take a while" mysqld --initialize + touch /opt/shinobi/mysql-init.txt + echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '"$MYSQL_ROOT_PASSWORD"';" >> /opt/shinobi/mysql-init.txt - /usr/bin/mysqld_safe & + /usr/bin/mysqld_safe --init-file=/opt/shinobi/mysql-init.txt > /dev/null 2>&1 & sleep 10s - echo "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'rootpass' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql + echo "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'rootpass' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql -u root -p"$MYSQL_ROOT_PASSWORD" -h 127.0.0.1 killall mysqld sleep 5s From 8f72b85e591f0084c5ab450f2b07198ba84bc058 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Mon, 12 Jun 2017 01:17:19 +0100 Subject: [PATCH 18/30] Add root password modifier to normal service start --- docker-entrypoint.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index e96aec71..fd9f6bd7 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -26,8 +26,11 @@ if [ "$MYSQL_HOST" == "127.0.0.1" ] && [ ! -f /var/lib/mysql/ibdata1 ]; then killall mysqld sleep 5s fi + echo -n "Starting mysql server..." - /usr/bin/mysqld_safe > /dev/null 2>&1 & + touch /opt/shinobi/mysql-init.txt + echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '"$MYSQL_ROOT_PASSWORD"';" >> /opt/shinobi/mysql-init.txt + /usr/bin/mysqld_safe --init-file=/opt/shinobi/mysql-init.txt > /dev/null 2>&1 & check_port() { timeout 3 bash -c "/dev/null From b4bce7a75dd2774806a96caab65021ff8834b17a Mon Sep 17 00:00:00 2001 From: cbrherms Date: Mon, 12 Jun 2017 01:33:30 +0100 Subject: [PATCH 19/30] Cleanup compose and entry --- docker-compose.yml | 19 +++---------------- docker-entrypoint.sh | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 952cd2dc..73213539 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,14 +4,12 @@ services: container_name: shinobi build: context: . - depends_on: - - database restart: always environment: - - MYSQL_HOST=shinobi-db + - MYSQL_HOST=127.0.0.1 - MYSQL_DATABASE=shinobi - MYSQL_USER=ccio - - MYSQL_PASSWORD=shinobi_pass + - MYSQL_PASSWORD=shinobi - MYSQL_ROOT_PASSWORD=rootpass ## Timezone - eg Europe/London - TIMEZONE=UTC @@ -19,15 +17,4 @@ services: - "8080:8080" volumes: - ./videos:/opt/shinobi/videos - database: - container_name: shinobi-db - image: mariadb - restart: always - environment: - - MYSQL_ROOT_PASSWORD=rootpass - volumes: - - dbdata:/var/lib/mysql -volumes: -## persistent data volume for mysql data - dbdata: - driver: local + - ./dbdata:/var/lib/mysql diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index fd9f6bd7..8b44c4ac 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -21,7 +21,7 @@ if [ "$MYSQL_HOST" == "127.0.0.1" ] && [ ! -f /var/lib/mysql/ibdata1 ]; then /usr/bin/mysqld_safe --init-file=/opt/shinobi/mysql-init.txt > /dev/null 2>&1 & sleep 10s - echo "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'rootpass' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql -u root -p"$MYSQL_ROOT_PASSWORD" -h 127.0.0.1 + echo "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '"$MYSQL_ROOT_PASSWORD"' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql -u root -p"$MYSQL_ROOT_PASSWORD" -h 127.0.0.1 killall mysqld sleep 5s From 7d3fe1a854dd1c7f2e7a1db54d6ca66a4b1f13ae Mon Sep 17 00:00:00 2001 From: cbrherms Date: Mon, 12 Jun 2017 01:52:17 +0100 Subject: [PATCH 20/30] fix rebase conflict --- sql/tables.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/tables.sql b/sql/tables.sql index d396b6f8..9064b149 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -11,6 +11,7 @@ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +-- Dumping structure for table ccio.API -- Dumping structure for table ccio.API CREATE TABLE IF NOT EXISTS `API` ( `ke` varchar(50) DEFAULT NULL, @@ -110,4 +111,4 @@ CREATE TABLE IF NOT EXISTS `Videos` ( -- Data exporting was unselected. /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; \ No newline at end of file From d12f13e5b5ec935588949f4242b5ed2a3f3d390a Mon Sep 17 00:00:00 2001 From: cbrherms Date: Mon, 12 Jun 2017 01:55:02 +0100 Subject: [PATCH 21/30] Add frameworks.sql back in --- sql/framework.sql | 117 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 sql/framework.sql diff --git a/sql/framework.sql b/sql/framework.sql new file mode 100644 index 00000000..fd98871b --- /dev/null +++ b/sql/framework.sql @@ -0,0 +1,117 @@ +-- -------------------------------------------------------- +-- Host: 192.168.88.58 +-- Server version: 5.7.17-0ubuntu0.16.04.1 - (Ubuntu) +-- Server OS: Linux +-- HeidiSQL Version: 9.3.0.4984 +-- -------------------------------------------------------- + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET NAMES utf8mb4 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; + +-- Dumping database structure for ccio +CREATE DATABASE IF NOT EXISTS `ccio` /*!40100 DEFAULT CHARACTER SET utf8 */; +USE `ccio`; + + +-- Dumping structure for table ccio.API +CREATE TABLE IF NOT EXISTS `API` ( + `ke` varchar(50) DEFAULT NULL, + `uid` varchar(50) DEFAULT NULL, + `ip` tinytext, + `code` varchar(100) DEFAULT NULL, + `details` text, + `time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Events +CREATE TABLE IF NOT EXISTS `Events` ( + `ke` varchar(50) DEFAULT NULL, + `mid` varchar(50) DEFAULT NULL, + `details` text, + `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Logs +CREATE TABLE IF NOT EXISTS `Logs` ( + `ke` varchar(50) DEFAULT NULL, + `mid` varchar(50) DEFAULT NULL, + `info` text, + `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Monitors +CREATE TABLE IF NOT EXISTS `Monitors` ( + `mid` varchar(50) DEFAULT NULL, + `ke` varchar(50) DEFAULT NULL, + `name` varchar(50) DEFAULT NULL, + `shto` text, + `shfr` text, + `details` longtext, + `type` varchar(50) DEFAULT 'jpeg', + `ext` varchar(50) DEFAULT 'webm', + `protocol` varchar(50) DEFAULT 'http', + `host` varchar(100) DEFAULT '0.0.0.0', + `path` varchar(100) DEFAULT '/', + `port` int(8) DEFAULT '80', + `fps` int(8) DEFAULT '1', + `mode` varchar(15) DEFAULT NULL, + `width` int(11) DEFAULT '640', + `height` int(11) DEFAULT '360' +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Presets +CREATE TABLE IF NOT EXISTS `Presets` ( + `ke` varchar(50) DEFAULT NULL, + `name` text, + `details` text, + `type` enum('monitor','event','user') DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Users +CREATE TABLE IF NOT EXISTS `Users` ( + `ke` varchar(50) DEFAULT NULL, + `uid` varchar(50) DEFAULT NULL, + `auth` varchar(50) DEFAULT NULL, + `mail` varchar(100) DEFAULT NULL, + `pass` varchar(100) DEFAULT NULL, + `details` longtext, + UNIQUE KEY `mail` (`mail`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Videos +CREATE TABLE IF NOT EXISTS `Videos` ( + `mid` varchar(50) DEFAULT NULL, + `ke` varchar(50) DEFAULT NULL, + `ext` enum('webm','mp4') DEFAULT NULL, + `time` timestamp NULL DEFAULT NULL, + `duration` float DEFAULT NULL, + `size` float DEFAULT NULL, + `frames` int(11) DEFAULT NULL, + `end` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `status` int(1) DEFAULT '0' COMMENT '0:Open,1:Complete,2:Error,3:Unknown' +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. +/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; +/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; \ No newline at end of file From 4e222fd36e18b38d0c182502cf1de59b28b0ecca Mon Sep 17 00:00:00 2001 From: cbrherms Date: Mon, 12 Jun 2017 01:56:46 +0100 Subject: [PATCH 22/30] Remove framework.sql again --- sql/framework.sql | 117 ---------------------------------------------- 1 file changed, 117 deletions(-) delete mode 100644 sql/framework.sql diff --git a/sql/framework.sql b/sql/framework.sql deleted file mode 100644 index fd98871b..00000000 --- a/sql/framework.sql +++ /dev/null @@ -1,117 +0,0 @@ --- -------------------------------------------------------- --- Host: 192.168.88.58 --- Server version: 5.7.17-0ubuntu0.16.04.1 - (Ubuntu) --- Server OS: Linux --- HeidiSQL Version: 9.3.0.4984 --- -------------------------------------------------------- - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET NAMES utf8mb4 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; - --- Dumping database structure for ccio -CREATE DATABASE IF NOT EXISTS `ccio` /*!40100 DEFAULT CHARACTER SET utf8 */; -USE `ccio`; - - --- Dumping structure for table ccio.API -CREATE TABLE IF NOT EXISTS `API` ( - `ke` varchar(50) DEFAULT NULL, - `uid` varchar(50) DEFAULT NULL, - `ip` tinytext, - `code` varchar(100) DEFAULT NULL, - `details` text, - `time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- Data exporting was unselected. - - --- Dumping structure for table ccio.Events -CREATE TABLE IF NOT EXISTS `Events` ( - `ke` varchar(50) DEFAULT NULL, - `mid` varchar(50) DEFAULT NULL, - `details` text, - `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; - --- Data exporting was unselected. - - --- Dumping structure for table ccio.Logs -CREATE TABLE IF NOT EXISTS `Logs` ( - `ke` varchar(50) DEFAULT NULL, - `mid` varchar(50) DEFAULT NULL, - `info` text, - `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- Data exporting was unselected. - - --- Dumping structure for table ccio.Monitors -CREATE TABLE IF NOT EXISTS `Monitors` ( - `mid` varchar(50) DEFAULT NULL, - `ke` varchar(50) DEFAULT NULL, - `name` varchar(50) DEFAULT NULL, - `shto` text, - `shfr` text, - `details` longtext, - `type` varchar(50) DEFAULT 'jpeg', - `ext` varchar(50) DEFAULT 'webm', - `protocol` varchar(50) DEFAULT 'http', - `host` varchar(100) DEFAULT '0.0.0.0', - `path` varchar(100) DEFAULT '/', - `port` int(8) DEFAULT '80', - `fps` int(8) DEFAULT '1', - `mode` varchar(15) DEFAULT NULL, - `width` int(11) DEFAULT '640', - `height` int(11) DEFAULT '360' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- Data exporting was unselected. - - --- Dumping structure for table ccio.Presets -CREATE TABLE IF NOT EXISTS `Presets` ( - `ke` varchar(50) DEFAULT NULL, - `name` text, - `details` text, - `type` enum('monitor','event','user') DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- Data exporting was unselected. - - --- Dumping structure for table ccio.Users -CREATE TABLE IF NOT EXISTS `Users` ( - `ke` varchar(50) DEFAULT NULL, - `uid` varchar(50) DEFAULT NULL, - `auth` varchar(50) DEFAULT NULL, - `mail` varchar(100) DEFAULT NULL, - `pass` varchar(100) DEFAULT NULL, - `details` longtext, - UNIQUE KEY `mail` (`mail`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- Data exporting was unselected. - - --- Dumping structure for table ccio.Videos -CREATE TABLE IF NOT EXISTS `Videos` ( - `mid` varchar(50) DEFAULT NULL, - `ke` varchar(50) DEFAULT NULL, - `ext` enum('webm','mp4') DEFAULT NULL, - `time` timestamp NULL DEFAULT NULL, - `duration` float DEFAULT NULL, - `size` float DEFAULT NULL, - `frames` int(11) DEFAULT NULL, - `end` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `status` int(1) DEFAULT '0' COMMENT '0:Open,1:Complete,2:Error,3:Unknown' -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- Data exporting was unselected. -/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; -/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; \ No newline at end of file From fbe8227e229d3d1425dbca992599c67360972ff7 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Mon, 12 Jun 2017 02:04:25 +0100 Subject: [PATCH 23/30] Remove double comment --- sql/tables.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/tables.sql b/sql/tables.sql index 9064b149..9798dfc7 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -11,7 +11,6 @@ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; --- Dumping structure for table ccio.API -- Dumping structure for table ccio.API CREATE TABLE IF NOT EXISTS `API` ( `ke` varchar(50) DEFAULT NULL, From ef45b5447a47f4fbcaf48d6fecc855331a017eb5 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Wed, 14 Jun 2017 00:04:22 +0100 Subject: [PATCH 24/30] MySQL start only on local database --- .gitignore | 3 ++- docker-entrypoint.sh | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c14e59ee..2a57ba43 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ web.old .DS_Store .vagrant conf.json -super.json \ No newline at end of file +super.json +dbdata \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 8b44c4ac..65c88cfd 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -27,10 +27,13 @@ if [ "$MYSQL_HOST" == "127.0.0.1" ] && [ ! -f /var/lib/mysql/ibdata1 ]; then sleep 5s fi + +if [ "$MYSQL_HOST" == "127.0.0.1" ]; then echo -n "Starting mysql server..." touch /opt/shinobi/mysql-init.txt echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '"$MYSQL_ROOT_PASSWORD"';" >> /opt/shinobi/mysql-init.txt /usr/bin/mysqld_safe --init-file=/opt/shinobi/mysql-init.txt > /dev/null 2>&1 & +fi check_port() { timeout 3 bash -c "/dev/null From efd771e5a0e9adbf301f9c3448ce82953de96f00 Mon Sep 17 00:00:00 2001 From: cbrherms Date: Wed, 14 Jun 2017 00:19:53 +0100 Subject: [PATCH 25/30] Comment entry script --- docker-entrypoint.sh | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 65c88cfd..11d7dc60 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/bash +#Environment variables SHIN_BIN_DIR=/opt/shinobi MYSQL_HOST="${MYSQL_HOST:-127.0.0.1}" MYSQL_DATABASE="${MYSQL_DATABASE:-shinobi}" @@ -9,25 +10,33 @@ MYSQL_USER="${MYSQL_USER:-ccio}" MYSQL_PASSWORD="${MYSQL_PASSWORD:-shinobi}" TIMEZONE="${TIMEZONE:-UTC}" +#Port check function +check_port() { + timeout 3 bash -c "/dev/null +} + +#Mysql login function +_mysql() { + mysql -u "${MYSQL_ROOT_USER}" -p"${MYSQL_ROOT_PASSWORD}" -h "${MYSQL_HOST}" "$@" +} + cd "$SHIN_BIN_DIR" || exit 9 +#Initialize db if running locally and it currently doesn't exist if [ "$MYSQL_HOST" == "127.0.0.1" ] && [ ! -f /var/lib/mysql/ibdata1 ]; then echo -n "Local database doesn't exist, initializing..." echo -n "Please wait, this may take a while" mysqld --initialize touch /opt/shinobi/mysql-init.txt echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '"$MYSQL_ROOT_PASSWORD"';" >> /opt/shinobi/mysql-init.txt - /usr/bin/mysqld_safe --init-file=/opt/shinobi/mysql-init.txt > /dev/null 2>&1 & sleep 10s - echo "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '"$MYSQL_ROOT_PASSWORD"' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql -u root -p"$MYSQL_ROOT_PASSWORD" -h 127.0.0.1 - killall mysqld sleep 5s fi - +#Start mysql-server if running locally if [ "$MYSQL_HOST" == "127.0.0.1" ]; then echo -n "Starting mysql server..." touch /opt/shinobi/mysql-init.txt @@ -35,18 +44,12 @@ if [ "$MYSQL_HOST" == "127.0.0.1" ]; then /usr/bin/mysqld_safe --init-file=/opt/shinobi/mysql-init.txt > /dev/null 2>&1 & fi -check_port() { - timeout 3 bash -c "/dev/null -} - -_mysql() { - mysql -u "${MYSQL_ROOT_USER}" -p"${MYSQL_ROOT_PASSWORD}" -h "${MYSQL_HOST}" "$@" -} - +#Set timezone echo "${TIMEZONE}" > /etc/timezone rm /etc/localtime dpkg-reconfigure -f noninteractive tzdata +#Check that mysql server is reachable echo -n "Waiting for MYSQL server port..." while ! check_port "$MYSQL_HOST" 3306 do @@ -54,6 +57,7 @@ do done echo 'Done!' +#Check for shinobi database data and if not present then install tables_check="select count(*) from information_schema.tables where table_schema='${MYSQL_DATABASE}' and table_name='API';" tables_num=$(mysql -N -s -u "${MYSQL_ROOT_USER}" -p"${MYSQL_ROOT_PASSWORD}" -h "${MYSQL_HOST}" -e "${tables_check}") @@ -68,11 +72,14 @@ then _mysql --database "$MYSQL_DATABASE" < "${SHIN_BIN_DIR}/sql/default_data.sql" npm cache clean -f && npm install -g n && n stable fi + +#set config data from variables sed -i 's/"user": "majesticflame"/"user": "'"${MYSQL_USER}"'"/g' "$SHIN_BIN_DIR/conf.json" sed -i 's/"password": ""/"password": "'"${MYSQL_PASSWORD}"'"/g' "$SHIN_BIN_DIR/conf.json" sed -i 's/"host": "127.0.0.1"/"host": "'"${MYSQL_HOST}"'"/g' "$SHIN_BIN_DIR/conf.json" sed -i 's/"database": "ccio"/"database": "'"${MYSQL_DATABASE}"'"/g' "$SHIN_BIN_DIR/conf.json" +#start shinobi daemon pm2 start "${SHIN_BIN_DIR}/cron.js" pm2 start "${SHIN_BIN_DIR}/camera.js" pm2 start "${SHIN_BIN_DIR}/plugins/motion/shinobi-motion.js" From 883b3ed4c099e94adcbc5d7d14516ac9d24e004e Mon Sep 17 00:00:00 2001 From: Moe Date: Thu, 15 Jun 2017 13:30:15 -0700 Subject: [PATCH 26/30] rtsp transport bug --- camera.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/camera.js b/camera.js index 1f14276a..898a57e9 100644 --- a/camera.js +++ b/camera.js @@ -566,9 +566,14 @@ s.ffmpeg=function(e,x){ //input - analyze duration if(e.details.aduration&&e.details.aduration!==''){x.cust_input+=' -analyzeduration '+e.details.aduration}; //input - check protocol - switch(e.protocol){ - case'rtsp': - if(e.details.rtsp_transport&&e.details.rtsp_transport!==''&&e.details.rtsp_transport!=='no'){x.cust_input+=' -rtsp_transport '+e.details.rtsp_transport;} + //input + switch(e.type){ + case'h264': + switch(e.protocol){ + case'rtsp': + if(e.details.rtsp_transport&&e.details.rtsp_transport!==''&&e.details.rtsp_transport!=='no'){x.cust_input+=' -rtsp_transport '+e.details.rtsp_transport;} + break; + } break; } //record - resolution From 1eb2212ae4aede2f3eda2fe12b04bd916d90a21b Mon Sep 17 00:00:00 2001 From: cbrherms Date: Thu, 15 Jun 2017 23:23:50 +0100 Subject: [PATCH 27/30] Add framework.sql back in and revert U & C install scripts --- INSTALL/centos.sh | 3 +- INSTALL/ubuntu.sh | 3 +- sql/framework.sql | 117 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 sql/framework.sql diff --git a/INSTALL/centos.sh b/INSTALL/centos.sh index 01f37c59..acb87438 100644 --- a/INSTALL/centos.sh +++ b/INSTALL/centos.sh @@ -24,8 +24,7 @@ echo "What is your SQL Password?" echo "**You set this just a few moments ago if MySQL was installed during this installer." read sqlpass mysql -u root -p$sqlpass -e "source sql/user.sql" || true -mysql -u root -p$sqlpass -e "source sql/database.sql" || true -mysql -u root -p$sqlpass --database ccio -e "source sql/tables.sql" || true +mysql -u root -p$sqlpass -e "source sql/framework.sql" || true mysql -u root -p$sqlpass --database ccio -e "source sql/default_data.sql" || true echo "Shinobi - Install NPM Libraries" npm install diff --git a/INSTALL/ubuntu.sh b/INSTALL/ubuntu.sh index e85fde1c..80eac24b 100644 --- a/INSTALL/ubuntu.sh +++ b/INSTALL/ubuntu.sh @@ -25,8 +25,7 @@ chmod -R 755 . echo "=============" echo "Shinobi - Database Installation" mysql -u root -p$sqlpass -e "source sql/user.sql" || true -mysql -u root -p$sqlpass -e "source sql/database.sql" || true -mysql -u root -p$sqlpass --database ccio -e "source sql/tables.sql" || true +mysql -u root -p$sqlpass -e "source sql/framework.sql" || true mysql -u root -p$sqlpass --database ccio -e "source sql/default_data.sql" || true echo "=============" echo "Shinobi - Install NPM Libraries" diff --git a/sql/framework.sql b/sql/framework.sql new file mode 100644 index 00000000..d887a0b9 --- /dev/null +++ b/sql/framework.sql @@ -0,0 +1,117 @@ +-- -------------------------------------------------------- +-- Host: 192.168.88.58 +-- Server version: 5.7.17-0ubuntu0.16.04.1 - (Ubuntu) +-- Server OS: Linux +-- HeidiSQL Version: 9.3.0.4984 +-- -------------------------------------------------------- + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET NAMES utf8mb4 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; + +-- Dumping database structure for ccio +CREATE DATABASE IF NOT EXISTS `ccio` /*!40100 DEFAULT CHARACTER SET utf8 */; +USE `ccio`; + + +-- Dumping structure for table ccio.API +CREATE TABLE IF NOT EXISTS `API` ( + `ke` varchar(50) DEFAULT NULL, + `uid` varchar(50) DEFAULT NULL, + `ip` tinytext, + `code` varchar(100) DEFAULT NULL, + `details` text, + `time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Events +CREATE TABLE IF NOT EXISTS `Events` ( + `ke` varchar(50) DEFAULT NULL, + `mid` varchar(50) DEFAULT NULL, + `details` text, + `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Logs +CREATE TABLE IF NOT EXISTS `Logs` ( + `ke` varchar(50) DEFAULT NULL, + `mid` varchar(50) DEFAULT NULL, + `info` text, + `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Monitors +CREATE TABLE IF NOT EXISTS `Monitors` ( + `mid` varchar(50) DEFAULT NULL, + `ke` varchar(50) DEFAULT NULL, + `name` varchar(50) DEFAULT NULL, + `shto` text, + `shfr` text, + `details` longtext, + `type` varchar(50) DEFAULT 'jpeg', + `ext` varchar(50) DEFAULT 'webm', + `protocol` varchar(50) DEFAULT 'http', + `host` varchar(100) DEFAULT '0.0.0.0', + `path` varchar(100) DEFAULT '/', + `port` int(8) DEFAULT '80', + `fps` int(8) DEFAULT '1', + `mode` varchar(15) DEFAULT NULL, + `width` int(11) DEFAULT '640', + `height` int(11) DEFAULT '360' +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Presets +CREATE TABLE IF NOT EXISTS `Presets` ( + `ke` varchar(50) DEFAULT NULL, + `name` text, + `details` text, + `type` enum('monitor','event','user') DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Users +CREATE TABLE IF NOT EXISTS `Users` ( + `ke` varchar(50) DEFAULT NULL, + `uid` varchar(50) DEFAULT NULL, + `auth` varchar(50) DEFAULT NULL, + `mail` varchar(100) DEFAULT NULL, + `pass` varchar(100) DEFAULT NULL, + `details` longtext, + UNIQUE KEY `mail` (`mail`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. + + +-- Dumping structure for table ccio.Videos +CREATE TABLE IF NOT EXISTS `Videos` ( + `mid` varchar(50) DEFAULT NULL, + `ke` varchar(50) DEFAULT NULL, + `ext` enum('webm','mp4') DEFAULT NULL, + `time` timestamp NULL DEFAULT NULL, + `duration` float DEFAULT NULL, + `size` float DEFAULT NULL, + `frames` int(11) DEFAULT NULL, + `end` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `status` int(1) DEFAULT '0' COMMENT '0:Open,1:Complete,2:Error,3:Unknown' +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Data exporting was unselected. +/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; +/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; From 830a80d0bcbd7485091a115796fe7bd18e86c0d0 Mon Sep 17 00:00:00 2001 From: Moe Date: Thu, 15 Jun 2017 21:20:43 -0700 Subject: [PATCH 28/30] two factor authentication, libs path relative --- camera.js | 114 ++++++++++++++++++++++++---------- web/pages/admin.ejs | 30 ++++----- web/pages/blocks/header.ejs | 12 ++-- web/pages/blocks/help.ejs | 2 +- web/pages/blocks/settings.ejs | 8 +++ web/pages/classic.ejs | 38 ++++++------ web/pages/factor.ejs | 69 ++++++++++++++++++++ web/pages/home.ejs | 50 +++++++-------- web/pages/index.ejs | 2 +- web/pages/streamer.ejs | 8 +-- web/pages/super.ejs | 34 +++++----- 11 files changed, 247 insertions(+), 120 deletions(-) create mode 100644 web/pages/factor.ejs diff --git a/camera.js b/camera.js index 898a57e9..002e2ef0 100644 --- a/camera.js +++ b/camera.js @@ -63,7 +63,7 @@ if(config.pluginKeys===undefined)config.pluginKeys={}; server.listen(config.port,config.bindip); -s={child_help:false,totalmem:os.totalmem(),platform:os.platform(),s:JSON.stringify,isWin:(process.platform==='win32')}; +s={factorAuth:{},child_help:false,totalmem:os.totalmem(),platform:os.platform(),s:JSON.stringify,isWin:(process.platform==='win32')}; s.systemLog=function(q,w,e){ if(!w){w=''} if(!e){e=''} @@ -2415,11 +2415,43 @@ app.post('/:auth/register/:ke/:uid',function (req,res){ },res,req); }) //login function +s.deleteFactorAuth=function(r){ + delete(s.factorAuth[r.ke][r.uid]) + if(Object.keys(s.factorAuth[r.ke]).length===0){ + delete(s.factorAuth[r.ke]) + } +} app.post('/',function (req,res){ req.failed=function(){ res.render("index",{failedLogin:true}); res.end(); } + req.fn=function(){ + switch(req.body.function){ + case'streamer': + sql.query('SELECT * FROM Monitors WHERE ke=? AND type=?',[r.ke,"socket"],function(err,rr){ + req.resp.mons=rr; + res.render("streamer",{$user:req.resp}); + }) + break; + case'admin': + if(!r.details.sub){ + sql.query('SELECT uid,mail,details FROM Users WHERE ke=? AND details LIKE \'%"sub"%\'',[r.ke],function(err,rr) { + sql.query('SELECT * FROM Monitors WHERE ke=?',[r.ke],function(err,rrr) { + res.render("admin",{$user:req.resp,$subs:rr,$mons:rrr}); + }) + }) + }else{ + //not admin user + res.render("home",{$user:req.resp,config:config}); + } + break; + default: + res.render("home",{$user:req.resp,config:config}); + break; + } + // res.end(); + } if(req.body.mail&&req.body.pass){ if(req.body.function==='super'){ if(!fs.existsSync('./super.json')){ @@ -2441,30 +2473,33 @@ app.post('/',function (req,res){ sql.query("UPDATE Users SET auth=? WHERE ke=? AND uid=?",[r.auth,r.ke,r.uid]) req.resp={ok:true,auth_token:r.auth,ke:r.ke,uid:r.uid,mail:r.mail,details:r.details}; r.details=JSON.parse(r.details); - - req.fn=function(){ - switch(req.body.function){ - case'streamer': - sql.query('SELECT * FROM Monitors WHERE ke=? AND type=?',[r.ke,"socket"],function(err,rr){ - req.resp.mons=rr; - res.render("streamer",{$user:req.resp}); - }) - break; - case'admin': - if(!r.details.sub){ - sql.query('SELECT uid,mail,details FROM Users WHERE ke=? AND details LIKE \'%"sub"%\'',[r.ke],function(err,rr) { - sql.query('SELECT * FROM Monitors WHERE ke=?',[r.ke],function(err,rrr) { - res.render("admin",{$user:req.resp,$subs:rr,$mons:rrr}); - }) - }) - }else{ - //not admin user - res.render("home",{$user:req.resp,config:config}); - } - break; - default: - res.render("home",{$user:req.resp,config:config}); - break; + + req.factorAuth=function(cb){ + if(r.details.factorAuth==="1"){ + if(!s.factorAuth[r.ke]){s.factorAuth[r.ke]={}} + if(!s.factorAuth[r.ke][r.uid]){ + s.factorAuth[r.ke][r.uid]={key:s.gid()} + r.mailOptions = { + from: '"ShinobiCCTV" ', + to: r.mail, + subject: '2-Factor Authentication', + html: 'Enter this code to proceed '+s.factorAuth[r.ke][r.uid].key+'. The code will only be active for 15 minutes. If you login again the timer will be reset to 15 minutes with the same code.', + }; + nodemailer.sendMail(r.mailOptions, (error, info) => { + if (error) { + console.log(error) + return ; + } + }); + } + s.factorAuth[r.ke][r.uid].info=req.resp; + clearTimeout(s.factorAuth[r.ke][r.uid].expireAuth) + s.factorAuth[r.ke][r.uid].expireAuth=setTimeout(function(){ + s.deleteFactorAuth(r) + },1000*60*15) + res.render("factor",{$user:req.resp}) + }else{ + req.fn() } } if(r.details.sub){ @@ -2473,22 +2508,37 @@ app.post('/',function (req,res){ rr.details=JSON.parse(rr.details); r.details.mon_groups=rr.details.mon_groups; req.resp.details=JSON.stringify(r.details); - req.fn(); + req.factorAuth() }) }else{ - req.fn() + req.factorAuth() } - - - - }else{ req.failed() } }) } }else{ - req.failed() + if(req.body.machineID&&req.body.factorAuthKey){ + console.log('Login Type : 2 Factor Auth') + if(s.factorAuth[req.body.ke]&&s.factorAuth[req.body.ke][req.body.id]&&s.factorAuth[req.body.ke][req.body.id].key===req.body.factorAuthKey){ + if(s.factorAuth[req.body.ke][req.body.id].key===req.body.factorAuthKey){ + console.log('Success') + req.resp=s.factorAuth[req.body.ke][req.body.id].info + req.fn() + }else{ + console.log('Incorrect, Try again') + res.render("factor",{$user:s.factorAuth[req.body.ke][req.body.id].info}); + res.end(); + } + }else{ + console.log('Key expired or incorrect') + req.failed() + } + }else{ + console.log('No known login type') + req.failed() + } } }); // Get Motion Buffer stream (m3u8) diff --git a/web/pages/admin.ejs b/web/pages/admin.ejs index 893614b1..490e13e5 100644 --- a/web/pages/admin.ejs +++ b/web/pages/admin.ejs @@ -14,14 +14,14 @@ } nav{margin-top:20px} - - - - - - - - + + + + + + + +
@@ -94,13 +94,13 @@ <% include blocks/subpermissions.ejs %>
- - - - - - - + + + + + + + - + + \ No newline at end of file diff --git a/web/pages/blocks/help.ejs b/web/pages/blocks/help.ejs index 8c87aec2..c7cf9469 100644 --- a/web/pages/blocks/help.ejs +++ b/web/pages/blocks/help.ejs @@ -9,7 +9,7 @@
+
+ +
<% if(!details.sub){ %> <% if(details.edit_size!=='0'){ %>
diff --git a/web/pages/classic.ejs b/web/pages/classic.ejs index c7720325..328b26d7 100644 --- a/web/pages/classic.ejs +++ b/web/pages/classic.ejs @@ -1,13 +1,13 @@ <% include blocks/header %> - - - - - - - - + + + + + + + +
- + - +
Stream
@@ -17,9 +17,9 @@ requires https or firefox
- - - + + + - - - - - - - + + + + + + + +