http://modulesgarden.com * CONTACT -> contact@modulesgarden.com * * * This software is furnished under a license and may be used and copied * only in accordance with the terms of such license and with the * inclusion of the above copyright notice. This software or any other * copies thereof may not be provided or otherwise made available to any * other person. No title to and ownership of the software is hereby * transferred. * * * ******************************************************************** */ namespace MGProvision\Proxmox\v2\models; use MGProvision\Proxmox\v2\ProxmoxApiException; /** * Description of User * * @author Pawel Kopec * @version 1.0.0 */ class User extends AbstractObject { protected $userid; public function __construct($userid = null) { $this->userid = $userid; } public function setUserid($userid) { if (empty($userid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("UserId is empty"); $this->userid = $userid; return $this; } public function getUserid() { return $this->userid; } public function updatePermission($vmid, $roles, $delete = 0) { if (empty($this->userid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("UserId is empty"); if (empty($vmid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("VMID is empty"); $parameter = array( "path" => "/vms/" . $vmid, "delete" => $delete, "roles" => $roles, "users" => $this->userid, ); return $this->api()->put("/access/acl", $parameter); } public function permissions() { return $this->api()->get("/access/acl"); } public function create($parameters) { $res = $this->api()->post("/access/users", $parameters); $this->userid = $parameters['userid']; return $res; } public function update($parameters) { if (empty($this->userid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("UserId is empty"); return $this->api()->put("/access/users/{$this->userid}", $parameters); } public function disable() { if (empty($this->userid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("UserId is empty"); return $this->api()->put("/access/users/{$this->userid}", array("enable" => "0")); } public function enable() { if (empty($this->userid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("UserId is empty"); return $this->api()->put("/access/users/{$this->userid}", array("enable" => "1")); } public function changePassword($password) { if (empty($this->userid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("UserId is empty"); $data = array( "userid" => $this->userid, "password" => $password ); return $this->api()->put("/access/password", $data); } public function delete() { if (empty($this->userid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("UserId is empty"); return $this->api()->delete("/access/users/" . $this->userid); } public function configuration() { if (empty($this->userid)) throw new \MGProvision\Proxmox\v2\ProxmoxApiException("UserId is empty"); return $this->api()->get("/access/users/" . $this->userid); } public function exist(){ try { $this->configuration(); return true; }catch (ProxmoxApiException $exception){ return false; } } }