From dbd5ce3a0927760a29f54298995bc948ed38ccfc Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 3 Jan 2018 15:19:17 +0100 Subject: [PATCH 1/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b9de5b9..394a6d2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2e2526c5266848f8ae3e03a87079bc49)](https://www.codacy.com/app/nico.wellpott/logwatch-scripts?utm_source=github.com&utm_medium=referral&utm_content=mightyBroccoli/logwatch-scripts&utm_campaign=Badge_Grade) + # TeamSpeak3 Logwatch Script Script which iterates through the latest teamspeak logfiles and captures the important parts. Main goal is to filter relevant loglines from the past day (UTC). Finally the selected lines are being formatted nicely, so it is easy to see what happened. There are two possible notification modes: From 32dff494d677ed5eb700c88cdebc9206151d0006 Mon Sep 17 00:00:00 2001 From: Julian Merkle Date: Fri, 9 Mar 2018 12:40:13 +0100 Subject: [PATCH 2/4] Append .sh file ending to script --- script/{teamspeak_log_daily_mail => teamspeak_log_daily_mail.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename script/{teamspeak_log_daily_mail => teamspeak_log_daily_mail.sh} (100%) diff --git a/script/teamspeak_log_daily_mail b/script/teamspeak_log_daily_mail.sh similarity index 100% rename from script/teamspeak_log_daily_mail rename to script/teamspeak_log_daily_mail.sh From 45c5123259d34fa31bed93b6fbf98dc6cae337ba Mon Sep 17 00:00:00 2001 From: Julian Merkle Date: Fri, 9 Mar 2018 12:47:13 +0100 Subject: [PATCH 3/4] Make comments uniform --- script/teamspeak_log_daily_mail.sh | 45 +++++++++++-------- script/teamspeak_log_xmpp-push.sh | 71 +++++++++++++++++------------- 2 files changed, 68 insertions(+), 48 deletions(-) diff --git a/script/teamspeak_log_daily_mail.sh b/script/teamspeak_log_daily_mail.sh index c5ef5fc..cac8b3d 100644 --- a/script/teamspeak_log_daily_mail.sh +++ b/script/teamspeak_log_daily_mail.sh @@ -17,6 +17,8 @@ # replace mailaddr_to/_from and possibly the tslog path to fit your needs # place inside /etc/cron.daily to run this script on a daily basis +#### Settings #### + # user specific config file tmp_directory=/tmp/teamspeak/daily_mail archive=/var/log/teamspeak @@ -24,13 +26,15 @@ configfile=$tmp_directory/.user.config configfile_secured=$tmp_directory/tmp.config backupconf=/var/backups/teamspeak_log_daily_mail_user.config -#system specific variables +# system specific variables tslogs=/etc/teamspeak3-server_linux_amd64/logs service_script=ts3server.service tsuser=teamspeak -#### DONT CHANGE FROM HERE #### -#log files +#### Business logic #### +#### DO NOT ALTER #### + +# log files logfiles=$tmp_directory/teamspeak_daily_log_files.txt daily_log=$tmp_directory/teamspeak_daily_log.txt @@ -44,8 +48,9 @@ mailcomposition=$tmp_directory/teamspeak_mail_composition.txt # debug parameter debug=false -###### FUNCTION SECTION ###### -## preparations +#### FUNCTION SECTION #### + +# preparations prerun_check() { # check if all commands needed to run are present in $PATH @@ -63,12 +68,12 @@ prerun_check() exit 11 fi - #check if tmp directory is present if not create it + # check if tmp directory is present if not create it if [ ! -d "$tmp_directory" ]; then mkdir -p "$tmp_directory" fi - #first run check + # first run check # check for presents of the configfile if not exit if [ ! -f "$configfile" ]; then if [ -f "$backupconf" ]; then @@ -107,11 +112,12 @@ collect_and_prepare() grep "$(date -d "$1" '+%Y-%m-%d')" "$tslogs/$(sed -n '2p' $logfiles)" >> $daily_log } -###### General Functions ###### +#### General Functions #### + clearcomp() { if [ "$1" = "-all" ]; then - #deleting possible old content + # deleting possible old content rm -f "$composition1" "$composition2" "$logfiles" "$daily_log" "$message_body" "$mailcomposition" fi # remove the composition files @@ -119,7 +125,8 @@ clearcomp() changed=false } -###### Mail ###### +#### Mail #### + start_finish() { # function to generate sections header @@ -135,7 +142,7 @@ archive_mail() { # only run this functions if $enable_archive is true if [ "$enable_archive" != "false" ]; then - #check if archive directory is present + # check if archive directory is present if [ ! -d "$archive" ]; then mkdir -p "$tmp_directory" fi @@ -147,7 +154,7 @@ send_mail() { # only send mails if $email = yes if [ "$email" = yes ]; then - #file is not empty + # file is not empty { echo -e "To: $mailaddr_to" echo -e "From: $mailaddr_from" echo -e "Subject: LogReport Teamspeak $(date -d "yesterday" '+%d.%m.%Y')\\n" @@ -157,7 +164,8 @@ send_mail() fi } -###### FILTER CODE SECTION ###### +#### FILTER CODE SECTION #### + general_filter() { # general filter which will shift through all positional parameters and filter for that @@ -165,7 +173,7 @@ general_filter() do grep -E "$1" "$daily_log" | sort >> "$composition1" - # only paste the results if there are + # only paste the results if there are any if [ -s "$composition1" ]; then { echo -e "------------------- $1 --------------------\\n" cat "$composition1" @@ -232,7 +240,7 @@ filter_group() } >> "$composition3" fi - #filter if somebody was removed from a group + # filter if somebody was removed from a group grep "was removed from" "$composition1" > "$composition2" if [ -s "$composition2" ]; then { echo -e "--- removed from---\\n" @@ -296,8 +304,9 @@ filter_user_activity() fi } -###### MAIN CODE SECTION ###### -#run all preparations and inital checks +#### MAIN CODE SECTION #### + +# run all preparations and inital checks # clear old stuff clearcomp -all @@ -307,7 +316,7 @@ prerun_check # collect and prepare logs and needed files if [ "$debug" = "true" ]; then - #forcefully use the logentries from today + # forcefully use the logentries from today collect_and_prepare today else # the normal routine diff --git a/script/teamspeak_log_xmpp-push.sh b/script/teamspeak_log_xmpp-push.sh index 96ad0b4..a7ad294 100644 --- a/script/teamspeak_log_xmpp-push.sh +++ b/script/teamspeak_log_xmpp-push.sh @@ -20,14 +20,18 @@ # run this script every x minutes to send the lines accumulated in the log files via cron eg # */x * * * * /PATH/teamspeak_log_xmpp-push.sh -#variables +#### Settings #### + +# variables tmp_directory=/tmp/teamspeak/xmpp_push tslogs=/etc/teamspeak3-server_linux_amd64/logs configfile=$tmp_directory/.user.config configfile_secured=$tmp_directory/.tmp.config backupconf=/var/backups/teamspeak_log_xmpp-push_user.config -#### DONT CHANGE FROM HERE #### +#### Business logic #### +#### DO NOT ALTER #### + # compositon variables composition1=$tmp_directory/composition1.txt composition2=$tmp_directory/composition2.txt @@ -52,7 +56,8 @@ currentday=$(date -u '+%Y-%m-%d') # debug parameter debug=false -###### PRE RUN FUNCTION SECTION ###### +#### PRE RUN FUNCTION SECTION #### + prerun_check() { needed_commands="rm ls echo grep sort cat date sendxmpp" @@ -69,18 +74,18 @@ prerun_check() exit 11 fi - #check if tmp directory is present if not create it + # check if tmp directory is present if not create it if [ ! -d "$tmp_directory" ]; then mkdir -p $tmp_directory fi - #first run check + # first run check if [ ! -f "$configfile" ]; then if [ -f "$backupconf" ]; then echo -e "no config inside $tmp_directory using $backupconf" cp "$backupconf" "$configfile" else - #config file is not present + # config file is not present echo -e "no config file has been set. copy the sample config file to $configfile" exit 10 fi @@ -98,15 +103,15 @@ prerun_check() # source the config file source "$configfile" - #is the history relevant? - #check if date file is present + # is the history relevant? + # check if date file is present if [ ! -f "$tmp_directory/date.txt" ]; then date -u '+%Y-%m-%d' > $tmp_directory/date.txt fi if [ ! "$currentday" = "$(cat $tmp_directory/date.txt)" ]; then - #they are not the same remove the old history + # they are not the same remove the old history rm $log_history - #set the new date inside the date file + # set the new date inside the date file date -u '+%Y-%m-%d' > $tmp_directory/date.txt fi clearcomp -all @@ -115,17 +120,17 @@ prerun_check() collect_and_prepare() { ## log file selection - #get the currently used logfiles + # get the currently used logfiles ls -t $tslogs | head -n2 | sort > $logfiles - #from the $logfiles get everything from today + # from the $logfiles get everything from today grep "$(date -u '+%Y-%m-%d')" "$tslogs/$(sed -n '1p' $logfiles)" > $log_selection_today_unsorted grep "$(date -u '+%Y-%m-%d')" "$tslogs/$(sed -n '2p' $logfiles)" >> $log_selection_today_unsorted # sort logentries sort $log_selection_today_unsorted > $log_selection_today - #if $log_history file exists append if not create it + # if $log_history file exists append if not create it if [ -s $log_history ]; then #it does exist grep -v -F -x -f $log_history $log_selection_today > $log_removed_old @@ -138,7 +143,8 @@ collect_and_prepare() fi } -###### General Functions ###### +#### General Functions #### + clearcomp() { # check if there is a final composition push if true @@ -187,8 +193,9 @@ pushstuff() clearcomp -all } -###### FILTER CODE SECTION ###### -# Filter Server Messages Accounting/ ServerMain / Warning / ERROR / CIDRManager +#### FILTER CODE SECTION #### + +# filter server messages accounting/ ServerMain / Warning / ERROR / CIDRManager filter_server() { # only run this filter if $enable_server is true @@ -207,7 +214,7 @@ filter_server() fi } -# Filter complaints +# filter complaints filter_complaint() { # only run this filter if $enable_complaint is true @@ -226,7 +233,7 @@ filter_complaint() fi } -# Filter Kick messages +# filter kick messages filter_kick() { # only run this filter if $enable_kick is true @@ -245,7 +252,7 @@ filter_kick() fi } -# Filter Channels added /deleted / edited +# filter channels added / deleted / edited filter_channel() { # only run this filter if $enable_channel is true @@ -264,7 +271,7 @@ filter_channel() fi } -# Filter bans added / deleted and general BanManager messages +# filter bans added / deleted and general BanManager messages filter_ban() { # only run this filter if $enable_ban is true @@ -307,7 +314,7 @@ filter_ban() fi } -# Filter Group changes +# filter group changes filter_groups() { # only enable this filter if $enable_groups is true @@ -316,7 +323,7 @@ filter_groups() # only paste the results if there are if [ -s $composition1 ]; then - #filter created or copied group events + # filter created or copied group events grep -E "was copied by|was added by" $composition1 > $composition2 if [ -s $composition2 ]; then { echo -e "--- created/ copied ---\\n" @@ -365,34 +372,38 @@ filter_groups() fi } -###### MAIN CODE SECTION ###### -#run all preparations and inital checks +#### MAIN CODE SECTION #### + +# run all preparations and inital checks # clear old stuff clearcomp -all + # prepare folders and config files prerun_check + # collect and prepare logs and needed files collect_and_prepare + #debug parameters debug ## server filter_server -## Complaint +## complaint filter_complaint -## Ban +## ban filter_ban -## Kick +## kick filter_kick -## Group change +## group change filter_groups -## Channel +## channel filter_channel -## Push Message +## push message pushstuff From 990908c0837ffc2c23b09778763460539787bb99 Mon Sep 17 00:00:00 2001 From: Julian Merkle Date: Fri, 9 Mar 2018 13:23:58 +0100 Subject: [PATCH 4/4] Move filter logic in own file and source it --- script/filters.sh | 141 ++++++++++++++++++++++ script/teamspeak_log_daily_mail.sh | 144 +---------------------- script/teamspeak_log_xmpp-push.sh | 183 +---------------------------- 3 files changed, 151 insertions(+), 317 deletions(-) create mode 100644 script/filters.sh diff --git a/script/filters.sh b/script/filters.sh new file mode 100644 index 0000000..60fb57d --- /dev/null +++ b/script/filters.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +#### Filter File #### + +general_filter() +{ + # general filter which will shift through all positional parameters and filter for that + while [ "$1" ] + do + grep -E "$1" "$daily_log" | sort >> "$composition1" + + # only paste the results if there are any + if [ -s "$composition1" ]; then + { echo -e "------------------- $1 --------------------\\n" + cat "$composition1" + echo -e "----------------- $1 End ------------------\\n" + } >> "$message_body" + fi + clearcomp + shift + done +} + +filter_server() +{ + # generate report header with info from the systemd script + { echo -e "LogReport Teamspeak $(date -d "yesterday" '+%d.%m.%Y')\\n" + start_finish --teamspeak-start + # server section + echo -e "-------------------- Server -----------------------\\n" + echo -e "Status : $(systemctl status $service_script)\\n" + } >> "$message_body" + + # only run this filter if $enable_server is true + if [ "$enable_server" != "false" ]; then + general_filter "ServerMain|stopped" "ERROR" "WARNING" "Accounting" "CIDRManager" + fi + + echo -e "------------------ Server End ---------------------\\n" >> "$message_body" +} + +filter_group() +{ + # only run this filter if $enable_groups is true + if [ "$enable_groups" != "false" ]; then + grep -E "was deleted by|was copied by|was added to|was added by|was removed from" "$daily_log" | grep -v "permission '" >> "$composition1" + + # only paste the results if there are + if [ -s "$composition1" ]; then + echo -e "------------------ Group change -------------------" >> "$message_body" + + # filter for created or copied group events + grep -E "was copied by|was added by" $composition1 > $composition2 + if [ -s "$composition2" ]; then + { echo -e "--- created/ copied ---\\n" + cat "$composition2" + changed=true + } >> "$composition3" + fi + + # filter for deleted group events + grep "was deleted by" "$composition1" > "$composition2" + if [ -s "$composition2" ]; then + { echo -e "--- deleted ---\\n" + cat "$composition2" + changed=true + } >> "$composition3" + fi + + # filter if sombody was added to servergroup + grep "was added to" "$composition1" > "$composition2" + if [ -s "$composition2" ]; then + { echo -e "--- added to---\\n" + cat "$composition2" + changed=true + } >> "$composition3" + fi + + # filter if somebody was removed from a group + grep "was removed from" "$composition1" > "$composition2" + if [ -s "$composition2" ]; then + { echo -e "--- removed from---\\n" + cat "$composition2" + changed=true + } >> "$composition3" + fi + + # if "changed" is true then paste the results in the mask + if [ "$changed" = "true" ]; then + { echo -e "---- Group ----" + cat "$composition3" + echo -e "\\n---- Group End ----" + } >> "$message_body" + fi + echo -e "---------------- Group change End -----------------\\n" >> "$message_body" + fi + clearcomp + fi +} + +filter_channel() +{ + # only run this filter if $enable_channel is true + if [ "$enable_channel" != "false" ]; then + + # filter for channel creation events + grep "channel" "$daily_log" | grep "VirtualServerBase">> "$composition1" + + # only paste the results if there are + if [ -s "$composition1" ]; then + { echo -e "--------------------- Channel ---------------------\\n" + cat "$composition1" + echo -e "------------------- Channel End -------------------\\n" + } >> "$message_body" + fi + clearcomp + fi +} + +filter_user_activity() +{ + # only enable this filter if $enable_complaint is true + if [ "$enable_complaint" != "false" ]; then + general_filter "^complaint" + fi + + # only enable this filter if $enable_ban is true + if [ "$enable_ban" != "false" ]; then + general_filter "ban added|BanManager" + fi + + # only enalbe this filter if $enable_kick is true + if [ "$enable_kick" != "false" ]; then + general_filter "reason 'invokerid" + fi + + # only enable this filter if $enable_perm is true + if [ "$enable_perm" != "false" ]; then + general_filter "permission" + fi +} \ No newline at end of file diff --git a/script/teamspeak_log_daily_mail.sh b/script/teamspeak_log_daily_mail.sh index cac8b3d..f80b5ca 100644 --- a/script/teamspeak_log_daily_mail.sh +++ b/script/teamspeak_log_daily_mail.sh @@ -17,6 +17,9 @@ # replace mailaddr_to/_from and possibly the tslog path to fit your needs # place inside /etc/cron.daily to run this script on a daily basis +# cd into script directory +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + #### Settings #### # user specific config file @@ -164,145 +167,8 @@ send_mail() fi } -#### FILTER CODE SECTION #### - -general_filter() -{ - # general filter which will shift through all positional parameters and filter for that - while [ "$1" ] - do - grep -E "$1" "$daily_log" | sort >> "$composition1" - - # only paste the results if there are any - if [ -s "$composition1" ]; then - { echo -e "------------------- $1 --------------------\\n" - cat "$composition1" - echo -e "----------------- $1 End ------------------\\n" - } >> "$message_body" - fi - clearcomp - shift - done -} - -filter_server() -{ - # generate report header with info from the systemd script - { echo -e "LogReport Teamspeak $(date -d "yesterday" '+%d.%m.%Y')\\n" - start_finish --teamspeak-start - # server section - echo -e "-------------------- Server -----------------------\\n" - echo -e "Status : $(systemctl status $service_script)\\n" - } >> "$message_body" - - # only run this filter if $enable_server is true - if [ "$enable_server" != "false" ]; then - general_filter "ServerMain|stopped" "ERROR" "WARNING" "Accounting" "CIDRManager" - fi - - echo -e "------------------ Server End ---------------------\\n" >> "$message_body" -} - -filter_group() -{ - # only run this filter if $enable_groups is true - if [ "$enable_groups" != "false" ]; then - grep -E "was deleted by|was copied by|was added to|was added by|was removed from" "$daily_log" | grep -v "permission '" >> "$composition1" - - # only paste the results if there are - if [ -s "$composition1" ]; then - echo -e "------------------ Group change -------------------" >> "$message_body" - - # filter for created or copied group events - grep -E "was copied by|was added by" $composition1 > $composition2 - if [ -s "$composition2" ]; then - { echo -e "--- created/ copied ---\\n" - cat "$composition2" - changed=true - } >> "$composition3" - fi - - # filter for deleted group events - grep "was deleted by" "$composition1" > "$composition2" - if [ -s "$composition2" ]; then - { echo -e "--- deleted ---\\n" - cat "$composition2" - changed=true - } >> "$composition3" - fi - - # filter if sombody was added to servergroup - grep "was added to" "$composition1" > "$composition2" - if [ -s "$composition2" ]; then - { echo -e "--- added to---\\n" - cat "$composition2" - changed=true - } >> "$composition3" - fi - - # filter if somebody was removed from a group - grep "was removed from" "$composition1" > "$composition2" - if [ -s "$composition2" ]; then - { echo -e "--- removed from---\\n" - cat "$composition2" - changed=true - } >> "$composition3" - fi - - # if "changed" is true then paste the results in the mask - if [ "$changed" = "true" ]; then - { echo -e "---- Group ----" - cat "$composition3" - echo -e "\\n---- Group End ----" - } >> "$message_body" - fi - echo -e "---------------- Group change End -----------------\\n" >> "$message_body" - fi - clearcomp - fi -} - -filter_channel() -{ - # only run this filter if $enable_channel is true - if [ "$enable_channel" != "false" ]; then - - # filter for channel creation events - grep "channel" "$daily_log" | grep "VirtualServerBase">> "$composition1" - - # only paste the results if there are - if [ -s "$composition1" ]; then - { echo -e "--------------------- Channel ---------------------\\n" - cat "$composition1" - echo -e "------------------- Channel End -------------------\\n" - } >> "$message_body" - fi - clearcomp - fi -} - -filter_user_activity() -{ - # only enable this filter if $enable_complaint is true - if [ "$enable_complaint" != "false" ]; then - general_filter "^complaint" - fi - - # only enable this filter if $enable_ban is true - if [ "$enable_ban" != "false" ]; then - general_filter "ban added|BanManager" - fi - - # only enalbe this filter if $enable_kick is true - if [ "$enable_kick" != "false" ]; then - general_filter "reason 'invokerid" - fi - - # only enable this filter if $enable_perm is true - if [ "$enable_perm" != "false" ]; then - general_filter "permission" - fi -} +# Source filters +source "${DIR}/filters.sh" #### MAIN CODE SECTION #### diff --git a/script/teamspeak_log_xmpp-push.sh b/script/teamspeak_log_xmpp-push.sh index a7ad294..c881fd5 100644 --- a/script/teamspeak_log_xmpp-push.sh +++ b/script/teamspeak_log_xmpp-push.sh @@ -20,6 +20,9 @@ # run this script every x minutes to send the lines accumulated in the log files via cron eg # */x * * * * /PATH/teamspeak_log_xmpp-push.sh +# cd into script directory +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + #### Settings #### # variables @@ -193,184 +196,8 @@ pushstuff() clearcomp -all } -#### FILTER CODE SECTION #### - -# filter server messages accounting/ ServerMain / Warning / ERROR / CIDRManager -filter_server() -{ - # only run this filter if $enable_server is true - if [ "$enable_server" != false ]; then - grep -E 'ServerMain|stopped|Accounting|Warning|ERROR|CIDRManager' $log_removed_old >> $composition1 - - # only paste the results if there are - if [ -s $composition1 ]; then - { echo -e "\\n---- Server ----\\n" - cat $composition1 - echo -e "\\n---- Server End ----" - } >> $server - cat $server >> $final_composition - fi - clearcomp - fi -} - -# filter complaints -filter_complaint() -{ - # only run this filter if $enable_complaint is true - if [ "$enable_complaint" != false ]; then - grep "^complaint" $log_removed_old >> $composition1 - - # only paste the results if there are - if [ -s $composition1 ]; then - { echo -e "\\n---- Complaint ----\\n" - cat $composition1 - echo -e "\\n---- Complaint End ----" - } >> $complaint - cat $complaint >> $final_composition - fi - clearcomp - fi -} - -# filter kick messages -filter_kick() -{ - # only run this filter if $enable_kick is true - if [ "$enable_kick" != false ]; then - grep "reason 'invokerid" $log_removed_old | grep -v "bantime" >> $composition1 - - # only paste the results if there are - if [ -s $composition1 ]; then - { echo -e "\\n---- Kick ----\\n" - cat $composition1 - echo -e "\\n---- Kick End ----" - } >> $kick - cat $kick >> $final_composition - fi - clearcomp - fi -} - -# filter channels added / deleted / edited -filter_channel() -{ - # only run this filter if $enable_channel is true - if [ "$enable_channel" != false ];then - grep "channel" $log_removed_old | grep VirtualServerBase > $composition1 - - # only paste the results if there are - if [ -s $composition1 ]; then - { echo -e "\\n---- Channel ----\\n" - cat $composition1 - echo -e "\\n---- Channel End ----" - } >> $channel - cat $channel >> $final_composition - fi - clearcomp - fi -} - -# filter bans added / deleted and general BanManager messages -filter_ban() -{ - # only run this filter if $enable_ban is true - if [ "$enable_ban" != false ]; then - # first collect all ban related events - grep -E 'ban added|BanManager|ban deleted' $log_removed_old >> $composition1 - - # only paste the results if there are - if [ -s $composition1 ]; then - # filter added bans - grep -E 'ban added' $composition1 > $composition2 - if [ -s $composition2 ]; then - { echo -e "--- Ban added ---\\n" - cat $composition2 - # change the "changed" value to true to indicate something has changed - changed=true - } >> $composition3 - fi - - # filter deleted bans - grep -E 'BanManager|ban deleted' $composition1 > $composition2 - if [ -s $composition2 ]; then - { echo -e "--- Ban deleted ---\\n" - cat $composition2 - # change the "changed" value to true to indicate something has changed - changed=true - } >> $composition3 - fi - fi - - # if "changed" is true paste the results in this mask - if [ "$changed" = true ]; then - { echo -e "\\n---- Ban ----" - cat $composition3 - echo -e "\\n---- Ban End ----" - }>> $ban - cat $ban >> $final_composition - fi - clearcomp - fi -} - -# filter group changes -filter_groups() -{ - # only enable this filter if $enable_groups is true - if [ "$enable_groups" != false ]; then - grep -E "was deleted by|was copied by|was added to|was added by|was removed from" $log_removed_old | grep -v "permission '" > $composition1 - - # only paste the results if there are - if [ -s $composition1 ]; then - # filter created or copied group events - grep -E "was copied by|was added by" $composition1 > $composition2 - if [ -s $composition2 ]; then - { echo -e "--- created/ copied ---\\n" - cat $composition2 - changed=true - } >> $composition3 - fi - - # filter deleted group events - grep "was deleted by" $composition1 > $composition2 - if [ -s $composition2 ]; then - { echo -e "--- deleted ---\\n" - cat $composition2 - changed=true - } >> $composition3 - fi - - # filter somebodys group changed - grep "was added to" $composition1 > $composition2 - if [ -s $composition2 ]; then - { echo -e "--- added to---\\n" - cat $composition2 - changed=true - } >> $composition3 - fi - - # filter somebody got removed from a group - grep "was removed from" $composition1 > $composition2 - if [ -s $composition2 ]; then - { echo -e "--- removed from---\\n" - cat $composition2 - changed=true - } >> $composition3 - fi - fi - - # if "changed" = true paste all results in this mask - if [ "$changed" = true ]; then - { echo -e "\\n---- Group ----" - cat $composition3 - echo -e "\\n---- Group End ----" - } >> $groupchange - cat $groupchange >> $final_composition - fi - clearcomp - fi -} +# Source filters +source "${DIR}/filters.sh" #### MAIN CODE SECTION ####