forked from gcoop-libre/freeipa-sssd-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipa-sss-dff
executable file
·323 lines (240 loc) · 5.52 KB
/
ipa-sss-dff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/bin/bash
# This script comes with ABSOLUTELY NO WARRANTY, use at own risk
# Copyright (C) 2021 Osiris Alejandro Gomez <osiris@gcoop.coop>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# shellcheck disable=SC1090
# shellcheck disable=SC1091
# shellcheck disable=SC2002
DIR_BIN="$(dirname "$0")" && source "$DIR_BIN/ipa-src-cfg"
function usage()
{
cat << EOF
## \`$BIN\` show attributes differences between sync requests from log
### Usage:
\`\`\`bash
$BIN [IPA_SSS_SYN_LOG]
\`\`\`
### Description
Show attributes differences between user sync requests from log
Attributes list:
\`\`\`
user
sAMAccountName
lockoutTime
pwdLastSet
pwdExpireDate
pwdExpireDays
pwdExpired
physicalDeliveryOfficeName
lastLogon
userAccountControl
adUserAccountControl
accountExpires
accountExpireDays
accountExpired
adAccountExpires
dataExpireTimestamp
sss_cache
newDataExpireTimestamp
newAdUserAccountControl
newAdAccountExpires
error
seconds
\`\`\`
### Example:
\`\`\`bash
$BIN
\`\`\`
See full example output in [\`ipa-sss-dff.md\`](examples/ipa-sss-dff.md)
and [\`ipa-sss-dff.pdf\`](examples/ipa-sss-dff.pdf)
EOF
exit 0
}
[[ "$1" =~ ^[-]+(h|help) ]] && usage
function defaults()
{
NOW="$(date +%F)"
LOG='ipa-sss-syn.log'
ATTR="$(cat << EOF
user
sAMAccountName
lockoutTime
pwdLastSet
pwdExpireDate
pwdExpireDays
pwdExpired
physicalDeliveryOfficeName
lastLogon
userAccountControl
adUserAccountControl
accountExpires
accountExpireDays
accountExpired
adAccountExpires
dataExpireTimestamp
sss_cache
newDataExpireTimestamp
newAdUserAccountControl
newAdAccountExpires
error
seconds
EOF
)"
}
function params()
{
[[ -z "$1" ]] || LOG="$1"
[[ -e "$LOG" ]] || die "NOT FOUND FILE $LOG"
NAME="$(basename "$LOG" .log)"
OUT="${DIR_PDF}/${NAME}.md"
[[ -z "$2" ]] || OUT="$2"
ATTRS="$(mktemp)"
echo "$ATTR" > "$ATTRS"
}
function validate()
{
[[ -z "$DIR_TMP" ]] && cfg "DIR_TMP"
[[ -d "$DIR_TMP" ]] || die "NOT FOUND DIRECTORY $DIR_TMP"
[[ -z "$DIR_PDF" ]] && cfg "DIR_PDF"
[[ -d "$DIR_PDF" ]] || die "NOT FOUND DIRECTORY $DIR_PDF"
}
function header()
{
TITLE="diff attributes $LOG"
cat << EOF
---
date: $NOW
title: $TITLE
author: CC-BY-SA Osiris Alejandro Gomez osiris@gcoop.coop
fontsize: 8pt
classoption: landscape
---
EOF
}
function clean_dir_file()
{
find "$1" -type f -iname "$2" -exec rm -f {} \;
}
function split_ipa()
{
split -d -l 6 "$TMP" "$DIR_TMP/ipasplit"
}
function get_value()
{
grep -wE "^$1" "$2" | head -1 | awk '{print $2}'
}
function pagebreak()
{
printf "\\n%s\\n" '\pagebreak'
}
function log2diff()
{
TMP="$(mktemp)"
USR="$(mktemp)"
grep -Eo 'sAMAccountName=[0-9a-z]+' "$LOG" \
| sort -u \
| cut -d '=' -f2 > "$USR"
while read -r U
do
grep "$U" "$LOG" | while read -r L
do
DT="$(echo "$L" | cut -d ' ' -f-2 | tr -d '-' | tr ' ' '-' | tr -d ':')"
F="$DIR_TMP/$U-$DT.ipa"
echo "$L" | tr ' ' '\n' | tr '=' ' ' | align2col > "$F"
done
find "$DIR_TMP" -maxdepth 1 -type f -iname "$U-*.ipa" \
| rev \
| cut -d '/' -f1 \
| rev \
| sort > "$TMP"
clean_dir_file "$DIR_TMP" 'ipasplit*'
split_ipa
find "$DIR_TMP" -maxdepth 1 -type f -iname "ipasplit*" \
| sort \
| while read -r SPLIT
do
printf "\\n## \`%s\`\\n\\n" "$U"
printf "| \`%-26s\` " "ATTR"
while read -r F
do
D="$(echo "$F" | cut -d '-' -f3 | cut -d '.' -f1)"
TT="$(echo "$F" | cut -d '-' -f2)"
DD="$(date -d "$TT" +'%F')"
HH="$(echo "$D" | cut -c -2)"
MM="$(echo "$D" | cut -c 3-)"
printf "| \`%20s\` " "$DD $HH:$MM"
done < "$SPLIT"
printf "|\\n"
printf "|------------------------------"
while read -r F
do
printf "|------------------------"
done < "$SPLIT"
printf "|\\n"
LAST='START'
cat "$ATTRS" | while read -r A
do
printf "| \`%-26s\` " "$A"
cat "$SPLIT" | while read -r F
do
V="$(get_value "$A" "$DIR_TMP/$F")"
[[ -z "$V" ]] && V=' '
if [[ "$LAST" != 'START' ]]
then
if [[ "$A" != 'seconds' ]]
then
if [[ "$LAST" != "$V" ]]
then
VAL="**\`$V\`**"
else
VAL="\`$V\`"
[[ -z "$V" ]] && VAL="\` \`"
fi
fi
else
if [[ "$A" = 'pwdLastSet' ]]
then
if [[ "${V%%"T"*}" = '1970-01-01' ]]
then
VAL="**\`$V\`**"
else
VAL="\`$V\`"
fi
else
VAL="\`$V\`"
[[ -z "$V" ]] && VAL="\` \`"
fi
fi
printf "| %22s " "$VAL"
LAST="$V"
done
printf "|\\n"
done
pagebreak
done
done < "$USR" >> "$OUT" && echo "$OUT"
#FIXME rm -f "$TMP"
}
function main()
{
config
defaults
params "$@"
validate
clean_dir_file "$DIR_TMP" '*.ipa'
header > "$OUT"
log2diff
}
main "$@"