Skip to content

Commit

Permalink
Added a new script
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec Clews committed Nov 9, 2018
1 parent 73ac60a commit 4721eeb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions PublicWebServicesAPI_AND_servercommandScripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ web services API to streamline using the health interface API
* `removeTempCardsJob.py`: Removes all temp cards from PaperCut, if the cards are listed in a table.
Easy to extend to use an external database (Python)
* `removeUsersListedInFile`: Bash script that removes any user _NOT_ listed in a file
* `setAccountSelectionMode.py`: Python script to set account selection mode depending on number shared accounts
user can access
* `simpleTopUpBalance`: Small and ugly web application to allow users to top up their PaperCut personal account balance
* `swapCardNumbers.sh`: Bash script to swap the primary-card-number and secondary-card-number fields for all users
* `swapCardNumbers.ps1`: Powershell script to swap the primary-card-number and secondary-card-number fields for all users.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

# For every user in the database, set the account selection mode to be either

# 1. Auto charge to personal when user has access to zero shared accounts
# 2. Auto charge to shared account when user has access to one shared account
# 3. User standard account selection pop up when user has access to multiple shared accounts

# This script would need to be run regularly to reflect group changes etc

import xmlrpc.client
from ssl import create_default_context, Purpose

host="https://localhost:9192/rpc/api/xmlrpc" # If not localhost then this address will need to be whitelisted in PaperCut
auth="token" # Value defined in advanced config property "auth.webservices.auth-token". Should be random

proxy = xmlrpc.client.ServerProxy(host, verbose=False,
context = create_default_context(Purpose.CLIENT_AUTH))

offset = 0

limit = 100 # Max number of usernames to retrieve on each call

while True:

userList = proxy.api.listUserAccounts(auth, offset,limit)

for user in userList:

if not proxy.api.isUserExists(auth, user):
print("Can't find user {}".format(user))

shared_accounts = proxy.api.listUserSharedAccounts(auth, user, 0, 99, True)

if len(shared_accounts) == 0:
proxy.api.setUserAccountSelectionAutoChargePersonal(auth, user, False)
print("Setting setUserAccountSelectionAutoChargePersonal for user {}".format(user))

elif len(shared_accounts) == 1:
proxy.api.setUserAccountSelectionAutoSelectSharedAccount(auth, user, shared_accounts[0], False)
print("Setting setUserAccountSelectionAutoSelectSharedAccount for user {} with account {}".format(
user, shared_accounts[0]))

else:
proxy.api.setUserAccountSelectionStandardPopup(auth, user, False, True, False, False, False)
print("Setting setUserAccountSelectionStandardPopup for user {}".format(user))

if len(userList) < limit:
break # We have reached the end

offset += limit # We need to next slice of users

0 comments on commit 4721eeb

Please sign in to comment.