function action()
 {
     $virtualization = new virtualization();
     $virtualization_list = array();
     $virtualization_list = $virtualization->get_list();
     $virtualization_link_section = "";
     // filter out the virtualization hosts
     foreach ($virtualization_list as $id => $virt) {
         $virtualization_id = $virt['value'];
         $available_virtualization = new virtualization();
         $available_virtualization->get_instance_by_id($virtualization_id);
         if (strstr($available_virtualization->type, "-vm")) {
             $virtualization_plugin_name = $available_virtualization->get_plugin_name();
             $virtualization_name = str_replace(" VM", "", $available_virtualization->name);
             $a = $this->response->html->a();
             $a->href = $this->response->get_url($this->actions_name, 'load') . '&rplugin=' . $virtualization_plugin_name . '&rcontroller=' . $virtualization_plugin_name . "-vm";
             $a->label = '<img title="' . sprintf($this->lang['create_vm'], $virtualization_plugin_name) . '" alt="' . sprintf($this->lang['create_vm'], $virtualization_plugin_name) . '" src="/openqrm/base/plugins/' . $virtualization_plugin_name . '/img/plugin.png" border=0>' . $virtualization_name . ' ' . $this->lang['vm'];
             #$new_vm_link = "/openqrm/base/index.php?plugin=".$virtualization_plugin_name."&controller=".$virtualization_plugin_name."-vm";
             #$virtualization_link_section .= "<a href='".$new_vm_link."' style='text-decoration: none'><img title='".sprintf($this->lang['create_vm'], $virtualization_plugin_name)."' alt='".sprintf($this->lang['create_vm'], $virtualization_plugin_name)."' src='/openqrm/base/plugins/".$virtualization_plugin_name."/img/plugin.png' border=0> ".$virtualization_name." ".$this->lang['vm']."</a><br>";
             $virtualization_link_section .= $a->get_string() . '<br>';
         }
     }
     if (!strlen($virtualization_link_section)) {
         $virtualization_link_section = $this->lang['start_vm_plugin'];
     }
     // local-server plugin enabled and started
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/openqrm/base/plugins/local-server/.running")) {
         $a = $this->response->html->a();
         $a->href = $this->response->get_url($this->actions_name, 'load') . '&rplugin=local-server&rcontroller=local-server-about&local_server_about_action=usage';
         $a->label = '<img title="' . $this->lang['integrate_local_server'] . '" alt="' . $this->lang['integrate_local_server'] . '" src="/openqrm/base/plugins/local-server/img/plugin.png" border="0">' . $this->lang['integrate_local_server'];
         $local_server_plugin_link = $a->get_string() . '<br>';
         #$local_server_plugin_link = "<a href='/openqrm/base/index.php?plugin=local-server&controller=local-server-about&local_server_about_action=usage' style='text-decoration: none'><img title='".$this->lang['integrate_local_server']."' alt='".$this->lang['integrate_local_server']."' src='/openqrm/base/plugins/local-server/img/plugin.png' border=0> ".$this->lang['integrate_local_server']."</a>";
     } else {
         $local_server_plugin_link = $this->lang['start_local_server'];
     }
     // manual add new resource
     $manual_new_resource_link = "<a href='/openqrm/base/index.php?base=resource&resource_action=new' style='text-decoration: none'><img title='" . $this->lang['manual_new_resource'] . "' alt='" . $this->lang['manual_new_resource'] . "' src='/openqrm/base/img/resource.png' border=0> " . $this->lang['manual_new_resource'] . "</a>";
     $t = $this->response->html->template($this->tpldir . '/resource-add.tpl.php');
     $t->add($virtualization_link_section, 'resource_virtual');
     $t->add($local_server_plugin_link, 'resource_local');
     $t->add($manual_new_resource_link, 'resource_new');
     $t->add($this->lang['title'], 'label');
     $t->add($this->lang['vm_type'], 'vm_type');
     $t->add($this->lang['local'], 'local');
     $t->add($this->lang['unmanaged'], 'unmanaged');
     $t->add($this->openqrm->get('baseurl'), 'baseurl');
     $t->add($this->lang['please_wait'], 'please_wait');
     $t->add($this->lang['canceled'], 'canceled');
     $t->add($this->prefix_tab, 'prefix_tab');
     $t->group_elements(array('param_' => 'form'));
     return $t;
 }
function openqrm_hybrid_cloud_cloud_product($cmd, $cloud_hook_config)
{
    global $event;
    global $OPENQRM_SERVER_BASE_DIR;
    global $OPENQRM_SERVER_IP_ADDRESS;
    global $OPENQRM_EXEC_PORT;
    global $RootDir;
    $openqrm_server = new openqrm_server();
    $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Handling " . $cmd . " event", "", "", 0, 0, 0);
    switch ($cmd) {
        case "add":
            $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Handling cloud-product " . $cmd . " event", "", "", 0, 0, 0);
            // create resource products
            $db = openqrm_get_db_connection();
            $image = new image();
            $checked_virtualization_plugins = array();
            $virtualization = new virtualization();
            $virtualization_id_ar = $virtualization->get_list();
            unset($virtualization_id_ar[0]);
            foreach ($virtualization_id_ar as $key => $value) {
                $next_sort_id = 0;
                $id = $value['value'];
                $virtualization->get_instance_by_id($id);
                $pos = strpos($virtualization->type, 'hybrid-cloud-vm-');
                if ($pos !== false) {
                    $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Adding " . $virtualization->type . " as cloud-product", "", "", 0, 0, 0);
                    $cloud_product_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                    $create_resource_cloudselector_config = "insert into cloud_selector (id, type, sort_id, quantity, price, name, description, state) VALUES (" . $cloud_product_id . ", 'resource', " . $next_sort_id . ", '" . $virtualization->id . "', 1, '" . $virtualization->type . "', '" . $virtualization->name . "', 1);";
                    $recordSet = $db->Execute($create_resource_cloudselector_config);
                    $next_sort_id++;
                    // add all existing images for this virtualization type to private images
                    $virtualization_plugin_name = $virtualization->get_plugin_name();
                    if (!in_array($virtualization_plugin_name, $checked_virtualization_plugins)) {
                        $checked_virtualization_plugins[] = $virtualization_plugin_name;
                        $deployment = new deployment();
                        $deployment_id_ar = $deployment->get_id_by_storagetype($virtualization_plugin_name);
                        foreach ($deployment_id_ar as $key => $value) {
                            $did = $value['value'];
                            $deployment->get_instance_by_id($did);
                            $image_id_deployment_ar = $image->get_ids_by_type($deployment->type);
                            foreach ($image_id_deployment_ar as $iid_ar) {
                                // add to private images
                                $image_id = $iid_ar['image_id'];
                                $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Adding Image " . $image_id . " as private image", "", "", 0, 0, 0);
                                $cloud_pr_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                                $create_private_image_config = "insert into cloud_private_image (co_id, co_image_id, co_cu_id, co_clone_on_deploy, co_state) VALUES (" . $cloud_pr_id . ", " . $image_id . ", 0, 1, 1);";
                                $recordSet = $db->Execute($create_private_image_config);
                            }
                        }
                    }
                }
            }
            // add host to admin resource pool
            $admin_project_id = $cloud_hook_config['cloud_admin_procect'];
            $virtualization->get_instance_by_type('hybrid-cloud');
            $appliance = new appliance();
            $appliance_id_ar = $appliance->get_ids_per_virtualization($virtualization->id);
            foreach ($appliance_id_ar as $key => $value) {
                $appliance_id = $value['appliance_id'];
                $appliance->get_instance_by_id($appliance_id);
                $cloud_respool_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
                $create_default_resource_pool_config = "insert into cloud_respool(rp_id, rp_resource_id, rp_cg_id) values (" . $cloud_respool_id . ", " . $appliance->resources . ", " . $admin_project_id . ");";
                $recordSet = $db->Execute($create_default_resource_pool_config);
            }
            break;
        case "remove":
            $cloud_product_class = $RootDir . "/plugins/cloud/class/cloudselector.class.php";
            if (file_exists($cloud_product_class)) {
                require_once $cloud_product_class;
                $cloud_selector = new cloudselector();
                $virtualization = new virtualization();
                $virtualization->get_instance_by_type('hybrid-cloud-vm-local');
                $event->log("openqrm_hybrid_cloud_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-hybrid-cloud-cloud-product-hook.php", "Removing resource type " . $virtualization->type . " from cloud-products", "", "", 0, 0, 0);
                $cloud_selector->remove_by_quantity($virtualization->id);
            }
            break;
    }
}
 function get_response()
 {
     $response = $this->response;
     $form = $response->get_form($this->actions_name, 'edit');
     $id = $this->apliance_id;
     $submit = $form->get_elements('submit');
     $submit->handler = 'onclick="wait();"';
     $form->add($submit, 'submit');
     $submit = $form->get_elements('cancel');
     $submit->handler = 'onclick="cancel();"';
     $form->add($submit, 'cancel');
     $appliance = new appliance();
     $appliance->get_instance_by_id($id);
     $resource = new resource();
     $list = $resource->get_list();
     $cpus[0] = array(0, $this->lang['option_auto']);
     $cspe[0] = array(0, $this->lang['option_auto']);
     $cmod[0] = array(0, $this->lang['option_auto']);
     $nics[0] = array(0, $this->lang['option_auto']);
     $memt[0] = array(0, $this->lang['option_auto']);
     $swap[0] = array(0, $this->lang['option_auto']);
     foreach ($list as $v) {
         $resource->get_instance_by_id($v['resource_id']);
         $c = $resource->cpunumber;
         $cs = $resource->cpuspeed;
         $cm = $resource->cpumodel;
         $n = $resource->nics;
         $m = $resource->memtotal;
         $s = $resource->swaptotal;
         if (isset($c) && $c != '0') {
             $cpus[$c] = array($c, $c);
         }
         if (isset($cs) && $cs != '0') {
             $cspe[$cs] = array($cs, $cs);
         }
         if (isset($cm) && $cm != '0' && $cm !== '') {
             $cmod[$cm] = array($cm, $cm);
         }
         if (isset($n) && $n != '0') {
             $nics[$n] = array($n, $n);
         }
         if (isset($m) && $m != '0') {
             $memt[$m] = array($m, $m);
         }
         if (isset($s) && $s != '0') {
             $swap[$s] = array($s, $s);
         }
     }
     ksort($cpus, SORT_NUMERIC);
     ksort($cspe, SORT_NUMERIC);
     ksort($cmod, SORT_STRING);
     ksort($nics, SORT_NUMERIC);
     ksort($memt, SORT_NUMERIC);
     ksort($swap, SORT_NUMERIC);
     $d['cpus']['label'] = $this->lang['form_cpus'];
     $d['cpus']['object']['type'] = 'htmlobject_select';
     $d['cpus']['object']['attrib']['index'] = array(0, 1);
     $d['cpus']['object']['attrib']['name'] = 'appliance_cpunumber';
     $d['cpus']['object']['attrib']['options'] = $cpus;
     $d['cpus']['object']['attrib']['selected'] = array($appliance->cpunumber);
     $d['cpuspeed']['label'] = $this->lang['form_cpuspeed'];
     $d['cpuspeed']['object']['type'] = 'htmlobject_select';
     $d['cpuspeed']['object']['attrib']['index'] = array(0, 1);
     $d['cpuspeed']['object']['attrib']['name'] = 'appliance_cpuspeed';
     $d['cpuspeed']['object']['attrib']['options'] = $cspe;
     $d['cpuspeed']['object']['attrib']['selected'] = array($appliance->cpuspeed);
     $d['cpumodel']['label'] = $this->lang['form_cpumodel'];
     $d['cpumodel']['object']['type'] = 'htmlobject_select';
     $d['cpumodel']['object']['attrib']['index'] = array(0, 1);
     $d['cpumodel']['object']['attrib']['name'] = 'appliance_cpumodel';
     $d['cpumodel']['object']['attrib']['options'] = $cmod;
     $d['cpumodel']['object']['attrib']['selected'] = array($appliance->cpumodel);
     $d['nics']['label'] = $this->lang['form_nics'];
     $d['nics']['object']['type'] = 'htmlobject_select';
     $d['nics']['object']['attrib']['index'] = array(0, 1);
     $d['nics']['object']['attrib']['name'] = 'appliance_nics';
     $d['nics']['object']['attrib']['options'] = $nics;
     $d['nics']['object']['attrib']['selected'] = array($appliance->nics);
     $d['memory']['label'] = $this->lang['form_memory'];
     $d['memory']['object']['type'] = 'htmlobject_select';
     $d['memory']['object']['attrib']['index'] = array(0, 1);
     $d['memory']['object']['attrib']['name'] = 'appliance_memtotal';
     $d['memory']['object']['attrib']['options'] = $memt;
     $d['memory']['object']['attrib']['selected'] = array($appliance->memtotal);
     $d['swap']['label'] = $this->lang['form_swap'];
     $d['swap']['object']['type'] = 'htmlobject_select';
     $d['swap']['object']['attrib']['index'] = array(0, 1);
     $d['swap']['object']['attrib']['name'] = 'appliance_swaptotal';
     $d['swap']['object']['attrib']['options'] = $swap;
     $d['swap']['object']['attrib']['selected'] = array($appliance->swaptotal);
     $resource = new resource();
     $resource_hostname = '';
     if (isset($appliance->resources) && $appliance->resources !== '') {
         if ($appliance->resources >= 0) {
             $res = $resource->get_instance_by_id($appliance->resources);
             $resource_hostname = $res->hostname;
         } else {
             $resource_hostname = 'auto-select';
         }
     }
     $a = $response->html->a();
     $a->name = '';
     #$a->label = '<img src="'.$this->controller->get('baseurl').'/img/resource.png">&#160;'.sprintf($this->lang['action_resource'], $resource_hostname);
     $a->label = $resource_hostname;
     $a->css = "manage";
     $a->title = sprintf($this->lang['action_resource'], $resource_hostname);
     $a->href = $response->get_url($this->actions_name, 'step2');
     $d['resource']['label'] = $this->lang['form_resource'];
     $d['resource']['object'] = $a;
     $img = new image();
     $img = $img->get_instance_by_id($appliance->imageid);
     $a = $response->html->a();
     $a->name = '';
     #$a->label = '<img src="'.$this->controller->get('baseurl').'/img/image.png">&#160;'.sprintf($this->lang['action_image'], $img->name) ;
     $a->label = $img->name;
     $a->css = "manage";
     $a->title = sprintf($this->lang['action_image'], $img->name);
     $a->href = $response->get_url($this->actions_name, 'step3');
     $d['image']['label'] = $this->lang['form_image'];
     $d['image']['object'] = $a;
     $kern = new kernel();
     $kern = $kern->get_instance_by_id($appliance->kernelid);
     $a = $response->html->a();
     $a->name = '';
     #$a->label = '<img src="'.$this->controller->get('baseurl').'/img/image.png">&#160;'.sprintf($this->lang['action_image'], $img->name) ;
     $a->label = $kern->name;
     $a->css = "manage";
     $a->title = sprintf($this->lang['action_kernel'], $kern->name);
     $a->href = $response->get_url($this->actions_name, 'step4');
     $d['kernel']['label'] = $this->lang['form_kernel'];
     $d['kernel']['object'] = $a;
     $virtualization = new virtualization();
     if (isset($appliance->resources) && $appliance->resources !== '') {
         $resource->get_instance_by_id($appliance->resources);
     }
     $vl = array();
     $list = $virtualization->get_list();
     foreach ($list as $v) {
         if (strpos($v['label'], ' VM') === false) {
             $vl[] = array($v['label'], $v['value']);
         } else {
             if ($v['value'] === $resource->vtype) {
                 $hide_virtualization = true;
                 break;
             }
         }
     }
     asort($vl);
     if (isset($hide_virtualization)) {
         $virtualization->get_instance_by_id($resource->vtype);
         $div = $this->response->html->div();
         $div->name = '';
         $div->add($virtualization->name);
         $d['virtualization']['label'] = $this->lang['form_virtualization'];
         $d['virtualization']['object'] = $div;
     } else {
         $d['virtualization']['label'] = $this->lang['form_virtualization'];
         $d['virtualization']['object']['type'] = 'htmlobject_select';
         $d['virtualization']['object']['attrib']['index'] = array(1, 0);
         $d['virtualization']['object']['attrib']['name'] = 'appliance_virtualization';
         $d['virtualization']['object']['attrib']['options'] = $vl;
         $d['virtualization']['object']['attrib']['selected'] = array($appliance->virtualization);
     }
     $d['capabilities']['label'] = $this->lang['form_capabilities'];
     $d['capabilities']['object']['type'] = 'htmlobject_input';
     $d['capabilities']['object']['attrib']['type'] = 'text';
     $d['capabilities']['object']['attrib']['name'] = 'appliance_capabilities';
     $d['capabilities']['object']['attrib']['value'] = $appliance->capabilities;
     $d['capabilities']['object']['attrib']['maxlength'] = 1000;
     $d['comment']['label'] = $this->lang['form_comment'];
     $d['comment']['validate']['regex'] = $this->openqrm->regex['comment'];
     $d['comment']['validate']['errormsg'] = sprintf($this->lang['error_comment'], $this->openqrm->regex['comment']);
     $d['comment']['object']['type'] = 'htmlobject_textarea';
     $d['comment']['object']['attrib']['name'] = 'appliance_comment';
     $d['comment']['object']['attrib']['value'] = $appliance->comment;
     $d['comment']['object']['attrib']['maxlength'] = 255;
     $form->add($d);
     $response->form = $form;
     return $response;
 }
 function select()
 {
     $d = array();
     $h = array();
     $h['resource_state']['title'] = $this->lang['table_state'];
     $h['resource_state']['sortable'] = false;
     $h['resource_id']['title'] = $this->lang['table_id'];
     $h['resource_id']['hidden'] = true;
     $h['resource_hostname']['title'] = $this->lang['table_name'];
     $h['resource_hostname']['hidden'] = true;
     $h['resource_mac']['title'] = $this->lang['table_mac'];
     $h['resource_mac']['hidden'] = true;
     $h['resource_ip']['title'] = $this->lang['table_ip'];
     $h['resource_ip']['hidden'] = true;
     $h['resource_type']['title'] = $this->lang['table_type'];
     $h['resource_type']['sortable'] = false;
     $h['resource_type']['hidden'] = true;
     $h['resource_memtotal']['title'] = $this->lang['table_memory'];
     $h['resource_memtotal']['hidden'] = true;
     $h['resource_cpunumber']['title'] = $this->lang['table_cpu'];
     $h['resource_cpunumber']['hidden'] = true;
     $h['resource_nics']['title'] = $this->lang['table_nics'];
     $h['resource_nics']['hidden'] = true;
     $h['resource_load']['title'] = $this->lang['table_load'];
     $h['resource_load']['hidden'] = true;
     $h['data']['title'] = '&#160;';
     $h['data']['sortable'] = false;
     $h['hw']['title'] = '&#160;';
     $h['hw']['sortable'] = false;
     $resource = new resource();
     $params = $this->response->get_array($this->actions_name, 'select');
     $b = array();
     #$this->response->html->help($resource->find_resource('00:e0:53:13'));
     // unset unnecessary params
     unset($params['resource_type_filter']);
     unset($params['resource_filter']);
     unset($params['resource[sort]']);
     unset($params['resource[order]']);
     unset($params['resource[limit]']);
     unset($params['resource[offset]']);
     $table = $this->response->html->tablebuilder('resource', $params);
     $table->offset = 0;
     $table->sort = 'resource_id';
     $table->limit = 20;
     $table->order = 'ASC';
     $table->max = $resource->get_count('all');
     $table->init();
     // handle table params
     $tps = $table->get_params();
     $tp = '';
     foreach ($tps['resource'] as $k => $v) {
         $tp .= '&resource[' . $k . ']=' . $v;
     }
     $resource_filter = null;
     if ($this->response->html->request()->get('resource_filter') !== '') {
         $resource_filter = array();
         $ar = $resource->find_resource($this->response->html->request()->get('resource_filter'));
         if (count($ar) > 0) {
             foreach ($ar as $k => $v) {
                 $resource_filter[] = $v['resource_id'];
             }
         }
     }
     $resources = $resource->display_overview(0, 10000, $table->sort, $table->order);
     foreach ($resources as $index => $resource_db) {
         // prepare the values for the array
         $resource = new resource();
         $resource->get_instance_by_id($resource_db["resource_id"]);
         $res_id = $resource->id;
         if ($this->response->html->request()->get('resource_type_filter') === '' || $this->response->html->request()->get('resource_type_filter') == $resource->vtype) {
             // Skip all resources not in $resource_filter
             if (isset($resource_filter)) {
                 if (!in_array($resource->id, $resource_filter)) {
                     continue;
                 }
             }
             $mem_total = $resource_db['resource_memtotal'];
             $mem_used = $resource_db['resource_memused'];
             $mem = "{$mem_used}/{$mem_total}";
             $swap_total = $resource_db['resource_swaptotal'];
             $swap_used = $resource_db['resource_swapused'];
             $swap = "{$swap_used}/{$swap_total}";
             $resource_mac = $resource_db["resource_mac"];
             // the resource_type
             $link = '';
             if (strlen($resource->vtype) && !strstr($resource->vtype, "NULL")) {
                 // find out what should be preselected
                 $virtualization = new virtualization();
                 $virtualization->get_instance_by_id($resource->vtype);
                 $virtualization_plugin_name = $virtualization->get_plugin_name();
                 $virtualization_vm_action_name = str_replace("-", "_", $virtualization_plugin_name);
                 if ($virtualization->id == 1) {
                     $resource_type = $virtualization->name;
                 } else {
                     $resource_type_link_text = $virtualization->name;
                     if ($resource->id == $resource->vhostid) {
                         // physical system or host
                         $host_appliance = new appliance();
                         $host_appliance->get_instance_by_virtualization_and_resource($virtualization->id, $resource->id);
                         if ($virtualization->id > 0 && $resource->id > 0) {
                             $link = '?plugin=' . $virtualization_plugin_name . '&controller=' . $virtualization_plugin_name . '-vm&' . $virtualization_vm_action_name . '_vm_action=edit&appliance_id=' . $host_appliance->id;
                             $resource_type_link_text = "<nobr>" . $virtualization->name . " Server " . $host_appliance->name . "</nobr>";
                         }
                     } else {
                         // vm
                         $host_virtualization = new virtualization();
                         $host_virtualization->get_instance_by_type($virtualization_plugin_name);
                         $host_appliance = new appliance();
                         if ($host_virtualization->id > 0) {
                             $host_appliance->get_instance_by_virtualization_and_resource($host_virtualization->id, $resource->vhostid);
                             $host_resource = new resource();
                             $host_resource->get_instance_by_id($resource->vhostid);
                             $link = '?plugin=' . $virtualization_plugin_name . '&controller=' . $virtualization_plugin_name . '-vm&' . $virtualization_vm_action_name . '_vm_action=edit&appliance_id=' . $host_appliance->id;
                             $resource_type_link_text = "<nobr>" . $virtualization->name . " on Res. " . $host_resource->hostname . "</nobr>";
                         }
                     }
                     $resource_type = $resource_type_link_text;
                 }
             } else {
                 $resource_type = "Unknown";
             }
             // openQRM resource ?
             if ($resource->id == 0) {
                 $resource_icon_default = "/openqrm/base/img/logo.png";
             } else {
                 $resource_icon_default = "/openqrm/base/img/resource.png";
             }
             $state_icon = '<span class="pill ' . $resource->state . '">' . $resource->state . '</span>';
             // idle ?
             if ("{$resource->imageid}" == "1" && "{$resource->state}" == "active") {
                 $state_icon = '<span class="pill idle">idle</span>';
             }
             $resource_cpus = $resource_db["resource_cpunumber"];
             if (!strlen($resource_cpus)) {
                 $resource_cpus = '?';
             }
             $resource_nics = $resource_db["resource_nics"];
             if (!strlen($resource_nics)) {
                 $resource_nics = '?';
             }
             isset($resource_db["resource_hostname"]) ? $name = $resource_db["resource_hostname"] : ($name = '&#160;');
             isset($resource_db["resource_nics"]) ? $nics = $resource_db["resource_nics"] : ($nics = '&#160;');
             isset($resource_db["resource_load"]) ? $load = $resource_db["resource_load"] : ($load = '&#160;');
             $data = '<b>' . $this->lang['table_id'] . '</b>: ' . $resource_db["resource_id"] . '<br>';
             $data .= '<b>' . $this->lang['table_name'] . '</b>: ' . $name . '<br>';
             $data .= '<b>' . $this->lang['table_mac'] . '</b>: ' . $resource_mac . '<br>';
             $data .= '<b>' . $this->lang['table_ip'] . '</b>: ' . $resource_db["resource_ip"] . '<br>';
             $data .= '<b>' . $this->lang['table_type'] . '</b>: ' . $resource_type;
             $hw = '<b>' . $this->lang['table_cpu'] . '</b>: ' . $resource_cpus . '<br>';
             $hw .= '<b>' . $this->lang['table_memory'] . '</b>: ' . $mem . '<br>';
             $hw .= '<b>' . $this->lang['table_nics'] . '</b>: ' . $nics . '<br>';
             $hw .= '<b>' . $this->lang['table_load'] . '</b>: ' . $load;
             $b[] = array('resource_state' => $state_icon, 'resource_id' => $resource_db["resource_id"], 'resource_hostname' => $name, 'resource_mac' => $resource_mac, 'resource_ip' => $resource_db["resource_ip"], 'resource_type' => $resource_type, 'resource_memtotal' => $mem, 'resource_cpunumber' => $resource_cpus, 'resource_nics' => $nics, 'resource_load' => $load, 'data' => $data, 'hw' => $hw);
         }
     }
     // Type Filter
     $virtulization_types = new virtualization();
     $list = $virtulization_types->get_list();
     $filter = array();
     $filter[] = array('', '');
     foreach ($list as $l) {
         $filter[] = array($l['label'], $l['value']);
     }
     asort($filter);
     $select = $this->response->html->select();
     $select->add($filter, array(1, 0));
     $select->name = 'resource_type_filter';
     $select->handler = 'onchange="wait();this.form.submit();return false;"';
     $select->selected = array($this->response->html->request()->get('resource_type_filter'));
     $box1 = $this->response->html->box();
     $box1->add($select);
     $box1->id = 'resource_type_filter';
     $box1->css = 'htmlobject_box';
     $box1->label = $this->lang['lang_type_filter'];
     // Resource Filter
     $input = $this->response->html->input();
     $input->name = 'resource_filter';
     $input->value = $this->response->html->request()->get('resource_filter');
     $input->title = $this->lang['lang_filter_title'];
     $box2 = $this->response->html->box();
     $box2->add($input);
     $box2->id = 'resource_filter';
     $box2->css = 'htmlobject_box';
     $box2->label = $this->lang['lang_filter'];
     $add = $this->response->html->a();
     $add->title = $this->lang['action_add'];
     $add->label = $this->lang['action_add'];
     $add->handler = 'onclick="wait();"';
     $add->css = 'add';
     $add->href = $this->response->get_url($this->actions_name, "add") . '' . $tp;
     $table->id = 'Tabelle';
     $table->css = 'htmlobject_table';
     $table->border = 1;
     $table->cellspacing = 0;
     $table->cellpadding = 3;
     $table->autosort = false;
     $table->sort_link = false;
     $table->head = $h;
     $table->body = $b;
     $table->max = count($b);
     $table->actions_name = $this->actions_name;
     $table->actions = array(array('reboot' => $this->lang['action_reboot']), array('poweroff' => $this->lang['action_poweroff']), array('remove' => $this->lang['action_remove']));
     $table->identifier = 'resource_id';
     $table->identifier_name = $this->identifier_name;
     $table->identifier_disabled = array(0);
     $table->limit_select = array(array("value" => 10, "text" => 10), array("value" => 20, "text" => 20), array("value" => 30, "text" => 30), array("value" => 50, "text" => 50), array("value" => 100, "text" => 100));
     $d['form'] = $this->response->get_form($this->actions_name, 'select', false)->get_elements();
     $d['add'] = $add->get_string();
     $d['resource_type_filter'] = $box1->get_string();
     $d['resource_filter'] = $box2->get_string();
     $d['table'] = $table;
     return $d;
 }
Exemple #5
0
 function VirtualizationGetList($method_parameters)
 {
     global $event;
     $parameter_array = explode(',', $method_parameters);
     $mode = $parameter_array[0];
     $username = $parameter_array[1];
     $password = $parameter_array[2];
     // check all user input
     for ($i = 0; $i <= 2; $i++) {
         if (!$this->check_param($parameter_array[$i])) {
             $event->log("cloudsoap->VirtualizationGetList", $_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 != 3) {
         $event->log("cloudsoap->VirtualizationGetList", $_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->VirtualizationGetList", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "User authentication failed (mode {$mode})", "", "", 0, 0, 0);
         return;
     }
     $event->log("cloudsoap->VirtualizationGetList", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Providing list of available virtualizations", "", "", 0, 0, 0);
     $virtualization = new virtualization();
     $virtualization_list = $virtualization->get_list();
     $virtualization_name_list = array();
     $virtualization_return_list = array();
     foreach ($virtualization_list as $virtualizations) {
         $virtualization_name_list[] = $virtualizations['label'];
     }
     // check if to show physical system type
     $cc_conf = new cloudconfig();
     $cc_request_physical_systems = $cc_conf->get_value(4);
     // request_physical_systems
     if (!strcmp($cc_request_physical_systems, "false")) {
         array_shift($virtualization_name_list);
     }
     // filter out the virtualization hosts
     $cloudselector = new cloudselector();
     $cloud_selector_enabled = $cc_conf->get_value(22);
     // cloudselector
     foreach ($virtualization_name_list as $virt) {
         if (!strstr($virt, "Host")) {
             // check cloudselector
             if (!strcmp($cloud_selector_enabled, "true")) {
                 // virtualization
                 $cs_virt_type = new virtualization();
                 $cs_virt_type->get_instance_by_name($virt);
                 if ($cloudselector->product_exists_enabled("resource", $cs_virt_type->id)) {
                     $virtualization_return_list[] = $virt;
                 }
             } else {
                 $virtualization_return_list[] = $virt;
             }
         }
     }
     return $virtualization_return_list;
 }
 function server_list()
 {
     require_once $this->controller->openqrm->get('basedir') . '/web/base/class/appliance.class.php';
     require_once $this->controller->openqrm->get('basedir') . '/web/base/class/virtualization.class.php';
     $virtObj = new virtualization();
     $list = $virtObj->get_list();
     foreach ($list as $virtualization) {
         $virtualizationMap[$virtualization['value']] = $virtualization['label'];
     }
     $applianceObj = new appliance();
     $list = $applianceObj->display_overview(0, 1000, 'appliance_id', '');
     $applist = array();
     $i = 0;
     foreach ($list as $appliance) {
         // check virtualization type exists
         if (isset($virtualizationMap[$appliance['appliance_virtualization']])) {
             $applist[$i]['appliance_virtualization'] = $virtualizationMap[$appliance['appliance_virtualization']];
             $i++;
         }
     }
     echo json_encode($applist);
     exit(0);
 }
    function select()
    {
        $d = array();
        $h = array();
        $h['appliance_state']['title'] = $this->lang['table_state'];
        $h['appliance_id']['title'] = $this->lang['table_id'];
        $h['appliance_id']['hidden'] = true;
        $h['appliance_name']['title'] = $this->lang['table_name'];
        $h['appliance_name']['hidden'] = true;
        $h['appliance_values']['title'] = '&#160;';
        $h['appliance_values']['sortable'] = false;
        $h['appliance_comment']['title'] = '&#160;';
        $h['appliance_comment']['sortable'] = false;
        $h['appliance_virtualization']['title'] = 'Type';
        $h['appliance_virtualization']['sortable'] = true;
        $h['appliance_virtualization']['hidden'] = true;
        $h['appliance_edit']['sortable'] = false;
        $appliance = new appliance();
        $params = $this->response->get_array($this->actions_name, 'select');
        $b = array();
        // unset unnecessary params
        unset($params['resource_type_filter']);
        unset($params['resource_filter']);
        unset($params['appliance[sort]']);
        unset($params['appliance[order]']);
        unset($params['appliance[limit]']);
        unset($params['appliance[offset]']);
        $table = $this->response->html->tablebuilder('appliance', $params);
        $table->offset = 0;
        $table->sort = 'appliance_id';
        $table->limit = 20;
        $table->order = 'ASC';
        $table->max = $appliance->get_count();
        $table->init();
        // handle table params
        #$tps = $table->get_params();
        $tp = '';
        #foreach($tps['appliance'] as $k => $v) {
        #	$tp .= '&appliance['.$k.']='.$v;
        #}
        $resource_filter = null;
        if ($this->response->html->request()->get('resource_filter') !== '') {
            $resource = $this->openqrm->resource();
            $resource_filter = array();
            $ar = $resource->find_resource($this->response->html->request()->get('resource_filter'));
            if (count($ar) > 0) {
                foreach ($ar as $k => $v) {
                    $resource_filter[] = $v['resource_id'];
                }
            }
        }
        $disabled = array();
        $appliances = $appliance->display_overview(0, 10000, $table->sort, $table->order);
        foreach ($appliances as $index => $appliance_db) {
            $appliance = new appliance();
            $appliance->get_instance_by_id($appliance_db["appliance_id"]);
            $resource = new resource();
            $resource->get_instance_by_id($appliance->resources);
            $appliance_resources = $appliance_db["appliance_resources"];
            $kernel = new kernel();
            $kernel->get_instance_by_id($appliance_db["appliance_kernelid"]);
            $image = new image();
            $image->get_instance_by_id($appliance_db["appliance_imageid"]);
            $virtualization = new virtualization();
            $virtualization->get_instance_by_id($appliance_db["appliance_virtualization"]);
            $appliance_virtualization_name = $virtualization->name;
            $virtualization_plugin_name = $virtualization->get_plugin_name();
            $resource_is_local_server = false;
            if ($this->response->html->request()->get('resource_type_filter') === '' || $this->response->html->request()->get('resource_type_filter') == $resource->vtype) {
                // Skip all resources not in $resource_filter
                if (isset($resource_filter)) {
                    if (!in_array($resource->id, $resource_filter)) {
                        continue;
                    }
                }
                if ($appliance_resources >= 0) {
                    // an appliance with a pre-selected resource
                    $resource->get_instance_by_id($appliance_resources);
                    $resource_state_icon = '<span class="pill ' . $resource->state . '">' . $resource->state . '</span>';
                    // idle ?
                    if ("{$resource->imageid}" == "1" && "{$resource->state}" == "active") {
                        $resource_state_icon = '<span class="pill idle">idle</span>';
                    }
                    // link to resource list
                    $virtualization_vm_action_name = $virtualization->name;
                    if (strstr($resource->capabilities, "TYPE=local-server")) {
                        $resource_is_local_server = true;
                    }
                    $appliance_resources_str = '';
                    if (strpos($virtualization->type, "-vm")) {
                        $host_resource = new resource();
                        $host_resource->get_instance_by_id($resource->vhostid);
                        $host_virtualization = new virtualization();
                        $host_virtualization_name = $virtualization->get_plugin_name();
                        $host_virtualization->get_instance_by_type($host_virtualization_name);
                        $host_appliance = new appliance();
                        $host_appliance->get_instance_by_virtualization_and_resource($host_virtualization->id, $resource->vhostid);
                        $link = '?base=appliance&appliance_action=load_select';
                        $link .= '&aplugin=' . $virtualization_plugin_name;
                        $link .= '&amp;acontroller=' . $virtualization_plugin_name . '-vm';
                        $link .= '&amp;' . $virtualization_plugin_name . '_vm_action=update';
                        $link .= '&amp;appliance_id=' . $host_appliance->id;
                        $link .= '&amp;vm=' . $resource->hostname;
                        $appliance_resources_str = '<a href="' . $this->response->html->thisfile . $link . '" onclick="wait();">' . $resource->hostname . '</a> ' . $resource_state_icon;
                    } else {
                        $appliance_resources_str = $resource->hostname . ' ' . $resource_state_icon;
                    }
                } else {
                    // an appliance with resource auto-select enabled
                    $appliance_resources_str = "auto-select";
                }
                // active or inactive
                $resource_icon_default = "/openqrm/base/img/appliance.png";
                $active_state_icon = '<span class="pill active">active</span>';
                $inactive_state_icon = '<span class="pill inactive">incative</span>';
                if ($appliance->stoptime == 0 || $appliance_resources == 0) {
                    $state_icon = $active_state_icon;
                } else {
                    $state_icon = $inactive_state_icon;
                }
                // link to image edit
                if ($image->id > 0) {
                    $link = '?base=image';
                    $link .= '&amp;image_action=edit';
                    $link .= '&amp;image_id=' . $image->id;
                    $image_edit_link = '<a href="' . $this->response->html->thisfile . $link . '" onclick="wait();">' . $image->name . '</a>';
                } else {
                    $image_edit_link = $image->name;
                }
                // release resource
                $release_resource = '';
                if ($appliance->stoptime == 0 || $appliance_resources == 0) {
                    $release_resource = '';
                } else {
                    if ($appliance->resources != -1) {
                        $a = $this->response->html->a();
                        $a->label = $this->lang['action_release'];
                        $a->title = $this->lang['resource_release'];
                        $a->css = 'enable';
                        $a->href = $this->response->get_url($this->actions_name, 'release') . '&appliance_id=' . $appliance->id . '' . $tp;
                        $release_resource = $a->get_string();
                    }
                }
                $str = '<strong>' . $this->lang['table_id'] . ':</strong> ' . $appliance_db["appliance_id"] . '<br>
						<strong>' . $this->lang['table_name'] . ':</strong> ' . $appliance_db["appliance_name"] . '<br>
						<strong>Type:</strong> ' . $appliance_virtualization_name . '<br>
						<strong>Kernel:</strong> ' . $kernel->name . '<br>
						<strong>Image:</strong> ' . $image_edit_link . '<br>
						<strong>Resource:</strong> ' . $appliance_resources_str . '<br>
						<strong>IP:</strong> ' . $resource->ip;
                if (strpos($virtualization->type, "-vm") && isset($resource->vhostid) && $resource->vhostid != '') {
                    $happliance = new appliance();
                    $hresource = $happliance->get_ids_per_resource($resource->vhostid);
                    if (isset($hresource[0]['appliance_id'])) {
                        $happliance->get_instance_by_id($hresource[0]['appliance_id']);
                        $link = '?base=appliance';
                        $link .= '&amp;appliance_action=edit';
                        $link .= '&amp;appliance_id=' . $happliance->id;
                        $href = '<a href="' . $this->response->html->thisfile . $link . '" onclick="wait();">' . $happliance->name . '</a>';
                        $str .= '<br><strong>Host:</strong> ' . $href;
                    }
                }
                // appliance edit
                $a = $this->response->html->a();
                $a->title = $this->lang['action_edit'];
                $a->label = $this->lang['action_edit'];
                $a->handler = 'onclick="wait();"';
                $a->css = 'edit';
                $a->href = $this->response->get_url($this->actions_name, 'edit') . '&appliance_id=' . $appliance->id . '' . $tp;
                $strEdit = $a->get_string();
                // appliance start
                $strStart = '';
                if ($appliance_resources !== '0') {
                    $a = $this->response->html->a();
                    $a->handler = 'onclick="wait();"';
                    if ($appliance->stoptime == 0) {
                        $a->title = $this->lang['action_stop'];
                        $a->label = $this->lang['action_stop'];
                        $a->css = 'disable';
                        $a->href = $this->response->get_url($this->actions_name, 'stop') . '&' . $this->identifier_name . '[]=' . $appliance->id . '' . $tp;
                    } else {
                        $a->title = $this->lang['action_start'];
                        $a->label = $this->lang['action_start'];
                        $a->css = 'enable';
                        $a->href = $this->response->get_url($this->actions_name, 'start') . '&' . $this->identifier_name . '[]=' . $appliance->id . '' . $tp;
                    }
                    $strStart = $a->get_string();
                }
                // build the plugin link section
                $appliance_link_section = '';
                // add link to continue if appliance has unfinished wizard
                $disabled = array();
                if (isset($appliance->wizard) && strpos($appliance->wizard, 'wizard') !== false) {
                    $params = explode(',', $appliance->wizard);
                    $wizard_step = explode('=', $params[0]);
                    $wizard_user = explode('=', $params[1]);
                    if ($wizard_user[1] === $this->user->name) {
                        // continue button
                        $a = $this->response->html->a();
                        $a->title = $this->lang['action_continue'];
                        $a->label = $this->lang['action_continue'];
                        $a->handler = 'onclick="wait();"';
                        $a->css = 'badge continue';
                        $a->href = $this->response->get_url($this->actions_name, $wizard_step[1]) . '&appliance_wizard_id=' . $appliance->id . '' . $tp;
                        $appliance_comment = $a->get_string();
                    } else {
                        $appliance_comment = sprintf($this->lang['appliance_create_in_progress'], $wizard_user[1]);
                    }
                    // disable all buttons
                    $disabled[] = $appliance->id;
                    $strEdit = '';
                    $strStart = '';
                    $strStop = '';
                    $release_resource = '';
                } else {
                    $plugin = new plugin();
                    $enabled_plugins = $plugin->enabled();
                    foreach ($enabled_plugins as $index => $plugin_name) {
                        $plugin_appliance_link_section_hook = $this->openqrm->get('webdir') . "/plugins/" . $plugin_name . "/openqrm-" . $plugin_name . "-appliance-link-hook.php";
                        if (file_exists($plugin_appliance_link_section_hook)) {
                            require_once "{$plugin_appliance_link_section_hook}";
                            $appliance_get_link_function = str_replace("-", "_", "get_" . "{$plugin_name}" . "_appliance_link");
                            if (function_exists($appliance_get_link_function)) {
                                $p = $plugin->get_config($plugin_name);
                                $alink = $appliance_get_link_function($appliance->id);
                                if (is_object($alink)) {
                                    //	$alink->handler = $alink->handler.' onclick="wait();"';
                                    $alink->css = 'enable';
                                    $alink->title = preg_replace('~(.*?)<a.*>(.*?)</a>(.*?)~i', '$1$2$3', $p['description']);
                                    $alink = $alink->get_string();
                                }
                                $appliance_link_section .= $alink;
                            }
                        }
                    }
                    if ($appliance_db["appliance_comment"] !== '') {
                        $appliance_comment = $appliance_db["appliance_comment"];
                        $appliance_comment .= "<hr>";
                        $appliance_comment .= $appliance_link_section;
                    } else {
                        $appliance_comment = $appliance_link_section;
                    }
                }
                $b[] = array('appliance_state' => $state_icon, 'appliance_id' => $appliance_db["appliance_id"], 'appliance_name' => $appliance_db["appliance_name"], 'appliance_values' => $str, 'appliance_comment' => $appliance_comment, 'appliance_virtualization' => $appliance_db["appliance_virtualization"], 'appliance_edit' => $strEdit . '' . $strStart . '' . $release_resource);
            }
        }
        // Filter
        $virtulization_types = new virtualization();
        $list = $virtulization_types->get_list();
        $filter = array();
        $filter[] = array('', '');
        foreach ($list as $l) {
            $filter[] = array($l['label'], $l['value']);
        }
        asort($filter);
        $select = $this->response->html->select();
        $select->add($filter, array(1, 0));
        $select->name = 'resource_type_filter';
        $select->handler = 'onchange="wait();this.form.submit();return false;"';
        $select->selected = array($this->response->html->request()->get('resource_type_filter'));
        $box1 = $this->response->html->box();
        $box1->add($select);
        $box1->id = 'resource_type_filter';
        $box1->css = 'htmlobject_box';
        $box1->label = $this->lang['lang_type_filter'];
        // Resource Filter
        $input = $this->response->html->input();
        $input->name = 'resource_filter';
        $input->value = $this->response->html->request()->get('resource_filter');
        $input->title = $this->lang['lang_filter_title'];
        $box2 = $this->response->html->box();
        $box2->add($input);
        $box2->id = 'resource_filter';
        $box2->css = 'htmlobject_box';
        $box2->label = $this->lang['lang_filter'];
        $add = $this->response->html->a();
        $add->title = $this->lang['action_add'];
        $add->label = $this->lang['action_add'];
        $add->handler = 'onclick="wait();"';
        $add->css = 'add';
        $add->href = $this->response->get_url($this->actions_name, "step1") . '' . $tp;
        $table->id = 'Tabelle';
        $table->css = 'htmlobject_table';
        $table->border = 1;
        $table->cellspacing = 0;
        $table->cellpadding = 3;
        $table->autosort = true;
        $table->sort_link = false;
        $table->max = count($b);
        $table->head = $h;
        $table->body = $b;
        #$table->form_action = $this->response->html->thisfile;
        $table->actions_name = $this->actions_name;
        $table->actions = array(array('start' => $this->lang['action_start']), array('stop' => $this->lang['action_stop']), array('remove' => $this->lang['action_remove']));
        $table->identifier = 'appliance_id';
        $table->identifier_name = $this->identifier_name;
        $table->identifier_disabled = $disabled;
        #$table->limit_select = array(
        #	array("value" => 10, "text" => 10),
        #	array("value" => 20, "text" => 20),
        #	array("value" => 30, "text" => 30),
        #	array("value" => 50, "text" => 50),
        #	array("value" => 100, "text" => 100),
        #);
        $d['form'] = $this->response->get_form($this->actions_name, 'select', false)->get_elements();
        $d['add'] = $add->get_string();
        $d['table'] = $table;
        $d['resource_type_filter'] = $box1->get_string();
        $d['resource_filter'] = $box2->get_string();
        return $d;
    }