Ejemplo n.º 1
0
 function select()
 {
     $h['state']['title'] = $this->lang['appliances']['state'];
     $h['id']['title'] = $this->lang['appliances']['id'];
     $h['id']['hidden'] = true;
     $h['name']['title'] = $this->lang['create']['hostname'];
     $h['name']['hidden'] = true;
     $h['type']['title'] = $this->lang['create']['type'];
     $h['type']['hidden'] = true;
     $h['cpu']['title'] = $this->lang['create']['cpu'];
     $h['cpu']['hidden'] = true;
     $h['ram']['title'] = $this->lang['create']['ram'];
     $h['ram']['hidden'] = true;
     $h['config']['title'] = ' ';
     $h['config']['sortable'] = false;
     $h['kernel']['title'] = $this->lang['create']['kernel'];
     $h['kernel']['hidden'] = true;
     $h['disk']['title'] = $this->lang['create']['disk'];
     $h['disk']['hidden'] = true;
     $h['image']['title'] = $this->lang['create']['image'];
     $h['image']['hidden'] = true;
     $h['comment']['title'] = ' ';
     $h['comment']['sortable'] = false;
     $h['action']['title'] = ' ';
     $h['action']['sortable'] = false;
     // mark sorted values
     $sort = $this->response->html->request()->get('cloud_table[sort]');
     if ($sort === 'id') {
         $this->lang['appliances']['id'] = '<span>' . $this->lang['appliances']['id'] . '</span>';
     } else {
         if ($sort === 'name') {
             $this->lang['create']['hostname'] = '<span>' . $this->lang['create']['hostname'] . '</span>';
         } else {
             if ($sort === 'type') {
                 $this->lang['create']['type'] = '<span>' . $this->lang['create']['type'] . '</span>';
             } else {
                 if ($sort === 'cpu') {
                     $this->lang['create']['cpu'] = '<span>' . $this->lang['create']['cpu'] . '</span>';
                 } else {
                     if ($sort === 'ram') {
                         $this->lang['create']['ram'] = '<span>' . $this->lang['create']['ram'] . '</span>';
                     } else {
                         if ($sort === 'kernel') {
                             $this->lang['create']['kernel'] = '<span>' . $this->lang['create']['kernel'] . '</span>';
                         } else {
                             if ($sort === 'disk') {
                                 $this->lang['create']['disk'] = '<span>' . $this->lang['create']['disk'] . '</span>';
                             } else {
                                 if ($sort === 'image') {
                                     $this->lang['create']['image'] = '<span>' . $this->lang['create']['image'] . '</span>';
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $cloudreq_array = $this->cloudrequest->get_all_ids_per_user($this->clouduser->id);
     $user_requests = array();
     // build an array of our appliance id's
     foreach ($cloudreq_array as $cr) {
         $user_requests[] = $cr['cr_id'];
     }
     $show_ip_mgmt = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('ip-management'), "true")) {
         $show_ip_mgmt = true;
     }
     $sshterm_enabled = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('show_sshterm_login'), "true")) {
         $sshterm_enabled = true;
     }
     $show_application_ha = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('show_ha_checkbox'), "true")) {
         $show_application_ha = true;
     }
     $collectd_graph_enabled = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('show_collectd_graphs'), "true")) {
         $collectd_graph_enabled = true;
     }
     $private_image_config_enabled = false;
     if (!strcmp($this->cloudconfig->get_value_by_key('show_private_image'), "true")) {
         $private_image_config_enabled = true;
     }
     $show_pause_button = false;
     $show_unpause_button = false;
     // now we go over all our appliances from the users request list
     $app_count = 0;
     $ta = array();
     foreach ($user_requests as $reqid) {
         $appliance = null;
         $this->cloudrequest->get_instance_by_id($reqid);
         if (strlen($this->cloudrequest->appliance_id) && $this->cloudrequest->appliance_id != 0) {
             $appliance = $this->openqrm->appliance();
             $appliance->get_instance_by_id($this->cloudrequest->appliance_id);
         }
         $sshterm_login = false;
         $appliance_resources_str = "";
         $res_ip_loop = 0;
         $resource = $this->openqrm->resource();
         // prepare values
         $str_cpu = intval($this->cloudrequest->cpu_req);
         if ($str_cpu === 0) {
             $str_cpu = 'Auto';
         }
         $str_ram = intval($this->cloudrequest->ram_req);
         if ($str_ram === 0) {
             $str_ram = 'Auto';
         } else {
             if ($str_ram >= 1000) {
                 $str_ram = round($str_ram / 1000, 3, PHP_ROUND_HALF_DOWN) . ' GB';
             } else {
                 $str_ram = $str_ram . ' MB';
             }
         }
         if (isset($appliance)) {
             $appliance_resources = $appliance->resources;
             #if (!strlen($sshterm_login_ip)) {
             // in case no external ip was given to the appliance we show the internal ip
             $resource->get_instance_by_id($appliance->resources);
             $appliance_resources_str .= $resource->ip;
             $sshterm_login_ip = $resource->ip;
             $sshterm_login = true;
             #}
             if ($appliance_resources >= 0) {
                 // check ip-mgmt
                 if ($show_ip_mgmt) {
                     if (file_exists($this->rootdir . "/plugins/ip-mgmt/.running")) {
                         require_once $this->rootdir . "/plugins/ip-mgmt/class/ip-mgmt.class.php";
                         $ip_mgmt = new ip_mgmt();
                         $appliance_first_nic_ip_mgmt_id = $ip_mgmt->get_id_by_appliance($appliance->id, 1);
                         if ($appliance_first_nic_ip_mgmt_id > 0) {
                             $appliance_ip_mgmt_config_arr = $ip_mgmt->get_instance('id', $appliance_first_nic_ip_mgmt_id);
                             if (isset($appliance_ip_mgmt_config_arr['ip_mgmt_address'])) {
                                 $sshterm_login_ip = $appliance_ip_mgmt_config_arr['ip_mgmt_address'];
                                 $appliance_resources_str .= ', ' . $appliance_ip_mgmt_config_arr['ip_mgmt_address'];
                                 $sshterm_login = true;
                             }
                         }
                     }
                 }
                 // check if we need to NAT the ip address
                 $cn_nat_enabled = $this->cloudconfig->get_value_by_key('cloud_nat');
                 // 18 is cloud_nat
                 if (!strcmp($cn_nat_enabled, "true")) {
                     $appliance_resources_str = $this->cloudnat->translate($appliance_resources_str);
                     $sshterm_login_ip = $this->cloudnat->translate($sshterm_login_ip);
                 }
             } else {
                 // an appliance with resource auto-select enabled
                 $appliance_resources_str = "auto-select";
                 $sshterm_login = false;
             }
             // state
             $state = $this->cloudrequest->getstatus($this->cloudrequest->id);
             $this->cloudappliance->get_instance_by_appliance_id($appliance->id);
             switch ($this->cloudappliance->state) {
                 case 0:
                     if ($state === 'starting' || $resource->state === 'transition') {
                         $cloudappliance_state = 'busy';
                         $sshterm_login = false;
                         $show_application_ha = false;
                         $show_pause_button = false;
                         $private_image_enabled = false;
                     } else {
                         $cloudappliance_state = "paused";
                         $sshterm_login = false;
                         $show_unpause_button = true;
                         $show_pause_button = false;
                         $show_application_ha = false;
                         $private_image_enabled = false;
                     }
                     break;
                 case 1:
                     if ($resource->state === 'active' && $state === 'active') {
                         $cloudappliance_state = "active";
                         $sshterm_login = true;
                         $show_application_ha = true;
                         $show_pause_button = true;
                         $private_image_enabled = true;
                     } else {
                         $cloudappliance_state = 'busy';
                         $sshterm_login = false;
                         $show_application_ha = false;
                         $show_pause_button = false;
                         $private_image_enabled = false;
                     }
                     break;
             }
             $kernel = $this->openqrm->kernel();
             if (isset($appliance->kernelid) && $appliance->kernelid !== '') {
                 $kernel->get_instance_by_id($appliance->kernelid);
             }
             $image_size = '';
             $image = $this->openqrm->image();
             if (isset($appliance->imageid) && $appliance->imageid !== '') {
                 $image->get_instance_by_id($appliance->imageid);
                 // image disk size
                 $this->cloudimage->get_instance_by_image_id($image->id);
                 $image_size = $this->cloudimage->disk_size;
             }
             $virtualization = $this->openqrm->virtualization();
             if (isset($appliance->virtualization) && $appliance->virtualization !== '') {
                 $virtualization->get_instance_by_id($appliance->virtualization);
             }
             // prepare actions
             $cloudappliance_action = "";
             $plugin_action = "";
             // sshterm login
             if ($sshterm_enabled) {
                 if ($sshterm_login && isset($sshterm_login_ip)) {
                     // get the parameters from the plugin config file
                     $OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE = $this->openqrm->get('basedir') . "/plugins/sshterm/etc/openqrm-plugin-sshterm.conf";
                     $store = openqrm_parse_conf($OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE);
                     extract($store);
                     $sshterm_window = 'window' . str_replace('.', '', $sshterm_login_ip);
                     $sshterm_login_url = "https://{$sshterm_login_ip}:{$OPENQRM_PLUGIN_WEBSHELL_PORT}";
                     $a = $this->response->html->a();
                     $a->label = $this->lang['appliances']['plugin_ssh'];
                     $a->handler = "";
                     $a->css = 'plugin console';
                     $a->href = '#';
                     $a->handler = 'onclick="sshwindow = window.open(\'' . $sshterm_login_url . '\',\'' . $sshterm_window . '\', \'location=0,status=0,scrollbars=yes,resizable=yes,width=973,height=500,left=100,top=100,screenX=400,screenY=100\'); sshwindow.focus(); return false;"';
                     $plugin_action .= $a->get_string();
                 }
             }
             // application ha
             /*
             				if ($show_application_ha) {
             					$lcmc_gui="lcmc/lcmc-gui.php";
             					$icon_size = "width='21' height='21'";
             					$icon_title = $this->lang['appliances']['plugin_ha'];
             					$lcmc_url = "<a style=\"text-decoration:none\" href=\"#\" onClick=\"javascript:window.open('$lcmc_gui','','location=0,status=0,scrollbars=1,width=1024,height=768,left=50,top=20,screenX=50,screenY=20');\">
             						<image border=\"0\" alt=\"".$icon_title."\" title=\"".$icon_title."\" src=\"../img/ha.png\">
             						</a>";
             					$plugin_action .= $lcmc_url;
             				}
             */
             // regular actions
             if ($show_pause_button) {
                 // pause
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_pause'];
                 $a->label = $this->lang['appliances']['action_pause'];
                 $a->handler = "";
                 $a->css = 'pause';
                 $a->href = $this->response->get_url($this->actions_name, 'pause') . '&' . $this->identifier_name . '[]=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
                 // restart
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_restart'];
                 $a->label = $this->lang['appliances']['action_restart'];
                 $a->handler = "";
                 $a->css = 'restart';
                 $a->href = $this->response->get_url($this->actions_name, 'restart') . '&' . $this->identifier_name . '[]=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
             }
             if ($show_unpause_button) {
                 // pause
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_unpause'];
                 $a->label = $this->lang['appliances']['action_unpause'];
                 $a->handler = "";
                 $a->css = 'start';
                 $a->href = $this->response->get_url($this->actions_name, 'unpause') . '&' . $this->identifier_name . '[]=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
             }
             if ($collectd_graph_enabled) {
                 // system stats
                 $data = $this->openqrm->get('basedir') . '/plugins/collectd/data/' . $appliance->name;
                 if (file_exists($data)) {
                     $a = $this->response->html->a();
                     $a->label = $this->lang['appliances']['plugin_collectd'];
                     $a->handler = "";
                     $a->css = 'plugin collectd';
                     $a->href = $this->response->get_url($this->actions_name, 'statistics') . '&appliance_id=' . $appliance->id;
                     $plugin_action .= $a->get_string();
                 }
             }
             // private images
             if ($private_image_enabled && $private_image_config_enabled) {
                 $a = $this->response->html->a();
                 $a->label = $this->lang['appliances']['action_private_image'];
                 $a->title = $this->lang['appliances']['action_private_image'];
                 $a->handler = "";
                 $a->css = 'private';
                 $a->href = $this->response->get_url($this->actions_name, 'image_private') . '&appliance_id=' . $appliance->id;
                 $cloudappliance_action .= $a->get_string();
             }
             // noVNC
             if (!strcmp($this->cloudconfig->get_value_by_key('allow_vnc_access'), "true") && $show_pause_button) {
                 $a = $this->response->html->a();
                 $a->label = $this->lang['appliances']['plugin_novnc'];
                 $a->handler = "";
                 $a->css = 'plugin novnc';
                 $a->href = 'api.php?action=novnc&appliance_id=' . $appliance->id;
                 $a->target = '_blank';
                 $plugin_action .= $a->get_string();
             }
             if ($cloudappliance_state === 'active' || $cloudappliance_state === 'paused') {
                 // appliance update
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_update'];
                 $a->label = $this->lang['appliances']['action_update'];
                 $a->handler = "";
                 $a->css = 'edit';
                 $a->href = $this->response->get_url($this->actions_name, 'appliance_update') . '&' . $this->identifier_name . '=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
                 // deprovision
                 $a = $this->response->html->a();
                 $a->title = $this->lang['appliances']['action_deprovision'];
                 $a->label = $this->lang['appliances']['action_deprovision'];
                 $a->handler = "";
                 $a->css = 'remove';
                 $a->href = $this->response->get_url($this->actions_name, 'deprovision') . '&' . $this->identifier_name . '[]=' . $this->cloudappliance->id;
                 $cloudappliance_action .= $a->get_string();
             }
             $disk = intval($image_size);
             if ($disk >= 1000) {
                 $disk = round($disk / 1000, 2, PHP_ROUND_HALF_DOWN) . ' GB';
             } else {
                 $disk = $disk . ' MB';
             }
             $config_column = '<b>' . $this->lang['appliances']['id'] . '</b> ' . $this->cloudrequest->id . '<br>';
             $config_column .= '<b>' . $this->lang['create']['hostname'] . '</b> ' . $appliance->name . '<br>';
             $config_column .= '<b>' . $this->lang['create']['type'] . '</b> ' . $virtualization->name . '<br>';
             $config_column .= '<b>' . $this->lang['create']['cpu'] . '</b> ' . $str_cpu . '<br>';
             $config_column .= '<b>' . $this->lang['create']['ram'] . '</b> ' . $str_ram . '<br>';
             $config_column .= '<b>' . $this->lang['create']['kernel'] . '</b> ' . $kernel->name . '<br>';
             $config_column .= '<b>' . $this->lang['create']['disk'] . '</b> ' . $disk . '<br>';
             $config_column .= '<b>' . $this->lang['create']['image'] . '</b> ' . $image->name . '<br>';
             $config_column .= '<b>IP</b> ' . $appliance_resources_str;
             $comment = $appliance->comment . '<hr>' . $plugin_action;
             if ($cloudappliance_state === 'busy') {
                 $comment = $this->lang['appliances']['error_command_running'];
                 $comment = $appliance->comment . '<hr><div class="busy_appliance">&#160;</div>';
             }
             #$comment .= '<textarea id="'.$this->cloudrequest->id.'" style="height:60px;width:95%;font-size:10px;"></textarea><script>get_state("'.$this->cloudrequest->id.'");</script>';
             $ta[] = array('id' => $this->cloudappliance->id, 'state' => '<span class="pill ' . $cloudappliance_state . '">' . $cloudappliance_state . '</span>', 'name' => $appliance->name, 'type' => $virtualization->name, 'cpu' => $this->cloudrequest->cpu_req, 'ram' => $this->cloudrequest->ram_req, 'disk' => $image_size, 'kernel' => $kernel->name, 'image' => $image->name, 'config' => $config_column, 'comment' => $comment, 'action' => $cloudappliance_action);
             $app_count++;
         } else {
             $this->cloudrequest->get_instance_by_id($reqid);
             $state = $this->cloudrequest->getstatus($this->cloudrequest->id);
             if ($state !== 'done') {
                 $kernel = $this->openqrm->kernel();
                 if (isset($this->cloudrequest->kernel_id) && $this->cloudrequest->kernel_id !== '') {
                     $kernel->get_instance_by_id($this->cloudrequest->kernel_id);
                 }
                 $image = $this->openqrm->image();
                 if (isset($this->cloudrequest->image_id) && $this->cloudrequest->image_id !== '') {
                     $image->get_instance_by_id($this->cloudrequest->image_id);
                 }
                 $virtualization = $this->openqrm->virtualization();
                 if (isset($this->cloudrequest->resource_type_req) && $this->cloudrequest->resource_type_req !== '') {
                     $virtualization->get_instance_by_id($this->cloudrequest->resource_type_req);
                 }
                 $disk = intval($this->cloudrequest->disk_req);
                 if ($disk >= 1000) {
                     $disk = round($disk / 1000, 2, PHP_ROUND_HALF_DOWN) . ' GB';
                 } else {
                     $disk = $disk . ' MB';
                 }
                 $config_column = '<b>' . $this->lang['appliances']['id'] . '</b> ' . $this->cloudrequest->id . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['hostname'] . '</b> ' . $this->cloudrequest->appliance_hostname . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['type'] . '</b> ' . $virtualization->name . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['cpu'] . '</b> ' . $str_cpu . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['ram'] . '</b> ' . $str_ram . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['kernel'] . '</b> ' . $kernel->name . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['disk'] . '</b> ' . $disk . '<br>';
                 $config_column .= '<b>' . $this->lang['create']['image'] . '</b> ' . $image->name . '<br>';
                 $config_column .= '<b>IP</b>';
                 $comment = '';
                 if (isset($this->lang['appliances']['info_' . $state])) {
                     $comment = $this->lang['appliances']['info_' . $state];
                 }
                 $ta[] = array('id' => $this->cloudrequest->id, 'state' => '<span class="pill ' . $state . '">' . $state . '</span>', 'name' => $this->cloudrequest->appliance_hostname, 'type' => $virtualization->name, 'cpu' => $this->cloudrequest->cpu_req, 'ram' => $this->cloudrequest->ram_req, 'disk' => $this->cloudrequest->disk_req, 'kernel' => $kernel->name, 'image' => $image->name, 'config' => $config_column, 'comment' => $comment, 'action' => '');
                 $app_count++;
             }
         }
     }
     // redirect if $ta is empty
     if (count($ta) > 0) {
         $table = $this->response->html->tablebuilder('cloud_table', $this->response->get_array($this->actions_name, 'appliances'));
         $table->css = 'htmlobject_table';
         $table->limit = 10;
         $table->id = 'cloud_appliances';
         $table->head = $h;
         $table->sort = 'state';
         $table->autosort = true;
         $table->sort_link = false;
         $table->actions_name = $this->actions_name;
         $table->form_action = $this->response->html->thisfile;
         $table->form_method = 'GET';
         $table->max = $app_count;
         $table->body = $ta;
         return $table;
     } else {
         $this->response->redirect($this->response->get_url($this->actions_name, 'create', $this->message_param, $this->lang['appliances']['msg_no_appliances_to_manage']));
     }
 }
Ejemplo n.º 2
0
 function CloudApplianceGetDetails($method_parameters)
 {
     global $event;
     global $RootDir;
     $parameter_array = explode(',', $method_parameters);
     $mode = $parameter_array[0];
     $username = $parameter_array[1];
     $password = $parameter_array[2];
     $ca_id = $parameter_array[3];
     // check all user input
     for ($i = 0; $i <= 3; $i++) {
         if (!$this->check_param($parameter_array[$i])) {
             $event->log("cloudsoap->CloudApplianceGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Not allowing user-intput with special-characters : {$parameter_array[$i]}", "", "", 0, 0, 0);
             return;
         }
     }
     // check parameter count
     $parameter_count = count($parameter_array);
     if ($parameter_count != 4) {
         $event->log("cloudsoap->CloudApplianceGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Wrong parameter count {$parameter_count} ! Exiting.", "", "", 0, 0, 0);
         return;
     }
     // check authentication
     if (!$this->check_user($mode, $username, $password)) {
         $event->log("cloudsoap->CloudApplianceGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "User authentication failed (mode {$mode})", "", "", 0, 0, 0);
         return;
     }
     $cr_appliance = new cloudappliance();
     $cr_appliance->get_instance_by_id($ca_id);
     // get the request to check for the user
     $cr = new cloudrequest();
     $cr->get_instance_by_id($cr_appliance->cr_id);
     $cl_user = new clouduser();
     $cl_user->get_instance_by_id($cr->cu_id);
     switch ($mode) {
         case 'user':
             if (strcmp($username, $cl_user->name)) {
                 $event->log("cloudsoap->CloudApplianceGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User {$username} is trying to get Details of Cloud User {$cl_user->name}!", "", "", 0, 0, 0);
                 return;
             }
             break;
     }
     $event->log("cloudsoap->CloudApplianceGetDetails", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Providing details for Cloud appliance {$ca_id}", "", "", 0, 0, 0);
     $cloudappliance_details = array();
     // create the array to return
     $cloudappliance_details['id'] = $ca_id;
     // appliance details
     $appliance = new appliance();
     $appliance->get_instance_by_id($cr_appliance->appliance_id);
     $cloudappliance_details['appliance_name'] = $appliance->name;
     $cloudappliance_details['appliance_state'] = $appliance->state;
     $cloudappliance_details['appliance_comment'] = $appliance->comment;
     // resource details
     $resource = new resource();
     $resource->get_instance_by_id($appliance->resources);
     $cloudappliance_details['resource_id'] = $resource->id;
     $cloudappliance_details['resource_type'] = $resource->capabilities;
     $cloudappliance_details['resource_int_ip'] = $resource->ip;
     $cloudappliance_details['resource_uptime'] = $resource->uptime;
     $cloudappliance_details['resource_cpumodel'] = $resource->cpumodel;
     $cloudappliance_details['resource_cpunumber'] = $resource->cpunumber;
     $cloudappliance_details['resource_cpuspeed'] = $resource->cpuspeed;
     $cloudappliance_details['resource_load'] = $resource->load;
     $cloudappliance_details['resource_memtotal'] = $resource->memtotal;
     $cloudappliance_details['resource_memused'] = $resource->memused;
     $cloudappliance_details['resource_swaptotal'] = $resource->swaptotal;
     $cloudappliance_details['resource_swapused'] = $resource->swapused;
     // image details
     $image = new image();
     $image->get_instance_by_id($appliance->imageid);
     $cloudappliance_details['image_name'] = $image->name;
     $cloud_image = new cloudimage();
     $cloud_image->get_instance_by_image_id($image->id);
     $cloudappliance_details['disk_size'] = $cloud_image->disk_size;
     // kernel details
     $kernel = new kernel();
     $kernel->get_instance_by_id($appliance->kernelid);
     $cloudappliance_details['kernel_name'] = $kernel->name;
     // cloud-appliance details
     $cloudappliance_details['cloud_appliance_state'] = $cr_appliance->state;
     $cloudappliance_details['cloud_appliance_cr_id'] = $cr_appliance->cr_id;
     // finding the external ip
     $appliance_resources = $appliance->resources;
     if ($appliance_resources >= 0) {
         // an appliance with a pre-selected resource
         // ip-mgmt enabled ? if yes try to get the external ip
         $cloud_ip_mgmt_config = new cloudconfig();
         $cloud_ip_mgmt = $cloud_ip_mgmt_config->get_value(26);
         // ip-mgmt enabled ?
         if (!strcmp($cloud_ip_mgmt, "true")) {
             if (file_exists($RootDir . "/plugins/ip-mgmt/.running")) {
                 require_once $RootDir . "/plugins/ip-mgmt/class/ip-mgmt.class.php";
                 $ip_mgmt = new ip_mgmt();
                 $ip_mgmt_id = $ip_mgmt->get_id_by_appliance($cr_appliance->appliance_id, 1);
                 if ($ip_mgmt_id > 0) {
                     $ipmgmt_config_arr = $ip_mgmt->get_config_by_id($ip_mgmt_id);
                     if (!strlen($ipmgmt_config_arr[0]['ip_mgmt_address'])) {
                         $event->log("cloudsoap->CloudApplianceGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Failed to get the external ip address for appliance id " . $cr_appliance->appliance_id . ". Falling back to internal ip!", "", "", 0, 0, 0);
                     } else {
                         $appliance_ip = $ipmgmt_config_arr[0]['ip_mgmt_address'];
                     }
                 } else {
                     $resource->get_instance_by_id($appliance->resources);
                     $appliance_ip = $resource->ip;
                 }
             } else {
                 // use internal ip
                 $event->log("cloudsoap->CloudApplianceGetDetails", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "IP-Mgmt is not enabled/available on this openQRM Cloud!", "", "", 0, 0, 0);
                 $resource->get_instance_by_id($appliance->resources);
                 $appliance_ip = $resource->ip;
             }
         } else {
             // in case no external ip was given to the appliance we show the internal ip
             $resource->get_instance_by_id($appliance->resources);
             $appliance_ip = $resource->ip;
         }
     } else {
         // an appliance with resource auto-select enabled
         $appliance_ip = "auto-select";
     }
     $cloudappliance_details['cloud_appliance_ip'] = $appliance_ip;
     return $cloudappliance_details;
 }
Ejemplo n.º 3
0
    function login()
    {
        $form = $this->response->get_form($this->actions_name, 'login');
        $cloud_cloudappliance_id_arr = $this->response->html->request()->get($this->identifier_name);
        $show_ip_mgmt = false;
        if (!strcmp($this->cloudconfig->get_value_by_key('ip-management'), "true")) {
            $show_ip_mgmt = true;
        }
        if (!strcmp($this->cloudconfig->get_value_by_key('show_sshterm_login'), "true")) {
            // is sshterm plugin enabled + started ?
            if (file_exists($this->rootdir . "/plugins/sshterm/.running")) {
                // get the parameters from the plugin config file
                $OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE = $this->OPENQRM_SERVER_BASE_DIR . "/openqrm/plugins/sshterm/etc/openqrm-plugin-sshterm.conf";
                $store = openqrm_parse_conf($OPENQRM_PLUGIN_SSHTERM_CONFIG_FILE);
                extract($store);
                foreach ($cloud_cloudappliance_id_arr as $key => $cloudappliance_id) {
                    $this->cloudappliance->get_instance_by_id($cloudappliance_id);
                    $this->appliance->get_instance_by_id($this->cloudappliance->appliance_id);
                    $this->cloudrequest->get_instance_by_id($this->cloudappliance->cr_id);
                    if ($this->cloudrequest->cu_id != $this->clouduser->id) {
                        // not request of the authuser
                        exit(1);
                    }
                    // here we check which ip to send to the user
                    // check ip-mgmt
                    $sshterm_login_ip = '';
                    if ($show_ip_mgmt) {
                        if (file_exists($this->rootdir . "/plugins/ip-mgmt/.running")) {
                            require_once $this->rootdir . "/plugins/ip-mgmt/class/ip-mgmt.class.php";
                            $ip_mgmt = new ip_mgmt();
                            $appliance_first_nic_ip_mgmt_id = $ip_mgmt->get_id_by_appliance($this->cloudappliance->appliance_id, 1);
                            if ($appliance_first_nic_ip_mgmt_id > 0) {
                                $appliance_ip_mgmt_config_arr = $ip_mgmt->get_instance('id', $appliance_first_nic_ip_mgmt_id);
                                if (isset($appliance_ip_mgmt_config_arr['ip_mgmt_address'])) {
                                    $sshterm_login_ip = $appliance_ip_mgmt_config_arr['ip_mgmt_address'];
                                }
                            }
                        }
                    }
                    if (!strlen($sshterm_login_ip)) {
                        // in case no external ip was given to the appliance we show the internal ip
                        $this->resourde->get_instance_by_id($this->appliance->resources);
                        $sshterm_login_ip = $this->resourde->ip;
                    }
                    if (!strlen($sshterm_login_ip)) {
                        continue;
                    }
                    $redirect_url = "https://{$sshterm_login_ip}:{$OPENQRM_PLUGIN_WEBSHELL_PORT}";
                    $left = 50 + $cloudappliance_id * 50;
                    $top = 100 + $cloudappliance_id * 50;
                    // add the javascript function to open an sshterm
                    ?>
								<script type="text/javascript">
								function open_sshterm (url) {
									sshterm_window = window.open(url, "<?php 
                    echo $sshterm_login_ip;
                    ?>
", "width=580,height=420,scrollbars=1,left=<?php 
                    echo $left;
                    ?>
,top=<?php 
                    echo $top;
                    ?>
");
									open_sshterm.focus();
								}
								open_sshterm("<?php 
                    echo $redirect_url;
                    ?>
");
								</script>
					<?php 
                }
            }
        }
        flush();
        $this->response->redirect($this->response->get_url($this->actions_name, 'appliances'));
        return $form;
    }