[v2] fff-hoods: Fix case of missing keyxchangev2data

Submitted by Adrian Schmutzler on Oct. 15, 2017, 4 p.m.

Details

Message ID 1508083233-56453-1-git-send-email-freifunk@adrianschmutzler.de
State Accepted
Headers show

Commit Message

Adrian Schmutzler Oct. 15, 2017, 4 p.m.
This fixes a missing /tmp/keyxchangev2data due to gateway
misconfiguration.

Changes in v2:
 - First set filename, then read json
 - Move filename evaluation to function

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 .../fff/fff-hoods/files/lib/functions/fff/keyxchange     | 16 ++++++++++++++--
 src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html |  7 ++++---
 2 files changed, 18 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange b/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
index be27e5a..9aedc3c 100644
--- a/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
+++ b/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
@@ -4,9 +4,21 @@ 
 
 . /usr/share/libubox/jshn.sh
 
+getJsonPath() {
+	jsonfile=""
+	if [ -s /www/public/keyxchangev2data ] ; then
+		jsonfile="/www/public/keyxchangev2data"
+	elif [ -s /tmp/keyxchangev2data ] ; then
+		jsonfile="/tmp/keyxchangev2data"
+	fi
+	echo "$jsonfile"
+}
+
 getUpgradePath() {
-	if [ -s /tmp/keyxchangev2data ]; then
-		json_load "$(cat /tmp/keyxchangev2data)"
+	jsonfile="$(getJsonPath)"
+
+	if [ -n "$jsonfile" ] ; then
+		json_load "$(cat $jsonfile)"
 		json_select hood
 		json_get_var upath upgrade_path
 		echo "$upath"
diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
index 1569c01..64c89f7 100755
--- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
+++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
@@ -48,9 +48,10 @@  else
 fi
 
 # read from keyxchangev2data
-. /usr/share/libubox/jshn.sh
-if [ -s /tmp/keyxchangev2data ] ; then
-	json_load "$(cat /tmp/keyxchangev2data)"
+. /lib/functions/fff/keyxchange
+jsonfile="$(getJsonPath)"
+if [ -n "$jsonfile" ] ; then
+	json_load "$(cat $jsonfile)"
 	json_select hood
 	json_get_var mesh_type2 mesh_type2
 	json_get_var mesh_type5 mesh_type5

Comments

Tim Niemeyer Oct. 15, 2017, 4:43 p.m.
Hi Adrian

Ich bin begeistert.. Es in eine Funktion auszulagern ist natürlich der
optimale Weg.

Sollten noch weitere Review-Kommentare kommen, bau doch bitte diese
Kleinigkeit unten mit ein. Dann kannst du gleich das Reviewed-by von
mir mit an den Patch dran hängen. Wenn keine weiteren Kommentare
kommen, dann würde ich das beim Applien ergänzen.

Reviewed-by: Tim Niemeyer <tim@tn-x.org>

Am Sonntag, den 15.10.2017, 18:00 +0200 schrieb Adrian Schmutzler:
> This fixes a missing /tmp/keyxchangev2data due to gateway
> misconfiguration.
> 
> Changes in v2:
>  - First set filename, then read json
>  - Move filename evaluation to function
> 
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> ---
>  .../fff/fff-hoods/files/lib/functions/fff/keyxchange     | 16
> ++++++++++++++--
>  src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html |  7 ++++
> ---
>  2 files changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/src/packages/fff/fff-
> hoods/files/lib/functions/fff/keyxchange b/src/packages/fff/fff-
> hoods/files/lib/functions/fff/keyxchange
> index be27e5a..9aedc3c 100644
> --- a/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
> +++ b/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
> @@ -4,9 +4,21 @@
>  
>  . /usr/share/libubox/jshn.sh
>  
> +getJsonPath() {
> +	jsonfile=""
> +	if [ -s /www/public/keyxchangev2data ] ; then
> +		jsonfile="/www/public/keyxchangev2data"
> +	elif [ -s /tmp/keyxchangev2data ] ; then
> +		jsonfile="/tmp/keyxchangev2data"
> +	fi
> +	echo "$jsonfile"
> +}
> +
>  getUpgradePath() {
> -	if [ -s /tmp/keyxchangev2data ]; then
> -		json_load "$(cat /tmp/keyxchangev2data)"
> +	jsonfile="$(getJsonPath)"
> +
> +	if [ -n "$jsonfile" ] ; then
> +		json_load "$(cat $jsonfile)"
                                 ^-- SC2086: Double quote to prevent globbing and word splitting.
Tim

>  		json_select hood
>  		json_get_var upath upgrade_path
>  		echo "$upath"
> diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html 
> b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> index 1569c01..64c89f7 100755
> --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> @@ -48,9 +48,10 @@ else
>  fi
>  
>  # read from keyxchangev2data
> -. /usr/share/libubox/jshn.sh
> -if [ -s /tmp/keyxchangev2data ] ; then
> -	json_load "$(cat /tmp/keyxchangev2data)"
> +. /lib/functions/fff/keyxchange
> +jsonfile="$(getJsonPath)"
> +if [ -n "$jsonfile" ] ; then
> +	json_load "$(cat $jsonfile)"
>  	json_select hood
>  	json_get_var mesh_type2 mesh_type2
>  	json_get_var mesh_type5 mesh_type5
> -- 
> 2.7.4
>
Adrian Schmutzler Oct. 15, 2017, 4:45 p.m.
Hallo Tim,

danke. Ich verstehe aber nicht, was man da quoten soll.

Grüße

Adrian

> -----Original Message-----
> From: Tim Niemeyer [mailto:tim@tn-x.org]
> Sent: Sonntag, 15. Oktober 2017 18:43
> To: Adrian Schmutzler <freifunk@adrianschmutzler.de>; franken-
> dev@freifunk.net
> Subject: Re: [PATCH v2] fff-hoods: Fix case of missing keyxchangev2data
> 
> Hi Adrian
> 
> Ich bin begeistert.. Es in eine Funktion auszulagern ist natürlich der optimale
> Weg.
> 
> Sollten noch weitere Review-Kommentare kommen, bau doch bitte diese
> Kleinigkeit unten mit ein. Dann kannst du gleich das Reviewed-by von mir mit
> an den Patch dran hängen. Wenn keine weiteren Kommentare kommen,
> dann würde ich das beim Applien ergänzen.
> 
> Reviewed-by: Tim Niemeyer <tim@tn-x.org>
> 
> Am Sonntag, den 15.10.2017, 18:00 +0200 schrieb Adrian Schmutzler:
> > This fixes a missing /tmp/keyxchangev2data due to gateway
> > misconfiguration.
> >
> > Changes in v2:
> >  - First set filename, then read json
> >  - Move filename evaluation to function
> >
> > Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> > ---
> >  .../fff/fff-hoods/files/lib/functions/fff/keyxchange     | 16
> > ++++++++++++++--
> >  src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html |  7 ++++
> > ---
> >  2 files changed, 18 insertions(+), 5 deletions(-)
> >
> > diff --git a/src/packages/fff/fff-
> > hoods/files/lib/functions/fff/keyxchange b/src/packages/fff/fff-
> > hoods/files/lib/functions/fff/keyxchange
> > index be27e5a..9aedc3c 100644
> > --- a/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
> > +++ b/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
> > @@ -4,9 +4,21 @@
> >
> >  . /usr/share/libubox/jshn.sh
> >
> > +getJsonPath() {
> > +	jsonfile=""
> > +	if [ -s /www/public/keyxchangev2data ] ; then
> > +		jsonfile="/www/public/keyxchangev2data"
> > +	elif [ -s /tmp/keyxchangev2data ] ; then
> > +		jsonfile="/tmp/keyxchangev2data"
> > +	fi
> > +	echo "$jsonfile"
> > +}
> > +
> >  getUpgradePath() {
> > -	if [ -s /tmp/keyxchangev2data ]; then
> > -		json_load "$(cat /tmp/keyxchangev2data)"
> > +	jsonfile="$(getJsonPath)"
> > +
> > +	if [ -n "$jsonfile" ] ; then
> > +		json_load "$(cat $jsonfile)"
>                                  ^-- SC2086: Double quote to prevent globbing and word
> splitting.
> Tim
> 
> >  		json_select hood
> >  		json_get_var upath upgrade_path
> >  		echo "$upath"
> > diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > index 1569c01..64c89f7 100755
> > --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > @@ -48,9 +48,10 @@ else
> >  fi
> >
> >  # read from keyxchangev2data
> > -. /usr/share/libubox/jshn.sh
> > -if [ -s /tmp/keyxchangev2data ] ; then
> > -	json_load "$(cat /tmp/keyxchangev2data)"
> > +. /lib/functions/fff/keyxchange
> > +jsonfile="$(getJsonPath)"
> > +if [ -n "$jsonfile" ] ; then
> > +	json_load "$(cat $jsonfile)"
> >  	json_select hood
> >  	json_get_var mesh_type2 mesh_type2
> >  	json_get_var mesh_type5 mesh_type5
> > --
> > 2.7.4
> >
Tim Niemeyer Oct. 15, 2017, 4:54 p.m.
Am Sonntag, den 15.10.2017, 18:45 +0200 schrieb mail@adrianschmutzler.de:
> Hallo Tim,
> 
> danke. Ich verstehe aber nicht, was man da quoten soll.
> 

[..]
> > >  getUpgradePath() {
> > > > > > -	if [ -s /tmp/keyxchangev2data ]; then
> > > > > > -		json_load "$(cat /tmp/keyxchangev2data)"
> > > > > > +	jsonfile="$(getJsonPath)"
> > > +
> > > > > > +	if [ -n "$jsonfile" ] ; then
> > > +		json_load "$(cat $jsonfile)"
> > 
> >                                  ^-- SC2086: Double quote to prevent globbing and word splitting.

Die Zeile müsste so aussehen:
json_load "$(cat "$jsonfile")"

Es könnte ja sein, dass $jsonfile eine Leerstelle enthält.. Deswegen
muss da quotet werden. Und ja... Sieht doof aus.. Und nein die Shell
macht darauf nicht "$(cat ", $jsonfile, ")".. ;)

Siehe auch:

cd /tmp/
echo "test" > "test file"
echo "$(cat "test file")"
echo $(cat "test file")
echo $(cat test file)
echo "$(cat test file)"

Viel Spass beim testen. ;)

Tim
Tim Niemeyer Oct. 16, 2017, 7:45 p.m.
Am Sonntag, den 15.10.2017, 18:43 +0200 schrieb Tim Niemeyer:
> Hi Adrian
> 
> Ich bin begeistert.. Es in eine Funktion auszulagern ist natürlich
> der
> optimale Weg.
> 
> Sollten noch weitere Review-Kommentare kommen, bau doch bitte diese
> Kleinigkeit unten mit ein. Dann kannst du gleich das Reviewed-by von
> mir mit an den Patch dran hängen. Wenn keine weiteren Kommentare
> kommen, dann würde ich das beim Applien ergänzen.

Wie besprochen ergänzt und applied.

Tim

> 
> Reviewed-by: Tim Niemeyer <tim@tn-x.org>
> 
> Am Sonntag, den 15.10.2017, 18:00 +0200 schrieb Adrian Schmutzler:
> > This fixes a missing /tmp/keyxchangev2data due to gateway
> > misconfiguration.
> > 
> > Changes in v2:
> >  - First set filename, then read json
> >  - Move filename evaluation to function
> > 
> > Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> > ---
> >  .../fff/fff-hoods/files/lib/functions/fff/keyxchange     | 16
> > ++++++++++++++--
> >  src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html |  7 ++++
> > ---
> >  2 files changed, 18 insertions(+), 5 deletions(-)
> > 
> > diff --git a/src/packages/fff/fff-
> > hoods/files/lib/functions/fff/keyxchange b/src/packages/fff/fff-
> > hoods/files/lib/functions/fff/keyxchange
> > index be27e5a..9aedc3c 100644
> > --- a/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
> > +++ b/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
> > @@ -4,9 +4,21 @@
> >  
> >  . /usr/share/libubox/jshn.sh
> >  
> > +getJsonPath() {
> > +	jsonfile=""
> > +	if [ -s /www/public/keyxchangev2data ] ; then
> > +		jsonfile="/www/public/keyxchangev2data"
> > +	elif [ -s /tmp/keyxchangev2data ] ; then
> > +		jsonfile="/tmp/keyxchangev2data"
> > +	fi
> > +	echo "$jsonfile"
> > +}
> > +
> >  getUpgradePath() {
> > -	if [ -s /tmp/keyxchangev2data ]; then
> > -		json_load "$(cat /tmp/keyxchangev2data)"
> > +	jsonfile="$(getJsonPath)"
> > +
> > +	if [ -n "$jsonfile" ] ; then
> > +		json_load "$(cat $jsonfile)"
> 
>                                  ^-- SC2086: Double quote to prevent
> globbing and word splitting.
> Tim
> 
> >  		json_select hood
> >  		json_get_var upath upgrade_path
> >  		echo "$upath"
> > diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-
> > bin/home.html 
> > b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > index 1569c01..64c89f7 100755
> > --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > @@ -48,9 +48,10 @@ else
> >  fi
> >  
> >  # read from keyxchangev2data
> > -. /usr/share/libubox/jshn.sh
> > -if [ -s /tmp/keyxchangev2data ] ; then
> > -	json_load "$(cat /tmp/keyxchangev2data)"
> > +. /lib/functions/fff/keyxchange
> > +jsonfile="$(getJsonPath)"
> > +if [ -n "$jsonfile" ] ; then
> > +	json_load "$(cat $jsonfile)"
> >  	json_select hood
> >  	json_get_var mesh_type2 mesh_type2
> >  	json_get_var mesh_type5 mesh_type5
> > -- 
> > 2.7.4