Giter Site home page Giter Site logo

lushpush / printtobox Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stedwards/printtobox

1.0 2.0 0.0 188 KB

Upload files to Box collaborated folders for enterprise users. E.g., cron output or as a Tea4CUPS printer driver

License: Other

Shell 0.76% Groovy 99.24%

printtobox's Introduction

PrintToBox

PrintToBox is an application for uploading files for enterprise users to collaborated folders in Box. E.g., cron output, logfiles, backups, etc.

Its initial inspiration was for Banner users to be able to print reports directly to Box. It works with both Banner 8 and Banner 9.

Usage

PrintToBox [<options>] <username> <filename> [<filename 2>...]

Upload files to a Box.com collaborated folder of which <username> is
the owner. Creates the collaborated folder and any subfolder[s] if they
do not exist. By default, it uploads a new version for existing files.

Options:
 -C,--create-user <username>   Create AppUser <username> and exit
 -d,--differ                   Upload new version only if the file differs
 -D,--debug                    Enable debugging
    --delete-user              CAUTION: Delete configured AppUser and exit
 -f,--folder <folder>          Box folder path. Top-level should be
                               unique. Default: "PrintToBox <username>"
 -h,--help                     Print this help text and exit
 -I,--user-info                Print information about the configured
                               AppUser and exit
 -R,--replace                  If the filename already exists in Box,
                               delete it (and all versions) and replace it
                               with this file
 -T,--total-size               Abort if total size of file set exceeds
                               storage in Box. May not make sense with
                               --replace, --differ, or --no-update
 -U,--no-update                If the filename already exists in Box, do
                               nothing
 -V,--version                  Display the program version and exit

Building and Installing

  1. Install Java 7+ and ensure /usr/bin/java -version or JAVA_HOME is set to it
  2. Download the git repository
  3. Build a package
    • RedHat/RPM distros: ./gradlew createRpm
    • Ubuntu/DEB distros: ./gradlew createDeb
  4. Install the package
    • RedHat/RPM distros: sudo rpm -i build/distributions/printtobox-VERSION.rpm
    • Ubuntu/DEB distros: sudo dpkg -i build/distributions/printtobox_VERSION.deb for updating, use -U instead of -i
  5. sudo usermod -a -G printtobox <username>
    • N.b., anyone in this group can read the config file, keys, and key password. This is why it is a good idea to abstract access via CUPS or cron. Making the executable setuid=root is not recommended.

Setting up configuration with Box.com

  1. Generate a public/private keypair with a password on the private key. Recommended:

     openssl genrsa -aes256 -out /etc/PrintToBox/PrintToBox_private_key.pem 8192
     openssl rsa -pubout -in /etc/PrintToBox/PrintToBox_private_key.pem -out /etc/PrintToBox/PrintToBox_public_key.pem
     chmod 640 /etc/PrintToBox/PrintToBox_private_key.pem /etc/PrintToBox/PrintToBox_public_key.pem
     chown root:printtobox /etc/PrintToBox/PrintToBox_private_key.pem /etc/PrintToBox/PrintToBox_public_key.pem
    
  2. Log into Box.com with an account with developer access

  3. Create a new application

    • Go here: https://EXAMPLE.app.box.com/developers/services/edit/
    • Name it something unique. Select "Box Content" and press "Create Application"
    • For redirect_uri, set it to a bogus https URL
    • User Type is "App Users"
    • Check these Scopes:
      • Read and write all files and folders
      • Create and manage app users
    • Click "Save Application"
    • Click "Add Public Key"
    • Copy the contents of /etc/PrintToBox/PrintToBox_public_key.pem into the "Public Key" field
    • Click "Verify" and then click "Save"
    • Click "Save Application"
    • Update /etc/PrintToBox/PrintToBox.conf with the following fields:
      • Enterprise domain (@example.com) — "enterpriseDomain"
      • Key Id — "keyId"
      • Private key filename — "keyFileName"
      • Private key password — "keyPassword"
      • client_id — "clientId"
      • client_secret — "clientSecret"
  4. Go to the Admin Console

    • Go here: https://EXAMPLE.app.box.com/master/settings
    • Click "Enterprise Settings" (or "Business Settings"). Click "Account Settings".
    • Update /etc/PrintToBox/PrintToBox.conf with the following fields:
      • Enterprise ID — "enterpriseId"
    • Then, click the "App" tab and click "Authorize New App". N.b., if you do not see the text for "Authorize New App", then you need to input a support ticket with Box.com and ask them to enable AppAuth/AppUsers for your enterprise
    • Copy the client_id from above into the "API Key" field and click "Okay"
  5. Generate an AppUser and update /etc/PrintToBox/PrintToBox.conf with the "appUserId"

     $ PrintToBox -C <APP_USERNAME>
     Created user. Add this to /etc/PrintToBox/PrintToBox.conf:
     "appUserId": "9999999999" 
    
  6. Try out a test upload

     PrintToBox <MY USERNAME> <TEST FILENAME>
    
  7. Check the PrintToBox <MY USERNAME> folder for your uploaded file

Tea4CUPS

  1. Install Tea4CUPS using your distribution package manager or get it here: Tea4CUPS

  2. Add a printer. E.g., sudo lpadmin -p 'BOXPRINTER' -E -v 'tea4cups://'

  3. Edit the Tea4CUPS config file, /etc/cups/tea4cups.conf, adding the following lines for the printer you are configuring:

     [BOXPRINTER]
     prehook_0 : /usr/bin/PrintToBox $TEAUSERNAME $TEADATAFILE >>/var/log/PrintToBox.log 2>>/var/log/PrintToBox.err
    
  4. Test

     lpr -PBOXPRINTER testfile
     lpq -PBOXPRINTER
    

Unfortunately, the CUPS job filename is what Tea4CUPS receives so you are stuck with that. E.g., tea4cups-BOXPRINTER-username-216.

printtobox's People

Contributors

luyseyal avatar mishatx avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.