Skip to content

Instantly share code, notes, and snippets.

@kudarisenmon
Created September 23, 2022 08:28
Show Gist options
  • Save kudarisenmon/69002a71dfc5a4eb238014a4728eb740 to your computer and use it in GitHub Desktop.
Save kudarisenmon/69002a71dfc5a4eb238014a4728eb740 to your computer and use it in GitHub Desktop.
ガルーン on cybozu.com メールサイズ制限値の書き出し
#!/bin/bash
if [ -z "$USERNAME" ]; then
echo 'USERNAME is not set'
exit
fi
if [ -z "$PASSWORD" ]; then
echo 'PASSWORD is not set'
exit
fi
if [ -z "$URL" ]; then
echo 'URL is not set'
exit
fi
curl -s -c cybozu-cookie.txt "$URL/login" > cybozu-login.html
REQUEST_TOKEN="{\"__REQUEST_TOKEN__\":\"`grep -oP "(?<=cybozu.data.REQUEST_TOKEN = ').+(?=';)" cybozu-login.html`\"}"
rm cybozu-login.html
curl -s -b cybozu-cookie.txt -c cybozu-cookie.txt "$URL/api/auth/getToken.json?_lc=ja" \
-H 'Content-Type: application/json' \
-H "Referer: $URL/login" \
--data-raw $REQUEST_TOKEN > cybozu-token.txt
TOKEN="{\"username\":\"$USERNAME\",\"password\":\"$PASSWORD\",\"keepUsername\":false,\"redirect\":\"\",\"__REQUEST_TOKEN__\":`jq .result.token cybozu-token.txt`}"
rm cybozu-token.txt
curl -s -b cybozu-cookie.txt -c cybozu-cookie.txt "$URL/api/auth/login.json?_lc=ja" \
-H 'Content-Type: application/json' \
-H "Referer: $URL/login" \
--data-raw "$TOKEN"
curl -s -b cybozu-cookie.txt "$URL/g/mail/system/mail_limit_export.csp?" \
-H "Referer: $URL/g/mail/system/export_index.csp?" \
--compressed > mail_limit_export.txt
CSRF_TICKET=`grep -oP '(?<=<input type="hidden" name="csrf_ticket" value=").+(?=">)' mail_limit_export.txt | head -1`
rm mail_limit_export.txt
curl -b cybozu-cookie.txt "$URL/g/mail/system/command_mail_limit_export.csp/-/mail_limit.csv?&.csv" \
-H 'Accept-Language: ja,en-US;q=0.9,en;q=0.8' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H "Referer: $URL/g/mail/system/mail_limit_export.csp?" \
--data-raw "csrf_ticket=$CSRF_TICKET&charset=UTF-8&item_name=1" \
--compressed > mail_limit.csv
rm cybozu-cookie.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment