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

add support on web interface to power off, configure rtsp server #200

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions bootstrap/www/action
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ if [ -n "$F_cmd" ]; then
echo "Rebooting device...<br/>"
/sbin/reboot
;;
poweroff)
echo "Powering off...<br/>"
/sbin/poweroff
;;
telnetd)
echo "Starting default telnetd (port 23)...<br/>"
start_telnetd
Expand Down
73 changes: 73 additions & 0 deletions bootstrap/www/cfg_rtsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/sh

echo "Content-type: text/html"
echo ""

CMDLINE="`grep -m 1 "_server" /media/mmcblk0p2/data/etc/scripts/20-rtsp-server`"

cat << EOF

<html>
<head>
<title>Fang Hacks</title>
<style type="text/css">
body { background-color: #B0E0E6; font-family: verdana, sans-serif; }
.err { color: red; }
hr { height: 1px; border: 0; border-top: 1px solid #aaa; }
button, input[type=submit] { background-color: #ddeaff; }
.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>
<head>
<body>
<h1>Configure RTSP</h1>
<hr/>
<button title='Status page' type='button' onClick="window.location.href='status'">Status</button>
<button title='Reboot the device' type='button' onClick="window.location.href='action?cmd=reboot'">Reboot</button>
<button title='Info' type='button' onClick="window.location.href='scripts'">Scripts</button>
<button title='View /tmp/hacks.log' type='button' onClick="window.location.href='action?cmd=showlog'">View log</button>
<button title='Network' type='button' onClick="window.location.href='network'">Network</button>
<hr/>
<div style='clear: both;'>
<form action="cfg_rtsp_save" id="textformid" method="get">
Command line: <input type="text" name="name" size="100" value="$CMDLINE"></input><br>
<input type="submit" />
</form>
<pre>Command line options:
Availability of some options depends on the program/version that is installed
-A username:password: username and password for authentication
-Q length: Number of frame queue (default 10)
ZXF options :
-D frame delay: Number of frames to delay (default 0)
-R record thresh: Motion detection threshold to record (default -1, <0 for off)
-L record length: Number of frames to record per file (must be >= 10*fps)
-B record buffer: Number of frames to record prior to motion (must be <= 60)
RTSP options :
-u url : unicast url (default unicast)
-m url : multicast url (default multicast)
-M addr : multicast group (default is a random address)
-P port : RTSP port (default 554)
-T port : RTSP over HTTP port (default 0)
V4L2 options :
-F fps : V4L2 capture framerate (default 30)
-i isp_fps : ISP capture framerate (default 30)
-W width : V4L2 capture width (default 1280)
-H height : V4L2 capture height (default 720)
V4L2 H264 options :
-b bitrate : V4L2 capture bitrate kbps(default 1024 kbps)
-g gop : V4L2 capture gop (default 30 )
device : V4L2 capture device (default /dev/video1)
V4L2 MJPEG options :
-j mjpeg_qp : MJPEG streaming and qp (default is 60)
-c capture path enable (default is disable)
-s encoder scale (1/2/4) (default is 1)
-a : enable A-law pcm streaming</pre>
EOF
#note: to display command line options, following works in shell but does not work in script, needs to be improved
#eval "$(grep -m 1 "_server" /media/mmcblk0p2/data/etc/scripts/20-rtsp-server | awk '{ print $1 }') -h"
cat << EOF
</div>
</body>
</html>
EOF
49 changes: 49 additions & 0 deletions bootstrap/www/cfg_rtsp_save
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh

echo "Content-type: text/html"
echo ""

cat << EOF

<html>
<head>
<title>Fang Hacks</title>
<style type="text/css">
body { background-color: #B0E0E6; font-family: verdana, sans-serif; }
.err { color: red; }
hr { height: 1px; border: 0; border-top: 1px solid #aaa; }
button, input[type=submit] { background-color: #ddeaff; }
.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>
<head>
<body>
<h1>Save RTSP Config</h1>
<hr/>
<button title='Status page' type='button' onClick="window.location.href='status'">Status</button>
<button title='Reboot the device' type='button' onClick="window.location.href='action?cmd=reboot'">Reboot</button>
<button title='Info' type='button' onClick="window.location.href='scripts'">Scripts</button>
<button title='View /tmp/hacks.log' type='button' onClick="window.location.href='action?cmd=showlog'">View log</button>
<button title='Network' type='button' onClick="window.location.href='network'">Network</button>
<button title='Configure RTSP' type='button' onClick="window.location.href='cfg_rtsp'">Config RTSP</button>
<hr/>
<div style='clear: both;'>
EOF
CMDLINE=$(echo $QUERY_STRING | sed 's/^.....//' | sed -e "s/\+/ /g" | sed -e "s/\%3E/>/g" | sed -e "s/\%26/\&/g" | sed -e "s/\%24/\$/g")
#don't save the file if it doesn't include _server in the command
if [ -z "${CMDLINE##*_server*}" ]; then
sed -i '/_server/c\'"$CMDLINE" /media/mmcblk0p2/data/etc/scripts/20-rtsp-server 2>&1
echo "File saved, 20-rtsp-server script must be restarted for changes to take effect"
else
echo "error"
fi
cat << EOF
</div>
<div style='clear: both;'>

</div>
</body>
</html>
EOF

10 changes: 7 additions & 3 deletions bootstrap/www/network
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,20 @@ function apply_config() {
function connect_ssid() {
var ssid = document.getElementById('ssid_name').textContent;
var enc = document.getElementById(ssid + '_ENC').value;
if (enc != "WPA") { alert("Sorry, " + enc + " encryption is not supported!"); return; }
if ((enc != "WPA") && (enc != "None")) { alert("Sorry, " + enc + " encryption is not supported!"); return; }
var data = {
action: 'connect',
ssid: ssid,
key: document.getElementById('ssid_key').value
};
if (data['key'].length >= 8 && data['key'].length <= 63) {
if ((data['key'].length >= 8 && data['key'].length <= 63) || (data['key'].length == 0 && enc == "None")) {
postData('/cgi-bin/network', data);
} else {
alert("Passphrase must be between 8 and 63 chars!");
if (enc == "None") {
alert("Passphrase must be blank!");
} else {
alert("Passphrase must be between 8 and 63 chars!");
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions bootstrap/www/status
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ cat << EOF
<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='Power off' type='button' onClick="window.location.href='action?cmd=poweroff'">Power off</button>
<button title='Manage scripts' type='button' onClick="window.location.href='scripts'">Manage scripts</button>
<button title='Network' type='button' onClick="window.location.href='network'">Network</button>
<button title='Configure RTSP' type='button' onClick="window.location.href='cfg_rtsp'">Config RTSP</button>
<button title='View /tmp/hacks.log' type='button' onClick="window.location.href='action?cmd=showlog'">View log</button>
<hr/>
<table class='tbl'>
Expand Down
28 changes: 23 additions & 5 deletions data/etc/scripts/01-network
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,23 @@ connect()
do_connect()
{
# temporary connect to ssid
if [ -z "$2" -o -z "$3" ]; then
if [ -z "$2" ]; then
echo "Usage: $0 connect [ssid] [passphrase]"
return 1
fi
cat > /tmp/wpa_tmp.conf << EOF
ctrl_interface=/var/run/wpa_supplicant
update_config=1
EOF
echo "network={" >> /tmp/wpa_tmp.conf
printf "ssid=\"" >> /tmp/wpa_tmp.conf
echo "$2"\" | tr '+' ' ' >> /tmp/wpa_tmp.conf
if [ -z "$3" ]; then
echo "key_mgmt=NONE" >> /tmp/wpa_tmp.conf
else
echo "psk=\"$3\"" >> /tmp/wpa_tmp.conf
fi
echo "}" >> /tmp/wpa_tmp.conf
if [ -e "/var/run/wpa_supplicant.pid" -o -d "/var/run/wpa_supplicant" ]; then
echo "Terminating wpa_supplicant"
killall wpa_supplicant
Expand All @@ -141,6 +150,10 @@ EOF
echo "Terminating udhcpc"
killall udhcpc
fi
if [ -e "/var/run/udhcpd.pid" ]; then
echo "Terminating udhcpd"
killall udhcpd
fi
if pidof hostapd >/dev/null; then
echo "Terminating hostapd"
killall hostapd
Expand All @@ -153,10 +166,15 @@ EOF
if [ "$status" != "OK" ]; then echo "wpa_cli ssid failed: $status"; return 1; fi
status="$(wpa_cli -iwlan0 set_network $id scan_ssid 1)"
if [ "$status" != "OK" ]; then echo "wpa_cli scan_ssid failed: $status"; return 1; fi
status="$(wpa_cli -iwlan0 set_network $id key_mgmt WPA-PSK)"
if [ "$status" != "OK" ]; then echo "wpa_cli key_mgmt failed: $status"; return 1; fi
status="$(wpa_cli -iwlan0 set_network $id psk \"$3\")"
if [ "$status" != "OK" ]; then echo "wpa_cli psk failed: $status"; return 1; fi
if [ -z "$3" ]; then
status="$(wpa_cli -iwlan0 set_network $id key_mgmt NONE)"
if [ "$status" != "OK" ]; then echo "wpa_cli key_mgmt failed: $status"; return 1; fi
else
status="$(wpa_cli -iwlan0 set_network $id key_mgmt WPA-PSK)"
if [ "$status" != "OK" ]; then echo "wpa_cli key_mgmt failed: $status"; return 1; fi
status="$(wpa_cli -iwlan0 set_network $id psk \"$3\")"
if [ "$status" != "OK" ]; then echo "wpa_cli psk failed: $status"; return 1; fi
fi
status="$(wpa_cli -iwlan0 enable_network $id)"
if [ "$status" != "OK" ]; then echo "wpa_cli psk failed: $status"; return 1; fi
else
Expand Down