[BASH] Keep2share Upload Plugin PlowShare

Status
Not open for further replies.

skinner

Active Member
741
2010
59
5,170
Hi,

I wrote this simple module that works with API for upload to Keep2Share.
I wrote in few minutes and makes only basic work.

Code:
#!/bin/bash#
# keep2share.cc module
# Copyright (c) 2011-2012 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_KEEP2SHARE_REGEXP_URL="http://\(keep2share\|k2s\)\.cc/"


MODULE_KEEP2SHARE_DOWNLOAD_OPTIONS=""
MODULE_KEEP2SHARE_DOWNLOAD_RESUME=no
MODULE_KEEP2SHARE_DOWNLOAD_FINAL_LINK_NEEDS_COOKIE=no
MODULE_KEEP2SHARE_DOWNLOAD_SUCCESSIVE_INTERVAL=


MODULE_KEEP2SHARE_UPLOAD_OPTIONS="AUTH,a,auth,a=EMAIL:PASSWORD,User account"
MODULE_KEEP2SHARE_UPLOAD_REMOTE_SUPPORT=no


MODULE_KEEP2SHARE_LIST_OPTIONS=""


keep2share_upload() {


#    local -r COOKIE_FILE=$1
    local -r FILE=$2
    local -r DEST_FILE=$3
    local -r BASE_URL='http://keep2share.cc/api/v1/'
    local -r MAX_SIZE=1073741823
    local PAGE SERVER FILE_ID AUTH_DATA ACCOUNT FOLDER_ID


test "$AUTH" || return $ERR_LINK_NEED_PERMISSIONS
split_auth "$AUTH" USER PASSWORD || return


    # Sanity checks
    [ -n "$AUTH" ] || return $ERR_LINK_NEED_PERMISSIONS


    if [ -n "$LINK_PASSWORD" ]; then
        local -r PW_MAX=12


        if [ -n "$PRIVATE_FILE" ]; then
            log_error 'Private files cannot be password protected'
            return $ERR_BAD_COMMAND_LINE
        fi


        # Check length limitation
        if [ ${#LINK_PASSWORD} -gt $PW_MAX ]; then
            log_error "Password must not be longer than $PW_MAX characters"
            return $ERR_BAD_COMMAND_LINE
        fi
    fi


    if [ -n "$ADMIN_CODE" ]; then
        local -r AC_MAX=30
        local -r AC_FORBIDDEN="/ '\"%#;&"


        # Check length limitation
        if [ ${#ADMIN_CODE} -gt $AC_MAX ]; then
            log_error "Admin code must not be longer than $AC_MAX characters"
            return $ERR_BAD_COMMAND_LINE
        fi


        # Check for forbidden characters
        if match "[$AC_FORBIDDEN]" "$ADMIN_CODE"; then
            log_error "Admin code must not contain any of these: $AC_FORBIDDEN"
            return $ERR_BAD_COMMAND_LINE
        fi
    else
        ADMIN_CODE=$(random a 8)
    fi


    PAGE=$(curl -d '{"username":"'$USER'","password":"'$PASSWORD'"}' "$BASE_URL"login  ) || return
    URL=$(parse_json 'auth_token' <<< "$PAGE") || return
    log_debug "LOGIN: $PAGE"
    
    FORMUPLOAD=$(curl -d '{"auth_token":"'$URL'"}' "$BASE_URL"GetUploadFormData ) || return
    #Resp= rep:{"status":"success","code":200,"form_action":"http:\/\/und-06.keep2share.cc:8081\/upload\/index","file_field":"Filedata","form_data":{"nodeName":"prx-06","userId":"81432","expires":1390950710,"projectName":"k2s","hmac":"176b17c5debbcbbc08d5d716e8cf1ed47f5a9140","api_request":true}}
    log_debug "FORM UPLOAD: $FORMUPLOAD"
    
    # Check status
    STATE=$(echo "$FORMUPLOAD" | parse_json 'status') || return
    if [ "$STATE" != 'success' ]; then
      log_error "Unexpected state: '$STATE'"
      return $ERR_FATAL
    fi
    
    form_action=$(parse_json 'form_action' <<< "$FORMUPLOAD" ) || return
    log_debug "FORM ACTION RESPONSE: $form_action"


    file_field=$(parse_json 'file_field' <<< "$FORMUPLOAD" ) || return
    log_debug "FILE FIELD RESPONSE: $file_field"
        
    form_data=$(parse_json 'form_data' <<< "$FORMUPLOAD" ) || return
    log_debug "FORM DATA RESPONSE: $form_data"
    
    nodeName=$(parse_json 'nodeName' <<< "$form_data" ) || return
    log_debug "NODE NAME RESPONSE: $nodeName"
    
    userId=$(parse_json 'userId' <<< "$form_data" ) || return
    log_debug "USERID RESPONSE: $userId"
    
    hmac=$(parse_json 'hmac' <<< "$FORMUPLOAD" ) || return
    log_debug "HMAC RESPONSE: $hmac"
    
    expires=$(parse_json 'expires' <<< "$form_data" ) || return
    log_debug "EXPIRES RESPONSE: $expires"
    
    UPLOAD=$(curl_with_log -F "$file_field"="@$FILE" -F "hmac"="$hmac" -F "expires"="$expires" -F "userId"="$userId" -F "nodeName"="$nodeName" -F "api_request"="$URL" "$form_action") || return
    log_debug "UPLOAD RESPONSE: $UPLOAD"
    
    #Response: {"user_file_id":"52e7b3e29034c","status":"success","status_code":200}
    
    status=$(parse_json 'status' <<< "$UPLOAD" ) || return
    user_file_id=$(parse_json 'user_file_id' <<< "$UPLOAD" ) || return
    
     # Check status
    if [ "$status" != 'success' ]; then
      log_error "Unexpected state: '$status'"
      return $ERR_FATAL
    fi
    
    echo "http://k2s.cc/file/$user_file_id/$DEST_FILE"
}

I've tested with single file and folder and it works.

I think that plowshare is an amazing upload tool for linux with a lot of hosting modules ready to use.
 
2 comments
Hi,

I wrote this simple module that works with API for upload to Keep2Share.
I wrote in few minutes and makes only basic work.

Code:
#!/bin/bash#
# keep2share.cc module
# Copyright (c) 2011-2012 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_KEEP2SHARE_REGEXP_URL="http://\(keep2share\|k2s\)\.cc/"


MODULE_KEEP2SHARE_DOWNLOAD_OPTIONS=""
MODULE_KEEP2SHARE_DOWNLOAD_RESUME=no
MODULE_KEEP2SHARE_DOWNLOAD_FINAL_LINK_NEEDS_COOKIE=no
MODULE_KEEP2SHARE_DOWNLOAD_SUCCESSIVE_INTERVAL=


MODULE_KEEP2SHARE_UPLOAD_OPTIONS="AUTH,a,auth,a=EMAIL:PASSWORD,User account"
MODULE_KEEP2SHARE_UPLOAD_REMOTE_SUPPORT=no


MODULE_KEEP2SHARE_LIST_OPTIONS=""


keep2share_upload() {


#    local -r COOKIE_FILE=$1
    local -r FILE=$2
    local -r DEST_FILE=$3
    local -r BASE_URL='http://keep2share.cc/api/v1/'
    local -r MAX_SIZE=1073741823
    local PAGE SERVER FILE_ID AUTH_DATA ACCOUNT FOLDER_ID


test "$AUTH" || return $ERR_LINK_NEED_PERMISSIONS
split_auth "$AUTH" USER PASSWORD || return


    # Sanity checks
    [ -n "$AUTH" ] || return $ERR_LINK_NEED_PERMISSIONS


    if [ -n "$LINK_PASSWORD" ]; then
        local -r PW_MAX=12


        if [ -n "$PRIVATE_FILE" ]; then
            log_error 'Private files cannot be password protected'
            return $ERR_BAD_COMMAND_LINE
        fi


        # Check length limitation
        if [ ${#LINK_PASSWORD} -gt $PW_MAX ]; then
            log_error "Password must not be longer than $PW_MAX characters"
            return $ERR_BAD_COMMAND_LINE
        fi
    fi


    if [ -n "$ADMIN_CODE" ]; then
        local -r AC_MAX=30
        local -r AC_FORBIDDEN="/ '\"%#;&"


        # Check length limitation
        if [ ${#ADMIN_CODE} -gt $AC_MAX ]; then
            log_error "Admin code must not be longer than $AC_MAX characters"
            return $ERR_BAD_COMMAND_LINE
        fi


        # Check for forbidden characters
        if match "[$AC_FORBIDDEN]" "$ADMIN_CODE"; then
            log_error "Admin code must not contain any of these: $AC_FORBIDDEN"
            return $ERR_BAD_COMMAND_LINE
        fi
    else
        ADMIN_CODE=$(random a 8)
    fi


    PAGE=$(curl -d '{"username":"'$USER'","password":"'$PASSWORD'"}' "$BASE_URL"login  ) || return
    URL=$(parse_json 'auth_token' <<< "$PAGE") || return
    log_debug "LOGIN: $PAGE"
    
    FORMUPLOAD=$(curl -d '{"auth_token":"'$URL'"}' "$BASE_URL"GetUploadFormData ) || return
    #Resp= rep:{"status":"success","code":200,"form_action":"http:\/\/und-06.keep2share.cc:8081\/upload\/index","file_field":"Filedata","form_data":{"nodeName":"prx-06","userId":"81432","expires":1390950710,"projectName":"k2s","hmac":"176b17c5debbcbbc08d5d716e8cf1ed47f5a9140","api_request":true}}
    log_debug "FORM UPLOAD: $FORMUPLOAD"
    
    # Check status
    STATE=$(echo "$FORMUPLOAD" | parse_json 'status') || return
    if [ "$STATE" != 'success' ]; then
      log_error "Unexpected state: '$STATE'"
      return $ERR_FATAL
    fi
    
    form_action=$(parse_json 'form_action' <<< "$FORMUPLOAD" ) || return
    log_debug "FORM ACTION RESPONSE: $form_action"


    file_field=$(parse_json 'file_field' <<< "$FORMUPLOAD" ) || return
    log_debug "FILE FIELD RESPONSE: $file_field"
        
    form_data=$(parse_json 'form_data' <<< "$FORMUPLOAD" ) || return
    log_debug "FORM DATA RESPONSE: $form_data"
    
    nodeName=$(parse_json 'nodeName' <<< "$form_data" ) || return
    log_debug "NODE NAME RESPONSE: $nodeName"
    
    userId=$(parse_json 'userId' <<< "$form_data" ) || return
    log_debug "USERID RESPONSE: $userId"
    
    hmac=$(parse_json 'hmac' <<< "$FORMUPLOAD" ) || return
    log_debug "HMAC RESPONSE: $hmac"
    
    expires=$(parse_json 'expires' <<< "$form_data" ) || return
    log_debug "EXPIRES RESPONSE: $expires"
    
    UPLOAD=$(curl_with_log -F "$file_field"="@$FILE" -F "hmac"="$hmac" -F "expires"="$expires" -F "userId"="$userId" -F "nodeName"="$nodeName" -F "api_request"="$URL" "$form_action") || return
    log_debug "UPLOAD RESPONSE: $UPLOAD"
    
    #Response: {"user_file_id":"52e7b3e29034c","status":"success","status_code":200}
    
    status=$(parse_json 'status' <<< "$UPLOAD" ) || return
    user_file_id=$(parse_json 'user_file_id' <<< "$UPLOAD" ) || return
    
     # Check status
    if [ "$status" != 'success' ]; then
      log_error "Unexpected state: '$status'"
      return $ERR_FATAL
    fi
    
    echo "http://k2s.cc/file/$user_file_id/$DEST_FILE"
}

I've tested with single file and folder and it works.

I think that plowshare is an amazing upload tool for linux with a lot of hosting modules ready to use.

Way cool man! Yeah PlowShare is definitely the shit, fuck ZOOM! lol

They just recently started up an IRC channel on irc.freenode.net in #plowshare and its starting to get active.

I personally have my own bash uploader that I slapped together with k2s's help. It works with fileboom.me as well so I'm sure if you wanted to post some of those links you could easily tweak what you wrote here slightly to adapt for fileboom.me integration as well :)

Good work, I'll hafta check your script out soon :)

__________________
Added after 1 Day 11 Hours:

Just FYI, I realized that the latest version of PlowShare has integration with Keep2Share (not sure how recently this was added, I only know it wasn't there a few months ago).

Within the command plowup --longhelp you can see:

Code:
Options for module <keep2share>:
  -b, --auth-free=EMAIL:PASSWORD   Free account
      --full-link                  Final link includes filename

Most of the PlowShare Script's modules use the argument -a to specify a user account for the file host to log in to. However from time to time the developers write a module when they themselves do not have a premium account to confirm full functionality; in such cases where the developers only have a free account to confirm functionality they use the -b argument. Most times I've found that if I use the -b argument with my premium credentials PlowShare's plowup will still work.

Just a few minutes ago I tested the plowup module for keep2share and confirm that it was able to upload a 50MB sparse text file into my premium keep2share account using the -b argument as such:

plowup keep2share -b myKeep2ShareEmail@Address.tld:'MyKeep2SharePassword' exampleFile.txt

One thing however that I'd like to give you props on is that you seem to have added support for downloading from Keep2Share. The current build of PlowShare installed on my servers does not appear to have plowdown support so good work on this.

Also, Keep2Share recently launched a secondary file host using the domain FileBoom.me/FBoom.Me. I'm sure that a few very slight modifications (probably by just using sed to replace keep2share.com with fileboom.me in your file) can be made to either your Keep2Share module or the official PlowShare Keep2Share module.

If anyone is wondering what PlowShare is, you can check out the script's official Google Project page available at: https://code.google.com/p/plowshare/
 
Last edited:
In the end I had to stop using PlowShare for keep2share because of the way it handles the upload sessions, basically if I upload from more than one server at a time it would knock out the other uploads on the other servers.

Last night I worked with Keep2Share's development team and with their help I wrote my own bash upload script that basically uploads all files in a directory into Keep2Share (and their other two file hosts, fileboom and publish2me). It does it pretty much the same way as PlowShare with a little twist at the end as I parse the download links into BBCode which can be copy/pasted directly from a SSH terminal into a forum or blog.

Here is the links to the source code if anyone is interested:
FileBoom: [Bash] fileBoomUploader.sh - Pastebin.com
Keep2Share: keep2ShareUploader.sh - Pastebin.com
Publish2Me: [Bash] publish2meUploader.sh - Pastebin.com

I'm posting this message on the 4th of July 2014, so if your reading this in the far distant future then you might want to stick to PlowShare as PlowShare has regular updates while my pastebin links can not be updated. In other words my scripts work today but no promises that they'll work tomorrow :)
 
Status
Not open for further replies.
Back
Top