USER.class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /**
  3. * USERS
  4. *
  5. * @author Naumov-Socolov <naumov.socolov@gmail.com>
  6. * @author Malishev Dima <dima.malishev@gmail.com>
  7. * @author vesta, http://vestacp.com/
  8. * @copyright vesta 2010-2011
  9. */
  10. class USER extends AjaxHandler
  11. {
  12. /**
  13. * Get list
  14. *
  15. * @param Request $request
  16. * @return
  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. foreach ($result as $ip => $details)
  23. {
  24. $reply[] = array(
  25. 'interface' => $details['INTERFACE'],
  26. 'sys_users' => $details['U_SYS_USERS'],
  27. 'web_domains' => $details['U_WEB_DOMAINS'],
  28. 'status' => $details['STATUS'],
  29. 'ip' => $ip,
  30. 'net_mask' => $details['NETMASK'],
  31. 'name' => $details['NAME'],
  32. 'owner' => $details['OWNER'],
  33. 'created_at' => date(Config::get('ui_date_format', strtotime($details['DATE'])))
  34. );
  35. }
  36. return $this->reply(true, $result);
  37. }
  38. /**
  39. * Add action
  40. *
  41. * @param Request $request
  42. * @return
  43. */
  44. public function addExecute($_spell = false)
  45. {
  46. $r = new Request();
  47. if ($_spell)
  48. {
  49. $_s = $_spell;
  50. }
  51. else
  52. {
  53. $_s = $r->getSpell();
  54. }
  55. $_user = 'vesta';
  56. $params = array(
  57. 'USER' => $_s['USER'],
  58. 'PASSWORD' => $_s['PASSWORD'],
  59. 'EMAIL' => $_s['EMAIL'],
  60. 'ROLE' => $_s['ROLE'],
  61. 'OWNER' => $_user,
  62. 'PACKAGE' => $_s['PACKAGE'],
  63. 'NS1' => $_s['NS1'],
  64. 'NS2' => $_s['NS2']
  65. );
  66. $result = Vesta::execute(Vesta::V_ADD_SYS_USER, $params);
  67. if (!$result['status'])
  68. {
  69. $this->errors[] = array($result['error_code'] => $result['error_message']);
  70. }
  71. return $this->reply($result['status'], $result['data']);
  72. }
  73. /**
  74. * Delete action
  75. *
  76. * @param Request $request
  77. * @return
  78. */
  79. public function delExecute($_spell = false)
  80. {
  81. $r = new Request();
  82. if ($_spell)
  83. {
  84. $_s = $_spell;
  85. }
  86. else
  87. {
  88. $_s = $r->getSpell();
  89. }
  90. $_user = 'vesta';
  91. $params = array(
  92. 'USER' => $_s['USER']
  93. );
  94. $result = Vesta::execute(Vesta::V_DEL_SYS_USER, $params);
  95. if (!$result['status'])
  96. {
  97. $this->errors[] = array($result['error_code'] => $result['error_message']);
  98. }
  99. return $this->reply($result['status'], $result['data']);
  100. }
  101. /**
  102. * Change action
  103. *
  104. * @param Request $request
  105. * @return
  106. */
  107. public function changeExecute($request)
  108. {
  109. $r = new Request();
  110. $_s = $r->getSpell();
  111. $_old = $_s['old'];
  112. $_new = $_s['new'];
  113. $_USER = $_new['USER'];
  114. if($_old['USER'] != $_new['USER'])
  115. {
  116. $result = array();
  117. // creating new user
  118. $result = $this->addExecute($_new);
  119. // deleting old
  120. if ($result['status'])
  121. {
  122. $result = array();
  123. $result = $this->delExecute($_old);
  124. return $this->reply($this->status, '');
  125. }
  126. }
  127. if ($_old['PASSWORD'] != $_new['PASSWORD'])
  128. {
  129. $result = array();
  130. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_PASSWORD,
  131. array('USER' => $_USER, 'PASSWORD' => $_new['PASSWORD']));
  132. if (!$result['status'])
  133. {
  134. $this->status = FALSE;
  135. $this->errors['PASSWORD'] = array($result['error_code'] => $result['error_message']);
  136. }
  137. }
  138. if ($_old['PACKAGE'] != $_new['PACKAGE'])
  139. {
  140. $result = array();
  141. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_PACKAGE,
  142. array('USER' => $_USER, 'PACKAGE' => $_new['PACKAGE']));
  143. if (!$result['status'])
  144. {
  145. $this->status = FALSE;
  146. $this->errors['PACKAGE'] = array($result['error_code'] => $result['error_message']);
  147. }
  148. }
  149. if ($_old['EMAIL'] != $_new['EMAIL'])
  150. {
  151. $result = array();
  152. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_CONTACT,
  153. array('USER' => $_USER, 'EMAIL' => $_new['EMAIL']));
  154. if (!$result['status'])
  155. {
  156. $this->status = FALSE;
  157. $this->errors['EMAIL'] = array($result['error_code'] => $result['error_message']);
  158. }
  159. }
  160. if ($_old['NS1'] != $_new['NS1'] || $_old['NS2'] != $_new['NS2'])
  161. {
  162. $result = array();
  163. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_NS,
  164. array('USER' => $_USER, 'NS1' => $_new['NS1'], 'NS2' => $_new['NS2']));
  165. if (!$result['status'])
  166. {
  167. $this->status = FALSE;
  168. $this->errors['NS'] = array($result['error_code'] => $result['error_message']);
  169. }
  170. }
  171. if ($_old['SHELL'] != $_new['SHELL'])
  172. {
  173. $result = array();
  174. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_SHELL,
  175. array('USER' => $_USER, 'SHELL' => $_new['SHELL']));
  176. if (!$result['status'])
  177. {
  178. $this->status = FALSE;
  179. $this->errors['SHELL'] = array($result['error_code'] => $result['error_message']);
  180. }
  181. }
  182. if (!$this->status)
  183. {
  184. Vesta::execute(Vesta::V_CHANGE_SYS_USER_PASSWORD, array('USER' => $_USER, 'PASSWORD' => $_old['PASSWORD']));
  185. Vesta::execute(Vesta::V_CHANGE_SYS_USER_PACKAGE, array('USER' => $_USER, 'PACKAGE' => $_old['PACKAGE']));
  186. Vesta::execute(Vesta::V_CHANGE_SYS_USER_CONTACT, array('USER' => $_USER, 'EMAIL' => $_old['EMAIL']));
  187. // change role // $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_PACKAGE, array('USER' => $_USER, 'PACKAGE' => $_new['PACKAGE']));
  188. Vesta::execute(Vesta::V_CHANGE_SYS_USER_NS, array('USER' => $_USER, 'NS1' => $_old['NS1'], 'NS2' => $_old['NS2']));
  189. Vesta::execute(Vesta::V_CHANGE_SYS_USER_SHELL, array('USER' => $_USER, 'SHELL' => $_old['SHELL']));
  190. }
  191. return $this->reply($this->status, '');
  192. }
  193. }