// Datacenter $result = $hosting_api->__call('datacenter.list', array(API_KEY)); //print_r($result); $dc_id = $result[0]['id']; echo $dc_id; // Operating system image $datacenter_spec = ['datacenter_id' => 1]; $result = $hosting_api->__call('image.list', array(API_KEY, $datacenter_spec)); print_r($result); // 19 = Debian 8 64 bits (HVM) // 20 = Ubuntu 14.04 64 bits LTS (HVM) $distribution_id = 19; $src_disk_id = $result[$distribution_id]['disk_id']; echo $src_disk_id; // VM creation $vmName = generateRandomName(); $cpu = 1; $ram = 2; $login = '******'; $password = "******"; //$run = 'touch /fakefile.txt '; $run = 'touch /home/' . $login . '/fakefile.txt'; $disc_spec = ['datacenter_id' => $dc_id, 'name' => $vmName]; $vm_spec = ['datacenter_id' => $dc_id, 'cores' => $cpu, 'memory' => $ram * 1024, 'hostname' => $vmName, 'login' => $login, 'password' => $password, 'run' => $run]; $result = $hosting_api->__call('vm.create_from', array(API_KEY, $vm_spec, $disc_spec, $src_disk_id)); print_r($result); // VM info // Get this info from the previous command $vm_id = $result[2]['vm_id']; $result = $hosting_api->__call('vm.info', array(API_KEY, $vm_id)); print_r($result);
/** * Creates a temporary file in the /tmp directory, appending a random suffix for uniqueness between * parallel tasks of the same script. * @param string $name Basic name of the temporary file. Optional * @return string Path to the created temporary file. An empty string if creation failed. */ function create_temporary_file($name = '') { $name = generateRandomName('A-Za-z0-9', 20) . '_' . $name . '.tmp'; $path = jailpath(DIAMONDMVC_ROOT . DS . 'tmp', $name); if (!touch($path)) { return ''; } return $path; }
/** * Generates HTML for displaying a filter - including operator selection and label - based on set parameters * @return string Field filter HTML */ public function renderFilter() { $result = ''; $id = $this->id; if (empty($id)) { $id = generateRandomName('A-Za-z0-9', 10); } $result .= '<div class="col1 field-column-wrapper">'; $result .= '<label for="' . $id . '" data-toggle="tooltip" title="' . $this->tooltip . '">' . $this->label . '</label>'; $result .= '</div>'; // Avoid a dropdown select if we only have a single operator. $result .= '<div class="col2 field-operators-wrapper">'; $operators = $this->getFilterOperators(); if (count($operators) === 1) { foreach ($operators as $operator => $display) { $result .= '<input type="hidden" name="' . $this->nameOperators . '" value="' . $operator . '">'; $result .= $display; } } else { $result .= '<select name="' . $this->nameOperators . '" id="' . $id . '_type" class="search-type">'; foreach ($operators as $operator => $display) { $result .= '<option value="' . $operator . '">' . $display . '</option>'; } $result .= '</select>'; } $result .= '</div>'; $result .= '<div class="field-meta col3"'; foreach ($this->data as $key => $value) { $key = strToLower($key); $result .= " data-{$key}=\"{$value}\""; } $result .= '>'; $result .= '<div class="current-filter">'; foreach ($operators as $operator => $display) { $result .= $this->_renderFilter($operator, $id, $this->name); break; } $result .= '</div>'; $result .= '</div>'; return $result; }
/** * Downloads an installation ZIP from the given URL. The file MUST have the .zip file extension as an added * pseudo-safety measurement. * @param string $url * @return string Path to the downloaded ZIP file. */ protected static function download($url) { // Attempt to download the file. $contents = @file_get_contents($url); if ($contents === false) { throw new InstallationException("Failed to download the installation ZIP from {$url}"); } // Brute force first free name to use do { $name = generateRandomName('A-Za-z0-9', 20); } while (file_exists(DIAMONDMVC_ROOT . "/tmp/{$name}.zip")); // Attempt to save the file. if (file_put_contents(DIAMONDMVC_ROOT . "/tmp/{$name}.zip", $contents) === false) { throw new InstallationException("Failed to save downloaded installation ZIP from {$url}"); } // Successfully saved. Return its path. return DIAMONDMVC_ROOT . "/tmp/{$name}.zip"; }
$wmarkPosX = $waterMarkLayerXpos; $wmarkPosY = $waterMarkLayerYpos; for ($i = 0; $i < $wmarkCountY; $i++) { if ($wmarkPosY < $basicImageLayerHeight && $wmarkPosY > -$waterMarkLayerHeight) { for ($j = 0; $j < $wmarkCountX; $j++) { if ($wmarkPosX < $basicImageLayerWidth && $wmarkPosX > -$waterMarkLayerWidth) { $basicImageLayer->addLayer(1, $waterMarkLayer, $wmarkPosX, $wmarkPosY, "LT"); $basicImageLayer = ImageWorkshop::initFromResourceVar($basicImageLayer->getResult()); } $wmarkPosX += $deltaX + $waterMarkLayerWidth; } } $wmarkPosY += $deltaY + $waterMarkLayerHeight; $wmarkPosX = $waterMarkLayerXpos; } } $image = $basicImageLayer->getResult(); $tempName = generateRandomName('.jpg'); imagejpeg($image, './php/temp/' . $tempName, 95); response(200, $tempName); exit; } catch (Exception $e) { response(400, $lang["perr_expt"] . $e->getMessage()); exit; } } response(400, $lang["perr_smtwr"]); exit; } response(400, $lang["perr_smtwr"]); exit;