XML Web Services API

在过去的几年里,网络服务已经被IT产业的 "buzz words"使用– 并且也是正确的!网络服务提供了一个标准的方式转换数据和调用不同操作系统的功能,程序语言和网络。网络服务数据是通过标准的HTTP被传递并且使用标准的XML标记。

通常这两个主网络服务的执行是用远程程序调用 (RPC)的:

PaperCut NG使用的是XML-RPC。XML-RPC是一项轻量级的网络服务执行和对所有主程序和脚本语言有着很好的支持,如:C#、Java、Visual Basic、Perl和Python。XML-RPC的方法通过PaperCut NG在 http://[server_name]:9191/rpc/api/xmlrpc的概要下有显示。

MethodDescription

api.isUserExists

Test to see if a user exists in the system/database.

api.getUserAccountBalance

Get the user's current account balance.

api.getUserProperty

Gets a user property. Properties include the user's full name, department, email, notes, office and restriction status among others.

api.setUserProperty

Sets a user property. Properties include the user's full name, department, email, notes, office, password (for internal users) and restriction status among others.

api.adjustUserAccountBalance

Adjust a user's account balance by an adjustment amount. An adjustment may be positive (add to the user's account) or negative (subtract from the account).

api.adjustUserAccountBalanceByGroup

Adjust the account balance for all users in a group by an adjustment amount. An adjustment may be positive (add to the user's account) or negative (subtract from the account).

api.adjustUserAccountBalanceByGroupUpTo

Adjust the account balance for all users in a group by an adjustment amount, but not above the given limit. An adjustment may be positive (add to the user's account) or negative (subtract from the account).

api.setUserAccountBalance

Set the balance on a user's account to a set value. This is conducted as a transaction.

api.setUserAccountBalanceByGroup

Set the balance for each member of a group to the given value.

api.resetUserCounts

Reset the counts (pages and job counts) associated with a user account.

api.reapplyInitialUserSettings

Re-applies initial settings on the user. Initial user settings are based on group membership.

api.disablePrintingForUser

Disable printing for a user for selected period of time.

api.addNewUser

Triggers the process of adding a new user account defined by a given username. Assuming the user exists in the OS/Network/Domain user directory, the account will be created with the correct initial settings as defined by the rules set up in the admin interface under the Group's section. Calling this method is equivalent to triggering the "new user" event when a new user performs printing for the first time.

api.renameUserAccount

Rename a user account. Useful when the user has been renamed in the domain / directory, so that usage history can be maintained for the new username. This should be performed in conjunction with a rename of the user in the domain / user directory, as all future usage and authentication will need to use the new username.

api.deleteExistingUser

Delete/remove an existing user from the user list. Use this method with care. Calling this will perminently delete the user account from the user list (print and transaction history records remain).

api.listUserAccounts

List all user accounts (sorted by username) starting at offset and ending at limit. This can be used to enumerate all user accounts in 'pages'. When retrieving a list of all user accounts, the recommended page size / limit is 1000. Batching in groups of 1000 ensures efficient transfer and processing.

E.g.:

    listUserAccounts(0, 1000) - 
    returns users 0 through 999
    listUserAccounts(1000, 1000) - 
    returns users 1000 through 1999
    listUserAccounts(2000, 1000) - 
    returns users 2000 through 2999
                                

api.listSharedAccounts

List all shared accounts (sorted by account name) starting at offset and ending at limit. This can be used to enumerate all shared accounts in 'pages'. When retrieving a list of all accounts, the recommended page size / limit is 1000. Batching in groups of 1000 ensures efficient transfer and processing.

E.g.:

    listSharedAccounts(0, 1000) - 
    returns users 0 through 999
    listSharedAccounts(1000, 1000) - 
    returns users 1000 through 1999
    listSharedAccounts(2000, 1000) - 
    returns users 2000 through 2999
                                

api.listUserSharedAccounts

List all shared accounts the user has access to (sorted by account name), starting at offset and ending at limit. This can be used to enumerate the accounts in 'pages'. When retrieving a list of all accounts, the recommended page size / limit is 1000. Batching in groups of 1000 ensures efficient transfer and processing.

E.g.:

    listUserSharedAccounts("username", 0, 1000) - 
    returns users 0 through 999
    listUserSharedAccounts("username", 1000, 1000) - 
    returns users 1000 through 1999
    listUserSharedAccounts("username", 2000, 1000) - 
    returns users 2000 through 2999
                                

api.isSharedAccountExists

Test to see if a shared account exists in the system/database.

api.getSharedAccountProperty

Gets a shared account property. Properties include access groups, balance, comment options, disabled status, notes, pin and restriction status among others.

api.setSharedAccountProperty

Sets a shared account property. Properties include access groups, balance, comment options, disabled status, notes, pin and restriction status among others.

api.setSharedAccountAccountBalance

Sets a shared account's current account balance.

api.adjustSharedAccountAccountBalance

Adjust a shared account's account balance by an adjustment amount. An adjustment may be positive (add to the account) or negative (subtract from the account).

api.setSharedAccountAccountBalance

Set the balance on a shared account to a set value. This is conducted as a transaction.

api.addNewSharedAccount

Create a new shared account with the given name.

api.deleteExistingSharedAccount

Delete a shared account from the system. Use this method with care. Deleting a shared account will permanently delete it from the shared account list (print history records will remain).

api.addSharedAccountAccessUser

Allow the given user access to the given shared account without using a pin.

api.addSharedAccountAccessGroup

Allow the given group access to the given shared account without using a pin.

api.removeSharedAccountAccessUser

Revoke the given user's access to the given shared account.

api.removeSharedAccountAccessGroup

Revoke the given group's access to the given shared account.

api.getPrinterProperty

Gets a printer property. Available properties include: disabled, print-stats.job-count, print-stats.page-count.

api.setPrinterProperty

Sets a printer property.

api.resetPrinterCounts

Reset the counts (pages and job counts) associated with a printer.

api.disablePrinter

Disable a printer for select period of time.

api.performOnlineBackup

Instigate an online backup. This process is equivalent to pressing the manual backup button in the web based admin interface. The data is exported into the server/data/backups directory as a timestamped, zipped XML file.

api.performGroupSync

Start the process of synchronizing the system's group membership with the OS/Network/Domain's group membership. The call to this method will start the synchronization process. The operation will commence and complete in the background.

api.performUserAndGroupSync

Start a full user and group synchronization. This is equivalent to pressing on the "Synchronize Now" button in the admin user interface. The behavior of the sync process, such as deleting old users, is determined by the current system settings as defined in the admin interface. A call to this method will commence the sync process and the operation will complete in the background.

api.performUserAndGroupSyncAdvanced

An advanced version of the user and group synchronization process providing control over the sync behavior. A call to this method will commence the sync process and the operation will complete in the background.

api.addNewUsers

Calling this method will start a specialized user and group synchronization process optimized for tracking down and adding any new users that exist in the OS/Network/Domain user directory and not in the system. Any existing user accounts will not be modified. A group synchronization will only be performed if new users are actually added to the system.

api.getTaskStatus

Return the status (completed flag and a status message) associated with a backgrounded task such as a sync operation started by the performGroupSync API. This method returns a struct (hashtable/map) containing elements with keys completed and message. This method may be polled to determine if a sync has completed.

api.batchImportSharedAccounts

Import the shared accounts contained in the given tab separated import file (located on the server).

api.batchImportInternalUsers

Import the internal users contained in the given tab-delimited import file (located on the server). See the section called “Batch Internal User Import and Update” for details of the required file format.

api.batchImportUserCardIdNumbers

Import the user card/ID numbers and PINs contained in the given tab-delimited import file.

api.getConfigValue

Gets the value of a configuration settings.

api.setConfigValue

Sets the value of a configuration setting. NOTE: Take care updating config values. You may cause serious problems which can only be fixed by reinstallation of the application. Use the setConfigValue API at your own risk.

表格 A.1. XML Web Services的方法

网络服务的实例代码

最好的证明如何使用网络服务界面的方法是使用实例码。PaperCut NG使用的实例码的位于:

    [app-path]/server/examples/webservices/
                

C#和Java的例子也包括了Proxy级的全部文档 – Proxy是一个共同的程序类型设计的。Proxy限制和显示网络服务方法作为标准的方法。设置和使用潜在的XML-RPC库是要用所有Proxy级来处理的,这意味着您采用的是集中调用的方法。

对于更多的例子的目录信息请查看 README.txt文件。在examples/webservices/java/docs/api下包括了Java的例子的全部JavaDoc文件格式。

开发者使用其它的语言诸如:Perl或Python将需要使用XML-RPC库调用目录的方法。所有方法通过<code class="literal">http://[server_name]:9191/rpc/api/xmlrpc</code>被显示。

提示

所有 XML Web Services的命令也要通过server-command程序来使用。PaperCut NG通过网络服务自动选择使用一个完整的程序环境,通过诸如批文件或隐藏的脚本来使用 server-comman程序来调用命令。对于一般的在晚间自动同步用户/组的任务这可能是比较简单的解决方案。

更多有关server-command程序的信息在 “服务器命令(server-command)”中可以找到。

安全性

网络服务API全部提供的是对系统内部的访问,因此需要确保其安全性。PaperCut NG使用了两个安全层进行安全访问:

  1. IP地址的安全

  2. 鉴定记号 – 需要对每种方法都调用

IP地址级的安全通常是由系统控制的,通过IP地址的指示,允许连接到服务器并调用API。默认此限制仅到localhost (127.0.0.1)。如果程序/脚本在其它系统上利用的是API,那么此系统的IP地址将需要在 选项概要被允许调用 XML Web Services的调用者下被添加到被列入许可的地址范围。

第一个参数对所有调用方法是一个鉴定记号 (authToken)。在当前发布的鉴定记号里是设立了admin用户密码的(此密码是在server.properties文件里被定义的)。密码必须提供给所有的调用方法。

To specify an alternative web service authentication token, to avoid the need to use/share the built-in admin user's password:

  1. Login to the system.

  2. Navigate to the Options section.

  3. Click on the Config editor link in the list of actions.

  4. Find the auth.webservices.auth-token config setting.

  5. Enter a new value that will be the new web services authentication token.

  6. Press the Update button to the right to apply the change.

  7. This authentication token can now be used in addition to the built-in admin user's password.