Skip to content

Commit

Permalink
[Merge] Merge branch 'dev' - WebUI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCrypt0 committed May 6, 2019
2 parents e93cb66 + f362c51 commit 4910bcb
Show file tree
Hide file tree
Showing 17 changed files with 1,016 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/static/static/home/yi-hack-v4/etc/system.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ CHECK_UPDATES=yes
DISABLE_CLOUD=no
REC_WITHOUT_CLOUD=no
MQTT=no
RTSP=no
NTPD=no

11 changes: 9 additions & 2 deletions src/static/static/home/yi-hack-v4/script/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ fi
ulimit -s 1024
hostname -F /etc/hostname

sleep 15 && camhash > /tmp/camhash &

if [[ $(get_config DISABLE_CLOUD) == "no" ]] ; then
(
cd /home/app
Expand Down Expand Up @@ -72,6 +70,15 @@ if [[ $(get_config MQTT) == "yes" ]] ; then
mqttv4 &
fi

if [[ $(get_config RTSP) == "yes" ]] ; then
if [[ -f "$YI_HACK_PREFIX/bin/viewd" && -f "$YI_HACK_PREFIX/bin/rtspv4" ]] ; then
viewd -D -S
rtspv4 -D -S
fi
fi

sleep 25 && camhash > /tmp/camhash &

# First run on startup, then every day via crond
$YI_HACK_PREFIX/script/check_update.sh

Expand Down
5 changes: 0 additions & 5 deletions src/www/httpd/cgi-bin/command.sh

This file was deleted.

5 changes: 0 additions & 5 deletions src/www/httpd/cgi-bin/getversion.sh

This file was deleted.

47 changes: 47 additions & 0 deletions src/www/httpd/cgi-bin/rtsp_backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

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

get_action_type()
{
CONF="$(echo $QUERY_STRING | cut -d'=' -f1)"
VAL="$(echo $QUERY_STRING | cut -d'=' -f2)"

if [ $CONF == "action" ] ; then
echo $VAL
fi
}

ACTION_TYPE="$(get_action_type)"
CONF_FILE="$YI_HACK_PREFIX/etc/viewd.conf"

printf "Content-type: application/json\r\n\r\n"

printf "{\n"

if [ $ACTION_TYPE == "getconf" ] ; then

while IFS= read -r LINE ; do
if [ ! -z $LINE ] ; then
if [ "$LINE" == "${LINE#\#}" ] ; then # skip comments
printf "\"%s\",\n" $(echo "$LINE" | sed -r 's/=/":"/g') # Format to json and replace = with ":"
fi
fi
done < "$CONF_FILE"

printf "\"%s\":\"%s\",\n" "VIEWD_FILE" $(ls $YI_HACK_PREFIX/bin/viewd)
printf "\"%s\":\"%s\",\n" "RTSP_FILE" $(ls $YI_HACK_PREFIX/bin/rtspv4)
printf "\"%s\":\"%s\",\n" "LIC_FILE" $(ls $YI_HACK_PREFIX/etc/viewd_*.lic)
printf "\"%s\":\"%s\",\n" "CAMHASH" $(camhash)
printf "\"%s\":\"%s\",\n" "REMOTE_ADDR" $HTTP_HOST

fi

# Empty values to "close" the json
printf "\"%s\":\"%s\"\n" "NULL" "NULL"

printf "}"
32 changes: 32 additions & 0 deletions src/www/httpd/cgi-bin/update_backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

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

REMOTE_VERSION_FILE=/tmp/.hackremotever
REMOTE_NEWVERSION_FILE=/tmp/.hacknewver

LOCAL_VERSION_FILE=/home/yi-hack-v4/version

IS_SD_PRESENT="NO"

if grep -qs '/tmp/sd ' /proc/mounts; then
IS_SD_PRESENT="YES"
fi

printf "Content-type: application/json\r\n\r\n"

printf "{\n"

printf "\"%s\":\"%s\",\n" "LOCAL_VERSION" "$(cat $LOCAL_VERSION_FILE)"
printf "\"%s\":\"%s\",\n" "REMOTE_VERSION" "$(cat $REMOTE_VERSION_FILE)"
printf "\"%s\":\"%s\",\n" "NEEDS_UPDATE" "$(cat $REMOTE_NEWVERSION_FILE)"
printf "\"%s\":\"%s\",\n" "IS_SD_PRESENT" "$IS_SD_PRESENT"

# Empty values to "close" the json
printf "\"%s\":\"%s\"\n" "NULL" "NULL"

printf "}"
95 changes: 95 additions & 0 deletions src/www/httpd/cgi-bin/upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/sh

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

get_file_type()
{
CONF="$(echo $QUERY_STRING | cut -d'=' -f1)"
VAL="$(echo $QUERY_STRING | cut -d'=' -f2)"

if [ $CONF == "file" ] ; then
echo $VAL
fi
}

get_random_tmp_file()
{
local CNT=5
local RND=""
local TMP_FILE=""

while : ; do
RND=$(</dev/urandom tr -dc 0-9 | dd bs=$CNT count=1 2>/dev/null | sed -e 's/^0\+//' )
TMP_FILE="/tmp/.tmpupload.$RND"

[ -f $TMP_FILE ] || break
done

echo $TMP_FILE
}

get_file_from_post()
{
local FILE=$1

local CR=`printf '\r'`

IFS="$CR"
read -r delim_line
IFS=""

while read -r line; do
test x"$line" = x"" && break
test x"$line" = x"$CR" && break
done

cat > "$FILE"

# We need to delete the tail of "\r\ndelim_line--\r\n"
tail_len=$((${#delim_line} + 6))

# Get and check file size
filesize=`ls -l "$FILE" | awk '{print $5}'`

# Truncate the file
dd of="$FILE" seek=$((filesize - tail_len)) bs=1 count=0 >/dev/null 2>/dev/null
}

printf "Content-type: application/json\r\n\r\n"

FILE_TYPE="$(get_file_type)"
TMP_FILE=$(get_random_tmp_file)

CUT_FILE_TYPE=$(echo $FILE_TYPE | cut -d'_' -f1)

if [[ "$CUT_FILE_TYPE" == "home" || "$CUT_FILE_TYPE" == "rootfs" ]] ; then
# If home or rootfs image, place directly on sd card
get_file_from_post "/tmp/sd/$FILE_TYPE"
else
get_file_from_post $TMP_FILE

if [ "$FILE_TYPE" == "rtspv4__upload" ] ; then
7za x "$TMP_FILE" -y -o. &>/dev/null
cp -rf rtspv4__*/* $YI_HACK_PREFIX/
rm -rf rtspv4__*

chmod +x $YI_HACK_PREFIX/bin/viewd
chmod +x $YI_HACK_PREFIX/bin/rtspv4
else
cp -f "$TMP_FILE" "$YI_HACK_PREFIX/$FILE_TYPE"
fi
fi

rm -f $TMP_FILE

printf "{\n"

printf "\"%s\":\"%s\"\n" "error" "false"

printf "}"

exit 0
14 changes: 13 additions & 1 deletion src/www/httpd/htdocs/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ nav ul li.icon { display: none; }
float: right;
}

.align-right {
text-align: right;
}

.inline {
display: inline;
}

.inline-block {
display: inline-block;
}
Expand All @@ -138,8 +146,12 @@ nav ul li.icon { display: none; }
padding-right: 20px;
}

.ios-onclick-fix {
cursor: pointer;
}

table.padded-table tr td {
padding: 10px 10px 9px; !important
padding: 10px 10px 9px;
}

table.padded-table td:first-child {
Expand Down
10 changes: 8 additions & 2 deletions src/www/httpd/htdocs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,20 @@
<li>
<a href="/?page=mqtt">MQTT</a>
</li>
<li>
<a href="/?page=rtsp">RTSP</a>
</li>
<li>
<a href="/?page=update">Update</a>
</li>
<li>
<a href="/?page=about">About</a>
</li>
<li class="nav-elem-right">
<a href="/?page=reboot">Reboot Camera</a>
<a href="/?page=reboot">Reboot</a>
</li>
<li class="icon">
<a class="nav-toggler">&#9776;</a>
<a class="nav-toggler ios-onclick-fix">&#9776;</a>
</li>
</ul>
</div>
Expand Down
37 changes: 36 additions & 1 deletion src/www/httpd/htdocs/js/modules/reboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,55 @@ APP.reboot = (function ($) {
var timeoutVar;

function init() {
rebootCamera();
registerEventHandler();
setStatus("Camera is online.");
}

function registerEventHandler() {
$(document).on("click", '#button-reboot', function (e) {
rebootCamera();
});
}

function rebootCamera() {
$('#button-reboot').attr("disabled", true);
$.ajax({
type: "GET",
url: 'cgi-bin/reboot.sh',
dataType: "json",
error: function(response) {
console.log('error', response);
$('#button-reboot').attr("disabled", false);
},
success: function(data) {
setStatus("Camera is rebooting...");
waitForBoot();
}
});
}

function waitForBoot() {
setInterval(function(){
$.ajax({
url: '/',
success: function(data) {
setStatus("Camera is back online, redirecting to home.");
$('#button-reboot').attr("disabled", false);
window.location.href="/";
},
error: function(data) {
setStatus("Waiting for the camera to come back online...");
},
timeout: 3000,
});
}, 3000);
}

function setStatus(text)
{
$('input[type="text"][data-key="STATUS"]').prop('value', text);
}

return {
init: init
};
Expand Down
Loading

0 comments on commit 4910bcb

Please sign in to comment.