├── README.md └── hubic.sh /README.md: -------------------------------------------------------------------------------- 1 | # hubiccli 2 | Unofficial hubiC cli manager, based on bash 3 | 4 | Version: 0.2 5 | 6 | Author: NetoMX 7 | 8 | Requires: BASH, cURL with https support 9 | 10 | # TODO: 11 | Verify last token - if it works, skip all the initial process. 12 | 13 | # Thanks 14 | 15 | https://www.tiernanotoole.ie/2015/03/31/HubiC_SWIFT_CURL.html for the idea 16 | 17 | https://gist.github.com/cdown/1163649 for the urlencode script 18 | 19 | LowEndTalk.com for the help 20 | -------------------------------------------------------------------------------- /hubic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | URL="EDIT_HERE" 3 | CLIENTID="EDIT_HERE" 4 | CLIENTSECRET="EDIT_HERE" 5 | USEREMAIL="EDIT@HERE" 6 | USERPWD="EDITHERE" 7 | CREDENTIALS=$( printf "$CLIENTID:$CLIENTSECRET" | base64 -w 0 ) 8 | 9 | urlen() { 10 | # Thanks https://gist.github.com/cdown/1163649 11 | local length="${#1}" 12 | for (( i = 0; i < length; i++ )); do 13 | local c="${1:i:1}" 14 | case $c in 15 | [a-zA-Z0-9.~_-]) printf "$c" ;; 16 | *) printf '%s' "$c" | xxd -p -c1 | 17 | while read c; do printf '%%%s' "$c"; done ;; 18 | esac 19 | done 20 | } 21 | 22 | function setup () { 23 | # Obtain request code 24 | OAUTH=$( curl -s --get "https://api.hubic.com/oauth/auth/" --data-urlencode "client_id=$CLIENTID" --data-urlencode "redirect_uri=$URL" --data-urlencode "scope=usage.r,account.r,getAllLinks.r,credentials.r,sponsorCode.r,activate.w,sponsored.r,links.drw" --data-urlencode "response_type=code" --data-urlencode "state=RandomString_mpOwM8gSJD" | grep "name=\"oauth\"" | cut -d" " -f4 | cut -c8-13 ) 25 | if [ $? -ne 0 ]; then 26 | echo "Error getting request code, verify credentials" 27 | exit 1 28 | fi 29 | 30 | # Accepting the app itself for the request token 31 | REQUESTTOKEN=$( curl -s -i "https://api.hubic.com/oauth/auth/" --data-urlencode "oauth=$OAUTH" --data-urlencode "action=accepted" --data-urlencode "account=r" --data-urlencode "credentials=r" --data-urlencode "getAllLinks=r" --data-urlencode "links=r" --data-urlencode "links=w" --data-urlencode "usage=r" --data-urlencode "login=$USEREMAIL" --data-urlencode "user_pwd=$USERPWD" --data-urlencode "submit=Accept" | grep Location | cut -c11- | grep code | cut -d"=" -f2 | cut -d"&" -f1 ) 32 | if [ $? -ne 0 ]; then 33 | echo "Error getting Request Token, try again later" 34 | exit 1 35 | fi 36 | 37 | # Obtaining the auth code 38 | AUTHCODE=$( curl -s "https://api.hubic.com/oauth/token/" -H "Authorization: Basic $CREDENTIALS" --data-urlencode "code=$REQUESTTOKEN" --data-urlencode "redirect_uri=$URL" --data-urlencode "grant_type=authorization_code" | cut -d"\"" -f10 ) 39 | if [ $? -ne 0 ] || [ -z "$AUTHCODE" ]; then 40 | echo "Error $? getting Auth Code, try again later." 41 | exit 1 42 | fi 43 | 44 | #Obtaining endpoint and token 45 | curl -s -H "Authorization: Bearer $AUTHCODE" https://api.hubic.com/1.0/account/credentials > /tmp/paso1.txt 46 | if [ $? -ne 0 ] || [ $( cat /tmp/paso1.txt | grep invalid ) ] ; then 47 | echo "Error $? getting token, check your AuthCode" 48 | echo "Debug: " 49 | cat /tmp/paso1.txt 50 | echo "***********************************" 51 | rm /tmp/paso1.txt 52 | exit 1 53 | fi 54 | 55 | TOKEN=$( cat /tmp/paso1.txt | cut -d"\"" -f4 ) 56 | ENDPOINT=$( cat /tmp/paso1.txt | cut -d"\"" -f8 ) 57 | 58 | #Deleting temp file 59 | rm /tmp/paso1.txt 60 | } 61 | 62 | if [ $# == 0 ]; then 63 | echo "hubiC cli manager - NetoMX v0.1" 64 | echo "Usage: $0 [-l / -d / -u] [FILE]" 65 | exit 1 66 | fi 67 | 68 | if [ "$1" == "-d" ] || [ "$1" == "-u" ] && [ $# != 2 ]; then 69 | echo "hubiC cli manager - NetoMX v0.1" 70 | echo "Usage: $0 [-l / -d / -u] [FILE]" 71 | exit 1 72 | fi 73 | 74 | case "$1" in 75 | "-d") echo "Downloading file: $2" 76 | setup 77 | FILENAME=$( urlen "$2" ) 78 | curl -s -g -H "X-Auth-Token: $TOKEN" "$ENDPOINT/default/$FILENAME" -X GET -o "$2" 79 | if [ $? -ne 0 ]; then 80 | echo "Error $? downloading file: $1" 81 | exit 1 82 | fi 83 | exit 0 84 | ;; 85 | "-u") echo "Uploading file: $2" 86 | setup 87 | curl -s -g -H "X-Auth-Token: $TOKEN" "$ENDPOINT/default/" -X PUT -T "$2" 88 | if [ $? -ne 0 ]; then 89 | echo "Error $? subiendo archivo $2" 90 | exit 1 91 | fi 92 | exit 0 93 | ;; 94 | "-l") echo "Listing files:" 95 | setup 96 | #Uncomment this if you want pretty JSON 97 | #curl -s -H "X-Auth-Token: $TOKEN" $ENDPOINT/default?format=json -X GET | python -m json.tool 98 | curl -s -H "X-Auth-Token: $TOKEN" $ENDPOINT/default?format=json -X GET | grep -e "bytes" -e "name" 99 | if [ $? -ne 0 ]; then 100 | echo "Error $? listing files" 101 | exit 1 102 | fi 103 | exit 0 104 | ;; 105 | *) echo "Error: argument not recognized." 106 | echo "Usage: $0 [-l / -d / -u] [FILE]" 107 | exit 108 | ;; 109 | esac 110 | --------------------------------------------------------------------------------