forked from samtap/fang-hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
222 changed files
with
694 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/sh | ||
|
||
HACKS_ENABLED=1 | ||
HACKS_HOME=/media/mmcblk0p2/data | ||
|
||
##################################################### | ||
|
||
logmsg() | ||
{ | ||
echo "$(date) - $0: $1" >> /tmp/hacks.log | ||
echo "$1" | ||
} | ||
|
||
do_patch() | ||
{ | ||
if [ ! -d "$1" ]; then | ||
logmsg "do_patch: \"$1\" must be a directory!" | ||
return 1 | ||
fi | ||
|
||
if [ ! -f "$2" ]; then | ||
logmsg "do_patch: \"$2\" must be a patch file!" | ||
return 1 | ||
fi | ||
|
||
old_cwd=$(pwd) | ||
cd "$1" | ||
patch < "$2" | ||
rc=$? | ||
cd "$old_cwd" | ||
return $rc | ||
} | ||
|
||
# Remove stale log | ||
if [ -f /tmp/hacks.log ]; then | ||
rm /tmp/hacks.log | ||
logmsg "Removed stale logfile" | ||
fi | ||
|
||
logmsg "Executing script (enabled: $HACKS_ENABLED)" | ||
|
||
# Link cgi files again if available (/tmp is volatile) | ||
CGI_FILES="/media/mmcblk0p1/bootstrap/www" | ||
if [ -d "$CGI_FILES" ]; then | ||
for i in $CGI_FILES/*; do | ||
if [ ! -e "/tmp/www/cgi-bin/$(basename $i)" ]; then | ||
logmsg "Linking $i -> /tmp/www/cgi-bin/$(basename $i)" | ||
ln -sf "$i" "/tmp/www/cgi-bin/$(basename $i)" | ||
else | ||
logmsg "Not linking $i: already exists" | ||
fi | ||
done | ||
fi | ||
|
||
if [ $HACKS_ENABLED -ne 1 ]; then | ||
return 0 | ||
fi | ||
|
||
if [ ! -d "$HACKS_HOME" -o ! -f "$HACKS_HOME/etc/profile" ]; then | ||
logmsg "Failed to find hacks in $HACKS_HOME!" | ||
mount /dev/mmcblk0p2 /media/mmcblk0p2 >> /tmp/hacks.log 2>&1 | ||
if [ ! -d "$HACKS_HOME" -o ! -f "$HACKS_HOME/etc/profile" ]; then | ||
logmsg "Failed to find $HACKS_HOME!" | ||
return 1 | ||
fi | ||
else | ||
source "$HACKS_HOME/etc/profile" >/dev/null | ||
fi | ||
|
||
if ! type patch >/dev/null; then | ||
logmsg "Patch command not found! Patches will not be applied." | ||
else | ||
# todo: apply patches? | ||
true | ||
fi | ||
|
||
logmsg "Running startup scripts" | ||
run-parts "$HACKS_HOME/etc/scripts" | ||
logmsg "Finished" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
# Set serial number (MAC address) as default hostname | ||
echo "Set hostname ..." | ||
if [ ! -f /etc/hostname ]; then | ||
echo "iSmartAlarm" > /etc/hostname | ||
fi | ||
/bin/hostname -F /etc/hostname | ||
|
||
ifconfig lo up | ||
|
||
echo 45 > /proc/sys/net/ipv4/tcp_keepalive_time | ||
echo 3 > /proc/sys/net/ipv4/tcp_keepalive_probes | ||
echo 5 > /proc/sys/net/ipv4/tcp_keepalive_intvl | ||
|
||
if [ -x "/etc/fang_hacks.sh" ]; then | ||
sleep 30 | ||
/etc/fang_hacks.sh | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/sh | ||
|
||
if [ $ACTION = "add" ]; then | ||
mkdir -p /media/$MDEV | ||
|
||
grep -w "3" /proc/mmc/pwroff | ||
$status = $? | ||
|
||
if [ ! -x /tmp/mmc.all.log ] || [ $status == 0 ]; then | ||
# sleep 1 | ||
|
||
ps > /tmp/mmc.ps.log | ||
grep -w "lsblk" /tmp/mmc.ps.log | ||
if [ $? == 0 ]; then | ||
echo "1" > /tmp/mmc.ps2.log | ||
exit 0 | ||
fi | ||
|
||
grep -w "1" /proc/mmc/removal | ||
if [ $? == 0 ]; then | ||
exit 0 | ||
fi | ||
|
||
grep -w "1" /proc/mmc/pwroff | ||
if [ $? == 0 ]; then | ||
killall -9 lsblk | ||
exit 0 | ||
fi | ||
|
||
sleep 1 | ||
# ps > /tmp/mmc.ps.log | ||
# grep -w "lsblk" /tmp/mmc.ps.log | ||
# if [ $? == 0 ]; then | ||
# echo "1" > /tmp/mmc.ps2.log | ||
# exit 0 | ||
# fi | ||
|
||
# echo "2" > /tmp/mmc.ps2.log | ||
|
||
echo "0x1" >/proc/mmc/pwroff | ||
lsblk -o KNAME,FSTYPE /dev/mmc* > /tmp/lsblk.log | ||
echo "0x0" >/proc/mmc/pwroff | ||
|
||
grep "mmc" /tmp/lsblk.log > /tmp/mmc.all.log | ||
|
||
grep "vfat" /tmp/mmc.all.log > /tmp/mmc.vfat.log | ||
grep "exfat" /tmp/mmc.all.log > /tmp/mmc.exfat.log | ||
grep "ntfs" /tmp/mmc.all.log > /tmp/mmc.ntfs.log | ||
grep "ext2" /tmp/mmc.all.log > /tmp/mmc.ext2.log | ||
fi | ||
|
||
grep -w $MDEV /tmp/mmc.vfat.log | ||
if [ $? == 0 ]; then | ||
# sleep 1 | ||
grep -w "1" /proc/mmc/removal | ||
if [ $? == 0 ]; then | ||
exit 0 | ||
fi | ||
|
||
mount -t vfat -o rw /dev/$MDEV /media/$MDEV | ||
echo "1" > /tmp/$MDEV | ||
mount -o remount,rw /dev/$MDEV | ||
echo "1" > /tmp/guozhixin | ||
if [ -f /media/$MDEV/snx_autorun.sh ]; then | ||
echo "find snx_autorun.sh" > /dev/console | ||
/media/$MDEV/snx_autorun.sh | ||
fi | ||
exit 0 | ||
fi | ||
|
||
grep -w $MDEV /tmp/mmc.exfat.log | ||
if [ $? == 0 ]; then | ||
mount /dev/$MDEV /media/$MDEV | ||
#mount.exfat-fuse /dev/$MDEV /media/$MDEV | ||
echo "1" > /tmp/$MDEV | ||
mount -o remount,rw /dev/$MDEV | ||
echo "2" > /tmp/guozhixin | ||
if [ -f /media/$MDEV/snx_autorun.sh ]; then | ||
echo "find snx_autorun.sh" > /dev/console | ||
/media/$MDEV/snx_autorun.sh | ||
fi | ||
exit 0 | ||
fi | ||
|
||
grep -w $MDEV /tmp/mmc.ntfs.log | ||
if [ $? == 0 ]; then | ||
ntfs-3g /dev/$MDEV /media/$MDEV | ||
echo "1" > /tmp/$MDEV | ||
#mount -o remount,rw /dev/$MDEV | ||
echo "3" > /tmp/guozhixin | ||
if [ -f /media/$MDEV/snx_autorun.sh ]; then | ||
echo "find snx_autorun.sh" > /dev/console | ||
/media/$MDEV/snx_autorun.sh | ||
fi | ||
exit 0 | ||
fi | ||
|
||
grep -w $MDEV /tmp/mmc.ext2.log | ||
if [ $? == 0 ]; then | ||
mount /dev/$MDEV /media/$MDEV | ||
echo "1" > /tmp/$MDEV | ||
exit 0 | ||
fi | ||
else | ||
umount /dev/$MDEV | ||
rm -rf /media/$MDEV | ||
rm -f /tmp/$MDEV | ||
rm -f /tmp/guozhixin | ||
echo "0x3" >/proc/mmc/pwroff | ||
fi |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/sh | ||
# Source: http://isquared.nl/blog/2008/11/01/Bourne-Bash-Shell-CGI-Scripts/ | ||
|
||
_DEBUG_= | ||
|
||
if [ "${REQUEST_METHOD}" = "POST" ] | ||
then | ||
POST_QUERY_STRING=`dd bs=1 count=${CONTENT_LENGTH} 2>/dev/null` | ||
if [ "${QUERY_STRING}" != "" ] | ||
then | ||
QUERY_STRING=${POST_QUERY_STRING}"&"${QUERY_STRING} | ||
else | ||
QUERY_STRING=${POST_QUERY_STRING}"&" | ||
fi | ||
fi | ||
|
||
#echo "Content-type: text/plain"; echo | ||
|
||
_IFS=${IFS}; IFS=\& | ||
i=0 | ||
for _VAR in ${QUERY_STRING} | ||
do | ||
if [ ${_DEBUG_} ] | ||
then | ||
i=`expr $i + 1`; echo "--- ENTER LOOP $i ---" | ||
echo _VAR: ${_VAR} | ||
echo -n variable: `echo ${_VAR} | cut -d= -f1`" " | ||
echo value: `echo ${_VAR} | cut -d= -f2` | ||
fi | ||
|
||
eval "`echo F_${_VAR} | cut -d= -f1`=`echo ${_VAR} | cut -d= -f2`" | ||
|
||
if [ ${_DEBUG_} ] | ||
then | ||
echo "--- EXIT LOOP $i ---" | ||
fi | ||
done | ||
IFS=${_IFS} | ||
unset i _IFS _VAR | ||
|
||
if [ ${_DEBUG_} ] | ||
then | ||
echo query string: ${QUERY_STRING} | ||
echo post-part of query string: ${POST_QUERY_STRING} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/sh | ||
|
||
echo "Content-type: text/html" | ||
echo "" | ||
|
||
cat << EOF | ||
<html> | ||
<head> | ||
<title>Fang Hacks</title> | ||
<head> | ||
<style type="text/css"> | ||
body { background-color: #B0E0E6; } | ||
.err { color: red; } | ||
.tbl { border-collapse: collapse; border-spacing: 0;} | ||
.tbl th { text-align: left; vertical-align: top; font-weight: bold; padding: 10px 5px; border-style: solid; border-width: 1px; overflow: hidden; word-break: normal; } | ||
.tbl td { padding: 10px 5px; border-style: solid; border-width: 1px; overflow: hidden; word-break: normal; } | ||
</style> | ||
<body> | ||
<pre> | ||
____ ___.__ ___________ | ||
\ \/ /|__|____ ____\_ _____/____ ____ ____ | ||
\ / | \__ \ / _ \| __) \__ \ / \ / ___\ | ||
/ \ | |/ __ \( <_> ) \ / __ \| | \/ /_/ > | ||
/___/\ \|__(____ /\____/\___ / (____ /___| /\___ / | ||
\_/ \/ \/ \/ \//_____/ | ||
___ ___ __ | ||
/ | \_____ ____ | | __ ______ | ||
/ ~ \__ \ _/ ___\| |/ / / ___/ | ||
\ Y // __ \\ \___| < \___ \ | ||
\___|_ /(____ /\___ >__|_ \/____ > | ||
\/ \/ \/ \/ \/ | ||
Version 1.0 | ||
</pre> | ||
<div> | ||
<p> | ||
EOF | ||
HACKS_HOME="/media/mmcblk0p2/data" | ||
if [ -x "/etc/fang_hacks.sh" ]; then | ||
echo "Script is already installed!<br/>" | ||
if [ ! $(mount |grep /media/mmcblk0p2) ]; then | ||
echo "<span class='err'>Error: Nothing is mounted on /media/mmcblk0p2!</span>" | ||
echo "<button title='Try to mount the hacks partition manually' type='button' onClick=\"window.location.href='action?cmd=manual_mount'\">Manual Mount</button>" | ||
echo "<br/>" | ||
elif [ ! -d "$HACKS_HOME" ]; then | ||
echo "<span class='err'>Error: No 'hacks' directory found in /media/mmcblk0p2!</span>" | ||
echo "<br/>" | ||
fi | ||
echo "Apply updates from sd-card?" | ||
echo "<button title='Copy updates from sd-card to device' type='button' onClick=\"window.location.href='action?cmd=update'\">Update</button>" | ||
else | ||
echo "Do you want to apply Xiao Fang hacks?<br/>" | ||
echo "<button title='Copy the fang_hacks.sh script to the device' type='button' onClick=\"window.location.href='action?cmd=apply'\">Apply</button>" | ||
fi | ||
|
||
cat << EOF | ||
</p> | ||
<hr/> | ||
<button title='Start default telnetd on port 23' type='button' onClick="window.location.href='action?cmd=telnetd'">Start rescue telnetd</button> | ||
<button title='Reboot the device' type='button' onClick="window.location.href='action?cmd=reboot'">Reboot</button> | ||
<button title='Manage scripts' type='button' onClick="window.location.href='action?cmd=scripts'">Manage scripts</button> | ||
<button title='Network' type='button' onClick="window.location.href='action?cmd=network'">Network</button> | ||
<button title='View /tmp/hacks.log' type='button' onClick="window.location.href='action?cmd=showlog'">View log</button> | ||
<hr/> | ||
<table class='tbl'> | ||
<tr> | ||
<th>Date:</th> | ||
<td>$(date)</td> | ||
</tr> | ||
<tr> | ||
<th>System uptime:</th> | ||
<td>$(uptime)</td> | ||
</tr> | ||
<tr> | ||
<th>Version:</th> | ||
<td>$(cat /etc/os-release | cut -d'=' -f2)</td> | ||
</tr> | ||
<tr> | ||
<th>Kernel:</th> | ||
<td>$(uname -a)</td> | ||
</tr> | ||
<tr> | ||
<th>Process list:</th> | ||
<td><pre>$(ps)</td> | ||
</tr> | ||
<tr> | ||
<th>Mounts:</th> | ||
<td><pre>$(mount)</td> | ||
</tr> | ||
</table> | ||
</div> | ||
</body> | ||
</html> | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
busybox |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
busybox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
busybox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
busybox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
busybox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
busybox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
busybox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
busybox |
Oops, something went wrong.