WEB_DOMAIN.class.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <?php
  2. /**
  3. * DOMAIN
  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 WEB_DOMAIN extends AjaxHandler
  11. {
  12. public function getListExecute(Request $request)
  13. {
  14. $user = $this->getLoggedUser();
  15. $reply = array();
  16. $result = Vesta::execute(Vesta::V_LIST_WEB_DOMAINS, array('USER' => $user['uid']), self::JSON);
  17. $stat = array();
  18. $result_stat = Vesta::execute('v_list_web_domains_stats', array('USER' => $user['uid']), self::JSON);
  19. foreach ($result_stat['data'] as $w_d => $w_d_details) {
  20. $stat[$w_d] = $w_d_details;
  21. }
  22. foreach($result['data'] as $web_domain => $record)
  23. {
  24. $web_details = array(
  25. 'IP' => $record['IP'],
  26. 'U_DISK' => $record['U_DISK'],
  27. 'U_BANDWIDTH' => $record['U_BANDWIDTH'],
  28. 'TPL' => $record['TPL'],
  29. 'ALIAS' => $record['ALIAS'],
  30. 'PHP' => $record['PHP'],
  31. 'CGI' => $record['CGI'],
  32. 'ELOG' => $record['ELOG'],
  33. 'STAT' => $record['STATS'],
  34. 'STATS_LOGIN' => $record['STATS_AUTH'],
  35. 'SSL' => $record['SSL'],
  36. 'SSL_HOME' => $record['SSL_HOME'],
  37. 'SSL_CERT' => $record['SSL_CERT'],
  38. 'NGINX' => $record['NGINX'],
  39. 'NGINX_EXT' => $record['NGINX_EXT'],
  40. 'SUSPEND' => $record['SUSPEND'],
  41. 'DATE' => date(Config::get('ui_date_format', strtotime($record['DATE'])))
  42. );
  43. $web_details['STAT'] == '' ? $web_details['STAT'] = 'none' : true;
  44. $reply[$web_domain] = $web_details;
  45. }
  46. if (!$result['status']) {
  47. $this->errors[] = array($result['error_code'] => $result['error_message']);
  48. }
  49. return $this->reply($result['status'], $reply);
  50. }
  51. public function addExecute(Request $request)
  52. {
  53. $_s = $request->getParameter('spell');
  54. $user = $this->getLoggedUser();
  55. $params = array(
  56. 'USER' => $user['uid'],
  57. 'DOMAIN' => $_s['DOMAIN'],
  58. 'IP' => $_s['IP']
  59. );
  60. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN, $params);
  61. if (!$result['status']) {
  62. $this->errors[] = array($result['error_code'] => $result['error_message']);
  63. }
  64. if (!empty($_s['TPL'])) {
  65. $params = array(
  66. 'USER' => $user['uid'],
  67. 'DOMAIN' => $_s['DOMAIN'],
  68. 'TPL' => $_s['TPL']
  69. );
  70. $result = 0;
  71. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_TPL, $params);
  72. if (!$result['status']) {
  73. $this->errors['CHANGE_TPL'] = array($result['error_code'] => $result['error_message']);
  74. }
  75. }
  76. if (!empty($_s['ALIAS'])) {
  77. $alias = str_replace("\n", "", $_s['ALIAS']);
  78. $alias = str_replace("\n", "", $alias);
  79. foreach ($alias_arr as $alias) {
  80. $params = array(
  81. 'USER' => $user['uid'],
  82. 'DOMAIN' => $_s['DOMAIN'],
  83. 'ALIAS' => trim($alias)
  84. );
  85. $result = 0;
  86. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ALIAS, $params);
  87. if (!$result['status']) {
  88. $this->errors['ALIAS'] = array($result['error_code'] => $result['error_message']);
  89. }
  90. }
  91. }
  92. if (!empty($_s['STATS']) && @$_s['STATS'] != 'none') {
  93. $params = array(
  94. 'USER' => $user['uid'],
  95. 'DOMAIN' => $_s['DOMAIN'],
  96. 'STAT' => $_s['STAT']);
  97. $result = 0;
  98. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT, $params);
  99. if (!$result['status']) {
  100. $this->errors['STATS'] = array($result['error_code'] => $result['error_message']);
  101. }
  102. }
  103. if (!empty($_s['STAT_AUTH']) && @Utils::getCheckboxBooleanValue($_s['STATS_AUTH'])) {
  104. $params = array(
  105. 'USER' => $user['uid'],
  106. 'DOMAIN' => $_s['DOMAIN'],
  107. 'STAT_USER' => $_s['STAT_USER'],
  108. 'STAT_PASSWORS' => $_s['STAT_PASSWORD']
  109. );
  110. $result = 0;
  111. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT_AUTH, $params);
  112. if(!$result['status'])
  113. $this->errors['STAT_AUTH'] = array($result['error_code'] => $result['error_message']);
  114. }
  115. if (!empty($_new['CGI'])) {
  116. if (Utils::getCheckboxBooleanValue($_new['CGI'])) {
  117. $result = array();
  118. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_CGI, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  119. if (!$result['status']) {
  120. $this->status = FALSE;
  121. $this->errors['ADD_CGI'] = array($result['error_code'] => $result['error_message']);
  122. }
  123. }
  124. }
  125. if (!empty($_new['ELOG'])) {
  126. if (Utils::getCheckboxBooleanValue($_new['ELOG'])) {
  127. $result = array();
  128. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ELOG, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  129. if (!$result['status']) {
  130. $this->status = FALSE;
  131. $this->errors['ADD_ELOG'] = array($result['error_code'] => $result['error_message']);
  132. }
  133. }
  134. }
  135. /*if ($_s['SSL']) {
  136. $params = array(
  137. 'USER' => $user[''],
  138. 'DOMAIN' => $_s['DOMAIN'],
  139. 'SSL_CERT' => $_s['SSL_CERT']
  140. );
  141. if ($_s['SSL_HOME']) {
  142. $params['SSL_HOME'] = $_s['SSL_HOME'];
  143. }
  144. $result = 0;
  145. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
  146. if (!$result['status']) {
  147. $this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
  148. }
  149. }
  150. if ($_s['SSL_HOME']) {
  151. }*/
  152. /*if (!empty($_s['DNS'])) {
  153. $params = array(
  154. 'USER' => $user['uid'],
  155. 'DNS_DOMAIN' => $_s['DOMAIN'],
  156. 'IP' => $_s['IP']
  157. );
  158. require_once V_ROOT_DIR . 'api/DNS.class.php';
  159. $dns = new DNS();
  160. $result = 0;
  161. $result = $dns->addExecute($params);
  162. if (!$result['status']) {
  163. $this->errors['DNS_DOMAIN'] = array($result['error_code'] => $result['error_message']);
  164. }
  165. }*/
  166. /*if (!empty($_s['MAIL'])) {
  167. $params = array(
  168. 'USER' => $_user,
  169. 'MAIL_DOMAIN' => $_s['DOMAIN'],
  170. 'IP' => $_s['IP']
  171. );
  172. require_once V_ROOT_DIR . 'api/MAIL.class.php';
  173. $mail = new MAIL();
  174. $result = 0;
  175. $result = $mail->addExecute($params);
  176. if (!$result['status'])
  177. $this->errors['MAIL_DOMAIN'] = array($result['error_code'] => $result['error_message']);
  178. }*/
  179. return $this->reply($result['status'], $result['data']);
  180. }
  181. public function deleteExecute(Request $request)
  182. {
  183. $_s = $request->getParameter('spell');
  184. $user = $this->getLoggedUser();
  185. $params = array(
  186. 'USER' => $user['uid'],
  187. 'DOMAIN' => $_s['DOMAIN']
  188. );
  189. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN, $params);
  190. if (!$result['status']) {
  191. $this->errors[] = array($result['error_code'] => $result['error_message']);
  192. }
  193. $params = array(
  194. 'USER' => $_user,
  195. 'DNS_DOMAIN' => $_s['DOMAIN']
  196. );
  197. return $this->reply($result['status'], $result['data']);
  198. }
  199. public function changeExecute(Request $request)
  200. {
  201. $_s = $request->getParameter('spell');
  202. $_old = $request->getParameter('old');
  203. $_new = $request->getParameter('new');
  204. $_old['ELOG'] = $_old['ELOG'] == 'yes' ? 'on' : 'off';
  205. $_old['CGI'] = $_old['CGI'] == 'yes' ? 'on' : 'off';
  206. $_old['AUTH'] = $_old['AUTH'] == 'yes' ? 'on' : 'off';
  207. $_old['SSL'] = $_old['SSL'] == 'yes' ? 'on' : 'off';
  208. $user = $this->getLoggedUser();
  209. $_DOMAIN = $_new['DOMAIN'];
  210. if ($_old['IP'] != $_new['IP']) {
  211. $result = array();
  212. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_IP, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'IP' => $_new['IP']));
  213. if (!$result['status']) {
  214. $this->status = FALSE;
  215. $this->errors['IP_ADDRESS'] = array($result['error_code'] => $result['error_message']);
  216. }
  217. }
  218. if ($_old['TPL'] != $_new['TPL']) {
  219. $result = array();
  220. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_TPL, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'TPL' => $_new['TPL']));
  221. if (!$result['status']) {
  222. $this->status = FALSE;
  223. $this->errors['TPL'] = array($result['error_code'] => $result['error_message']);
  224. }
  225. }
  226. if ($_old['ALIAS'] != $_new['ALIAS']) {
  227. $result = array();
  228. $old_arr = explode(',', $_old['ALIAS']);
  229. $new_arr = explode(',', $_new['ALIAS']);
  230. $added = array_diff($new_arr, $old_arr);
  231. $deleted = array_diff($old_arr, $new_arr);
  232. foreach ($added as $alias) {
  233. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ALIAS, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'ALIAS' => $alias));
  234. if (!$result['status']) {
  235. $this->status = FALSE;
  236. $this->errors['ADD_ALIAS'] = array($result['error_code'] => $result['error_message']);
  237. }
  238. }
  239. foreach ($deleted as $alias) {
  240. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ALIAS, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'ALIAS' => $alias));
  241. if (!$result['status']) {
  242. $this->status = FALSE;
  243. $this->errors['DEL_ALIAS'] = array($result['error_code'] => $result['error_message']);
  244. }
  245. }
  246. }
  247. if (($_old['STATH_AUTH'] != $_new['STAT_AUTH']) && !empty($_s['STAT_AUTH']) && @Utils::getCheckboxBooleanValue($_s['STATS_AUTH'])) {
  248. $params = array(
  249. 'USER' => $user['uid'],
  250. 'DOMAIN' => $_DOMAIN,
  251. 'STAT_USER' => $_new['STAT_USER'],
  252. 'STAT_PASSWORS' => $_new['STAT_PASSWORD']
  253. );
  254. $result = 0;
  255. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT_AUTH, $params);
  256. if(!$result['status']) {
  257. $this->errors['STAT_AUTH'] = array($result['error_code'] => $result['error_message']);
  258. }
  259. }
  260. if (($_old['STAT'] != $_new['STAT'])) {
  261. if ($_new['STAT'] != 'none') {
  262. $result = array();
  263. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'STAT' => $_new['STAT']));
  264. if (!$result['status']) {
  265. $this->status = FALSE;
  266. $this->errors['ADD_STAT'] = array($result['error_code'] => $result['error_message']);
  267. }
  268. }
  269. else {
  270. $result = array();
  271. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  272. if (!$result['status']) {
  273. $this->status = FALSE;
  274. $this->errors['DEL_STAT'] = array($result['error_code'] => $result['error_message']);
  275. }
  276. $result = array();
  277. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT_AUTH, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'STAT_USER' => $_new['STAT_USER']));
  278. if (!$result['status']) {
  279. $this->status = FALSE;
  280. $this->errors['DEL_STAT_AUTH'] = array($result['error_code'] => $result['error_message']);
  281. }
  282. }
  283. }
  284. if (($_old['CGI'] != $_new['CGI'])) {
  285. if (Utils::getCheckboxBooleanValue($_new['CGI'])) {
  286. $result = array();
  287. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_CGI, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  288. if (!$result['status']) {
  289. $this->status = FALSE;
  290. $this->errors['ADD_CGI'] = array($result['error_code'] => $result['error_message']);
  291. }
  292. }
  293. else {
  294. $result = array();
  295. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_CGI, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  296. if (!$result['status']) {
  297. $this->status = FALSE;
  298. $this->errors['DEL_CGI'] = array($result['error_code'] => $result['error_message']);
  299. }
  300. }
  301. }
  302. if (($_old['ELOG'] != $_new['ELOG'])) {
  303. if (Utils::getCheckboxBooleanValue($_new['ELOG'])) {
  304. $result = array();
  305. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ELOG, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  306. if (!$result['status']) {
  307. $this->status = FALSE;
  308. $this->errors['ADD_ELOG'] = array($result['error_code'] => $result['error_message']);
  309. }
  310. }
  311. else {
  312. $result = array();
  313. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ELOG, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  314. if (!$result['status']) {
  315. $this->status = FALSE;
  316. $this->errors['DEL_ELOG'] = array($result['error_code'] => $result['error_message']);
  317. }
  318. }
  319. }
  320. return $this->reply($result['status'], $result['data']);
  321. }
  322. public function suspendExecute(Request $request)
  323. {
  324. $_s = $request->getParameter('spell');
  325. $user = $this->getLoggedUser();
  326. $params = array(
  327. 'USER' => $user['uid'],
  328. 'DOMAIN' => $_s['DOMAIN']
  329. );
  330. $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, $params);
  331. if (!$result['status']) {
  332. $this->errors[] = array($result['error_code'] => $result['error_message']);
  333. }
  334. return $this->reply($result['status'], $result['data']);
  335. }
  336. public function unsuspendExecute(Request $request)
  337. {
  338. $_s = $request->getParameter('spell');
  339. $user = $this->getLoggedUser();
  340. $params = array(
  341. 'USER' => $user['uid'],
  342. 'DOMAIN' => $_s['DOMAIN']
  343. );
  344. $result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, $params);
  345. if (!$result['status']) {
  346. $this->errors[] = array($result['error_code'] => $result['error_message']);
  347. }
  348. return $this->reply($result['status'], $result['data']);
  349. }
  350. }