-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-wpid
executable file
·430 lines (403 loc) · 11.6 KB
/
no-wpid
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#!/bin/bash
# ----------------------------------------------------------------------------------------------------
# no-wpid: simple script to null/enable WordPress readme.html and license.txt files on a cPanel server
# no-wpid Version: 1.0
# Github: https://github.com/InterGenStudios/no-wpid
# ---------------------------------------------------
# InterGenStudios: 5-12-15
# Copyright (c) 2015: Christopher 'InterGen' Cork InterGenStudios
# URL: https://intergenstudios.com
# --------------------------------
# License: GPL-2.0+
# URL: http://opensource.org/licenses/gpl-license.php
# ---------------------------------------------------
# no-wpid is free software:
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software
# Foundation, either version 2 of the License, or (at your discretion)
# any later version.
# ------------------
#############################################
##-----------------------------------------##
## BEGIN - MAKE SURE WE'RE RUNNING AS ROOT ##
##-----------------------------------------##
#############################################
if [ "$(id -u)" != "0" ]; then
tput bold
tput setaf 1
printf "\n\n"
echo "--------"
echo "WARNING!"
echo "--------"
echo
tput sgr0
echo "no-wpid must be run as root!"
echo "(Exiting now...)"
printf "\n\n"
exit 1
fi
###########################################
##---------------------------------------##
## END - MAKE SURE WE'RE RUNNING AS ROOT ##
##---------------------------------------##
###########################################
#######################
##-------------------##
## BEGIN - FUNCTIONS ##
##-------------------##
#######################
# Colors trailing text Red
RED () {
tput bold
tput setaf 1
}
# Colors trailing text Green
GREEN () {
tput bold
tput setaf 2
}
# Colors trailing text Yellow
YELLOW () {
tput bold
tput setaf 3
}
# Colors trailing text Blue
BLUE () {
tput bold
tput setaf 4
}
# Clears any preceding text color declarations
WHITE () {
tput sgr0
}
# Simple divider
SEPARATOR () {
GREEN
echo
echo "----------------------------"
echo
WHITE
}
# Simple divider
SEPARATOR_WHITE () {
WHITE
echo "------------------------------------------------------------------"
}
# Creates uniform look during script execution when called after any clear command
HEADER () {
echo
BLUE
echo "============================================================================"
WHITE
echo " no-wpid v1.0"
BLUE
echo "============================================================================"
WHITE
printf "\n\n"
}
# Blocks readme.html and license.txt files in WordPress installations
BLOCK () {
if [ -f /home/"$USR"/public_html/readme.html ]; then
clear
HEADER
BLUE
printf "Checking for WordPress Identifiers in account "
WHITE
printf "\"$USR\"\n"
for identifier in $(find /home/"$USR"/public_html -type f -name "LICENSE.*" -o -name "license.*" -o -name "readme.*" -o -name "README.*"); do
chown nobody:nobody "$identifier" && chmod 000 "$identifier" && echo "$USR" >> userlist
done
else
clear
HEADER
BLUE
printf "Checking for WordPress Identifiers in account "
WHITE
printf "\"$USR\"\n"
echo "$USR" >> noidfoundlist
fi
clear
HEADER
BLUE
echo "Wordpress Identifiers blocked for account(s):"
echo
WHITE
cat userlist | uniq
SEPARATOR
if [ -e noidfoundlist ]; then
echo "No readme.* or license.* files found for account(s):"
echo
WHITE
cat noidfoundlist | uniq
fi
printf "\n\n"
WHITE
}
# Unblocks readme.html and license.txt files in WordPress installatins (to allow for upgrading)
UNBLOCK () {
if [ -f /home/"$USR"/public_html/readme.html ]; then
clear
HEADER
BLUE
printf "Checking for WordPress Identifiers in account "
WHITE
printf "\"$USR\"\n"
echo
for identifier in $(find /home/"$USR"/public_html -type f -name "LICENSE.*" -o -name "license.*" -o -name "readme.*" -o -name "README.*"); do
chown "$USR":"$USR" "$identifier" && chmod 644 "$identifier" && echo "$USR" >> userlist
done
else
clear
HEADER
BLUE
printf "Checking for WordPress Identifiers in account "
tput sgr0
printf "\"$USR\"\n"
echo "$USR" >> noidfoundlist
fi
clear
HEADER
BLUE
echo "Wordpress Identifiers unblocked for account(s):"
echo
WHITE
cat userlist | uniq
SEPARATOR
if [ -e noidfoundlist ]; then
echo "No readme.* or license.* files found for account(s):"
echo
WHITE
cat noidfoundlist | uniq
fi
printf "\n\n"
WHITE
}
# Routes for all users
ALL_USERS () {
clear
HEADER
GREEN
echo "Which operation are we performing?"
echo
echo " 1) Blocking"
echo
echo " 2) Unblocking"
echo
WHITE
echo -n "[enter selection]: "
read CHOICE
case $CHOICE in
1) for USR in $(grep \: /etc/trueuserdomains | grep -v nobody | awk '{print $2}' | uniq); do
if [ -f /home/"$USR"/public_html/readme.html ]; then
clear
HEADER
BLUE
printf "Checking for WordPress Identifiers in account "
WHITE
printf "\"$USR\"\n"
for identifier in $(find /home/"$USR"/public_html -type f -name "LICENSE.*" -o -name "license.*" -o -name "readme.*" -o -name "README.*"); do
chown nobody:nobody "$identifier" && chmod 000 "$identifier" && echo "$USR" >> userlist
done
else
clear
HEADER
BLUE
printf "Checking for WordPress Identifiers in account "
WHITE
printf "\"$USR\"\n"
echo "$USR" >> noidfoundlist
fi
done
clear
HEADER
BLUE
echo "Wordpress Identifiers blocked for account(s):"
echo
WHITE
cat userlist | uniq
SEPARATOR
if [ -e noidfoundlist ]; then
YELLOW
echo "No readme.* or license.* files found for account(s):"
echo
WHITE
cat noidfoundlist | uniq
fi
printf "\n\n"
WHITE;;
2) for USR in $(grep \: /etc/trueuserdomains | grep -v nobody | awk '{print $2}' | uniq); do
if [ -f /home/"$USR"/public_html/readme.html ]; then
clear
HEADER
BLUE
printf "Checking for WordPress Identifiers in account "
WHITE
printf "\"$USR\"\n"
echo
for identifier in $(find /home/"$USR"/public_html -type f -name "LICENSE.*" -o -name "license.*" -o -name "readme.*" -o -name "README.*"); do
chown "$USR":"$USR" "$identifier" && chmod 644 "$identifier" && echo "$USR" >> userlist
done
else
clear
HEADER
BLUE
printf "Checking for WordPress Identifiers in account "
tput sgr0
printf "\"$USR\"\n"
echo "$USR" >> noidfoundlist
fi
done
clear
HEADER
BLUE
echo "Wordpress Identifiers unblocked for account(s):"
echo
WHITE
cat userlist | uniq
SEPARATOR
if [ -e noidfoundlist ]; then
YELLOW
echo "No readme.* or license.* files found for account(s):"
echo
WHITE
cat noidfoundlist | uniq
fi
printf "\n\n"
WHITE;;
esac
}
# Routes for single users
SINGLE_USER () {
NC='^[0-9]+$'
clear
HEADER
GREEN
echo "Which account are we adjusting WordPress Identifiers for? "
SEPARATOR
WHITE
grep \: /etc/trueuserdomains | grep -v nobody | awk '{print $2}' | uniq > accountlist
sed = accountlist | sed 'N;s/\n/\t/' > accountchoices
cat accountchoices
echo
SEPARATOR
WHITE
echo -n "Select account [q for quit]? "
read ACCOUNT_CHOICE
if [ "$(echo "$ACCOUNT_CHOICE")" = "Q" ] || [ "$(echo "$ACCOUNT_CHOICE")" = "q" ]; then
printf "\n\n"
RED
echo "Quiting..."
rm -rf accountlist accountchoices
WHITE
sleep 1
clear
exit 0
else
# Loop the script if an invalid choice is given
if ! [[ $ACCOUNT_CHOICE =~ $NC ]]; then
echo
RED
echo "\"$ACCOUNT_CHOICE\" is not a valid selection."
echo
echo "Restarting..."
sleep 2
SINGLE_USER
else
# Setting 1st match (-m 1) ensures $ doesn't confuse grep when there's also $$, $$$, $$$$, etc
USR="$(grep -m 1 "$ACCOUNT_CHOICE" accountchoices | awk '{print $2}')"
rm -rf accountlist accountchoices
if [ "$USR" != "$(grep "$USR" /etc/passwd | cut -d ':' -f 1)" ]; then
clear
HEADER
WHITE
printf "\"$USR\""
RED
printf " isn't a valid user on this server, Sparky... run it again...\n"
echo
SEPARATOR
sleep 2
SINGLE_USER
else
clear
HEADER
GREEN
echo "Which operation are we performing?"
echo
echo " 1) Blocking"
echo
echo " 2) Unblocking"
echo
WHITE
echo -n "[enter selection]:"
read CHOICE
case $CHOICE in
1) BLOCK;;
2) UNBLOCK;;
esac
fi
fi
fi
}
#####################
##-----------------##
## END - FUNCTIONS ##
##-----------------##
#####################
#########################
##---------------------##
## BEGIN - CORE SCRIPT ##
##---------------------##
#########################
case $1 in
-u) for USR in $(grep \: /etc/trueuserdomains | grep -v nobody | awk '{print $2}' | uniq); do
for identifier in $(find /home/"$USR"/public_html -type f -name "LICENSE.*" -o -name "license.*" -o -name "readme.*" -o -name "README.*"); do
chown "$USR":"$USR" "$identifier" && chmod 644 "$identifier" >/dev/null 2>&1
done
done
;;
-b) for USR in $(grep \: /etc/trueuserdomains | grep -v nobody | awk '{print $2}' | uniq); do
for identifier in $(find /home/"$USR"/public_html -type f -name "LICENSE.*" -o -name "license.*" -o -name "readme.*" -o -name "README.*"); do
chown nobody:nobody "$identifier" && chmod 000 "$identifier" >/dev/null 2>&1
done
done
;;
*) clear
HEADER
GREEN
echo
printf "Are we adjusting WordPress Identifiers for the entire server "
WHITE
echo -n "[y/n]? "
old_stty_cfg=$(stty -g)
stty raw -echo
answer="$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )"
stty $old_stty_cfg
if echo "$answer" | grep -iq "^y" ;then
echo
ALL_USERS
if [ -f userlist ]; then
rm -rf userlist
fi
if [ -f noidfoundlist ]; then
rm -rf noidfoundlist
fi
printf "\n\n"
exit 0
else
echo
SINGLE_USER
if [ -f userlist ]; then
rm -rf userlist
fi
if [ -f noidfoundlist ]; then
rm -rf noidfoundlist
fi
fi
exit 0
;;
esac
#######################
##-------------------##
## END - CORE SCRIPT ##
##-------------------##
#######################