NAME

XML-RPC Server

Back to Top


VERSION

Release date = 2006-05-27

Back to Top


SYNOPSIS

On Win32 running ActiveState Perl

wperl.exe gus_xml-rpc_server.pl --help

On Unix, etc.

perl gus_xml-rpc_server.pl --help &

Back to Top


DESCRIPTION

An XML-RPC server useful in allowing external Perl scripts to be triggered remotely (for backup, etc).

Back to Top


CUSTOMIZATION

At head of script is an area for user configuration. But in taking advantage of them, one therby documents the settings, some of which might best remain secret. Should you prefer to leave them as empty strings, a pop-up GUI will let you set them at startup.

Back to Top


XML-RPC METHODS

server_status

A harmless way to test the server/client connection. Requests the server to inform of its status.

server_log

Copy the current log, if any, back to the client.

change_password

Allows a client to change the password of the server.

change_cipher

Allows a client to change the cipher pass pharase of the server.

execute_command

A means of executing a single command on each selected server.

How it works:
Client opens a window for wherein the user types out, very carefully, the exact command to be executed. Each server will, in its own turn, open said script and attempt to execute it expecting pure text as the return. This return-text is then passed back to the client for display in a pop-up window.

execute_script

A means of executing external scripts line-by-line on each selected server.

How it works:
Client browses for a Perl script and sends its file path to all selected servers. Each server will, in its own turn, open said script and attempt to execute it expecting pure text as the return. This return-text is then passed back to the client for display in a pop-up window.

Example of use:
Say a single backup script exists on a network directory. On each PC needing to run said backup script, this very XML-RPC server runs as a daemon. Then from any other PC you call up the companion XML-RPC GUI client. From the client you select one or more URLs from the list and click the Execute button, browsing to the network path of the backup script. Each selected server will run said backup script in turn, not all at once, but one after another.

kill_server

Client remotely kills selected servers. As of this version the results are ungraceful. Although harmless, a killed server cannot reply to the client with an I have died packet. So the client, after a short timeout, thinks the procedure call has failed. A subsequent attempt with the server_status method will verify that said server is indeed off-line.

add_new_script

Client browses for and transmits a new script to selected servers. Once transmitted, those servers store a copy locally. It is then immediately available to the<C execute_script >method. This, quite obviously, is a dangerous thing to do. Hence on the client, it is accessed via a warningly entitled titled pull-down menu: At Your Hazard!

Any script thus sent is subjected to a certain degree of scrutiny by receiving servers. This scrutiny is only for known types of scripting languages, pure-ASCII content, etc. No test whatever is made for dangerous instructions embeded therein. Accordingly, use of this feature is AT YOUR OWN HAZARD! The author of this server/client pair assumes no responsibility whatever for any use to which it is put.

remove_scripts

User enters exact script name or regular expression into client. Client then requests selected servers to delete matching files. Once transmitted, each selected server will completely delete its local copy along with info related to it. The client too forgets its existence so that you cannot ask for it again.

add_doc_elsewhere

Client browses for, filters and then transmits a pure ASCII text file to selected servers. Once transmitted, those servers store a copy locally, in a directory path generally outside that where executable scripts are stored. The exact path will vary, depending pupon the contents of the '%elsewhere' hash as defined by the user.

Where files are stored
The keys of the %elsewhere hash are polled as filename-matching regexes. The values are directory paths. So when the server receives a filtered file sent to it from the client via the add_doc_elsewhere method, the server store it accordingly

How files are filtered
At the client there exists a %lines_to_skip hash with keys similar to those of the %elsewhere hash on the server, and likewise employed to match against filenames. But there each value will be an array of regular expressions for disallowed phrases. Any such lines as match a regex therein listed will be removed prior to transmission.

Example usage
The author employs the add_doc_elsewhere method as follows. Certain MTS servo-hydraulic testing machines which are left to run unattended on weekends had formerly required on-site visitation by operators working on overtime, and at their considerable inconvenience. Most frequently, however, such efforts were merely to determine that, no, the machines in question had not stopped and did not therefor require any service.

Now, however, an XML-RPC client oversees these machines, forwarding filtered copies of their current status logs over the Internet to an XML-RPC server. There the server matches the received, filtered logs to a directory on a co-resident Apache web server. Thus operators have only to check that URL via web browser from their home PC to know if the machine requires service or not.

The filtering so often mentioned above serves a two-fold purpose. Firstly it removes many lines from the status logs which are of no interest to the operator in determining if their machine needs tending. Secondly it removes any reference as to what sort of test the machine is running...customer proprietary information...that kind of thing (which, in a sense, is really just part of the first criterion).

Browser annoyances
Know that if your browser is set to accellerate downloads, most likely it caches them instead. That means when you go to a certain website and click on a file you might not really get the most current version of that file. Instead you may see an out-of-date version which was cached during an earlier visitation to that same URL. This is no fault of XML-RPC; adjust your browser settings to correct the situation instead.

remove_doc_elsewhere

User enters exact script name or regular expression into client. Client then requests selected servers to delete matching files from their designated elsewhere-paths.

reboot_server

Hereby the client transmits a request for the server to transfer control temporarilly to companion script gus_xml-rpc_update.pl which kills and restarts the server. Works for both Unix and Win32 being tested on NetBSD, Win2K and WinXP.

relay_sql_query

Assuming you have a database server (PostgreSQL, MySQL, etc.) on the same PC. Then this method will function very like a CGI web page so that you may relay SQL queries to it. Each method call will do as follows:

Open a new connection to the DB.
Pass a single SQL query.
Close the connection to the DB.
Transmit collected rows as an array back to the client.

There is not much advantage in doing this way unless you need to bridge a firewall, in which case you will, of course, also require the companion Perl/CGI script for doing just that. Suitable as a stop-gap until such time as you can persuade your friendly, local, corporate IT SysAdmin to unblock the port where your DB normally listens.

So if, like me, you have an fetal DB project gestating in your home PC, then this little feature will give you access to it from work until such time as it is ready for presentation to management. And then, being thus armed with a fait accompli, you stand a much better chance of weaning your IT department off their nasty commercial addition with a taste of open source.

Back to Top


SECURITY

Encryption
A full 56-byte Blowfish cipher is employed to secure data contained within the otherwise standard XML-RPC transactions. At startup, both client and server must employ identical plain text pass phrases (refer to $cipher_key near the head of each). Or if this has been left empty, a default pass phrase (refer to $GUS::Crypt::DEFAULT_KEY near the tail of each) will serve in its stead.. The client may later propagate new pass phrases to selected servers at any time.

For all methods
Method names are irreversibly obfuscated at startup (refer to subroutine $GUS::Crypt::obfuscate for details) and again each time the cipher is changed.

You may not rely upon the built-in default cipher key. The server will not allow it for any method except 'change_cipher'. Thus, in order to do anything useful, you will have to supply a cipher key of your own.

Transactions also require a password. At startup, both client and server must employ identical plain text passwords (refer to $plain_pw near the head of each). The client may later propagate new passwords to selected servers at any time.

The client and server each keep their own separate logs. Verbosity is according to user-elected startup options.

For the execute_script method
In making a script-execution request, all that the client does is pass a name to the server. The server makes its own determination whether to run said script. Firstly, the server enforces its own directory for executable scripts (same as for $script_script ) stripping away any ascending path elements. Secondly, it checks against its own list of allowable scripts (ref $script_list). Thirdly it makes sure the script is pure ASCII. Lastly it insures against any modification since upload or server startup.

Vulnerabilities
The server enforces whatever conditions it found on startup. That is to say, it cannot know whether a script to be employed by the execute_script method is free from any malicious tampering prior to startup. Nor does it filter the contents of pure ASCII scripts uploaded by the client. The user alone is wholly responsible for script content.

Back to Top


DEPENDENCIES

Perl Modules

Install these into Perl via ActiveState PPM, else into NetBSD via pkgsrc or CPAN as appropriate for your OS: Frontier::Daemon, Sys::Hostname::Long, Crypt::CBC, Crypt::Blowfish, Digest::MD5::File, Log::Logger.

Further, if you expect to relay SQL queries to a database server, then you will also require the DBI module and an associated DBD for whichever DB you are using.

My own GUS::Crypt package is already embeded in both the client and server scripts. It does not add anything truly novel but exists as a separate package for the sake of authorial convenience.

For Unix

Nothing here presentes itself as a difficulty. Required external dependencies are available from the expected sources: /usr/pkgsrc for NetBSD and/or CPAN for Perl. I cannot say for Linux, since I have yet to try it. If any report a problem for Linux, I would very like to help work it out and document the solution here

For Win32

No especial problems here either, except that some things are not where most folks expect to find them.

Cryptography for ActiveState Perl 5.8
The Crypt::* family of modules is not fully maintained by ActiveState who fears a lowering brow the US alphabet agencies. Happily, folks in more freedom-loving countries have ammended this lack. Just perform these steps in the ActiveState PPM window.

ppm> help repository

ppm> repository add ``Lincoln Stein'' http://stein.cshl.org/ppm

ppm> repository add ``Randy Kobes'' http://theoryx5.uwinnipeg.ca/ppms

Companion XML-RPC Client

Unless the companion Perl script gus_xml-rpc_client_tk.pl running on some other network-attached PC, this server will lack any client to communicate with. Refer to documentation for the client at this URL: http://starling.us/tet/gus_perl/gus_xml-rpc_pl/gus_xml-rpc_client_tk.html.

Auxilliary Perl Scripts

These are for use with the execute_script method. See the complete list at this URL: http://starling.us/tet/gus_perl/gus_xml-rpc_pl.

Back to Top


AUTHOR

Gan Uesli Starling <gan@starling.us>

Back to Top


COPYRIGHT

Copyright (c) 2005-2006, Gan Uesli Starling. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Back to Top


SCRIPT CATEGORIES

Networking

Back to Top