bash: สคริปต์บล๊อกผู้ใช้ Drupal

Topic: 
 

ทำสคริปต์บล๊อกผู้ใช้ Drupal จากบรรทัดคำสั่ง (bash)

$ vi drupal_blockuser.sh
#!/bin/bash

#FROM: https://drupal.org/node/118759

if [ "$#" == "0" ]; then
    echo "Script to block drupal users by uid"
    echo "Usage: $0 UID1 UID2 UID3 ..."
    exit 1
fi

SITE=http://www.example.com    #NO END SLASH
NAME=drupal_admin_user
PASS=drupal_admin_password

STATUS=0    #0:block,1:unblock
OPLOGIN="Log%20in"
OPSUBMIT="Save"
TMP=/tmp/$RANDOM.txt
COOKIES=/tmp/$RANDOM.txt

#LOGIN
wget -q -o /dev/null -O /dev/null \
    --keep-session-cookies --save-cookies $COOKIES --load-cookies $COOKIES \
    --post-data="name=${NAME}&pass=${PASS}&op=${OPLOGIN}&form_id=user_login" \
    "${SITE}/?q=user/login"

#DO BLOCK
while (( "$#" )); do
    ID=$1
    wget -q -o /dev/null -O $TMP \
        --keep-session-cookies --save-cookies $COOKIES --load-cookies $COOKIES \
        "${SITE}/?q=user/${ID}/edit"
    let "LINE=`grep -n 'value="user_profile_form"' $TMP | cut -d: -f1`-1"
    TOKEN=`sed -n -e "${LINE}p" $TMP | awk -F'value="' '{ print $2 }' | cut -d\" -f1`
    USER1=`grep 'id="edit-name"' $TMP | awk -F'value="' '{ print $2 }' | cut -d\" -f1`
    EMAIL=`grep 'id="edit-mail"' $TMP | awk -F'value="' '{ print $2 }' | cut -d\" -f1`
    wget -q -o /dev/null -O /dev/null \
        --keep-session-cookies --save-cookies $COOKIES --load-cookies $COOKIES \
        --post-data="status=${STATUS}&op=${OPSUBMIT}&name=${USER1}&mail=${EMAIL}&form_token=${TOKEN}&form_id=user_profile_form" \
        "${SITE}/?q=user/${ID}/edit"
    echo "USER:\"$USER1\" --- EMAIL:\"$EMAIL\" --- Blocked."

    shift
done

rm $TMP
rm $COOKIES
$ chmod 700 ./drupal_blockuser.sh

วิธีใช้งานก็สั่ง

$ ./drupal_blockuser.sh UID1 UID2 UID3 ...

อย่าลืมแก้ตัวแปร SITE, NAME, PASS ให้เข้ากับงานเรา

 

Syndicate

Subscribe to Syndicate

Who's online

There are currently 0 users online.