function CloudRequestUpdate($method_parameters) { global $event; $parameter_array = explode(',', $method_parameters); $mode = $parameter_array[0]; $username = $parameter_array[1]; $password = $parameter_array[2]; $cr_id = $parameter_array[3]; $cr_key = $parameter_array[4]; $cr_value = $parameter_array[5]; // check all user input for ($i = 0; $i <= 5; $i++) { if (!$this->check_param($parameter_array[$i])) { $event->log("cloudsoap->CloudRequestUpdate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Not allowing user-intput with special-characters : {$parameter_array[$i]}", "", "", 0, 0, 0); return -1; } } // check parameter count $parameter_count = count($parameter_array); if ($parameter_count != 6) { $event->log("cloudsoap->CloudRequestUpdate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Wrong parameter count {$parameter_count} ! Exiting.", "", "", 0, 0, 0); return -2; } // check authentication if (!$this->check_user($mode, $username, $password)) { $event->log("cloudsoap->CloudRequestUpdate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "User authentication failed (mode {$mode})", "", "", 0, 0, 0); return -3; } $cr_request = new cloudrequest(); $cr_request->get_instance_by_id($cr_id); $cl_user = new clouduser(); $cl_user->get_instance_by_id($cr_request->cu_id); switch ($mode) { case 'user': if (strcmp($username, $cl_user->name)) { $event->log("cloudsoap->CloudRequestUpdate", $_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 -5; } break; } // check user limits $cloud_user_limit = new clouduserlimits(); $cloud_user_limit->get_instance_by_cu_id($cl_user->id); $cloud_user_memory_limit = $cloud_user_limit->memory_limit; $cloud_user_cpu_limit = $cloud_user_limit->cpu_limit; // if cloudselector is enabled check if products exist $cc_conf = new cloudconfig(); $cloud_selector_enabled = $cc_conf->get_value(22); // cloudselector // cpu or memory update switch ($cr_key) { case 'cpu': if ($cloud_user_cpu_limit != 0) { if ($cloud_user_cpu_limit > $cr_value) { $event->log("cloudsoap->CloudRequestUpdate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User {$cloud_username}: Cloud CPU Limit reached ({$cr_value})", "", "", 0, 0, 0); return -10; } } if (!strcmp($cloud_selector_enabled, "true")) { $cloudselector = new cloudselector(); // cpu if (!$cloudselector->product_exists_enabled("cpu", $cr_value)) { $event->log("cloudsoap->CloudRequestUpdate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User {$cloud_username}: Cloud CPU Product ({$cr_value}) is not existing", "", "", 0, 0, 0); return -11; } } $cr_cpu_fields['cr_cpu_req'] = $cr_value; $cr_request->update($cr_id, $cr_cpu_fields); $event->log("cloudsoap->CloudRequestUpdate", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Updated CPU in Cloud request {$cr_id}", "", "", 0, 0, 0); break; case 'memory': if ($cloud_user_memory_limit != 0) { if ($cloud_user_memory_limit > $cr_value) { $event->log("cloudsoap->CloudRequestUpdate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User {$cloud_username}: Cloud Memory Limit reached ({$cr_value})", "", "", 0, 0, 0); return -10; } } if (!strcmp($cloud_selector_enabled, "true")) { $cloudselector = new cloudselector(); // memory if (!$cloudselector->product_exists_enabled("memory", $cr_value)) { $event->log("cloudsoap->CloudRequestUpdate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User {$cloud_username}: Cloud Memory Product ({$cr_value}) is not existing", "", "", 0, 0, 0); return -14; } } $cr_mem_fields['cr_ram_req'] = $cr_value; $cr_request->update($cr_id, $cr_mem_fields); $event->log("cloudsoap->CloudRequestUpdate", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Updated RAM in Cloud request {$cr_id}", "", "", 0, 0, 0); break; } return 0; }
function CloudUserSetLimits($method_parameters) { global $event; $parameter_array = explode(',', $method_parameters); $mode = $parameter_array[0]; $username = $parameter_array[1]; $password = $parameter_array[2]; $clouduser_name = $parameter_array[3]; $resource_limit = $parameter_array[4]; $memory_limit = $parameter_array[5]; $disk_limit = $parameter_array[6]; $cpu_limit = $parameter_array[7]; $network_limit = $parameter_array[8]; // check all user input for ($i = 0; $i <= 8; $i++) { if (!$this->check_param($parameter_array[$i])) { $event->log("cloudsoap->CloudUserSetLimits", $_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 != 9) { $event->log("cloudsoap->CloudUserSetLimits", $_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->CloudUserSetLimits", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "User authentication failed (mode {$mode})", "", "", 0, 0, 0); return; } // check for admin if (strcmp($mode, "admin")) { $event->log("cloudsoap->CloudUserSetLimits", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud method only available in admin mode", "", "", 0, 0, 0); return; } $cl_user = new clouduser(); if ($cl_user->is_name_free($clouduser_name)) { $event->log("cloudsoap->CloudUserSetLimits", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User name {$clouduser_name} does not exists in the Cloud !", "", "", 0, 0, 0); return 1; } $event->log("cloudsoap->CloudUserSetLimits", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Setting Cloud Limits for Cloud Users {$clouduser_name}", "", "", 0, 0, 0); $cloud_user_limits_fields = array(); $cloud_user_limits_fields['cl_resource_limit'] = $resource_limit; $cloud_user_limits_fields['cl_memory_limit'] = $memory_limit; $cloud_user_limits_fields['cl_disk_limit'] = $disk_limit; $cloud_user_limits_fields['cl_cpu_limit'] = $cpu_limit; $cloud_user_limits_fields['cl_network_limit'] = $network_limit; $cl_user->get_instance_by_name($clouduser_name); $clouduser_limit = new clouduserlimits(); $clouduser_limit->get_instance_by_cu_id($cl_user->id); $clouduser_limit->update($clouduser_limit->id, $cloud_user_limits_fields); return 0; }
$cc_conf = new cloudconfig(); $cc_auto_give_ccus = $cc_conf->get_value(12); // 12 is auto_give_ccus $user_fields['cu_ccunits'] = $cc_auto_give_ccus; $cl_user = new clouduser(); $cl_user->add($user_fields); // add user to htpasswd $cloud_htpasswd = "{$CloudDir}/user/.htpasswd"; if (file_exists($cloud_htpasswd)) { $openqrm_server_command = "htpasswd -b {$CloudDir}/user/.htpasswd {$username} {$password}"; } else { $openqrm_server_command = "htpasswd -c -b {$CloudDir}/user/.htpasswd {$username} {$password}"; } $output = shell_exec($openqrm_server_command); // set user permissions and limits, set to 0 (infinite) by default $cloud_user_limit = new clouduserlimits(); $cloud_user_limits_fields['cl_id'] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0")); $cloud_user_limits_fields['cl_cu_id'] = $user_fields['cu_id']; $cloud_user_limits_fields['cl_resource_limit'] = 0; $cloud_user_limits_fields['cl_memory_limit'] = 0; $cloud_user_limits_fields['cl_disk_limit'] = 0; $cloud_user_limits_fields['cl_cpu_limit'] = 0; $cloud_user_limits_fields['cl_network_limit'] = 0; $cloud_user_limit->add($cloud_user_limits_fields); // send mail to user // get admin email $cc_admin_email = $cc_conf->get_value(1); // 1 is admin_email // get external name $external_portal_name = $cc_conf->get_value(3); // 3 is the external name