-
Notifications
You must be signed in to change notification settings - Fork 17
/
replace_nagioscore_logo.sh
181 lines (134 loc) · 5.59 KB
/
replace_nagioscore_logo.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
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
#!/bin/bash
# This script is used to replace the logo used on a Nagios Core servers web GUI logos with your own image
USAGE="
SYNTAX: $0 [-h] -u <url> | [ -f <file> ]
DESCRIPTION:
This script is used to replace the Nagios Core web GUI logos with your company logo.
There are two logos to replace. The loging logo and the smaller logo you see after sign in.
REQUIREMENTS:
1.) Access to a website hosting or a file location for your company logo
2.) Wget or Curl command to download files
3.) PNG file type logo
4.) Not required but for asthetics the dimensions should be 142x40
CONTACT INFORMATION
Company: OsbornePro LLC.
Website: https://osbornepro.com
Author: Robert H, Osborne
Contact: [email protected]
USAGE: $0 [-u <url>] [-f <file path>] [[-m]||[-s]]
OPTIONS:
-h : Displays the help information for the command.
-u : Set the URL to download your logo file from
-f : Set the path to your logo file
-m : Replace only the Nagios Core Login logo (Anything under 500 pixels width and height should look pretty good)
-s : Replace only the Nagios Core GUI logo in the top left of window after logging in (Recommended size is 142x40)
EXAMPLES:
$0 -u https://customwebsite.domain.com/your-logo.png
# This example replaces the both the main Nagios Core login logo and small in the GUI logo with a company logo downloaded from https://customwebsite.domain.om/your-logo.png
$0 -f ~/Pictures/logo.png
# This example replaces the both the main Nagios Core login logo and small in the GUI logo with a company logo using the file ~/Pictures.logo.png
$0 -u https://customwebsite.domain.com/your-logo.png -m
# This example replaces the main Nagios Core login logo with a company logo downloaded from https://customwebsite.domain.om/your-logo.png
$0 -f ~/Pictures/logo.png -s
# This example replaces the small GUI Nagios Core logo with a company logo using the file ~/Pictures.logo.png
"
# VARIABLES
NAGIOSLOGOFILES=("/usr/local/nagios/html/images/sblogo.png" "/usr/local/nagios/share/images/sblogo.png" "/var/www/html/images/sblogo.png" "/usr/local/nagios/html/images/logofullsize.png" "/usr/local/nagios/share/images/logofullsize.png" "/var/www/html/images/logofullsize.png")
DLFILE="/tmp/company-logo.png"
# FUNCTIONS
function allow_ctrlc {
# Allow Ctrl+C to stop execution
trap '
trap - INT # restore default INT handler
kill -s INT "$$"
' INT
} # End function allow_ctrlc
function print_usage {
printf "$USAGE\n" >&2
exit 1
} # End function print_usage
function get_download_command {
if which wget > /dev/null; then
wget --no-check-certificate $URL -O $DLFILE
elif which curl > /dev/null; then
curl -skL $URL -O $DLFILE
else
printf "[x] You do not have a way to download your image file. Install wget or curl and try again. \n\tDEBIAN: sudo apt update && sudo apt install -y wget \n\tFEDORA: sudo dnf install -y wget"
exit 1
fi
} # End function get_download_command
function verify_file_type {
FILEID=$(file "${DLFILE}" | cut -d" " -f2)
if [ "${FILEID}" != "PNG" ]; then
printf "[x] You are required to use a PNG file type \n"
exit 1
fi
} # End function verify_type
function backup_nagios_logo {
if [ -f "$NAGIOSLOGOFILES" ]; then
printf "[*] Backing up original Nagios Core logo files \n"
for F in "${NAGIOSLOGOFILES[@]}"; do
if [ -f "${F}.orig" ]; then
cp "${F}" "${F}.bak"
else
cp "${F}" "${F}.orig"
fi
done
else
printf "[x] Expected sblogo.png Nagios Logo file was not found at \n"
exit 1
fi
} # End function backup_nagios_logo
function update_logo {
if [ -f $DLFILE ]; then
printf "[*] Updating the Nagios Core web GUI logo with your image \n"
for F in "${NAGIOSLOGOFILES[@]}"; do
cp "${DLFILE}" "${F}"
done
elif [ -f $LOGOFILE ]; then
printf "[*] Updating the Nagios Core web GUI logo with your image \n"
for F in "${NAGIOSLOGOFILES[@]}"; do
cp "${LOGOFILE}" "${F}"
done
else
printf "[x] Unable to find the replacement logo file \n"
fi
} # End function update_logo
function file_cleanup {
if [ -f "${DLFILE}" ]; then
rm -rf -- "${DLFILE}"
fi
printf "[*] You will need to restart the hosting web service (apache,nginx,etc.) to display your new logo \n"
} # End function file_cleanup
# EXECUTION
while [ ! -z "$1" ]; do
case "$1" in
-u)
shift
URL=$1
get_download_command
wait
verify_file_type
;;
-f)
shift
LOGOFILE=$1
;;
-m)
shift
NAGIOSLOGOFILES=("/usr/local/nagios/html/images/logofullsize.png" "/usr/local/nagios/share/images/logofullsize.png" "/var/www/html/images/logofullsize.png")
;;
-s)
shift
NAGIOSLOGOFILES=("/usr/local/nagios/html/images/sblogo.png" "/usr/local/nagios/share/images/sblogo.png" "/var/www/html/images/sblogo.png")
;;
*)
print_usage
;;
esac
shift
done
allow_ctrlc
backup_nagios_logo
update_logo
file_cleanup