#!/bin/sed -nrf #log-filter.sed #this is part of the program "propogate" #rearrange input into the format that the command parser expects: property_name,value #I tried to prevent any potential security flaws from crafted input by: # - exactly matching allowable properties, instead of removing all the possible invalid ones that I could think of # - restricting the allowed characters to the minimum required to do their jobs # - first field: property name, without any leading or trailing whitespace, and without a colon at the end # allowed characters: # - uppercase letters # - lowercase letters # - underscores # - dashes # - second field: the value of the property, stripped of quotes and leading and trailing white space # allowed characters: # - uppercase letters # - lowercase letters # - numbers # - underscores # - dashes # - periods # - colons # - spaces #to prevent any invalid input from getting past, I had this script by default output nothing #in addition, I placed the "d" command (delete current buffer, move on to next line) #before the "p" command (print contents of pattern buffer), and the script only jumps #to the "p" command if the input is validly formatted #trim white space s/^[ ]*(.*)[ ]*$/\1/ #handle opening and closing curly braces, and skip to the print command if they're found /^[\{\}]$/ b print #main substitution line: if the line matches an acceptable format for an input, extract the property #name and its value, and put them into a comma-separated list s/^([A-Za-z_\-]*)\:[ ]*\"([A-Za-z0-9 _\-\.\:\/]*)\"\,?/\1,\2/ #if the previous substitution succeeded, skip to the print command t print #if the previous substitution failed, output an error message #s/.*/error,&/ #delete the contents of the pattern space, thus implicitly moving on to the next line d #the script should only get to this point if the previous substitution was a success :print p