From 38bb0c87dcb0473e9b499e9cf3be77a77825e180 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 09:08:21 -0600 Subject: [PATCH 01/13] Add files via upload add web interface functionality to configure rtsp server, power-off --- action | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++ cfg_rtsp | 73 ++++++++++++++++++ cfg_rtsp_save | 49 ++++++++++++ status | 142 +++++++++++++++++++++++++++++++++++ 4 files changed, 466 insertions(+) create mode 100644 action create mode 100644 cfg_rtsp create mode 100644 cfg_rtsp_save create mode 100644 status diff --git a/action b/action new file mode 100644 index 0000000..0728891 --- /dev/null +++ b/action @@ -0,0 +1,202 @@ +#!/bin/sh + +echo "Content-type: text/html" +echo "" + +source func.cgi + +start_telnetd() +{ + if [ $(pidof telnetd) ]; then + pid=$(pidof telnetd) + echo "Telnetd is already running! (PID: $pid)
" + echo "Killing PID $pid
" + kill $pid + sleep 1 + fi + /usr/sbin/telnetd & + sleep 1 + echo "Started (PID: $(pidof telnetd))
" +} + +manual_mount() +{ + present=$(lsblk -o KNAME,FSTYPE |grep mmcblk0p2) + if [ $? -eq 0 ]; then + echo "Device is present (filesystem: $(echo $present | cut -d' ' -f2))
" + if [ ! -d /media/mmcblk0p2 ]; then + echo "Creating mount-point (/media/mmcblk0p2)
" + mkdir /media/mmcblk0p2 + fi + mount /dev/mmcblk0p2 /media/mmcblk0p2 2>&1 + rc=$? + echo "
" + if [ $rc -eq 0 ]; then echo "Mounted successfully!
"; else echo "Failed to mount!
"; fi + else + echo "Failed: The sd-card is not inserted or does not contain a mmcblk0p2 partition!
" + fi +} + +update_file() +{ + if [ ! -e "$2" ]; then + echo "Source file not found: '$2'
" + return + fi + + diff="$(diff "$1" "$2")" + if [ $? -eq 0 ]; then + echo "$1: Unchanged!
" + else + echo "$1: Changed!
" + echo "
$diff
" + install -m $3 "$2" "$1" 2>&1 + if [ $? -eq 0 ]; then echo "Updated successfully
"; else echo "Failed to update '$2' -> '$1'
"; fi + fi +} + +update() +{ + echo "
" + update_file "/etc/hotplug/sdcard" "/media/mmcblk0p1/bootstrap/sdcard" 755 + echo "
" + update_file "/etc/fang_hacks.sh" "/media/mmcblk0p1/bootstrap/fang_hacks.sh" 755 + echo "
" + update_file "/etc/fang_hacks.cfg" "/media/mmcblk0p1/bootstrap/fang_hacks.cfg" 644 + echo "
" + update_file "/etc/init.d/rc.local" "/media/mmcblk0p1/bootstrap/rc.local" 755 + echo "
" + update_file "/etc/init.d/rcS" "/media/mmcblk0p1/bootstrap/rcS" 755 +} + +apply_file() +{ + if [ -e "$1" ]; then + install -m $3 "$1" "$2" 2>&1 + if [ $? -ne 0 ]; then echo "Failed to install $(basename $1)
"; fi + else + echo "Source file not found: '$1'
" + fi +} + +apply() +{ + apply_file "/media/mmcblk0p1/bootstrap/sdcard" "/etc/hotplug/sdcard" 755 + apply_file "/media/mmcblk0p1/bootstrap/rc.local" "/etc/init.d/rc.local" 755 + apply_file "/media/mmcblk0p1/bootstrap/rcS" "/etc/init.d/rcS" 755 + apply_file "/media/mmcblk0p1/bootstrap/fang_hacks.sh" "/etc/fang_hacks.sh" 755 + apply_file "/media/mmcblk0p1/bootstrap/fang_hacks.cfg" "/etc/fang_hacks.cfg" 644 + + if [ -x "/etc/fang_hacks.sh" ]; then + echo "Running fang_hacks.sh...
" + echo "
"
+    /etc/fang_hacks.sh 2>&1
+    echo "
" + fi +} + +echo "
" +if [ -n "$F_cmd" ]; then + case "$F_cmd" in + showlog) + echo "Contents of /tmp/hacks.log:
" + echo "
"
+    cat /tmp/hacks.log
+    echo "
" + ;; + reboot) + echo "Rebooting device...
" + /sbin/reboot + ;; + poweroff) + echo "Powering off...
" + /sbin/poweroff + ;; + telnetd) + echo "Starting default telnetd (port 23)...
" + start_telnetd + ;; + manual_mount) + echo "Mounting /dev/mmcblk0p2 to /media/mmcblk0p2...
" + manual_mount + ;; + update) + echo "Updating fang hacks scripts...
" + update + ;; + apply) + echo "Applying fang hacks scripts...
" + apply + ;; + apply_cfg) + echo "Applying fang hacks configuration...
" + echo "
"
+    if [ -n "${F_hacks_enable}" ]; then
+      echo "HACKS_ENABLED=1"
+      cmd="s/^\(HACKS_ENABLED\)=0/\1=1/;"
+    else
+      echo "HACKS_ENABLED=0"
+      cmd="s/^\(HACKS_ENABLED\)=1/\1=0/;"
+    fi
+
+    if [ -n "${F_disable_cloud}" ]; then
+      echo "DISABLE_CLOUD=1"
+      cmd="$cmd s/^\(DISABLE_CLOUD\)=0/\1=1/;"
+    else
+      echo "DISABLE_CLOUD=0"
+      cmd="$cmd s/^\(DISABLE_CLOUD\)=1/\1=0/;"
+    fi
+    sed -i.bak "$cmd" /etc/fang_hacks.cfg 2>&1
+    echo "
" + if [ $? -eq 0 ]; then echo "Success"; else echo "Failed"; fi + ;; + settz) + tz=$(printf '%b' "${F_tz//%/\\x}") + if [ $(cat /etc/TZ) != "$tz" ]; then + echo "Setting TZ to '$tz'...
" + echo "$tz" > /etc/TZ + echo "Syncing time...
" + /usr/sbin/ntpd -q -n -p time.google.com 2>&1 + fi + hst=$(printf '%b' "${F_hostname//%/\\x}") + if [ $(cat /etc/hostname) != "$hst" ]; then + echo "Setting hostname to '$hst'...
" + echo "$hst" > /etc/hostname + fi + if [ $? -eq 0 ]; then echo "
Success
"; else echo "
Failed
"; fi + ;; + expandfs) + source /media/mmcblk0p2/data/etc/profile >/dev/null + if type awk >/dev/null; then + if type fdisk >/dev/null; then + p2_start=$(fdisk -l /dev/mmcblk0 | grep mmcblk0p2 | awk '{print $2}') + echo "Found the start point of mmcblk0p2: $p2_start
" + fdisk /dev/mmcblk0 >/dev/null << __EOF__ +d +2 +n +p +2 +$p2_start + +p +w +__EOF__ + sync + touch /etc/.resize_runonce + echo "Ok, Partition resized, please reboot now
" + else + echo "fdisk not found!
" + fi + else + echo "awk not found!" + fi + ;; + *) + echo "Unsupported command '$F_cmd'" + ;; + esac +fi + +echo "
" +echo "" diff --git a/cfg_rtsp b/cfg_rtsp new file mode 100644 index 0000000..baa26fc --- /dev/null +++ b/cfg_rtsp @@ -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 + + + +Fang Hacks + + + +

Configure RTSP

+
+ + + + + +
+
+
+ Command line:
+ +
+
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
+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/test/20-rtsp-server | awk '{ print $1 }') -h" +cat << EOF +
+ + +EOF diff --git a/cfg_rtsp_save b/cfg_rtsp_save new file mode 100644 index 0000000..4329fea --- /dev/null +++ b/cfg_rtsp_save @@ -0,0 +1,49 @@ +#!/bin/sh + +echo "Content-type: text/html" +echo "" + +cat << EOF + + + +Fang Hacks + + + +

Save RTSP Config

+
+ + + + + + +
+
+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" +else + echo "error" +fi +cat << EOF +
+
+ +
+ + +EOF + diff --git a/status b/status new file mode 100644 index 0000000..309b0af --- /dev/null +++ b/status @@ -0,0 +1,142 @@ +#!/bin/sh + +echo "Content-type: text/html" +echo "" + +cat << EOF + + + +Fang Hacks + + + +
+____  __.__             ___________                     
+\   \/  |_______    ____\_   __________    ____   ____  
+ \     /|  \__  \  /  _ \|    __) \__  \  /    \ / ___\ 
+ /     \|  |/ __ \(  <_> |     \   / __ \|   |  / /_/  >
+/___/\  |__(____  /\____/\___  /  (____  |___|  \___  / 
+      \_/       \/           \/        \/     \/_____/  
+
+
+
               
  ___ ___                __           
+
               
 /   |   \_____    ____ |  | __ ______
+
               
/    ~    \__  \ _/ ___\|  |/ //  ___/
+
               
\    Y    // __ \\  \___|    < \___ \ 
+
               
 \___|_  /(____  /\___  |__|_ /____  >
+
               
       \/      \/     \/     \/    \/ 
+
                                              Version 0.2.0
+
+
+
+EOF +HACKS_HOME="/media/mmcblk0p2/data" +if [ -x "/etc/fang_hacks.sh" ]; then + echo "Script is already installed!
" + if [ ! $(mount |grep /media/mmcblk0p2) ]; then + echo "Error: Nothing is mounted on /media/mmcblk0p2!" + echo "" + echo "
" + elif [ ! -d "$HACKS_HOME" ]; then + echo "Error: No 'data' directory found in /media/mmcblk0p2!" + echo "
" + else + if [ -e "/etc/.resize_runonce" ]; then + echo "Reboot required to apply new partition layout!" + echo "
" + elif [ -e "$HACKS_HOME/.resize" ]; then + echo "Expand data partition (/media/mmcblk0p2)?" + echo "" + echo "
" + fi + fi + if [ -e /etc/fang_hacks.cfg ]; then + source /etc/fang_hacks.cfg + echo "
" + echo "" + if [ "$HACKS_ENABLED" -eq 1 ]; then checked="checked"; fi + echo "" + echo "" + echo "
" + unset checked + + if [ "$DISABLE_CLOUD" -eq 1 ]; then + checked="checked" + else + if [ "$NETWORK_MODE" -eq 0 ]; then + disabled="disabled" + title="Cannot disable when network is set to Cloud Mode!" + fi + fi + echo "" + echo "" + echo "
" + echo "
" + echo "
" + fi + echo "Apply updates from sd-card?" + echo "" +else + echo "Do you want to apply Xiao Fang hacks?
" + echo "" +fi + +cat << EOF +

+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Date: +
+ $(date) + + + + + +
+
System uptime:$(uptime)
Version:$(cat /etc/os-release | cut -d'=' -f2)
Kernel:$(uname -a)
Process list:
$(ps)
Mounts:
$(mount)
+ + + +EOF From 1a4c648f5b96ee61f9459a1f4973aa2ecbdca66c Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 10:03:14 -0600 Subject: [PATCH 02/13] Add files via upload add functionality to configure rtsp server from web interface (there probably is easier way to do this) also add functionality to power-off from web interface --- bootstrap/www/action | 4 ++ bootstrap/www/cfg_rtsp | 73 +++++++++++++++++++++++++++++++++++++ bootstrap/www/cfg_rtsp_save | 49 +++++++++++++++++++++++++ bootstrap/www/status | 6 ++- 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 bootstrap/www/cfg_rtsp create mode 100644 bootstrap/www/cfg_rtsp_save diff --git a/bootstrap/www/action b/bootstrap/www/action index de76c76..0728891 100755 --- a/bootstrap/www/action +++ b/bootstrap/www/action @@ -108,6 +108,10 @@ if [ -n "$F_cmd" ]; then echo "Rebooting device...
" /sbin/reboot ;; + poweroff) + echo "Powering off...
" + /sbin/poweroff + ;; telnetd) echo "Starting default telnetd (port 23)...
" start_telnetd diff --git a/bootstrap/www/cfg_rtsp b/bootstrap/www/cfg_rtsp new file mode 100644 index 0000000..baa26fc --- /dev/null +++ b/bootstrap/www/cfg_rtsp @@ -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 + + + +Fang Hacks + + + +

Configure RTSP

+
+ + + + + +
+
+
+ Command line:
+ +
+
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
+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/test/20-rtsp-server | awk '{ print $1 }') -h" +cat << EOF +
+ + +EOF diff --git a/bootstrap/www/cfg_rtsp_save b/bootstrap/www/cfg_rtsp_save new file mode 100644 index 0000000..4329fea --- /dev/null +++ b/bootstrap/www/cfg_rtsp_save @@ -0,0 +1,49 @@ +#!/bin/sh + +echo "Content-type: text/html" +echo "" + +cat << EOF + + + +Fang Hacks + + + +

Save RTSP Config

+
+ + + + + + +
+
+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" +else + echo "error" +fi +cat << EOF +
+
+ +
+ + +EOF + diff --git a/bootstrap/www/status b/bootstrap/www/status index 0558ef1..309b0af 100755 --- a/bootstrap/www/status +++ b/bootstrap/www/status @@ -4,7 +4,7 @@ echo "Content-type: text/html" echo "" cat << EOF - + Fang Hacks @@ -17,7 +17,7 @@ button, input[type=submit] { background-color: #ddeaff; } .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; } - +
____  __.__             ___________                     
@@ -95,8 +95,10 @@ cat << EOF
+ +
From a25b263ac59588a0309909d567f3b8728e3ab0e5 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 10:06:03 -0600 Subject: [PATCH 03/13] Delete cfg_rtsp_save deleting from incorrect folder --- cfg_rtsp_save | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 cfg_rtsp_save diff --git a/cfg_rtsp_save b/cfg_rtsp_save deleted file mode 100644 index 4329fea..0000000 --- a/cfg_rtsp_save +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -echo "Content-type: text/html" -echo "" - -cat << EOF - - - -Fang Hacks - - - -

Save RTSP Config

-
- - - - - - -
-
-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" -else - echo "error" -fi -cat << EOF -
-
- -
- - -EOF - From 0702b284895ed162bbf6eefe408fba2834b43069 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 10:06:20 -0600 Subject: [PATCH 04/13] Delete status deleting from incorrect folder --- status | 142 --------------------------------------------------------- 1 file changed, 142 deletions(-) delete mode 100644 status diff --git a/status b/status deleted file mode 100644 index 309b0af..0000000 --- a/status +++ /dev/null @@ -1,142 +0,0 @@ -#!/bin/sh - -echo "Content-type: text/html" -echo "" - -cat << EOF - - - -Fang Hacks - - - -
-____  __.__             ___________                     
-\   \/  |_______    ____\_   __________    ____   ____  
- \     /|  \__  \  /  _ \|    __) \__  \  /    \ / ___\ 
- /     \|  |/ __ \(  <_> |     \   / __ \|   |  / /_/  >
-/___/\  |__(____  /\____/\___  /  (____  |___|  \___  / 
-      \_/       \/           \/        \/     \/_____/  
-
-
-
               
  ___ ___                __           
-
               
 /   |   \_____    ____ |  | __ ______
-
               
/    ~    \__  \ _/ ___\|  |/ //  ___/
-
               
\    Y    // __ \\  \___|    < \___ \ 
-
               
 \___|_  /(____  /\___  |__|_ /____  >
-
               
       \/      \/     \/     \/    \/ 
-
                                              Version 0.2.0
-
-
-
-EOF -HACKS_HOME="/media/mmcblk0p2/data" -if [ -x "/etc/fang_hacks.sh" ]; then - echo "Script is already installed!
" - if [ ! $(mount |grep /media/mmcblk0p2) ]; then - echo "Error: Nothing is mounted on /media/mmcblk0p2!" - echo "" - echo "
" - elif [ ! -d "$HACKS_HOME" ]; then - echo "Error: No 'data' directory found in /media/mmcblk0p2!" - echo "
" - else - if [ -e "/etc/.resize_runonce" ]; then - echo "Reboot required to apply new partition layout!" - echo "
" - elif [ -e "$HACKS_HOME/.resize" ]; then - echo "Expand data partition (/media/mmcblk0p2)?" - echo "" - echo "
" - fi - fi - if [ -e /etc/fang_hacks.cfg ]; then - source /etc/fang_hacks.cfg - echo "" - echo "" - if [ "$HACKS_ENABLED" -eq 1 ]; then checked="checked"; fi - echo "" - echo "" - echo "
" - unset checked - - if [ "$DISABLE_CLOUD" -eq 1 ]; then - checked="checked" - else - if [ "$NETWORK_MODE" -eq 0 ]; then - disabled="disabled" - title="Cannot disable when network is set to Cloud Mode!" - fi - fi - echo "" - echo "" - echo "
" - echo "
" - echo "" - fi - echo "Apply updates from sd-card?" - echo "" -else - echo "Do you want to apply Xiao Fang hacks?
" - echo "" -fi - -cat << EOF -

-
- - - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - -
Date: -
- $(date) - - - - - -
-
System uptime:$(uptime)
Version:$(cat /etc/os-release | cut -d'=' -f2)
Kernel:$(uname -a)
Process list:
$(ps)
Mounts:
$(mount)
-
- - -EOF From cf35cc74498b005c51fad2b5c4de818ade10a7f7 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 10:06:35 -0600 Subject: [PATCH 05/13] Delete cfg_rtsp deleting from incorrect folder --- cfg_rtsp | 73 -------------------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 cfg_rtsp diff --git a/cfg_rtsp b/cfg_rtsp deleted file mode 100644 index baa26fc..0000000 --- a/cfg_rtsp +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh - -echo "Content-type: text/html" -echo "" - -CMDLINE="`grep -m 1 "_server" /media/mmcblk0p2/data/etc/scripts/20-rtsp-server`" - -cat << EOF - - - -Fang Hacks - - - -

Configure RTSP

-
- - - - - -
-
-
- Command line:
- -
-
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
-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/test/20-rtsp-server | awk '{ print $1 }') -h" -cat << EOF -
- - -EOF From 94f0a07c739055d128686b8a81e4441c7ce69a5a Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 10:06:52 -0600 Subject: [PATCH 06/13] Delete action deleting from incorrect folder --- action | 202 --------------------------------------------------------- 1 file changed, 202 deletions(-) delete mode 100644 action diff --git a/action b/action deleted file mode 100644 index 0728891..0000000 --- a/action +++ /dev/null @@ -1,202 +0,0 @@ -#!/bin/sh - -echo "Content-type: text/html" -echo "" - -source func.cgi - -start_telnetd() -{ - if [ $(pidof telnetd) ]; then - pid=$(pidof telnetd) - echo "Telnetd is already running! (PID: $pid)
" - echo "Killing PID $pid
" - kill $pid - sleep 1 - fi - /usr/sbin/telnetd & - sleep 1 - echo "Started (PID: $(pidof telnetd))
" -} - -manual_mount() -{ - present=$(lsblk -o KNAME,FSTYPE |grep mmcblk0p2) - if [ $? -eq 0 ]; then - echo "Device is present (filesystem: $(echo $present | cut -d' ' -f2))
" - if [ ! -d /media/mmcblk0p2 ]; then - echo "Creating mount-point (/media/mmcblk0p2)
" - mkdir /media/mmcblk0p2 - fi - mount /dev/mmcblk0p2 /media/mmcblk0p2 2>&1 - rc=$? - echo "
" - if [ $rc -eq 0 ]; then echo "Mounted successfully!
"; else echo "Failed to mount!
"; fi - else - echo "Failed: The sd-card is not inserted or does not contain a mmcblk0p2 partition!
" - fi -} - -update_file() -{ - if [ ! -e "$2" ]; then - echo "Source file not found: '$2'
" - return - fi - - diff="$(diff "$1" "$2")" - if [ $? -eq 0 ]; then - echo "$1: Unchanged!
" - else - echo "$1: Changed!
" - echo "
$diff
" - install -m $3 "$2" "$1" 2>&1 - if [ $? -eq 0 ]; then echo "Updated successfully
"; else echo "Failed to update '$2' -> '$1'
"; fi - fi -} - -update() -{ - echo "
" - update_file "/etc/hotplug/sdcard" "/media/mmcblk0p1/bootstrap/sdcard" 755 - echo "
" - update_file "/etc/fang_hacks.sh" "/media/mmcblk0p1/bootstrap/fang_hacks.sh" 755 - echo "
" - update_file "/etc/fang_hacks.cfg" "/media/mmcblk0p1/bootstrap/fang_hacks.cfg" 644 - echo "
" - update_file "/etc/init.d/rc.local" "/media/mmcblk0p1/bootstrap/rc.local" 755 - echo "
" - update_file "/etc/init.d/rcS" "/media/mmcblk0p1/bootstrap/rcS" 755 -} - -apply_file() -{ - if [ -e "$1" ]; then - install -m $3 "$1" "$2" 2>&1 - if [ $? -ne 0 ]; then echo "Failed to install $(basename $1)
"; fi - else - echo "Source file not found: '$1'
" - fi -} - -apply() -{ - apply_file "/media/mmcblk0p1/bootstrap/sdcard" "/etc/hotplug/sdcard" 755 - apply_file "/media/mmcblk0p1/bootstrap/rc.local" "/etc/init.d/rc.local" 755 - apply_file "/media/mmcblk0p1/bootstrap/rcS" "/etc/init.d/rcS" 755 - apply_file "/media/mmcblk0p1/bootstrap/fang_hacks.sh" "/etc/fang_hacks.sh" 755 - apply_file "/media/mmcblk0p1/bootstrap/fang_hacks.cfg" "/etc/fang_hacks.cfg" 644 - - if [ -x "/etc/fang_hacks.sh" ]; then - echo "Running fang_hacks.sh...
" - echo "
"
-    /etc/fang_hacks.sh 2>&1
-    echo "
" - fi -} - -echo "
" -if [ -n "$F_cmd" ]; then - case "$F_cmd" in - showlog) - echo "Contents of /tmp/hacks.log:
" - echo "
"
-    cat /tmp/hacks.log
-    echo "
" - ;; - reboot) - echo "Rebooting device...
" - /sbin/reboot - ;; - poweroff) - echo "Powering off...
" - /sbin/poweroff - ;; - telnetd) - echo "Starting default telnetd (port 23)...
" - start_telnetd - ;; - manual_mount) - echo "Mounting /dev/mmcblk0p2 to /media/mmcblk0p2...
" - manual_mount - ;; - update) - echo "Updating fang hacks scripts...
" - update - ;; - apply) - echo "Applying fang hacks scripts...
" - apply - ;; - apply_cfg) - echo "Applying fang hacks configuration...
" - echo "
"
-    if [ -n "${F_hacks_enable}" ]; then
-      echo "HACKS_ENABLED=1"
-      cmd="s/^\(HACKS_ENABLED\)=0/\1=1/;"
-    else
-      echo "HACKS_ENABLED=0"
-      cmd="s/^\(HACKS_ENABLED\)=1/\1=0/;"
-    fi
-
-    if [ -n "${F_disable_cloud}" ]; then
-      echo "DISABLE_CLOUD=1"
-      cmd="$cmd s/^\(DISABLE_CLOUD\)=0/\1=1/;"
-    else
-      echo "DISABLE_CLOUD=0"
-      cmd="$cmd s/^\(DISABLE_CLOUD\)=1/\1=0/;"
-    fi
-    sed -i.bak "$cmd" /etc/fang_hacks.cfg 2>&1
-    echo "
" - if [ $? -eq 0 ]; then echo "Success"; else echo "Failed"; fi - ;; - settz) - tz=$(printf '%b' "${F_tz//%/\\x}") - if [ $(cat /etc/TZ) != "$tz" ]; then - echo "Setting TZ to '$tz'...
" - echo "$tz" > /etc/TZ - echo "Syncing time...
" - /usr/sbin/ntpd -q -n -p time.google.com 2>&1 - fi - hst=$(printf '%b' "${F_hostname//%/\\x}") - if [ $(cat /etc/hostname) != "$hst" ]; then - echo "Setting hostname to '$hst'...
" - echo "$hst" > /etc/hostname - fi - if [ $? -eq 0 ]; then echo "
Success
"; else echo "
Failed
"; fi - ;; - expandfs) - source /media/mmcblk0p2/data/etc/profile >/dev/null - if type awk >/dev/null; then - if type fdisk >/dev/null; then - p2_start=$(fdisk -l /dev/mmcblk0 | grep mmcblk0p2 | awk '{print $2}') - echo "Found the start point of mmcblk0p2: $p2_start
" - fdisk /dev/mmcblk0 >/dev/null << __EOF__ -d -2 -n -p -2 -$p2_start - -p -w -__EOF__ - sync - touch /etc/.resize_runonce - echo "Ok, Partition resized, please reboot now
" - else - echo "fdisk not found!
" - fi - else - echo "awk not found!" - fi - ;; - *) - echo "Unsupported command '$F_cmd'" - ;; - esac -fi - -echo "
" -echo "" From 5362c4abf142ff2271e4a651f2af3fc7df28a5d1 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 10:16:05 -0600 Subject: [PATCH 07/13] Add files via upload minor changes, to match main repository --- bootstrap/www/status | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrap/www/status b/bootstrap/www/status index 309b0af..276ff2c 100755 --- a/bootstrap/www/status +++ b/bootstrap/www/status @@ -4,6 +4,7 @@ echo "Content-type: text/html" echo "" cat << EOF + @@ -17,7 +18,7 @@ button, input[type=submit] { background-color: #ddeaff; } .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; } - +
____  __.__             ___________                     
From 1ebcb0d963d6854fbfa7f5fd86ae534051798931 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 10:17:31 -0600 Subject: [PATCH 08/13] Add files via upload minor change, to match main repository --- bootstrap/www/status | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap/www/status b/bootstrap/www/status index 276ff2c..bf7aad5 100755 --- a/bootstrap/www/status +++ b/bootstrap/www/status @@ -5,7 +5,6 @@ echo "" cat << EOF - Fang Hacks From a90cdee9f59d34fe0c49bad13e6e7d7de22258d2 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 17:41:12 -0600 Subject: [PATCH 09/13] Add files via upload update path of 20-rtsp-server --- bootstrap/www/cfg_rtsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/www/cfg_rtsp b/bootstrap/www/cfg_rtsp index baa26fc..c8be8e8 100644 --- a/bootstrap/www/cfg_rtsp +++ b/bootstrap/www/cfg_rtsp @@ -65,7 +65,7 @@ Availability of some options depends on the program/version that is installed -a : enable A-law pcm streaming 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/test/20-rtsp-server | awk '{ print $1 }') -h" +#eval "$(grep -m 1 "_server" /media/mmcblk0p2/data/etc/scripts/20-rtsp-server | awk '{ print $1 }') -h" cat << EOF
From 63e5d4318de996638be7ba8c08bacbba2cc26b3e Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sat, 5 Aug 2017 17:43:43 -0600 Subject: [PATCH 10/13] Add files via upload add note to restart 20-rtsp-server after changing config --- bootstrap/www/cfg_rtsp_save | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/www/cfg_rtsp_save b/bootstrap/www/cfg_rtsp_save index 4329fea..263cc4b 100644 --- a/bootstrap/www/cfg_rtsp_save +++ b/bootstrap/www/cfg_rtsp_save @@ -34,7 +34,7 @@ CMDLINE=$(echo $QUERY_STRING | sed 's/^.....//' | sed -e "s/\+/ /g" | sed -e "s/ #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" + echo "File saved, 20-rtsp-server script must be restarted for changes to take effect" else echo "error" fi From 0b7a473d8b7979ed8189862ff9bd5980e349d0d1 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sun, 4 Mar 2018 11:36:15 -0700 Subject: [PATCH 11/13] network updates disable dhcp server in client mode, support connection to network with no encryption --- 01-network | 213 ++++++++++++++++++++++++++++++ network | 377 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 590 insertions(+) create mode 100644 01-network create mode 100644 network diff --git a/01-network b/01-network new file mode 100644 index 0000000..fa3a8e1 --- /dev/null +++ b/01-network @@ -0,0 +1,213 @@ +#!/bin/sh + +source /etc/fang_hacks.cfg +source /media/mmcblk0p2/data/etc/profile + +NETWORK_MODE=${NETWORK_MODE:-0} +DISABLE_CLOUD=${DISABLE_CLOUD:-0} + +kill_network() +{ + if [ -e "/var/run/wpa_supplicant.pid" -o -d "/var/run/wpa_supplicant" ]; then + echo "Terminating wpa_supplicant" + killall wpa_supplicant + fi + + if [ -e "/var/run/hostapd.pid" -o -d "/var/run/hostapd" ]; then + echo "Terminating hostapd" + killall hostapd + fi + if [ -e "/var/run/udhcpc.pid" ]; then + echo "Terminating udhcpc" + killall udhcpc + fi + if [ -e "/var/run/udhcpd.pid" ]; then + echo "Terminating udhcpd" + killall udhcpd + fi +} + +start() +{ + echo "Starting Network..." + rc=0 + case $NETWORK_MODE in + 0) + echo "Cloud mode: network unmanaged" + if [ "$DISABLE_CLOUD" -eq 1 ]; then + echo "WARNING: DISABLE_CLOUD is enabled!" + echo "WARNING: Network will NOT be operational!" + rc=1 + fi + + if [ -n "$try_recover" ]; then + ssid="$(cat /etc/config/.wifissid)" + key="$(cat /etc/config/.wifipasswd)" + echo "Trying to recover from failed connection (ssid: $ssid)..." + do_connect 0 "$ssid" "$key" + rc=$? + fi + ;; + 1) + echo "WiFi Client mode: using wpa_supplicant.conf" + CFG_WPA="${CFG_WPA:-/media/mmcblk0p2/data/etc/wpa_supplicant.conf}" + if [ ! -e "$CFG_WPA" ]; then echo "File not found: $CFG_WPA"; return 1; fi + kill_network + + wpa_supplicant -B -i wlan0 \ + -c /media/mmcblk0p2/data/etc/wpa_supplicant.conf \ + -P /var/run/wpa_supplicant.pid 2>&1 + rc=$? + if [ $rc -eq 0 ]; then + udhcpc -i wlan0 -p /var/run/udhcpc.pid -b 2>&1 + rc=$? + if [ $rc -ne 0 ]; then + echo "Failed to start udhcpc" + fi + else + echo "Failed to start wpa_supplicant" + fi + ;; + 2) + echo "Access point mode: using hostapd.conf" + CFG_AP="${CFG_AP:-/media/mmcblk0p2/data/etc/hostapd.conf}" + CFG_DHCPD="${CFG_DHCPD:-/media/mmcblk0p2/data/etc/udhcpd.conf}" + if [ ! -e "$CFG_AP" ]; then echo "File not found: $CFG_AP"; return 1; fi + if [ ! -e "$CFG_DHCPD" ]; then echo "File not found: $CFG_AP"; return 1; fi + ap_addr="$(cat $CFG_DHCPD | grep ^opt.*router | awk '{print $3}')" + ap_ssid="$(cat $CFG_AP | grep ^ssid= | cut -d'=' -f2)" + if expr "$ap_addr" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then + kill_network + ifconfig wlan0 $ap_addr 2>&1 + if [ $? -ne 0 ]; then + echo "Failed to set IP $ap_addr"; return 1; + fi + hostapd -B -P /var/run/hostapd.pid /media/mmcblk0p2/data/etc/hostapd.conf 2>&1 + if [ $? -ne 0 ]; then + echo "Failed to start hostapd"; return 1; + fi + udhcpd -f /media//mmcblk0p2/data/etc/udhcpd.conf >>/tmp/hacks.log 2>&1 & + if [ $? -ne 0 ]; then + echo "Failed to start udhcpd"; return 1; + fi + echo "Hotspot '$ap_addr' online" + else + echo "Invalid IP: $ap_addr" + rc=1 + fi + ;; + *) + echo "Unsupported NETWORK_MODE($NETWORK_MODE)" + ;; + esac + return $rc +} + +stop() +{ + echo "For safety reasons, the network cannot be stopped." + echo "You would be locked out!" +} + +connect() +{ + # If connection fails, run start() to hopefully restore connection + try_recover=1 + do_connect "$@" + ret=$? + if [ $ret -ne 0 ]; then + echo "Connection failed: trying to recover..." + start + fi + return $ret +} + +do_connect() +{ + # temporary connect to ssid + 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 +#echo "bssid=$4" >> /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 + fi + if [ -e "/var/run/udhcpc.pid" ]; then + 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 + fi + echo "Connecting to '$2'..." + wpa_supplicant -B -i wlan0 -c /tmp/wpa_tmp.conf -P /var/run/wpa_supplicant.pid >/dev/null + if [ $? -eq 0 ]; then + id="$(wpa_cli -iwlan0 add_network)" + status="$(wpa_cli -iwlan0 set_network $id ssid \"$2\")" + 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 + 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 + echo "Failed to start wpa_supplicant" + return 1 + fi + + udhcpc -i wlan0 -p /var/run/udhcpc.pid -b 2>&1 + if [ $? -ne 0 ]; then + echo "Failed to start udhcpc" + return 1 + fi + echo "Success" + return 0 +} + +status() +{ + case $NETWORK_MODE in + 0) echo "Cloud" ;; + 1) echo "Client" ;; + 2) echo "AP" ;; + *) echo "NOK"; return 1; ;; + esac + return 0 +} + +if [ $# -eq 0 ]; then + start +else + case $1 in start|stop|status|connect|kill_network) + $1 "$@" + ;; + esac +fi diff --git a/network b/network new file mode 100644 index 0000000..95fcb0c --- /dev/null +++ b/network @@ -0,0 +1,377 @@ +#!/bin/sh + +echo "Content-type: text/html" +echo "" +source func.cgi +if [ -e "/etc/fang_hacks.cfg" ]; then source /etc/fang_hacks.cfg; fi +PATH="/bin:/sbin:/usr/bin:/media/mmcblk0p2/data/bin:/media/mmcblk0p2/data/sbin:/media/mmcblk0p2/data/usr/bin" + +CFG_MODE="${NETWORK_MODE:-0}" +CFG_CLIENT="/media/mmcblk0p2/data/etc/wpa_supplicant.conf" +CFG_AP="/media/mmcblk0p2/data/etc/hostapd.conf" +CFG_DHCPD="/media/mmcblk0p2/data/etc/udhcpd.conf" + + +if [ -n "$F_action" ]; then + case "$F_action" in + connect) + client_ssid=$(printf '%b' "${F_ssid//%/\\x}") + client_key=$(printf '%b' "${F_key//%/\\x}") + ACTION_MSG="$(/media/mmcblk0p2/data/etc/scripts/01-network connect "$client_ssid" "$client_key")" + ACTION_RC=$? + CFG_MODE=1 + ;; + apply) + ACTION_RC=1 + apply_ssid=$(printf '%b' "${F_ssid//%/\\x}") + apply_key=$(printf '%b' "${F_key//%/\\x}") + case "$F_mode" in + 0) + # apply cloud settings + if [ -n "$apply_ssid" -a -n "${apply_key}" ]; then + ACTION_MSG="Updating cloud settings..." + echo -n "$apply_ssid" > /etc/config/.wifissid + echo -n "$apply_key" > /etc/config/.wifipasswd + ACTION_RC=0 + CFG_MODE=0 + fi + ;; + 1) + # apply wpa_supplicant settings + if [ -n "$apply_ssid" -a -n "${apply_key}" ]; then + if [ -e "$CFG_CLIENT" ]; then + ACTION_MSG="Updating wpa_supplicant..." + sed -i.bak 's/^\(\sssid\).*/\1="'${apply_ssid}'"/; s/^\(\spsk\).*/\1="'${apply_key}'"/' "$CFG_CLIENT" 2>&1 + ACTION_RC=$? + CFG_MODE=1 + else + ACTION_MSG="$CFG_CLIENT doesn't exist!" + fi + fi + ;; + 2) + # apply hostapd settings + if [ -n "$apply_ssid" -a -n "$apply_key" ]; then + if [ -e "$CFG_AP" ]; then + ACTION_MSG="Updating hostapd..." + sed -i.bak 's/^\(ssid\).*/\1='${apply_ssid}'/; s/^\(wpa_passphrase\).*/\1='${apply_key}'/' "$CFG_AP" 2>&1 + ACTION_RC=$? + CFG_MODE=2 + else + ACTION_MSG="$CFG_AP doesn't exist!" + fi + fi + ;; + esac + if [ $ACTION_RC -eq 0 ]; then + # apply network mode + sed -i.bak 's/^NETWORK_MODE=[0-9]/NETWORK_MODE='$CFG_MODE'/' /etc/fang_hacks.cfg + ACTION_MSG="$ACTION_MSG
Applying network mode $CFG_MODE" + echo "Restarting Network..." + ACTION_MSG="$ACTION_MSG
$(/media/mmcblk0p2/data/etc/scripts/01-network start 2>&1)
" + fi + ;; + esac +fi + +if [ -e "$CFG_CLIENT" ]; then + CFG_SSID="$(cat "$CFG_CLIENT")" +fi + +cat << EOF + + + +Fang Hacks + + + + + +

Network Settings

+
+ + + + +
+
$ACTION_MSG
+
+
+Wireless Mode + + + + + + +
+
+ + + + + +
+ +
+Information: +
Interfaces:
$(ifconfig; iwconfig)
+
Routes:
$(route)
+
DNS:
$(cat /etc/resolv.conf)
+ + +EOF + + From 4a71a6e66e8339805b68d01c3d8ad4c3a4fde5e2 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sun, 4 Mar 2018 13:22:15 -0700 Subject: [PATCH 12/13] Revert "network updates" This reverts commit 0b7a473d8b7979ed8189862ff9bd5980e349d0d1. --- 01-network | 213 ------------------------------ network | 377 ----------------------------------------------------- 2 files changed, 590 deletions(-) delete mode 100644 01-network delete mode 100644 network diff --git a/01-network b/01-network deleted file mode 100644 index fa3a8e1..0000000 --- a/01-network +++ /dev/null @@ -1,213 +0,0 @@ -#!/bin/sh - -source /etc/fang_hacks.cfg -source /media/mmcblk0p2/data/etc/profile - -NETWORK_MODE=${NETWORK_MODE:-0} -DISABLE_CLOUD=${DISABLE_CLOUD:-0} - -kill_network() -{ - if [ -e "/var/run/wpa_supplicant.pid" -o -d "/var/run/wpa_supplicant" ]; then - echo "Terminating wpa_supplicant" - killall wpa_supplicant - fi - - if [ -e "/var/run/hostapd.pid" -o -d "/var/run/hostapd" ]; then - echo "Terminating hostapd" - killall hostapd - fi - if [ -e "/var/run/udhcpc.pid" ]; then - echo "Terminating udhcpc" - killall udhcpc - fi - if [ -e "/var/run/udhcpd.pid" ]; then - echo "Terminating udhcpd" - killall udhcpd - fi -} - -start() -{ - echo "Starting Network..." - rc=0 - case $NETWORK_MODE in - 0) - echo "Cloud mode: network unmanaged" - if [ "$DISABLE_CLOUD" -eq 1 ]; then - echo "WARNING: DISABLE_CLOUD is enabled!" - echo "WARNING: Network will NOT be operational!" - rc=1 - fi - - if [ -n "$try_recover" ]; then - ssid="$(cat /etc/config/.wifissid)" - key="$(cat /etc/config/.wifipasswd)" - echo "Trying to recover from failed connection (ssid: $ssid)..." - do_connect 0 "$ssid" "$key" - rc=$? - fi - ;; - 1) - echo "WiFi Client mode: using wpa_supplicant.conf" - CFG_WPA="${CFG_WPA:-/media/mmcblk0p2/data/etc/wpa_supplicant.conf}" - if [ ! -e "$CFG_WPA" ]; then echo "File not found: $CFG_WPA"; return 1; fi - kill_network - - wpa_supplicant -B -i wlan0 \ - -c /media/mmcblk0p2/data/etc/wpa_supplicant.conf \ - -P /var/run/wpa_supplicant.pid 2>&1 - rc=$? - if [ $rc -eq 0 ]; then - udhcpc -i wlan0 -p /var/run/udhcpc.pid -b 2>&1 - rc=$? - if [ $rc -ne 0 ]; then - echo "Failed to start udhcpc" - fi - else - echo "Failed to start wpa_supplicant" - fi - ;; - 2) - echo "Access point mode: using hostapd.conf" - CFG_AP="${CFG_AP:-/media/mmcblk0p2/data/etc/hostapd.conf}" - CFG_DHCPD="${CFG_DHCPD:-/media/mmcblk0p2/data/etc/udhcpd.conf}" - if [ ! -e "$CFG_AP" ]; then echo "File not found: $CFG_AP"; return 1; fi - if [ ! -e "$CFG_DHCPD" ]; then echo "File not found: $CFG_AP"; return 1; fi - ap_addr="$(cat $CFG_DHCPD | grep ^opt.*router | awk '{print $3}')" - ap_ssid="$(cat $CFG_AP | grep ^ssid= | cut -d'=' -f2)" - if expr "$ap_addr" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then - kill_network - ifconfig wlan0 $ap_addr 2>&1 - if [ $? -ne 0 ]; then - echo "Failed to set IP $ap_addr"; return 1; - fi - hostapd -B -P /var/run/hostapd.pid /media/mmcblk0p2/data/etc/hostapd.conf 2>&1 - if [ $? -ne 0 ]; then - echo "Failed to start hostapd"; return 1; - fi - udhcpd -f /media//mmcblk0p2/data/etc/udhcpd.conf >>/tmp/hacks.log 2>&1 & - if [ $? -ne 0 ]; then - echo "Failed to start udhcpd"; return 1; - fi - echo "Hotspot '$ap_addr' online" - else - echo "Invalid IP: $ap_addr" - rc=1 - fi - ;; - *) - echo "Unsupported NETWORK_MODE($NETWORK_MODE)" - ;; - esac - return $rc -} - -stop() -{ - echo "For safety reasons, the network cannot be stopped." - echo "You would be locked out!" -} - -connect() -{ - # If connection fails, run start() to hopefully restore connection - try_recover=1 - do_connect "$@" - ret=$? - if [ $ret -ne 0 ]; then - echo "Connection failed: trying to recover..." - start - fi - return $ret -} - -do_connect() -{ - # temporary connect to ssid - 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 -#echo "bssid=$4" >> /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 - fi - if [ -e "/var/run/udhcpc.pid" ]; then - 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 - fi - echo "Connecting to '$2'..." - wpa_supplicant -B -i wlan0 -c /tmp/wpa_tmp.conf -P /var/run/wpa_supplicant.pid >/dev/null - if [ $? -eq 0 ]; then - id="$(wpa_cli -iwlan0 add_network)" - status="$(wpa_cli -iwlan0 set_network $id ssid \"$2\")" - 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 - 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 - echo "Failed to start wpa_supplicant" - return 1 - fi - - udhcpc -i wlan0 -p /var/run/udhcpc.pid -b 2>&1 - if [ $? -ne 0 ]; then - echo "Failed to start udhcpc" - return 1 - fi - echo "Success" - return 0 -} - -status() -{ - case $NETWORK_MODE in - 0) echo "Cloud" ;; - 1) echo "Client" ;; - 2) echo "AP" ;; - *) echo "NOK"; return 1; ;; - esac - return 0 -} - -if [ $# -eq 0 ]; then - start -else - case $1 in start|stop|status|connect|kill_network) - $1 "$@" - ;; - esac -fi diff --git a/network b/network deleted file mode 100644 index 95fcb0c..0000000 --- a/network +++ /dev/null @@ -1,377 +0,0 @@ -#!/bin/sh - -echo "Content-type: text/html" -echo "" -source func.cgi -if [ -e "/etc/fang_hacks.cfg" ]; then source /etc/fang_hacks.cfg; fi -PATH="/bin:/sbin:/usr/bin:/media/mmcblk0p2/data/bin:/media/mmcblk0p2/data/sbin:/media/mmcblk0p2/data/usr/bin" - -CFG_MODE="${NETWORK_MODE:-0}" -CFG_CLIENT="/media/mmcblk0p2/data/etc/wpa_supplicant.conf" -CFG_AP="/media/mmcblk0p2/data/etc/hostapd.conf" -CFG_DHCPD="/media/mmcblk0p2/data/etc/udhcpd.conf" - - -if [ -n "$F_action" ]; then - case "$F_action" in - connect) - client_ssid=$(printf '%b' "${F_ssid//%/\\x}") - client_key=$(printf '%b' "${F_key//%/\\x}") - ACTION_MSG="$(/media/mmcblk0p2/data/etc/scripts/01-network connect "$client_ssid" "$client_key")" - ACTION_RC=$? - CFG_MODE=1 - ;; - apply) - ACTION_RC=1 - apply_ssid=$(printf '%b' "${F_ssid//%/\\x}") - apply_key=$(printf '%b' "${F_key//%/\\x}") - case "$F_mode" in - 0) - # apply cloud settings - if [ -n "$apply_ssid" -a -n "${apply_key}" ]; then - ACTION_MSG="Updating cloud settings..." - echo -n "$apply_ssid" > /etc/config/.wifissid - echo -n "$apply_key" > /etc/config/.wifipasswd - ACTION_RC=0 - CFG_MODE=0 - fi - ;; - 1) - # apply wpa_supplicant settings - if [ -n "$apply_ssid" -a -n "${apply_key}" ]; then - if [ -e "$CFG_CLIENT" ]; then - ACTION_MSG="Updating wpa_supplicant..." - sed -i.bak 's/^\(\sssid\).*/\1="'${apply_ssid}'"/; s/^\(\spsk\).*/\1="'${apply_key}'"/' "$CFG_CLIENT" 2>&1 - ACTION_RC=$? - CFG_MODE=1 - else - ACTION_MSG="$CFG_CLIENT doesn't exist!" - fi - fi - ;; - 2) - # apply hostapd settings - if [ -n "$apply_ssid" -a -n "$apply_key" ]; then - if [ -e "$CFG_AP" ]; then - ACTION_MSG="Updating hostapd..." - sed -i.bak 's/^\(ssid\).*/\1='${apply_ssid}'/; s/^\(wpa_passphrase\).*/\1='${apply_key}'/' "$CFG_AP" 2>&1 - ACTION_RC=$? - CFG_MODE=2 - else - ACTION_MSG="$CFG_AP doesn't exist!" - fi - fi - ;; - esac - if [ $ACTION_RC -eq 0 ]; then - # apply network mode - sed -i.bak 's/^NETWORK_MODE=[0-9]/NETWORK_MODE='$CFG_MODE'/' /etc/fang_hacks.cfg - ACTION_MSG="$ACTION_MSG
Applying network mode $CFG_MODE" - echo "Restarting Network..." - ACTION_MSG="$ACTION_MSG
$(/media/mmcblk0p2/data/etc/scripts/01-network start 2>&1)
" - fi - ;; - esac -fi - -if [ -e "$CFG_CLIENT" ]; then - CFG_SSID="$(cat "$CFG_CLIENT")" -fi - -cat << EOF - - - -Fang Hacks - - - - - -

Network Settings

-
- - - - -
-
$ACTION_MSG
-
-
-Wireless Mode - - - - - - -
-
- - - - - -
- -
-Information: -
Interfaces:
$(ifconfig; iwconfig)
-
Routes:
$(route)
-
DNS:
$(cat /etc/resolv.conf)
- - -EOF - - From c33e6350a1d403676cce5bb47e68e90fc1ef4c05 Mon Sep 17 00:00:00 2001 From: zavviodotcom <30752771+zavviodotcom@users.noreply.github.com> Date: Sun, 4 Mar 2018 14:12:56 -0700 Subject: [PATCH 13/13] network updates turn off dhcp server in client mode, support open network --- bootstrap/www/network | 10 +++++++--- data/etc/scripts/01-network | 28 +++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/bootstrap/www/network b/bootstrap/www/network index ec0f8a2..f75ac02 100755 --- a/bootstrap/www/network +++ b/bootstrap/www/network @@ -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!"); + } } } diff --git a/data/etc/scripts/01-network b/data/etc/scripts/01-network index ad5c942..cc3d6a4 100755 --- a/data/etc/scripts/01-network +++ b/data/etc/scripts/01-network @@ -125,7 +125,7 @@ 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 @@ -133,6 +133,15 @@ do_connect() 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 @@ -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 @@ -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