-
Notifications
You must be signed in to change notification settings - Fork 3
/
drupaloscopy.sh
executable file
·98 lines (82 loc) · 3.33 KB
/
drupaloscopy.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
#!/bin/bash
# Init variables.
drupalmajor=""
drupalversion=""
versionstatus=""
versionstylestatus="warning"
# Clear tmp and create new one.
tmpdirectory=tmp-`date '+%Y%m%d%H%M%S'`-$$
rm -Rf $tmpdirectory
mkdir $tmpdirectory
cd $tmpdirectory
# If drush cannot be found, use drush_script.
# File drush_script has to be created manually with path to drush.
drush="drush"
if [ -f ../drush_script ]; then
drush=`cat ../drush_script`
fi
# Get Drupal major version from Drupal version.
getDrupalMajorFromDrupalVersion() {
drupalmajor=`echo $drupalversion | cut -d'.' -f1`
}
getLastDrupalVersion ()
{
# No lastdrupalversion for this major version yet
if [ "${lastdrupalversion[$versionmajor]}" = "" ]; then
lastdrupalversion[$drupalmajor]=`$drush rl drupal-$drupalmajor | sed -n '/Recommended/{p;q;}' | sed 's/.* *\([0-9]\.[0-9]*\) .*/\1/'`
fi
}
drupalversion=`../find-version.sh $1`
# Version has been found.
baseroot=`../find-baseroot.sh $1`
if [ -z `../get-http-status.sh $1$baseroot/misc/drupal.js` ]; then
getDrupalMajorFromDrupalVersion
../setlog.sh "{\"label\": \"Drupal Site\", \"result\": \"YES\", \"style\": \"ok\"}"
# Log if changelog is protected or not.
if [ -z `../get-http-status.sh $1$baseroot/CHANGELOG.txt` ]; then
../setlog.sh "{\"label\": \".TXT files Protection\", \"result\": \"NO - Your .txt files are not protected and are readable. You should remove them or deny access.\", \"style\": \"fail\"}"
else
../setlog.sh "{\"label\": \".TXT files Protection\", \"result\": \"YES\", \"style\": \"ok\"}"
fi
getLastDrupalVersion
# Define if version is the recommended one.
versionprefix=""
if [ $drupalmajor -gt 7 ]; then
versionprefix="$drupalmajor."
fi
if [ $drupalmajor -lt 7 ]; then
versionstatus=" (NOT RECOMMENDED)"
elif [[ "`echo $drupalversion | grep "^$versionprefix${lastdrupalversion[$drupalmajor]}$"`" = "" ]]; then
versionstatus=" (NOT RECOMMENDED - RECOMMENDED: $versionprefix${lastdrupalversion[$drupalmajor]})"
if [ -z $drupalversion ]]; then
versionstatus="NOT FOUND"
elif [[ "`echo $drupalversion | grep "$versionprefix${lastdrupalversion[$drupalmajor]}"`" != "" ]]; then
versionstylestatus="ok"
versionstatus=" (MAY BE RECOMMENDED - RECOMMENDED: $versionprefix${lastdrupalversion[$drupalmajor]})"
fi
else
versionstylestatus="ok"
fi
drupalversion=`echo $drupalversion | sed 's/ / or /g'`
../setlog.sh "{\"label\": \"Drupal Version\", \"result\": \"$drupalversion$versionstatus\", \"style\": \"$versionstylestatus\"}"
# Get page.html to make search on it
uri=( $(echo "$1" | sed 's~http://\([^/][^/]*\)\(.*\)~\1 \2~') )
HOST=${uri[0]:=localhost}
FILE=${uri[1]:=/}
curl --silent --location http://$HOST$FILE --output page.html
# Get page-header.log to make search on it
curl --silent --location --head http://$HOST$FILE --output page-header-full.log
sed -ne '/HTTP\/1.1 200 OK/,$p' page-header-full.log > page-header.log
# Check if CSS and JS are aggregated
../setlog.sh "`../drupaloscopy-aggregation.sh`"
# Check if CSS and JS are aggregated
../setlog.sh `../drupaloscopy-cache.sh`
# Check if CSS and JS are aggregated
../setlog.sh "`../drupaloscopy-header.sh`"
else
echo "$1" >> drupaloscopy-notfound.log
../setlog.sh "{\"label\": \"Drupal Site\", \"result\": \"NO\", \"style\": \"fail\"}"
fi
cat drupal-info.log
cd ..
rm -Rf $tmpdirectory