Skip to content

VIDEO Camera

wifiBlocker EUROPE edited this page Nov 28, 2024 · 7 revisions

Install motion on iBlocker

Uncomment below line from /etc/apk/repositories

http://dl-cdn.alpinelinux.org/alpine/v3.20/community

Launch apk update

Launch below commands (as root):

apk add build-base v4l-utils autoconf automake bash gettext-dev v4l-utils-dev linux-headers libjpeg-turbo-dev ffmpeg-dev libmicrohttpd-dev libwebp-dev

mkdir /opt/IB/MOTION    - the Motion video records location

Download and unzip motion-release-4.6.0.tar.gz in /home/iblocker/

cd /home/iblocker/motion-release-4.6.0
autoreconf -fiv
./configure
make
make install

-> conf file located in /usr/local/etc/motion

 cp motion-dist.conf motion.conf and adjust the settings with iblocker motion.conf

/usr/local/bin/motion start or stop

As root edit crontab (crontab -e) and add below lines:

# do daily/weekly/monthly maintenance
# min   hour    day     month   weekday command
#*/15    *       *       *       *       /etc/periodic/15min/empty_motion
0       *       *       *       *       /etc/periodic/hourly/empty_motion
0       2       *       *       *       run-parts /etc/periodic/daily
0       3       *       *       6       run-parts /etc/periodic/weekly
0       5       1       *       *       run-parts /etc/periodic/monthly
@reboot /var/www/localhost/cgi-bin/modem/AT/ushubctl-reset-hub.cgi
@reboot /var/www/localhost/cgi-bin/piwall/camera.cgi &
@reboot /var/www/localhost/cgi-bin/piwall/check_ssh_tunnel.cgi &
@reboot /var/www/localhost/cgi-bin/modem/AT/Read_SMS_Daemon.cgi &
@reboot /var/www/localhost/cgi-bin/modem/AT/Usb0-Reboot-Daemon.cgi &

Save and exit.

or add below command in crontab (instead of check_ssh_tunnel script):

@reboot autossh -M 0 -q -i /home/iblocker/.ssh/id_ed25519 iblocker@8x.ab4.17z.22x -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 80xy:localhost:8081 &

iBlocker is configured for an USB camera: a daemon will automatically detect it and use it via motion. Used port for video is 8081.

motion.conf settings below:

daemon on
setup_mode off
; pid_file value
; log_file value
log_level 6
; target_dir value
target_dir /opt/IB/MOTION
videodevice /dev/video0
; vid_control_params value
; netcam_url value
; mmalcam_name value
; mmalcam_control_params value
width 1280
height 720
framerate 30
text_left CAMERA1
text_right %Y-%m-%d\n%T-%q
emulate_motion off
threshold 5000
; noise_level 32
despeckle_filter EedDl
minimum_motion_frames 1
event_gap 60
pre_capture 3
post_capture 5
; on_event_start value
; on_event_end value
; on_movie_end value
picture_output off
picture_filename %Y%m%d%H%M%S-%q
movie_output on
movie_max_time 60
movie_quality 100
movie_codec mpeg4
movie_filename %t-%v-%Y%m%d%H%M%S
webcontrol_port 8080
webcontrol_localhost off
webcontrol_parms 0
stream_port 8081
stream_localhost off
stream_quality 40
stream_maxrate 20
; camera /usr/etc/motion/camera1.conf
; camera /usr/etc/motion/camera2.conf
; camera /usr/etc/motion/camera3.conf
; camera /usr/etc/motion/camera4.conf
; camera_dir /usr/etc/motion/conf.d
movie_passthrough on

To restrict access to camera with user/password, add below lines to /usr/local/etc/motion/motion.conf and reboot.

stream_auth_method 1
stream_authentication user:password

Camera resolutions (width x height):

640 x 360
960 x 544
1280 x 720
1920 x 1080
3840 x 1080
4800 x 1200

Port 8081 SSH Tunneling from iblocker to a public server

Add user iblocker to group root:

~# adduser iblocker root

As user=iblocker generate public/private rsa key pair

~$ ssh-keygen -b 4096

Note: Leave password blank

You will need to copy id_*.pub file from iblocker /home/autossh/.ssh/ to the /home/iblocker/.ssh/authorized_keys file on the remote system you want to connect to for the tunnel - 8x.ab4.17z.22x.

or

ssh-copy-id -i /home/iblocker/.ssh/id_ed25519 iblocker@8x.ab4.17z.22x 

Make a test connection: ~$ ssh iblocker@8x.ab4.17z.22x
The authenticity of host '8x.ab4.17z.22x (8x.ab4.17z.22x)' can't be established. ED25519 key fingerprint is SHA256:fjuh8QWIkAXQblablablabla. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes ~$ exit

Create SSH tunnel:

ssh -f -N -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o ExitOnForwardFailure=yes -R 80xy:localhost:8081 iblocker@8x.ab4.17z.22x -i /home/iblocker/.ssh/id_ed25519   - creates a SSH tunnel

As iblocker edit crontab (crontab -e) and add below line:

@reboot ssh -f -N -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o ExitOnForwardFailure=yes -R 80xy:localhost:8081 iblocker@8x.ab4.17z.22x -i /home/iblocker/.ssh/id_ed25519 &

Save and exit.

pgrep -f 8081 - returns Process_ID for the SSH tunnel

The command - kill -9 pgrep -f 8081 - will stop the SSH tunnel created on port 8081

On server 8x.ab4.17z.22x, change below lines from /etc/sshd_config:

AllowTcpForwarding yes
GatewayPorts yes

then systemctl ssh.service restart

Then on server 8x.ab4.17z.22x, port 8081 is open and could be accessed as http://8x.ab4.17z.22x:8081

Explanation of ssh -f -N -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o ExitOnForwardFailure=yes -R 8081:localhost:8081 iblocker@8x.ab4.17z.22x:

  • -N - Do not execute a remote command; this is useful for just forwarding ports.

  • ServerAliveInterval - the number of seconds that the client will wait before sending a "server alive" message to the server to keep the connection alive.

  • ServerAliveCountMax - the number of "server alive" messages which may be sent without reply from the server. If this threshold is reached ssh will disconnect from the server, terminating the session.

  • ExitOnForwardFailure - if set to "yes", the connection shall be terminated if ssh cannot set up all requested dynamic, tunnel, local, and remote port forwardings, (e.g. if either end is unable to bind and listen on a specified port).

  • -R 8080:localhost:80 - Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side. In this case, it means forward port 80 of the remote server to port 8080 of the client.

e.g. Open SSH to iBlocker on port 2022:

ssh -f -N -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o ExitOnForwardFailure=yes -R 2022:localhost:22 iblocker@8x.ab4.17z.22x

Then ssh iblocker@8x.ab4.17z.22x


Delete Motion movies

Create a script (empty_motion.sh, chmod 755 empty_motion.sh) in /etc/periodic/hourly.

Script should contain one line (outside #!/bin/sh):

  1. Delete files older than 12 hours:
find /opt/IB/MOTION/ -name "*" -type f -mmin +720 -delete
  1. Delete files older than 1 day:
find  /opt/IB/MOTION/ -name "*" -type f -mtime +1 -delete
  1. As root use crontab -e and add below lines:
# do daily/weekly/monthly maintenance
# min   hour    day     month   weekday command
#*/15    *       *       *       *       /etc/periodic/15min/empty_motion
0       *       *       *       *       /etc/periodic/hourly/empty_motion
0       2       *       *       *       run-parts /etc/periodic/daily
0       3       *       *       6       run-parts /etc/periodic/weekly
0       5       1       *       *       run-parts /etc/periodic/monthly
@reboot /var/www/localhost/cgi-bin/modem/AT/ushubctl-reset-hub.cgi
@reboot /var/www/localhost/cgi-bin/piwall/camera.cgi &
@reboot /var/www/localhost/cgi-bin/piwall/check_ssh_tunnel.cgi &
@reboot /var/www/localhost/cgi-bin/modem/AT/Read_SMS_Daemon.cgi &
@reboot /var/www/localhost/cgi-bin/modem/AT/Usb0-Reboot-Daemon.cgi &

Note: empty_motion.sh is added without extension in crontab.

--------//-------------

and restart cron:

 rc-service crond restart

Clone this wiki locally