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 8, 2024
1 parent 51c2a3c commit f65fee9
Show file tree
Hide file tree
Showing 57 changed files with 1,017 additions and 347 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
10 changes: 10 additions & 0 deletions docker/config/nginx/motionui.conf
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,14 @@ server {
location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
access_log off;
}

# Websocket server
location /ws {
proxy_pass http://127.0.0.1:8081;
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;
}
}
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) {
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();
}
}
24 changes: 12 additions & 12 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 @@ -136,8 +136,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 f65fee9

Please sign in to comment.