示例#1
0
function processRequestInput()
{
    global $user;
    $baseaccess = getContinuationVar('baseaccess', 0);
    $imagingaccess = getContinuationVar('imagingaccess', 0);
    $serveraccess = getContinuationVar('serveraccess', 0);
    $openend = getContinuationVar('openend', 0);
    $nousercheck = getContinuationVar('nousercheck', 0);
    $return['imaging'] = getContinuationVar('imaging', 0);
    $maxinitial = getContinuationVar('maxinitial', 0);
    $noimaging = getContinuationVar('noimaging', array());
    $return = array('err' => 0);
    # type
    $return['type'] = processInputVar('type', ARG_STRING);
    if (!preg_match('/^basic|imaging|server$/', $return['type'])) {
        $return['err'] = 1;
        $return['errmsg'] = i('Invalid data submitted');
        return $return;
    }
    if ($return['type'] == 'basic' && !$baseaccess || $return['type'] == 'imaging' && !$imagingaccess || $return['type'] == 'server' && !$serveraccess) {
        $return['err'] = 1;
        $return['errmsg'] = i('No access to submitted reservation type');
        return $return;
    }
    # ending
    $return['ending'] = processInputVar('ending', ARG_STRING);
    if (!preg_match('/^indefinite|endat|duration$/', $return['ending'])) {
        $return['err'] = 1;
        $return['errmsg'] = i('Invalid data submitted');
        return $return;
    }
    if ($return['ending'] == 'duration' && !$baseaccess || $return['ending'] == 'indefinite' && !$serveraccess || $return['ending'] == 'endat' && !$openend && !$serveraccess) {
        $return['err'] = 1;
        $return['errmsg'] = i('No access to submitted end type');
        return $return;
    }
    # imageid
    $return['imageid'] = processInputVar('imageid', ARG_NUMERIC);
    $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
    $withnocheckout = $resources['image'];
    $images = removeNoCheckout($resources["image"]);
    $extraimages = getServerProfileImages($user['id']);
    if (!array_key_exists($return['imageid'], $images) && ($return['type'] != 'server' || !array_key_exists($return['imageid'], $extraimages)) && ($return['type'] != 'imaging' || !array_key_exists($return['imageid'], $withnocheckout)) || $return['type'] == 'imaging' && array_key_exists($return['imageid'], $noimaging)) {
        $return['err'] = 1;
        $return['errmsg'] = i('No access to submitted environment');
        return $return;
    }
    # nousercheck
    $return['nousercheck'] = processInputVar('nousercheck', ARG_NUMERIC);
    if (!$nousercheck || $return['nousercheck'] != 1) {
        $return['nousercheck'] = 0;
    }
    # revisionid
    $revids = processInputVar("revisionid", ARG_STRING);
    $revids = explode(':', $revids);
    $images = getImages(0, $return['imageid']);
    $return['revisionids'] = array();
    if (array_key_exists('subimages', $images[$return['imageid']])) {
        $subimages = $images[$return['imageid']]['subimages'];
        array_unshift($subimages, $return['imageid']);
        foreach ($subimages as $key => $imgid) {
            $revisions = getImageRevisions($imgid);
            if (!array_key_exists($key, $revids) || !is_numeric($revids[$key]) || !array_key_exists($revids[$key], $revisions)) {
                $revid = getProductionRevisionid($imgid);
            } else {
                $revid = $revids[$key];
            }
            if (!array_key_exists($imgid, $return['revisionids'])) {
                $return['revisionids'][$imgid] = array();
            }
            $return['revisionids'][$imgid][] = $revid;
        }
    } elseif ($revids[0] != '' && is_numeric($revids[0])) {
        $return['revisionids'][$return['imageid']][] = $revids[0];
    } else {
        $return['revisionids'][$return['imageid']][] = getProductionRevisionid($return['imageid']);
    }
    # duration
    if ($return['ending'] == 'duration') {
        $return['duration'] = processInputVar('duration', ARG_NUMERIC, 0);
        if ($return['duration'] > $maxinitial) {
            $return['duration'] = $maxinitial;
        }
    }
    # start/end
    $return['start'] = processInputVar('start', ARG_NUMERIC);
    $return['end'] = processInputVar('end', ARG_NUMERIC, 0);
    $now = time();
    if ($return['start'] == 0) {
        $start = $now;
    } else {
        $start = $return['start'];
    }
    if ($return['ending'] == 'endat') {
        $end = $return['end'];
    }
    if ($return['ending'] == 'indefinite') {
        $end = datetimeToUnix('2038-01-01 00:00:00');
    } elseif ($return['ending'] == 'duration') {
        $end = $start + $return['duration'] * 60;
    }
    if ($start < $now) {
        $return['err'] = 1;
        $return['errmsg'] = i('The submitted start time is in the past.');
        return $return;
    }
    if ($start + 900 > $end) {
        $return['err'] = 1;
        $return['errmsg'] = i('The end time must be at least 15 minutes later than the start time.');
        return $return;
    }
    $return['ipaddr'] = '';
    $return['macaddr'] = '';
    # server specific input
    if ($return['type'] == 'server') {
        # name
        $return['name'] = processInputVar('name', ARG_STRING);
        if (!preg_match('/^([-a-zA-Z0-9_\\. ]){0,255}$/', $return['name'])) {
            $return['err'] = 1;
            $return['errmsg'] = i('The reservation name can only contain letters, numbers, spaces, dashes(-), underscores(_), and periods(.) and can be up to 255 characters long');
            return $return;
        }
        # ipaddr
        $return['ipaddr'] = processInputVar('ipaddr', ARG_STRING);
        if ($return['ipaddr'] != '') {
            # validate fixed IP address
            if (!validateIPv4addr($return['ipaddr'])) {
                $return['err'] = 1;
                $return['errmsg'] = i('Invalid IP address. Must be w.x.y.z with each of w, x, y, and z being between 1 and 255 (inclusive)');
                return $return;
            }
            # validate netmask
            $return['netmask'] = processInputVar('netmask', ARG_STRING);
            $bnetmask = ip2long($return['netmask']);
            if (!preg_match('/^[1]+0[^1]+$/', sprintf('%032b', $bnetmask))) {
                $return['err'] = 1;
                $return['errmsg'] = i('Invalid netmask specified');
                return $return;
            }
            # validate router
            $return['router'] = processInputVar('router', ARG_STRING);
            if (!validateIPv4addr($return['router'])) {
                $return['err'] = 1;
                $return['errmsg'] = i('Invalid router address. Must be w.x.y.z with each of w, x, y, and z being between 1 and 255 (inclusive)');
                return $return;
            }
            $return['network'] = ip2long($return['ipaddr']) & $bnetmask;
            if ($return['network'] != (ip2long($return['router']) & $bnetmask)) {
                $return['err'] = 1;
                $return['errmsg'] = i('IP address and router are not on the same subnet based on the specified netmask.');
                return $return;
            }
            # validate dns server(s)
            $dns = processInputVar('dns', ARG_STRING);
            $tmp = explode(',', $dns);
            $cnt = 0;
            $return['dnsArr'] = array();
            foreach ($tmp as $dnsaddr) {
                if ($cnt && $dnsaddr == '') {
                    continue;
                }
                if ($cnt == 3) {
                    $return['err'] = 1;
                    $return['errmsg'] = i('Too many DNS servers specified - up to 3 are allowed.');
                    return $return;
                }
                if (!validateIPv4addr($dnsaddr)) {
                    $return['err'] = 1;
                    $return['errmsg'] = i('Invalid DNS server specified.');
                    return $return;
                }
                $return['dnsArr'][] = $dnsaddr;
                $cnt++;
            }
            # check that a management node can handle the network
            $mappedmns = getMnsFromImage($return['imageid']);
            $mnnets = checkAvailableNetworks($return['ipaddr']);
            $intersect = array_intersect($mappedmns, $mnnets);
            if (empty($intersect)) {
                $return['err'] = 1;
                $return['errmsg'] = i('There are no management nodes that can deploy the selected image with the specified IP address.');
                return $return;
            }
        }
        # macaddr
        $return['macaddr'] = processInputVar('macaddr', ARG_STRING);
        if ($return['macaddr'] != '' && !preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return['macaddr'])) {
            $return['err'] = 1;
            $return['errmsg'] = i('Invalid MAC address. Must be XX:XX:XX:XX:XX:XX with each pair of XX being from 00 to FF (inclusive)');
            return $return;
        }
        # profileid
        $return['profileid'] = processInputVar('profileid', ARG_NUMERIC, 0);
        $resources = getUserResources(array("serverCheckOut", "serverProfileAdmin"), array("available", "administer"));
        if (!array_key_exists($return['profileid'], $resources['serverprofile'])) {
            $return['profileid'] = 0;
        } elseif ($return['profileid'] != 0) {
            $tmp = getServerProfiles($return['profileid']);
            $tmp = $tmp[$return['profileid']];
            if ($tmp['imageid'] != $return['imageid'] && ($tmp['fixedIP'] != $return['ipaddr'] && $tmp['fixedMAC'] != $return['macaddr'] || $tmp['fixedIP'] == $return['ipaddr'] && $return['ipaddr'] == '' && $tmp['fixedMAC'] == $return['macaddr'] && $return['macaddr'] == '')) {
                $return['profileid'] = 0;
            }
        }
        # admingroupid
        $usergroups = getUserGroups();
        $return['admingroupid'] = processInputVar('admingroupid', ARG_NUMERIC);
        if ($return['admingroupid'] != 0 && !array_key_exists($return['admingroupid'], $usergroups)) {
            $return['err'] = 1;
            $return['errmsg'] = i('You do not have access to use the specified admin user group.');
            return $return;
        }
        # logingroupid
        $return['logingroupid'] = processInputVar('logingroupid', ARG_NUMERIC);
        if ($return['logingroupid'] != 0 && !array_key_exists($return['logingroupid'], $usergroups)) {
            $return['err'] = 1;
            $return['errmsg'] = i('You do not have access to use the specified access user group.');
            return $return;
        }
        # monitored
        $return['monitored'] = processInputVar('monitored', ARG_NUMERIC, 0);
        if ($return['monitored'] != 0 && $return['monitored'] != 1) {
            $return['monitored'] = 0;
        }
        # configs
        # TODO configs
        /*$tmp = getUserResources(array("configAdmin"));
        		$userconfigs = $tmp['config'];
        		$initconfigs = getMappedConfigs($return['imageid']);
        		if(array_key_exists('configdata', $_POST)) {
        			if(get_magic_quotes_gpc())
        				$_POST['configdata'] = stripslashes($_POST['configdata']);
        			$configdata = json_decode($_POST['configdata']);
        		}
        		if(array_key_exists('configdata', $_POST) &&
        			isset($configdata->configs))
        			$configs = $configdata->configs;
        		else
        			$configs = (object)array();
        		$return['configs'] = array();
        		foreach($initconfigs as $id => $config) {
        			if(isset($configs->{$id}) &&
        				isset($configs->{$id}->applied) &&
        			   $configs->{$config['id']}->applied != 'true' &&
        				$configs->{$config['id']}->applied != 'false')
        				unset($configs->{$config['id']});
        			if($config['optional'] &&
        			   (! isset($configs->{$id}) ||
        			   ! $configs->{$id}->applied))
        				continue;
        			$return['configs'][$id] = array('configid' => $config['configid'],
        			                                'configmapid' => $config['configmapid'],
        			                                'imageid' => $config['subimageid']);
        			if(isset($configs->{$id}))
        				unset($configs->{$id});
        		}
        		$rescfgmapids = array();
        		foreach($configs as $id => $config) {
        			if(! array_key_exists($config->configid, $userconfigs))
        				continue;
        			$return['configs'][$id] = array('configid' => $config->configid,
        			                                'configstageid' => $config->configstageid,
        			                                'imageid' => $config->imageid);
        			$tmp = explode('/', $id);
        			$rescfgmapids[$tmp[1]] = 1;
        		}
        
        		# configvars
        		$tmp = array_splice($initconfigs, 0);
        		$initconfigvars = getImageConfigVariables($tmp);
        		if(array_key_exists('configdata', $_POST) &&
        			isset($configdata->configvars))
        			$configvars = $configdata->configvars;
        		else
        			$configvars = (object)array();
        		#print "/*";
        		#printArray($initconfigvars);
        		#printArray($configvars);
        		#print "*" . "/";
        		$return['configvars'] = array();
        		foreach($initconfigvars as $id => $configvar) {
        			$tmp = explode('/', $id);
        			$cfgid = "{$tmp[0]}/{$tmp[1]}";
        			$varid = $tmp[2];
        			if($configvar['ask'] == 0 ||
        			   ! isset($configvars->{$id}) ||
        			   ! isset($configvars->{$id}->value)) {
        				$return['configvars'][$cfgid][$varid] =
        				         array('value' => $configvar['defaultvalue']);
        			}
        			else {
        				switch($configvar['datatype']) {
        					case 'bool':
        					case 'int':
        					case 'float':
        						$value = processInputData($configvars->{$id}->value, ARG_NUMERIC);
        						break;
        					default:
        						$value = processInputData($configvars->{$id}->value, ARG_STRING);
        						break;
        				}
        				$return['configvars'][$cfgid][$varid] = array('value' => $value);
        			}
        			if(isset($configvars->{$id}))
        				unset($configvars->{$id});
        		}*/
        /*print "/*";
        		printArray($rescfgmapids);
        		foreach($configvars as $id => $var) {
        			$cfgid = explode('/', $id);
        			print "cfgid: {$cfgid[1]}\n";
        			if(! array_key_exists($cfgid[1], $rescfgmapids))
        				continue;
        			// TODO validate based on var type
        			$value = processInputData($configvars->{$id}->value, ARG_STRING);
        			$return['configvars']["{$cfgid[0]}/{$cfgid[1]}"][$cfgid[2]] = array('value' => $value);
        		}
        		printArray($configvars);*/
        #print "*/";
    }
    return $return;
}
示例#2
0
function AJstartImage()
{
    global $user;
    $requestid = getContinuationVar("requestid");
    $checkpoint = getContinuationVar("checkpoint", 0);
    $data = getRequestInfo($requestid, 1);
    if (is_null($data) || $data['stateid'] == 11 || $data['stateid'] == 12 || $data['stateid'] == 14 && ($data['laststateid'] == 11 || $data['laststateid'] == 12)) {
        $ret = array('status' => 'resgone', 'errmsg' => i("The reservation you selected to image has expired."));
        sendJSON($ret);
        return;
    }
    $disableUpdate = 1;
    $imageid = '';
    if (count($data['reservations']) == 1) {
        $imageid = $data['reservations'][0]['imageid'];
        $revid = $data['reservations'][0]['imagerevisionid'];
    } else {
        foreach ($data["reservations"] as $res) {
            if ($res["forcheckout"]) {
                $imageid = $res["imageid"];
                $revid = $res['imagerevisionid'];
                break;
            }
        }
    }
    $ostype = 'windows';
    if (!empty($imageid)) {
        $imageData = getImages(0, $imageid);
        if ($imageData[$imageid]['ownerid'] == $user['id']) {
            $disableUpdate = 0;
        }
        if ($imageData[$imageid]['installtype'] == 'none' || $imageData[$imageid]['installtype'] == 'kickstart') {
            $disableUpdate = 1;
        }
        $ostype = $imageData[$imageid]['ostype'];
    } else {
        $data['status'] = 'error';
        $data['errmsg'] = i("There was an error in starting the imaging process. Please contact a system administrator.");
        sendJSON($data);
        return;
    }
    # check for root access being disabled
    if ($imageData[$imageid]['rootaccess'] == 0 && $imageData[$imageid]['ownerid'] != $user['id']) {
        $ret = array('status' => 'rootaccessnoimage');
        sendJSON($ret);
        return;
    }
    $obj = new Image();
    $cdata = array('obj' => $obj, 'requestid' => $requestid, 'imageid' => $imageid, 'baserevisionid' => $revid, 'checkpoint' => $checkpoint, 'add' => 1);
    $cont = addContinuationsEntry('AJsaveResource', $cdata, SECINDAY, 0);
    $arr = array('newcont' => $cont, 'enableupdate' => 0, 'connectmethods' => $imageData[$imageid]['connectmethods'], 'owner' => "{$user['unityid']}@{$user['affiliation']}", 'checkpoint' => $checkpoint, 'ostype' => $ostype);
    $cdata = array('obj' => $obj, 'imageid' => $imageid, 'newimage' => 1, 'curmethods' => $imageData[$imageid]['connectmethods']);
    $cont = addContinuationsEntry('connectmethodDialogContent', $cdata);
    $arr['connectmethodurl'] = BASEURL . SCRIPT . "?continuation={$cont}";
    if (!$disableUpdate) {
        $revisions = getImageRevisions($imageid, 1);
        if (array_key_exists($revid, $revisions)) {
            $comments = $revisions[$revid]['comments'];
        } else {
            $keys = array_keys($revisions);
            if (count($keys)) {
                $key = array_pop($keys);
                $comments = $revisions[$key]['comments'];
            } else {
                $comments = '';
            }
        }
        if (preg_match('/\\w/', $comments)) {
            $cmt = sprintf(i("These are the comments from the previous revision (%s):"), $revisions[$revid]['revision']);
            $cmt .= "<br>";
            $cmt .= "{$revisions[$revid]['comments']}<br><br>";
        } else {
            $cmt = i("The previous revision did not have any comments.") . "<br><br>";
        }
        $arr['comments'] = $cmt;
        $cdata = array('obj' => $obj, 'requestid' => $requestid, 'imageid' => $imageid, 'checkpoint' => $checkpoint, 'revisionid' => $revid);
        $cont = addContinuationsEntry('AJupdateImage', $cdata, SECINDAY, 0);
        $arr['updatecont'] = $cont;
        $arr['enableupdate'] = 1;
    }
    $arr['status'] = 'success';
    sendJSON($arr);
}
示例#3
0
 function getRevisionHTML($imageid)
 {
     $revisions = getImageRevisions($imageid);
     $rt = '';
     $rt .= "<h3>" . i("Revisions of this Image") . "</h3>\n";
     $rt .= "<table summary=\"\"><tr><td>\n";
     if (count($revisions) > 1 && isImageBlockTimeActive($imageid)) {
         $rt .= "<font color=\"red\">";
         $warn = i("WARNING: This image is part of an active block allocation. Changing the production revision of the image at this time will result in new reservations under the block allocation to have full reload times instead of a &lt; 1 minutes wait.");
         $rt .= preg_replace("/(.{1,100}([ \n]|\$))/", '\\1<br>', $warn);
         $rt .= "</font><br>\n";
     }
     $rt .= "<table summary=\"\" id=\"revisiontable\">\n";
     $rt .= "  <tr>\n";
     $rt .= "    <td></td>\n";
     $rt .= "    <th>" . i("Revision") . "</th>\n";
     $rt .= "    <th>" . i("Creator") . "</th>\n";
     $rt .= "    <th>" . i("Created") . "</th>\n";
     $rt .= "    <th nowrap>" . i("In Production") . "</th>\n";
     $rt .= "    <th>" . i("Comments (click to edit)") . "</th>\n";
     $rt .= "  </tr>\n";
     foreach ($revisions as $rev) {
         if ($rev['deleted'] == 1) {
             continue;
         }
         $rt .= "  <tr>\n";
         $rt .= "    <td><INPUT type=checkbox\n";
         $rt .= "              id=chkrev{$rev['id']}\n";
         $rt .= "              name=chkrev[{$rev['id']}]\n";
         $rt .= "              value=1></td>\n";
         $rt .= "    <td align=center>{$rev['revision']}</td>\n";
         $rt .= "    <td>{$rev['creator']}</td>\n";
         $created = date('g:ia n/j/Y', datetimeToUnix($rev['datecreated']));
         $rt .= "    <td>{$created}</td>\n";
         $cdata = $this->basecdata;
         $cdata['imageid'] = $imageid;
         $cdata['revisionid'] = $rev['id'];
         $cont = addContinuationsEntry('AJupdateRevisionProduction', $cdata);
         $rt .= "    <td align=center><INPUT type=radio\n";
         $rt .= "           name=production\n";
         $rt .= "           value={$rev['id']}\n";
         $rt .= "           id=radrev{$rev['id']}\n";
         $rt .= "           onclick=\"updateRevisionProduction('{$cont}');\"\n";
         if ($rev['production']) {
             $rt .= "           checked\n";
         }
         $rt .= "           ></td>\n";
         $cont = addContinuationsEntry('AJupdateRevisionComments', $cdata);
         $rt .= "    <td width=200px><span id=comments{$rev['id']} \n";
         $rt .= "              dojoType=\"dijit.InlineEditBox\"\n";
         $rt .= "              editor=\"dijit.form.Textarea\"\n";
         $rt .= "              onChange=\"updateRevisionComments('comments{$rev['id']}', '{$cont}');\"\n";
         $rt .= "              noValueIndicator=\"(empty)\">\n";
         $rt .= "        {$rev['comments']}</span></td>\n";
         $rt .= "  </tr>\n";
     }
     $rt .= "</table>\n";
     $rt .= "<div align=left>\n";
     $keys = array_keys($revisions);
     $cdata = $this->basecdata;
     $cdata['revids'] = $keys;
     $cdata['imageid'] = $imageid;
     $cont = addContinuationsEntry('AJdeleteRevisions', $cdata);
     $ids = implode(',', $keys);
     $rt .= "<button onclick=\"deleteRevisions('{$cont}', '{$ids}'); return false;\">";
     $rt .= i("Delete selected revisions") . "</button>\n";
     $rt .= "</div>\n";
     $rt .= "</td></tr></table>\n";
     return $rt;
 }
示例#4
0
function updateExistingImageComments()
{
    $cdata = getContinuationVar();
    $data = getRequestInfo($cdata['requestid']);
    foreach ($data["reservations"] as $res) {
        if ($res["forcheckout"]) {
            $imageid = $res["imageid"];
            $revisionid = $res['imagerevisionid'];
            break;
        }
    }
    $revisions = getImageRevisions($imageid);
    print "<H2>Update Existing Image</H2>\n";
    print "<h3>New Revision Comments</h3>\n";
    print "Enter any notes for yourself and other admins about how the image ";
    print "was setup/installed.<br>\nThese are optional and not visible to end ";
    print "users:<br>\n";
    print "<form action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    print "<textarea dojoType=\"dijit.form.Textarea\" name=comments ";
    print "style=\"width: 400px; text-align: left;\"\">\n\n</textarea>\n";
    print "<h3>Previous Revision Comments</h3>\n";
    if (preg_match('/\\w/', $revisions[$revisionid]['comments'])) {
        print "These are the comments from the previous revision ";
        print "({$revisions[$revisionid]['revision']}):<br>\n";
        print "{$revisions[$revisionid]['comments']}<br><br>\n";
    } else {
        print "The previous revision did not have any comments.<br>\n";
    }
    print "<table summary=\"\">\n";
    print "  <tr>\n";
    print "    <td>\n";
    $cont = addContinuationsEntry('updateExistingImage', $cdata, SECINDAY, 0, 0);
    print "      <input type=hidden name=continuation value=\"{$cont}\">\n";
    print "      <input type=submit value=\"Create New Revision\">\n";
    print "      </form>\n";
    print "    </td>\n";
    print "    <td>\n";
    print "      <form action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    $cont = addContinuationsEntry('viewRequests');
    print "      <input type=hidden name=continuation value=\"{$cont}\">\n";
    print "      <input type=submit value=\"Cancel\">\n";
    print "      </form>\n";
    print "    </td>\n";
    print "  </tr>\n";
    print "</table>\n";
}