| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- /* * ********************************************************************
- * ProxmoxVPS product developed. (2016-10-12)
- * *
- *
- * CREATED BY MODULESGARDEN -> 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 <pawelk@modulesgarden.com>
- * @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;
- }
- }
- }
|