#!/bin/bash -e # Stanislav German-Evtushenko , 2012-2013 # Description: the script enables OnLime turbo-button for 1, 3 or 6 hours # http://www.onlime.ru # Define usage command usage() { echo -e "Usage: $0 [b]turbo_mode or $0 check\n where turbo_mode is 1, 3 or 6 hours and 'b' means 'use bonus', for example:\n $0 3 or $0 b1"; exit 0; } # Get command line arguments and set turbo_id [[ $# != 1 ]] && usage || turbo_mode=$1 if [[ $turbo_mode == 1 ]]; then request_data="turbo_id=134" elif [[ $turbo_mode == 3 ]]; then request_data="turbo_id=135" elif [[ $turbo_mode == 6 ]]; then request_data="turbo_id=136" elif [[ $turbo_mode == b1 ]]; then request_data="ids=LOY_TURBO1" elif [[ $turbo_mode == b3 ]]; then request_data="ids=LOY_TURBO3" elif [[ $turbo_mode == b6 ]]; then request_data="ids=LOY_TURBO6" elif [[ $turbo_mode != check ]]; then usage; fi # Common variables . $HOME/.onlime-turbo.conf [[ -z $site_username ]] && read -p "Login: " site_username [[ -z $site_password ]] && read -s -p "Password: " site_password [[ ${turbo_mode#b} == ${turbo_mode} ]] && \ url_turbo_request=turbo || \ url_turbo_request=bonus/activate/ site=https://my.onlime.ru url_turbo=turbo url_turbo_history=turbo/history url_login=session/login url_logout=session/logout url_status=json/cabinet # Special variables logged_in_successfuly='href="/services/"' status="egrep -o '[^,{]+:[^,}]+' | egrep '(balance|points|tier)'" status_off="

Услуга Турбокнопка<\/u>.+<\/p>" status_pending="услуга.+обработки.+турбокнопка.+невозможны\." status_activated="Услуга уже подключена.[^<]+" status_period="awk '/^]*>$/ {record=1;line=0;start=\"\";end=\"\";status=\"\"} {if (record==1) line++; if (line==2) start=\$0; if (line==3) end=\$0; if (line==4) status=\$0 } /<\/tr>/ {record=0; if (status==\"Подключено\") print \"Период действия турбо-кнопки: \" start \" - \" end }' | sed -r 's/|<\/td>//g'" # Core variables CURL_OPTIONS="--silent" if [[ -z $proxy_url ]]; then CURL="curl $CURL_OPTIONS" else CURL="curl $CURL_OPTIONS --proxy $proxy_url --proxy-user $proxy_username:$proxy_password"; fi CURL_LOGIN="eval $CURL --data \"login_credentials[login]=$site_username&login_credentials[password]=$site_password\" $site/$url_login -c -" # Login, get session id, define CURL_SESSION PHPSESSID=$($CURL_LOGIN | grep PHPSESSID | cut -f7) CURL_SESSION="eval $CURL --cookie \"PHPSESSID=$PHPSESSID\"" # Get WTF and generate header for status page WTF="X-Wtf: $($CURL_SESSION $site | egrep -o "var wtf = '[0-9a-f]+'" | awk '{print $4}' | tr -d \')" CURL_SESSION="$CURL_SESSION --header \"$WTF\"" # Check if logged in $CURL_SESSION $site | grep "$logged_in_successfuly" > /dev/null && echo "Logged in successfuly" || { echo "Please check login or password"; exit 1; } # Activate turbo mode or check if [[ $turbo_mode == check ]]; then $CURL_SESSION $site/$url_turbo | egrep -io "($status_off|$status_pending|$status_activated)" | sed -r "s/<[^>]+>?//g" $CURL_SESSION $site/$url_turbo_history | eval $status_period echo "Account information:"; $CURL_SESSION $site/$url_status | eval $status else # Dirty work around to make bonus turbo-button work (we need to request /bonus page before we request /bonus/activate) [[ ${turbo_mode#b} == ${turbo_mode} ]] || $CURL_SESSION $site/bonus > /dev/null # Request for turbo mode echo "Requesting for turbo mode $turbomode..." $CURL_SESSION $site/$url_turbo_request --data "$request_data" > /dev/null && echo "Well done!" || echo "Something wrong has happened" fi # Logout $CURL_SESSION $site/$url_logout $CURL_SESSION $site | grep "$logged_in_successfuly" > /dev/null || echo "Logged out successfuly"