You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by jf...@apache.org on 2015/03/07 00:00:55 UTC

svn commit: r1664756 - in /vcl/trunk/web: .ht-inc/image.php .ht-inc/resource.php .ht-inc/utils.php .ht-inc/xmlrpcWrappers.php js/resources/image.js

Author: jfthomps
Date: Fri Mar  6 23:00:54 2015
New Revision: 1664756

URL: http://svn.apache.org/r1664756
Log:
VCL-392 - Add option to rename computer separate from Sysprep

image.php:
-modified fieldDisplayName: added sethostname to fields for which a custom value is returned
-modified addEditDialogHTML: (unrelated) wrapped description text for Usage Notes and Revision Comments; added sethostname widget that is wrapped with a div that can be hidden; wrapped sysprep with a div that can be hidden
-modified AJsaveResource: added sethostname to fields that trigger imagemeta table being updated
-modified createImage: added ostype to fields added to $data for passing to addResource
-modified addResource: added sethostname to fields that trigger entry being added imagemeta table
-modified validateResourceData: added sethostname to fields returned and validated

resource.php: modified AJstartImage: added ostype to array of json data returned

utils.php: getImages: added 'sethostname' to set of fields returned for each image

xmlrpcWrappers.php: modified XMLRPCautoCapture: added 'ostype' and 'sethostname' to array of data passed to addResource function

image.js:
-modified colformatter: added sethostname to fields for which true/false is returned
-modified inlineEditResourceCB: added sethostname to widgets having their value set; show/hide sethostnamediv based on ostype
-modified resetEditResource: added sethostname to fields reset
-modified saveResource: added sethostname to data that is validated, only show error if sethostnamediv is displayed
-modified saveResourceCB: added sethostname to fields updated in store and to widgets being reset
-modified startImageCB: added code to show/hide sethostnamediv and to initialize value for sethostname widget; added code to show/hide new div that wrpas the sysprep widget so it is only shown for Windows images

Modified:
    vcl/trunk/web/.ht-inc/image.php
    vcl/trunk/web/.ht-inc/resource.php
    vcl/trunk/web/.ht-inc/utils.php
    vcl/trunk/web/.ht-inc/xmlrpcWrappers.php
    vcl/trunk/web/js/resources/image.js

Modified: vcl/trunk/web/.ht-inc/image.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/image.php?rev=1664756&r1=1664755&r2=1664756&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/image.php (original)
+++ vcl/trunk/web/.ht-inc/image.php Fri Mar  6 23:00:54 2015
@@ -141,6 +141,8 @@ class Image extends Resource {
 				return _("Check Logged in User");
 			case 'rootaccess':
 				return _("Admin. Access");
+			case 'sethostname':
+				return _("Set Hostname");
 		}
 		return _(ucfirst($field));
 	}
@@ -353,16 +355,16 @@ class Image extends Resource {
 		# usage notes
 		$h .= "<fieldset>\n";
 		$h .= "<legend>" . _("Usage Notes") . "</legend>\n";
-		$h .= _("Optional notes to the user explaining how to use the image (users will see this on the <strong>Connect!</strong> page):");
-		$h .= "<br>\n";
+		$msg = _("Optional notes to the user explaining how to use the image (users will see this on the <strong>Connect!</strong> page):");
+		$h .= preg_replace("/(.{1,100}([ \n]|$))/", '\1<br>', $msg);
 		$h .= "<textarea dojoType=\"dijit.form.Textarea\" id=\"usage\" ";
 		$h .= "style=\"width: 400px; text-align: left;\"></textarea>\n";
 		$h .= "</fieldset>\n";
 		if($add) {
 			$h .= "<fieldset>\n";
 			$h .= "<legend>" . _("Revision Comments") . "</legend>\n";
-			$h .= _("Notes for yourself and other admins about how the image was setup/installed. These are optional and are not visible to end users.");
-			$h .= "<br>\n";
+			$msg = _("Notes for yourself and other admins about how the image was setup/installed. These are optional and are not visible to end users.");
+			$h .= preg_replace("/(.{1,80}([ \n]|$))/", '\1<br>', $msg);
 			$h .= "<textarea dojoType=\"dijit.form.Textarea\" id=\"imgcomments\" ";
 			$h .= "style=\"width: 400px; text-align: left;\"></textarea>";
 			$h .= "</fieldset>\n";
@@ -409,9 +411,16 @@ class Image extends Resource {
 		$h .= labeledFormItem('checkuser', _('Check for logged in user'), 'select', $yesno);
 		# admin access
 		$h .= labeledFormItem('rootaccess', _('Users have administrative access'), 'select', $yesno);
+		# set hostname
+		$h .= "<div id=\"sethostnamediv\">\n";
+		$h .= labeledFormItem('sethostname', _('Set computer hostname'), 'select', $yesno);
+		$h .= "</div>\n";
 		# sysprep
-		if($add)
+		if($add) {
+			$h .= "<div id=\"sysprepdiv\">\n";
 			$h .= labeledFormItem('sysprep', _('Use sysprep'), 'select', $yesno);
+			$h .= "</div>\n";
+		}
 		# connect methods
 		$h .= "<label for=\"connectmethodlist\">" . _("Connect methods:") . "</label>\n";
 		$h .= "<div class=\"labeledform\"><span id=\"connectmethodlist\"></span><br>\n";
@@ -749,12 +758,20 @@ class Image extends Resource {
 			doQuery($query);
 		}
 		if(empty($olddata['imagemetaid']) &&
-		   ($data['checkuser'] == 0 || $data['rootaccess'] == 0)) {
+		   ($data['checkuser'] == 0 || $data['rootaccess'] == 0 ||
+		   ($olddata['ostype'] == 'windows' && $data['sethostname'] == 1) ||
+		   ($olddata['ostype'] == 'linux' && $data['sethostname'] == 0))) {
+			if(($olddata['ostype'] != 'windows' && $olddata['ostype'] != 'linux') ||
+			   ($olddata['ostype'] == 'windows' && $data['sethostname'] == 0) ||
+			   ($olddata['ostype'] == 'linux' && $data['sethostname'] == 1))
+				$data['sethostname'] = 'NULL';
 			$query = "INSERT INTO imagemeta "
 					 .        "(checkuser, "
-					 .        "rootaccess) "
+					 .        "rootaccess, "
+					 .        "sethostname) "
 					 . "VALUES ({$data['checkuser']}, "
-					 .        "{$data['rootaccess']})";
+					 .        "{$data['rootaccess']}, "
+					 .        "{$data['sethostname']})";
 			doQuery($query, 101);
 			$qh = doQuery("SELECT LAST_INSERT_ID() FROM imagemeta", 101);
 			if(! $row = mysql_fetch_row($qh))
@@ -767,10 +784,17 @@ class Image extends Resource {
 		}
 		elseif(! empty($olddata['imagemetaid'])) {
 			if($data['checkuser'] != $olddata['checkuser'] ||
-			   $data['rootaccess'] != $olddata['rootaccess']) {
+			   $data['rootaccess'] != $olddata['rootaccess'] ||
+			   (($olddata['ostype'] == 'windows' || $olddata['ostype'] == 'linux') &&
+			     $data['sethostname'] != $olddata['sethostname'])) {
+				if(($olddata['ostype'] != 'windows' && $olddata['ostype'] != 'linux') ||
+			      ($olddata['ostype'] == 'windows' && $data['sethostname'] == 0) ||
+			      ($olddata['ostype'] == 'linux' && $data['sethostname'] == 1))
+					$data['sethostname'] = 'NULL';
 				$query = "UPDATE imagemeta "
 						 . "SET checkuser = {$data['checkuser']}, "
-						 .     "rootaccess = {$data['rootaccess']} "
+						 .     "rootaccess = {$data['rootaccess']}, "
+						 .     "sethostname = {$data['sethostname']} "
 						 . "WHERE id = {$olddata['imagemetaid']}";
 				doQuery($query, 101);
 			}
@@ -831,6 +855,7 @@ class Image extends Resource {
 		$imagedata = getImages(0, $data["imageid"]);
 		$data["platformid"] = $imagedata[$data["imageid"]]["platformid"];
 		$data["osid"] = $imagedata[$data["imageid"]]["osid"];
+		$data["ostype"] = $imagedata[$data["imageid"]]["ostype"];
 		$data["basedoffrevisionid"] = $data["baserevisionid"];
 		$data["reload"] = 10;
 		$data["autocaptured"] = 0;
@@ -1127,15 +1152,23 @@ class Image extends Resource {
 		$imagemetaid = 0;
 		if($data['checkuser'] == 0 ||
 		   $data['rootaccess'] == 0 ||
-		   $data['sysprep'] == 0) {
+			$data['sysprep'] == 0 ||
+		   ($data['ostype'] == 'windows' && $data['sethostname'] == 1) ||
+		   ($data['ostype'] == 'linux' && $data['sethostname'] == 0)) {
+			if(($data['ostype'] != 'windows' && $data['ostype'] != 'linux') ||
+		      ($data['ostype'] == 'windows' && $data['sethostname'] == 0) ||
+		      ($data['ostype'] == 'linux' && $data['sethostname'] == 1))
+				$data['sethostname'] = 'NULL';
 			$query = "INSERT INTO imagemeta "
 			       .        "(checkuser, "
 			       .        "rootaccess, "
-			       .        "sysprep) "
+			       .        "sysprep, "
+			       .        "sethostname) "
 			       . "VALUES "
 			       .        "({$data['checkuser']}, "
 			       .        "{$data['rootaccess']}, "
-			       .        "{$data['sysprep']})";
+			       .        "{$data['sysprep']}, "
+			       .        "{$data['sethostname']})";
 			doQuery($query, 101);
 			$imagemetaid = dbLastInsertID();
 		}
@@ -1492,6 +1525,7 @@ class Image extends Resource {
 		$return["checkout"] = processInputVar("checkout", ARG_NUMERIC);
 		$return["checkuser"] = processInputVar("checkuser", ARG_NUMERIC);
 		$return["rootaccess"] = processInputVar("rootaccess", ARG_NUMERIC);
+		$return["sethostname"] = processInputVar("sethostname", ARG_NUMERIC);
 		$return["sysprep"] = processInputVar("sysprep", ARG_NUMERIC); # only in add
 		$return["connectmethodids"] = processInputVar("connectmethodids", ARG_STRING); # only in add
 
@@ -1591,6 +1625,10 @@ class Image extends Resource {
 			$return['error'] = 1;
 			$errormsg[] = _("Users have administrative access must be Yes or No");
 		}
+		if($return['sethostname'] != 0 && $return['sethostname'] != 1) {
+			$return['error'] = 1;
+			$errormsg[] = _("Set computer hostname must be Yes or No");
+		}
 		if($return['mode'] == 'add' && $return['sysprep'] != 0 &&
 		   $return['sysprep'] != 1) {
 			$return['error'] = 1;

Modified: vcl/trunk/web/.ht-inc/resource.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/resource.php?rev=1664756&r1=1664755&r2=1664756&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/resource.php (original)
+++ vcl/trunk/web/.ht-inc/resource.php Fri Mar  6 23:00:54 2015
@@ -1665,6 +1665,7 @@ function AJstartImage() {
 			}
 		}
 	}
+	$ostype = 'windows';
 	if(! empty($imageid)) {
 		$imageData = getImages(0, $imageid);
 		if($imageData[$imageid]['ownerid'] == $user['id'])
@@ -1672,6 +1673,7 @@ function AJstartImage() {
 		if($imageData[$imageid]['installtype'] == 'none' ||
 		   $imageData[$imageid]['installtype'] == 'kickstart')
 			$disableUpdate = 1;
+		$ostype = $imageData[$imageid]['ostype'];
 	}
 	else {
 		$data['status'] = 'error';
@@ -1691,7 +1693,8 @@ function AJstartImage() {
 	             'enableupdate' => 0,
 	             'connectmethods' => $imageData[$imageid]['connectmethods'],
 	             'owner' => "{$user['unityid']}@{$user['affiliation']}",
-	             'checkpoint' => $checkpoint);
+	             'checkpoint' => $checkpoint,
+	             'ostype' => $ostype);
 
 	$cdata = array('obj' => $obj,
 	               'imageid' => $imageid,

Modified: vcl/trunk/web/.ht-inc/utils.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/utils.php?rev=1664756&r1=1664755&r2=1664756&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/utils.php (original)
+++ vcl/trunk/web/.ht-inc/utils.php Fri Mar  6 23:00:54 2015
@@ -1244,6 +1244,7 @@ function getImages($includedeleted=0, $i
 	       .        "rootaccess, "
 	       .        "subimages, "
 	       .        "sysprep, "
+	       .        "sethostname, "
 	       .        "id "
 	       . "FROM imagemeta";
 	$qh = doQuery($query);
@@ -1329,12 +1330,18 @@ function getImages($includedeleted=0, $i
 		$imagelist[$includedeleted][$row["id"]] = $row;
 		$imagelist[$includedeleted][$row["id"]]['checkuser'] = 1;
 		$imagelist[$includedeleted][$row["id"]]['rootaccess'] = 1;
+		if($row['ostype'] == 'windows' || $row['ostype'] == 'osx')
+			$imagelist[$includedeleted][$row['id']]['sethostname'] = 0;
+		else
+			$imagelist[$includedeleted][$row['id']]['sethostname'] = 1;
 		if($row["imagemetaid"] != NULL) {
 			if(array_key_exists($row['imagemetaid'], $allmetadata)) {
 				$metaid = $row['imagemetaid'];
 				$imagelist[$includedeleted][$row['id']]['checkuser'] = $allmetadata[$metaid]['checkuser'];
 				$imagelist[$includedeleted][$row['id']]['rootaccess'] = $allmetadata[$metaid]['rootaccess'];
 				$imagelist[$includedeleted][$row['id']]['sysprep'] = $allmetadata[$metaid]['sysprep'];
+				if($allmetadata[$metaid]['sethostname'] != NULL)
+					$imagelist[$includedeleted][$row['id']]['sethostname'] = $allmetadata[$metaid]['sethostname'];
 				$imagelist[$includedeleted][$row["id"]]["subimages"] = array();
 				if($allmetadata[$metaid]["subimages"]) {
 					$query2 = "SELECT imageid "

Modified: vcl/trunk/web/.ht-inc/xmlrpcWrappers.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php?rev=1664756&r1=1664755&r2=1664756&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/xmlrpcWrappers.php (original)
+++ vcl/trunk/web/.ht-inc/xmlrpcWrappers.php Fri Mar  6 23:00:54 2015
@@ -1335,6 +1335,8 @@ function XMLRPCautoCapture($requestid) {
 		              'basedoffrevisionid' => $reqData['reservations'][0]['imagerevisionid'],
 		              'platformid' => $imageData[$imageid]['platformid'],
 		              'osid' => $imageData[$imageid]["osid"],
+		              'ostype' => $imageData[$imageid]["ostype"],
+		              'sethostname' => $imageData[$imageid]["sethostname"],
 		              'reload' => 20,
 		              'comments' => $comments,
 		              'connectmethodids' => implode(',', array_keys($connectmethods)),

Modified: vcl/trunk/web/js/resources/image.js
URL: http://svn.apache.org/viewvc/vcl/trunk/web/js/resources/image.js?rev=1664756&r1=1664755&r2=1664756&view=diff
==============================================================================
--- vcl/trunk/web/js/resources/image.js (original)
+++ vcl/trunk/web/js/resources/image.js Fri Mar  6 23:00:54 2015
@@ -28,7 +28,8 @@ Image.prototype.colformatter = function(
 	   obj.field == 'test' ||
 	   obj.field == 'forcheckout' ||
 	   obj.field == 'checkuser' ||
-	   obj.field == 'rootaccess') {
+	   obj.field == 'rootaccess' ||
+	   obj.field == 'sethostname') {
 		if(value == "0")
 			return '<span class="rederrormsg">' + _('false') + '</span>';
 		if(value == "1")
@@ -62,6 +63,11 @@ function inlineEditResourceCB(data, ioAr
 		dijit.byId('checkout').set('value', data.items.data.forcheckout);
 		dijit.byId('checkuser').set('value', data.items.data.checkuser);
 		dijit.byId('rootaccess').set('value', data.items.data.rootaccess);
+		dijit.byId('sethostname').set('value', data.items.data.sethostname);
+		if(data.items.data.ostype == 'windows' || data.items.data.ostype == 'linux')
+			dojo.removeClass('sethostnamediv', 'hidden');
+		else
+			dojo.addClass('sethostnamediv', 'hidden');
 		dojo.byId('connectmethodlist').innerHTML = data.items.data.connectmethods.join('<br>');
 		dijit.byId('connectmethodttd').set('href', data.items.data.connectmethodurl);
 		dijit.byId('subimagedlg').set('href', data.items.data.subimageurl);
@@ -95,6 +101,7 @@ function resetEditResource() {
 	dijit.byId('checkout').reset();
 	dijit.byId('checkuser').reset();
 	dijit.byId('rootaccess').reset();
+	dijit.byId('sethostname').reset();
 	if(dijit.byId('sysprep'))
 		dijit.byId('sysprep').reset();
 	if(dojo.byId('connectmethodids'))
@@ -195,6 +202,16 @@ function saveResource() {
 		errobj.innerHTML = _('Invalid value specified for \'Users have administrative access\'');
 		return;
 	}
+	data['sethostname'] = parseInt(dijit.byId('sethostname').get('value'));
+	if(data['sethostname'] != 0 && data['sethostname'] != 1) {
+		if(dojo.hasClass('sethoatnamediv', 'hidden')) {
+			data['sethostname'] = 0;
+		}
+		else {
+			errobj.innerHTML = _('Invalid value specified for \'Set computer hostname\'');
+			return;
+		}
+	}
 	if(dijit.byId('sysprep')) {
 		data['sysprep'] = parseInt(dijit.byId('sysprep').get('value'));
 		if(data['sysprep'] != 0 && data['sysprep'] != 1) {
@@ -268,6 +285,7 @@ function saveResourceCB(data, ioArgs) {
 					resourcegrid.store.setValue(item, 'forcheckout', data.items.data.forcheckout);
 					resourcegrid.store.setValue(item, 'checkuser', data.items.data.checkuser);
 					resourcegrid.store.setValue(item, 'rootaccess', parseInt(data.items.data.rootaccess));
+					resourcegrid.store.setValue(item, 'sethostname', parseInt(data.items.data.sethostname));
 					resourcegrid.store.setValue(item, 'reloadtime', data.items.data.reloadtime);
 				},
 				onComplete: function(items, result) {
@@ -283,6 +301,7 @@ function saveResourceCB(data, ioArgs) {
 		dijit.byId('checkout').reset();
 		dijit.byId('checkuser').reset();
 		dijit.byId('rootaccess').reset();
+		dijit.byId('sethostname').reset();
 		dijit.byId('description').reset();
 		dijit.byId('usage').reset();
 		if(dijit.byId('imgcomments')) {
@@ -631,6 +650,19 @@ function startImageCB(data, ioArgs) {
 	dijit.byId('addeditbtn').set('label', _('Create Image'));
 	dijit.byId('addeditbtn').set('disabled', false);
 	dijit.byId('clickthroughDlgBtn').set('disabled', false);
+	if(data.items.ostype == 'windows' || data.items.ostype == 'linux') {
+		dojo.removeClass('sethostnamediv', 'hidden');
+		if(data.items.ostype == 'windows')
+			dijit.byId('sethostname').set('value', 0);
+		else
+			dijit.byId('sethostname').set('value', 1);
+	}
+	else
+		dojo.addClass('sethostnamediv', 'hidden');
+	if(data.items.ostype == 'windows')
+		dojo.removeClass('sysprepdiv', 'hidden');
+	else
+		dojo.addClass('sysprepdiv', 'hidden');
 
 	if(data.items.checkpoint) {
 		dojo.addClass('imageendrescontent', 'hidden');