forked from luckow/DrupalSiege
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drplsiege.sh
executable file
·61 lines (50 loc) · 1.45 KB
/
drplsiege.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
#!/bin/bash
while getopts ":f:" OPT
do
case $OPT in
f ) URLFILE="$OPTARG" ;;
esac
done
## prompt for drupal login. Comment this out and fill define DBUSER and DBPASS below to skip this step....
read -p "Drupal Login: " DUSER;
stty -echo
read -p "Password: " DPASS;
stty echo
#DUSER=''
#DPASS=''
## url encode the password
DPASS=$(echo -n "${DPASS}" | perl -pe 's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg')
## create a temp file to hold the siegerc
SIEGERCFILE=$(mktemp /tmp/$(basename $0).XXXXXX) || exit 1
if [[ -n "$URLFILE" ]]
then
RAWSITE="$(head -1 $URLFILE)"
SITE="${RAWSITE#}"
else
SITE="${!#}"
fi
## figure out the base site URL to contruct the URL for the login page
## remove trailing slash
BASESITE=$(echo ${SITE%/})
while true
do
SUB=$(echo ${BASESITE##*/})
HTTPCODE=$(curl -s --output /dev/null -w "%{http_code}\n" ${BASESITE}/install.php)
if [[ "${HTTPCODE}" == 200 ]]
then
break
fi
BASESITE=$(echo ${BASESITE} | sed "s/\/${SUB}//")
done
LOGINURL="${BASESITE}/user"
POSTVARS="name=${DUSER}&pass=${DPASS}&form_id=user_login&op=Log+in"
LOGFILE=$(siege -C | grep "log file" | awk -F: '{print $2}' | sed 's# ##g')
SIEGERC="$(siege -C | grep "resource file:" | awk -F: '{print $2}' | sed 's# ##g')"
SIEGELOGINURL="
login-url = ${LOGINURL} POST ${POSTVARS}
"
cat "${SIEGERC}" > ${SIEGERCFILE}
echo "${SIEGELOGINURL}" >> ${SIEGERCFILE}
echo "siege -R ${SIEGERCFILE} $@"
siege -R ${SIEGERCFILE} $@ -f urls.txt
rm ${SIEGERCFILE}