Пример #1
0
 public function testbuildUrl()
 {
     $config = array('protocol' => 'http', 'ipaddress' => '10.20.30.40', 'port' => '5656', 'usertype' => 'admin');
     $solusVm = new SolusVM();
     $result = $solusVm->buildUrl($config);
     $this->assertInternalType('string', $result);
     $this->assertNotEmpty($result);
     $expected = $config['protocol'] . "://" . $config['ipaddress'] . ":" . $config['port'] . "/api/" . $config['usertype'] . "/command.php";
     $this->assertEquals($expected, $result);
 }
Пример #2
0
if (!preg_match('/^[a-f0-9]{40}$/', $hash)) {
    die(json_encode(array('status' => 'error', 'message' => '<p class="red">' . A_VALID_API_HASH_SHOULD_BE_40_CHARACTERS_IN_LENGTH . '</p>')));
}
$db->connect();
// Make sure virtualization is valid
if (!getVz($vzId)) {
    die(json_encode(array('status' => 'error', 'message' => '<p class="red">' . INVALID_VIRTUALIZATION_SELECTED . '</p>')));
}
// Check if key exists
$db->select('vm', '*', 'key=\'' . $db->escape($key) . '\' AND user_id=\'' . $db->escape($_SESSION['user_id']) . '\'' . ($vmId ? ' AND vm_id != \'' . $db->escape($vmId) . '\'' : ''));
if ($db->affectedRows() == 1) {
    die(json_encode(array('status' => 'error', 'message' => '<p class="red">' . API_KEY_ALREADY_EXISTS . '</p>')));
}
// Try to access the API for validation
require_once LIBRARIES . 'solusvm.class.php';
$svm = new SolusVM();
$svm->setProtocol($isHttps ? 'https' : 'http');
$svm->setHost($host);
$svm->setPort($port);
$svm->setKey($key);
$svm->setHash($hash);
$result = $svm->getStatus();
if ($result['status'] != 'success') {
    die(json_encode(array('status' => 'error', 'message' => '<p class="red">' . UNABLE_TO_ACCESS_SOLUSVM_API . '</p>')));
}
$data = array('label' => $label, 'vz_id' => $vzId, 'is_https' => $isHttps ? 1 : 0, 'host' => $host, 'port' => empty($port) ? $isHttps ? '443' : '80' : $port, 'key' => $key, 'hash' => $hash, 'user_id' => $_SESSION['user_id']);
// Edit existing VM
if ($vmId) {
    $db->update('vm', $data, 'vm_id=\'' . $db->escape($vmId) . '\' AND user_id=\'' . $db->escape($_SESSION['user_id']) . '\'');
    // Remove existing tags
    $db->delete('tag_linker', 'vm_id=\'' . $db->escape($vmId) . '\'');
Пример #3
0
$id = $form->post('id');
$action = $form->post('action');
if (!in_array($action, array('boot', 'reboot', 'shutdown'))) {
    die(json_encode(array('status' => 'error', 'message' => '<p class="red">' . INVALID_ACTION . '</p>')));
}
$db->connect();
$rows = $db->select('vm', '*', 'vm_id=\'' . $db->escape($id) . '\' AND user_id=\'' . $db->escape($_SESSION['user_id']) . '\' LIMIT 1');
if ($db->affectedRows() == 0) {
    die(json_encode(array('status' => 'error', 'message' => '<p class="red">' . VM_NOT_FOUND . '</p>')));
}
foreach ($rows[0] as $key => $value) {
    $vm[$key] = $value;
}
foreach ($rows as $row) {
    require_once LIBRARIES . 'solusvm.class.php';
    $svm = new SolusVM();
    $svm->setProtocol($vm['is_https'] ? 'https' : 'http');
    $svm->setHost($vm['host']);
    $svm->setPort($vm['port']);
    $svm->setKey($vm['key']);
    $svm->setHash($vm['hash']);
    switch ($action) {
        case 'boot':
            $result = $svm->boot();
            $message = str_replace('%name%', $vm['label'], VM_HAS_BEEN_BOOTED);
            break;
        case 'reboot':
            $result = $svm->reboot();
            $message = str_replace('%name%', $vm['label'], VM_HAS_BEEN_REBOOTED);
            break;
        case 'shutdown':
Пример #4
0
defined('INDEX') or die('Access is denied.');
if (!isset($_SESSION['user_id'])) {
    die(json_encode(array('status' => 'connect-unknown', 'message' => '<p class="red">' . SESSION_EXPIRED . '</p>', 'hostname' => '', 'main_ip' => '', 'ip_list' => '', 'hdd_total' => 0, 'hdd_used' => 0, 'hdd_free' => 0, 'hdd_percent' => 0, 'mem_total' => 0, 'mem_used' => 0, 'meme_free' => 0, 'mem_percent' => 0, 'bw_total' => 0, 'bw_used' => 0, 'bw_free' => 0, 'bw_percent' => 0)));
}
$vmId = $form->post('id');
$db->connect();
$rows = $db->select('vm', '*', 'vm_id=\'' . $db->escape($vmId) . '\' AND user_id=\'' . $db->escape($_SESSION['user_id']) . '\' LIMIT 1');
$status = get_object_vars(json_decode($_SESSION['status']));
if ($db->affectedRows() == 0) {
    $status['vm-' . $vmId] = 'connect-unknown';
    $_SESSION['status'] = json_encode($status);
    die(json_encode(array('status' => 'connect-unknown', 'message' => '<p class="red">' . VM_NOT_FOUND . '</p>', 'hostname' => '', 'main_ip' => '', 'ip_list' => '', 'hdd_total' => 0, 'hdd_used' => 0, 'hdd_free' => 0, 'hdd_percent' => 0, 'mem_total' => 0, 'mem_used' => 0, 'meme_free' => 0, 'mem_percent' => 0, 'bw_total' => 0, 'bw_used' => 0, 'bw_free' => 0, 'bw_percent' => 0)));
}
foreach ($rows as $row) {
    require_once LIBRARIES . 'solusvm.class.php';
    $svm = new SolusVM();
    $svm->setProtocol($row['is_https'] ? 'https' : 'http');
    $svm->setHost($row['host']);
    $svm->setPort($row['port']);
    $svm->setKey($row['key']);
    $svm->setHash($row['hash']);
    $result = $svm->getStatus();
    if (!$result) {
        $status['vm-' . $vmId] = 'connect-error';
        $_SESSION['status'] = json_encode($status);
        die(json_encode(array('status' => 'connect-error', 'message' => '<p class="red">' . CONNECTION_ERROR_WHEN_ACCESSING . '</p>', 'hostname' => '', 'main_ip' => '', 'ips' => array(), 'hdd_total' => 0, 'hdd_used' => 0, 'hdd_free' => 0, 'hdd_percent' => 0, 'mem_total' => 0, 'mem_used' => 0, 'meme_free' => 0, 'mem_percent' => 0, 'bw_total' => 0, 'bw_used' => 0, 'bw_free' => 0, 'bw_percent' => 0)));
    }
    list($hddTotal, $hddUsed, $hddFree, $hddPercent) = explode(',', strpos($result['hdd'], ',') ? $result['hdd'] : '0,0,0,0');
    list($memTotal, $memUsed, $memFree, $memPercent) = explode(',', strpos($result['mem'], ',') ? $result['mem'] : '0,0,0,0');
    list($bwTotal, $bwUsed, $bwFree, $bwPercent) = explode(',', strpos($result['bw'], ',') ? $result['bw'] : '0,0,0,0');
    $ipList = array();