Author: jfthomps
Date: Thu Jun  2 19:40:08 2016
New Revision: 1746619

URL: http://svn.apache.org/viewvc?rev=1746619&view=rev
Log:
VCL-952 - API modifications to allow interaction via "VCL go" iOS app

the initial work for the VCL OneClick (renamed to VCL go) was done as a student 
project in the NCSU CSC Cloud Computing class in the Spring of 2012 by a group 
headed by Ignacio Dominguez

oneclick.php - initial commit

states.php:
-added newOneClick (also added to $actions['entry'])
-added submitOneClick
-added deleteOneClick
-added editOneClick
-added submitEditOneClick

utils.php:
-modified initGlobals: added case oneclicks to switch statement that includes 
files to include oneclick.php
-modified getUserRequests: added ostype to returned data for each reservation
-modified xmlrpccall: added XMLRPCgetOneClickParams, XMLRPCgetOneClicks, 
XMLRPCaddOneClick, XMLRPCeditOneClick, XMLRPCdeleteOneClick, and XMLRPCgetIP
-modified getNavMenu: added "VCL gos" to menu
-modified getDojoHTML: added cases newOneClick, editOneClick, submitOneClick, 
submitEditOneClick, and deleteOneClick to switch statement

xmlrpcWrappers.php:
-modified XMLRPCgetRequestIds: added ostype and serverowner to data returned 
for each reservation
-added XMLRPCgetOneClickParams
-added XMLRPCgetOneClicks
-added XMLRPCaddOneClick
-added XMLRPCeditOneClick
-added XMLRPCdeleteOneClick
-added XMLRPCgetIP

Added:
    vcl/trunk/web/.ht-inc/oneclick.php   (with props)
Modified:
    vcl/trunk/web/.ht-inc/states.php
    vcl/trunk/web/.ht-inc/utils.php
    vcl/trunk/web/.ht-inc/xmlrpcWrappers.php

Added: vcl/trunk/web/.ht-inc/oneclick.php
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/oneclick.php?rev=1746619&view=auto
==============================================================================
--- vcl/trunk/web/.ht-inc/oneclick.php (added)
+++ vcl/trunk/web/.ht-inc/oneclick.php Thu Jun  2 19:40:08 2016
@@ -0,0 +1,421 @@
+<?php
+
+/**
+ * \file
+ */
+
+/// signifies an error with the submitted name
+define("NAMEERR", 1);
+/// signifies an error with the submitted image
+define("IMAGEERR", 1 << 1);
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn newOneClick()
+///
+/// \brief prints form for submitting a new OneClick
+///
+////////////////////////////////////////////////////////////////////////////////
+function newOneClick() {
+       global $user, $mode, $submitErr;
+
+       if($submitErr) {
+               $imageid = processInputVar("imageid", ARG_NUMERIC);
+               $length = processInputVar("length", ARG_NUMERIC);
+               $autologin = processInputVar("autologin", ARG_NUMERIC) == 1 ? 1 
: 0;
+       }
+       else {
+               $imageid = getUsersLastImage($user['id']);
+               $length = 120;
+               $autologin = 0;
+       }
+
+       $query = "SELECT o.id, "
+              .        "o.name, "
+              .        "o.duration, "
+              .        "o.autologin, "
+              .        "i.prettyname AS imagename "
+              . "FROM oneclick o "
+              . "LEFT JOIN image i ON (o.imageid = i.id) "
+              . "WHERE o.status = 1 AND "
+              .       "o.userid = {$user['id']}";
+       $oneclicks = array();
+       $qh = doQuery($query, 101);
+       while($row = mysql_fetch_assoc($qh))
+               $oneclicks[$row['id']] = $row;
+
+       print "<H2>" . i("VCL go Configurator") . "</H2>\n";
+
+       printf(i("VCL gos are for use with the %sVCL iOS app%s. VCL gos can be 
managed here but can only be used from an iOS device.") . "<br><br>\n", "<a 
href=\"https://itunes.apple.com/us/app/vcl-go/id1068500147?mt=8\";>", "</a>");
+
+       if(count($oneclicks)) {
+               if($mode == 'submitEditOneClick' || $mode == 'deleteOneClick') {
+                       $tab1sel = "";
+                       $tab2sel = "selected=\"true\"";
+               }
+               else {
+                       $tab1sel = "selected=\"true\"";
+                       $tab2sel = "";
+               }
+               print "<div id=\"mainTabContainer\" 
dojoType=\"dijit.layout.TabContainer\"\n";
+               print "     style=\"width:800px;height:600px\">\n";
+
+               print "<div id=\"newOneClick\" 
dojoType=\"dijit.layout.ContentPane\" ";
+               print "title=\"" . i("New VCL go Configuration") . "\" 
$tab1sel>\n";
+       }
+
+       if(! $submitErr && $mode == 'submitOneClick')
+               print "<br><font color=\"#008000\">" . i("VCL go successfully 
created") . "</font><br>\n";
+
+       print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post 
onsubmit=\"return validateForm(this);\" >\n";
+       # name of OneClick
+       print "<br>\n";
+       print i("Choose a name for your new VCL go configuration") . "<br>\n";
+       printSubmitErr(NAMEERR);
+       print "<strong>" . i("Name:") . "</strong>\n";
+       print "<input type=\"text\" dojoType=\"dijit.form.ValidationTextBox\" ";
+       print "id=\"newOneClickName\" name=\"newOneClickName\" 
required=\"true\" invalidMessage=\"";
+       print i("Name can only contain letters, numbers, spaces, dashes(-), 
parenthesis, <br>and periods(.) and can be from 3 to 70 characters long");
+       print "\" regExp=\"^([-a-zA-Z0-9\. \(\)]){3,70}$\" style=\"width: 
300px\">";
+       print "<br><br>\n";
+
+       # resources; image types
+       $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
+       $resources["image"] = removeNoCheckout($resources["image"]);
+
+       print i("Please select the resource you want to use from the list:") . 
"<br>\n";
+       printSubmitErr(IMAGEERR);
+       print "<br>\n";
+       $images = getImages();
+       # list of images
+       print "<select name=\"imageid\">\n";
+       foreach($resources['image'] as $id => $image)
+               if($id == $imageid)
+                       print "  <option value=\"$id\" 
selected>$image</option>\n";
+               else
+                       print "  <option value=\"$id\">$image</option>\n";
+       print "</select>\n";
+       print "<br><br>\n";
+
+       # list of duration of the reservation from this OneClick
+       if(array_key_exists($imageid, $images))
+               $maxlength = $images[$imageid]['maxinitialtime'];
+       else
+               $maxlength = 0;
+       # create an array of usage times based on the user's max times
+       $maxtimes = getUserMaxTimes();
+       if($maxlength > 0 && $maxlength < $maxtimes['initial'])
+               $maxtimes['initial'] = $maxlength;
+       $lengths = array();
+       if($maxtimes["initial"] >= 30)
+               $lengths["30"] = "30 " . i("minutes");
+       if($maxtimes["initial"] >= 60)
+               $lengths["60"] = "1 " . i("hour");
+       for($i = 120; $i <= $maxtimes["initial"] && $i < 2880; $i += 60)
+               $lengths[$i] = $i / 60 . " " . i("hours");
+       for($i = 2880; $i <= $maxtimes["initial"]; $i += 1440)
+               $lengths[$i] = $i / 1440 . " " . i("days");
+       $last = $i;
+       print "<strong>" . i("Duration:") . "</strong>&nbsp;\n";
+       printSelectInput("length", $lengths, $length, 0, 0, 'reqlength');
+       print "<br><br>\n";
+
+       # other choice
+       print "<INPUT type=\"checkbox\" name=\"autologin\" value=\"1\"" . 
($autologin == 1 ? "checked=\"checked\"" : "") . ">";
+       print i("Auto Login");
+       print "<br><br>\n";
+
+       # submit button
+       $cdata = array('maxlength' => $last);
+       $cont = addContinuationsEntry('submitOneClick', $cdata, SECINDAY, 1, 0);
+       print "<INPUT type=\"hidden\" name=\"continuation\" value=\"$cont\">\n";
+       print "<INPUT type=\"submit\" value=\"" . i("Create VCL go 
Configuration") . "\">\n";
+
+       print "</FORM>\n";
+       # end of first tab
+       print "</div>\n";
+
+       if(count($oneclicks)) {
+               # the tab that list all the OneClicks the user have
+               print "<div id=\"listOneClick\" 
dojoType=\"dijit.layout.ContentPane\" ";
+               print "title=\"" . i("List of VCL go Configurations") . "\" 
$tab2sel>\n";
+               if($mode == 'submitEditOneClick') {
+                       print "<br><font color=\"#008000\">" . i("VCL go 
successfully updated");
+                       print "</font><br><br>\n";
+               }
+               elseif($mode == 'deleteOneClick') {
+                       print "<br><font color=\"#008000\">" . i("VCL go 
successfully deleted");
+                       print "</font><br><br>\n";
+               }
+       }
+
+       foreach($oneclicks as $oneclick) {
+               print "<fieldset id=\"list\" class=\"oneclicklist\">\n";
+
+               print i("VCL go Name:") . "\n";
+               $oneclickname = $oneclick['name'];
+               print "<strong>" . htmlentities($oneclickname) . "</strong>\n";
+               print "<br><br>\n";
+
+               $oneclickid = $oneclick['id'];
+
+               print i("Resource:") . " <strong>" . 
htmlentities($oneclick['imagename']) . "</strong><br>\n";
+               # Duration
+               $duration = $oneclick['duration'];
+               if($duration < 60) {
+                       print i("Duration:") . " <strong>" . $duration . " " . 
i("minutes") . "</strong><br>\n";
+               }
+               else {
+                       if($duration < (60 * 24)) {
+                               $hourduration = (int) $duration / 60;
+                               print i("Duration:") . " <strong>" . 
$hourduration . " " . i("hour") . ($hourduration == 1 ? "" : "s") . 
"</strong><br>";
+                       }
+                       else {
+                               $dayduration = (int) $duration / (60 * 24);
+                               print i("Duration:") . " <strong>" . 
$dayduration . " " . i("day") . ($dayduration == 1 ? "" : "s") . 
"</strong><br>";
+                       }
+               }
+               print i("Auto Login") . ": <strong>" . ($oneclick['autologin'] 
== 1 ? i("Yes") : i("No")) . "</strong><br>\n";
+               print "<br>\n";
+
+               $cdata = array('oneclickid' => $oneclickid,
+                              'oneclickname' => $oneclickname,
+                              'maxlength' => $last);
+
+               # edit button
+               print "<form action=\"" . BASEURL . SCRIPT . "\" 
method=\"post\" style=\"display: inline;\">\n";
+               $cont = addContinuationsEntry('editOneClick', $cdata, SECINDAY, 
1);
+               print "<input type=\"hidden\" name=\"continuation\" 
value=\"$cont\">\n";
+               print "<input type=\"submit\" value=\"" . i("Edit VCL go") . 
"\">\n";
+               print "</form>\n";
+
+               # Delete button
+               print "<form action=\"" . BASEURL . SCRIPT . "\" 
method=\"post\" style=\"display: inline;\">\n";
+               $cont = addContinuationsEntry('deleteOneClick', $cdata, 
SECINDAY, 1);
+               print "<input type=\"hidden\" name=\"continuation\" 
value=\"$cont\">\n";
+               print "<input type=\"submit\" value=\"" . i("Delete") . "\">\n";
+               print "</form>\n";
+
+               print "</fieldset>\n";
+               print "<br><br>\n";
+       }
+       if(count($oneclicks)) {
+               print "</div>\n";
+               print "</div>\n";
+       }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn submitOneClick()
+///
+/// \to create one Button from Web Configurator
+///
+////////////////////////////////////////////////////////////////////////////////
+function submitOneClick() {
+       global $user, $submitErr, $submitErrMsg;
+       $maxlength = getContinuationVar('maxlength');
+       $imageid = processInputVar("imageid", ARG_NUMERIC);
+       $name = processInputVar("newOneClickName", ARG_STRING);
+       $duration = processInputVar("length", ARG_NUMERIC);
+       $autologin = processInputVar("autologin", ARG_NUMERIC) == 1 ? 1 : 0;
+
+       # validate access to $imageid
+       $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
+       $images = removeNoCheckout($resources["image"]);
+       if(! array_key_exists($imageid, $images)) {
+          $submitErr |= IMAGEERR;
+          $submitErrMsg[IMAGEERR] = i("Invalid image submitted.");
+       }
+
+       # validate $name
+       if(! preg_match('/^([-a-zA-Z0-9\. \(\)]){3,70}$/', $name)) {
+          $submitErr |= NAMEERR;
+          $submitErrMsg[NAMEERR] = i("Name can only contain letters, numbers, 
spaces, dashes(-), parenthesis, <br>and periods(.) and can be from 3 to 70 
characters long");
+       }
+
+       if($submitErr) {
+               newOneClick();
+               return;
+       }
+
+       if($duration > $maxlength)
+               $duration = $maxlength;
+
+       $query = "INSERT INTO oneclick"
+              .        "(userid, "
+              .        "imageid, "
+              .        "name, "
+              .        "duration, "
+              .        "autologin, "
+              .        "status) "
+              . "VALUES "
+              .        "({$user['id']}, "
+              .        "$imageid, "
+              .        "'$name', "
+              .        "$duration, "
+              .        "$autologin, "
+              .        "1) ";
+       doQuery($query, 101);
+
+       newOneClick();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn deleteOneClick()
+///
+/// \to delete one Button from Web Configurator
+///
+////////////////////////////////////////////////////////////////////////////////
+function deleteOneClick() {
+       $oneclickid = getContinuationVar('oneclickid');
+       $query = "UPDATE oneclick SET status = 0 WHERE id = $oneclickid";
+       doQuery($query, 150);
+       newOneClick();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn editOneClick()
+///
+/// \to edit one Button from Web Configurator
+///
+////////////////////////////////////////////////////////////////////////////////
+function editOneClick() {
+       global $user, $submitErr;
+       $oneclickid = getContinuationVar('oneclickid');
+
+       if($submitErr)
+               $delfromself = 1;
+       else
+               $delfromself = 0;
+
+       $query = "SELECT o.imageid, "
+              .        "o.name, "
+              .        "o.duration, "
+              .        "o.autologin, "
+              .        "i.prettyname AS imagename, "
+              .        "i.id AS imageid "
+              . "FROM oneclick o "
+              . "LEFT JOIN image i ON (o.imageid = i.id) "
+              . "WHERE o.status = 1 AND "
+              .       "o.id = $oneclickid AND "
+              .       "o.userid = {$user['id']}";
+
+       $qh = doQuery($query, 101);
+       print "<form action=\"" . BASEURL . SCRIPT . "\" method=\"post\" 
style=\"display: inline;\" onsubmit=\"return validateForm(this);\">\n";
+
+       if(! ($row = mysql_fetch_assoc($qh))) {
+               print i("VCL go not found") . "\n";
+               return NULL;
+       }
+
+       print "<h2>" . i("VCL go Editor") . "</h2>\n";
+
+       print "<br>\n";
+       # infomations
+       # Name
+       printSubmitErr(NAMEERR);
+       print i("VCL go Name:") . " \n";
+       print "<input type=\"text\" dojoType=\"dijit.form.ValidationTextBox\" ";
+       print "id=\"name\" name=\"name\" required=\"true\" invalidMessage=\"";
+       print i("Name can only contain letters, numbers, spaces, dashes(-), 
parenthesis, <br>and periods(.) and can be from 3 to 70 characters long");
+       print "\" regExp=\"^([-a-zA-Z0-9\. \(\)]){3,70}$\" style=\"width: 
300px\" ";
+       print "value=\"" . htmlentities($row['name']) . "\">\n";
+       print "<br><br>\n";
+       # Image
+       print i("Resource:") . " <strong>" . htmlentities($row['imagename']) . 
"</strong><br>\n";
+       print "<br>\n";
+
+       # Duration
+       $preduration = $row['duration'];
+       $images = getImages(0, $row['imageid']);
+       $maxlength = $images[$row['imageid']]['maxinitialtime'];
+       $maxtimes = getUserMaxTimes();
+       if($maxlength == 0 || $maxlength < 0)
+               $maxlength = $maxtimes['initial'];
+       else
+               $maxlength = $maxtimes['initial'] > $maxlength ? $maxlength : 
$maxtimes['initial'];
+       $iteri = 30;
+       print "<strong>" . i("Duration:") . "</strong>\n";
+       print "  <select name=\"duration\">\n";
+       for($iteri = 30; $iteri <= $maxlength; $iteri+=60) {
+               if($iteri == 30) {
+                       print "<option value=\"$iteri\" " . ($iteri == 
$preduration ? "selected" : "") . ">30 " . i("minutes") . "</option>\n";
+                       $iteri+=30;
+               }
+               if($iteri >= 60 && $iteri < 1440) {
+                       $temphour = (int) $iteri / 60;
+                       if($temphour == 1)
+                               print "<option value=\"$iteri\" " . ($iteri == 
$preduration ? "selected" : "") . ">$temphour " . i("hour") . "</option>\n";
+                       else
+                               print "<option value=\"$iteri\" " . ($iteri == 
$preduration ? "selected" : "") . ">$temphour " . i("hours") . "</option>\n";
+                       continue;
+               }
+               if($iteri > 1440) {
+                       $tempday = (int) $iteri / 1440;
+                       if($tempday == 1)
+                               print "<option value=\"$iteri\" " . ($iteri == 
$preduration ? "selected" : "") . ">$tempday " . i("day") . "</option>\n";
+                       else
+                               print "<option value=\"$iteri\" " . ($iteri == 
$preduration ? "selected" : "") . ">$tempday " . i("days") . "</option>\n";
+                       continue;
+               }
+       }
+       print "  </select>\n";
+       print "<br><br>\n";
+       # Auto Login
+       print "<INPUT type=\"checkbox\" name=\"autologin\" value=\"1\"" . 
($row['autologin'] == 1 ? "checked=\"checked\"" : "") . ">";
+       print i("Auto Login");
+       print "<br><br>\n";
+       # submit
+       $cdata = array('oneclickid' => $oneclickid,
+                      'maxlength' => $maxlength);
+       $cont = addContinuationsEntry('submitEditOneClick', $cdata, SECINDAY, 
$delfromself, 0);
+       print "<INPUT type=hidden name=continuation value=\"$cont\">\n";
+       print "<INPUT type=submit value=\"" . i("Submit Changes") . "\">\n";
+       print "</form>\n";
+       # cancel
+       print "<form action=\"" . BASEURL . SCRIPT . "\" method=\"post\" 
style=\"display: inline;\">\n";
+       $cont = addContinuationsEntry('newOneClick', array(), SECINDAY);
+       print "<INPUT type=hidden name=continuation value=\"$cont\">\n";
+       print "<INPUT type=submit value=\"" . i("Cancel") . "\">\n";
+       print "</form>\n";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn submitEditOneClick()
+///
+/// \to submit the change to one Button
+///
+////////////////////////////////////////////////////////////////////////////////
+function submitEditOneClick() {
+       global $submitErr, $submitErrMsg;
+       $oneclickid = getContinuationVar('oneclickid');
+       $maxlength = getContinuationVar('maxlength');
+       $name = processInputVar('name', ARG_STRING);
+       $duration = processInputVar("duration", ARG_NUMERIC);
+       $autologin = processInputVar("autologin", ARG_NUMERIC) == 1 ? 1 : 0;
+
+       # validate $name
+       if(! preg_match('/^([-a-zA-Z0-9\. \(\)]){3,70}$/', $name)) {
+          $submitErr |= NAMEERR;
+          $submitErrMsg[NAMEERR] = i("Name can only contain letters, numbers, 
spaces, dashes(-), parenthesis, <br>and periods(.) and can be from 3 to 70 
characters long");
+               editOneClick();
+               return;
+       }
+
+       # validate $duration
+       if($duration > $maxlength)
+               $duration = $maxlength;
+
+       $query = "UPDATE oneclick "
+              . "SET duration = $duration, "
+              .     "name = '$name', "
+              .     "autologin = $autologin "
+              . "WHERE id = $oneclickid";
+       doQuery($query, 150);
+       newOneClick();
+}
+?>

Propchange: vcl/trunk/web/.ht-inc/oneclick.php
------------------------------------------------------------------------------
    svn:executable = *

Modified: vcl/trunk/web/.ht-inc/states.php
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/states.php?rev=1746619&r1=1746618&r2=1746619&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/states.php (original)
+++ vcl/trunk/web/.ht-inc/states.php Thu Jun  2 19:40:08 2016
@@ -60,6 +60,7 @@ $actions["entry"] = array('main',
                           'RESTresourceDetail',
                           #'testDojoREST',
                           'siteconfig',
+                          'newOneClick',
 );
 
 $noHTMLwrappers = array('sendRDPfile',
@@ -730,4 +731,15 @@ $actions['pages']['shiblogout'] = "misc"
 $actions['pages']['AJvalidateUserid'] = "misc";
 $actions['pages']['changeLocale'] = "misc";
 
+# OneClicks (VCL go)
+$actions['mode']['newOneClick'] = "newOneClick";
+$actions['mode']['submitOneClick'] = "submitOneClick";
+$actions['mode']['deleteOneClick'] = "deleteOneClick";
+$actions['mode']['editOneClick'] = "editOneClick";
+$actions['mode']['submitEditOneClick']= "submitEditOneClick";
+$actions['pages']['newOneClick'] = "oneClicks";
+$actions['pages']['submitOneClick'] = "oneClicks";
+$actions['pages']['deleteOneClick'] = "oneClicks";
+$actions['pages']['editOneClick'] = "oneClicks";
+$actions['pages']['submitEditOneClick'] = "oneClicks";
 ?>

Modified: vcl/trunk/web/.ht-inc/utils.php
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/utils.php?rev=1746619&r1=1746618&r2=1746619&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/utils.php (original)
+++ vcl/trunk/web/.ht-inc/utils.php Thu Jun  2 19:40:08 2016
@@ -309,6 +309,9 @@ function initGlobals() {
                        require_once(".ht-inc/serverprofiles.php");
                        require_once(".ht-inc/requests.php");
                        break;
+               case 'oneClicks':
+                       require_once(".ht-inc/oneclick.php");
+                       break;
                default:
                        require_once(".ht-inc/requests.php");
        }
@@ -6137,6 +6140,7 @@ function getUserRequests($type, $id=0) {
               .        "rq.daterequested, "
               .        "rq.id, "
               .        "o.prettyname AS OS, "
+              .        "o.type AS ostype, "
               .        "o.installtype AS OSinstalltype, "
               .        "rq.stateid AS currstateid, "
               .        "rq.laststateid, "
@@ -11898,6 +11902,12 @@ function xmlrpccall() {
        xmlrpc_server_register_method($xmlrpc_handle, 
"XMLRPCgetUserGroupMembers", "xmlRPChandler");
        xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCaddUsersToGroup", 
"xmlRPChandler");
        xmlrpc_server_register_method($xmlrpc_handle, 
"XMLRPCremoveUsersFromGroup", "xmlRPChandler");
+       xmlrpc_server_register_method($xmlrpc_handle, 
"XMLRPCgetOneClickParams", "xmlRPChandler");
+       xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCgetOneClicks", 
"xmlRPChandler");
+       xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCaddOneClick", 
"xmlRPChandler");
+       xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCeditOneClick", 
"xmlRPChandler");
+       xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCdeleteOneClick", 
"xmlRPChandler");
+       xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCgetIP", 
"xmlRPChandler");
        xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCautoCapture", 
"xmlRPChandler");
        xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCdeployServer", 
"xmlRPChandler");
        xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCgetNodes", 
"xmlRPChandler");
@@ -12659,6 +12669,9 @@ function getNavMenu($inclogout, $inchome
                $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=dashboard\">";
                $rt .= i("Dashboard") . "</a></li>\n";
        }
+       $rt .= menulistLI('oneClick');
+       $rt .= "<a href=\"" . BASEURL . SCRIPT . "?mode=newOneClick\">";
+       $rt .= i("VCL gos") . "</a></li>\n";
        if(checkUserHasPerm('Site Configuration (global)') ||
           checkUserHasPerm('Site Configuration (affiliation only)')) {
                $rt .= menulistLI('siteconfig');
@@ -12986,6 +12999,16 @@ function getDojoHTML($refresh) {
                                              'dojox.layout.FloatingPane',
                                              'dijit.layout.TabContainer');
                        break;
+               case 'newOneClick':
+               case 'editOneClick':
+               case 'submitOneClick':
+               case 'submitEditOneClick':
+               case 'deleteOneClick':
+                       $dojoRequires = array('dojo.parser',
+                                             'dijit.layout.ContentPane',
+                                             'dijit.form.ValidationTextBox',
+                                             'dijit.layout.TabContainer');
+                       break;
                # TODO clean up
                /*case 'testDojoREST':
                        $filename = '';

Modified: vcl/trunk/web/.ht-inc/xmlrpcWrappers.php
URL: 
http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php?rev=1746619&r1=1746618&r2=1746619&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/xmlrpcWrappers.php (original)
+++ vcl/trunk/web/.ht-inc/xmlrpcWrappers.php Thu Jun  2 19:40:08 2016
@@ -664,8 +664,10 @@ function XMLRPCgetRequestIds() {
                             'start' => $start,
                             'end' => $end,
                             'OS' => $req['OS'],
+                            'ostype' => $req['ostype'],
                             'isserver' => $req['server'],
-                            'admin' => $req['serveradmin']);
+                            'admin' => $req['serveradmin'],
+                            'serverowner' => $req['serverowner']);
                if($req['currstateid'] == 14)
                        $tmp['state'] = $states[$req['laststateid']];
                else
@@ -3730,4 +3732,394 @@ function XMLRPCfinishBaseImageCapture($o
        $obj->addImagePermissions($ownerdata, $resourceid, $virtual);
        return array('status' => 'success');
 }
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn XMLRPCgetOneClickParams($oneclickid)
+///
+/// \param $oneclickid - id of the one click
+///
+/// \return an array with at least one index named 'status' which will have
+/// one of these values:\n
+/// \b error - error occurred; there will be 2 additional elements in the 
array:
+/// \li \b errorcode - error number
+/// \li \b errormsg - error string
+///
+/// \b success - there will be these additional elements:
+/// \li \b name - name of one click
+/// \li \b imageid - id of image
+/// \li \b imagename - name of image
+/// \li \b ostype - type of OS in image
+/// \li \b duration - duration for reservations for this one click
+/// \li \b autologin - whether or not autologin should be used with this one
+/// click
+///
+/// \brief returns the parameters for a one click configuration
+///
+////////////////////////////////////////////////////////////////////////////////
+function XMLRPCgetOneClickParams($oneclickid) {
+       global $user;
+       $oneclickid = processInputData($oneclickid, ARG_NUMERIC);
+       $query = "SELECT o.id, "
+              .        "o.userid, "
+              .        "o.imageid, "
+              .        "i.prettyname AS imagename, "
+              .        "os.`type` AS ostype, "
+              .        "o.name, "
+              .        "o.duration, "
+              .        "o.autologin "
+              . "FROM oneclick o "
+              . "LEFT JOIN image i ON (o.imageid = i.id) "
+              . "LEFT JOIN OS os ON (i.OSid = os.id) "
+              . "WHERE o.id = $oneclickid AND "
+              .       "o.status = 1 AND "
+              .       "o.userid = {$user['id']}";
+       $qh = doQuery($query);
+       //if nothing returned, oneclick does not exist
+       if(! $row = mysql_fetch_assoc($qh)) {
+               return array('status' => 'error',
+                            'errorcode' => 95,
+                            'errormsg' => "The OneClick with ID $oneclickid 
does not exist.");
+       }
+       elseif($row['userid'] != $user['id']) {
+               return array('status' => 'error',
+                            'errorcode' => 90,
+                            'errormsg' => "The OneClick with ID $oneclickid 
does not belong to the user that requested it.");
+       }
+
+       return array('status' => 'success',
+                    'name' => $row['name'],
+                    'imageid' => $row['imageid'],
+                    'imagename' => $row['imagename'],
+                    'ostype' => $row['ostype'],
+                    'duration' => $row['duration'],
+                    'autologin' => $row['autologin']);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn XMLRPCgetOneClicks()
+///
+/// \return an array with 2 indices:\n
+/// \b status - will be 'success'\n
+/// \b oneclicks - will be an array of oneclicks
+///
+/// \brief builds an array of one clicks belonging to user
+///
+////////////////////////////////////////////////////////////////////////////////
+function XMLRPCgetOneClicks() {
+       global $user;
+       $states = "8,28,26,27,19,6,3,25,29";
+       $query = "SELECT o.id oneclickid, "
+               .       "rq.requestid, "
+               .       "COALESCE(rq.reqcount, 0) AS reqcount, "
+               .       "o.userid, "
+               .       "o.imageid, "
+               .       "i.prettyname imagename, "
+               .       "os.`type` ostype, "
+               .       "o.name, "
+               .       "o.duration, "
+               .       "o.autologin, "
+               .       "rq2.stateid AS currstateid, "
+               .       "rq2.laststateid "
+               . "FROM oneclick o "
+               . "LEFT JOIN image i ON (o.imageid = i.id) "
+               . "LEFT JOIN OS os ON (i.OSid = os.id) "
+               . "LEFT JOIN ("
+               .      "SELECT rs.imageid, "
+               .             "MAX(rq.id) AS requestid, " 
+               .             "COUNT(rq.id) AS reqcount " 
+               .      "FROM reservation rs, "
+               .           "request rq "
+               .      "WHERE rs.requestid = rq.id AND "
+               .            "rq.userid = {$user['id']} AND "
+               .            "(rq.stateid IN ($states) OR "
+               .            "(rq.stateid = 14 AND "
+               .             "rq.laststateid IN (13,$states))) " // also 
include new state if in pending
+               .      "GROUP BY rs.imageid) AS rq ON (rq.imageid = i.id) "
+               . "LEFT JOIN request rq2 ON (rq.requestid = rq2.id) "
+               . "WHERE o.status = 1 AND "
+               .       "o.userid = {$user['id']} "
+               . "ORDER BY o.name";
+       $qh = doQuery($query, 101);
+       if(! $qh) {
+               return array('status' => 'error',
+                            'errorcode' => 94,
+                            'errormsg' => "Unable to retrieve user's 
OneClicks.");
+       }
+       $result = array();
+       $result['status'] = 'success';
+       $result['oneclicks'] = array();
+       #$allstates = getStates();
+       while($row = mysql_fetch_assoc($qh)) {
+               /*if($row['currstateid'] == 14)
+                       $state = $allstates[$row['laststateid']];
+               elseif(! is_null($row['currstateid']))
+                       $state = $allstates[$row['currstateid']];
+               else
+                       $state = 'none';*/
+               $result['oneclicks'][] = array('oneclickid' => 
$row['oneclickid'],
+                                              'name' => $row['name'],
+                                              'imageid' => $row['imageid'],
+                                              'imagename' => $row['imagename'],
+                                              'ostype' => $row['ostype'],
+                                              'duration' => $row['duration'],
+                                              'autologin' => $row['autologin'],
+                                              'requestid' => $row['requestid'],
+                                              'reqcount' => $row['reqcount']/*,
+                                              'state' => $state*/);
+       }
+       return $result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn XMLRPCaddOneClick($name, $imageid, $duration, $autologin)
+///
+/// \param $name - name of new one click
+/// \param $imageid - id of image for new one click
+/// \param $duration - duration for reservations made for this one click
+/// \param $autologin - (?) 1 for autologin, 0 to skip autologin
+///
+/// \return an array with at least one index named 'status' which will have
+/// one of these values:\n
+/// \b error - error occurred; there will be 2 additional elements in the 
array:
+/// \li \b errorcode - error number
+/// \li \b errormsg - error string
+///
+/// \b success - there will be one additional element in this case:
+/// \li \b oneclickid - id of new one click
+///
+/// \brief adds a new one click to VCL
+///
+////////////////////////////////////////////////////////////////////////////////
+function XMLRPCaddOneClick($name, $imageid, $duration, $autologin) {
+       global $user;
+       $userid = $user['id'];
+       $imageid = processInputData($imageid, ARG_NUMERIC);
+       $name = processInputData($name, ARG_STRING);
+       $duration = processInputData($duration, ARG_NUMERIC);
+       $autologin = processInputData($autologin, ARG_NUMERIC) == 1 ? 1 : 0;
+
+       # validate $imageid
+       $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
+       $images = removeNoCheckout($resources["image"]);
+       if(! array_key_exists($imageid, $images)) {
+               return array('status' => 'error',
+                            'errorcode' => 93,
+                            'errormsg' => "Unable to create OneClick.");
+       }
+
+       # validate $name
+       if(! preg_match('/^([-a-zA-Z0-9\. \(\)]){3,70}$/', $name)) {
+               return array('status' => 'error',
+                            'errorcode' => 93,
+                            'errormsg' => "Unable to create OneClick.");
+       }
+
+       # validate $duration
+       $images = getImages(0, $imageid);
+       $maxlength = $images[$imageid]['maxinitialtime'];
+       $maxtimes = getUserMaxTimes();
+       if($maxlength && $maxlength < $maxtimes['initial'])
+               $maxduration = $maxlength;
+       else
+               $maxduration = $maxtimes['initial'];
+       if($duration > $maxduration) {
+               return array('status' => 'error',
+                            'errorcode' => 93,
+                            'errormsg' => "Unable to create OneClick.");
+       }
+
+       $query = "INSERT INTO oneclick"
+              .        "(userid, "
+              .        "imageid, "
+              .        "name, "
+              .        "duration, "
+              .        "autologin, "
+              .        "status) "
+              . "VALUES "
+              .        "($userid, "
+              .        "$imageid, "
+              .        "'$name', "
+              .        "$duration, "
+              .        "$autologin, "
+              .        "1) ";
+       $qh = doQuery($query, 101);
+       if(! $qh) {
+               return array('status' => 'error',
+                            'errorcode' => 93,
+                            'errormsg' => "Unable to create OneClick.");
+       }
+       $return = array();
+       $return['oneclickid']= dbLastInsertID();
+       $return['status'] = 'success';
+       return $return;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn XMLRPCeditOneClick($oneclickid, $name, $imageid, $duration, $autologin)
+///
+/// \param $oneclickid - id of the one click
+/// \param $name - name of new one click
+/// \param $imageid - id of image for new one click
+/// \param $duration - duration for reservations made for this one click
+/// \param $autologin - (?) 1 for autologin, 0 to skip autologin
+///
+/// \return an array with at least one index named 'status' which will have
+/// one of these values:\n
+/// \b error - error occurred; there will be 2 additional elements in the 
array:
+/// \li \b errorcode - error number
+/// \li \b errormsg - error string
+///
+/// \b success - there will be these additional elements:
+/// \li \b name - name of one click
+/// \li \b imageid - id of image
+/// \li \b imagename - name of image
+/// \li \b ostype - type of OS in image
+/// \li \b duration - duration for reservations for this one click
+/// \li \b autologin - whether or not autologin should be used with this one
+/// click
+///
+/// \brief edits the configuration of a one click
+///
+////////////////////////////////////////////////////////////////////////////////
+function XMLRPCeditOneClick($oneclickid, $name, $imageid, $duration, 
$autologin) {
+       global $user;
+       $oneclickid = processInputData($oneclickid, ARG_NUMERIC);
+       $imageid = processInputData($imageid, ARG_NUMERIC);
+       $name = processInputData($name, ARG_STRING);
+       $duration = processInputData($duration, ARG_NUMERIC);
+       $autologin = processInputData($autologin, ARG_NUMERIC) == 1 ? 1 : 0;
+
+       # validate $imageid
+       $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
+       $images = removeNoCheckout($resources["image"]);
+       if(! array_key_exists($imageid, $images)) {
+               return array('status' => 'error',
+                            'errorcode' => 92,
+                            'errormsg' => "Invalid image specified");
+       }
+
+       # validate $name
+       if(! preg_match('/^([-a-zA-Z0-9\. \(\)]){3,70}$/', $name)) {
+               return array('status' => 'error',
+                            'errorcode' => 96,
+                            'errormsg' => "Invalid name specified - name can 
be from 3 to 70 characters long and can only contain letters, numbers, spaces, 
and these characters: - . ( )");
+       }
+
+       # validate $duration
+       $images = getImages(0, $imageid);
+       $maxlength = $images[$imageid]['maxinitialtime'];
+       $maxtimes = getUserMaxTimes();
+       if($maxlength && $maxlength < $maxtimes['initial'])
+               $maxduration = $maxlength;
+       else
+               $maxduration = $maxtimes['initial'];
+       if($duration > $maxduration) {
+               $allowed = prettyLength($maxduration);
+               return array('status' => 'error',
+                            'errorcode' => 97,
+                            'errormsg' => "Specified duration is too long",
+                            'maxduration' => $allowed);
+       }
+       
+       $query = "SELECT id "
+              . "FROM oneclick "
+              . "WHERE id = $oneclickid AND "
+              .       "status = 1 AND "
+              .       "userid = {$user['id']}";
+       $qh = doQuery($query, 101);
+       //if nothing returned, oneclick does not exist or belongs to another 
user
+       if(! $row = mysql_fetch_assoc($qh)) {
+               return array('status' => 'error',
+                            'errorcode' => 95,
+                            'errormsg' => "The OneClick with ID $oneclickid 
does not exist.");
+       }
+       /*elseif($row['userid'] != $user['id']) {
+               return array('status' => 'error',
+                            'errorcode' => 90,
+                            'errormsg' => "The OneClick with ID $oneclickid 
does not belong to the user that requested it.");
+       }*/
+       
+       $query = "UPDATE oneclick "
+              . "SET imageid = $imageid, "
+              .     "name = '$name', "
+              .     "duration = $duration, "
+              .     "autologin = $autologin "
+              . "WHERE id = $oneclickid AND "
+              .       "userid = {$user['id']}";
+       $qh = doQuery($query, 101);
+       if(! $qh)
+               return array('status' => 'error',
+                            'errorcode' => 98,
+                            'errormsg' => "Unable to update OneClick.");
+
+       return XMLRPCgetOneClickParams($oneclickid);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn XMLRPCdeleteOneClick($oneclickid) {
+///
+/// \param $oneclickid - id of the one click
+///
+/// \return an array with at least one index named 'status' which will have
+/// one of these values:\n
+/// \b error - error occurred; there will be 2 additional elements in the 
array:
+/// \li \b errorcode - error number
+/// \li \b errormsg - error string
+///
+/// \b success - one click was successfully deleted
+///
+/// \brief deletes a one click
+///
+////////////////////////////////////////////////////////////////////////////////
+function XMLRPCdeleteOneClick($oneclickid) {
+       global $user;
+       $oneclickid = processInputData($oneclickid, ARG_NUMERIC);
+       
+       $query = "SELECT id "
+              . "FROM oneclick "
+              . "WHERE id = $oneclickid AND "
+              .       "userid = {$user['id']}";
+       $qh = doQuery($query, 101);
+       //if nothing returned, oneclick does not exist or belongs to another 
user
+       if(! $row = mysql_fetch_assoc($qh)) {
+               return array('status' => 'error',
+                            'errorcode' => 95,
+                            'errormsg' => "The OneClick with ID $oneclickid 
does not exist.");
+       }
+
+       $query = "UPDATE oneclick "
+              . "SET status = 0 "
+              . "WHERE id = $oneclickid AND "
+              .       "userid = {$user['id']}";
+       $qh = doQuery($query, 101);
+       if(! $qh) {
+               return array('status' => 'error',
+                            'errorcode' => 91,
+                            'errormsg' => "Unable to delete OneClick.");
+       }
+       $return = array();
+       $return['status'] = 'success';
+       return $return;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn XMLRPCgetIP()
+///
+/// \return an array with 2 indices:\n
+/// \b status - will be 'success'\n
+/// \b ip - will be the client's IP address as seen by the server\n
+///
+/// \brief this is a function that returns the client's IP address as seen by
+/// the server
+///
+////////////////////////////////////////////////////////////////////////////////
+function XMLRPCgetIP() {
+       return array('status' => 'success', 'ip' => $_SERVER['REMOTE_ADDR']);
+}
 ?>



Reply via email to