Skip to content

Commit

Permalink
[New] WebUI Pre-Release install & Minor Wording Change
Browse files Browse the repository at this point in the history
  • Loading branch information
alienatedsec committed Jul 20, 2023
1 parent 24af7d0 commit 7a743ef
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 14 deletions.
85 changes: 80 additions & 5 deletions src/www/httpd/cgi-bin/fw_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
YI_HACK_PREFIX="/tmp/sd/yi-hack-v5"
MODEL_SUFFIX=`cat /home/app/.camver`
FW_VERSION=`cat /tmp/sd/yi-hack-v5/version`
BASELINE_VERSION=`cat /home/yi-hack-v5/version`

export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/home/base/tools:/home/app/localbin:/home/base:/tmp/sd/yi-hack-v5/bin:/tmp/sd/yi-hack-v5/sbin:/tmp/sd/yi-hack-v5/usr/bin:/tmp/sd/yi-hack-v5/usr/sbin
export LD_LIBRARY_PATH=/lib:/usr/lib:/home/lib:/home/qigan/lib:/home/app/locallib:/tmp/sd:/tmp/sd/gdb:/tmp/sd/yi-hack-v5/lib
Expand All @@ -19,15 +20,16 @@ if [ "$VAL" == "info" ] ; then
printf "Content-type: application/json\r\n\r\n"

FW_VERSION=`cat /tmp/sd/yi-hack-v5/version`
LATEST_FW=`/usr/bin/wget -O - https://api.github.com/repos/alienatedsec/yi-hack-v5/releases/latest 2>&1 | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`

LATEST_FW=`/usr/bin/wget -O - https://api.github.com/repos/alienatedsec/yi-hack-v5/releases/latest 2>&1 | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`
PRERELEASE_FW=`/usr/bin/wget -O - https://api.github.com/repos/alienatedsec/yi-hack-v5/releases 2>&1 | grep -B 4 '"prerelease": true' | awk -F '"' '{print $4; exit}'`

printf "{\n"
printf "\"%s\":\"%s\",\n" "fw_version" "$FW_VERSION"
printf "\"%s\":\"%s\"\n" "latest_fw" "$LATEST_FW"
printf "\"%s\":\"%s\",\n" "fw_version" "$FW_VERSION"
printf "\"%s\":\"%s\",\n" "latest_fw" "$LATEST_FW"
printf "\"%s\":\"%s\"\n" "prerelease_fw" "$PRERELEASE_FW"
printf "}"

elif [ "$VAL" == "upgrade" ] ; then

FREE_SD=$(df /tmp/sd/ | grep mmc | awk '{print $4}')
if [ -z "$FREE_SD" ]; then
printf "Content-type: text/html\r\n\r\n"
Expand Down Expand Up @@ -89,9 +91,82 @@ elif [ "$VAL" == "upgrade" ] ; then
printf "Content-type: text/html\r\n\r\n"
printf "Download completed, rebooting and upgrading."

sync
sync
sync
sleep 1
reboot

elif [ "$VAL" == "preupgrade" ] ; then
FREE_SD=$(df /tmp/sd/ | grep mmc | awk '{print $4}')
if [ -z "$FREE_SD" ]; then
printf "Content-type: text/html\r\n\r\n"
printf "No SD detected."
exit
fi

if [ $FREE_SD -lt 100000 ]; then
printf "Content-type: text/html\r\n\r\n"
printf "No space left on SD."
exit
fi

# Clean old upgrades
rm -rf /tmp/sd/${MODEL_SUFFIX}
rm -rf /tmp/sd/${MODEL_SUFFIX}.conf
rm -rf /tmp/sd/Factory
rm -rf /tmp/sd/newhome
rm /tmp/sd/rootfs*
rm /tmp/sd/home*

mkdir -p /tmp/sd/${MODEL_SUFFIX}
mkdir -p /tmp/sd/${MODEL_SUFFIX}.conf
# cd /tmp/sd/${MODEL_SUFFIX}
cd /tmp/sd

if [ -f /tmp/sd/${MODEL_SUFFIX}_x.x.x.tgz ]; then
# mv /tmp/sd/${MODEL_SUFFIX}_x.x.x.tgz /tmp/sd/${MODEL_SUFFIX}/${MODEL_SUFFIX}_x.x.x.tgz
PRERELEASE_FW="x.x.x"
else
PRERELEASE_FW=`/usr/bin/wget -O - https://api.github.com/repos/alienatedsec/yi-hack-v5/releases 2>&1 | grep -B 4 '"prerelease": true' | awk -F '"' '{print $4; exit}'`
if [ "$FW_VERSION" == "$PRERELEASE_FW" ]; then
printf "Content-type: text/html\r\n\r\n"
printf "No new firmware available."
exit
elif [ "$BASELINE_VERSION" != "0.3.8" ]; then
printf "Content-type: text/html\r\n\r\n"
printf "Wrong baseline version"
exit
fi

/usr/bin/wget https://github.com/alienatedsec/yi-hack-v5/releases/download/$PRERELEASE_FW/${MODEL_SUFFIX}_${PRERELEASE_FW}.tgz

if [ ! -f ${MODEL_SUFFIX}_${PRERELEASE_FW}.tgz ]; then
printf "Content-type: text/html\r\n\r\n"
printf "Unable to download firmware file."
exit
fi
fi

# Backup configuration
cp -rf $YI_HACK_PREFIX/etc/* /tmp/sd/${MODEL_SUFFIX}.conf/
rm /tmp/sd/${MODEL_SUFFIX}.conf/*.tar.gz

# Prepare new hack
gzip -d ${MODEL_SUFFIX}_${PRERELEASE_FW}.tgz
tar xvf ${MODEL_SUFFIX}_${PRERELEASE_FW}.tar
rm ${MODEL_SUFFIX}_${PRERELEASE_FW}.tar
mkdir -p /tmp/sd/${MODEL_SUFFIX}/yi-hack-v5/etc
cp -rf /tmp/sd/${MODEL_SUFFIX}.conf/* /tmp/sd/${MODEL_SUFFIX}/yi-hack-v5/etc/

# Report the status to the caller
printf "Content-type: text/html\r\n\r\n"
printf "Download completed, rebooting and upgrading."

sync
sync
sync
sleep 1
reboot
fi

2 changes: 2 additions & 0 deletions src/www/httpd/cgi-bin/status.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ printf "Content-type: application/json\r\n\r\n"
NAME="yi-hack-v5"
HOSTNAME=$(hostname)
FW_VERSION=$(cat /tmp/sd/yi-hack-v5/version)
BASEFW_VERSION=$(cat /home/yi-hack-v5/version)
HOME_VERSION=$(cat /home/app/.appver)
MODEL_SUFFIX=$(cat /home/app/.camver)
if [[ $MODEL_SUFFIX == "yi_dome_1080p" ]] || [[ $MODEL_SUFFIX == "yi_cloud_dome_1080p" ]] ; then
Expand Down Expand Up @@ -45,6 +46,7 @@ printf "{\n"
printf "\"%s\":\"%s\",\n" "name" "$NAME"
printf "\"%s\":\"%s\",\n" "hostname" "$HOSTNAME"
printf "\"%s\":\"%s\",\n" "fw_version" "$FW_VERSION"
printf "\"%s\":\"%s\",\n" "basefw_version" "$BASEFW_VERSION"
printf "\"%s\":\"%s\",\n" "home_version" "$HOME_VERSION"
printf "\"%s\":\"%s\",\n" "model_suffix" "$MODEL_SUFFIX"
printf "\"%s\":\"%s\",\n" "hardware_id" $HARDWARE_ID
Expand Down
62 changes: 56 additions & 6 deletions src/www/httpd/htdocs/js/modules/maintenance.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ APP.maintenance = (function($) {
registerEventHandler();
setRebootStatus("Camera is online.");
getFwStatus();
getPreFwStatus();
}

function registerEventHandler() {
Expand All @@ -26,6 +27,9 @@ APP.maintenance = (function($) {
$(document).on("click", '#button-upgrade', function(e) {
upgradeFirmware();
});
$(document).on("click", '#button-preupgrade', function(e) {
preupgradeFirmware();
});
}

function saveConfig() {
Expand Down Expand Up @@ -140,29 +144,53 @@ APP.maintenance = (function($) {
},
success: function(response) {
setFwStatus(response);
waitForUpgrade();
waitForUpgrade("button-upgrade");
}
});
}

function waitForUpgrade() {

function preupgradeFirmware() {
$('#button-preupgrade').attr("disabled", true);
setPreFwStatus("Pre-Release Firmware download in progress.");
$.ajax({
type: "GET",
url: 'cgi-bin/fw_upgrade.sh?get=preupgrade',
error: function(response) {
console.log('error', response);
$('#button-preupgrade').attr("disabled", false);
},
success: function(response) {
setPreFwStatus(response);
waitForUpgrade("button-preupgrade");
}
});
}

function waitForUpgrade(buttonType) {
setInterval(function() {
$.ajax({
url: 'index.html',
cache: false,
success: function(data) {
setFwStatus("Camera is upgrading.");
$('#button-upgrade').attr("disabled", false);
if (buttonType === "button-upgrade") {
setFwStatus("Camera is upgrading.");
} else if (buttonType === "button-preupgrade") {
setPreFwStatus("Pre-upgrade in progress...");
}

$('#' + buttonType).attr("disabled", false);
window.location.href = "index.html";
},
error: function(data) {
setFwStatus("Waiting for the camera to come back online...");
setPreFwStatus("Waiting for the camera to come back online...");
},
timeout: 3000,
});
}, 5000);
}


function setRebootStatus(text) {
$('input[type="text"][data-key="STATUS"]').prop('value', text);
}
Expand All @@ -174,6 +202,10 @@ APP.maintenance = (function($) {
function setFwStatus(text) {
$('input[type="text"][data-key="FW"]').prop('value', text);
}

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

function getFwStatus() {
$.ajax({
Expand All @@ -192,7 +224,25 @@ APP.maintenance = (function($) {
}
});
}


function getPreFwStatus() {
$.ajax({
type: "GET",
url: 'cgi-bin/fw_upgrade.sh?get=info',
dataType: "json",
error: function(response) {
console.log('error', response);
setPreFwStatus("Error getting fw info");
},
success: function(data) {
setPreFwStatus("Installed: " + data.fw_version + " - Available: " + data.prerelease_fw);
if (data.fw_version == data.prelease_fw) {
$('#button-preupgrade').attr("disabled", true);
}
}
});
}

return {
init: init
};
Expand Down
23 changes: 20 additions & 3 deletions src/www/httpd/htdocs/pages/maintenance.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h5 class="tiny-margin strong">Reboot</h5>
</tbody>
</table>

<h5 class="tiny-margin strong">Reset to yi-hack default</h5>
<h5 class="tiny-margin strong">Reset to YI-HACK-V5 defaults</h5>
<hr class="no-margin"/>

<table class="u-full-width padded-table">
Expand All @@ -69,7 +69,7 @@ <h5 class="tiny-margin strong">Reset to yi-hack default</h5>
</tbody>
</table>

<h5 class="tiny-margin strong">Online FW upgrade</h5>
<h5 class="tiny-margin strong">Latest FW upgrade</h5>
<hr class="no-margin"/>

<table class="u-full-width padded-table">
Expand All @@ -79,10 +79,27 @@ <h5 class="tiny-margin strong">Online FW upgrade</h5>
<input class="u-full-width" type="text" placeholder="" readonly="" data-key="FW" id="FW"/>
</td>
<td>
<input class="button-primary" type="button" id="button-upgrade" value="Upgrade Firmware"/>
<input class="button-primary" type="button" id="button-upgrade" value="Upgrade to Latest"/>
</td>
</tr>
</tbody>
</table>

<h5 class="tiny-margin strong">Pre-Release FW upgrade</h5>
<hr class="no-margin"/>

<table class="u-full-width padded-table">
<tbody>
<tr class="row">
<td>
<input class="u-full-width" type="text" placeholder="" readonly="" data-key="PREFW" id="PREFW"/>
</td>
<td>
<input class="button-primary" type="button" id="button-preupgrade" value="Upgrade to Pre-Release"/>
</td>
</tr>
</tbody>
</table>

</div>
</div>
4 changes: 4 additions & 0 deletions src/www/httpd/htdocs/pages/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ <h5 class="tiny-margin strong">System</h5>
<td>Firmware Version</td>
<td id="fw_version"></td>
</tr>
<tr>
<td>Baseline Firmware Version</td>
<td id="basefw_version"></td>
</tr>
<tr>
<td>Base Version</td>
<td id="home_version"></td>
Expand Down

0 comments on commit 7a743ef

Please sign in to comment.