Preferences page working
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@154 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -1,54 +1,53 @@ | ||||
| <?php | ||||
|  | ||||
| // Allow the user to set preferences for this web interface | ||||
| // Allow the user to set preferences for this web interface.  The preferences are stored | ||||
| // in the browsers cookie. | ||||
|  | ||||
| $TOPDIR = '..'; | ||||
| require_once "$TOPDIR/lib/functions.php"; | ||||
|  | ||||
| insertHeader('Preferences', NULL, NULL, array('config','prefs')); | ||||
| ?> | ||||
| <FORM NAME="prefs"> | ||||
| <TABLE class="inner_table" cellspacing=0 cellpadding=5> | ||||
|   <TBODY> | ||||
|   	<TR> | ||||
|       <TD colspan="3"><font class="BlueBack">Number of nodes per display: </font> | ||||
|       <INPUT type="text" id="number_of_node" name="number_of_node" | ||||
|       value="<?php if(@$_POST["number_of_node"] == "") echo "20"; else echo $_POST["number_of_node"];?>"> | ||||
|  	  </TD> | ||||
|     </TR> | ||||
|     <TR> | ||||
|       <TD colspan="3"><p> | ||||
| 		<INPUT type="button" id="setPrefButton" name="setPrefButton" value="Set Preferences" class=middle onclick="checkEmpty();"></p> | ||||
|       </TD> | ||||
|     </TR> | ||||
|  | ||||
|   </TBODY> | ||||
| </TABLE> | ||||
| </FORM> | ||||
| </TD> | ||||
| </TR> | ||||
| </TABLE> | ||||
| <SCRIPT language="JavaScript"> | ||||
| <!-- | ||||
| echo "<FORM NAME=prefs onsubmit='return false'><TABLE class=inner_table cellspacing=0 cellpadding=5><TBODY>\n"; | ||||
|  | ||||
| window.onload = function(){window.document.prefs.setPrefButton.focus()}; | ||||
| //foreach ($_COOKIE as $key => $value) { echo "<p>$key: {$_COOKIE[$key]}</p>\n"; } | ||||
|  | ||||
| function checkEmpty(){ | ||||
| echo "<tr><td colspan=2>\n"; | ||||
| insertButtons(array('label' => 'Set Preferences', 'onclick' => 'doSetPref()')); | ||||
| echo " <span id=setMsg class=Info style='display: none'>Preferences set successfully</span></td></tr>\n"; | ||||
|  | ||||
| $nodesPerPage = getPref('nodesPerPage'); | ||||
| echo "<TR><TD align=right><font class=BlueBack>Number of nodes to display per page:</font></td>\n"; | ||||
| echo "<td><INPUT type=text id=nodesPerPage name=nodesPerPage value='$nodesPerPage' onchange='doSetPref()'></TD></TR>\n"; | ||||
|  | ||||
| $displayCmds = getPref('displayCmds'); | ||||
| $displayStr = $displayCmds ? 'checked' : ''; | ||||
| echo "<TR><TD align=right><font class=BlueBack>Display commands run by this interface:</font></td>\n"; | ||||
| echo "<td><INPUT type=checkbox id=displayCmds name=displayCmds $displayStr></TD></TR>\n"; | ||||
|  | ||||
| //echo "<TR><TD colspan=3><INPUT type=button id=setPrefButton name=setPrefButton value='Set Preferences' class=middle onclick='doSetPref();'> <span id=setMsg class=Info style='display: none'>Preferences set successfully</span></TD></TR>\n"; | ||||
| echo "</TBODY></TABLE></FORM>\n"; | ||||
| echo <<<EOS | ||||
| <SCRIPT language=JavaScript> | ||||
| //window.onload = function(){window.document.prefs.setPrefButton.focus()}; | ||||
|  | ||||
| function doSetPref(){ | ||||
| 	var form = window.document.prefs; | ||||
| 	var number_of_node = form.number_of_node.value; | ||||
| 	if (number_of_node.length == 0) | ||||
| 	  { | ||||
| 	    alert('Enter a number before pressing the Set Preferences button.'); | ||||
| 	    return false; | ||||
| 	  } | ||||
| 	else { | ||||
| 		setCookie('number_of_node',number_of_node); | ||||
| 		alert('Preferences set.'); | ||||
| 		return true; | ||||
| 	} | ||||
| } | ||||
| 	var cookies = getCookies(); | ||||
| 	//for (c in cookies) { alert('cookies['+c+']='+cookies[c]); } | ||||
| 	//alert('cookies[nodesPerPage]='+cookies['nodesPerPage']); | ||||
|  | ||||
| --> | ||||
| 	var nodesPerPage = form.nodesPerPage.value; | ||||
| 	if (nodesPerPage != cookies['nodesPerPage']) { setCookie('nodesPerPage',nodesPerPage,'/'); } | ||||
|  | ||||
| 	var displayCmds = form.displayCmds.checked ? '1' : '0'; | ||||
| 	if (displayCmds != cookies['displayCmds']) { setCookie('displayCmds',displayCmds,'/'); } | ||||
|  | ||||
| 	document.getElementById('setMsg').style.display = 'inline'; | ||||
| 	//return false; | ||||
| } | ||||
| </SCRIPT> | ||||
| </BODY> | ||||
| </HTML> | ||||
| </HTML> | ||||
| EOS; | ||||
| ?> | ||||
| @@ -2,6 +2,18 @@ | ||||
|  | ||||
| // Main page of the xCAT web interface, but will redirect to the default page | ||||
|  | ||||
| header( 'Location: machines/groups.php' ) ; | ||||
| $TOPDIR = '.'; | ||||
| require_once "$TOPDIR/lib/functions.php"; | ||||
|  | ||||
| // First try to get the cookie of the last visited page | ||||
| if (isset($_COOKIE['currentpage'])) { | ||||
| 	//echo "<p>here</p>\n"; | ||||
| 	$keys = $_COOKIE['currentpage']; | ||||
| 	$m = $MENU[$keys[0]];              // this gets us to the menu choice for the top menu in the data structure | ||||
| 	$url = $m['list'][$keys[1]]['url'];      // get to the list of submenu choices, choose the proper one, and get its url | ||||
| 	//echo "<p>url: $url, m[label]: " . $m['label'] . "</p>\n"; | ||||
| } else { $url = 'machines/groups.php'; } | ||||
|  | ||||
| header("Location: $url"); | ||||
|  | ||||
| ?> | ||||
| @@ -1,40 +1,27 @@ | ||||
| var CommandWindow = {}; | ||||
|  | ||||
| CommandWindow.updateCommandResult = function() { | ||||
| 	var commandQueryId = "commandQuery"; | ||||
| 	var copyChkBoxId = "copyChkBox"; | ||||
| 	var nodenameHiddenTxtId = "nodename"; | ||||
| 	var nodegrpsCboBoxId = "nodegrpsCboBox"; | ||||
| 	var pshChkBoxId = "pshChkBox"; | ||||
| 	//todo:  add commandQueryObj.value to the history select box | ||||
|  | ||||
| 	var serialChkBoxId = "serialChkBox"; | ||||
| 	var verifyChkBoxId = "verifyChkBox"; | ||||
| 	var fanoutTxtBoxId = "fanoutTxtBox"; | ||||
| 	var userIDTxtBoxId = "userIDTxtBox"; | ||||
| 	var rshellTxtBoxId = "rshellTxtBox"; | ||||
| 	var rshellTxtBoxId = "rshellTxtBox"; | ||||
| 	var monitorChkBoxId = "monitorChkBox"; | ||||
| 	var ret_codeChkBoxId = "ret_codeChkBox"; | ||||
| 	var commandQueryObj = $('commandQuery'); | ||||
| 	var copyChkBoxObj = $('copyChkBox'); | ||||
| 	var nodelistTxtObj = $('nodeList'); | ||||
| 	var nodegrpsCboBoxObj = $('nodegrpsCboBox'); | ||||
| 	var pshChkBoxObj = $('pshChkBox'); | ||||
|  | ||||
| 	var copyChkBoxObj = $(copyChkBoxId); | ||||
| 	var commandQueryObj = $(commandQueryId); | ||||
| 	var nodenameHiddenTxtObj = $(nodenameHiddenTxtId); | ||||
| 	var nodegrpsCboBoxObj = $(nodegrpsCboBoxId); | ||||
| 	var pshChkBoxObj = $(pshChkBoxId); | ||||
|  | ||||
| 	var serialChkBoxObj = $(serialChkBoxId); | ||||
| 	var verifyChkBoxObj = $(verifyChkBoxId); | ||||
| 	var fanoutTxtBoxObj = $(fanoutTxtBoxId); | ||||
| 	var userIDTxtBoxObj = $(userIDTxtBoxId); | ||||
| 	var rshellTxtBoxObj = $(rshellTxtBoxId); | ||||
| 	var monitorChkBoxObj = $(monitorChkBoxId); | ||||
| 	var ret_codeChkBoxObj = $(ret_codeChkBoxId); | ||||
| 	var serialChkBoxObj = $('serialChkBox'); | ||||
| 	var verifyChkBoxObj = $('verifyChkBox'); | ||||
| 	var fanoutTxtBoxObj = $('fanoutTxtBox'); | ||||
| 	var userIDTxtBoxObj = $('userIDTxtBox'); | ||||
| 	var rshellTxtBoxObj = $('rshellTxtBox'); | ||||
| 	var monitorChkBoxObj = $('monitorChkBox'); | ||||
| 	var ret_codeChkBoxObj = $('ret_codeChkBox'); | ||||
|  | ||||
| 	// Do AJAX call and get HTML here. | ||||
| 	var url = "dsh_action.php"; | ||||
| 	var postPara = "command=" + encodeURIComponent(commandQueryObj.value); | ||||
| 	postPara += "&node=" + encodeURIComponent(nodenameHiddenTxtObj.value); | ||||
| 	postPara += "&nodegrps=" + encodeURIComponent(nodegrpsCboBoxObj.options[nodegrpsCboBoxObj.selectedIndex].value); | ||||
| 	if (nodelistTxtObj) { postPara += "&node=" + encodeURIComponent(nodelistTxtObj.value); } | ||||
| 	if (nodegrpsCboBoxObj) { postPara += "&nodegrps=" + encodeURIComponent(nodegrpsCboBoxObj.options[nodegrpsCboBoxObj.selectedIndex].value); } | ||||
| 	if (copyChkBoxObj.checked == true)	postPara += "©=on";	else postPara += "©=off"; | ||||
| 	if (pshChkBoxObj.checked == true)	postPara += "&psh=on";	else postPara += "&psh=off"; | ||||
| 	if (serialChkBoxObj.checked == true)	postPara += "&serial=on"; else postPara += "&serial=off"; | ||||
|   | ||||
| @@ -1,17 +1,21 @@ | ||||
| // Javascript functions that most pages need. | ||||
| // Note: this is included by all pages, so only put functions in this file that most/all pages need. | ||||
|  | ||||
| function setCookies(form) | ||||
| { | ||||
| var value = (form.rack.checked?1:0) + '&' + form.nodegrps.value + '&' + form.nodeRange.value; | ||||
| setCookie('mainpage', value); | ||||
| function setCookie(name, value, path) { | ||||
| value = escape(value);    // this is needed if value contains spaces, semicolons, or commas | ||||
| document.cookie = name + '=' + value | ||||
| 				+ ';expires=' + (new Date("December 31, 2023")).toGMTString() | ||||
| 				+ ';path=' + path; | ||||
| } | ||||
|  | ||||
| function setCookie(name, value) | ||||
| { | ||||
| value = escape(value); | ||||
| value = value.replace(/\+/g, '%2B'); // The un_urlize() function in webmin works slightly differently than javascript escape() | ||||
| document.cookie = name + '=' + value + ';expires=' + (new Date("December 31, 2023")).toGMTString(); | ||||
| // Return a hash of the cookie names and values | ||||
| function getCookies() { | ||||
| //alert('"'+document.cookie+'"'); | ||||
| var cookies = document.cookie.split(/; */); | ||||
| //alert(cookies[0]); | ||||
| var cookret = new Object();   // this is the return value | ||||
| for (i in cookies) { var pair = cookies[i].split('='); cookret[pair[0]] = unescape(pair[1]); } | ||||
| return cookret; | ||||
| } | ||||
|  | ||||
| function selectAll(element, objectName) | ||||
|   | ||||
| @@ -4,22 +4,28 @@ | ||||
|  | ||||
| // Some common/global settings | ||||
| session_start();     // retain session variables across page requests | ||||
| if (!isset($TOPDIR)) { $TOPDIR = '..'; } | ||||
|  | ||||
| // The settings below display error on the screen, instead of giving blank pages. | ||||
| error_reporting(E_ALL ^ E_NOTICE); | ||||
| ini_set('display_errors', true); | ||||
|  | ||||
| // Todo: get rid of these globals | ||||
| $XCATROOT = '/opt/xcat/bin'; | ||||
| $CURRDIR = '/opt/xcat/web'; | ||||
|  | ||||
|  | ||||
| /*----------------------------------------------------------------------------------------------- | ||||
| 	Function to insert the header part of the HTML and the top part of the page | ||||
| ------------------------------------------------------------------------------------------------*/ | ||||
| /** | ||||
|  * Inserts the header part of the HTML and the top part of the page, including the menu. | ||||
|  * Also includes some common css and js files and the css and js files specified. | ||||
|  * This function should be called at the beginning of every page. | ||||
|  * @param String $title The page title that should go in the window title bar. | ||||
|  * @param array $stylesheets The paths of the styles that are specific to this page. | ||||
|  * @param array $javascripts The paths of the javascript files that are specific to this page. | ||||
|  * @param array $currents The keys to the top menu and 2nd menu that represent the current choice for this page.  See insertMenus() for the keys. | ||||
|  */ | ||||
| function insertHeader($title, $stylesheets, $javascripts, $currents) { | ||||
| global $TOPDIR; | ||||
| if (!$TOPDIR) 	$TOPDIR = '..'; | ||||
|  | ||||
| // Remember the current page so we can open it again the next time they come to the web interface | ||||
| $expire_time = gmmktime(0, 0, 0, 1, 1, 2038); | ||||
| foreach ($currents as $key => $value) { setcookie("currentpage[$key]", $value, $expire_time, '/'); } | ||||
|  | ||||
| echo <<<EOS | ||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11-strict.dtd"> | ||||
| @@ -74,63 +80,87 @@ echo "</td><td><img src='$TOPDIR/images/topr.jpg'></td></tr></table>\n"; | ||||
| }  // end insertHeader | ||||
|  | ||||
|  | ||||
| // This is the data structure that represents the menu for each page. | ||||
| $MENU = array( | ||||
| 	'machines' => array( | ||||
| 		'label' => 'Machines', | ||||
| 		'default' => 'groups', | ||||
| 		'list' => array( | ||||
| 			'lab' => array('label' => 'Lab Floor', 'url' => "$TOPDIR/machines/lab.php"), | ||||
| 			'frames' => array('label' => 'Frames', 'url' => "$TOPDIR/machines/frames.php"), | ||||
| 			'groups' => array('label' => 'Groups', 'url' => "$TOPDIR/machines/groups.php"), | ||||
| 			'nodes' => array('label' => 'Nodes', 'url' => "$TOPDIR/machines/nodes.php"), | ||||
| 			'layout' => array('label' => 'Layout', 'url' => "$TOPDIR/machines/layout.php"), | ||||
| 			) | ||||
| 		), | ||||
| 	'manage' => array( | ||||
| 		'label' => 'Manage', | ||||
| 		'default' => 'dsh', | ||||
| 		'list' => array( | ||||
| 			'dsh' => array('label' => 'Run Cmds', 'url' => "$TOPDIR/manage/dsh.php"), | ||||
| 			'copyfiles' => array('label' => 'Copy Files', 'url' => "$TOPDIR/manage/copyfiles.php"), | ||||
| 			'cfm' => array('label' => 'Sync Files', 'url' => "$TOPDIR/manage/cfm.php"), | ||||
| 			'hwctrl' => array('label' => 'HW Ctrl', 'url' => "$TOPDIR/manage/hwctrl.php"), | ||||
| 			'diagnodes' => array('label' => 'Diagnose', 'url' => "$TOPDIR/manage/diagnodes.php"), | ||||
| 			) | ||||
| 		), | ||||
| 	'jobs' => array( | ||||
| 		'label' => 'Jobs', | ||||
| 		'default' => 'overview', | ||||
| 		'list' => array( | ||||
| 			'overview' => array('label' => 'Overview', 'url' => "$TOPDIR/jobs/overview.php"), | ||||
| 			//todo:  Vallard fill in rest | ||||
| 			) | ||||
| 		), | ||||
| 	'deploy' => array( | ||||
| 		'label' => 'Deploy', | ||||
| 		'default' => 'osimages', | ||||
| 		'list' => array( | ||||
| 			'osimages' => array('label' => 'OS Images', 'url' => "$TOPDIR/deploy/osimages.php"), | ||||
| 			'prepare' => array('label' => 'Prepare', 'url' => "$TOPDIR/deploy/prepare.php"), | ||||
| 			'deploy' => array('label' => 'Deploy', 'url' => "$TOPDIR/deploy/deploy.php"), | ||||
| 			'monitor' => array('label' => 'Monitor', 'url' => "$TOPDIR/deploy/monitor.php"), | ||||
| 			) | ||||
| 		), | ||||
| 	'config' => array( | ||||
| 		'label' => 'Configure', | ||||
| 		'default' => 'site', | ||||
| 		'list' => array( | ||||
| 			'prefs' => array('label' => 'Preferences', 'url' => "$TOPDIR/config/prefs.php"), | ||||
| 			'site' => array('label' => 'Cluster Settings', 'url' => "$TOPDIR/config/site.php"), | ||||
| 			'mgmtnode' => array('label' => 'Mgmt Node', 'url' => "$TOPDIR/config/mgmtnode.php"), | ||||
| 			'monitor' => array('label' => 'Monitor Setup', 'url' => "$TOPDIR/config/monitor.php"), | ||||
| 			'eventlog' => array('label' => 'Event Log', 'url' => "$TOPDIR/config/eventlog.php"), | ||||
| 			) | ||||
| 		), | ||||
| 	'support' => array( | ||||
| 		'label' => 'Support', | ||||
| 		'default' => 'diagnose', | ||||
| 		'list' => array( | ||||
| 			'diagnose' => array('label' => 'Diagnose', 'url' => "$TOPDIR/support/diagnose.php"), | ||||
| 			'update' => array('label' => 'Update', 'url' => "$TOPDIR/support/update.php"), | ||||
| 			'howtos' => array('label' => 'HowTos', 'url' => "$TOPDIR/support/howtos.php"), | ||||
| 			'manpages' => array('label' => 'Man Pages', 'url' => "$TOPDIR/support/manpages.php"), | ||||
| 			'maillist' => array('label' => 'Mail List', 'url' => "http://xcat.org/mailman/listinfo/xcat-user"), | ||||
| 			'wiki' => array('label' => 'Wiki', 'url' => "http://xcat.wiki.sourceforge.net/"), | ||||
| 			'suggest' => array('label' => 'Suggestions', 'url' => "$TOPDIR/support/suggest.php"), | ||||
| 			'about' => array('label' => 'About', 'url' => "$TOPDIR/support/about.php"), | ||||
| 			) | ||||
| 		), | ||||
| 	); | ||||
|  | ||||
|  | ||||
| // Insert the menus at the top of the page | ||||
| //   $currents is an array of the current menu choice tree | ||||
| function insertMenus($currents) { | ||||
| 	global $TOPDIR; | ||||
| 	global $MENU; | ||||
| 	echo "<table border=0 cellspacing=0 cellpadding=0>\n"; | ||||
|  | ||||
| 	insertMenuRow($currents[0], 1, array( | ||||
| 		'machines' => array('Machines', "$TOPDIR/machines/groups.php"), | ||||
| 		'jobs' => array('Jobs', "$TOPDIR/jobs/overview.php"), | ||||
| 		'deploy' => array('Deploy', "$TOPDIR/deploy/osimages.php"), | ||||
| 		'config' => array('Configuration', "$TOPDIR/config/site.php"), | ||||
| 		'support' => array('Support', "$TOPDIR/support/diagnose.php") | ||||
| 	)); | ||||
| 	if ($currents[0] == 'machines') { | ||||
| 		insertMenuRow($currents[1], 0, array( | ||||
| 			'lab' => array('Lab Floor', "$TOPDIR/machines/lab.php"), | ||||
| 			'frames' => array('Frames', "$TOPDIR/machines/frames.php"), | ||||
| 			'groups' => array('Groups', "$TOPDIR/machines/groups.php"), | ||||
| 			'nodes' => array('Nodes', "$TOPDIR/machines/nodes.php"), | ||||
| 			'layout' => array('Layout', "$TOPDIR/machines/layout.php") | ||||
| 		)); | ||||
| 	} | ||||
| 	elseif ($currents[0] == 'jobs') { | ||||
| 		insertMenuRow($currents[1], 0, array( | ||||
| 			'overview' => array('Overview', "$TOPDIR/jobs/overview.php"), | ||||
| 			//todo:  Vallard fill in rest | ||||
| 		)); | ||||
| 	} | ||||
| 	elseif ($currents[0] == 'deploy') { | ||||
| 		insertMenuRow($currents[1], 0, array( | ||||
| 			'osimages' => array('OS Images', "$TOPDIR/deploy/osimages.php"), | ||||
| 			'prepare' => array('Prepare', "$TOPDIR/deploy/prepare.php"), | ||||
| 			'deploy' => array('Deploy', "$TOPDIR/deploy/deploy.php"), | ||||
| 			'monitor' => array('Monitor', "$TOPDIR/deploy/monitor.php"), | ||||
| 		)); | ||||
| 	} | ||||
| 	elseif ($currents[0] == 'config') { | ||||
| 		insertMenuRow($currents[1], 0, array( | ||||
| 			'prefs' => array('Preferences', "$TOPDIR/config/prefs.php"), | ||||
| 			'site' => array('Cluster Settings', "$TOPDIR/config/site.php"), | ||||
| 			'mgmtnode' => array('Mgmt Node', "$TOPDIR/config/mgmtnode.php"), | ||||
| 			'monitor' => array('Monitor Setup', "$TOPDIR/config/monitor.php"), | ||||
| 			'eventlog' => array('Event Log', "$TOPDIR/config/eventlog.php"), | ||||
| 		)); | ||||
| 	} | ||||
| 	elseif ($currents[0] == 'support') { | ||||
| 		insertMenuRow($currents[1], 0, array( | ||||
| 			'diagnose' => array('Diagnose', "$TOPDIR/support/diagnose.php"), | ||||
| 			'update' => array('Update', "$TOPDIR/support/update.php"), | ||||
| 			'howtos' => array('HowTos', "$TOPDIR/support/howtos.php"), | ||||
| 			'manpages' => array('Man Pages', "$TOPDIR/support/manpages.php"), | ||||
| 			'maillist' => array('Mail List', "http://xcat.org/mailman/listinfo/xcat-user"), | ||||
| 			'wiki' => array('Wiki', "http://xcat.wiki.sourceforge.net/"), | ||||
| 			'suggest' => array('Suggestions', "$TOPDIR/support/suggest.php"), | ||||
| 			'about' => array('About', "$TOPDIR/support/about.php"), | ||||
| 		)); | ||||
| 	} | ||||
| 	insertMenuRow($currents[0], 1, $MENU); | ||||
|  | ||||
| 	insertMenuRow($currents[1], 0, $MENU[$currents[0]]['list']); | ||||
|  | ||||
| 	echo "</table>\n"; | ||||
| } | ||||
|  | ||||
| @@ -147,13 +177,19 @@ function insertMenuRow($current, $isTop, $items) { | ||||
| 	//echo "<div class=$menuRowClass><ul id=mainNav>\n"; | ||||
| 	echo "<tr><td $menuRowClass><ul id=mainNav>\n"; | ||||
|  | ||||
| 	foreach ($items as $key => $link) { | ||||
| 	foreach ($items as $key => $value) { | ||||
| 		$label = $value['label']; | ||||
| 		if ($isTop) { | ||||
| 			$url = $value['list'][$value['default']]['url'];      // get to the list of submenu choices, choose the default one, and get its url | ||||
| 		} else { | ||||
| 			$url = $value['url']; | ||||
| 		} | ||||
| 		if ($key == $current){ | ||||
| 			//echo "<TD><a id=$key href='$link[1]'>$link[0]</a></TD>\n"; | ||||
| 			echo "<li><p $currentClass>$link[0]</p></li>"; | ||||
| 			echo "<li><p $currentClass>$label</p></li>"; | ||||
| 		} else { | ||||
| 			//echo "<TD><a class=NavItem id=$key href='$link[1]'>$link[0]</a></TD>\n"; | ||||
| 			echo "<li><a $menuItemClass id=$key href='$link[1]'>$link[0]</a></li>"; | ||||
| 			echo "<li><a $menuItemClass id=$key href='$url'>$label</a></li>"; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -172,7 +208,6 @@ function insertMenuRow($current, $isTop, $items) { | ||||
| 		  	  2: Like mode 0, if successful, return output to a reference variable in the caller function, with the newlines removed. | ||||
| 		  	     But error msgs are output to reference variable in the caller function | ||||
| 			  1: Long running cmd, intermediate results/errors are ouput as the command is executed | ||||
| 			 -1: Like mode 1 | ||||
| 			  3: Long running cmd. Results/errors are output to a file and return a file handle to the caller function | ||||
| 		3. Reference variable to hold the output returned to caller function | ||||
| 		4. Reference to an options hash, e.g. { NoVerbose => 1, NoRedirectStderr => 1 } | ||||
| @@ -182,31 +217,35 @@ function runcmd ($cmd, $mode, &$output, $options=NULL){ | ||||
|  | ||||
| 	//Set error output to the same source as standard output (on Linux) | ||||
| 	if (strstr($cmd,'2>&1') == FALSE && !$options["NoRedirectStdErr"]) { $cmd .= ' 2>&1'; } | ||||
| 	$cmd = "/bin/sudo $cmd";      //todo: change this when move to xcat 2 | ||||
|  | ||||
| 	if (!isSupported('ClientServer')) { $cmd = "/bin/sudo $cmd"; } | ||||
| 	//todo: add support for xcat 2 | ||||
|  | ||||
| 	$ret_stat = ""; | ||||
| 	$arr_output = NULL; | ||||
| 	if ($mode == 3){ | ||||
| 	//$arr_output = NULL; | ||||
| 	if ($mode == 3) {    // long running cmd - pipe output to file handle | ||||
| 		$handle = popen($cmd, "r"); | ||||
| 		if($handle){ | ||||
| 		if($handle) { | ||||
| 			$output = $handle;	//return file handle to caller | ||||
| 			return 0;	//successful | ||||
| 		}else{ | ||||
| 			echo "Piping command into a file failed"; | ||||
| 		} else { | ||||
| 			msg('E', "Piping command ($cmd) into a file handle failed."); | ||||
| 			return 1; | ||||
| 		} | ||||
| 	}elseif ($mode == 0 || $mode == 2 ){ | ||||
| 		exec($cmd,$arr_output,$ret_stat); | ||||
| 		exec($cmd, $output, $ret_stat); | ||||
| 		if ($ret_stat == 0){ | ||||
| 			$output = $arr_output; | ||||
| 			//$output = $arr_output; | ||||
| 		} else { | ||||
| 			//output the error msg to the screen | ||||
| 			if ($mode == 0)	echo $arr_output[0]; | ||||
| 			if ($mode == 0)	foreach ($output as $line) { msg('E', $line); } | ||||
| 			//output error msg to the caller function | ||||
| 			elseif ($mode == 2) $output = $arr_output[0]; | ||||
| 			//elseif ($mode == 2) $output = $arr_output[0];   // error is already in the output | ||||
| 		} | ||||
| 	}elseif ($mode == 1 || $mode == -1){ | ||||
| 		system($cmd,$ret_stat); | ||||
| 	} elseif ($mode == 1){ | ||||
| 		echo "<code>\n"; | ||||
| 		system($cmd, $ret_stat); | ||||
| 		echo "</code>\n"; | ||||
| 	} | ||||
| 	return $ret_stat; | ||||
| } | ||||
| @@ -227,8 +266,10 @@ function dumpGlobals() { //------------------------------------ | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function getXcatRoot() { return isset($_ENV['XCATROOT']) ? $_ENV['XCATROOT'] : '/opt/xcat'; } | ||||
|  | ||||
| # Returns true if the given rpm file is already installed at this version or higher. | ||||
| function isInstalled($rpmfile) { //------------------------------------ | ||||
| function isInstalled($rpmfile) { | ||||
| 	$aixrpmopt = isAIX() ? '--ignoreos' : ''; | ||||
| 	$lang = isWindows() ? '' : 'LANG=C';    //todo: add this back in | ||||
| 	$out = array(); | ||||
| @@ -241,6 +282,28 @@ function isInstalled($rpmfile) { //------------------------------------ | ||||
|   } | ||||
|  | ||||
|  | ||||
| $isSupportedHash = array(); | ||||
|  | ||||
| # Returns true if the specified feature is supported.  This is normally determined by some fast | ||||
| # method like checking for the existence of a file.  The answer is also cached for next time. | ||||
| function isSupported($feature) { | ||||
|   if (isset($isSupportedHash[$feature])) { return $isSupportedHash[$feature]; } | ||||
|  | ||||
|   # These are supported in xCAT 2.0 and above | ||||
|   if ($feature == 'ClientServer' | ||||
| 	  || $feature == 'DB') | ||||
| 	{ $isSupportedHash[$feature] = file_exists(getXcatRoot() . '/bin/xcatclient'); } | ||||
|  | ||||
|   # These are supported in xCAT x.x and above | ||||
|   //elseif ($feature == 'DshExecute') | ||||
|   //	{ $isSupportedHash[$feature] = -e '/opt/csm/bin/csmsetuphwmaint'; } | ||||
|  | ||||
|   else { return false; } | ||||
|  | ||||
|   return $isSupportedHash[$feature]; | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| // Debug output  ------------------------------------ | ||||
| define("TRACE", "1"); | ||||
| @@ -411,10 +474,16 @@ function getStatusImage($status) { | ||||
| } | ||||
|  | ||||
|  | ||||
| // Returns the specified user preference value.  Not finished. | ||||
| function getPref($key) { //------------------------------------ | ||||
| 	if ($key == 'MaxNodesDisplayed') { return 50; } | ||||
| 	return ''; | ||||
| // Returns the specified user preference value, or the default.  (The preferences are stored in cookies.) | ||||
| // If no key is specified, it will return the list of preference names. | ||||
| function getPref($key) { | ||||
| 	$prefDefaults = array( | ||||
| 		'nodesPerPage' => 40, | ||||
| 		'displayCmds' => 0, | ||||
| 		); | ||||
| 	if (!isset($key)) { return array_keys($prefDefaults); } | ||||
| 	if (isset($_COOKIE[$key])) { return $_COOKIE[$key]; } | ||||
| 	return $prefDefaults[$key];         // return default if not in the cookie | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -495,19 +564,35 @@ function insertTabs ($tablist, $currentTabIndex) { //--------------------------- | ||||
| } | ||||
|  | ||||
|  | ||||
| // Create the Action buttons in a table.  Buttonlist is an array of arrays of button attribute strings. | ||||
| function insertButtons ($buttonsets) { //------------------------------------ | ||||
| 	foreach ($buttonsets as $buttonlist) { | ||||
| 		echo "<TABLE cellpadding=0 cellspacing=2><TR>"; | ||||
| 		foreach ($buttonlist as $button) { | ||||
| 			//echo "<td><INPUT type=submit class=but $button ></td>"; | ||||
| 			echo "<td><a class=button href=''><span>$button</span></a></td>"; | ||||
| 			} | ||||
| 		echo "</TR></TABLE>\n"; | ||||
| 	} | ||||
| // Create the Action buttons in a table.  Each argument passed in is a button, which is an array of attribute strings. | ||||
| // If your onclick attribute contains javascript code that uses quotes, use double quotes instead of single quotes. | ||||
| // Note:  if only 1 button is passed in, the button is not put in a table. | ||||
| function insertButtons () { | ||||
| 	$num = func_num_args(); | ||||
| 	if ($num > 1) echo "<TABLE cellpadding=0 cellspacing=2><TR>"; | ||||
| 	foreach (func_get_args() as $button) { | ||||
| 		//echo "<td><INPUT type=submit class=but $button ></td>"; | ||||
| 		$otherattrs = @$button['otherattrs']; | ||||
| 		if ($num > 1) echo "<td>"; | ||||
| 		echo "<a class=button href='' onclick='{$button['onclick']};return false' $otherattrs><span>{$button['label']}</span></a>"; | ||||
| 		if ($num > 1) echo "</td>"; | ||||
| 		} | ||||
| 	if ($num > 1) echo "</TR></TABLE>\n"; | ||||
| } | ||||
|  | ||||
|  | ||||
| // Display messages in the html.  If severity is W or E, it will attempt to use the Error class | ||||
| // from the style sheet. | ||||
| function msg($severity, $msg) | ||||
|   { | ||||
| 	//if ($severity=~/V/ && !$::GUI_VERBOSE) { return; } | ||||
| 	if (preg_match('/O/', $severity)) { echo "$msg\n";  return; } | ||||
| 	$styleclass = 'Info'; | ||||
| 	if (preg_match('/[WE]/', $severity)) { $styleclass = 'Error'; } | ||||
| 	echo "<P class=$styleclass>$msg</P>\n"; | ||||
|   } | ||||
|  | ||||
|  | ||||
| function insertNotDoneYet() { echo "<p class=NotDone>This page is not done yet.</p>\n"; } | ||||
|  | ||||
| ?> | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| <?php | ||||
| //setcookie("history", "", time() - 3600);  //to delete a cookie, but did not seem to work | ||||
| phpinfo() | ||||
| ?> | ||||
| @@ -22,13 +22,6 @@ var value = (form.rack.checked?1:0) + '&' + form.nodegrps.value + '&' + form.nod | ||||
| setCookie('mainpage', value); | ||||
| } | ||||
|  | ||||
| function setCookie(name, value) | ||||
| { | ||||
| value = escape(value); | ||||
| value = value.replace(/\\+/g, '%2B'); // The un_urlize() function in webmin works slightly differently than javascript escape() | ||||
| document.cookie = name + '=' + value + ';expires=' + (new Date("December 31, 2023")).toGMTString(); | ||||
| } | ||||
|  | ||||
| function selectAll(element, rack) | ||||
| { | ||||
| var sel = element.checked; | ||||
|   | ||||
| @@ -14,24 +14,23 @@ insertHeader('Groups', array('groups.css'), | ||||
|  | ||||
| echo "<div id=content align=center>\n"; | ||||
|  | ||||
| insertButtons(array( | ||||
| 	array( | ||||
| 		'Attributes', | ||||
| 		'Create Group', | ||||
| 		'Ping', | ||||
| insertButtons( | ||||
| 		array('label' => 'Attributes', 'onclick' => ''), | ||||
| 		array('label' => 'Create Group', 'onclick' => ''), | ||||
| 		array('label' => 'Ping', 'onclick' => ''), | ||||
| 		//'Updatenode', | ||||
| 		'Run Cmd', | ||||
| 		'Copy Files', | ||||
| 		'Sync Files' | ||||
| 	), | ||||
| 	array( | ||||
| 		array('label' => 'Run Cmd', 'onclick' => ''), | ||||
| 		array('label' => 'Copy Files', 'onclick' => ''), | ||||
| 		array('label' => 'Sync Files', 'onclick' => '') | ||||
| 	); | ||||
| insertButtons( | ||||
| 		//'Soft Maint', | ||||
| 		'HW Ctrl', | ||||
| 		'RSA/MM/FSP', | ||||
| 		'Deploy', | ||||
| 		'Diagnose', | ||||
| 		'Remove' | ||||
| 	), | ||||
| 		array('label' => 'HW Ctrl', 'onclick' => ''), | ||||
| 		array('label' => 'RSA/MM/FSP', 'onclick' => ''), | ||||
| 		array('label' => 'Deploy', 'onclick' => ''), | ||||
| 		array('label' => 'Diagnose', 'onclick' => ''), | ||||
| 		array('label' => 'Remove', 'onclick' => '') | ||||
| 	); | ||||
| 	/* | ||||
| 	array( | ||||
| 		'name=propButton value="Attributes"', | ||||
| @@ -53,7 +52,6 @@ insertButtons(array( | ||||
| 		'name=removeButton value="Remove"' | ||||
| 	), | ||||
| 	*/ | ||||
| )); | ||||
|  | ||||
| echo '<form name="nodelist" class=ContentForm>'; | ||||
|  | ||||
|   | ||||
| @@ -4,72 +4,66 @@ | ||||
| ------------------------------------------------------------------------------*/ | ||||
| $TOPDIR = '..'; | ||||
| $expire_time = gmmktime(0, 0, 0, 1, 1, 2038); | ||||
| setcookie("history", "date;hello.sh", $expire_time); | ||||
| //setcookie('history[]', "date;hello.sh", $expire_time);
 | ||||
| 
 | ||||
| require_once "$TOPDIR/lib/functions.php"; | ||||
| 
 | ||||
| insertHeader('Run Commands on Nodes', array("$TOPDIR/themes/default.css"), | ||||
| 			array("$TOPDIR/lib/CommandWindow.js", "$TOPDIR/js/prototype.js", "$TOPDIR/js/scriptaculous.js?load=effects", "$TOPDIR/js/window.js"), | ||||
| 			array('machines','dsh')); | ||||
| 			array('manage','dsh')); | ||||
| 
 | ||||
| ?>
 | ||||
| echo <<<EOS | ||||
| <div id=content> | ||||
| <FORM NAME="dsh_options" onsubmit="checkEmpty();"> | ||||
| <input type="hidden" id="nodename" value=<?php echo @$_REQUEST["noderange"] ?> >
 | ||||
| <TABLE class="inner_table" cellspacing=0 cellpadding=5> | ||||
|   <TBODY> | ||||
|   	<TR> | ||||
|   	  <TD colspan="3"> | ||||
| 		<?php if (@$_REQUEST["noderange"] == ""){ ?>
 | ||||
|   	  	<font class="BlueBack">Run Command on Group:</font> | ||||
|   	  	<SELECT name=nodegrps id=nodegrpsCboBox class=middle> | ||||
|   	  	<OPTION value="">Choose ...</OPTION> | ||||
|   	  	<?php | ||||
|   	  	$nodegroups = getGroups(); | ||||
| 		foreach ($nodegroups as $group) { | ||||
| 				//if($group == $currentGroup) { $selected = 'selected'; } else { $selected = ''; }
 | ||||
| 				echo "<OPTION value='$group' $selected>$group</OPTION>\n"; | ||||
| 		} | ||||
| 		?>
 | ||||
|    		</SELECT> | ||||
|   	<TR><TD colspan=3> | ||||
| EOS; | ||||
| 
 | ||||
|    		<?php }else{ ?>
 | ||||
|    		<font class="BlueBack">Run Command on: </font><?php echo @$_REQUEST["noderange"];  } ?>
 | ||||
|   	  </TD> | ||||
|   	</TR> | ||||
| 	<TR> | ||||
| 	  <TD colspan="3"> | ||||
| if (isset($_REQUEST['noderange'])) { | ||||
| 	echo "<B><FONT size='+1'>Run Command on: </FONT></B>"; | ||||
| 	if (strlen($_REQUEST['noderange']) > 70) { | ||||
| 		echo "<TEXTAREA rows=1 cols=70 readonly name=nodeList class=middle>" . $_REQUEST['noderange'] . "</TEXTAREA>\n"; | ||||
| 	} else { | ||||
| 		echo "<INPUT size=70 type=text name=nodeList id=nodeList class=middle value='" . $_REQUEST['noderange'] . "'>\n"; | ||||
| 	} | ||||
| } else { echo "<B><FONT size='+1'>Run Command on a Group of Nodes</FONT></B>\n"; } | ||||
| 
 | ||||
| echo <<<EOS2 | ||||
|   	</TD></TR> | ||||
| 	<TR><TD colspan=3> | ||||
| 		<P>Select a previous command from the history, or enter the command and options below. Then click on Run Cmd.</P> | ||||
| 	  </TD> | ||||
| 	</TR> | ||||
|     <TR> | ||||
|       <TD colspan="3"><p> | ||||
| 		<INPUT type="button" id="runCmdButton" name="runCmdButton" value="Run Cmd" class=middle onclick="CommandWindow.updateCommandResult()"></p> | ||||
|       </TD> | ||||
|     </TR> | ||||
|     <TR> | ||||
|       <TD colspan="3"><font class="BlueBack">Command History:</font> | ||||
|       <SELECT name="history" onChange="_setvars();" class="middle"> | ||||
| 	</TD></TR> | ||||
|     <TR><TD colspan=3> | ||||
| EOS2; | ||||
| //		<INPUT type="button" id="runCmdButton" name="runCmdButton" value="Run Cmd" class=middle onclick="CommandWindow.updateCommandResult()">
 | ||||
| insertButtons(array('label' => 'Run Cmd', 'onclick' => 'CommandWindow.updateCommandResult()')); | ||||
| echo "</TD></TR>\n"; | ||||
| 
 | ||||
| if (!isset($_REQUEST['noderange'])) { | ||||
| 	echo "<TR class=FormTable><TD colspan=3>Run Command on Group:<SELECT name=nodegrps id=nodegrpsCboBox class=middle><OPTION value=''>Choose ...</OPTION>\n"; | ||||
|   	$nodegroups = getGroups(); | ||||
| 	foreach ($nodegroups as $group) { | ||||
| 		//if($group == $currentGroup) { $selected = 'selected'; } else { $selected = ''; }
 | ||||
| 		echo "<OPTION value='$group' $selected>$group</OPTION>\n"; | ||||
| 		} | ||||
| 	echo "</SELECT></td></tr>\n"; | ||||
| } | ||||
| 
 | ||||
| ?>
 | ||||
|     <TR class=FormTable> | ||||
|       <TD colspan=3>Command:  | ||||
|        <INPUT size=80 type=text name=command id=commandQuery class=middle onchange='CommandWindow.updateCommandResult()'> | ||||
|        History: | ||||
|       <SELECT name=history onChange="_setvars();" class=middle> | ||||
|       <OPTION value="">Choose ...</OPTION> | ||||
|       <?php | ||||
| 		$string = @$_COOKIE["history"]; | ||||
| 		echo $token = strtok($string, ';'); | ||||
| 		echo "<option value=\"" . $token . "\">" . $token . "</option>"; | ||||
| 
 | ||||
| 		while (FALSE !== ($token = strtok(';'))) { | ||||
|    			echo "<option value=\"" . $token . "\">" . $token . "</option>"; | ||||
| 		if (isset($_COOKIE['history'])) { | ||||
| 			foreach ($_COOKIE['history'] as $value) { echo "<option value='$value'>$value</option>\n"; } | ||||
| 		} | ||||
| 	 ?>
 | ||||
|      </SELECT> | ||||
|  	     Selecting one of these commands will fill in the fields below. | ||||
|  	  </TD> | ||||
|     </TR> | ||||
|     <TR> | ||||
|       <TD colspan="3"><div id="commandResult"></div></TD> | ||||
|     </TR> | ||||
|     <TR class=FormTable> | ||||
|       <TD colspan="3">Command:  | ||||
|       <INPUT size="80" type="text" name="command" id="commandQuery" class="middle"></TD> | ||||
|       </TD> | ||||
|     </TR> | ||||
|     <TR class=FormTable> | ||||
|       <TD colspan="3" nowrap><INPUT type="checkbox" name="copy_script" id="copyChkBox"> | ||||
| @@ -143,7 +137,7 @@ insertHeader('Run Commands on Nodes', array("$TOPDIR/themes/default.css"), | ||||
| // in CSM perl script this portion used to be javascript to get
 | ||||
| // and set cookies, now php has handled it
 | ||||
| 
 | ||||
| window.onload = function(){window.document.dsh_options.runCmdButton.focus()}; | ||||
| //window.onload = function(){window.document.dsh_options.runCmdButton.focus()};
 | ||||
| function _setvars(){ | ||||
| 	var form = window.document.dsh_options; | ||||
| 	form.command.value = form.history.value; | ||||
| @@ -7,22 +7,24 @@ $TOPDIR = '..'; | ||||
| require_once "$TOPDIR/lib/functions.php"; | ||||
| 
 | ||||
| 
 | ||||
| // HTTP Headers: headers, cookies, ...
 | ||||
| // HTTP Headers to tell the browser to always update, never cache this page
 | ||||
| // so the History combo box always update the new commands added whenever the page is reloaded
 | ||||
| header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // date in the past
 | ||||
| header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
 | ||||
| header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
 | ||||
| header("Cache-Control: post-check=0, pre-check=0", false); | ||||
| header("Pragma: no-cache"); // HTTP/1.0
 | ||||
| 
 | ||||
| // Store commands into Cookie
 | ||||
| //setcookie("history","");
 | ||||
| // Store command into history cookie, if it is not already there
 | ||||
| $expire_time = gmmktime(0, 0, 0, 1, 1, 2038); | ||||
| ?>
 | ||||
| if (isset($_COOKIE['history']) && array_search($_REQUEST['command'], $_COOKIE['history'])) { | ||||
| 	// this command is already in the history, so do not need to add it
 | ||||
| } else { | ||||
| 	$i = isset($_COOKIE['history']) ? count($_COOKIE['history']) : 0; | ||||
| 	setcookie("history[$i]", $_REQUEST['command'], $expire_time); | ||||
| } | ||||
| 
 | ||||
| <FORM> | ||||
| <?php | ||||
| 
 | ||||
| //echo "history:" . $_COOKIE["history"];
 | ||||
| //print_r($_COOKIE);
 | ||||
| 
 | ||||
| 	//get the command and the options
 | ||||
| 	$cmd = @$_REQUEST["command"]; | ||||
| @@ -42,18 +44,18 @@ $expire_time = gmmktime(0, 0, 0, 1, 1, 2038); | ||||
| 	$ret_code = @$_REQUEST["ret_code"]; | ||||
| 
 | ||||
| 
 | ||||
| 		 if ($group == "")	$nodegrps = "blade7";	// For now, use blade7 as test node
 | ||||
| 		 //if ($group == "")	$nodegrps = "blade7";	// For now, use blade7 as test node
 | ||||
| 
 | ||||
| 		 if ($psh == "off"){ //using dsh
 | ||||
| 			$command = "xdsh "; | ||||
| 			$copy_cmd = "xdcp "; | ||||
| 			if ($group == "") $node_group = "-n " . $nodegrps; | ||||
| 			if ($group == "") $node_group = "-n " . $node; | ||||
| 			else $node_group = "-N " . $group; | ||||
| 
 | ||||
| 		 }else{ | ||||
| 		 	$command = "psh "; | ||||
| 			$copy_cmd = "prcp "; | ||||
| 			if ($group == "") $node_group = $nodegrps; | ||||
| 			if ($group == "") $node_group = $node; | ||||
| 			else $node_group = $group; | ||||
| 		 } | ||||
| 
 | ||||
| @@ -107,9 +109,7 @@ $expire_time = gmmktime(0, 0, 0, 1, 1, 2038); | ||||
| 		if ($ret_code == "on"){ | ||||
| 			$rc = runcmd($command_string, 0, $output);	//mode 0
 | ||||
| 			if ($rc == 0){ | ||||
| 				foreach ($outp as $key => $val){ | ||||
| 					echo $val. "</br>"; | ||||
| 				} | ||||
| 				foreach ($output as $line){ echo "$line<br>"; } | ||||
| 			} | ||||
| 
 | ||||
| 		}else{ | ||||
| @@ -193,8 +193,4 @@ $expire_time = gmmktime(0, 0, 0, 1, 1, 2038); | ||||
| 
 | ||||
| 	}*/ | ||||
| 
 | ||||
| ?>
 | ||||
| </FORM> | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| ?>
 | ||||
| @@ -25,7 +25,6 @@ approximately priority order:</p> | ||||
|   <li>Update the spec file for this web interface to have all the necessary post installation scripts (Bruce)</li> | ||||
|   <li>One button update of this web interface from the internet (Bruce)</li> | ||||
|   <li>Improve the look of associating the top menu with the 2nd menu (Quyen)</li> | ||||
|   <li>Have the task pane save the current task in the cookie and have each page set the current task (Bruce)</li> | ||||
|   <li>Do frame view and rack layout pages (Bruce)</li> | ||||
|   <li>Do several of the buttons within the machines views (Bruce): | ||||
|   <ul> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user