Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable/Disable services from config file (and web interface) #102

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 39 additions & 30 deletions sd/test/equip_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ led() {
kill $(ps | grep led_ctl | grep -v grep | awk '{print $1}')
# then process
/home/led_ctl $@ &

}

LOG_DIR=/home/hd1/test/
Expand Down Expand Up @@ -319,15 +318,18 @@ sync

### Launch FTP server
log "Start ftp server..."
if [[ $(get_config DEBUG) == "yes" ]] ; then
tcpsvd -vE 0.0.0.0 21 ftpd -w / > /${LOG_DIR}/log_ftp.txt 2>&1 &
else
tcpsvd -vE 0.0.0.0 21 ftpd -w / &
fi
sleep 1
log "Check for ftp process : "
ps | grep tcpsvd | grep -v grep >> ${LOG_FILE}
if [[ $(get_config FTP) == "yes" ]] ; then

if [[ $(get_config DEBUG) == "yes" ]] ; then
tcpsvd -vE 0.0.0.0 21 ftpd -w / > /${LOG_DIR}/log_ftp.txt 2>&1 &
else
tcpsvd -vE 0.0.0.0 21 ftpd -w / &
fi
sleep 1

log "Check for ftp process : "
ps | grep tcpsvd | grep -v grep >> ${LOG_FILE}
fi

### Launch web server

Expand All @@ -343,25 +345,29 @@ mount -o bind /home/hd1/record/ /home/hd1/test/http/record/
touch /home/hd1/test/http/motion

# start the server
log "Start http server : server${HTTP_VERSION}..."
if [[ $(get_config DEBUG) == "yes" ]] ; then
./server${HTTP_VERSION} 80 > /${LOG_DIR}/log_http.txt 2>&1 &
else
./server${HTTP_VERSION} 80 &
if [[ $(get_config HTTP) == "yes" ]] ; then

log "Start http server : server${HTTP_VERSION}..."

if [[ $(get_config DEBUG) == "yes" ]] ; then
./server${HTTP_VERSION} 80 > /${LOG_DIR}/log_http.txt 2>&1 &
else
./server${HTTP_VERSION} 80 &
fi
sleep 1
log "Check for http server process : "
ps | grep server | grep -v grep | grep -v log_server >> ${LOG_FILE}
fi
sleep 1
log "Check for http server process : "
ps | grep server | grep -v grep | grep -v log_server >> ${LOG_FILE}

sync



### Launch record event
cd /home
./record_event &
./mp4record 60 &

if [[ $(get_config RECORD) == "yes" ]] ; then
./record_event &
./mp4record 60 &
fi

### Some configuration

Expand Down Expand Up @@ -415,18 +421,21 @@ cd /home

### Rtsp server
cd /home/hd1/test/
log "Start rtsp server : rtspsvr${RTSP_VERSION}..."
if [[ $(get_config DEBUG) == "yes" ]] ; then
./rtspsvr${RTSP_VERSION} > /${LOG_DIR}/log_rtsp.txt 2>&1 &
else
./rtspsvr${RTSP_VERSION} &
if [[ $(get_config RTSP) == "yes" ]] ; then
log "Start rtsp server : rtspsvr${RTSP_VERSION}..."
if [[ $(get_config DEBUG) == "yes" ]] ; then
./rtspsvr${RTSP_VERSION} > /${LOG_DIR}/log_rtsp.txt 2>&1 &
else
./rtspsvr${RTSP_VERSION} &
fi
sleep 1
log "Check for rtsp process : "
ps | grep rtspsvr | grep -v grep >> ${LOG_FILE}
fi
sleep 1
log "Check for rtsp process : "
ps | grep rtspsvr | grep -v grep >> ${LOG_FILE}

sleep 5

cd /tmp/hd1/test/http/interactive
./interactive.sh

### List the processes after startup
log "Processes after startup :"
Expand Down
3 changes: 3 additions & 0 deletions sd/test/http/index.html.tpl_footer
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
</pre>
<div id="iframe"></div>

<script type="text/javascript">
var ip = location.host;
document.getElementById("ip").textContent=ip;
document.getElementById("ch0_0").href="rtsp://"+ip+":554/ch0_0.h264";
document.getElementById("ch0_1").href="rtsp://"+ip+":554/ch0_1.h264";
document.getElementById("ch0_3").href="rtsp://"+ip+":554/ch0_3.h264";
document.getElementById("iframe").innerHTML = "<iframe src='http://" + ip + ":8080'></iframe>";
</script>
</body>
</html>
177 changes: 177 additions & 0 deletions sd/test/http/interactive/interactive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#! /bin/sh

FIRMWARE_LETTER=$(cat /home/version | grep "version=" | head -1 | cut -d"=" -f2 | sed "s/^[0-9]\.[0-9]\.[0-9]\.[0-9]\([A-Z]\).*/\1/")

case ${FIRMWARE_LETTER} in
# 1.8.6.1
A) # NOT TESTTED YET
RTSP_VERSION='M'
HTTP_VERSION='M'
;;

# 1.8.5.1
M) # Tested :)
RTSP_VERSION='M'
HTTP_VERSION='M'
;;

L) # Tested :)
RTSP_VERSION='M'
HTTP_VERSION='M'
;;

K) # NOT TESTED YET
RTSP_VERSION='K'
HTTP_VERSION='M'
;;

B|E|F|H|I|J) # NOT TESTED YET
RTSP_VERSION='I'
HTTP_VERSION='J'
;;

*)
RTSP_VERSION='M'
HTTP_VERSION='M'
log "WARNING : I don't know which RTSP binary version is compliant with your firmware! I will try to use the M..."
;;
esac


get_config() {
key=$1
grep $1 /home/hd1/test/yi-hack.cfg | cut -d"=" -f2
}

contains() {
string="$1"
substring="$2"
if test "${string#*$substring}" != "$string"
then
return 0 # $substring is in $string
else
return 1 # $substring is not in $string
fi
}

ftp() {
RESULT="$(pgrep tcpsvd)"
if [ "${TOGGLE}" = "YES" ]; then
if [ "${RESULT:-null}" = null ]; then
echo "Starting FTP server"
tcpsvd -vE 0.0.0.0 21 ftpd -w / &
STATUS="Starting"
BUTTON="Disable"
else
echo "Closing FTP server"
pkill "tcpsvd"
STATUS="Stopping"
BUTTON="Enable"
fi
else
if [ "${RESULT:-null}" = null ]; then
STATUS="Stopped"
BUTTON="Enable"
else
STATUS="Running"
BUTTON="Disable"
fi
fi
}

rtsp() {
RESULT="$(pgrep rtspsvr)"
if [ "${TOGGLE}" = "YES" ]; then
if [ "${RESULT:-null}" = null ]; then
echo "Starting RTSP server"
../.././rtspsvr${RTSP_VERSION} &
STATUS="Starting"
BUTTON="Disable"
else
echo "Closing RTSP server"
pkill "rtspsvr"
STATUS="Stopping"
BUTTON="Enable"
fi
else
if [ "${RESULT:-null}" = null ]; then
STATUS="Stopped"
BUTTON="Enable"
else
STATUS="Running"
BUTTON="Disable"
fi
fi


}

record() {
RESULT="$(pgrep mp4record)"
if [ "${TOGGLE}" = "YES" ]; then
if [ "${RESULT:-null}" = null ]; then
echo "Starting Motion Recording"
/home/./record_event &
/home/./mp4record 60 &
STATUS="Starting"
BUTTON="Disable"
else
echo "Stopping Motion Recording"
pkill "record_event"
pkill "mp4record"
STATUS="Stopping"
BUTTON="Enable"
fi
else
if [ "${RESULT:-null}" = null ]; then
STATUS="Stopped"
BUTTON="Enable"
else
STATUS="Running"
BUTTON="Disable"
fi
fi
}

STATUS=null
BUTTON=null

# we need to create a redirect page that takes our iframe back to the status page

IP=$(get_config IP)
echo -e "HTTP/1.1 200 OK\r\n" > redirect
echo "<html><head><meta http-equiv='refresh' content='1;url=http://${IP}/interactive/status.html'></meta></head><body>Refreshing...</body></html>" >> redirect


while :
do
# we use netcat to dynamically interact with the camera, we need to regenerate the status page on change
OUTPUT="$(nc -l -p 8080 < redirect)"

echo "<html><head><meta http-equiv='refresh' content='10;url=http://${IP}:8080'></meta></head><body>" > status.html
echo "<table><tr><td>Service</td><td>Status</td><td>Action</td></tr>" >> status.html

TOGGLE=NO
contains "$OUTPUT" "FTP" && TOGGLE=YES

ftp

echo "<tr><td>FTP</td><td>${STATUS}</td><td><a href='http://${IP}:8080/?FTP'><button type="button">${BUTTON}</button></a></td></tr>" >> status.html

TOGGLE=NO
contains "$OUTPUT" "RTSP" && TOGGLE=YES

rtsp

echo "<tr><td>RTSP</td><td>${STATUS}</td><td><a href='http://${IP}:8080/?RTSP'><button type="button">${BUTTON}</button></a></td></tr>" >> status.html

TOGGLE=NO
contains "$OUTPUT" "RECORD" && TOGGLE=YES

record

echo "<tr><td>Recording</td><td>${STATUS}</td><td><a href='http://${IP}:8080/?RECORD'><button type="button">${BUTTON}</button></a><td></td></tr></td></tr>" >> status.html


echo "</body></html>" >> status.html
done
7 changes: 7 additions & 0 deletions sd/test/yi-hack.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ NAMESERVER=192.168.1.254
# - orange : startup
# - blue blinking : configuration
# - blue : configuration finished, camera ready
# - orange blinking : camera unable to ping gateway
# - ??? : color set a few seconds after the camera is ready

# values :
Expand Down Expand Up @@ -40,3 +41,9 @@ NTP_SERVER=0.uk.pool.ntp.org
# Values : yes|no
DEBUG=no

### Services
# Enable/Disable services
HTTP = yes
FTP = yes
RTSP = yes
RECORD = yes