Copy received files to Google Drive

Discussion in 'ActionScripts' started by David, Oct 1, 2019.

  1. David

    David Administrator
    Staff Member

    Joined:
    Dec 1, 2015
    Messages:
    781
    Likes Received:
    31
    This example describes how to use User delivery Action Script together with Gdrive tool to copy files from a received message for a specified user.

    1) Gdrive tool installation
    Log in to the LF console as root, download latest gdrive for 64bit linux platform and save in to the /usr/loca/bin folder.
    Code:
    curl -L  https://github.com/gdrive-org/gdrive/releases/download/2.1.0/gdrive-linux-x64 -o /usr/local/bin/gdrive
    cd /usr/local/bin
    chmod +x gdrive

    2) Authentication with your google drive account (important)
    Run the gdrive tool from the shell as "_actionscript" user and open the URL the tool will display in a browser.
    Finally paste the returned unique code back in the cmd line.
    Code:
    sudo -u _actionscript /usr/local/bin/gdrive list
    
    Authentication needed
    Go to the following url in your browser:
    https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=123456......
    
    Enter verification code: a/b/c/d/1/2/3/....
    

    3) Action Script
    Create your Action script named i.e. "copy_to_gdrive.rb" in "Admin > Configuration > Action Scripts > Add" settings.
    Code:
    #!/usr/bin/env ruby
    require 'json'
    
    #read message data
    message_data = JSON.parse(File.read(ARGV[0]))
    
    #parse attachments
    message_data["message"]["attachments"].map {
    |a| file=a["system_file"] 
    
    #copy files one by one to gdrive
    result=%x{ /usr/local/bin/gdrive upload "#{file}" }
    
    #log details to the activity logs
    %x{ logger -p local0.info -t copy_to_gdrive "#{result}" }
    }

    4) Script Assignment
    Assign that script to the required user with the "Action" switch in the profile in "Admin > Users > Edit".

    5) Testing

    Log in as some another user and send a Secure message with test files to the user with the script.
    After a while after the message is received the files should appear in the gdrive.
     
    Sam-72891 likes this.

Share This Page