function AJcompStateChange() { $newstateid = processInputVar('stateid', ARG_NUMERIC); $states = getContinuationVar('states'); if (!array_key_exists($newstateid, $states)) { $ret = array('status' => 'noaction'); sendJSON($ret); return; } $cdata = $this->basecdata; $cdata['newstateid'] = $newstateid; $tmp = getUserResources(array($this->restype . "Admin"), array("administer"), 0, 1); $computers = $tmp['computer']; $msg = ''; $complist = ''; $compids = $this->validateCompIDs(); if ($newstateid == 2) { $msg .= "You are about to place the following computers into the "; $msg .= "available state:<br><br>\n"; foreach ($compids as $compid) { $complist .= $computers[$compid] . "<br>\n"; } $complist .= "<br>\n"; $cdata['compids'] = $compids; } elseif ($newstateid == 10) { $msg .= "Please enter a reason you are changing the following computers to "; $msg .= "the maintenance state:<br><br>\n"; $msg .= "<textarea "; $msg .= "dojoType=\"dijit.form.Textarea\" "; $msg .= "style=\"width: 30em; text-align: left;\" "; $msg .= "_destroyOnRemove=\"true\" "; $msg .= "id=\"utilnotes\">"; $msg .= "</textarea><br><br>\n"; $msg .= "These computers will be placed into the maintenance state:<br><br>\n"; foreach ($compids as $compid) { $complist .= $computers[$compid] . "<br>\n"; } $complist .= "<br>\n"; $cdata['compids'] = $compids; } elseif ($newstateid == 20) { $profiles = getVMProfiles(); $cdata['profiles'] = $profiles; $msg .= "Select a VM Host Profile to use on the selected computers:"; $msg .= "<br><br>\n"; $msg .= selectInputAutoDijitHTML('', $profiles, 'profileid'); $msg .= "<br><br>\n"; $msg .= "These computers will be deployed as VM Hosts:<br><br>\n"; foreach ($compids as $compid) { $complist .= $computers[$compid] . "<br>\n"; } $complist .= "<br>\n"; $cdata['compids'] = $compids; } elseif ($newstateid == 23) { $msg .= "These computers will be placed into the hpc state:<br><br>\n"; foreach ($compids as $compid) { $complist .= $computers[$compid] . "<br>\n"; } $complist .= "<br>\n"; $cdata['compids'] = $compids; } $cont = addContinuationsEntry('AJsubmitCompStateChange', $cdata, SECINDAY, 1, 0); $ret = array('status' => 'success', 'title' => "State Change", 'btntxt' => 'Submit State Change', 'cont' => $cont, 'actionmsg' => $msg, 'complist' => $complist); sendJSON($ret); }
function AJupdateVMprofileItem() { if (!checkUserHasPerm('Manage VM Profiles')) { print "alert('You do not have access to manage this vm profile.');"; return; } $profileid = processInputVar('profileid', ARG_NUMERIC); $item = processInputVar('item', ARG_STRING); if (!preg_match('/^(profilename|imageid|resourcepath|folderpath|repositorypath|repositoryimagetypeid|datastorepath|datastoreimagetypeid|vmdisk|vmpath|virtualswitch[0-3]|username|password|eth0generated|eth1generated|rsakey|rsapub)$/', $item)) { print "alert('Invalid data submitted.');"; return; } if (preg_match('/^eth[01]generated$/', $item)) { $newvalue = processInputVar('newvalue', ARG_NUMERIC); if ($newvalue != 0 && $newvalue != 1) { $newvalue = 0; } } elseif (preg_match('/imagetypeid$/', $item)) { $newvalue = processInputVar('newvalue', ARG_STRING); $imagetypes = getImageTypes(); if (!array_key_exists($newvalue, $imagetypes)) { $newvalue = 1; } } elseif ($item == 'vmdisk') { $newvalue = processInputVar('newvalue', ARG_STRING); $vmdisks = getENUMvalues('vmprofile', 'vmdisk'); if (!in_array($newvalue, $vmdisks)) { $newvalue = $vmdisks[0]; } } elseif ($item == 'password') { $newvalue = $_POST['newvalue']; } else { $newvalue = processInputVar('newvalue', ARG_STRING); } if ($newvalue == '') { $newvalue2 = 'NULL'; } else { if (get_magic_quotes_gpc()) { $newvalue = stripslashes($newvalue); } $newvalue2 = mysql_real_escape_string($newvalue); $newvalue2 = "'{$newvalue2}'"; } $item = mysql_real_escape_string($item); $profile = getVMProfiles($profileid); if ($item == 'password' && $profile[$profileid]['rsapub']) { $encrypted = encryptDataAsymmetric($newvalue, $profile[$profileid]['rsapub']); $escaped = mysql_real_escape_string($encrypted); $query = "UPDATE vmprofile " . "SET `encryptedpasswd` = '{$escaped}' " . "WHERE id = {$profileid}"; doQuery($query, 101); # don't store the unencrypted password $newvalue2 = 'NULL'; $newvalue = ''; } else { if ($profile[$profileid][$item] == $newvalue) { return; } } $query = "UPDATE vmprofile " . "SET `{$item}` = {$newvalue2} " . "WHERE id = {$profileid}"; doQuery($query, 101); if ($item == 'password') { print "document.getElementById('savestatus').innerHTML = 'Saved'; "; print "setTimeout(function() {document.getElementById('savestatus').innerHTML = '';}, 3000); "; } $newvalue = preg_replace("/'/", "\\'", $newvalue); print "curprofile.{$item} = '{$newvalue}';"; }
function AJupdateVMprofileItem() { global $viewmode; if ($viewmode != ADMIN_DEVELOPER) { print "alert('You do not have access to manage this vm profile.');"; return; } $profileid = processInputVar('profileid', ARG_NUMERIC); $item = processInputVar('item', ARG_STRING); if ($item == 'password') { $newvalue = $_POST['newvalue']; } else { $newvalue = processInputVar('newvalue', ARG_STRING); } if ($newvalue == '') { $newvalue2 = 'NULL'; } else { if (get_magic_quotes_gpc()) { $newvalue = stripslashes($newvalue); } $newvalue2 = mysql_escape_string($newvalue); $newvalue2 = "'{$newvalue2}'"; } $profile = getVMProfiles($profileid); if ($profile[$profileid][$item] == $newvalue) { return; } $query = "UPDATE vmprofile " . "SET `{$item}` = {$newvalue2} " . "WHERE id = {$profileid}"; doQuery($query, 101); if ($item == 'password') { print "document.getElementById('savestatus').innerHTML = 'Saved'; "; print "setTimeout(function() {document.getElementById('savestatus').innerHTML = '';}, 3000); "; } $newvalue = preg_replace("/'/", "\\'", $newvalue); print "curprofile.{$item} = '{$newvalue}';"; }
function compStateChange() { global $submitErr; print "<H2>Change State of Computers</H2>\n"; $data = processComputerInput3(); $computers = getComputers(1); if ($data['stateid'] == 10) { $notes = explode('@', $data['notes']); if (count($notes) != 2) { $notes[1] = ""; } } if ($data['stateid'] == 2) { print "You are about to place the following computers into the "; print "available state:\n"; print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; } elseif ($data['stateid'] == 10) { print "Please enter a reason you are changing the following computers to "; print "the maintenance state:<br><br>\n"; print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; print "<TEXTAREA name=notes rows=4 cols=35>{$notes[1]}</TEXTAREA><br>\n"; print "<br>Selected computers:\n"; } elseif ($data['stateid'] == 20) { $profiles = getVMProfiles(); $data['profiles'] = $profiles; print "Select a VM Host Profile and then click <strong>Submit</strong>\n"; print "to place the computers into the vmhostinuse state:<br><br>\n"; print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; printSelectInput('profileid', $profiles); print "<br><br>\n"; } elseif ($data['stateid'] == 23) { print "You are about to place the following computers into the "; print "hpc state:\n"; print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n"; } $cont = addContinuationsEntry('submitCompStateChange', $data, SECINDAY, 0, 0); print " <INPUT type=hidden name=continuation value=\"{$cont}\">\n"; print "<TABLE>\n"; foreach ($data['computerids'] as $compid) { print " <TR>\n"; #print " <TD><font color=\"#008000\">{$computers[$compid]['hostname']}</font></TD>\n"; print " <TD>{$computers[$compid]['hostname']}</TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "<br>\n"; print "<INPUT type=submit value=Submit>\n"; print "</FORM>\n"; }