/** * Get service OS templates list * * @param integer $serverid service id * @param string $templatesid list of templates CSV in format * * return array list of templates */ function get_templates($serverid, $templatesid) { $onapp_config = get_onapp_config($serverid); $template = new ONAPP_Template(); $template->auth($onapp_config["adress"], $onapp_config['username'], $onapp_config['password']); $templates_id = explode(',', $templatesid); $templates = array(); foreach ($template->getList() as $template) { if (in_array($template->_id, $templates_id)) { $templates[$template->_id] = $template; } } return $templates; }
function onapp_ConfigOptions() { global $packageconfigoption, $_GET, $_POST, $_LANG; $serviceid = $_GET["id"] ? $_GET["id"] : $_POST["id"]; $serviceid = addslashes($serviceid); $configarray = array(); if (!file_exists(ONAPP_WRAPPER_INIT)) { return array(sprintf("%s " . realpath(dirname(__FILE__) . '/../../../') . "/includes ( %s )", $_LANG['onappwrappernotfound'], $_LANG['onappmakesuredirectoryisaccessible']) => array()); } $table_result = onapp_createTables(); if ($table_result["error"]) { return array(sprintf("<font color='red'><b>%s</b></font>", $table_result["error"]) => array()); } //////////////////////////// // BEGIN Load Servers // $sql_servers_result = full_query("SELECT id, name FROM tblservers WHERE type = 'onapp'"); $onapp_servers = array(); while ($server = mysql_fetch_assoc($sql_servers_result)) { $onapp_servers[$server['id']] = $server['name']; } // Error if not found onapp server if (!$onapp_servers) { return array("<font color='red'><b>" . $_LANG["onapperrcantfoundactiveserver"] . "</b></font>" => array()); } $onapp_server_id = $packageconfigoption[1] != "" ? $packageconfigoption[1] : array_shift(array_keys($onapp_servers)); $js_serverOptions = ""; foreach (array_keys($onapp_servers) as $id_server) { $js_serverOptions .= " serverOptions[{$id_server}] = '" . addslashes($onapp_servers[$id_server]) . "';\n"; } $onapp_config = onapp_Config($onapp_server_id); if (isset($onapp_config["error"])) { // Error JS Begin $javascript = "\n<script>\n var serverOptions = new Array();\n{$js_serverOptions}\n\n serverSelect = \$(\"select[name\$='packageconfigoption[1]']\");\n serverSelected = serverSelect.val();\n\n selectHTML = '';\n for ( var option in serverOptions )\n selectHTML += '<option value=\"'+option+'\">'+serverOptions[option]+'</option>';\n\n serverSelect.html(selectHTML);\n serverSelect.val(serverSelected);\n\n serverSelect.change( function () {\n form = \$(\"form[name\$='packagefrm']\");\n\tform.submit();\n } );\n</script>"; return array("Server" => array("Type" => "dropdown", "Options" => implode(',', array_keys($onapp_servers)), "Description" => ""), "<font color='red'><b>" . $onapp_config['error'] . "</b></font>" . $javascript => array()); } // END Load Servers // //////////////////////////// //////////////////////////// // BEGIN Load Templates // $template = new ONAPP_Template(); $template->auth($onapp_config["adress"], $onapp_config['username'], $onapp_config['password']); $templates = $template->getList(); $template_ids = array(); $js_templateOptions = ""; $created_os = array(); if (!empty($templates)) { foreach ($templates as $_template) { $template_ids[$_template->_id] = array('label' => $_template->_label); $os = $_template->_operating_system; $os .= empty($_template->_operating_system_distro) ? '' : '_' . $_template->_operating_system_distro; if (!in_array($os, $created_os)) { array_push($created_os, $os); $js_templateOptions .= " templateOptions['{$os}'] = new Array();\n"; } $js_templateOptions .= " templateOptions['{$os}'][{$_template->_id}] = '" . htmlspecialchars(addslashes(preg_replace('/\\r\\n|\\n|\\r/', " ", $_template->_label))) . "';\n"; } } // END Load Templates // //////////////////////////// ////////////////////////////// // BEGIN Load Data Store Zones // $option = explode(",", $packageconfigoption[11]); if (count($option) > 1) { $ds_zone_primary_selected = $option[1]; } else { $ds_zone_primary_selected = 0; } $option = explode(",", $packageconfigoption[9]); if (count($option) > 1) { $ds_zone_swap_selected = $option[1]; } else { $ds_zone_swap_selected = 0; } $dstore_zone = new ONAPP_DataStoreZone(); $dstore_zone->auth($onapp_config["adress"], $onapp_config['username'], $onapp_config['password']); $dstore_zones = $dstore_zone->getList(); $js_dsOptions = " dsOptions[0] = '" . $_LANG["onappautoselect"] . "';\n"; if (!empty($dstore_zones)) { foreach ($dstore_zones as $_ds) { $js_dsOptions .= " dsOptions[{$_ds->_id}] = '" . addslashes($_ds->_label) . "';\n"; } } // END Load Data Store Zones // //////////////////////////// //////////////////////////// // BEGIN Load Hypervisor Zones // ' $hv_zone = new ONAPP_HypervisorZone(); $hv_zone->auth($onapp_config["adress"], $onapp_config['username'], $onapp_config['password']); $hv_zones = $hv_zone->getList(); $hv_zone_ids = array(); if (!empty($hv_zones)) { $js_hvZoneOptions = " hvZoneOptions[0] = '" . $_LANG["onappautoselect"] . "';\n"; foreach ($hv_zones as $_hv_zone) { $js_hvZoneOptions .= " hvZoneOptions[ {$_hv_zone->_id} ] = '" . addslashes($_hv_zone->_label) . "';\n"; } } // END Load Hypervisor Zones // //////////////////////////// //////////////////////////// // BEGIN Load Hypervisors // $option = explode(",", $packageconfigoption[4]); if (count($option) > 1) { $hv_and_zone_selected = $option; } else { $hv_and_zone_selected = 0; } $hv = new ONAPP_Hypervisor(); $hv->auth($onapp_config["adress"], $onapp_config['username'], $onapp_config['password']); $hvs = $hv->getList(); $hv_ids = array(); $js_hvOptions = " hvOptions[0] = '" . $_LANG["onappautoselect"] . "';\n"; $js_hvZonesArray = ''; if (!empty($hvs)) { foreach ($hvs as $_hv) { if ($_hv->_online == "true" && $_hv->_hypervisor_group_id) { $hv_ids[$_hv->_id] = array('label' => $_hv->_label); $js_hvOptions .= " hvOptions[{$_hv->_id}] = '" . addslashes($_hv->_label) . "';\n"; $js_hvZonesArray .= " hvZonesArray[{$_hv->_id}] = {$_hv->_hypervisor_group_id}" . " \n"; } } } // END Load Hypervisors // //////////////////////////// //////////////////////////// // BEGIN Primary networks // $network = new ONAPP_Network(); $network->auth($onapp_config["adress"], $onapp_config['username'], $onapp_config['password']); $networks = $network->getList(); $network_ids = array(); $js_networkOptions = ""; if (!empty($networks)) { foreach ($networks as $_network) { $network_ids[$_network->_id] = array('label' => $_network->_label); $js_networkOptions .= " networkOptions[{$_network->_id}] = '" . addslashes($_network->_label) . "';\n"; } } // END Primary networks // //////////////////////////// // //////////////////////////// // BEGIN Load Roles // $role = new ONAPP_Role(); $role->auth($onapp_config["adress"], $onapp_config['username'], $onapp_config['password']); $roles = $role->getList(); $role_ids = array(); $js_roleOptions = ''; if ($option = (array) json_decode(htmlspecialchars_decode($packageconfigoption[21]))) { $js_rolesSelected = $option['role_ids']; $js_userGroupSelected = $option['user_group']; $js_timeZoneSelected = $option['time_zone']; $js_billingPlanSelected = $option['billing_plan']; } else { $js_billingPlanSelected = 1; $js_rolesSelected = array(2); $js_userGroupSelected = 0; $js_timeZoneSelected = 0; } if (!empty($roles)) { foreach ($roles as $_role) { $js_roleOptions .= " roleOptions[{$_role->_id}] = '" . addslashes($_role->_label) . "';\n"; } } // END Load Roles // //////////////////////////// //////////////////////////// // BEGIN Load User Groups // $ugroup = new ONAPP_UserGroup(); $ugroup->auth($onapp_config["adress"], $onapp_config['username'], $onapp_config['password']); $ugroups = $ugroup->getList(); $js_ugroupOptions = " ugroupOptions[0] = '';\n"; if (!empty($ugroups)) { foreach ($ugroups as $_group) { $js_ugroupOptions .= " ugroupOptions[{$_group->_id}] = '" . addslashes($_group->_label) . "';\n"; } } // END Load User Groups // //////////////////////////// //////////////////////////////// //// BEGIN Load Billing Plans // $bplan = new ONAPP_BillingPlan(); $bplan->auth($onapp_config["adress"], $onapp_config['username'], $onapp_config['password']); $bplans = $bplan->getList(); $js_bplanOptions = ''; if (!empty($bplans)) { foreach ($bplans as $_plan) { $js_bplanOptions .= " bplanOptions[{$_plan->_id}] = '" . addslashes($_plan->_label) . "';\n"; } } // END Load Billing Plans // //////////////////////////// //////////////////////////// // BEGIN Config options // $configoptions_query = full_query("SELECT\n configoptions.id AS id,\n configoptions.optionname AS name,\n sub.id AS subid,\n sub.sortorder AS suborder\n FROM\n tblproductconfigoptions AS configoptions,\n tblproductconfiglinks AS configlinks,\n tblproductconfigoptionssub AS sub\n WHERE\n configlinks.gid = configoptions.gid\n AND sub.configid = configoptions.id\n AND configlinks.pid = {$serviceid}"); $js_ConfigOptions = " configOptions[0] = '" . $_LANG["onappselconfoption"] . "';\n"; $js_ConfigOptionsSub = ""; $configoptions = array(); $options = array(); while ($option = mysql_fetch_assoc($configoptions_query)) { $options[$option['id']]['options'][$option['suborder']] = $option['subid']; if (!isset($options[$option['id']]['name'])) { $options[$option['id']]['name'] = addslashes($option['name']); } } foreach ($options as $key => $configoption) { $js_ConfigOptions .= " configOptions[{$key}] ='" . addslashes($configoption['name']) . "';\n"; $js_ConfigOptionsSub .= " configOptionsSub[{$key}] = '" . implode(",", array_keys($configoption['options'])) . "';\n"; $configoptions[] = $key; } $js_addBandwidthSelected = $packageconfigoption[22] ? $packageconfigoption[22] : "0"; // END Config options // //////////////////////////// //GET build options $option = explode(',', $packageconfigoption[10]); $js_requireAutoBuild = $option[0] ? $option[0] : 0; $js_requireAutoBackups = $option[1] ? $option[1] : 0; $js_error = " var error_msg = "; if (count($hv_ids) == 0) { $js_error .= "'<b><font color=\\'red\\'>" . $_LANG["onapphvnotfound"] . "</font></b>'"; } else { if (count($template_ids) == 0) { $js_error .= "'<b><font color=\\'red\\'>" . $_LANG["onapposnotfound"] . "</font></b>'"; } else { if (count($network_ids) == 0) { $js_error .= "'<b><font color=\\'red\\'>" . $_LANG["onappnetnotfound"] . "</font></b>'"; } else { $js_error .= "''"; } } } $js_localization_array = array('res', 'netconfig', 'addres', 'youwantrefreshtemplates', 'settemplate', 'wrongram', 'wrongcpucores', 'wrongcpuprior', 'wrongswap', 'wrongdisksize', 'wrongspead', 'userroles', 'hvzones', 'primarydisk', 'swapdisk', 'dszone', 'vmproperties', 'usergroups', 'userproperties', 'timezones', 'billingplans', 'requireautobackups', 'addbandwidth', 'suspendifbwexceeded'); $js_localization_string = ''; foreach ($js_localization_array as $string) { if (isset($_LANG['onapp' . $string])) { $js_localization_string .= " LANG['onapp{$string}'] = '" . $_LANG['onapp' . $string] . "';\n"; } } $javascript = "\n\n<script type=\"text/javascript\">\n selectWidth = 280;\n\n var serverOptions = new Array();\n{$js_serverOptions}\n var templateOptions = {};\n{$js_templateOptions}\n var hvOptions = new Array();\n{$js_hvOptions}\n var networkOptions = new Array();\n{$js_networkOptions}\n var roleOptions = new Array();\n{$js_roleOptions}\n var configOptions = new Array();\n{$js_ConfigOptions}\n var configOptionsSub = new Array();\n{$js_ConfigOptionsSub}\n var hvZonesArray = new Array();\n{$js_hvZonesArray}\n var hvZoneOptions = new Array();\n{$js_hvZoneOptions}\n var dsOptions = new Array();\n{$js_dsOptions}\n var ugroupOptions = new Array();\n{$js_ugroupOptions}\n var bplanOptions = new Array();\n{$js_bplanOptions}\n var productAddons = new Array();\n \nvar hvAndZoneSelected = " . json_encode($hv_and_zone_selected) . "\nvar dsPrimarySelected = {$ds_zone_primary_selected}\nvar dsSwapSelected = {$ds_zone_swap_selected}\nvar rolesSelected = " . json_encode($js_rolesSelected) . "\nvar userGroupSelected = {$js_userGroupSelected}\nvar timeZoneSelected = '{$js_timeZoneSelected}'\nvar billingPlanSelected = {$js_billingPlanSelected}\nvar requireAutoBuild = '{$js_requireAutoBuild}'\nvar requireAutoBackups = '{$js_requireAutoBackups}'\nvar addBwSelected = '{$js_addBandwidthSelected}'\n\n{$js_error};\n\n// Localization\n var LANG = new Array();\n{$js_localization_string}\n\n</script>\n<script type=\"text/javascript\" src=\"../modules/servers/onapp/includes/jquery.multiselects.js\"></script>\n<script type=\"text/javascript\" src=\"../modules/servers/onapp/includes/onapp.js\"></script>\n<script type=\"text/javascript\" src=\"../modules/servers/onapp/includes/slider.js\"></script>\n<script type=\"text/javascript\" src=\"../modules/servers/onapp/includes/tz.js\"></script>\n"; $configarray = array($_LANG["onappiservers"] => array("Type" => "dropdown", "Options" => implode(',', array_keys($onapp_servers)), "Description" => ""), $_LANG["onapptemlates"] => array("Type" => "text", "Size" => "5", "Description" => count($template_ids) != 0 ? "" : $_LANG["onappnotfoundred"]), $_LANG["onappram"] => array("Type" => "text", "Size" => "5", "Description" => "MB"), $_LANG["onapphv"] => array("Type" => count($hv_ids) != 0 ? "dropdown" : null, "Options" => count($hv_ids) != 0 ? "0," . implode(',', array_keys($hv_ids)) : null, "Description" => count($hv_ids) != 0 ? "" : $_LANG["onappnotfoundred"]), $_LANG["onappcpucores"] => array("Type" => "text", "Size" => "5", "Description" => ""), $_LANG["onappprimarynet"] => array("Type" => count($network_ids) != 0 ? "dropdown" : null, "Options" => count($network_ids) != 0 ? implode(',', array_keys($network_ids)) : null, "Description" => count($network_ids) != 0 ? "" : $_LANG["onappnotfoundred"]), $_LANG["onappcpuprior"] => array("Type" => "text", "Size" => "5", "Description" => "%"), $_LANG["onappportspeed"] => array("Type" => "text", "Size" => "5", "Description" => "Mbps ( Unlimited if not set )"), $_LANG["onappswapsize"] => array("Type" => "text", "Size" => "5", "Description" => "GB"), $_LANG["onappbuildauto"] => array("Type" => "yesno", "Description" => $_LANG["onappticktobuildauto"]), $_LANG["onappprivarydisksize"] => array("Type" => "text", "Size" => "5", "Description" => "GB"), $_LANG["onappadditionalram"] => array("Type" => "dropdown", "Options" => "0," . implode(',', $configoptions), "Description" => ""), $_LANG["onappadditionallcores"] => array("Type" => "dropdown", "Options" => "0," . implode(',', $configoptions), "Description" => ""), $_LANG["onappadditionallcpupriority"] => array("Type" => "dropdown", "Options" => "0," . implode(',', $configoptions), "Description" => ""), $_LANG["onappadditionalldisksize"] => array("Type" => "dropdown", "Options" => "0," . implode(',', $configoptions), "Description" => ""), $_LANG["onappipaddress"] => array("Type" => "dropdown", "Options" => "0," . implode(',', $configoptions), "Description" => ""), $_LANG["onappbackup"] => array("Type" => "dropdown", "Options" => "0," . implode(',', $configoptions), "Description" => ""), $_LANG["onappincludedips"] => array("Type" => "text", "Size" => "5", "Description" => ""), $_LANG["onappaddonresource"] => array("Type" => "dropdown", "Options" => "0," . implode(',', $configoptions), "Description" => ""), $_LANG["onappadditionallportspeed"] => array("Type" => "dropdown", "Options" => "0," . implode(',', $configoptions), "Description" => ""), " " => array("Type" => "text", "Description" => "\n{$javascript}")); return $configarray; }