function openqrm_puppet_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_puppet_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-cloud-product-hook.php", "Handling " . $cmd . " event", "", "", 0, 0, 0); switch ($cmd) { case "add": $event->log("openqrm_puppet_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-cloud-product-hook.php", "Handling cloud-product " . $cmd . " event", "", "", 0, 0, 0); // create application products $next_sort_id = 0; $db = openqrm_get_db_connection(); $puppet = new puppet(); $puppet_group_array = $puppet->get_available_groups(); foreach ($puppet_group_array as $index => $puppet_app) { $event->log("openqrm_puppet_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-cloud-product-hook.php", "Adding application " . $puppet_app . " as cloud-product", "", "", 0, 0, 0); $cloud_product_id = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $create_application_cloudselector_config = "insert into cloud_selector (id, type, sort_id, quantity, price, name, description, state) VALUES (" . $cloud_product_id . ", 'application', " . $next_sort_id . ", 'puppet/" . $puppet_app . "', 1, '" . $puppet_app . "', '" . $puppet_app . " via puppet', 1);"; $recordSet = $db->Execute($create_application_cloudselector_config); $next_sort_id++; } 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(); $cloud_selector_id_ar = $cloud_selector->get_all_ids(); foreach ($cloud_selector_id_ar as $key => $value) { $id = $value['id']; $cloud_selector->get_instance_by_id($id); $pos = strpos($cloud_selector->quantity, 'puppet/'); if ($pos !== false) { $event->log("openqrm_puppet_cloud_product", $_SERVER['REQUEST_TIME'], 5, "openqrm-puppet-cloud-product-hook.php", "Removing application " . $cloud_selector->quantity . " from cloud-products", "", "", 0, 0, 0); $cloud_selector->remove($id); } } } break; } }
function get_ip_address() { global $RESOURCE_INFO_TABLE; global $event; $db = openqrm_get_db_connection(); $rs = $db->Execute("select resource_openqrmserver from {$RESOURCE_INFO_TABLE} where resource_id=0"); if (!$rs) { $event->log("get_ip_address", $_SERVER['REQUEST_TIME'], 2, "openqrm_server.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$rs->EOF) { $resource_openqrmserver = $rs->fields["resource_openqrmserver"]; $rs->MoveNext(); } } if (!strlen($resource_openqrmserver)) { $event->log("get_ip_address", $_SERVER['REQUEST_TIME'], 2, "openqrm_server.class.php", "Could not find out IP-Address of the openQRM server. Server misconfiguration!", "", "", 0, 0, 0); } return $resource_openqrmserver; }
function display_overview($offset, $limit, $sort, $order) { global $CLOUD_MATRIX_TABLE; global $event; $db = openqrm_get_db_connection(); $recordSet = $db->SelectLimit("select * from {$CLOUD_MATRIX_TABLE} order by {$sort} {$order}", $limit, $offset); $cloudmatrix_array = array(); if (!$recordSet) { $event->log("display_overview", $_SERVER['REQUEST_TIME'], 2, "cloudmatrix.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$recordSet->EOF) { array_push($cloudmatrix_array, $recordSet->fields); $recordSet->MoveNext(); } $recordSet->Close(); } return $cloudmatrix_array; }
function display_overview($offset, $limit, $sort, $order, $mode = null) { switch ($mode) { case '': case 'all': $sql = "select * from " . $this->_db_table . " order by " . $sort . " " . $order; break; case 'error': $sql = "select * from " . $this->_db_table . " where event_priority < 4 and event_status <> 1 order by " . $sort . " " . $order; break; case 'acknowledge': $sql = "select * from " . $this->_db_table . " where event_status = 1 order by " . $sort . " " . $order; break; case 'warning': $sql = "select * from " . $this->_db_table . " where event_priority = 4 and event_status <> 1 order by " . $sort . " " . $order; break; case 'active': $sql = "select * from " . $this->_db_table . " where event_priority = 9 and event_status <> 1 order by " . $sort . " " . $order; break; } $db = openqrm_get_db_connection(); $recordSet = $db->SelectLimit($sql, $limit, $offset); $event_array = array(); if (!$recordSet) { $this->log("display_overview", $_SERVER['REQUEST_TIME'], 2, "event.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$recordSet->EOF) { array_push($event_array, $recordSet->fields); $recordSet->MoveNext(); } $recordSet->Close(); } return $event_array; }
case 'init': // this command creates the following tables // -> nagios3_services // nagios3_service_id BIGINT // nagios3_service_name VARCHAR(50) // nagios3_service_port VARCHAR(50) // nagios3_service_type VARCHAR(50) // nagios3_service_description VARCHAR(255) $create_nagios3_service_table = "create table nagios3_services(nagios3_service_id BIGINT, nagios3_service_name VARCHAR(50), nagios3_service_port VARCHAR(50), nagios3_service_type VARCHAR(50), nagios3_service_description VARCHAR(255))"; // -> nagios3_hosts // nagios3_host_id BIGINT // nagios3_appliance_id BIGINT // nagios3_appliance_services VARCHAR(255) $create_nagios3_host_table = "create table nagios3_hosts(nagios3_host_id BIGINT, nagios3_appliance_id BIGINT, nagios3_appliance_services VARCHAR(255))"; $db = openqrm_get_db_connection(); $recordSet = $db->Execute($create_nagios3_service_table); $recordSet = $db->Execute($create_nagios3_host_table); $db->Close(); break; case 'uninstall': $drop_nagios3_service_table = "drop table nagios3_services"; $drop_nagios3_host_table = "drop table nagios3_hosts"; $db = openqrm_get_db_connection(); $recordSet = $db->Execute($drop_nagios3_service_table); $recordSet = $db->Execute($drop_nagios3_host_table); $db->Close(); break; default: $event->log("{$nagios3_command}", $_SERVER['REQUEST_TIME'], 3, "nagios3-action", "No such event command ({$nagios3_command})", "", "", 0, 0, 0); break; }
function get_id_by_cr($cr_id) { $list = array(); $query = 'SELECT ca_id FROM ' . $this->_db_table . ' WHERE ca_cr_id="' . $cr_id . '"'; $db = openqrm_get_db_connection(); $rs = $db->Execute($query); if (is_object($rs)) { while (!$rs->EOF) { $list[] = $rs->fields; $rs->MoveNext(); } return $list[0]['ca_id']; } }
function display_overview($offset, $limit, $sort, $order) { global $IMAGE_AUTHENTICATION_TABLE; global $event; $db = openqrm_get_db_connection(); $recordSet = $db->SelectLimit("select * from {$IMAGE_AUTHENTICATION_TABLE} order by {$sort} {$order}", $limit, $offset); $image_authentication_array = array(); if (!$recordSet) { $event->log("display_overview", $_SERVER['REQUEST_TIME'], 2, "image_authentication.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$recordSet->EOF) { array_push($image_authentication_array, $recordSet->fields); $recordSet->MoveNext(); } $recordSet->Close(); } return $image_authentication_array; }
function set_wizard($username, $wizardname, $step, $id) { $db = openqrm_get_db_connection(); $sql = "update " . $this->_user_table . " set user_wizard_name='" . $wizardname . "', user_wizard_step=" . $step . ",user_wizard_id=" . $id . " where user_name='" . $username . "'"; $rs = $db->Execute($sql); return $rs; }
function get_deployment_ids() { $deployment_array = array(); $query = "select deployment_id from {$this->_db_table}"; $db = openqrm_get_db_connection(); $rs = $db->Execute($query); if (!$rs) { $event->log("get_deployment_ids", $_SERVER['REQUEST_TIME'], 2, "deployment.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$rs->EOF) { $deployment_array[] = $rs->fields; $rs->MoveNext(); } } return $deployment_array; }
function remove_by_section($section) { $db = openqrm_get_db_connection(); $rs = $db->Execute("delete from " . $this->db_name . " where lock_section='{$section}'"); }
function find_resource($search) { global $RESOURCE_INFO_TABLE; global $event; $db = openqrm_get_db_connection(); // replace glob wildcards with sql wildcards $search = str_replace('_', '\\_', $search); $search = str_replace('%', '\\%', $search); $search = str_replace('?', '_', $search); $search = str_replace('*', '%', $search); $sql = 'SELECT * FROM ' . $RESOURCE_INFO_TABLE; $sql .= ' WHERE resource_id LIKE ?'; $sql .= ' OR resource_hostname LIKE ?'; $sql .= ' OR resource_mac LIKE ?'; // handle sql injection $sql = $db->db->Prepare($sql); $recordSet = $db->db->Execute($sql, array($search, $search, $search)); $resource_array = array(); if (!$recordSet) { $event->log("find_resource", $_SERVER['REQUEST_TIME'], 2, "resource.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$recordSet->EOF) { array_push($resource_array, $recordSet->fields); $recordSet->MoveNext(); } $recordSet->Close(); } return $resource_array; }
function remove_by_type($type) { global $VIRTUALIZATION_INFO_TABLE; $db = openqrm_get_db_connection(); $rs = $db->Execute("delete from {$VIRTUALIZATION_INFO_TABLE} where virtualization_type='{$type}'"); }
function openqrm_db_get_result($query) { $ar = array(); $db = openqrm_get_db_connection(); $db->SetFetchMode(ADODB_FETCH_ASSOC); $result = $db->Execute($query); if (is_object($result)) { while ($arr = $result->FetchRow()) { $tmp = array(); foreach ($arr as $key => $val) { if (is_string($key)) { $tmp[] = array("value" => $val, "label" => $key); } } $ar[] = $tmp; } } return $ar; }
function get_all_ids() { global $AUTH_BLOCKER_TABLE; global $event; $authblocker_list = array(); $query = "select ab_id from " . $this->_db_table; $db = openqrm_get_db_connection(); $rs = $db->Execute($query); if (!$rs) { $event->log("get_list", $_SERVER['REQUEST_TIME'], 2, "authblocker.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$rs->EOF) { $authblocker_list[] = $rs->fields; $rs->MoveNext(); } } return $authblocker_list; }
function display_overview($offset, $limit, $sort, $order) { global $KERNEL_INFO_TABLE; $db = openqrm_get_db_connection(); $recordSet = $db->SelectLimit("select * from {$KERNEL_INFO_TABLE} where kernel_id > 0 order by {$sort} {$order}", $limit, $offset); $kernel_array = array(); if (!$recordSet) { $this->__event->log("display_overview", $_SERVER['REQUEST_TIME'], 2, "kernel.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$recordSet->EOF) { array_push($kernel_array, $recordSet->fields); $recordSet->MoveNext(); } $recordSet->Close(); } return $kernel_array; }
function display_overview($offset, $limit, $sort, $order) { $db = openqrm_get_db_connection(); $recordSet = $db->SelectLimit("select * from " . $this->_db_table . " order by {$sort} {$order}", $limit, $offset); $cloudiplc_array = array(); if (!$recordSet) { $this->_event->log("display_overview", $_SERVER['REQUEST_TIME'], 2, "cloudiplc.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$recordSet->EOF) { array_push($cloudiplc_array, $recordSet->fields); $recordSet->MoveNext(); } $recordSet->Close(); } return $cloudiplc_array; }
function get() { $sql = "select * from " . $this->_db_table . " order by datacenter_id ASC"; $db = openqrm_get_db_connection(); $recordSet = $db->SelectLimit($sql, 60, 0); $datacenter_array = array(); if (!$recordSet) { $this->log("get", $_SERVER['REQUEST_TIME'], 2, "datacenter.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$recordSet->EOF) { array_push($datacenter_array, $recordSet->fields); $recordSet->MoveNext(); } $recordSet->Close(); } return $datacenter_array; }
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_all_ids() { $linuxcoestate_list = array(); $query = "select linuxcoe_id from " . $this->_db_table; $db = openqrm_get_db_connection(); $rs = $db->Execute($query); if (!$rs) { $this->_event->log("get_list", $_SERVER['REQUEST_TIME'], 2, "linuxcoestate.class.php", $db->ErrorMsg(), "", "", 0, 0, 0); } else { while (!$rs->EOF) { $linuxcoestate_list[] = $rs->fields; $rs->MoveNext(); } } return $linuxcoestate_list; }