USER.class.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /**
  3. * USERS
  4. *
  5. * @author vesta, http://vestacp.com/
  6. * @author Dmitry Malishev <dima.malishev@gmail.com>
  7. * @author Dmitry Naumov-Socolov <naumov.socolov@gmail.com>
  8. * @copyright vesta 2010-2011
  9. */
  10. class USER extends AjaxHandler
  11. {
  12. /**
  13. * Get USER entries
  14. *
  15. * @param Request $request
  16. * @return string - Ajax Reply
  17. */
  18. public function getListExecute($request)
  19. {
  20. $reply = array();
  21. $result = Vesta::execute(Vesta::V_LIST_SYS_USERS, array(Config::get('response_type')));
  22. $users = array('Han Solo', 'Darth Vader', 'Jabba the Hutt', 'Boba Fett', 'Jango Fett', ' Aurra Sing', 'Padme',
  23. 'Tusken Raider', 'General Grievous', 'Wedge Antilles', 'Padme Amidala', 'Bib Fortuna', 'Kyle Katarn',
  24. 'Quinlan Vos', 'Princess Leia', 'Obi-Wan Kenobi', 'Han Solo', 'Hondo Ohnaka', 'Noa Briqualon', 'C3P0',
  25. 'R2-D2', 'Quinlan Vos', 'Mara Jade' , 'Luke Skywalker', 'Luke Skywalker' , 'Luke Skywalker'
  26. );
  27. foreach ($result['data'] as $user => $details) {
  28. $fullname_id = rand(0, count($users)-1);
  29. $fullname = $users[$fullname_id];
  30. $reply[$user] = array(
  31. "LOGIN_NAME" => $user,
  32. "FULLNAME" => $fullname, // TODO skid
  33. "PACKAGE" => $details['PACKAGE'],
  34. "WEB_DOMAINS" => $details['WEB_DOMAINS'],
  35. "WEB_SSL" => $details['WEB_SSL'],
  36. "WEB_ALIASES" => $details['WEB_ALIASES'],
  37. "DATABASES" => $details['DATABASES'],
  38. "MAIL_DOMAINS" => $details['MAIL_DOMAINS'],
  39. "MAIL_BOXES" => $details['MAIL_BOXES'],
  40. "MAIL_FORWARDERS" => $details['MAIL_FORWARDERS'],
  41. "DNS_DOMAINS" => $details['DNS_DOMAINS'],
  42. "DISK_QUOTA" => $details['DISK_QUOTA'],//$disk_quota,
  43. "BANDWIDTH" => $details['BANDWIDTH'],//$bandwidth,
  44. "NS_LIST" => array($details['NS1'], $details['NS2']), // TODO skid
  45. "SHELL" => $details['"SHELL'],
  46. "BACKUPS" => $details['BACKUPS'],
  47. "WEB_TPL" => $details['WEB_TPL'],
  48. "MAX_CHILDS" => $details['MAX_CHILDS'],
  49. "SUSPENDED" => $details['SUSPENDED'],
  50. "OWNER" => $details['OWNER'],
  51. "ROLE" => $details['ROLE'],
  52. "IP_OWNED" => $details['IP_OWNED'],
  53. "U_CHILDS" => $details['U_CHILDS'],
  54. "U_DISK" => $details['U_DISK'],//$u_disk,
  55. "U_BANDWIDTH" => $details['U_BANDWIDTH'],//$u_bandwidth,
  56. "U_WEB_DOMAINS" => $details['U_WEB_DOMAINS'],
  57. "U_WEB_SSL" => $details['U_WEB_SSL'],
  58. "U_DNS_DOMAINS" => $details['U_DNS_DOMAINS'],
  59. "U_DATABASES" => $details['U_DATABASES'],
  60. "U_MAIL_DOMAINS" => $details['U_MAIL_DOMAINS'],
  61. "CONTACT" => $details['CONTACT'],
  62. "DATE" => $details['DATE'],
  63. "U_MAIL_BOXES" => rand(1, 10), // TODO: skid
  64. "U_MAIL_FORWARDERS" => rand(1, 10), // TODO: skid
  65. "REPORTS_ENABLED" => 'enabled' // TODO: skid
  66. );
  67. }
  68. return $this->reply(TRUE, $reply);
  69. }
  70. /**
  71. * Add USER entry
  72. *
  73. * @param Request $request
  74. * @return string - Ajax Reply
  75. */
  76. public function addExecute($_spell = FALSE)
  77. {
  78. $r = new Request();
  79. if ($_spell) {
  80. $_s = $_spell;
  81. }
  82. else {
  83. $_s = $r->getSpell();
  84. }
  85. $_user = 'vesta';
  86. $params = array(
  87. 'USER' => $_s['USER'],
  88. 'PASSWORD' => $_s['PASSWORD'],
  89. 'EMAIL' => $_s['EMAIL'],
  90. 'ROLE' => $_s['ROLE'],
  91. 'OWNER' => $_user,
  92. 'PACKAGE' => $_s['PACKAGE'],
  93. 'NS1' => $_s['NS1'],
  94. 'NS2' => $_s['NS2']
  95. );
  96. $result = Vesta::execute(Vesta::V_ADD_SYS_USER, $params);
  97. if (!$result['status']) {
  98. $this->errors[] = array($result['error_code'] => $result['error_message']);
  99. }
  100. return $this->reply($result['status'], $result['data']);
  101. }
  102. /**
  103. * Delete USER entry
  104. *
  105. * @param Request $request
  106. * @return string - Ajax Reply
  107. */
  108. public function delExecute($_spell = false)
  109. {
  110. $r = new Request();
  111. if ($_spell) {
  112. $_s = $_spell;
  113. }
  114. else {
  115. $_s = $r->getSpell();
  116. }
  117. $_user = 'vesta';
  118. $params = array(
  119. 'USER' => $_s['USER']
  120. );
  121. $result = Vesta::execute(Vesta::V_DEL_SYS_USER, $params);
  122. if (!$result['status']) {
  123. $this->errors[] = array($result['error_code'] => $result['error_message']);
  124. }
  125. return $this->reply($result['status'], $result['data']);
  126. }
  127. /**
  128. * Change USER entry
  129. *
  130. * @param Request $request
  131. * @return string - Ajax Reply
  132. */
  133. public function changeExecute($request)
  134. {
  135. $r = new Request();
  136. $_s = $r->getSpell();
  137. $_old = $_s['old'];
  138. $_new = $_s['new'];
  139. $_USER = $_new['USER'];
  140. if ($_old['USER'] != $_new['USER']) {
  141. $result = array();
  142. // creating new user
  143. $result = $this->addExecute($_new);
  144. // deleting old
  145. if ($result['status']) {
  146. $result = array();
  147. $result = $this->delExecute($_old);
  148. return $this->reply($this->status, '');
  149. }
  150. }
  151. if ($_old['PASSWORD'] != $_new['PASSWORD']) {
  152. $result = array();
  153. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_PASSWORD, array('USER' => $_USER, 'PASSWORD' => $_new['PASSWORD']));
  154. if (!$result['status']) {
  155. $this->status = FALSE;
  156. $this->errors['PASSWORD'] = array($result['error_code'] => $result['error_message']);
  157. }
  158. }
  159. if ($_old['PACKAGE'] != $_new['PACKAGE']) {
  160. $result = array();
  161. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_PACKAGE, array('USER' => $_USER, 'PACKAGE' => $_new['PACKAGE']));
  162. if (!$result['status']) {
  163. $this->status = FALSE;
  164. $this->errors['PACKAGE'] = array($result['error_code'] => $result['error_message']);
  165. }
  166. }
  167. if ($_old['EMAIL'] != $_new['EMAIL']) {
  168. $result = array();
  169. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_CONTACT, array('USER' => $_USER, 'EMAIL' => $_new['EMAIL']));
  170. if (!$result['status']) {
  171. $this->status = FALSE;
  172. $this->errors['EMAIL'] = array($result['error_code'] => $result['error_message']);
  173. }
  174. }
  175. if ($_old['NS1'] != $_new['NS1'] || $_old['NS2'] != $_new['NS2']) {
  176. $result = array();
  177. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_NS, array('USER' => $_USER, 'NS1' => $_new['NS1'], 'NS2' => $_new['NS2']));
  178. if (!$result['status']) {
  179. $this->status = FALSE;
  180. $this->errors['NS'] = array($result['error_code'] => $result['error_message']);
  181. }
  182. }
  183. if ($_old['SHELL'] != $_new['SHELL']) {
  184. $result = array();
  185. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_SHELL, array('USER' => $_USER, 'SHELL' => $_new['SHELL']));
  186. if (!$result['status']) {
  187. $this->status = FALSE;
  188. $this->errors['SHELL'] = array($result['error_code'] => $result['error_message']);
  189. }
  190. }
  191. if (!$this->status) {
  192. Vesta::execute(Vesta::V_CHANGE_SYS_USER_PASSWORD, array('USER' => $_USER, 'PASSWORD' => $_old['PASSWORD']));
  193. Vesta::execute(Vesta::V_CHANGE_SYS_USER_PACKAGE, array('USER' => $_USER, 'PACKAGE' => $_old['PACKAGE']));
  194. Vesta::execute(Vesta::V_CHANGE_SYS_USER_CONTACT, array('USER' => $_USER, 'EMAIL' => $_old['EMAIL']));
  195. Vesta::execute(Vesta::V_CHANGE_SYS_USER_NS, array('USER' => $_USER, 'NS1' => $_old['NS1'], 'NS2' => $_old['NS2']));
  196. Vesta::execute(Vesta::V_CHANGE_SYS_USER_SHELL, array('USER' => $_USER, 'SHELL' => $_old['SHELL']));
  197. }
  198. return $this->reply($this->status, '');
  199. }
  200. }