Skip to content

Commit

Permalink
Adding Alarm functionality (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank van der Stad committed Jan 8, 2018
1 parent 51c2b43 commit 2782048
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/home/yi-hack-v3/etc/system.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ HTTPD=yes
TELNETD=no
FTPD=yes
DROPBEAR=yes
ALARM=no
50 changes: 50 additions & 0 deletions src/home/yi-hack-v3/script/alarm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

# Copyright 2018 Vladimir Dronnikov
# Additional enhancements: Frank van der Stad
# GPL

CONF_FILE="/yi-hack-v3/etc/system.conf"

if [ -d "/usr/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/usr"
elif [ -d "/home/yi-hack-v3" ]; then
YI_HACK_V3_PREFIX="/home"
fi

get_config()
{
key=$1
grep $1 $YI_HACK_V3_PREFIX$CONF_FILE | cut -d "=" -f2
}

TELEGRAM_BOT_TOKEN=$(get_config TELEGRAM_BOT_TOKEN)
TELEGRAM_CHAT_ID=$(get_config TELEGRAM_CHAT_ID)
TELEGRAM_SILENT=0

CAMERA_NAME=`more $YI_HACK_V3_PREFIX/yi-hack-v3/etc/hostname`;

curl() {
LD_LIBRARY_PATH=/tmp/sd /tmp/sd/curl -k -q $@
}

photo() {
cp $1 /tmp/sd/record/last.jpg
curl -F photo="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendPhoto?chat_id=${TELEGRAM_CHAT_ID}&caption=$2&disable_notification=${TELEGRAM_SILENT}"
}

video() {
curl -F video="@$1" "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendVideo?chat_id=${TELEGRAM_CHAT_ID}&caption=$2&disable_notification=${TELEGRAM_SILENT}"
}

ALARM=0
while true; do
test -r /tmp/sd/record/tmp.mp4.tmp && REC=1 || REC=0
if [ "$REC" != "$ALARM" ]; then
ALARM="$REC"
[ "n$ALARM" == "n0" ] && rm /tmp/temp.jpg /tmp/temp.mp4
fi
[ -r /tmp/motion.jpg -a ! -r /tmp/temp.jpg ] && cp /tmp/motion.jpg /tmp/temp.jpg && echo JPG ready && photo /tmp/temp.jpg "Photo from $CAMERA_NAME"
[ -r /tmp/motion.mp4 -a ! -r /tmp/temp.mp4 ] && cp /tmp/motion.mp4 /tmp/temp.mp4 && echo MP4 ready && video /tmp/temp.mp4 "Video from $CAMERA_NAME"
sleep 1
done
7 changes: 7 additions & 0 deletions src/home/yi-hack-v3/script/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ if [ -f "/tmp/sd/yi-hack-v3/startup.sh" ]; then
elif [ -f "/home/hd1/yi-hack-v3/startup.sh" ]; then
/home/hd1/yi-hack-v3/startup.sh
fi

if [[ $(get_config ALARM) == "yes" ]] ; then
if [ -f "/home/yi-hack-v3/script/alarm.sh" ]; then
sh /home/yi-hack-v3/script/alarm.sh &
fi
fi

25 changes: 14 additions & 11 deletions src/home/yi-hack-v3/www/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<div class="page-header">
<h1>About yi-hack-v3</h1>
</div>

<p>Yi-hack-v3 unlocks features not available with the official Yi camera firmware. Features implemented include:</p>
<ul>
<li>Telnet Server</li>
Expand All @@ -66,7 +66,7 @@ <h1>About yi-hack-v3</h1>
<li>Yi Dome</li>
<li>Yi 1080p Dome</li>
</ul>

<h2>Version</h2>
<dl class="dl-horizontal">
<dt>Camera</dt>
Expand All @@ -76,10 +76,13 @@ <h2>Version</h2>
<dt>yi-hack-v3 Firmware</dt>
<dd><div class=hack_version></div></dd>
</dl>

<h2>More Information</h2>
<a href="https://github.com/shadow-1/yi-hack-v3">https://github.com/shadow-1/yi-hack-v3</a>


<h2>Last picture/video</h2>
<img src="img/last.jpg" alt="Last" class="img-thumbnail">

</div>

<!-- Bootstrap core JavaScript
Expand Down Expand Up @@ -120,7 +123,7 @@ <h2>More Information</h2>
}

/* yi-hack-v3_info protocol */

var socket_info;

if (typeof MozWebSocket != "undefined") {
Expand All @@ -134,7 +137,7 @@ <h2>More Information</h2>
try {
socket_info.onopen = function() {
init();
}
}

socket_info.onmessage = function got_packet(msg) {
jso = JSON.parse(msg.data);
Expand All @@ -147,25 +150,25 @@ <h2>More Information</h2>
for (var i = 0, max = CameraElements.length; i < max; i++) {
CameraElements[i].textContent = jso.camera;
}

document.getElementsByClassName("base_version")[0].textContent = jso.base_version;
document.getElementsByClassName("hack_version")[0].textContent = jso.hack_version;
}
}
}

socket_info.onclose = function(){

}
} catch(exception) {
alert('<p>Error' + exception);
alert('<p>Error' + exception);
}

function init() {
socket_info.send("SEND_CAM_INFO\n");
}

</script>

</body>

</html>
64 changes: 46 additions & 18 deletions src/home/yi-hack-v3/www/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,30 @@ <h1>System Configuration</h1>
<input type="text" class="form-control" id="hostname_text">
</div>

<hr/>
<div class="form-group">
<label class="col-sm-3 control-label">Alarm Enabled</label>
<label class="radio-inline">
<input type="radio" name="ALARM" id="ALARM_yes" value="yes"> Yes
</label>
<label class="radio-inline">
<input type="radio" name="ALARM" id="ALARM_no" value="no"> No
</label>
</div>
<div class="form-group form-inline">
<label class="col-sm-3 control-label">TELEGRAM_BOT_TOKEN</label>
<input type="text" class="form-control" id="TELEGRAM_BOT_TOKEN_text">
</div>
<div class="form-group form-inline">
<label class="col-sm-3 control-label">TELEGRAM_CHAT_ID</label>
<input type="text" class="form-control" id="TELEGRAM_CHAT_ID_text">
</div>

<div class="button-wrapper">
<input class="btn btn-primary" id="apply" type="submit" value="Apply">
</div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
Expand All @@ -121,7 +140,7 @@ <h1>System Configuration</h1>
<script src="/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="/js/ie10-viewport-bug-workaround.js"></script>

<script>

document.getElementById('apply').onclick = apply;
Expand Down Expand Up @@ -154,7 +173,7 @@ <h1>System Configuration</h1>
}

/* yi-hack-v3_info protocol */

var socket_info;

if (typeof MozWebSocket != "undefined") {
Expand All @@ -168,16 +187,18 @@ <h1>System Configuration</h1>
try {
socket_info.onopen = function() {
init();
}
}

socket_info.onmessage = function got_packet(msg) {
jso = JSON.parse(msg.data);

if (jso.message == "SEND_CAM_INFO") {
document.title = jso.camera;

document.getElementsByClassName("camera")[0].textContent = jso.camera;
document.getElementById("hostname_text").value = jso.hostname;
document.getElementById("TELEGRAM_BOT_TOKEN_text").value = jso.TELEGRAM_BOT_TOKEN;
document.getElementById("TELEGRAM_CHAT_ID_text").value = jso.TELEGRAM_CHAT_ID;
} else if (jso.message == "SEND_CONFIG") {
if (jso.proxychainsng_enabled == "yes") {
document.getElementById("PROXYCHAINSNG_yes").checked = true;
Expand Down Expand Up @@ -208,6 +229,12 @@ <h1>System Configuration</h1>
} else if (jso.dropbear_enabled == "no") {
document.getElementById("DROPBEAR_no").checked = true;
}

if (jso.alarm_enabled == "yes") {
document.getElementById("ALARM_yes").checked = true;
} else if (jso.alamr_enabled == "no") {
document.getElementById("ALARM_no").checked = true;
}
} else if (jso.message == "SEND_NOTIFICATION") {
var message;

Expand All @@ -228,13 +255,13 @@ <h1>System Configuration</h1>
break;
}
}
}
}

socket_info.onclose = function(){

}
} catch(exception) {
alert('<p>Error' + exception);
alert('<p>Error' + exception);
}

function init() {
Expand All @@ -250,38 +277,39 @@ <h1>System Configuration</h1>
var telnetd_enabled;
var ftpd_enabled;
var dropbear_enabled;
var alarm_enabled;

if (document.getElementById("PROXYCHAINSNG_yes").checked == true) {
proxychainsng_enabled = "yes";
} else {
proxychainsng_enabled = "no";
}

if (document.getElementById("HTTPD_yes").checked == true) {
httpd_enabled = "yes";
} else {
httpd_enabled = "no";
}

if (document.getElementById("TELNETD_yes").checked == true) {
telnetd_enabled = "yes";
} else {
telnetd_enabled = "no";
}

if (document.getElementById("FTPD_yes").checked == true) {
ftpd_enabled = "yes";
} else {
ftpd_enabled = "no";
}

if (document.getElementById("DROPBEAR_yes").checked == true) {
dropbear_enabled = "yes";
} else {
dropbear_enabled = "no";
}
message = "SAVE_CONFIG\nproxychainsng_enabled=" + proxychainsng_enabled + "\nhttpd_enabled=" + httpd_enabled + "\ntelnetd_enabled=" + telnetd_enabled + "\nftpd_enabled=" + ftpd_enabled + "\ndropbear_enabled=" + dropbear_enabled + "\nhostname=" + document.getElementById("hostname_text").value;
if (document.getElementById("ALARM_yes").checked == true) {
alarm_enabled = "yes";
} else {
alarm_enabled = "no";
}

message = "SAVE_CONFIG\nproxychainsng_enabled=" + proxychainsng_enabled + "\nhttpd_enabled=" + httpd_enabled + "\ntelnetd_enabled=" + telnetd_enabled + "\nftpd_enabled=" + ftpd_enabled + "\ndropbear_enabled=" + dropbear_enabled + "\nalamr_enabled=" + alarm_enabled + "\nhostname=" + document.getElementById("hostname_text").value + "\TELEGRAM_BOT_TOKEN=" + document.getElementById("TELEGRAM_BOT_TOKEN_text").value + "\TELEGRAM_CHAT_ID=" + document.getElementById("TELEGRAM_BOT_TOKEN_text").value;

socket_info.send(message);
}
Expand Down

0 comments on commit 2782048

Please sign in to comment.