Menu

#11 Escaped spaces not supported in filename

v0.0.1
open
nobody
None
1
2017-03-19
2017-03-07
Calvin E.
No

Original filename: Client to TCS 7605717390.pcapng.gz

Command: callflow Client\ to\ TCS\ 7605717390.pcapng.gz
Also tried callflow 'Client to TCS 7605717390.pcapng.gz' with similar result

Result:

callflow Client\ to\ TCS\ 7605717390.pcapng.gz
basename: extra operand `TCS'
Try `basename --help' for more information.
/usr/local/share/callflow/scripts/pcap-parser.sh: line 5: $DESTDIR/callflow.long: ambiguous redirect
tshark: "Client" is a directory (folder), not a file.
tshark: "Client" is a directory (folder), not a file.
/usr/local/share/callflow/scripts/pcap-parser.sh: line 188: $DESTDIR/callflow.short: ambiguous redirect
sort: stat failed: 7605717390.pcapng/callflow.short: No such file or directory
basename: extra operand `TCS'
Try `basename --help' for more information.
md5sum: Client: Is a directory
md5sum: to: Is a directory
md5sum: TCS: Is a directory
md5sum: 7605717390.pcapng.gz: No such file or directory
/usr/local/bin/callflow: line 98: $DESTDIR/metadb: ambiguous redirect
/usr/local/bin/callflow: line 436: [: too many arguments
sed: couldn't edit Client: not a regular file
/usr/local/bin/callflow: line 445: [: too many arguments
sed: couldn't edit Client: not a regular file
/usr/local/bin/callflow: line 463: $DESTDIR/callflow.long: ambiguous redirect
/usr/local/bin/callflow: line 469: $DESTDIR/frames/callflow.css: ambiguous redirect
awk: /usr/local/share/callflow/scripts/list-nodes.awk:6: fatal: cannot open file `Client' for reading (Inappropriate ioctl for device)
callflow: warning: no "order" file found -- using auto generated
cat: Client: Is a directory
cat: to: Is a directory
cat: TCS: Is a directory
cat: 7605717390.pcapng/callflow.short: No such file or directory
/usr/local/bin/callflow: line 561: $DESTDIR/callflow.svg: ambiguous redirect

Discussion

  • Richard Bos

    Richard Bos - 2017-03-07

    Please check the current version available in the repository. It has a solution for this.
    Not sure about the spaces in filenames though. For this moment the solution is to replace the spaces with e.g. "_"

     
    • Calvin E.

      Calvin E. - 2017-03-08

      I updated to callflow version 20141023 and it still failed on quoted or
      escaped filenames.

       

      Last edit: Calvin E. 2017-03-08
  • Richard Bos

    Richard Bos - 2017-03-08

    Please use the version from svn:
    cat callflow.version
    20170115.08

    Only thing left is to release it.

     
    • Calvin E.

      Calvin E. - 2017-03-09

      Similar failures on 20170115.226. I'm nearly finished editing the variable quoting within bin/callflow and scripts/pcap-parser.sh, all that's left to fix is how the file name is passed to inkscape and tar/zip. I expect to have a patch ready today.

      Also, my TShark version 1.8.10 doesn't support gui.column.format; that was resolved by changing the option to column.format instead.

      There's a comment in callflow asking what a particular sed expression is doing:

        DESTDIR=$(basename "$inputfile" | sed -r "s/(.+)\.(.+)/\1/");
      

      This removes the extension from the filename, e.g. filename.pcap.gz becomes filenam.pcap, and filename.trace becomes filename.

      I've changed ls to basename in the command above, so the DESTDIR is within the current directory, not where the pcap itself is. This way my web interface can upload the pcap to a temp folder that's regularly purged, and I can run callflow from the intended destination directly.

       

      Last edit: Calvin E. 2017-03-10
  • Calvin E.

    Calvin E. - 2017-03-10

    Here's an svn diff for my changes:

    • Quoting for $inputilfe, $DESTDIR, and others to support spaces and other unfriendly characters in filenames
    • Where quoting failed, tweaked IFS
    • Adjusted $DESTDIR to exist in current directory, not location of pcap
    • Adjusted zip and tar to receive file list from stdin rather than arguments
    • Tweaked alignment of filename title in .svg/.png to tolerate long file name with only two nodes
    • Permit wider node width for better display of very long R-URI
    Index: scripts/callflow.awk
    ===================================================================
    --- scripts/callflow.awk        (revision 226)
    +++ scripts/callflow.awk        (working copy)
    @@ -70,8 +70,15 @@
    
       # With 'leftMargin + ( 1.5 * xHostSpace )' the title is centered above
       # the second column
    
    +  # Centering text over a column causes longer filnames to be cut off
    +  # when there is less total column width than the lenth of the filename
    +  # It's cleaner to left-justify the title by removing the "label" style
    +  # and setting a static indent, or center it on half the page width
    +  # printf "<text x=\"%d\" y=\"%d\" class=\"title-text\">%s</text>\n",
    +    # 50 ,
       printf "<text x=\"%d\" y=\"%d\" class=\"label title-text\">%s</text>\n",
    -    leftMargin + ( 1.5 * xHostSpace ),
    +    #leftMargin + ( 1.5 * xHostSpace ),
    +    w / 2 ,
         y,
         title;
    
    Index: scripts/pcap-parser.sh
    ===================================================================
    --- scripts/pcap-parser.sh      (revision 226)
    +++ scripts/pcap-parser.sh      (working copy)
    @@ -1,13 +1,13 @@
     function make_long_and_short_caches_of_pcap_trace() {
    
    
    -  PCAP_FILE=$1
    +  PCAP_FILE="$1"
       unset PREV_CALL_ID
       unset PREV_TIME
       unset PREV_SRC_IP
       unset PREV_DST_IP
       unset PREV_CSEQ
    
    
    -  tshark -V -r $PCAP_FILE $FARG "$FVAL" > $DESTDIR/callflow.long
    +  tshark -V -r "$PCAP_FILE" $FARG "$FVAL" > "$DESTDIR"/callflow.long
    
       # Create a datafile with the data needed to create the callflow.
       # This is done in 2 steps, because of the following reasons:  the tshark command
    @@ -15,7 +15,7 @@
       # data.  Some additional information about the Call-ID; this field can show up
       # in (at least) 2 ways in SIP messages.  The field can indeed be called "Call-ID",
       # but just "i" in abbreviated SIP messages!  Both formats can be used in 1 call.
    
    -  tshark -r $PCAP_FILE -t a -T fields -E separator='|' \
    +  tshark -r "$PCAP_FILE" -t a -T fields -E separator='|' \
         -e frame.number -e ip.src -e ip.dst -e sip.CSeq -e sip.Call-ID \
         -e sdp.connection_info -e sdp.media -e sdp.media_attr -e ipv6.src -e ipv6.dst \
         $FARG "$FVAL" | awk '
    @@ -102,7 +102,7 @@
       # - Megaco has a "|" in its info string, this character is however the
       #   field separator in the output file, remove it.  The actual string
       #   being removed is " |=".
    -  tshark -r $PCAP_FILE -t a \
    +  tshark -r "$PCAP_FILE" -t a \
         -o 'gui.column.format: "No.", "%m", "Time", %t, "Protocol", "%p", "srcport", %S, "dstport", %D, "Info", "%i"' \
         $FARG "$FVAL" |
           sed -e 's/^[[:blank:]]*//' \
    @@ -283,7 +283,7 @@
         PREV_SRC_IP  = CURR_SRC_IP
         PREV_DST_IP  = CURR_DST_IP
    
    
    -  }' $TMPDIR/${PRGNAME}-tshark-4.$$ > $DESTDIR/callflow.short
    +  }' $TMPDIR/${PRGNAME}-tshark-4.$$ > "$DESTDIR/callflow.short"
    
       rm $TMPDIR/${PRGNAME}-tshark-[1234].$$
     }
    Index: callflow
    ===================================================================
    --- callflow    (revision 226)
    +++ callflow    (working copy)
    @@ -68,24 +68,24 @@
       # in 2 files, being $DESTDIR/callflow.short and $DESTDIR/callflow.long
    
       # Try to be smart and figure out the format of the input file
    
    -  INPUT_FILE_FORMAT=$(file $inputfile | cut -d: -f2)
    +  INPUT_FILE_FORMAT=$(file "$inputfile" | cut -d: -f2)
       case $INPUT_FILE_FORMAT in
       *ASCII*)
          . $SETUPDIR/scripts/broadworks-parser.sh
    -     make_long_and_short_caches_of_broadworks_log $inputfile
    +     make_long_and_short_caches_of_broadworks_log "$inputfile"
          ;;
       *)
          # Any other file type is considered a network trace
          . $SETUPDIR/scripts/pcap-parser.sh
    -     make_long_and_short_caches_of_pcap_trace $inputfile
    +     make_long_and_short_caches_of_pcap_trace "$inputfile"
       esac
    
       # Store the input characteristics.  It will be used in subsequent runs
       # to determine that the cache can be used, or that the input must be
       # processed again.
    
    -  TRACE_FILE=$(basename $inputfile)
    -  MD5SUM=$(md5sum $inputfile | awk '{print $1}')
    -  echo "$TRACE_FILE|$MD5SUM|$FVAL" > $DESTDIR/metadb
    +  TRACE_FILE=$(basename "$inputfile")
    +  MD5SUM=$(md5sum "$inputfile" | awk '{print $1}')
    +  echo "$TRACE_FILE|$MD5SUM|$FVAL" > "$DESTDIR"/metadb
     }
    
     function usage() {
    @@ -283,11 +283,19 @@
    
     inputfile="$1"
     if [[ ! -f "$inputfile" ]]; then
    
    -  echo "$PRGNAME: error: Input file ($inputfile) does not exists!"
    +  echo "$PRGNAME: error: Input file ($inputfile) does not exist!"
       exit 1;
     else
       # TODO: what is the sed command doing precisely, is it really needed?
    -  DESTDIR=$(ls "$inputfile" | sed -r "s/(.+)\.(.+)/\1/");
    +  # It removes the file extension, but only one. e.g. filename.trace becomes filename
    +  # but filename.pcap.gz becomes filenam.pcap
    +  # Here's an addition to replace spaces in the input filename to underscore
    +  # but that won't help with other unfriendly characters sometimes found in SIP
    +  # pcap filenames like @ ( ) [ ] ~ etc.
    +  # DESTDIR=$(basename "$inputfile" | sed -r "s/(.+)\.(.+)/\1/;s/ /_/g");
    +  # Changed ls to basename so destination dirctory is in current directory,
    +  # not location of pcap
    +  DESTDIR=$(basename "$inputfile" | sed -r "s/(.+)\.(.+)/\1/");
     fi
    
     if [[ ! -z "$OPT_FILTER" ]]; then
    @@ -312,7 +320,7 @@
    
     if [[ -n "$OPT_WIDTH_BETWEEN_NODES" ]]; then
    
    
    -  if [[ $OPT_WIDTH_BETWEEN_NODES -gt 250 ]]; then
    +  if [[ $OPT_WIDTH_BETWEEN_NODES -gt 1000 ]]; then
         echo "$PRGNAME: error: width ($OPT_WIDTH_BETWEEN_NODES) between nodes too big" >&2
         exit 1
       fi
    @@ -359,7 +367,7 @@
           ;;
       esac
    
    
    -  ARCHIVE_NAME=$(basename $DESTDIR)
    +  ARCHIVE_NAME=$(basename "$DESTDIR")
       case $ARCHIVE_TYPE in
         bz2|bzip2)
           ARCHIVE_FILE=$ARCHIVE_NAME.tar.bz2
    @@ -394,8 +402,8 @@
    
     if [[ -f order ]]; then
       orderFile=order
    -elif [[ -f $DESTDIR/order ]]; then
    
    -  orderFile=$DESTDIR/order
    +elif [[ -f "${DESTDIR}/order" ]]; then
    +  orderFile="${DESTDIR}/order"
     else
       orderFile=none
     fi
    @@ -404,16 +412,16 @@
     if [[ "$OPT_REFRESH_CACHE" == "yes" ]]; then
       USE_CACHE=no
     else
    -  if [[ -f $DESTDIR/metadb ]]; then
    -    if [[ -f $DESTDIR/callflow.short ]]; then
    -      FILE=$(basename $inputfile)
    -      MD5_FILE=$(md5sum $inputfile | awk '{print $1}')
    +  if [[ -f "$DESTDIR"/metadb ]]; then
    +    if [[ -f "$DESTDIR"/callflow.short ]]; then
    +      FILE=$(basename "$inputfile")
    +      MD5_FILE=$(md5sum "$inputfile" | awk '{print $1}')
    
    
    -      MD5_CACHE=$(awk -F"|" -v FILE=$FILE '{if ($1 == FILE) {print $2} }' $DESTDIR/metadb)
    +      MD5_CACHE=$(awk -F"|" -v FILE="$FILE" '{if ($1 == FILE) {print $2} }' "$DESTDIR"/metadb)
    
           if [[ $MD5_FILE == $MD5_CACHE ]]; then
    
    
    -        CACHED_FILTER=$(awk -F"|" -v FILE=$FILE '{if ($1 == FILE) {print $3} }' $DESTDIR/metadb)
    +        CACHED_FILTER=$(awk -F"|" -v FILE="$FILE" '{if ($1 == FILE) {print $3} }' "$DESTDIR"/metadb)
    
             # Are the cached filter and used filter the same?
             if [[ "$FVAL" == "$CACHED_FILTER" ]]; then
    @@ -437,53 +445,53 @@
    
     [[ $USE_CACHE == "no" ]] && {
       # Create the DESTDIR, do it only here, as it isn't needed earlier
    
    -  mkdir -p $DESTDIR
    +  mkdir -p "$DESTDIR"
    
       make_long_and_short_caches
     }
    
     # Check that the short and long caches exist
    -if [ ! -f $DESTDIR/callflow.long ]; then
    +if [ ! -f "$DESTDIR/callflow.long" ]; then
       echo "$PRGNAME: error: File callflow.long does not exist!"
       exit 1;
     else
       # Some SIP messages don't include a space between the Call-ID tag and
       # Call-ID value
    
    -  sed -i 's,\(Call-ID:\)\([^ ]\),\1 \2,' $DESTDIR/callflow.long
    +  sed -i 's,\(Call-ID:\)\([^ ]\),\1 \2,' "$DESTDIR/callflow.long"
     fi
    
    -if [ ! -f $DESTDIR/callflow.short ]; then
    +if [ ! -f "$DESTDIR"/callflow.short ]; then
       echo "$PRGNAME: error: File callflow.short does not exist!"
       exit 1;
     else
       # Remove Malformed packages from callflow.short, especially because it
       # contains unpaired "["
    
    -  sed -i '/Malform/d' $DESTDIR/callflow.short
    +  sed -i '/Malform/d' "$DESTDIR"/callflow.short
     fi
    
     # Display the node order and exit
     [[ $ORDER == 1 ]] && {
    
    
    -  awk -f $SETUPDIR/scripts/list-nodes.awk -v NODENAMES=$NODENAMES $DESTDIR/callflow.short
    +  awk -f $SETUPDIR/scripts/list-nodes.awk -v NODENAMES=$NODENAMES "$DESTDIR/callflow.short"
       exit 0
     }
    
     # Create Frames
    -mkdir -p $DESTDIR/frames
    -awk -f $SETUPDIR/scripts/long2html.awk -v destDir=$DESTDIR < $DESTDIR/callflow.long
    +mkdir -p "$DESTDIR"/frames
    +awk -f $SETUPDIR/scripts/long2html.awk -v "destDir=$DESTDIR" < "$DESTDIR/callflow.long"
    
     for FILE in $SETUPDIR/css/callflow.css $HOME/.callflow/callflow.css callflow.css; do
       [[ -f $FILE ]] && STYLESHEET=$FILE
     done
    
    -sed s/@SIP_MSG_FONT_SIZE@/${SIP_MSG_FONT_SIZE:-small}/ $STYLESHEET > $DESTDIR/frames/callflow.css
    +sed s/@SIP_MSG_FONT_SIZE@/${SIP_MSG_FONT_SIZE:-small}/ $STYLESHEET > "$DESTDIR"/frames/callflow.css
    
     # Remove duplicate Frame
     if [ $removeDF = 1 ]; then
       #echo "Removing duplicate frames"
    
    -  $SETUPDIR/scripts/removedups.sh $DESTDIR $DESTDIR/frames $TMPDIR ${REMOVE_DUP_MODE:-REMOVE_ALL_DUPS}
    -  rm $DESTDIR/callflow.short
    -  mv $DESTDIR/callflow.short.new $DESTDIR/callflow.short
    +  $SETUPDIR/scripts/removedups.sh "$DESTDIR" "$DESTDIR"/frames $TMPDIR ${REMOVE_DUP_MODE:-REMOVE_ALL_DUPS}
    +  rm "$DESTDIR"/callflow.short
    +  mv "$DESTDIR"/callflow.short.new "$DESTDIR"/callflow.short
     fi
    
     ##################################
    @@ -491,27 +499,28 @@
     ##################################
     # Compute nodes
     awk -f $SETUPDIR/scripts/list-nodes.awk -v NODENAMES=$NODENAMES \
    
    -  $DESTDIR/callflow.short > $TMPDIR/callflow.auto-uniq.$PPID
    +  "$DESTDIR"/callflow.short > $TMPDIR/callflow.auto-uniq.$PPID
    
     # orderFile
    -if [ $orderFile != none ]; then
    +if [ "$orderFile" != none ]; then
    
    +    echo "Using existing order file '$orderFile'"
         # add forced nodes
         cp $TMPDIR/callflow.auto-uniq.$PPID $TMPDIR/callflow.auto-uniq-forced.$PPID
    -    grep "!f!" $orderFile | cut -d " " -f 1 >> $TMPDIR/callflow.auto-uniq-forced.$PPID
    -    cut -d " " -f 1 < $orderFile > $TMPDIR/callflow.order-nodes.$PPID
    +    grep "!f!" "$orderFile" | cut -d " " -f 1 >> $TMPDIR/callflow.auto-uniq-forced.$PPID
    +    cut -d " " -f 1 < "$orderFile" > $TMPDIR/callflow.order-nodes.$PPID
    
         # prune nodes not appearing in capture file and not forced.
         grep -w -v -f $TMPDIR/callflow.auto-uniq-forced.$PPID $TMPDIR/callflow.order-nodes.$PPID > $TMPDIR/callflow.prune-candidate.$PPID
         awk -f $SETUPDIR/scripts/makevars.awk < $TMPDIR/callflow.prune-candidate.$PPID > $TMPDIR/callflow.prune-vars.$PPID
         cat $TMPDIR/callflow.prune-vars.$PPID $SETUPDIR/scripts/prunenodes.awk > $TMPDIR/callflow.prune-awk.$PPID
    
    -    awk -F"|" -f $TMPDIR/callflow.prune-awk.$PPID < $DESTDIR/callflow.short > $TMPDIR/callflow.auto-not-pruned.$PPID
    +    awk -F"|" -f $TMPDIR/callflow.prune-awk.$PPID < "$DESTDIR"/callflow.short > $TMPDIR/callflow.auto-not-pruned.$PPID
         grep -w -v -f $TMPDIR/callflow.auto-not-pruned.$PPID $TMPDIR/callflow.prune-candidate.$PPID > $TMPDIR/callflow.auto-prune.$PPID
         grep -w -v -f $TMPDIR/callflow.auto-prune.$PPID $TMPDIR/callflow.order-nodes.$PPID > $TMPDIR/callflow.order-nodes-pruned.$PPID
    
         # add nodes appearing in capture file but not in order file
         cp $TMPDIR/callflow.order-nodes-pruned.$PPID $TMPDIR/callflow.order-nodes-final.$PPID
         grep -w -f $TMPDIR/callflow.auto-uniq-forced.$PPID $TMPDIR/callflow.order-nodes.$PPID >> $TMPDIR/callflow.order-nodes-final.$PPID
    
    -    grep -w -f $TMPDIR/callflow.order-nodes-final.$PPID $orderFile > $TMPDIR/callflow.order.$PPID
    +    grep -w -f $TMPDIR/callflow.order-nodes-final.$PPID "$orderFile" > $TMPDIR/callflow.order.$PPID
         grep -w -v -E -f $TMPDIR/callflow.order-nodes.$PPID $TMPDIR/callflow.auto-uniq-forced.$PPID >> $TMPDIR/callflow.order.$PPID
         sed "s/!f!//g" < $TMPDIR/callflow.order.$PPID > $TMPDIR/callflow.order-final.$PPID
    
    @@ -556,8 +565,11 @@
    
     AWK_BEGIN_SECTION
    
    
    +  ORIG_IFS=$IFS
    +  IFS=";"
       echo "numLines = $(cat $DESTDIR/callflow.short | wc -l)"
       echo
    +  IFS=$ORIG_IFS
    
       # Add colors from colorFile
       awk 'BEGIN { I = 0} {
    @@ -574,7 +586,7 @@
     ) > $TMPDIR/callflow.awk.$PPID
    
     # Build callflow.svg
    -awk -F "|" -f $TMPDIR/callflow.awk.$PPID $DESTDIR/callflow.short > $DESTDIR/callflow.svg
    +awk -F "|" -f $TMPDIR/callflow.awk.$PPID "$DESTDIR"/callflow.short > "$DESTDIR/callflow.svg"
    
     # Remove temporary files
     rm $TMPDIR/callflow.*.$PPID
    @@ -582,10 +594,12 @@
     # Build callflow.png if inkscape is available
     if which inkscape >/dev/null 2>&1; then
    
    
    -  INKSCAPE_ARGS="--export-dpi=90 -C --export-background=white --export-png=$DESTDIR/callflow.png $DESTDIR/callflow.svg"
    +  ORIG_IFS=$IFS
    +  IFS=";"
    +  INKSCAPE_ARGS="--export-dpi=90;-C;--export-background=white;--export-png=$DESTDIR/callflow.png;$DESTDIR/callflow.svg"
    
       [[ "$SVG_TO_PDF" == "yes" ]] && {
    
    -    INKSCAPE_ARGS="--export-pdf=$DESTDIR/callflow.pdf $INKSCAPE_ARGS"
    +    INKSCAPE_ARGS="--export-pdf=$DESTDIR/callflow.pdf;$INKSCAPE_ARGS"
       }
    
       # Inkscape does not have a quiet option, it might get one in a future release
    @@ -595,16 +609,17 @@
       else
         inkscape $INKSCAPE_ARGS
       fi
    
    +  IFS=$ORIG_IFS
    
       # TODO: should there indeed be a target="_blank" in the callflow.svg or not?
       # Remove the target so the link (frame.html) is opened in the same window where
       # callflow.svg is displayed.  The user has the ability to sent the link to
       # a new tab or new window
    
    -  sed -i 's/ target="_blank"//' $DESTDIR/callflow.svg
    +  sed -i 's/ target="_blank"//' "$DESTDIR"/callflow.svg
    
       # Copy the input file into destination directory
    
    -  TRACEFILE=$(basename $inputfile)
    -  cp $inputfile $DESTDIR/$TRACEFILE
    +  TRACEFILE=$(basename "$inputfile")
    +  cp "$inputfile" "$DESTDIR"/"$TRACEFILE"
    
       # Build HTML files
       for INDEX_FILE in dynamic frameless; do
    @@ -665,19 +680,19 @@
           echo " </body>"
           echo "</html>"
    
    
    -    ) > $DESTDIR/index_$INDEX_FILE.html
    +    ) > "$DESTDIR"/index_$INDEX_FILE.html
    
       done
    
       rm $IMAGE_MAP
    
       #Copy JavaScript files into DESTDIR
    
    -  cp -af $SETUPDIR/js $DESTDIR/
    +  cp -af $SETUPDIR/js "$DESTDIR"/
    
       # (SIP) Messages will be presented in right frame
    
    -  sed 's/coords=/target=\"msg\" coords=/' $DESTDIR/index_frameless.html > $DESTDIR/graph.html
    +  sed 's/coords=/target=\"msg\" coords=/' "$DESTDIR"/index_frameless.html > "$DESTDIR"/graph.html
    
    
    -  firstFrame=$(grep -v "^#" $DESTDIR/callflow.short | awk -F "|" '{ if (NR == 1) print $3 }')
    +  firstFrame=$(grep -v "^#" "$DESTDIR"/callflow.short | awk -F "|" '{ if (NR == 1) print $3 }')
    
       ( echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\""
         echo "   \"http://www.w3.org/TR/html4/frameset.dtd\">"
    @@ -691,20 +706,20 @@
         echo "  <frame name=\"msg\" src=\"frames/Frame${firstFrame}.html\">"
         echo " </frameset>"
         echo "</html>"
    
    -  ) > $DESTDIR/index_frame_right.html
    +  ) > "$DESTDIR"/index_frame_right.html
    
       # (SIP) Messages will be presented in bottom frame
    
    -  sed 's/cols=/rows=/' $DESTDIR/index_frame_right.html > $DESTDIR/index_frame_bottom.html
    +  sed 's/cols=/rows=/' "$DESTDIR"/index_frame_right.html > "$DESTDIR"/index_frame_bottom.html
    
    
    -  mkdir -p $DESTDIR/images
    -  cp -a $SETUPDIR/images/*png $DESTDIR/images
    +  mkdir -p "$DESTDIR"/images
    +  cp -a $SETUPDIR/images/*png "$DESTDIR"/images
       sed \
         -e "s|@TRACE@|$inputfile|" \
         -e "s|@TITLE@|$PRGNAME - $TITLE|" \
         -e "s|@ARCHIVE_FILE@|$ARCHIVE_FILE|" \
    -    $SETUPDIR/images/index.tpl > $DESTDIR/index.html
    -  [[ $ARCHIVE != "yes" ]] && sed -i '/@@@ARCHIVE_FILE@@@/d' $DESTDIR/index.html
    -  [[ "$SVG_TO_PDF" != "yes" ]] && sed -i '/@@@PDF_FILE@@@/d' $DESTDIR/index.html
    +    $SETUPDIR/images/index.tpl > "$DESTDIR"/index.html
    +  [[ $ARCHIVE != "yes" ]] && sed -i '/@@@ARCHIVE_FILE@@@/d' "$DESTDIR"/index.html
    +  [[ "$SVG_TO_PDF" != "yes" ]] && sed -i '/@@@PDF_FILE@@@/d' "$DESTDIR"/index.html
    
     else
       ( echo "Error $PRGNAME: inkscape not found."
    @@ -719,18 +734,19 @@
     if [[ "$ARCHIVE" == "yes" ]]; then
    
       # Be specific in the files to be included in the archive
    
    -  cd $DESTDIR
    +  cd "$DESTDIR"
       DIRS="frames images js"
       FILES=$(find $DIRS -type f)
    +  FILES=$(tr " " "," <<< "$FILES")
    
    
    -  FILES="$FILES $TRACEFILE callflow.svg callflow.png graph.html"
    -  FILES="$FILES index_dynamic.html index_frame_bottom.html index_frameless.html"
    -  FILES="$FILES index_frame_right.html index.html"
    +  FILES="$FILES,$TRACEFILE,callflow.svg,callflow.png,graph.html"
    +  FILES="$FILES,index_dynamic.html,index_frame_bottom.html,index_frameless.html"
    +  FILES="$FILES,index_frame_right.html,index.html"
       [[ "$SVG_TO_PDF" == "yes" ]] && {
    -    FILES="$FILES callflow.pdf"
    +    FILES="$FILES,callflow.pdf"
       }
    
    
    -  ARCHIVE_FILES=$(tr " " "\n" <<< "$FILES" | sort)
    +  ARCHIVE_FILES=$(tr "," "\n" <<< "$FILES" | sort)
    
       if [[ "$ARCHIVE_TYPE" == "files" ]]; then
         echo
    @@ -742,11 +758,11 @@
    
         FILES=$( sed "s,^,$ARCHIVE_NAME/," <<< "$ARCHIVE_FILES" )
    
    
    -    cd $DESTDIR/..
    +    cd ..
         if [[ "$ARCHIVE_TYPE" == "zip" ]]; then
    -      zip --quiet $DESTDIR/$ARCHIVE_NAME.zip $FILES
    +      zip --quiet -@ "$DESTDIR/$ARCHIVE_NAME.zip" <<< "$FILES"
         else
    -      tar cjf $DESTDIR/$ARCHIVE_NAME.tar.bz2 $FILES
    +      tar cjf "$DESTDIR/$ARCHIVE_NAME.tar.bz2" -T - <<< "$FILES"
         fi
         echo "$PRGNAME: $ARCHIVE_TYPE archive available at \"$DESTDIR/$ARCHIVE_FILE\""
       fi
    @@ -772,9 +788,9 @@
       echo
       echo "The output can be viewed with a browser: "
       if [[ -z "$CALLFLOW_URL" ]]; then
    -    echo " ${BROWSER:=firefox} $DESTDIR/index.html"
    +    echo " ${BROWSER:=firefox} \"$DESTDIR/index.html\""
       else
    -    echo " ${BROWSER:=firefox} $CALLFLOW_URL/$DESTDIR/index.html"
    +    echo " ${BROWSER:=firefox} \"$CALLFLOW_URL/$DESTDIR/index.html\""
       fi
     fi
    
     
    • Calvin E.

      Calvin E. - 2017-03-10

      And this too:

      Index: scripts/broadworks-parser.sh
      ===================================================================
      --- scripts/broadworks-parser.sh        (revision 226)
      +++ scripts/broadworks-parser.sh        (working copy)
      @@ -3,7 +3,7 @@
         # TODO: make BW_IP_ADDR configurable from the command line
         [[ -z $BW_IP_ADDR ]] && BW_IP_ADDR=127.0.0.1
      
      
      -  awk -v destDir=$DESTDIR -v bwIpAddr=$BW_IP_ADDR 'BEGIN {
      +  awk -v "destDir=$DESTDIR" -v bwIpAddr=$BW_IP_ADDR 'BEGIN {
           FRAME_NR = 1
           LOG_MSG_LINE_NR = 0
           NOC = 1  # Number Of Call-IDs
      
       
  • Richard Bos

    Richard Bos - 2017-03-18

    Calvin, thanks for the patch. However, do not provide the various changes in one big patch. Provide a patch per related change,please.

    Having said that, feedback on your patch:

    Prevent spaces to be used in the patch or filename. Using spaces makes processing files only more cumbersome.

    Quoting for $inputilfe, $DESTDIR, and others to support spaces and other unfriendly characters in filenames
    Where quoting failed, tweaked IFS
    Adjusted zip and tar to receive file list from stdin rather than arguments
    

    Patch is not needed, when no spaces are used in the filename. Have your web frontend modify the filename, so there are no spaces anymore.

    Adjusted $DESTDIR to exist in current directory, not location of pcap
    

    If you want this, do not change the current behavior. Provide a patch that adds an option that specifies the output directory.

    Tweaked alignment of filename title in .svg/.png to tolerate long file name with only two nodes
    

    This is too specific (for two nodes only, normally there are many, many more nodes involved). Add one or more firewalls (in the order file) to the right of the picture, that makes the diagram wider.

    If you look in the history, you'll see that the filename location was recently changed to the current location.

    Permit wider node width for better display of very long R-URI
    

    The most left part of the URI provides the usefull information. As such a width of 250 should be sufficient. In case it is still too small, add firewalls (as explained in the previous item) to obtain a wider diagram.

    A better solution might be to be able to specify the width of the diagram on the command line.

     
    • Calvin E.

      Calvin E. - 2017-03-18

      Robert, thank you for the feedback. This is my first open source contribution and I appreciate the opportunity to learn from your comments

      Regarding the adjustment to the output directory, I agree this should be a separate patch for a new command line argument, e.g. --outputdir.

      The change to the filename alignment was not solely for the case of two nodes; that's simply how the issue first presented itself in my environment. I deal with a lot of very long filenames, which were still being cut off even when more than two nodes were present.

      This was elaborated upon in the source comments:

      +  # Centering text over a column causes longer filnames to be cut off
      +  # when there is less total column width than the lenth of the filename
      +  # It's cleaner to left-justify the title by removing the "label" style
      +  # and setting a static indent, or center it on half the page width
      

      Adding firewalls is certainly one way to handle that, but I'm doing all that I can to save my end users from editing order files unless absolutely necessary. I'm also trying to keep any middleware as simple as possible by addressing issues within callflow itself.

      Perhaps this could become another command line argument, i.e. --titlealign or --titlepos with options for leftmargin, center, default (2nd column).

      The most left part of the URI provides the usefull information. As such a width of 250 should be sufficient. In case it is still too small, add firewalls (as explained in the previous item) to obtain a wider diagram.
      A better solution might be to be able to specify the width of the diagram on the command line.

      The change is simply an increase in the max allowed when specifying the width on the command line:

      -  if [[ $OPT_WIDTH_BETWEEN_NODES -gt 250 ]]; then
      +  if [[ $OPT_WIDTH_BETWEEN_NODES -gt 1000 ]]; then
      

      Although the leftmost part of the R-URI may be most commonly used, in our environment we deal with very long registration contacts, and I was making room to still see the SDP after that. Also keeping non-technical end users away from the order files.

      Adding a line break between the R-URI and the SDP would be another way to keep that tidy.

      Saving this for last:

      Patch is not needed, when no spaces are used in the filename. Have your web frontend modify the filename, so there are no spaces anymore.

      This is not a tenable solution. The issue is not about spaces, this is an issue of properly quoting variables to safely handle user input without unexpected failure. Although not common in Unix-like environments, there are many characters allowed in Windows and Mac environments which will cause scripts to fail when this is not taken into consideration.

      I frequently deal with filenames containing characters like @(){}[] and often with justifiable purpose. E.g. capture tools which use the R-URI, Call-ID, Contact, or To as the filename. Renaming these files breaks continuity with other people involved in the work.

      Putting the onus on end users or middleware to only provide "safe" file names forces every other user to solve the problem repeatedly, indefinitely. Adding some quotes to callflow fixes it permanently for all users.

      Since I'm starting to get philosophical about this I'll return to the concrete with two things:

      http://www.linfo.org/file_name.html Although specific characters are forbidden and others are discouraged, I'm aware of no standard that spaces and other punctuation cannot be used, especially in cross-platform environments like SIP and the Internet where the characters are commonplace in filenames on other platforms.

      And more importantly, https://en.wikipedia.org/wiki/Robustness_principle

      Be conservative in what you send, be liberal in what you accept

      I'll re-post this patch without the un-related changes.

       

      Last edit: Calvin E. 2017-03-18
  • Richard Bos

    Richard Bos - 2017-03-19

    I rather prevent filenames with spaces, as such add a check for invalid characters in the filename, and if there are reject the file. Or rename the file to only use valid characters.

     

Log in to post a comment.

MongoDB Logo MongoDB