-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysdDepViewer.sh
101 lines (93 loc) · 3.21 KB
/
sysdDepViewer.sh
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
#!/bin/bash
LINK="plot.html"
tee -a <<EOL
.___
_________.__. ______ __| _/
/ ___< | |/ ___// __ |
\___ \ \___ |\___ \/ /_/ |
/____ >/ ____/____ >____ |
\/ \/ \/ \/ Dependency Viewer. By @lakabd
EOL
echo -n "[+] Retrieving services..."
service_names=($(systemd-analyze plot | grep '\"left' | awk -F '>' '{print $2}'| awk -F '<' '{print $1}'| awk -F ' ' '{print $1}'))
#removing kernel and systemd from array
service_names=("${service_names[@]:1}")
service_names=("${service_names[@]:1}")
#removing svg legend keywords from array
unset service_names[${#service_names[@]}-1]
unset service_names[${#service_names[@]}-1]
unset service_names[${#service_names[@]}-1]
unset service_names[${#service_names[@]}-1]
unset service_names[${#service_names[@]}-1]
unset service_names[${#service_names[@]}-1]
echo "done !"
echo -n "[+] Html parsing..."
flag=0
echo "<!-- Systemd Dependency Viewer v1.0 -->" > $LINK
while IFS= read -r line
do
echo "$line" | grep '<rect.*x="[0-9][0-9]' &> /dev/null
if [ $? -eq 0 ]; then
if [ $flag -eq 0 ]; then
echo "</a><a style='cursor: pointer;' onclick='javascript:sysdDep(this);'>" >> $LINK
fi
echo $line >> $LINK
flag=1
else
echo $line >> $LINK
flag=0
fi
done <<< $(systemd-analyze plot)
tee -a $LINK > /dev/null <<EOL
<script>
function sysdDep(element){
if (element.getElementsByClassName('left')[0].innerHTML.split(" ")[0] != null){
service_name=element.getElementsByClassName('left')[0].innerHTML.split(" ")[0];
}
else{
service_name=element.getElementsByClassName('right')[0].innerHTML.split(" ")[0];
}
if (document.getElementsByClassName(service_name)[0] != null){
dotsrc=document.getElementsByClassName(service_name)[0].textContent;
}
else{
alert(service_name + " have no dependency !")
return;
}
var svg=Viz(dotsrc,"svg");
console.log(svg);
var tempDiv = document.createElement('div');
tempDiv.innerHTML = svg;
var svg_width=(parseInt(tempDiv.getElementsByTagName("svg")[0].getAttribute("width").split('pt')[0])*4.2)/3; //pt to px
var svg_height=(parseInt(tempDiv.getElementsByTagName("svg")[0].getAttribute("height").split('pt')[0])*4.6)/3; //pt to px
var legend= "<div style='margin: auto;text-align: center;'> \
<span style='color:black'>Requires - </span> \
<span style='color:DarkBlue'>Requisite - </span> \
<span style='color:DarkGrey'>Wants - </span> \
<span style='color:red'>Conflicts - </span> \
<span style='color:green'>After - </span> \
</div> \
"
var win = window.open("", "Systemd Dep By lakabd", "width="+svg_width+",height="+svg_height+","+"location=no,menubar=no,status=no,resizable=no");
win.document.write(svg);
win.document.write(legend);
tempDiv.remove();
}
</script>
<script src="https://lakabd.github.io/viz.js" type="text/javascript" charset="utf-8"></script>
EOL
echo "done !"
sleep 0.5
echo "[+] Retrieving dependencies (in DOT format) for:"
sleep 1
for service in "${service_names[@]}"
do
OUTPUT=$(systemd-analyze dot $service 2>/dev/null)
if [ $? -eq 0 ]; then
echo "<div class='$service' style='display: none'>" >> $LINK
echo $OUTPUT >> $LINK
echo "</div>" >> $LINK
echo -e "\t -> $service"
fi
done
echo "[+] $LINK created succesfully !"