예제 #1
0
 public function __construct($esxman, $database, $username = '', $error = null)
 {
     $this->esxman = $esxman;
     $this->database = $database;
     $this->username = $username;
     $this->html = array('footer' => ' ', 'menu' => ' ', 'tree' => ' ', 'user' => ' ', 'content' => ' ');
     $this->commands = array();
     $this->title = _('Login');
     if (request('form_name') == 'login') {
         if ($this->database->authenticate_user(request('username'), request('password'))) {
             session_destroy();
             session_start();
             $_SESSION['username'] = request('username');
             $_SESSION['key'] = md5($_SESSION['username'] . getenv('REMOTE_ADDR') . getenv('X-FORWARDED-FOR'));
             debug('User ' . request('username') . ' logging in!');
             $this->commands[] = "\$('#dialog').html('" . _('Populating inventory...') . "');";
             $this->commands[] = js_command('get', 'action=populate_inventory');
             return;
         }
         $error = _('Authentication failed');
     }
     $tpl = new Template('dialog_login.html');
     if ($error) {
         $tpl->setVar('error', $error);
         $tpl->parse('error_message');
     }
     $this->commands[] = js_command('display_dialog', _('Login'), $tpl->get(), _('Login'));
 }
예제 #2
0
 public function __construct($esxman, $database)
 {
     $this->esxman = $esxman;
     $this->database = $database;
     $this->html = array();
     $this->commands = array();
     $this->title = request('vm');
     $this->commands[] = "\$('#header').addClass('console');";
     $this->commands[] = "\$('#content').addClass('console');";
     $this->commands[] = "\$('#user').css('display', 'none');";
     $this->commands[] = "\$('#menu').css('display', 'none');";
     $this->commands[] = "\$('#tree').css('display', 'none');";
     $this->commands[] = "\$('#footer').css('display', 'none');";
     $this->commands[] = js_command('initconsole', request('host'), request('vm'));
 }
예제 #3
0
 private function power($host, $vm, $action)
 {
     try {
         $host = $this->database->gethost($host);
         $esx = $this->esxman->get_esx($host['hostname']);
         $tasks = array('poweroff' => 'PowerOffVM_Task', 'poweron' => 'PowerOnVM_Task', 'suspend' => 'SuspendVM_Task', 'shutdown' => 'ShutdownGuest', 'reset' => 'ResetVM_Task');
         $texts = array('poweroff' => sprintf(_('Powering off \'%s\'.'), $vm), 'poweron' => sprintf(_('Powering on \'%s\'.'), $vm), 'suspend' => sprintf(_('Suspending \'%s\'.'), $vm), 'shutdown' => sprintf(_('Shutting down \'%s\'.'), $vm), 'reset' => sprintf(_('Resetting \'%s\'.'), $vm));
         $task = $esx->{$tasks[$action]}(array('_this' => $_SESSION['hosts'][$host['hostname']]['vm'][$vm]['obj']));
         if (preg_match('/_Task$/', $tasks[$action])) {
             $this->commands[] = "\$('#dialog').remove();";
             $this->commands[] = js_command('wait_for_task', $texts[$action], $host['hostname'], $task->returnval->_, true);
         } else {
             $this->singlevm($host['hostname'], $vm);
         }
     } catch (Exception $e) {
         fatal_error($e->getMessage(), $e->getFile(), $e->getLine());
     }
 }
예제 #4
0
 private function dialog_editsettings($hostname, $host, $error = null)
 {
     $tpl = new Template('dialog_host_editsettings.html');
     if ($error) {
         $tpl->setVar('error', $error);
         $tpl->parse('error_message');
     } else {
         $tpl->hideBlock('error_message');
     }
     $tpl->setVars(array('label_hostname' => _('Hostname'), 'hostname' => $host['hostname'], 'regex_hostname' => '^(' . REGEX_HOSTNAME . '|' . REGEX_IPV4 . '|' . REGEX_IPV6 . ')$', 'label_username' => _('Username'), 'username' => $host['username'], 'label_password' => _('Password')));
     if ($GLOBALS['config']['console']) {
         $tpl->setVars(array('label_enableconsole' => _('Enable console'), 'enableconsole' => $host['console'] ? 'checked="checked"' : '', 'label_consoleaddress' => _('Console address'), 'consoleaddress' => $host['consoleaddress'], 'display_consoleaddress' => $host['console'] ? '\'\'' : 'none', 'regex_empty_hostname' => '^(' . REGEX_HOSTNAME . '|' . REGEX_IPV4 . '|' . REGEX_IPV6 . ')?$', 'tip_consoleaddress' => _('The address to which the vmrc plugin should connect, if different from the hostname.')));
         $tpl->parse('console');
     } else {
         $tpl->hideBlock('console');
     }
     $tpl->setVar('oldhostname', $hostname);
     $this->commands[] = js_command('display_dialog', _('Edit settings'), $tpl->get(), _('Apply'), _('Cancel'));
 }
예제 #5
0
 private function wait_for_task($task, $host, $refresh)
 {
     try {
         $host = $this->database->gethost($host);
         $esx = $this->get_esx($host['hostname']);
         $taskobj = (object) array('_' => $task, 'type' => 'Task');
         $details = $esx->getproperties($taskobj);
         $commands = array();
         if ($details->propSet->info->state == 'running' || $details->propSet->info->state == 'queued') {
             $commands[] = js_command('wait_for_task', '', $host['hostname'], $task, $refresh);
         } else {
             if ($details->propSet->info->state == 'error') {
                 $commands[] = "\$('#wait_dialog').remove();";
                 $commands[] = js_command('display_error', _('Error'), $details->propSet->info->error->localizedMessage);
             } else {
                 if ($details->propSet->info->entity->type == 'VirtualMachine') {
                     foreach ($_SESSION['hosts'][$host['hostname']]['vm'] as $vmname => $vm) {
                         if ($vm['obj']->_ == $details->propSet->info->entity->_) {
                             $this->populate_inventory($host['hostname'], $vmname);
                         }
                     }
                 }
                 $commands[] = "\$('#wait_dialog').remove();";
                 $commands[] = "get(location.hash.replace(/.*#\\//, ''));";
             }
         }
     } catch (Exception $e) {
         fatal_error(_('Error'), $e->getMessage(), $e->getFile(), $e->getLine());
         /* Either the task is gone or the host has. */
         $commands[] = "\$('#wait_dialog').remove();";
         $commands[] = "get(location.hash.replace(/.*#\\//, ''));";
     }
     echo json_encode(array('commands' => $commands));
     exit;
 }