-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity.pl
More file actions
79 lines (79 loc) · 2.83 KB
/
Copy pathsecurity.pl
File metadata and controls
79 lines (79 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl
##############################################################
#BouPi
#Version: 1.0 28/03/2016)
#Copyright (c) 2016 Masahito Hayashi
#This software is released under the MIT Licenses:
#https://opensource.org/licenses/mit-license.php
##############################################################
#モジュール読み込み
use strict;
use warnings;
use File::stat;
my $aquestalkpi = '/aquestalkpi/AquesTalkPi -s 70'; #AquesTalkPiのディレクトリとオプション指定
my $targetdir = '/motion'; #キャプチャ画像があるディレクトリ
my $my_no = 'aa:bb:cc:dd:ee:ff'; #Bluetoothデバイス
my $expiretime = 60*60*24*7; #画像を保存する期間:一週間
my $vol_aq = 60; #音声再生時のボリューム
my $blue_count = 0;
my $imgdel_count = 0;
my $file_count = 0;
my $unix_time;
while (1) {
sleep(60);
my $blue_status = `/usr/bin/sudo /usr/bin/hcitool info $my_no 2>&1 | /bin/grep Device`;
my $motion_status = `/usr/bin/pgrep motion`;
#Enable
if ( $blue_status ) {
$blue_count = 0;
if ( $motion_status ) {
#motion停止
system("sudo service motion stop > /dev/null 2>&1");
#画像ファイル操作
opendir(DIR,$targetdir);
my @dir2 = readdir(DIR);
closedir(DIR);
foreach (@dir2) {
my $file = $targetdir."/".$_;
#直近の1分間の画像ファイルを削除・画像ファイル件数読み取り
if ( -f $file and $file =~ /\.(jpg|gif|png)$/i and stat($file)->mtime > time() - 60 ) {
unlink $file;
} elsif ( -f $file and $file =~ /\.(jpg|gif|png)$/i and stat($file)->mtime > $unix_time ) {
$file_count++;
}
}
#音声案内
system("amixer set PCM $vol_aq\% > /dev/null 2>&1 ; $aquestalkpi '防犯システムを解除しました。おかえりなさいませー。' | aplay > /dev/null 2>&1 ; sleep 1");
if ( $file_count ) {
system("amixer set PCM $vol_aq\% > /dev/null 2>&1 ; $aquestalkpi '$file_count件の画像がありました。' | aplay > /dev/null 2>&1");
} else {
system("amixer set PCM $vol_aq\% > /dev/null 2>&1 ; $aquestalkpi '画像ファイルはありませんでした。' | aplay > /dev/null 2>&1");
}
}
}
#Disable
if ( ! $blue_status and ! $motion_status ) {
$blue_count++;
if ( $blue_count > 2 ) {
$unix_time = time();
$file_count = 0;
#motion起動
system("sudo service motion start > /dev/null 2>&1");
#音声案内
system("amixer set PCM $vol_aq\% > /dev/null 2>&1 ; $aquestalkpi '防犯システムを有効にしました。' | aplay > /dev/null 2>&1");
}
}
#img-delete (60分毎)
$imgdel_count++;
if ( $imgdel_count > 60 ) {
opendir(DIR,$targetdir);
my @dir3 = readdir(DIR);
closedir(DIR);
foreach (@dir3) {
my $file = $targetdir."/".$_;
if ( -f $file and $file =~ /\.(jpg|gif|png)$/i and stat($file)->mtime < time() - $expiretime ) { unlink $file; }
}
$imgdel_count = 0;
}
}
exit;