USER.class.php 10 KB

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