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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
#!/bin/bash
# Copyright (C) 2007-2010 PlayOnLinux Team
# Copyright (C) 2011 Pâris Quentin
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# website.lib
# -----------
#
# This lib contains playonlinux's website api
POL_Website_login()
{
# Ask for PlayOnLinux's login and check it
# Usage: POL_Website_login
POL_SetupWindow_login "$(eval_gettext 'Connect to your $APPLICATION_TITLE account')" "$TITLE"
POL_Website_check_login
}
POL_Website_logout()
{
# Remove login and password from memory
# Usage: POL_Website_logout
POL_Debug_Message "Logged out"
export POL_LOGIN=""
export POL_PASSWORD=""
}
POL_Website_Init()
{
# Open PlayOnLinux's session
# Usage: POL_Website_Init
if [ "$POL_LOGIN" = "" ]
then
POL_Debug_Error "Not logged"
else
cat << EOF > "$POL_USER_ROOT/login_info"
# HTTP cookie file.
# Edit at your own risk.
.playonlinux.com TRUE / FALSE 0 pass $(POL_MD5 $POL_PASSWORD)
.playonlinux.com TRUE / FALSE 0 login $POL_LOGIN
.playonmac.com TRUE / FALSE 0 pass $(POL_MD5 $POL_PASSWORD)
.playonmac.com TRUE / FALSE 0 login $POL_LOGIN
EOF
fi
}
POL_Website_urlencode() # Un peu violente celle la
{
# Encode strings to url
# Usage: POL_Website_urlencode [string]
echo "$1" | $SED -e 's/%/%25/g' -e 's/ /%20/g' -e 's/!/%21/g' -e 's/"/%22/g' -e 's/#/%23/g' -e 's/\$/%24/g' -e 's/\&/%26/g' -e 's/'\''/%27/g' -e 's/(/%28/g' -e 's/)/%29/g' -e 's/\*/%2a/g' -e 's/+/%2b/g' -e 's/,/%2c/g' -e 's/-/%2d/g' -e 's/\./%2e/g' -e 's/\//%2f/g' -e 's/:/%3a/g' -e 's/;/%3b/g' -e 's//%3e/g' -e 's/?/%3f/g' -e 's/@/%40/g' -e 's/\[/%5b/g' -e 's/\\/%5c/g' -e 's/\]/%5d/g' -e 's/\^/%5e/g' -e 's/_/%5f/g' -e 's/`/%60/g' -e 's/{/%7b/g' -e 's/|/%7c/g' -e 's/}/%7d/g' -e 's/~/%7e/g'
}
POL_Website_urlparse()
{
# Parse a value to put it in a url
# Usage: POL_Website_urlparse [strings]
POL_Website_urlencode "$@"
# & %26
# = %3D
# chars="$1"
# chars="${chars//'&'/%26}"
# chars="${chars//'='/%3D}"
# chars="${chars//'+'/%2B}"
# echo "$chars"
}
POL_Website_Close()
{
# Close PlayOnLinux's session
# Usage: POL_Website_Close
rm "$POL_USER_ROOT/login_info"
}
POL_Website_Request()
{
# Make a POST request
# Usage: POL_Website_Request [url] [post_data]
POL_Debug_Message "POST $1"
$POL_WGET "$1" --post-data="$2" --load-cookies "$POL_USER_ROOT/login_info" -O- -q > "$POL_USER_ROOT/tmp/POL_Website_data"
}
POL_Website_curl()
{
url="$1"
shift
> "$POL_USER_ROOT/tmp/POL_Website_data"
$POL_CURL -b "$POL_USER_ROOT/login_info" -o "$POL_USER_ROOT/tmp/POL_Website_data" "$@" "$url"
}
POL_Website_POST()
{
# Make a POST request
# Usage: POL_Website_POST [url] [post_data]
POL_Website_Request "$@"
}
POL_Website_GET()
{
# Make a GET request
# Usage: POL_Website_GET [url]
POL_Debug_Message "GET $1"
$POL_WGET "$1" --load-cookies "$POL_USER_ROOT/login_info" -O- -q > "$POL_USER_ROOT/tmp/POL_Website_data"
}
POL_Website_Result()
{
# Get the result of the last request
# Usage: POL_Website_Result
POL_Debug_Message "Reading result"
cat "$POL_USER_ROOT/tmp/POL_Website_data"
}
POL_Website_check_login()
{
# Check if the user's login is valid
# Usage: POL_Website_check_login
POL_Debug_Message "Login to $APPLICATION_TITLE website"
POL_SetupWindow_wait_next_signal "$(eval_gettext "Connecting...")" "$TITLE"
result="$($POL_WGET http://repository.playonlinux.com/V4_data/repository/check_login.php?l=$(POL_Website_urlencode "$POL_LOGIN")\&m=$(POL_MD5 $POL_PASSWORD) -O-)"
if [ "$result" = "0" ]
then
POL_SetupWindow_message "$(eval_gettext "Failed to connect !\nPlease ensure that your login and your password are valid.")" "$TITLE"
POL_Website_login
fi
}
|