#!/bin/sed -nrf #log-filter.sed #this is used by a shell script for parsing input, and filtering out any invalid input #created by Erik Popp address@hidden #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 #this script should output: # - 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/^[ ]*|[ ]*$//g #handle opening and closing curly braces, and skip to the success section if they're found /^[{}]$/ b success #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 success section t success #record invalid input as an error. If I can get this script to work properly, I want this script to report any syntax errors it finds 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 input was valid :success p