USER.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 $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 = implode('', array($details['FNAME'], ' ', $details['LNAME']));
  30. $nses = $this->getNS($user, $details);
  31. $user_details = array(
  32. "FNAME" => $details['FNAME'],
  33. "LNAME" => $details['LNAME'],
  34. "LOGIN_NAME" => $user,
  35. "FULLNAME" => $fullname,
  36. "PACKAGE" => $details['PACKAGE'],
  37. "WEB_DOMAINS" => $details['WEB_DOMAINS'],
  38. "WEB_SSL" => $details['WEB_SSL'],
  39. "WEB_ALIASES" => $details['WEB_ALIASES'],
  40. "DATABASES" => $details['DATABASES'],
  41. "MAIL_DOMAINS" => $details['MAIL_DOMAINS'],
  42. "MAIL_BOXES" => $details['MAIL_BOXES'],
  43. "MAIL_FORWARDERS" => $details['MAIL_FORWARDERS'],
  44. "DNS_DOMAINS" => $details['DNS_DOMAINS'],
  45. "DISK_QUOTA" => $details['DISK_QUOTA'],
  46. "BANDWIDTH" => $details['BANDWIDTH'],
  47. "SHELL" => $details['SHELL'],
  48. "BACKUPS" => $details['BACKUPS'],
  49. "WEB_TPL" => $details['WEB_TPL'],
  50. "MAX_CHILDS" => $details['MAX_CHILDS'],
  51. "SUSPENDED" => $details['SUSPENDED'],
  52. "OWNER" => $details['OWNER'],
  53. "ROLE" => $details['ROLE'],
  54. "IP_OWNED" => $details['IP_OWNED'],
  55. "U_CHILDS" => $details['U_CHILDS'],
  56. "U_DISK" => $details['U_DISK'],//$u_disk,
  57. "U_BANDWIDTH" => $details['U_BANDWIDTH'],//$u_bandwidth,
  58. "U_WEB_DOMAINS" => $details['U_WEB_DOMAINS'],
  59. "U_WEB_SSL" => $details['U_WEB_SSL'],
  60. "U_DNS_DOMAINS" => $details['U_DNS_DOMAINS'],
  61. "U_DATABASES" => $details['U_DATABASES'],
  62. "U_MAIL_DOMAINS" => $details['U_MAIL_DOMAINS'],
  63. "CONTACT" => $details['CONTACT'],
  64. "DATE" => $details['DATE'],
  65. "U_MAIL_BOXES" => rand(1, 10), // TODO: skid
  66. "U_MAIL_FORWARDERS" => rand(1, 10), // TODO: skid
  67. "REPORTS_ENABLED" => 'enabled' // TODO: skid
  68. );
  69. $reply[$user] = array_merge($user_details, $nses);
  70. }
  71. return $this->reply(TRUE, $reply);
  72. }
  73. /**
  74. * Add USER entry
  75. *
  76. * @param Request $request
  77. * @return string - Ajax Reply
  78. */
  79. public function addExecute(Request $request)
  80. {
  81. $spell = $request->getParameter('spell');
  82. $user = $this->getLoggedUser();
  83. $params = array(
  84. 'USER' => $spell['LOGIN_NAME'],
  85. 'PASSWORD' => $spell['PASSWORD'],
  86. 'EMAIL' => $spell['CONTACT'],
  87. 'ROLE' => $spell['ROLE'],
  88. 'OWNER' => $user['uid'],
  89. 'PACKAGE' => $spell['PACKAGE'],
  90. 'FNAME' => $spell['FNAME'],
  91. 'LNAME' => $spell['LNAME']
  92. );
  93. $result = Vesta::execute(Vesta::V_ADD_SYS_USER, $params);
  94. // Reports
  95. $enable_reports = Utils::getCheckboxBooleanValue($spell['REPORTS_ENABLED']);
  96. $reports_result = $this->setUserReports($spell['LOGIN_NAME'], $spell['REPORTS_ENABLED']);
  97. // NS
  98. $ns_result = $this->setNSentries($spell['LOGIN_NAME'], $spell);
  99. if (!$result['status']) {
  100. $this->errors[] = array($result['error_code'] => $result['error_message']);
  101. }
  102. return $this->reply($result['status'], $result['data']);
  103. }
  104. /**
  105. * Delete USER entry
  106. *
  107. * @param Request $request
  108. * @return string - Ajax Reply
  109. */
  110. public function deleteExecute(Request $request)
  111. {
  112. $user = $this->getLoggedUser();
  113. $spell = $request->getParameter('spell');
  114. $params = array(
  115. 'USER' => $spell['LOGIN_NAME']
  116. );
  117. $result = Vesta::execute(Vesta::V_DEL_SYS_USER, $params);
  118. if (!$result['status']) {
  119. $this->errors[] = array($result['error_code'] => $result['error_message']);
  120. }
  121. return $this->reply($result['status'], $result['data']);
  122. }
  123. /**
  124. * Change USER entry
  125. *
  126. * @param Request $request
  127. * @return string - Ajax Reply
  128. */
  129. public function changeExecute(Request $request)
  130. {
  131. $_new = $request->getParameter('new');
  132. $_old = $request->getParameter('old');
  133. $_USER = $_old['LOGIN_NAME'];
  134. if ($_old['PASSWORD'] != $_new['PASSWORD']) {
  135. $result = array();
  136. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_PASSWORD, array('USER' => $_USER, 'PASSWORD' => $_new['PASSWORD']));
  137. if (!$result['status']) {
  138. $this->status = FALSE;
  139. $this->errors['PASSWORD'] = array($result['error_code'] => $result['error_message']);
  140. }
  141. }
  142. if ($_old['PACKAGE'] != $_new['PACKAGE']) {
  143. $result = array();
  144. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_PACKAGE, array('USER' => $_USER, 'PACKAGE' => $_new['PACKAGE']));
  145. if (!$result['status']) {
  146. $this->status = FALSE;
  147. $this->errors['PACKAGE'] = array($result['error_code'] => $result['error_message']);
  148. }
  149. }
  150. if ($_old['CONTACT'] != $_new['CONTACT']) {
  151. $result = array();
  152. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_CONTACT, array('USER' => $_USER, 'EMAIL' => $_new['CONTACT']));
  153. if (!$result['status']) {
  154. $this->status = FALSE;
  155. $this->errors['EMAIL'] = array($result['error_code'] => $result['error_message']);
  156. }
  157. }
  158. $this->setNSentries($_USER, $_new);
  159. $names = array(
  160. 'USER' => $_USER,
  161. 'NAME' => $_new['LOGIN_NAME'],
  162. 'FNAME' => $_new['FNAME'],
  163. 'LNAME' => $_new['LNAME']
  164. );
  165. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_NAME, $names);
  166. if (!$result['status']) {
  167. $this->status = FALSE;
  168. $this->errors['NAMES'] = array($result['error_code'] => $result['error_message']);
  169. }
  170. /*if ($_old['SHELL'] != $_new['SHELL']) {
  171. $result = array();
  172. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_SHELL, array('USER' => $_USER, 'SHELL' => $_new['SHELL']));
  173. if (!$result['status']) {
  174. $this->status = FALSE;
  175. $this->errors['SHELL'] = array($result['error_code'] => $result['error_message']);
  176. }
  177. }*/
  178. if (!$this->status) {
  179. Vesta::execute(Vesta::V_CHANGE_SYS_USER_PASSWORD, array('USER' => $_USER, 'PASSWORD' => $_old['PASSWORD']));
  180. Vesta::execute(Vesta::V_CHANGE_SYS_USER_PACKAGE, array('USER' => $_USER, 'PACKAGE' => $_old['PACKAGE']));
  181. Vesta::execute(Vesta::V_CHANGE_SYS_USER_CONTACT, array('USER' => $_USER, 'EMAIL' => $_old['EMAIL']));
  182. Vesta::execute(Vesta::V_CHANGE_SYS_USER_NS, array('USER' => $_USER, 'NS1' => $_old['NS1'], 'NS2' => $_old['NS2']));
  183. Vesta::execute(Vesta::V_CHANGE_SYS_USER_SHELL, array('USER' => $_USER, 'SHELL' => $_old['SHELL']));
  184. }
  185. return $this->reply($this->status, '');
  186. }
  187. protected function setUserReports($user, $enabled)
  188. {
  189. if ($enabled === true) {
  190. $result = Vesta::execute(Vesta::V_ADD_SYS_USER_REPORTS, array('USER' => $user));
  191. }
  192. else {
  193. $result = Vesta::execute(Vesta::V_DEL_SYS_USER_REPORTS, array('USER' => $user));
  194. }
  195. return $result['status'];
  196. }
  197. protected function setNSentries($user, $data)
  198. {
  199. $ns = array();
  200. $ns['USER'] = $user;
  201. $ns['NS1'] = $data['NS1'];
  202. $ns['NS2'] = $data['NS2'];
  203. $ns['NS3'] = isset($data['NS3']) ? $data['NS3'] : '';
  204. $ns['NS4'] = isset($data['NS4']) ? $data['NS4'] : '';
  205. $ns['NS5'] = isset($data['NS5']) ? $data['NS5'] : '';
  206. $ns['NS6'] = isset($data['NS6']) ? $data['NS6'] : '';
  207. $ns['NS7'] = isset($data['NS7']) ? $data['NS7'] : '';
  208. $ns['NS8'] = isset($data['NS8']) ? $data['NS8'] : '';
  209. $result = Vesta::execute(Vesta::V_CHANGE_SYS_USER_NS, $ns);
  210. return $result['status'];
  211. }
  212. protected function getNS($user, $data)
  213. {
  214. $result = array();
  215. $ns_str = $data['NS'];
  216. $ns_list = explode(',', $ns_str);
  217. foreach (range(0, 7) as $index) {
  218. $result['NS'.($index + 1)] = @trim(@$ns_list[$index]);
  219. }
  220. return $result;
  221. }
  222. }