This file is indexed.

/usr/share/plowshare/modules/4share_vn.sh is in plowshare-modules 0~git20160124.8a8190d-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Plowshare 4share.vn module
# Copyright (c) 2013 Plowshare team
#
# This file is part of Plowshare.
#
# Plowshare 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 3 of the License, or
# (at your option) any later version.
#
# Plowshare 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 Plowshare.  If not, see <http://www.gnu.org/licenses/>.

MODULE_4SHARE_VN_REGEXP_URL='http://up\.4share\.vn/\(d\|f\)/[[:alnum:]]\+'

MODULE_4SHARE_VN_DOWNLOAD_OPTIONS=""
MODULE_4SHARE_VN_DOWNLOAD_RESUME=no
MODULE_4SHARE_VN_DOWNLOAD_FINAL_LINK_NEEDS_COOKIE=no
MODULE_4SHARE_VN_DOWNLOAD_SUCCESSIVE_INTERVAL=

MODULE_4SHARE_VN_UPLOAD_OPTIONS=""
MODULE_4SHARE_VN_UPLOAD_REMOTE_SUPPORT=no

MODULE_4SHARE_VN_LIST_OPTIONS=""
MODULE_4SHARE_VN_LIST_HAS_SUBFOLDERS=no

MODULE_4SHARE_VN_PROBE_OPTIONS=""

# Output a 4share.vn file download URL
# $1: cookie file
# $2: 4share.vn url
# stdout: real file download link
4share_vn_download() {
    local -r COOKIE_FILE=$1
    local -r URL=$2
    local -r BASE_URL='http://up.4share.vn'

    local PAGE WAIT_TIME TIME CAPTCHA_IMG FILE_URL FILENAME

    PAGE=$(curl -c "$COOKIE_FILE" -b "$COOKIE_FILE" "$URL") || return

    if match 'FID Không hợp lệ!' "$PAGE" || \
        match 'Xin lỗi bạn, File đã bị xóa' "$PAGE"; then
        return $ERR_LINK_DEAD
    fi

    if match 'Đợi .* nữa để Download!' "$PAGE"; then
        WAIT_TIME=$(parse 'Đợi <b>' 'Đợi <b>\([^<]\+\)' <<< "$PAGE") || return

        log_error 'Forced delay between downloads.'

        echo "$WAIT_TIME"
        return $ERR_LINK_TEMP_UNAVAILABLE
    fi

    WAIT_TIME=$(parse 'var counter=' 'var counter=\([0-9]\+\)' <<< "$PAGE") || return

    # If captcha solve will take too long
    TIME=$(date +%s)

    CAPTCHA_IMG=$(create_tempfile '.jpg') || return

    curl -b "$COOKIE_FILE" -o "$CAPTCHA_IMG" \
        "$BASE_URL/library/captcha1.html" || return

    local WI WORD ID
    WI=$(captcha_process "$CAPTCHA_IMG") || return
    { read WORD; read ID; } <<<"$WI"
    rm -f "$CAPTCHA_IMG"

    TIME=$(($(date +%s) - $TIME))
    if [ $TIME -lt $WAIT_TIME ]; then
        WAIT_TIME=$((WAIT_TIME - $TIME))
        wait $WAIT_TIME || return
    fi

    PAGE=$(curl -i -b "$COOKIE_FILE" \
        -d "security_code=$WORD" \
        -d 'submit=DOWNLOAD FREE' \
        -d 's=' \
        "$URL") || return

    if match 'Bạn đã nhập sai Mã bảo vệ download' "$PAGE"; then
        log_error 'Wrong captcha.'
        captcha_nack $ID
        return $ERR_CAPTCHA
    fi

    FILE_URL=$(grep_http_header_location <<< "$PAGE") || return
    FILENAME=$(parse . '&f=\([^&]\+\)' <<< "$FILE_URL") || return

    captcha_ack $ID

    echo "$FILE_URL"
    echo "$FILENAME"
}

# Upload a file to 4share.vn
# $1: cookie file
# $2: input file (with full path)
# $3: remote filename
# stdout: download link
4share_vn_upload() {
    local -r COOKIE_FILE=$1
    local -r FILE=$2
    local -r DEST_FILE=$3
    local -r BASE_URL='http://4share.vn'

    local PAGE MAX_SIZE LINK_DL ERROR

    MAX_SIZE=209715200 # 200 MiB

    FILE_SIZE=$(get_filesize "$FILE")
    if [ "$FILE_SIZE" -gt "$MAX_SIZE" ]; then
        log_debug "File is bigger than $MAX_SIZE"
        return $ERR_SIZE_LIMIT_EXCEEDED
    fi

    # Does not count files uploaded to free account for some reason, so login dropped for a while

    PAGE=$(curl_with_log \
        -F "Filename=$DEST_FILE" \
        -F 'name=public_upload' \
        -F 'folder=/files' \
        -F "Filedata=@$FILE;filename=$DEST_FILE" \
        -F 'Upload=Submit Query' \
        "$BASE_URL/upload_script/uploadify1.lib") || return

    if match 'ERROR' "$PAGE"; then
        ERROR=$(parse 'ERROR:\([^<]\+\)' <<< "$PAGE") || return
        log_error "Remote error: $ERROR"
        return $ERR_FATAL
    fi

    LINK_DL=$(parse_attr 'href' <<< "$PAGE") || return

    echo "$LINK_DL"
}

# Probe a download URL
# $1: cookie file (unused here)
# $2: 4share.vn url
# $3: requested capability list
# stdout: 1 capability per line
4share_vn_probe() {
    local -r URL=$2
    local -r REQ_IN=$3

    local PAGE FILE_SIZE REQ_OUT

    PAGE=$(curl "$URL") || return

    if match 'FID Không hợp lệ!' "$PAGE" || \
        match 'Xin lỗi bạn, File đã bị xóa' "$PAGE"; then
        return $ERR_LINK_DEAD
    fi

    REQ_OUT=c

    if [[ $REQ_IN = *f* ]]; then
        parse 'Downloading: <strong>' \
        'Downloading: <strong>\([^<]\+\)' <<< "$PAGE" &&
            REQ_OUT="${REQ_OUT}f"
    fi

    if [[ $REQ_IN = *s* ]]; then
        FILE_SIZE=$(parse 'c: <strong>' \
        'Kích thước: <strong>\([^<]\+\)' <<< "$PAGE") && \
            translate_size "$FILE_SIZE" && REQ_OUT="${REQ_OUT}s"
    fi

    echo $REQ_OUT
}

# List a 4share.vn web folder URL
# $1: folder URL
# $2: recurse subfolders (null string means not selected)
# stdout: list of links and file names (alternating)
4share_vn_list() {
    local -r URL=$1
    local -r REC=$2

    local PAGE URL_LIST LINKS NAMES

    URL_LIST=$(replace '/d/' '/dlist/' <<< "$URL")

    PAGE=$(curl "$URL_LIST") || return
    PAGE=$(break_html_lines_alt <<< "$PAGE")

    LINKS=$(parse_all_quiet '^http://up.4share.vn/f/' '^\([^<]\+\)' <<< "$PAGE")
    NAMES=$(parse_all_quiet '^http://up.4share.vn/f/' '^http://up.4share.vn/f/[[:alnum:]]\+/\([^<]\+\)' <<< "$PAGE")

    list_submit "$LINKS" "$NAMES"
}