From 4ad9216707a0f9ed81c14f6d80cc4e2b92d59293 Mon Sep 17 00:00:00 2001 From: phamt Date: Tue, 1 May 2012 23:43:11 +0000 Subject: [PATCH] Formatted code. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@12434 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/configure.php | 4 +- xCAT-UI/css/login.css | 10 +- xCAT-UI/css/style.css | 118 +- xCAT-UI/ganglianode.php | 64 +- xCAT-UI/help.php | 4 +- xCAT-UI/index.php | 4 +- xCAT-UI/js/monitor/gangliamon.js | 24 +- xCAT-UI/js/monitor/rmcmon.js | 20 +- xCAT-UI/js/nodes/physical.js | 10 +- xCAT-UI/js/srv_xcatauth.js | 14 +- xCAT-UI/js/xcatauth.js | 12 +- xCAT-UI/lib/cmd.php | 52 +- xCAT-UI/lib/functions.php | 142 +- xCAT-UI/lib/rcons.php | 4 +- xCAT-UI/lib/srv_cmd.php | 48 +- xCAT-UI/lib/srv_functions.php | 446 ++- xCAT-UI/lib/srv_log.php | 24 +- xCAT-UI/lib/systemcmd.php | 36 +- xCAT-UI/lib/tabRestore.php | 14 +- xCAT-UI/lib/ui.php | 139 +- xCAT-UI/lib/upload.php | 34 +- xCAT-UI/lib/zCmd.php | 10 +- xCAT-UI/monitor.php | 4 +- xCAT-UI/provision.php | 4 +- xCAT-UI/rcons.php | 30 +- xCAT-UI/service.php | 86 +- xCAT-UI/xCAT-UI.spec | 2 +- xCAT-UI/xcat/plugins/web.pm | 4208 +++++++++++++++-------------- xCAT-UI/xcat/plugins/webportal.pm | 1350 ++++----- 29 files changed, 3429 insertions(+), 3488 deletions(-) diff --git a/xCAT-UI/configure.php b/xCAT-UI/configure.php index 0d754e90f..f518ad157 100644 --- a/xCAT-UI/configure.php +++ b/xCAT-UI/configure.php @@ -10,8 +10,8 @@ loadPage(); /* Login user */ if (!isAuthenticated()) { - login(); + login(); } else { - loadContent(); + loadContent(); } ?> \ No newline at end of file diff --git a/xCAT-UI/css/login.css b/xCAT-UI/css/login.css index 1e8be9733..8aea60065 100644 --- a/xCAT-UI/css/login.css +++ b/xCAT-UI/css/login.css @@ -30,11 +30,11 @@ body { padding: 5px; } -#login label{ +#login label { font: bold 12px sans-serif; } -#login_status { +#login-status { font: bold 12px sans-serif; } @@ -44,7 +44,7 @@ body { float: right; } -#login_form { +#login-form { background-color: #f5f5f5; height: 280px; -moz-border-radius: 3px; @@ -52,9 +52,9 @@ body { border-radius: 3px; } -#loginfo { +#log-info { margin: 5px 0px; text-align: right; color: #f5f5f5; - font-weight:bold; + font-weight: bold; } \ No newline at end of file diff --git a/xCAT-UI/css/style.css b/xCAT-UI/css/style.css index 066636d80..58f7b2828 100644 --- a/xCAT-UI/css/style.css +++ b/xCAT-UI/css/style.css @@ -1,11 +1,10 @@ -/*--------------- Dialogs ---------------*/ +/*--- Dialogs ---*/ .ui-dialog input { border: solid 1px #BDBDBD; font: 12px sans-serif; } -.ui-dialog label,.ui-dialog input,.ui-dialog p,.ui-dialog button,.ui-dialog td - { +.ui-dialog label,.ui-dialog input,.ui-dialog p,.ui-dialog button,.ui-dialog td { font: 12px sans-serif; } @@ -13,12 +12,11 @@ font: 12px sans-serif; } -.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button - { +.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button { font: 12px sans-serif; } -/*--------------- Tooltip ---------------*/ +/*--- Tooltip ---*/ .tooltip { background-color: #000; border: 1px solid #fff; @@ -37,7 +35,7 @@ margin: 0px; } -/*--------------- Header ---------------*/ +/*--- Header ---*/ #header { height: 39px; width: 1000px; @@ -90,15 +88,7 @@ color: #FF0000; } -#layoutselector { - padding: 2px 10px 0px 2px; /* Top right left bottom*/ - text-align: right; - color: #FFC125; - text-decoration: none; - display: block; -} - -/*--------------- Body and content ---------------*/ +/*--- Body and content ---*/ body { background: #1C1C1C; font: 12px sans-serif; @@ -124,7 +114,7 @@ pre { font-size: 10px; } -/*--------------- Groups ---------------*/ +/*--- Groups ---*/ #groups { width: 150px; vertical-align: top; @@ -178,7 +168,7 @@ pre { border-top: thin solid #E7EBFF; } -/*--------------- Nodes section ---------------*/ +/*--- Nodes section ---*/ #nodes { width: 790px; min-height: 570px; @@ -204,7 +194,7 @@ pre { line-height: 1; } -/*--------------- Info/warning bar ---------------*/ +/*--- Info and warning bar ---*/ span.ui-icon-info { float: left; margin-right: 0.3em; @@ -227,7 +217,7 @@ span.ui-icon-info { text-align: center } -/*--------------- jQuery tabs ---------------*/ +/*--- jQuery tabs ---*/ .tab { font: 12px sans-serif; border-style: none; @@ -248,7 +238,7 @@ span.ui-icon-info { cursor: pointer; } -/*--------------- Inventory and user entry ---------------*/ +/*--- Inventory and user entry ---*/ .tab table { border-width: 1px; border-spacing: 0px; @@ -326,7 +316,7 @@ legend { height: 300px; } -/*--------------- menu Div Actions bar ---------------*/ +/*--- menu Div Actions bar ---*/ .menuDiv { padding: 0.5em; height: 30px; @@ -373,7 +363,7 @@ legend { margin: 0; } -/*--------------- jQuery datatable ---------------*/ +/*--- jQuery datatable ---*/ .dataTables_wrapper { overflow: auto; width: auto; @@ -414,8 +404,7 @@ legend { } /*** < > buttons ***/ -.paginate_disabled_previous,.paginate_enabled_previous,.paginate_disabled_next,.paginate_enabled_next - { +.paginate_disabled_previous,.paginate_enabled_previous,.paginate_disabled_next,.paginate_enabled_next { height: 19px; width: 19px; margin-left: 2px; @@ -472,7 +461,7 @@ legend { color: #FF0000; } -/*--------------- Editable column ---------------*/ +/*--- Editable column ---*/ .tab .datatable textarea { font: 12px sans-serif; border: solid 1px #BDBDBD; @@ -498,7 +487,7 @@ legend { background: none; } -/*--------------- jQuery context menu ---------------*/ +/*--- jQuery context menu ---*/ .context-menu-theme-vista { background: #FAFAFA url(../images/contextmenu/context-menu-bg.gif) repeat-y left top; @@ -536,8 +525,7 @@ legend { background-image: none; } -.context-menu-theme-vista .context-menu-item-hover .context-menu-item-inner - { +.context-menu-theme-vista .context-menu-item-hover .context-menu-item-inner { padding: 3px 15px 3px 35px; margin-left: 0px; } @@ -546,7 +534,7 @@ legend { color: #A7A7A7; } -/*--------------- Forms ---------------*/ +/*--- Forms ---*/ .form label { color: #424242; line-height: 1.5; @@ -613,7 +601,7 @@ table a:hover { border: solid 1px #d4d4d4; } -/*--------------- Provision disk table ---------------*/ +/*--- Provision disk table ---*/ .provision table { border-width: 1px; border-spacing: 0px; @@ -630,7 +618,7 @@ table a:hover { width: 60px; } -/*--------------- Provision and clone table ---------------*/ +/*--- Provision and clone table ---*/ .special table { border-width: 1px; border-spacing: 0px; @@ -646,52 +634,52 @@ table a:hover { padding: 3px; } -/*--------------- Provision and monitor forms ---------------*/ -.monitornormal { +/*--- Provision and monitor forms ---*/ +.monitor-normal { background: #66CD00; cursor: pointer; } -.mornitorwarning { +.mornitor-warning { background: #FFD700; cursor: pointer; } -.monitorerror { +.monitor-error { background: #FF3030; } -.monitorunknown { +.monitor-unknown { background: #8B8B7A; } -.monitornodeli { +.monitor-node-li { width: 10px; height: 10px; float: left; border: 1px solid white; } -.monitorsumdiv { +.monitor-sum-div { width: 300px; height: 180px; float: left; margin: 0px 0px 10px 10px; } -.monitorsumdiv td { +.monitor-sum-div td { padding: 0; border-style: none; font-size: 10px; } -.monitornodediv { +.monitor-node-div { width: 240px; height: 120px; margin: 0px 0px 15px 0px; } -.monitorzoomlink { +.monitor-zoom-link { cursor: pointer; color: blue; } @@ -710,7 +698,7 @@ table a:hover { height: 150px; } -/*--------------- Physical layout section ---------------*/ +/*--- Physical layout section ---*/ .frameDiv { width: 179px; height: 500px; @@ -768,7 +756,7 @@ table a:hover { height: 11px; } -.fspcheckbox { +.fspCheckbox { padding: 0px; margin: 3px 3px 1px 3px; } @@ -796,7 +784,7 @@ table a:hover { background: url(../images/nodes/blade.jpg); } -.xnodeDiv { +.xNodeDiv { font-size: 12px; height: 21px; line-height: 21px; @@ -809,45 +797,7 @@ table a:hover { display: inline-block; } -/*--------------- Discovery section ---------------*/ -.discoverstep { - width: 960px; - vertical-align: top; - background-color: #A9D0F5; - padding: 0px 0px 0px 5px; - -moz-border-radius: .3em; - -webkit-border-radius: .3em; - border-radius: .3em; -} - -.discovercurrentstep { - background-color: yellow; - font: normal bold 12px/35px sans-serif; - padding: 5px; -} - -.discovercontent { - width: 960px; - display: inline-table; - padding: 0; -} - -.discovercontent table { - border: none; -} - -.discovercontent td { - border: none; - text-align: left; -} - -.discovercontent th { - font: normal bold 15px sans-serif; - text-align: center; - border: none; -} - -/*--------------- jqPlot Pie legend ---------------*/ +/*--- jqPlot Pie legend ---*/ td.jqplot-table-legend { border-width: 0px; } diff --git a/xCAT-UI/ganglianode.php b/xCAT-UI/ganglianode.php index 370fbefcf..3ee6b5d89 100644 --- a/xCAT-UI/ganglianode.php +++ b/xCAT-UI/ganglianode.php @@ -1,17 +1,18 @@ - - Node {$_GET['n']} Ganglia Report - - - - - - - + + Node {$_GET['n']} Ganglia Report + + + + + + + EEE; ?> + + - - - -
- - - - - - - - - - - -
-
- + + + + +
+ + + + + + + + + + + +
+
+ EEE; ?> \ No newline at end of file diff --git a/xCAT-UI/help.php b/xCAT-UI/help.php index d9d5b552c..95bf6e353 100644 --- a/xCAT-UI/help.php +++ b/xCAT-UI/help.php @@ -10,8 +10,8 @@ loadPage(); /* Login user */ if (!isAuthenticated()) { - login(); + login(); } else { - loadContent(); + loadContent(); } ?> \ No newline at end of file diff --git a/xCAT-UI/index.php b/xCAT-UI/index.php index dadb7b817..b55a5842c 100644 --- a/xCAT-UI/index.php +++ b/xCAT-UI/index.php @@ -11,8 +11,8 @@ loadPage(); /* Login user */ if (!isAuthenticated()) { - login(); + login(); } else { - loadContent(); + loadContent(); } ?> \ No newline at end of file diff --git a/xCAT-UI/js/monitor/gangliamon.js b/xCAT-UI/js/monitor/gangliamon.js index 2fd4c4ddd..664a6d6ff 100644 --- a/xCAT-UI/js/monitor/gangliamon.js +++ b/xCAT-UI/js/monitor/gangliamon.js @@ -476,11 +476,11 @@ function drawGridSummary() { } gridDrawArea.empty(); - showStr = '' + - '' + - '' + - '' + - '' + + showStr = '
' + + '' + + '' + + '' + + '' + '
'; gridDrawArea.append(showStr); drawLoadFlot('gangliasummaryload', 'Grid', gridData['load_one'], gridData['cpu_num']); @@ -906,23 +906,23 @@ function drawGangliaNodesAreaPic(type, name) { nodename = temparray[index]; switch (nodeStatus[nodename]) { case 'ERROR': - showStr = '
  • '; + showStr = '
  • '; break; case 'WARNING': - showStr = '
  • '; + showStr = '
  • '; break; case 'NORMAL': - showStr = '
  • '; + showStr = '
  • '; break; default: - showStr = '
  • '; + showStr = '
  • '; break; } $('#gangliaNodes ul').append(showStr); } // Bind all normal and warning nodes click event - $('.monitornormal,.monitorwarning').bind('click', function() { + $('.monitor-normal,.monitorwarning').bind('click', function() { var nodename = $(this).attr('title'); window.open('ganglianode.php?n=' + nodename + '&p=' + nodePath[nodename], 'nodedetail','height=430,width=950,scrollbars=yes,status =no'); @@ -1077,7 +1077,7 @@ function updateZoom(obj) { while ($('#zoomDiv span:last').attr('name') != type) { $('#zoomDiv span:last').remove(); } - $(obj).removeClass('monitorzoomlinkli'); + $(obj).removeClass('monitor-zoom-link'); $(obj).unbind('click'); drawGangliaNodesArea(); @@ -1093,7 +1093,7 @@ function addZoomDiv(obj) { var type = $(obj).attr('name'); var lastzoomobj = $('#zoomDiv span:last'); - lastzoomobj.addClass('monitorzoomlink'); + lastzoomobj.addClass('monitor-zoom-link'); lastzoomobj.bind('click', function() { updateZoom(this); }); diff --git a/xCAT-UI/js/monitor/rmcmon.js b/xCAT-UI/js/monitor/rmcmon.js index c2215a251..8eb011415 100644 --- a/xCAT-UI/js/monitor/rmcmon.js +++ b/xCAT-UI/js/monitor/rmcmon.js @@ -273,13 +273,13 @@ function showRmcSummary(returnData) { summaryTable.append(summaryRow); } summaryRow.append(tempTd); - attrDiv = $('
    '); + attrDiv = $('
    '); tempTd.append(attrDiv); for (var i in attrValues) { tempArray.push( [ globalTimeStamp[i], Number(attrValues[i]) ]); } - $.jqplot('monitorsumdiv' + attr, [ tempArray ], { + $.jqplot('monitor-sum-div' + attr, [ tempArray ], { series: [{ showMarker : false }], @@ -348,13 +348,13 @@ function parseRmcData(returnData) { } function createUnkownNode(nodeName) { - var tempLi = '
  • '; return tempLi; } function createErrorNode(nodeName) { - var tempLi = '
  • '; } @@ -403,12 +403,12 @@ function showRmcNodes(data, nodename) { memAvg = parseInt(tempSum / index); if (cpuAvg >= 10 && memAvg <= 90){ - classname = 'monitornormal'; + classname = 'monitor-normal'; } else { - classname = 'mornitorwarning'; + classname = 'mornitor-warning'; } - var normalLi = $('
  • '); $('#rmcmonDetail ul').append(normalLi); @@ -440,8 +440,8 @@ function showNode(nodeName) { for ( var attr in globalNodesDetail[nodeName]) { var tempTd = $(''); - var attrChat = $('
    '); + var attrChat = $('
    '); if (0 == parseNum % 4) { nodeRow = $(''); nodeTable.append(nodeRow); @@ -457,7 +457,7 @@ function showNode(nodeName) { tempArray.push( [ globalTimeStamp[i], Number(tempData[i]) ]); } - $.jqplot('monitornodediv' + nodeName + attr, [ tempArray ], { + $.jqplot('monitor-node-div' + nodeName + attr, [ tempArray ], { series : [{ showMarker : false }], diff --git a/xCAT-UI/js/nodes/physical.js b/xCAT-UI/js/nodes/physical.js index 498ffd35c..18066b328 100644 --- a/xCAT-UI/js/nodes/physical.js +++ b/xCAT-UI/js/nodes/physical.js @@ -312,7 +312,7 @@ function createSystempGraphical(bpa, fsp, area){ var td = $(''); var frameDiv = $('
    '); - frameDiv.append('
    '); + frameDiv.append('
    '); //for P7-IH, all the cecs are insert into the frame from down to up, so we had to show the cecs same as the //physical layout. @@ -445,7 +445,7 @@ function createSystempGraphical(bpa, fsp, area){ updateSelectNodeDiv(); }); - $('.fspcheckbox').bind('click', function(){ + $('.fspCheckbox').bind('click', function(){ var itemName = $(this).attr('name'); name = itemName.substr(6); @@ -571,8 +571,8 @@ function createSystemxGraphical(xnodes, area){ } xnodenum++; var td = $(''); - var xnodeDiv = '
    '; - td.append(xnodeDiv); + var xNodeDiv = '
    '; + td.append(xNodeDiv); row.append(td); } } @@ -801,7 +801,7 @@ function createFspDiv(fspName, mtm, fsp){ } //create return value - var retHtml = ''; + var retHtml = ''; retHtml += '
    '; retHtml += '
    ' + lparStatusRow + '
    '; return retHtml; diff --git a/xCAT-UI/js/srv_xcatauth.js b/xCAT-UI/js/srv_xcatauth.js index a22fc56ad..e9c4ef89c 100644 --- a/xCAT-UI/js/srv_xcatauth.js +++ b/xCAT-UI/js/srv_xcatauth.js @@ -24,8 +24,8 @@ $(document).ready(function() { }).button(); if (document.location.protocol == 'http:') { - $('#login_status').html('You are using an unencrypted session!'); - $('#login_status').css('color', 'red'); + $('#login-status').html('You are using an unencrypted session!'); + $('#login-status').css('color', 'red'); } if (!$("#login input[name='username']").val()) { @@ -62,7 +62,7 @@ function onlogin(data, txtStatus) { var usrName = $("#login input[name='username']").val(); $("#login input[name='password']").val(''); if (data.authenticated == 'yes') { - $('#login_status').text('Login successful'); + $('#login-status').text('Login successful'); window.location = 'service.php'; // Set user name cookie @@ -70,8 +70,8 @@ function onlogin(data, txtStatus) { exDate.setTime(exDate.getTime() + (240 * 60 * 1000)); $.cookie('xcat_username', usrName, { expires: exDate }); } else { - $('#login_status').text('Authentication failure'); - $('#login_status').css('color', '#FF0000'); + $('#login-status').text('Authentication failure'); + $('#login-status').css('color', '#FF0000'); } } @@ -79,8 +79,8 @@ function onlogin(data, txtStatus) { * Authenticate user for new session */ function authenticate() { - $('#login_status').css('color', '#000000'); - $('#login_status').html('Authenticating...'); + $('#login-status').css('color', '#000000'); + $('#login-status').html('Authenticating...'); var passwd = $("#login input[name='password']").val(); $.post('lib/srv_log.php', { diff --git a/xCAT-UI/js/xcatauth.js b/xCAT-UI/js/xcatauth.js index 9d615b349..22fb185fc 100644 --- a/xCAT-UI/js/xcatauth.js +++ b/xCAT-UI/js/xcatauth.js @@ -26,8 +26,8 @@ $(document).ready(function() { $('#login button').button(); if (document.location.protocol == "http:") { - $("#login_status").html("You are using an unencrypted session!"); - $("#login_status").css("color", "#ff0000"); + $("#login-status").html("You are using an unencrypted session!"); + $("#login-status").css("color", "#ff0000"); } if ($("#login input[name='username']").val() == "") { @@ -64,7 +64,7 @@ function onlogin(data, txtStatus) { // Clear password field regardless of what happens $("#login input[name='password']").val(""); if (data.authenticated == "yes") { - $("#login_status").text("Login successful"); + $("#login-status").text("Login successful"); // Not the first time to log if ($.cookie('logonflag')){ @@ -87,7 +87,7 @@ function onlogin(data, txtStatus) { }); } else { - $("#login_status").text("Authentication failure").css("color", "#FF0000"); + $("#login-status").text("Authentication failure").css("color", "#FF0000"); } } @@ -97,8 +97,8 @@ function onlogin(data, txtStatus) { * @return Nothing */ function authenticate() { - $("#login_status").css("color", "#000000"); - $("#login_status").html('Authenticating...'); + $("#login-status").css("color", "#000000"); + $("#login-status").html('Authenticating...'); var passwd = $("#login input[name='password']").val(); $.post("lib/log.php", { username : $("#login input[name='username']").val(), diff --git a/xCAT-UI/lib/cmd.php b/xCAT-UI/lib/cmd.php index d040fe499..d272b9d79 100644 --- a/xCAT-UI/lib/cmd.php +++ b/xCAT-UI/lib/cmd.php @@ -6,26 +6,26 @@ require_once "$TOPDIR/lib/jsonwrapper.php"; /** * Issue a xCAT command, e.g. rinv gpok123 all - * This will handle most commands. If not, you can create your - * own .php. Look at zCmd.php for an example. + * This will handle most commands. If not, you can create your own .php. + * Look at zCmd.php for an example. * - * @param $cmd The xCAT command - * @param $tgt The target node or group - * @param $args The xCAT command arguments, separated by semicolons - * @param $opts The xCAT command options, separated by semicolons - * @return The xCAT response. Replies are in the form of JSON + * @param $cmd The xCAT command + * @param $tgt The target node or group + * @param $args The xCAT command arguments, separated by semicolons + * @param $opts The xCAT command options, separated by semicolons + * @return The xCAT response. Replies are in the form of JSON */ if (isset($_GET["cmd"])) { // HTTP GET requests $cmd = $_GET["cmd"]; $tgt = $_GET["tgt"]; $args = $_GET["args"]; - + // File contents in case of file write if (isset($_GET["cont"])) { $cont = $_GET["cont"]; } - + // Special messages put here // This gets sent back to the AJAX request as is. $msg = $_GET["msg"]; @@ -34,7 +34,7 @@ if (isset($_GET["cmd"])) { if (!$tgt) { $tgt = NULL; } - + // If no $msg is given, set $msg to NULL if (!$msg) { $msg = NULL; @@ -52,12 +52,12 @@ if (isset($_GET["cmd"])) { $args_array = array($args); } } - + // If no $opts are given, set $opts_array to NULL $opts_array = array(); if (isset($_GET["opts"])) { $opts = $_GET["opts"]; - + // If $args contains multiple arguments, split it into an array if (strpos($opts,";")) { // Split the arguments into an array @@ -74,7 +74,7 @@ if (isset($_GET["cmd"])) { if (in_array("flush", $opts_array)) { return; } - + $rsp = array(); // webrun pping and gangliastatus output needs special handling @@ -90,7 +90,7 @@ if (isset($_GET["cmd"])) { // This command gets the nodes and groups else if(strncasecmp($cmd, "extnoderange", 12) == 0) { $rsp = extractExtnoderange($xml); - } + } // Write contents to file else if(strncasecmp($cmd, "write", 4) == 0) { // Directory should be /var/opt/xcat/profiles @@ -99,7 +99,7 @@ if (isset($_GET["cmd"])) { $handle = fopen($file, 'w') or die("Cannot open $file"); fwrite($handle, $cont); fclose($handle); - + $rsp = "Directory entry written to $file"; } // Handle the typical output @@ -108,20 +108,20 @@ if (isset($_GET["cmd"])) { foreach ($child->children() as $data) { if($data->name) { $node = $data->name; - + if ($data->data->contents) { $cont = $data->data->contents; } else { $cont = $data->data; } - + if ($data->data->desc) { $cont = $data->data->desc . ": " . $cont; } - + $cont = str_replace(":|:", "\n", $cont); array_push($rsp, "$node: $cont"); - } else if(strlen("$data") > 2) { + } else if (strlen("$data") > 2) { $data = str_replace(":|:", "\n", $data); array_push($rsp, "$data"); } @@ -137,8 +137,8 @@ if (isset($_GET["cmd"])) { /** * Extract the output for a webrun command * - * @param $xml The XML output from docmd() - * @return An array containing the output + * @param $xml The XML output from docmd() + * @return An array containing the output */ function extractWebrun($xml) { $rsp = array(); @@ -149,7 +149,7 @@ function extractWebrun($xml) { foreach($nodes->children() as $node){ // Get the node name $name = $node->name; - + // Get the content $status = $node->data; $status = str_replace(":|:", "\n", $status); @@ -166,8 +166,8 @@ function extractWebrun($xml) { /** * Extract the output for a nodels command * - * @param $xml The XML output from docmd() - * @return An array containing the output + * @param $xml The XML output from docmd() + * @return An array containing the output */ function extractNodels($xml) { $rsp = array(); @@ -195,8 +195,8 @@ function extractNodels($xml) { /** * Extract the output for a extnoderange command * - * @param $xml The XML output from docmd() - * @return The nodes and groups + * @param $xml The XML output from docmd() + * @return The nodes and groups */ function extractExtnoderange($xml) { $rsp = array(); diff --git a/xCAT-UI/lib/functions.php b/xCAT-UI/lib/functions.php index c1e23b5eb..52935d368 100644 --- a/xCAT-UI/lib/functions.php +++ b/xCAT-UI/lib/functions.php @@ -5,22 +5,21 @@ // Retain session variables across page requests session_start(); -session_write_close(); // Do not block HTTP requests +session_write_close(); // Do not block other HTTP requests -// The settings below display error on the screen, -// instead of giving blank pages. +// The settings below display error on the screen, instead of giving blank pages. error_reporting(E_ALL); ini_set('display_errors', true); /** * Run a command using the xCAT client/server protocol * - * @param $cmd The xCAT command - * @param $nr Node range or group - * @param $args_array Command arguments - * @param $opts_array Command options - * @return A tree of SimpleXML objects. - * See perl-xCAT/xCAT/Client.pm for the format + * @param $cmd The xCAT command + * @param $nr Node range or group + * @param $args_array Command arguments + * @param $opts_array Command options + * @return A tree of SimpleXML objects. + * See perl-xCAT/xCAT/Client.pm for the format */ function docmd($cmd, $nr, $args_array, $opts_array){ // If we are not logged in, @@ -34,7 +33,9 @@ function docmd($cmd, $nr, $args_array, $opts_array){ // Add command, node range, and arguments to request $request = simplexml_load_string(''); $request->addChild('command', $cmd); - if(!empty($nr)) { $request->addChild('noderange', $nr); } + if (!empty($nr)) { + $request->addChild('noderange', $nr); + } if (!empty($args_array)) { foreach ($args_array as $a) { $request->addChild('arg',$a); @@ -53,9 +54,9 @@ function docmd($cmd, $nr, $args_array, $opts_array){ /** * Used by docmd() to submit request to xCAT * - * @param $req Tree of SimpleXML objects - * @param $opts_array Request options - * @return A tree of SimpleXML objects + * @param $req Tree of SimpleXML objects + * @param $opts_array Request options + * @return A tree of SimpleXML objects */ function submit_request($req, $skipVerify, $opts_array){ $xcathost = "localhost"; @@ -63,46 +64,46 @@ function submit_request($req, $skipVerify, $opts_array){ $rsp = FALSE; $response = ''; $cleanexit = 0; - + // Determine whether to flush output or not $flush = false; if ($opts_array && in_array("flush", $opts_array)) { $flush = true; } - + // Determine how to handle the flush output // You can specify a function name, in place of TBD, to handle the flush output $flush_format = ""; if ($opts_array && in_array("flush-format=TBD", $opts_array)) { $flush_format = "TBD"; } - - // Open syslog, include the process ID and also send - // the log to standard error, and use a user defined - // logging mechanism + + // Open syslog, include the process ID and also send the log to standard error, + // and use a user defined logging mechanism openlog("xCAT-UI", LOG_PID | LOG_PERROR, LOG_LOCAL0); // Open a socket to xcatd syslog(LOG_INFO, "Opening socket to xcatd..."); - if($fp = stream_socket_client('ssl://'.$xcathost.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT)){ + if ($fp = stream_socket_client('ssl://'.$xcathost.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT)){ $reqXML = $req->asXML(); $nr = $req->noderange; $cmd = $req->command; - + syslog(LOG_INFO, "Sending request: $cmd $nr"); - stream_set_blocking($fp, 0); // Set as non-blocking - fwrite($fp,$req->asXML()); // Send XML to xcatd - set_time_limit(900); // Set 15 minutes timeout (for long running requests) - // The default is 30 seconds which is too short for some requests - + stream_set_blocking($fp, 0); // Set as non-blocking + fwrite($fp,$req->asXML()); // Send XML to xcatd + set_time_limit(900); // Set 15 minutes timeout (for long running requests) + // The default is 30 seconds which is too short for some requests + // Turn on output buffering ob_start(); - while(!feof($fp)) { // Read until there is no more + while (!feof($fp)) { + // Read until there is no more // Remove newlines and add it to the response $str = fread($fp, 8192); if ($str) { $response .= preg_replace('/>\n\s*<', $str); - + // Flush output to browser if ($flush) { // Strip HTML tags from output @@ -117,50 +118,48 @@ function submit_request($req, $skipVerify, $opts_array){ flush(); } } - } + } } - + // Look for serverdone response $fullpattern = '/\s*\s*<\/serverdone>\s*<\/xcatresponse>/'; $mixedpattern = '/\s*<\/serverdone>.*<\/xcatresponse>/'; $recentpattern = '/<\/xcatresponse>/'; - if(preg_match($recentpattern,$str) && preg_match($mixedpattern,$response)) { - // Transaction is done, - // Package up XML and return it + if (preg_match($recentpattern,$str) && preg_match($mixedpattern,$response)) { + // Transaction is done, package up XML and return it // Remove the serverdone response and put an xcat tag around the rest $count = 0; - $response = preg_replace($fullpattern,'', $response, -1, $count); // 1st try to remove the long pattern - if (!$count) { $response = preg_replace($mixedpattern,'', $response) . '/'; } // if its not there, then remove the short pattern + $response = preg_replace($fullpattern,'', $response, -1, $count); // 1st try to remove the long pattern + if (!$count) { + $response = preg_replace($mixedpattern,'', $response) . '/'; + } $response = "$response"; - //delete the \n between '>' and '<' $response = preg_replace('/>\n\s*<', $response); - //replace the '\n' by ':|:' in the data area. $response = preg_replace('/\n/', ':|:', $response); $rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA); $cleanexit = 1; break; } } // End of while(!feof($fp)) - + syslog(LOG_INFO, "($cmd $nr) Sending response"); fclose($fp); } else { echo "

    xCAT submit request socket error: $errno - $errstr

    "; } - + // Flush (send) the output buffer and turn off output buffering ob_end_flush(); // Close syslog closelog(); - + if(! $cleanexit) { if (preg_match('/^\s*.*<\/xcatresponse>\s*$/',$response)) { // Probably an error message $response = "$response"; $rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA); - } - elseif(!$skipVerify) { + } else if(!$skipVerify) { echo "

    (Error) xCAT response ended prematurely: ", htmlentities($response), "

    "; $rsp = FALSE; } @@ -170,10 +169,6 @@ function submit_request($req, $skipVerify, $opts_array){ /** * Enable password storage to split between cookie and session variable - * - * @param $data - * @param $key - * @return */ function xorcrypt($data, $key) { $datalen = strlen($data); @@ -187,9 +182,6 @@ function xorcrypt($data, $key) { /** * Get password - * - * @param Nothing - * @return */ function getpassword() { if (isset($GLOBALS['xcatauthsecret'])) { @@ -204,13 +196,11 @@ function getpassword() { } /** - * Get the password splitting knowledge between server - * and client side persistant storage. Caller should regenerate - * session ID when contemplating a new user/password, to preclude - * session fixation, though fixation is limited without the secret. + * Get the password splitting knowledge between server and client side persistant storage. + * Caller should regenerate session ID when contemplating a new user/password, + * to preclude session fixation, though fixation is limited without the secret. * - * @param $password Password - * @return Nothing + * @param $password Password */ function setpassword($password) { $randlen = strlen($password); @@ -227,8 +217,8 @@ function setpassword($password) { /** * Get RAND characters * - * @param $length Length of characters - * @return RAND characters + * @param $length Length of characters + * @return RAND characters */ function getrandchars($length) { $charset = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*'; @@ -246,9 +236,7 @@ function getrandchars($length) { /** * Determine if a user/password session exists * - * @param Nothing - * @return True If user has a session. - * False Otherwise + * @return True if user has a session, false otherwise */ function is_logged() { if (isset($_SESSION["username"]) and !is_bool(getpassword())) { @@ -260,10 +248,8 @@ function is_logged() { /** * Determine if a user is currently logged in successfully - * - * @param Nothing - * @return True If the user is currently logged in successfully - * False Otherwise + * + * @return True if the user is currently logged in successfully, false otherwise */ function isAuthenticated() { if (is_logged()) { @@ -290,12 +276,10 @@ function isAuthenticated() { } /** -* Determine if a user has root access -* -* @param Nothing -* @return True If the user has root access -* False Otherwise -*/ + * Determine if a user has root access + * + * @return True if the user has root access, false otherwise + */ function isRootAcess() { if (is_logged() && $_SESSION["xcatpassvalid"]) { $testacc = docmd('tabdump', '', array('policy', '-w', "name==" . $_SESSION["username"]), array()); @@ -304,7 +288,7 @@ function isRootAcess() { $result = str_replace('"', '', $result); $args = array(); $args = explode(",", $result); - + // Get the comments which contains the privilege $comments = $args[8]; $args = explode(";", $comments); @@ -319,13 +303,13 @@ function isRootAcess() { $privilege = 'root'; $_SESSION["xcatpassvalid"] = 1; } - + break; - } + } } } } - + if (strcmp($_SESSION["username"], 'root') == 0) { $_SESSION["xcatpassvalid"] = 1; } @@ -338,10 +322,7 @@ function isRootAcess() { } /** - * Log out of the current user session - * - * @param Nothing - * @return Nothing + * Log out of current user session */ function logout() { // Clear the secret cookie from browser @@ -360,12 +341,9 @@ function logout() { /** * Format a given string and echo it back to the browser - * - * @param $str String - * @return Nothing */ function format_TBD($str) { - // Format a given string however you want it + // Format a given string however you want it echo $tmp . '
    '; flush(); } diff --git a/xCAT-UI/lib/rcons.php b/xCAT-UI/lib/rcons.php index 5ddc2825a..d27960aa2 100644 --- a/xCAT-UI/lib/rcons.php +++ b/xCAT-UI/lib/rcons.php @@ -77,14 +77,14 @@ function rconsSynchronise($parameter) { if (0 == strlen($line)) { continue; } - + if ('<' == substr($line, 0, 1)) { $flag = true; $return .= $line; break; } } - + if ($flag) { while (!feof($fp)) { $return .= fgets($fp, 1024); diff --git a/xCAT-UI/lib/srv_cmd.php b/xCAT-UI/lib/srv_cmd.php index 3798fab27..ae3b4878b 100644 --- a/xCAT-UI/lib/srv_cmd.php +++ b/xCAT-UI/lib/srv_cmd.php @@ -5,22 +5,21 @@ require_once "$TOPDIR/lib/srv_functions.php"; require_once "$TOPDIR/lib/jsonwrapper.php"; /** - * Issue a xCAT command, e.g. rinv gpok123 all - * This will handle most commands. If not, you can create your - * own .php. Look at zCmd.php for an example. + * Issue a xCAT command, e.g. rinv gpok123 all. This will handle most commands. + * If not, you can create your own .php. Look at zCmd.php for an example. * - * @param $cmd The xCAT command - * @param $tgt The target node or group - * @param $args The xCAT command arguments, separated by semicolons - * @param $opts The xCAT command options, separated by semicolons - * @return The xCAT response. Replies are in the form of JSON + * @param $cmd The xCAT command + * @param $tgt The target node or group + * @param $args The xCAT command arguments, separated by semicolons + * @param $opts The xCAT command options, separated by semicolons + * @return The xCAT response. Replies are in the form of JSON */ if (isset($_GET["cmd"])) { // HTTP GET requests $cmd = $_GET["cmd"]; $tgt = $_GET["tgt"]; $args = $_GET["args"]; - + // Special messages put here // This gets sent back to the AJAX request as is. $msg = $_GET["msg"]; @@ -29,7 +28,7 @@ if (isset($_GET["cmd"])) { if (!$tgt) { $tgt = NULL; } - + // If no $msg is given, set $msg to NULL if (!$msg) { $msg = NULL; @@ -47,12 +46,12 @@ if (isset($_GET["cmd"])) { $args_array = array($args); } } - + // If no $opts are given, set $opts_array to NULL $opts_array = array(); if (isset($_GET["opts"])) { $opts = $_GET["opts"]; - + // If $args contains multiple arguments, split it into an array if (strpos($opts,";")) { // Split the arguments into an array @@ -69,7 +68,7 @@ if (isset($_GET["cmd"])) { if (in_array("flush", $opts_array)) { return; } - + $rsp = array(); // webrun pping and gangliastatus output needs special handling @@ -92,17 +91,16 @@ if (isset($_GET["cmd"])) { foreach ($child->children() as $data) { if($data->name) { $node = $data->name; - + if($data->data->contents){ $cont = $data->data->contents; - } - else{ + } else { $cont = $data->data; } - + $cont = str_replace(":|:", "\n", $cont); array_push($rsp, "$node: $cont"); - } else if(strlen("$data") > 2) { + } else if (strlen("$data") > 2) { $data = str_replace(":|:", "\n", $data); array_push($rsp, "$data"); } @@ -118,8 +116,8 @@ if (isset($_GET["cmd"])) { /** * Extract the output for a webrun command * - * @param $xml The XML output from docmd() - * @return An array containing the output + * @param $xml The XML output from docmd() + * @return An array containing the output */ function extractWebrun($xml) { $rsp = array(); @@ -130,7 +128,7 @@ function extractWebrun($xml) { foreach($nodes->children() as $node){ // Get the node name $name = $node->name; - + // Get the content $status = $node->data; $status = str_replace(":|:", "\n", $status); @@ -147,8 +145,8 @@ function extractWebrun($xml) { /** * Extract the output for a nodels command * - * @param $xml The XML output from docmd() - * @return An array containing the output + * @param $xml The XML output from docmd() + * @return An array containing the output */ function extractNodels($xml) { $rsp = array(); @@ -176,8 +174,8 @@ function extractNodels($xml) { /** * Extract the output for a extnoderange command * - * @param $xml The XML output from docmd() - * @return The nodes and groups + * @param $xml The XML output from docmd() + * @return The nodes and groups */ function extractExtnoderange($xml) { $rsp = array(); diff --git a/xCAT-UI/lib/srv_functions.php b/xCAT-UI/lib/srv_functions.php index 624db7687..c18a336fb 100644 --- a/xCAT-UI/lib/srv_functions.php +++ b/xCAT-UI/lib/srv_functions.php @@ -5,7 +5,7 @@ // Retain session variables across page requests session_start(); -session_write_close(); // Do not block HTTP requests +session_write_close(); // Do not block HTTP requests // The settings below display error on the screen, // instead of giving blank pages. @@ -15,310 +15,286 @@ ini_set('display_errors', true); /** * Run a command using the xCAT client/server protocol * - * @param $cmd The xCAT command - * @param $nr Node range or group - * @param $args_array Command arguments - * @param $opts_array Command options - * @return A tree of SimpleXML objects. - * See perl-xCAT/xCAT/Client.pm for the format + * @param $cmd The xCAT command + * @param $nr Node range or group + * @param $args_array Command arguments + * @param $opts_array Command options + * @return A tree of SimpleXML objects. See perl-xCAT/xCAT/Client.pm for the format */ function docmd($cmd, $nr, $args_array, $opts_array){ - // If we are not logged in, - // do not try to communicate with xcatd - if (!is_logged()) { - echo "

    You are not logged in! Failed to run command.

    "; - return simplexml_load_string('', 'SimpleXMLElement', LIBXML_NOCDATA); - } + // If we are not logged in, + // do not try to communicate with xcatd + if (!is_logged()) { + echo "

    You are not logged in! Failed to run command.

    "; + return simplexml_load_string('', 'SimpleXMLElement', LIBXML_NOCDATA); + } - // Create xCAT request - // Add command, node range, and arguments to request - $request = simplexml_load_string(''); - $request->addChild('command', $cmd); - if(!empty($nr)) { $request->addChild('noderange', $nr); } - if (!empty($args_array)) { - foreach ($args_array as $a) { - $request->addChild('arg',$a); - } - } + // Create xCAT request + // Add command, node range, and arguments to request + $request = simplexml_load_string(''); + $request->addChild('command', $cmd); + if (!empty($nr)) { $request->addChild('noderange', $nr); } + if (!empty($args_array)) { + foreach ($args_array as $a) { + $request->addChild('arg',$a); + } + } - // Add user and password to request - $usernode=$request->addChild('becomeuser'); - $usernode->addChild('username',$_SESSION["srv_username"]); - $usernode->addChild('password',getpassword()); + // Add user and password to request + $usernode=$request->addChild('becomeuser'); + $usernode->addChild('username',$_SESSION["srv_username"]); + $usernode->addChild('password',getpassword()); - $xml = submit_request($request, 0, $opts_array); - return $xml; + $xml = submit_request($request, 0, $opts_array); + return $xml; } /** * Used by docmd() to submit request to xCAT * - * @param $req Tree of SimpleXML objects - * @param $opts_array Request options - * @return A tree of SimpleXML objects + * @param $req Tree of SimpleXML objects + * @param $opts_array Request options + * @return A tree of SimpleXML objects */ function submit_request($req, $skipVerify, $opts_array){ - $xcathost = "localhost"; - $port = "3001"; - $rsp = FALSE; - $response = ''; - $cleanexit = 0; - - // Determine whether to flush output or not - $flush = false; - if ($opts_array && in_array("flush", $opts_array)) { - $flush = true; - } - - // Determine how to handle the flush output - // You can specify a function name, in place of TBD, to handle the flush output - $flush_format = ""; - if ($opts_array && in_array("flush-format=TBD", $opts_array)) { - $flush_format = "TBD"; - } - - // Open syslog, include the process ID and also send - // the log to standard error, and use a user defined - // logging mechanism - openlog("xCAT-UI", LOG_PID | LOG_PERROR, LOG_LOCAL0); + $xcathost = "localhost"; + $port = "3001"; + $rsp = FALSE; + $response = ''; + $cleanexit = 0; + + // Determine whether to flush output or not + $flush = false; + if ($opts_array && in_array("flush", $opts_array)) { + $flush = true; + } + + // Determine how to handle the flush output + // You can specify a function name, in place of TBD, to handle the flush output + $flush_format = ""; + if ($opts_array && in_array("flush-format=TBD", $opts_array)) { + $flush_format = "TBD"; + } + + // Open syslog, include the process ID and also send + // the log to standard error, and use a user defined + // logging mechanism + openlog("xCAT-UI", LOG_PID | LOG_PERROR, LOG_LOCAL0); - // Open a socket to xcatd - syslog(LOG_INFO, "Opening socket to xcatd..."); - if($fp = stream_socket_client('ssl://'.$xcathost.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT)){ - $reqXML = $req->asXML(); - $nr = $req->noderange; - $cmd = $req->command; - - syslog(LOG_INFO, "Sending request: $cmd $nr"); - stream_set_blocking($fp, 0); // Set as non-blocking - fwrite($fp,$req->asXML()); // Send XML to xcatd - set_time_limit(900); // Set 15 minutes timeout (for long running requests) - // The default is 30 seconds which is too short for some requests - - // Turn on output buffering - ob_start(); - while(!feof($fp)) { // Read until there is no more - // Remove newlines and add it to the response - $str = fread($fp, 8192); - if ($str) { - $response .= preg_replace('/>\n\s*<', $str); - - // Flush output to browser - if ($flush) { - // Strip HTML tags from output - if ($tmp = trim(strip_tags($str))) { - // Format the output based on what was given for $flush_format - if ($flush_format == "TDB") { - format_TBD($tmp); - } else { - // Print out output by default - echo '
    ' . $tmp . '
    '; - ob_flush(); - flush(); - } - } - } - } - - // Look for serverdone response - $fullpattern = '/\s*\s*<\/serverdone>\s*<\/xcatresponse>/'; - $mixedpattern = '/\s*<\/serverdone>.*<\/xcatresponse>/'; - $recentpattern = '/<\/xcatresponse>/'; - if(preg_match($recentpattern,$str) && preg_match($mixedpattern,$response)) { - // Transaction is done, - // Package up XML and return it - // Remove the serverdone response and put an xcat tag around the rest - $count = 0; - $response = preg_replace($fullpattern,'', $response, -1, $count); // 1st try to remove the long pattern - if (!$count) { $response = preg_replace($mixedpattern,'', $response) . '/'; } // if its not there, then remove the short pattern - $response = "$response"; - //delete the \n between '>' and '<' - $response = preg_replace('/>\n\s*<', $response); - //replace the '\n' by ':|:' in the data area. - $response = preg_replace('/\n/', ':|:', $response); - $rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA); - $cleanexit = 1; - break; - } - } // End of while(!feof($fp)) - - syslog(LOG_INFO, "($cmd $nr) Sending response"); - fclose($fp); - } else { - echo "

    xCAT submit request socket error: $errno - $errstr

    "; - } - - // Flush (send) the output buffer and turn off output buffering - ob_end_flush(); + // Open a socket to xcatd + syslog(LOG_INFO, "Opening socket to xcatd..."); + if ($fp = stream_socket_client('ssl://'.$xcathost.':'.$port, $errno, $errstr, 30, STREAM_CLIENT_CONNECT)){ + $reqXML = $req->asXML(); + $nr = $req->noderange; + $cmd = $req->command; + + syslog(LOG_INFO, "Sending request: $cmd $nr"); + stream_set_blocking($fp, 0); // Set as non-blocking + fwrite($fp,$req->asXML()); // Send XML to xcatd + set_time_limit(900); // Set 15 minutes timeout (for long running requests) + // The default is 30 seconds which is too short for some requests + + // Turn on output buffering + ob_start(); + while(!feof($fp)) { // Read until there is no more + // Remove newlines and add it to the response + $str = fread($fp, 8192); + if ($str) { + $response .= preg_replace('/>\n\s*<', $str); + + // Flush output to browser + if ($flush) { + // Strip HTML tags from output + if ($tmp = trim(strip_tags($str))) { + // Format the output based on what was given for $flush_format + if ($flush_format == "TDB") { + format_TBD($tmp); + } else { + // Print out output by default + echo '
    ' . $tmp . '
    '; + ob_flush(); + flush(); + } + } + } + } + + // Look for serverdone response + $fullpattern = '/\s*\s*<\/serverdone>\s*<\/xcatresponse>/'; + $mixedpattern = '/\s*<\/serverdone>.*<\/xcatresponse>/'; + $recentpattern = '/<\/xcatresponse>/'; + if(preg_match($recentpattern,$str) && preg_match($mixedpattern,$response)) { + // Transaction is done, package up XML and return it + // Remove the serverdone response and put an xcat tag around the rest + $count = 0; + $response = preg_replace($fullpattern,'', $response, -1, $count); // 1st try to remove the long pattern + if (!$count) { $response = preg_replace($mixedpattern,'', $response) . '/'; } + $response = "$response"; + $response = preg_replace('/>\n\s*<', $response); + $response = preg_replace('/\n/', ':|:', $response); + $rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA); + $cleanexit = 1; + break; + } + } // End of while(!feof($fp)) + + syslog(LOG_INFO, "($cmd $nr) Sending response"); + fclose($fp); + } else { + echo "

    xCAT submit request socket error: $errno - $errstr

    "; + } + + // Flush (send) the output buffer and turn off output buffering + ob_end_flush(); - // Close syslog - closelog(); - - if(! $cleanexit) { - if (preg_match('/^\s*.*<\/xcatresponse>\s*$/',$response)) { - // Probably an error message - $response = "$response"; - $rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA); - } - elseif(!$skipVerify) { - echo "

    (Error) xCAT response ended prematurely: ", htmlentities($response), "

    "; - $rsp = FALSE; - } - } - return $rsp; + // Close syslog + closelog(); + + if(! $cleanexit) { + if (preg_match('/^\s*.*<\/xcatresponse>\s*$/',$response)) { + // Probably an error message + $response = "$response"; + $rsp = simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOCDATA); + } else if (!$skipVerify) { + echo "

    (Error) xCAT response ended prematurely: ", htmlentities($response), "

    "; + $rsp = FALSE; + } + } + return $rsp; } /** * Enable password storage to split between cookie and session variable - * - * @param $data - * @param $key - * @return */ function xorcrypt($data, $key) { - $datalen = strlen($data); - $keylen = strlen($key); - for ($i=0;$i<$datalen;$i++) { - $data[$i] = chr(ord($data[$i])^ord($key[$i])); - } + $datalen = strlen($data); + $keylen = strlen($key); + for ($i=0;$i<$datalen;$i++) { + $data[$i] = chr(ord($data[$i])^ord($key[$i])); + } - return $data; + return $data; } /** * Get RAND characters * - * @param $length Length of characters - * @return RAND characters + * @param $length Length of characters + * @return RAND characters */ function getrandchars($length) { - $charset = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*'; - $charsize = strlen($charset); - srand(); - $chars = ''; - for ($i=0;$i<$length;$i++) { - $num=rand()%$charsize; - $chars=$chars.substr($charset,$num,1); - } + $charset = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*'; + $charsize = strlen($charset); + srand(); + $chars = ''; + for ($i=0;$i<$length;$i++) { + $num=rand()%$charsize; + $chars=$chars.substr($charset,$num,1); + } - return $chars; + return $chars; } /** * Format a given string and echo it back to the browser - * - * @param $str String - * @return Nothing */ function format_TBD($str) { - // Format a given string however you want it - echo $tmp . '
    '; - flush(); + // Format a given string however you want it + echo $tmp . '
    '; + flush(); } /** * Get password - * - * @param Nothing - * @return */ function getpassword() { - if (isset($GLOBALS['xcatauthsecret'])) { - $cryptext = $GLOBALS['xcatauthsecret']; - } else if (isset($_COOKIE["xcatauthsecret"])) { - $cryptext = $_COOKIE["xcatauthsecret"]; - } else { - return false; - } + if (isset($GLOBALS['xcatauthsecret'])) { + $cryptext = $GLOBALS['xcatauthsecret']; + } else if (isset($_COOKIE["xcatauthsecret"])) { + $cryptext = $_COOKIE["xcatauthsecret"]; + } else { + return false; + } - return xorcrypt($_SESSION["secretkey"], base64_decode($cryptext)); + return xorcrypt($_SESSION["secretkey"], base64_decode($cryptext)); } /** - * Get the password splitting knowledge between server - * and client side persistant storage. Caller should regenerate - * session ID when contemplating a new user/password, to preclude - * session fixation, though fixation is limited without the secret. + * Get the password splitting knowledge between server and client side persistant storage. + * Caller should regenerate session ID when contemplating a new user/password, + * to preclude session fixation, though fixation is limited without the secret. * - * @param $password Password - * @return Nothing + * @param $password Password */ function setpassword($password) { - $randlen = strlen($password); - $key = getrandchars($randlen); - $cryptext = xorcrypt($password,$key); + $randlen = strlen($password); + $key = getrandchars($randlen); + $cryptext = xorcrypt($password,$key); - // Non-ascii characters, encode it in base64 - $cryptext = base64_encode($cryptext); - setcookie("xcatauthsecret",$cryptext,0,'/'); - $GLOBALS["xcatauthsecret"] = $cryptext; - $_SESSION["secretkey"] = $key; + // Non-ascii characters, encode it in base64 + $cryptext = base64_encode($cryptext); + setcookie("xcatauthsecret",$cryptext,0,'/'); + $GLOBALS["xcatauthsecret"] = $cryptext; + $_SESSION["secretkey"] = $key; } /** * Determine if a user/password session exists * - * @param Nothing - * @return True If user has a session. - * False Otherwise + * @return True if user has a session, false otherwise */ function is_logged() { - if (isset($_SESSION["srv_username"]) and !is_bool(getpassword())) { - return true; - } else { - return false; - } + if (isset($_SESSION["srv_username"]) and !is_bool(getpassword())) { + return true; + } else { + return false; + } } /** * Determine if a user is currently logged in successfully - * - * @param Nothing - * @return True If the user is currently logged in successfully - * False Otherwise + * + * @return True if the user is currently logged in successfully, false otherwise */ function isAuthenticated() { - if (is_logged()) { - if ($_SESSION["srv_xcatpassvalid"] != 1) { - $testcred = docmd("authcheck", "", NULL, NULL); - if (isset($testcred->{'xcatresponse'}->{'data'})) { - $result = "".$testcred->{'xcatresponse'}->{'data'}; - if (is_numeric(strpos("Authenticated",$result))) { - // Logged in successfully - $_SESSION["srv_xcatpassvalid"] = 1; - } else { - // Not logged in - $_SESSION["srv_xcatpassvalid"] = 0; - } - } - } - } + if (is_logged()) { + if ($_SESSION["srv_xcatpassvalid"] != 1) { + $testcred = docmd("authcheck", "", NULL, NULL); + if (isset($testcred->{'xcatresponse'}->{'data'})) { + $result = "".$testcred->{'xcatresponse'}->{'data'}; + if (is_numeric(strpos("Authenticated",$result))) { + // Logged in successfully + $_SESSION["srv_xcatpassvalid"] = 1; + } else { + // Not logged in + $_SESSION["srv_xcatpassvalid"] = 0; + } + } + } + } - if (isset($_SESSION["srv_xcatpassvalid"]) and $_SESSION["srv_xcatpassvalid"]==1) { - return true; - } else { - return false; - } + if (isset($_SESSION["srv_xcatpassvalid"]) and $_SESSION["srv_xcatpassvalid"]==1) { + return true; + } else { + return false; + } } /** * Log out of the current user session - * - * @param Nothing - * @return Nothing */ function logout() { - // Clear the secret cookie from browser - if (isset($_COOKIE["xcatauthsecret"])) { - setcookie("xcatauthsecret",'',time()-86400*7,'/'); - } + // Clear the secret cookie from browser + if (isset($_COOKIE["xcatauthsecret"])) { + setcookie("xcatauthsecret",'',time()-86400*7,'/'); + } - // Expire session cookie - if (isset($_COOKIE[session_name()])) { - setcookie(session_name(),"",time()-86400*7,"/"); - } + // Expire session cookie + if (isset($_COOKIE[session_name()])) { + setcookie(session_name(),"",time()-86400*7,"/"); + } - // Clear server store of data - $_SESSION=array(); + // Clear server store of data + $_SESSION=array(); } ?> diff --git a/xCAT-UI/lib/srv_log.php b/xCAT-UI/lib/srv_log.php index 5a9f3bccc..31106b9aa 100644 --- a/xCAT-UI/lib/srv_log.php +++ b/xCAT-UI/lib/srv_log.php @@ -11,29 +11,29 @@ header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); if (isset($_REQUEST["password"])) { - // Clear data from session - $_SESSION = array(); + // Clear data from session + $_SESSION = array(); - // Zap existing session entirely - session_regenerate_id(true); - setpassword($_REQUEST["password"]); + // Zap existing session entirely + session_regenerate_id(true); + setpassword($_REQUEST["password"]); - // Invalid password - $_SESSION["srv_xcatpassvalid"] = -1; + // Invalid password + $_SESSION["srv_xcatpassvalid"] = -1; } if (isset($_REQUEST["username"])) { - $_SESSION["srv_username"] = $_REQUEST["username"]; + $_SESSION["srv_username"] = $_REQUEST["username"]; - // Invalid user name - $_SESSION["srv_xcatpassvalid"]=-1; + // Invalid user name + $_SESSION["srv_xcatpassvalid"]=-1; } $jdata = array(); if (isAuthenticated()) { - $jdata["authenticated"]="yes"; + $jdata["authenticated"]="yes"; } else { - $jdata["authenticated"]="no"; + $jdata["authenticated"]="no"; } echo json_encode($jdata); diff --git a/xCAT-UI/lib/systemcmd.php b/xCAT-UI/lib/systemcmd.php index 469551789..7990aa035 100644 --- a/xCAT-UI/lib/systemcmd.php +++ b/xCAT-UI/lib/systemcmd.php @@ -7,30 +7,30 @@ require_once "$TOPDIR/lib/jsonwrapper.php"; /** * This will handle system commands, e.g. rpm -qa xCAT * - * @param $cmd The system command - * @return The system response. Replies are in the form of JSON + * @param $cmd The system command + * @return The system response. Replies are in the form of JSON */ if (!isAuthenticated()) { - echo ("Please login before continuing!"); - exit; + echo ("Please login before continuing!"); + exit; } if (isset($_GET["cmd"])) { - // HTTP GET requests - $cmd = $_GET["cmd"]; - $msg = NULL; - $ret = ""; + // HTTP GET requests + $cmd = $_GET["cmd"]; + $msg = NULL; + $ret = ""; - if (isset($_GET["msg"])) { - $msg = $_GET["msg"]; - } - - if ($cmd == "ostype") { - $ret = strtolower(PHP_OS); - } else { - $ret = shell_exec($cmd); - } + if (isset($_GET["msg"])) { + $msg = $_GET["msg"]; + } + + if ($cmd == "ostype") { + $ret = strtolower(PHP_OS); + } else { + $ret = shell_exec($cmd); + } - echo json_encode(array("rsp"=>$ret, "msg" => $msg)); + echo json_encode(array("rsp"=>$ret, "msg" => $msg)); } ?> \ No newline at end of file diff --git a/xCAT-UI/lib/tabRestore.php b/xCAT-UI/lib/tabRestore.php index 79fafd6b8..4d3e960dc 100644 --- a/xCAT-UI/lib/tabRestore.php +++ b/xCAT-UI/lib/tabRestore.php @@ -7,8 +7,8 @@ require_once "$TOPDIR/lib/jsonwrapper.php"; /** * Replace the contents of an xCAT table * - * @param $tab The xCAT table - * @param $cont The xCAT table contents + * @param $tab The xCAT table + * @param $cont The xCAT table contents * @return The xCAT response. Replies are in the form of JSON */ if (isset($_POST["table"])) { @@ -24,7 +24,7 @@ $request = simplexml_load_string(''); $request->addChild('command', 'tabrestore'); // Setup authentication -$usernode=$request->addChild('becomeuser'); +$usernode = $request->addChild('becomeuser'); $usernode->addChild('username', $_SESSION["username"]); $usernode->addChild('password', getpassword()); @@ -43,7 +43,7 @@ foreach($cont as $line){ } // Go through each column - foreach($line as &$col){ + foreach ($line as &$col){ // If the column does begins and end with a quote // Change quotes to " if(!empty($col) && !preg_match('/^".*"$/', $col)) { @@ -55,9 +55,11 @@ foreach($cont as $line){ ksort($line, SORT_NUMERIC); $keys = array_keys($line); $max = count($line) - 1; - if($keys[$max] != $max){ + if ($keys[$max] != $max){ for ($i = 0; $i <= $keys[$max]; $i++) { - if (!isset($line[$i])) {$line[$i]='';} + if (!isset($line[$i])) { + $line[$i]=''; + } } ksort($line, SORT_NUMERIC); } diff --git a/xCAT-UI/lib/ui.php b/xCAT-UI/lib/ui.php index 163785eb8..c45b83a26 100644 --- a/xCAT-UI/lib/ui.php +++ b/xCAT-UI/lib/ui.php @@ -1,96 +1,87 @@ - - xCAT - - - - - - - '; + // Include CSS and Javascripts + echo + ' + + xCAT + + + + + + + '; - // Header menu - echo - ' - '; + // Content + echo '
    '; - // End of page - echo - ' - '; + // End of page + echo + ' + '; } /** * Load page content - * - * @param Nothing - * @return Nothing */ function loadContent() { - // Initialize page - echo - ''; + // Initialize page + echo + ''; } /** * Login user into a new session - * - * @param Nothing - * @return Nothing */ function login() { - // xcatauth.js will open a dialog box - // asking for the user name and password - echo - ' - -
    -
    - - - - - - - - -
    eXtreme Cloud Administration Toolkit
    -
    -
    Open Source. EPL License.
    -
    '; + // xcatauth.js will open a dialog box + // asking for the user name and password + echo + ' + +
    +
    + + + + + + + + +
    eXtreme Cloud Administration Toolkit
    +
    +
    Open Source. EPL License.
    +
    '; } ?> \ No newline at end of file diff --git a/xCAT-UI/lib/upload.php b/xCAT-UI/lib/upload.php index 2f33fc940..983fa30a1 100644 --- a/xCAT-UI/lib/upload.php +++ b/xCAT-UI/lib/upload.php @@ -4,26 +4,26 @@ */ $type = $_FILES["file"]["type"]; if ($type == "text/plain" || $type == "application/octet-stream" || $type == "application/x-shellscript" || $type == "application/x-sh") { - $error = $_FILES["file"]["error"]; - if ($error) { - echo "Return Code: " . $error; - } else { - $file = $_FILES["file"]["name"]; - $path = "/var/tmp/" . $file; - move_uploaded_file($_FILES["file"]["tmp_name"], $path); + $error = $_FILES["file"]["error"]; + if ($error) { + echo "Return Code: " . $error; + } else { + $file = $_FILES["file"]["name"]; + $path = "/var/tmp/" . $file; + move_uploaded_file($_FILES["file"]["tmp_name"], $path); - // Open and read given file - $handler = fopen($path, "r"); - $data = fread($handler, filesize($path)); - fclose($handler); + // Open and read given file + $handler = fopen($path, "r"); + $data = fread($handler, filesize($path)); + fclose($handler); - // Print out file contents - echo $data; + // Print out file contents + echo $data; - // Remove this file - unlink($path); - } + // Remove this file + unlink($path); + } } else { - echo "(Error) File type $type not supported"; + echo "(Error) File type $type not supported"; } ?> \ No newline at end of file diff --git a/xCAT-UI/lib/zCmd.php b/xCAT-UI/lib/zCmd.php index 24c6dcf32..706248268 100644 --- a/xCAT-UI/lib/zCmd.php +++ b/xCAT-UI/lib/zCmd.php @@ -7,9 +7,9 @@ require_once "$TOPDIR/lib/jsonwrapper.php"; /** * Issue an xCAT command (only for z) * - * @param $cmd The xCAT command - * @param $tgt The target node or group - * @param $args The xCAT command arguments, separated by semicolons + * @param $cmd The xCAT command + * @param $tgt The target node or group + * @param $args The xCAT command arguments, separated by semicolons * @return The xCAT response. Replies are in the form of JSON */ if (isset($_GET["cmd"])) { @@ -56,7 +56,7 @@ if (isset($_GET["cmd"])) { $rsp = array(); // Replace user entry - if(strncasecmp($cmd, "chvm", 4) == 0 && strncasecmp($arr[0], "--replacevs", 11) == 0) { + if (strncasecmp($cmd, "chvm", 4) == 0 && strncasecmp($arr[0], "--replacevs", 11) == 0) { // Directory /var/tmp permissions = 777 // You can write anything to that directory $userEntry = "/var/tmp/$tgt.txt"; @@ -77,7 +77,7 @@ if (isset($_GET["cmd"])) { } // Create virtual server - else if(strncasecmp($cmd, "mkvm", 4) == 0) { + else if (strncasecmp($cmd, "mkvm", 4) == 0) { // Directory /var/tmp permissions = 777 // You can write anything to that directory $userEntry = "/var/tmp/$tgt.txt"; diff --git a/xCAT-UI/monitor.php b/xCAT-UI/monitor.php index db1637792..29010ad74 100644 --- a/xCAT-UI/monitor.php +++ b/xCAT-UI/monitor.php @@ -10,8 +10,8 @@ loadPage(); /* Login user */ if (!isAuthenticated()) { - login(); + login(); } else { - loadContent(); + loadContent(); } ?> \ No newline at end of file diff --git a/xCAT-UI/provision.php b/xCAT-UI/provision.php index 8e12c5609..ef494bee5 100644 --- a/xCAT-UI/provision.php +++ b/xCAT-UI/provision.php @@ -10,8 +10,8 @@ loadPage(); /* Login user */ if (!isAuthenticated()) { - login(); + login(); } else { - loadContent(); + loadContent(); } ?> \ No newline at end of file diff --git a/xCAT-UI/rcons.php b/xCAT-UI/rcons.php index 67877ba02..a18102ff4 100644 --- a/xCAT-UI/rcons.php +++ b/xCAT-UI/rcons.php @@ -1,21 +1,21 @@ - - {$_GET['rconsnd']} - - - - - - - -
    - + + {$_GET['rconsnd']} + + + + + + + +
    + EEE; ?> diff --git a/xCAT-UI/service.php b/xCAT-UI/service.php index 972ce6428..558d39f85 100644 --- a/xCAT-UI/service.php +++ b/xCAT-UI/service.php @@ -12,30 +12,30 @@ require_once "lib/jsonwrapper.php"; // Include CSS and Javascripts echo ' - - xCAT Service Portal - - - - - - - - '; + + xCAT Service Portal + + + + + + + + '; // Create header menu echo ' -