#!/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 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 > "$REPERTOIRE/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] arg="$@" i="0" while [ "$i" -lt ${#arg} ]; do c=${arg:$i:1} if echo "$c" | grep -q '[0-9a-zA-Z]'; then echo -n "$c" else printf %%%02X \'"$c" fi i=$((i+1)) done } POL_Website_urlparse() { # Parse a value to put it in a url # Usage: POL_Website_urlparse [strings] # & %26 # = %3D chars="$1" chars="${chars//"&"/\%26}" chars="${chars//"="/%3D}" echo "$chars" } POL_Website_Close() { # Close PlayOnLinux's session # Usage: POL_Website_Close rm "$REPERTOIRE/login_info" } POL_Website_Request() { # Make a POST request # Usage: POL_Website_Request [url] [post_data] wget -4 "$1" --post-data="$2" --load-cookies "$REPERTOIRE/login_info" -O- -q > "$POL_USER_ROOT/tmp/POL_Website_data" } 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] wget -4 "$1" --load-cookies "$REPERTOIRE/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 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_SetupWindow_wait_next_signal "$(eval_gettext "Connecting...")" "$TITLE" result="$(wget -4 -q http://repository.playonlinux.com/V4_data/repository/check_login.php?l=$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 }