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.
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
- Install Java 7+ and ensure
/usr/bin/java -version
orJAVA_HOME
is set to it - Download the git repository
- Build a package
- RedHat/RPM distros:
./gradlew createRpm
- Ubuntu/DEB distros:
./gradlew createDeb
- RedHat/RPM distros:
- 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
- RedHat/RPM distros:
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.
-
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
-
Log into Box.com with an account with developer access
- Sign up to be a developer here: https://developers.box.com
- Then, go to your account settings (https://EXAMPLE.app.box.com/settings/security) and enable two-factor authentication unless you are using single sign-on (two-factor or SSO are mandatory for the steps below)
-
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"
-
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"
-
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"
-
Try out a test upload
PrintToBox <MY USERNAME> <TEST FILENAME>
-
Check the
PrintToBox <MY USERNAME>
folder for your uploaded file
-
Install Tea4CUPS using your distribution package manager or get it here: Tea4CUPS
-
Add a printer. E.g.,
sudo lpadmin -p 'BOXPRINTER' -E -v 'tea4cups://'
-
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
-
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
.