예제 #1
0
 function CloudUserCreate($method_parameters)
 {
     global $CloudDir;
     global $event;
     $parameter_array = explode(',', $method_parameters);
     $mode = $parameter_array[0];
     $username = $parameter_array[1];
     $password = $parameter_array[2];
     $clouduser_name = $parameter_array[3];
     $clouduser_password = $parameter_array[4];
     $clouduser_email = $parameter_array[5];
     $clouduser_group_name = $parameter_array[6];
     $clouduser_forename = $parameter_array[7];
     $clouduser_lastname = $parameter_array[8];
     $clouduser_street = $parameter_array[9];
     $clouduser_city = $parameter_array[10];
     $clouduser_country = $parameter_array[11];
     $clouduser_phone = $parameter_array[12];
     $clouduser_ccus = $parameter_array[13];
     $clouduser_lang = $parameter_array[14];
     // check parameter count
     $parameter_count = count($parameter_array);
     if ($parameter_count != 15) {
         $event->log("cloudsoap->CloudUserCreate", $_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->CloudUserCreate", $_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->CloudUserCreate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud method only available in admin mode", "", "", 0, 0, 0);
         return;
     }
     // user input checking
     if (!strlen($clouduser_name)) {
         $event->log("cloudsoap->CloudUserCreate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud user name is empty. Not adding new user.", "", "", 0, 0, 0);
         return;
     }
     if (!strlen($clouduser_email)) {
         $event->log("cloudsoap->CloudUserCreate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud user email is empty. Not adding new user.", "", "", 0, 0, 0);
         return;
     }
     // email valid ?
     $cloud_email = new clouduser();
     if (!$cloud_email->checkEmail($clouduser_email)) {
         $event->log("cloudsoap->CloudUserCreate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud user email address is invalid. Not adding new user.", "", "", 0, 0, 0);
         return;
     }
     // set the user group
     if (!strlen($clouduser_group_name)) {
         $user_fields['cu_cg_id'] = 0;
         // 0 = default user group
     } else {
         $cloudusergroup = new cloudusergroup();
         $cloudusergroup->get_instance_by_name($clouduser_group_name);
         $user_fields['cu_cg_id'] = $cloudusergroup->id;
     }
     // set defaults
     if (!strlen($clouduser_forename)) {
         $user_fields['cu_forename'] = "Cloud-User";
     } else {
         $user_fields['cu_forename'] = $clouduser_forename;
     }
     if (!strlen($clouduser_lastname)) {
         $user_fields['cu_lastname'] = $clouduser_name;
     } else {
         $user_fields['cu_lastname'] = $clouduser_lastname;
     }
     if (!strlen($clouduser_street)) {
         $user_fields['cu_street'] = "na";
     } else {
         $user_fields['cu_street'] = $clouduser_street;
     }
     if (!strlen($clouduser_city)) {
         $user_fields['cu_city'] = "na";
     } else {
         $user_fields['cu_city'] = $clouduser_city;
     }
     if (!strlen($clouduser_country)) {
         $user_fields['cu_country'] = "na";
     } else {
         $user_fields['cu_country'] = $clouduser_country;
     }
     if (!strlen($clouduser_phone)) {
         $user_fields['cu_phone'] = "0";
     } else {
         $user_fields['cu_phone'] = $clouduser_phone;
     }
     if (!strlen($clouduser_ccus)) {
         // check how many ccunits to give for a new user
         $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;
     } else {
         $user_fields['cu_ccunits'] = $clouduser_ccus;
     }
     // username free ?
     $cl_user = new clouduser();
     if (!$cl_user->is_name_free($clouduser_name)) {
         $event->log("cloudsoap->CloudUserCreate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Cloud User name {$clouduser_name} already exists in the Cloud. Not adding !", "", "", 0, 0, 0);
         return;
     }
     $event->log("cloudsoap->CloudUserCreate", $_SERVER['REQUEST_TIME'], 5, "cloud-soap-server.php", "Creating new Cloud Users {$clouduser_name}", "", "", 0, 0, 0);
     // create user_fields array
     $user_fields['cu_name'] = $clouduser_name;
     $user_fields['cu_password'] = $clouduser_password;
     $user_fields['cu_email'] = $clouduser_email;
     // enabled by default
     $user_fields['cu_status'] = 1;
     $user_fields['cu_lang'] = $clouduser_lang;
     // get a new clouduser id
     $user_fields['cu_id'] = openqrm_db_get_free_id('cu_id', $cl_user->_db_table);
     $cl_user->add($user_fields);
     // add user to htpasswd
     $username = $user_fields['cu_name'];
     $password = $user_fields['cu_password'];
     $cloud_htpasswd = "{$CloudDir}/user/.htpasswd";
     if (!strlen($password)) {
         $event->log("cloudsoap->CloudUserCreate", $_SERVER['REQUEST_TIME'], 2, "cloud-soap-server.php", "Created Cloud Users " . $clouduser_name . " with empty password. Assuming LDAP authentication", "", "", 0, 0, 0);
     } else {
         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);
     return $user_fields['cu_id'];
 }
예제 #2
0
 $username = $user_fields['cu_name'];
 $password = $user_fields['cu_password'];
 $c_error = 0;
 // checks
 check_param("Username", $user_fields['cu_name']);
 check_param("Password", $user_fields['cu_password']);
 check_param("Lastname", $user_fields['cu_lastname']);
 check_param("Forename", $user_fields['cu_forename']);
 check_param("Street", $user_fields['cu_street']);
 check_param("City", $user_fields['cu_city']);
 check_param("Country", $user_fields['cu_country']);
 check_param("Phone", $user_fields['cu_phone']);
 // email valid ?
 $cloud_email = new clouduser();
 if (strcmp($user_fields['cu_email'], "@localhost")) {
     if (!$cloud_email->checkEmail($user_fields['cu_email'])) {
         $strMsg = "Email address is invalid. <br>";
         $c_error = 1;
         redirect($strMsg, 'tab0', "cloud-user.php");
         exit(0);
     }
 }
 // password min 6 characters
 if (strlen($user_fields['cu_password']) < 6) {
     $strMsg .= "Password must be at least 6 characters long <br>";
     $c_error = 1;
     redirect($strMsg, 'tab0', "cloud-user.php");
     exit(0);
 }
 // username min 4 characters
 if (strlen($user_fields['cu_name']) < 4) {