Skip to content

Commit

Permalink
5.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Dec 10, 2024
1 parent 51c2a3c commit 92171df
Show file tree
Hide file tree
Showing 581 changed files with 74,153 additions and 467 deletions.
8 changes: 4 additions & 4 deletions .github/archives/workflows/build-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ jobs:

- name: Install motionui repo to grant access to most recent motion packages
run: |
curl -sS https://packages.bespin.ovh/repo/gpgkeys/packages.bespin.ovh.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.bespin.ovh_deb.gpg
echo "deb https://packages.bespin.ovh/repo/motionui/buster/main_prod buster main" > /etc/apt/sources.list.d/motionui.list
curl -sS https://packages.repomanager.net/repo/gpgkeys/packages.repomanager.net.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.repomanager.net_deb.gpg
echo "deb https://packages.repomanager.net/repo/motionui/buster/main_prod buster main" > /etc/apt/sources.list.d/motionui.list
# Download builded deb package artifact
- name: Download artifact
Expand Down Expand Up @@ -117,8 +117,8 @@ jobs:

- name: Install motionui repo to grant access to most recent motion packages
run: |
curl -sS https://packages.bespin.ovh/repo/gpgkeys/packages.bespin.ovh.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.bespin.ovh_deb.gpg
echo "deb https://packages.bespin.ovh/repo/motionui/bullseye/main_prod bullseye main" > /etc/apt/sources.list.d/motionui.list
curl -sS https://packages.repomanager.net/repo/gpgkeys/packages.repomanager.net.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.repomanager.net_deb.gpg
echo "deb https://packages.repomanager.net/repo/motionui/bullseye/main_prod bullseye main" > /etc/apt/sources.list.d/motionui.list
# Download builded deb package artifact
- name: Download artifact
Expand Down
8 changes: 4 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ RUN apt-get update -y
RUN apt-get install findutils iputils-ping git curl ca-certificates apt-transport-https dnsutils vim gnupg2 ffmpeg postfix -y

# Add motion 4.5.x repository
RUN curl -sS https://packages.bespin.ovh/repo/gpgkeys/packages.bespin.ovh.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.bespin.ovh.gpg
RUN echo "deb https://packages.bespin.ovh/repo/motion/bookworm/main_prod bookworm main" > /etc/apt/sources.list.d/motion.list
RUN curl -sS https://packages.repomanager.net/repo/gpgkeys/packages.repomanager.net.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.repomanager.net.gpg
RUN echo "deb https://packages.repomanager.net/repo/motion/bookworm/main_prod bookworm main" > /etc/apt/sources.list.d/motion.list

# Add nginx and PHP repositories
RUN echo "deb https://packages.bespin.ovh/repo/motionui-nginx/bookworm/nginx_prod bookworm nginx" > /etc/apt/sources.list.d/nginx.list
RUN echo "deb https://packages.bespin.ovh/repo/motionui-php/bookworm/main_prod bookworm main" > /etc/apt/sources.list.d/php.list
RUN echo "deb https://packages.repomanager.net/repo/motionui-nginx/bookworm/nginx_prod bookworm nginx" > /etc/apt/sources.list.d/nginx.list
RUN echo "deb https://packages.repomanager.net/repo/motionui-php/bookworm/main_prod bookworm main" > /etc/apt/sources.list.d/php.list
RUN apt-get update -y

# Install nginx and PHP 8.3
Expand Down
15 changes: 13 additions & 2 deletions docker/config/nginx/motionui.conf
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ server {
fastcgi_request_buffering off;
}

location ~ /api/stream.mjpeg {
# Go2rtc stream access
location /api/stream.mjpeg {
proxy_pass http://127.0.0.1:1984;
proxy_http_version 1.1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
Expand Down Expand Up @@ -122,4 +123,14 @@ server {
location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
access_log off;
}

# Websocket server
location /ws {
proxy_pass http://127.0.0.1:8085;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_read_timeout 86400;
}
}
3 changes: 2 additions & 1 deletion docker/init
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
WWW_DIR="/var/www/motionui"
DATA_DIR="/var/lib/motionui"
GO2RTC_DIR="/var/lib/motionui/go2rtc"
GO2RTC_LOG=""

# Make sure motion service is stopped
/usr/sbin/service motion stop
Expand Down Expand Up @@ -42,7 +43,7 @@ fi
/bin/su -s /bin/bash -c "php $WWW_DIR/tools/update-database.php" www-data

# Start go2rtc in background
/bin/su -s /bin/bash -c "/usr/local/bin/go2rtc -c $GO2RTC_DIR/go2rtc.yml >/dev/null 2>/dev/null &" www-data
/bin/su -s /bin/bash -c "/usr/local/bin/go2rtc -c $GO2RTC_DIR/go2rtc.yml >/var/lib/motionui/go2rtc/go2rtc.log &" www-data

# Start shell service in background
/bin/bash "$WWW_DIR/bin/service.sh" &
Expand Down
10 changes: 9 additions & 1 deletion www/controllers/App/Config/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Main
public static function get()
{
if (!defined('ROOT')) {
define('ROOT', dirname(__FILE__, 4));
define('ROOT', '/var/www/motionui');
}
if (!defined('DATA_DIR')) {
define('DATA_DIR', '/var/lib/motionui');
Expand All @@ -20,9 +20,17 @@ public static function get()
if (!defined('DB')) {
define('DB', DB_DIR . '/motionui.sqlite');
}
// Websocket server database
if (!defined('WS_DB')) {
define('WS_DB', DB_DIR . "/motionui-ws.sqlite");
}
if (!defined('LOGS_DIR')) {
define('LOGS_DIR', DATA_DIR . '/logs');
}
// Websocket server logs dir
if (!defined('WS_LOGS_DIR')) {
define('WS_LOGS_DIR', LOGS_DIR . '/websocket');
}
if (!defined('CAMERAS_DIR')) {
define('CAMERAS_DIR', DATA_DIR . '/cameras');
}
Expand Down
4 changes: 3 additions & 1 deletion www/controllers/App/Config/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public static function get()
* If an update is available, generate a new notification
*/
if (UPDATE_AVAILABLE) {
$message = '<span class="yellowtext">A new release is available: <b>' . GIT_VERSION . '</b>.</span><br><br>Please update your docker image by following the steps documented <a href="' . PROJECT_UPDATE_DOC_URL . '">here</a></span>';
$message = '<p>A new release is available: <a href="' . PROJECT_GIT_REPO . '/releases/latest" target="_blank" rel="noopener noreferrer" title="See changelog"><code>' . GIT_VERSION . '</code> <img src="/assets/icons/external-link.svg" class="icon" /></a></p>';
$message .= '<p>Please update your docker image by following the steps documented <b><a href="' . PROJECT_UPDATE_DOC_URL . '" target="_blank" rel="noopener noreferrer"><code>here</code></b> <img src="/assets/icons/external-link.svg" class="icon" /></a></p>';

$NOTIFICATION_MESSAGES[] = array('Title' => 'Update available', 'Message' => $message);
$NOTIFICATION++;
}
Expand Down
4 changes: 4 additions & 0 deletions www/controllers/App/Structure/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public static function create()
mkdir(LOGS_DIR, 0770, true);
}

if (!is_dir(WS_LOGS_DIR)) {
mkdir(WS_LOGS_DIR, 0770, true);
}

if (!is_dir(CAMERAS_DIR)) {
mkdir(CAMERAS_DIR, 0770, true);

Expand Down
2 changes: 1 addition & 1 deletion www/controllers/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct(string $level = 'all')
$__LOAD_ERROR_MESSAGES = array();

if (!defined('ROOT')) {
define('ROOT', dirname(__FILE__, 2));
define('ROOT', '/var/www/motionui');
}

$this->register();
Expand Down
31 changes: 11 additions & 20 deletions www/controllers/Camera/Timelapse.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,23 @@ public function timelapse()
/**
* Capture image
*/
$content = file_get_contents('http://127.0.0.1:1984/api/frame.jpeg?src=camera_' . $camera['Id'], false, stream_context_create([
'http' => [
'timeout' => 3
]
]));

/**
* Define ffmpeg command
* Timeout is set to 3 seconds, kill after 5 seconds if it does not exit
* Ignore if it fails to capture image because the camera may not be running 24/7
*/
$ffmpeg = '/usr/bin/timeout --kill-after=5 3 /usr/bin/ffmpeg';

/**
* Add input stream
*/
$ffmpeg .= ' -i ' . 'http://127.0.0.1:1984/api/stream.mjpeg?src=camera_' . $camera['Id'];

/**
* Execute ffmpeg command and save to file
*/
$myprocess = new \Controllers\Process($ffmpeg . ' ' . $targetDir . '/timelapse_' . date('H-i-s') . '.jpg >/dev/null 2>/dev/null &');
$myprocess->execute();
$output = $myprocess->getOutput();
$myprocess->close();
if ($content === false or empty($content)) {
continue;
}

/**
* Ignore error if ffmpeg fails to capture image because the camera may not be running 24/7
* Save image to file
*/
// if ($myprocess->getExitCode() != 0) {
// throw new Exception('Failed to capture timelapse image for camera "' . $camera['Name'] . '" (ffmpeg error)');
// }
file_put_contents($targetDir . '/timelapse_' . date('H-i-s') . '.jpg', $content);
} catch (Exception $e) {
$this->logController->log('error', 'Camera timelapse', 'Errow while executing timelapse capture: ' . $e->getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$mycamera = new \Controllers\Camera\Camera();
$mymotionEvent = new \Controllers\Motion\Event();

/**
* Get total cameras and cameras Ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use Exception;
use Datetime;

class ContainerState
class ContainerReload
{
private $model;

public function __construct()
{
$this->model = new \Models\Layout\ContainerState();
$this->model = new \Models\Layout\ContainerReload();
}

/**
Expand All @@ -23,35 +23,18 @@ public function get()
}

/**
* Add a new layout container state
* Add a container to reload in database
*/
public function add(string $name, string $id)
public function reload(string $name)
{
$this->model->add($name, $id);
}

/**
* Update a layout container state
*/
public function update(string $name)
{
/**
* Generate a new random Id
*/
$id = rand(10000, 100000);

/**
* Check if container name exists
* Ignore if container already exists in the database
*/
if ($this->model->exists($name)) {
$this->model->update($name, $id);
return;
}

/**
* If not, add it
*/
$this->add($name, $id);
$this->model->add($name);
}

/**
Expand All @@ -61,4 +44,12 @@ public function exists(string $name)
{
return $this->model->exists($name);
}

/**
* Clean all containers entries
*/
public function clean()
{
$this->model->clean();
}
}
51 changes: 38 additions & 13 deletions www/controllers/Motion/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
class Event
{
private $model;
private $layoutContainerStateController;
private $layoutContainerReloadController;
private $logController;

public function __construct()
{
$this->model = new \Models\Motion\Event();
$this->layoutContainerStateController = new \Controllers\Layout\ContainerState();
$this->layoutContainerReloadController = new \Controllers\Layout\ContainerReload();
$this->logController = new \Controllers\Log\Log();
}

Expand Down Expand Up @@ -47,9 +47,9 @@ public function new(string $motionEventId, int $motionEventIdShort, int $cameraI
/**
* Refresh page
*/
$this->layoutContainerStateController->update('motion/events/list');
$this->layoutContainerStateController->update('motion/stats/list');
$this->layoutContainerStateController->update('buttons/bottom');
$this->layoutContainerReloadController->reload('motion/events/list');
$this->layoutContainerReloadController->reload('motion/stats/list');
$this->layoutContainerReloadController->reload('buttons/bottom');
}

/**
Expand All @@ -62,9 +62,9 @@ public function end(string $motionEventId)
/**
* Refresh page
*/
$this->layoutContainerStateController->update('motion/events/list');
$this->layoutContainerStateController->update('motion/stats/list');
$this->layoutContainerStateController->update('buttons/bottom');
$this->layoutContainerReloadController->reload('motion/events/list');
$this->layoutContainerReloadController->reload('motion/stats/list');
$this->layoutContainerReloadController->reload('buttons/bottom');
}

/**
Expand All @@ -86,9 +86,9 @@ public function seen(int $id)
/**
* Return total unseen events count
*/
public function getUnseenCount()
public function getUnseenCount(int|null $cameraId = null)
{
return $this->model->getUnseenCount();
return $this->model->getUnseenCount($cameraId);
}

/**
Expand Down Expand Up @@ -120,9 +120,34 @@ public function attachFile(string $motionEventId, string $file, int $width, int
* Create thumbnail if not already exist
*/
if (!file_exists($file . '.thumbnail')) {
$myprocess = new \Controllers\Process('/usr/bin/ffmpeg -loglevel error -ss 00:00:00.10 -i ' . $file . ' -vf \'scale=320:320:force_original_aspect_ratio=decrease\' -vframes 1 ' . $file . '.thumbnail.jpg');
/**
* First, get the duration of the movie
*/
$myprocess = new \Controllers\Process("/usr/bin/ffmpeg -i " . $file . " 2>&1 | grep 'Duration' | awk '{print $2}' | tr -d ,");
$myprocess->execute();
$output = $myprocess->getOutput();
$myprocess->close();

/**
* If duration has been found, then create thumbnail
*/
if (!empty($output)) {
$duration = $output;

/**
* Convert duration to seconds
*/
list($hours, $minutes, $seconds) = explode(":", $duration);
$totalSeconds = ($hours * 3600) + ($minutes * 60) + $seconds;

/**
* Create thumbnail at the middle of the movie
*/
$myprocess = new \Controllers\Process('/usr/bin/ffmpeg -loglevel error -ss ' . gmdate("H:i:s", $totalSeconds / 2) . ' -i ' . $file . " -vf 'scale=320:320:force_original_aspect_ratio=decrease' -vframes 1 " . $file . '.thumbnail.jpg');
$myprocess->execute();
$output = $myprocess->getOutput();
$myprocess->close();
}
}
}

Expand All @@ -136,8 +161,8 @@ public function attachFile(string $motionEventId, string $file, int $width, int
/**
* Refresh page
*/
$this->layoutContainerStateController->update('motion/events/list');
$this->layoutContainerStateController->update('motion/stats/list');
$this->layoutContainerReloadController->reload('motion/events/list');
$this->layoutContainerReloadController->reload('motion/stats/list');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions www/controllers/Motion/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
class Service
{
private $model;
private $layoutContainerStateController;
private $layoutContainerReloadController;

public function __construct()
{
$this->model = new \Models\Motion\Service();
$this->layoutContainerStateController = new \Controllers\Layout\ContainerState();
$this->layoutContainerReloadController = new \Controllers\Layout\ContainerReload();
}

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ public function stop() : bool
return false;
}

$this->layoutContainerStateController->update('motion/buttons/main');
$this->layoutContainerReloadController->reload('motion/buttons/main');

return true;
}
Expand All @@ -81,7 +81,7 @@ public function start() : bool
return false;
}

$this->layoutContainerStateController->update('motion/buttons/main');
$this->layoutContainerReloadController->reload('motion/buttons/main');

return true;
}
Expand Down
Loading

0 comments on commit 92171df

Please sign in to comment.