Mani,
there is documentation for the XML RPC located here: http://people.apache.org/~jfthomps/xmlrpcdocs/xmlrpcWrappers_8php.html

I have been using the remote API for some time now, and it works very well. To make things easier for me, I wrote a php class that encapsulates some of these functions (see attached). This class doesn't implement any of the group management features, but they would be easy to add.

You can then use the class like this (if, for instance, you wanted to list the reservations for a particular user):

$vcl = new VCL($userid, $password);

if ($reservations = $vcl->getReservations()){
foreach ($reservations as $r){
print "<p>";
print "<b>{$r['imagename']}</b> ";
if ($status = $vcl->getRequestStatus($r['requestid'])){
switch ($status['status']){
...
}
}
print "</p>";
}
}

The authentication piece is handed off to the appropriate affiliation function in the VCL code, so if you are using LDAP, the user's password would be verified in that way. Since we use Shibboleth with our VCL installation, the web application (neither the VCL nor any remote webapp) will know anything about what constitutes a valid password, so I ended up modifying the 'checkAccess()' function in .ht-inc/utils.php. If this is relevant for your installation, I can explain further how this is done.

The remote API allows me, for instance, to embed the VCL inside other web applications (such as our campus learning management system), without requiring students to login to the main VCL site when they want to make and connect to their reservations.

Best regards,
Aaron


<?php

class VCL {

    const VCLHOST = "YOUR VCL HOST LOCATION HERE";

    public $errcode = 0;
    public $errmsg = "";
    public $message = "";
    private $username = "";
    private $password = "";


    public function __construct($username, $password){
        $this->username = $username;
        $this->password = $password;
    }


    public function getImages(){
        if($images = $this->rpc('XMLRPCgetImages', array()))
            if( count($images) )
                return $images;
        return 0;
    }


    public function addReservation($imageid, $time, $duration){
        if( $rc = $this->rpc('XMLRPCaddRequest', array($imageid, $time, $duration))){
            $this->message = "Successfully added reservation.";
            return 1;
        } else {
            return 0;
        }
    }

    public function extendReservation($id, $duration){
        $this->reset();
        if( $rc = $this->rpc("XMLRPCextendRequest", array($id, $duration))){
            $this->message = "Reservation successfully extended.";
            return 1;
        } else {
            return 0;
        }
    }

    public function deleteReservation($id){
        $this->reset();
        if( $rc = $this->rpc("XMLRPCendRequest", array($id))){ 
            $this->message = "Reservation successfully deleted.";
            return 1;
        } else {
            return 0;
        }
    }


    public function getRequestStatus($id){
        $this->reset();
        if( $rc = $this->rpc("XMLRPCgetRequestStatus", array($id)))
            return $rc;
        else
            return 0;
    }


    public function getConnectData($requestid, $remote_addr){
        $this->reset();
        if( $rc = $this->rpc("XMLRPCgetRequestConnectData", array($requestid,
            $remote_addr))){
            if( $rc["status"] == "ready" ){
                return array( "serverIP" => $rc["serverIP"],
                              "user" => $rc["user"],
                              "password" => $rc["password"] );
            } else {
                $this->message = "The connection is not yet ready.";
            }
        }
        return 0;
    }

    public function affiliations(){
        $this->reset();
        if($response = $this->rpc("XMLRPCaffiliations", array())){
            if(count($response)){
                return $response;
            }
        }
        return 0;
    }

    public function getReservations(){
        $this->reset();
        if($response = $this->rpc('XMLRPCgetRequestIds', array()))
            if( count( $response["requests"] ) )
                return $response["requests"];
        return 0;
    }


    private function reset(){
        $this->errcode = 0;
        $this->errmsg = "";
        $this->message = "";
    }


    private function rpc($method, $args) {
        $request = xmlrpc_encode_request($method, $args);
        $header  = "Content-Type: text/xml\r\n";
        $header .= "X-User: " . $this->username . "\r\n";
        $header .= "X-Pass: " . $this->password . "\r\n";
        $header .= "Cookie: " . $_SERVER["HTTP_COOKIE"] . "\r\n";
        $header .= "X-APIVERSION: 2";
        $context = stream_context_create(
                array(
                        'http' => array(
                                'method' => "POST",
                                'header' => $header,
                                'content' => $request
                        )
                )
        );
        $location = "?mode=" . ($method == "XMLRPCaffiliations" ? "xmlrpcaffiliations" :
                                                                  "xmlrpccall"); 
        $file = file_get_contents(self::VCLHOST.$location, false, $context);
        $response = xmlrpc_decode($file);
        if( isset($response['status']) && $response['status'] == 'error' ){
            $this->errcode = $response['errorcode'];
            $this->errmsg = $response['errormsg'];
            return;
        } else {
            return $response;
        }
    }
} // class VCL


--
Aaron Coburn
Systems Administrator and Programmer
Academic Technology Services, Amherst College
(413) 542-5451 acob...@amherst.edu





On Nov 29, 2011, at 6:08 PM, Mani Shafa'atDoost wrote:

Josh,

Thank you. Do you have any proper documentation for functions that you provided by XML RPC?

Best Regards
Mani

On Tue, Nov 29, 2011 at 4:32 PM, Josh Thompson <josh_thomp...@ncsu.edu> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mani,

Unfortunately, the example code is way out of date and uses API version 1
which is no longer supported.

A more current example, though in python, is available here:

https://svn.apache.org/repos/asf/incubator/vcl/sandbox/useful_scripts/managegroups.py

Josh

On Sunday November 20, 2011, Mani Shafa'atDoost wrote:
> Hello,
>
> I just used your sample file to use VCL through XMLRPC, but I received
> following error :
>
> *Notice*:  xmlrpc: Unsupported API version, cannot continue.
>
> I just modified username and password in your sample PHP file. I will
> appreciate if you could guide me.
>
>
> Best Regards
>
> Mani
- --
- -------------------------------
Josh Thompson
VCL Developer
North Carolina State University

my GPG/PGP key can be found at pgp.mit.edu
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)

iEYEARECAAYFAk7VT1MACgkQV/LQcNdtPQP+5ACfTAXRcH07hlq+Efkt1NTSfoey
vBYAnRhq3Tu0u0C7+9l3eIva8oY4zdQB
=vdCS
-----END PGP SIGNATURE-----


Reply via email to