WEB_DOMAIN.class.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <?php
  2. /**
  3. * DOMAIN
  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 WEB_DOMAIN extends AjaxHandler
  11. {
  12. /**
  13. * Get list
  14. *
  15. * @param Request $request
  16. * @return
  17. */
  18. public function getListExecute($request)
  19. {
  20. $_user = 'vesta';
  21. $reply = array();
  22. $result = Vesta::execute(Vesta::V_LIST_WEB_DOMAINS, array($_user, Config::get('response_type')));
  23. foreach ($result['data'] as $web_domain => $data)
  24. {
  25. $reply[$web_domain] = array(
  26. 'IP' => $record['IP'],
  27. 'U_DISK' => $record['U_DISK'],
  28. 'U_BANDWIDTH' => $record['U_BANDWIDTH'],
  29. 'TPL' => $record['TPL'],
  30. 'ALIAS' => $record['ALIAS'],
  31. 'PHP' => $record['PHP'],
  32. 'CGI' => $record['CGI'],
  33. 'ELOG' => $record['ELOG'],
  34. 'STATS' => $record['STATS'],
  35. 'STATS_AUTH' => $record['STATS_AUTH'],
  36. 'SSL' => $record['SSL'],
  37. 'SSL_HOME' => $record['SSL_HOME'],
  38. 'SSL_CERT' => $record['SSL_CERT'],
  39. 'NGINX' => $record['NGINX'],
  40. 'NGINX_EXT' => $record['NGINX_EXT'],
  41. 'SUSPEND' => $record['SUSPEND'],
  42. 'DATE' => date(Config::get('ui_date_format', strtotime($record['DATE'])))
  43. );
  44. }
  45. if (!$result['status'])
  46. {
  47. $this->errors[] = array($result['error_code'] => $result['error_message']);
  48. }
  49. return $this->reply($result['status'], $reply);
  50. }
  51. /**
  52. * Add entry
  53. *
  54. * @param Request $request
  55. * @return
  56. */
  57. public function addExecute($request)
  58. {
  59. $r = new Request();
  60. $_s = $r->getSpell();
  61. $_user = 'vesta';
  62. $params = array(
  63. 'USER' => $_user,
  64. 'DOMAIN' => $_s['DOMAIN'],
  65. 'IP' => $_s['IP']
  66. );
  67. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN, $params);
  68. if (!$result['status'])
  69. {
  70. $this->errors[] = array(
  71. $result['error_code'] => $result['error_message']
  72. );
  73. }
  74. if ($_s['TPL'])
  75. {
  76. $params = array(
  77. 'USER' => $_user,
  78. 'DOMAIN' => $_s['DOMAIN'],
  79. 'TPL' => $_s['TPL']
  80. );
  81. $result = 0;
  82. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_TPL, $params);
  83. if (!$result['status'])
  84. {
  85. $this->errors['CHANGE_TPL'] = array(
  86. $result['error_code'] => $result['error_message']
  87. );
  88. }
  89. }
  90. if ($_s['ALIAS'])
  91. {
  92. $alias_arr = explode(',', $_s['ALIAS']);
  93. foreach ($alias_arr as $alias)
  94. {
  95. $params = array(
  96. 'USER' => $_user,
  97. 'DOMAIN' => $_s['DOMAIN'],
  98. 'ALIAS' => trim($alias)
  99. );
  100. $result = 0;
  101. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ALIAS, $params);
  102. if (!$result['status'])
  103. {
  104. $this->errors['ALIAS'] = array(
  105. $result['error_code'] => $result['error_message']
  106. );
  107. }
  108. }
  109. }
  110. if ($_s['STAT'])
  111. {
  112. $params = array(
  113. 'USER' => $_user,
  114. 'DOMAIN' => $_s['DOMAIN'],
  115. 'STAT' => $_s['STAT']
  116. );
  117. $result = 0;
  118. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT, $params);
  119. if (!$result['status'])
  120. {
  121. $this->errors['STATS'] = array(
  122. $result['error_code'] => $result['error_message']
  123. );
  124. }
  125. }
  126. if ($_s['STAT_AUTH'])
  127. {
  128. $params = array(
  129. 'USER' => $_user,
  130. 'DOMAIN' => $_s['DOMAIN'],
  131. 'STAT_USER' => $_s['STAT_USER'],
  132. 'STAT_PASSWORS' => $_s['STAT_PASSWORD']
  133. );
  134. $result = 0;
  135. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT_AUTH, $params);
  136. if (!$result['status'])
  137. {
  138. $this->errors['STAT_AUTH'] = array(
  139. $result['error_code'] => $result['error_message']
  140. );
  141. }
  142. }
  143. if ($_s['SSL'])
  144. {
  145. $params = array(
  146. 'USER' => $_user,
  147. 'DOMAIN' => $_s['DOMAIN'],
  148. 'SSL_CERT' => $_s['SSL_CERT']
  149. );
  150. if ($_s['SSL_HOME'])
  151. {
  152. $params['SSL_HOME'] = $_s['SSL_HOME'];
  153. }
  154. if ($_s['SSL_TEXT'])
  155. {
  156. // TODO: write it up
  157. }
  158. $result = 0;
  159. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
  160. if (!$result['status'])
  161. {
  162. $this->errors['SSL'] = array(
  163. $result['error_code'] => $result['error_message']
  164. );
  165. }
  166. }
  167. if ($_s['CREATE_DNS_DOMAIN'])
  168. {
  169. $params = array(
  170. 'USER' => $_user,
  171. 'DNS_DOMAIN' => $_s['DOMAIN'],
  172. 'IP' => $_s['IP']
  173. );
  174. require_once V_ROOT_DIR . 'api/DNS.class.php';
  175. $dns = new DNS();
  176. $result = 0;
  177. $result = $dns->addExecute($params);
  178. if (!$result['status'])
  179. {
  180. $this->errors['DNS_DOMAIN'] = array(
  181. $result['error_code'] => $result['error_message']
  182. );
  183. }
  184. }
  185. if ($_s['CREATE_MAIL_DOMAIN'])
  186. {
  187. $params = array(
  188. 'USER' => $_user,
  189. 'MAIL_DOMAIN' => $_s['DOMAIN'],
  190. 'IP' => $_s['IP']
  191. );
  192. require_once V_ROOT_DIR . 'api/MAIL.class.php';
  193. $mail = new MAIL();
  194. $result = 0;
  195. $result = $mail->addExecute($params);
  196. if (!$result['status'])
  197. {
  198. $this->errors['MAIL_DOMAIN'] = array(
  199. $result['error_code'] => $result['error_message']
  200. );
  201. }
  202. }
  203. return $this->reply($result['status'], $result['data']);
  204. }
  205. /**
  206. * Delete entry
  207. *
  208. * @param Request $request
  209. * @return
  210. */
  211. public function delExecute($request)
  212. {
  213. $r = new Request();
  214. $_s = $r->getSpell();
  215. $_user = 'vesta';
  216. $params = array(
  217. 'USER' => $_user,
  218. 'DOMAIN' => $_s['DOMAIN']
  219. );
  220. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN, $params);
  221. if (!$result['status'])
  222. $this->errors[] = array(
  223. $result['error_code'] => $result['error_message']
  224. );
  225. $params = array(
  226. 'USER' => $_user,
  227. 'DNS_DOMAIN' => $_s['DOMAIN']
  228. );
  229. require_once V_ROOT_DIR . 'api/DNS.class.php';
  230. $dns = new DNS();
  231. $result = $dns->delExecute($params);
  232. if (!$result['status'] && $result['error_code'] != 31) // domain not found
  233. {
  234. $this->errors['DNS'] = array(
  235. $result['error_code'] => $result['error_message']
  236. );
  237. }
  238. require_once V_ROOT_DIR . 'api/DNS.class.php';
  239. $params = array(
  240. 'USER' => $_user,
  241. 'MAIL_DOMAIN' => $_s['DOMAIN']
  242. );
  243. return $this->reply($result['status'], $result['data']);
  244. }
  245. /**
  246. * Change entry
  247. *
  248. * @param Request $request
  249. * @return
  250. */
  251. public function changeExecute($request)
  252. {
  253. $r = new Request();
  254. $_s = $r->getSpell();
  255. $_old = $_s['old'];
  256. $_new = $_s['new'];
  257. $_user = 'vesta';
  258. $_DOMAIN = $_new['DOMAIN'];
  259. if ($_old['IP'] != $_new['IP'])
  260. {
  261. $result = array();
  262. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_IP, array(
  263. 'USER' => $_user,
  264. 'DOMAIN' => $_DOMAIN,
  265. 'IP' => $_new['IP']
  266. ));
  267. if (!$result['status'])
  268. {
  269. $this->status = FALSE;
  270. $this->errors['IP_ADDRESS'] = array(
  271. $result['error_code'] => $result['error_message']
  272. );
  273. }
  274. }
  275. if ($_old['TPL'] != $_new['TPL'])
  276. {
  277. $result = array();
  278. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_TPL, array(
  279. 'USER' => $_user,
  280. 'DOMAIN' => $_DOMAIN,
  281. 'TPL' => $_new['TPL']
  282. ));
  283. if (!$result['status'])
  284. {
  285. $this->status = FALSE;
  286. $this->errors['TPL'] = array(
  287. $result['error_code'] => $result['error_message']
  288. );
  289. }
  290. }
  291. if ($_old['ALIAS'] != $_new['ALIAS'])
  292. {
  293. $result = array();
  294. $old_arr = explode(',', $_old['ALIAS']);
  295. $new_arr = explode(',', $_new['ALIAS']);
  296. $added = array_diff($new_arr, $old_arr);
  297. $deleted = array_diff($old_arr, $new_arr);
  298. foreach ($added as $alias)
  299. {
  300. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ALIAS, array(
  301. 'USER' => $_user,
  302. 'DOMAIN' => $_DOMAIN,
  303. 'ALIAS' => $alias
  304. ));
  305. if (!$result['status'])
  306. {
  307. $this->status = FALSE;
  308. $this->errors['ADD_ALIAS'] = array(
  309. $result['error_code'] => $result['error_message']
  310. );
  311. }
  312. }
  313. foreach ($deleted as $alias)
  314. {
  315. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ALIAS, array(
  316. 'USER' => $_user,
  317. 'DOMAIN' => $_DOMAIN,
  318. 'ALIAS' => $alias
  319. ));
  320. if (!$result['status'])
  321. {
  322. $this->status = FALSE;
  323. $this->errors['DEL_ALIAS'] = array(
  324. $result['error_code'] => $result['error_message']
  325. );
  326. }
  327. }
  328. }
  329. if ($_old['STAT'] != $_new['STAT'])
  330. {
  331. if ($_new['STAT'] == true)
  332. {
  333. $result = array();
  334. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT, array(
  335. 'USER' => $_user,
  336. 'DOMAIN' => $_DOMAIN,
  337. 'STAT' => $_new['STAT']
  338. ));
  339. if (!$result['status'])
  340. {
  341. $this->status = FALSE;
  342. $this->errors['ADD_STAT'] = array(
  343. $result['error_code'] => $result['error_message']
  344. );
  345. }
  346. }
  347. if ($_new['STAT'] == false)
  348. {
  349. $result = array();
  350. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT, array(
  351. 'USER' => $_user,
  352. 'DOMAIN' => $_DOMAIN
  353. ));
  354. if (!$result['status'])
  355. {
  356. $this->status = FALSE;
  357. $this->errors['DEL_STAT'] = array(
  358. $result['error_code'] => $result['error_message']
  359. );
  360. }
  361. $result = array();
  362. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT_AUTH, array(
  363. 'USER' => $_user,
  364. 'DOMAIN' => $_DOMAIN,
  365. 'STAT_USER' => $_new['STAT_USER']
  366. ));
  367. if (!$result['status'])
  368. {
  369. $this->status = FALSE;
  370. $this->errors['DEL_STAT_AUTH'] = array(
  371. $result['error_code'] => $result['error_message']
  372. );
  373. }
  374. }
  375. }
  376. if ($_old['SSL'] != $_new['SSL'])
  377. {
  378. if ($_new['SSL'] == true)
  379. {
  380. // TODO: write it
  381. }
  382. if ($_new['SSL'] == false)
  383. {
  384. // TODO: write it
  385. }
  386. }
  387. else
  388. {
  389. if ($_old['SSL_CERT'] != $_new['SSL_CERT'])
  390. {
  391. $result = array();
  392. $_SSL_CERT = $_new['SSL_CERT'];
  393. // or read uploaded tmp file
  394. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_CERT, array(
  395. 'USER' => $_user,
  396. 'DOMAIN' => $_DOMAIN,
  397. 'SSL_CERT' => $_SSL_CERT
  398. ));
  399. if (!$result['status'])
  400. {
  401. $this->status = FALSE;
  402. $this->errors['SSL_CERT'] = array(
  403. $result['error_code'] => $result['error_message']
  404. );
  405. }
  406. }
  407. if ($_old['SSL_HOME'] != $_new['SSL_HOME'])
  408. {
  409. $result = array();
  410. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_SSLHOME, array(
  411. 'USER' => $_user,
  412. 'DOMAIN' => $_DOMAIN,
  413. 'SSL_HOME' => $_new['SSL_HOME']
  414. ));
  415. if (!$result['status'])
  416. {
  417. $this->status = FALSE;
  418. $this->errors['SSL_HOME'] = array(
  419. $result['error_code'] => $result['error_message']
  420. );
  421. }
  422. }
  423. }
  424. if ($_old['CGI'] != $_new['CGI'])
  425. {
  426. if ($_new['CGI'] == true)
  427. {
  428. $result = array();
  429. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_CGI, array(
  430. 'USER' => $_user,
  431. 'DOMAIN' => $_DOMAIN
  432. ));
  433. if (!$result['status'])
  434. {
  435. $this->status = FALSE;
  436. $this->errors['ADD_CGI'] = array(
  437. $result['error_code'] => $result['error_message']
  438. );
  439. }
  440. }
  441. if ($_new['CGI'] == false)
  442. {
  443. $result = array();
  444. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_CGI, array(
  445. 'USER' => $_user,
  446. 'DOMAIN' => $_DOMAIN
  447. ));
  448. if (!$result['status'])
  449. {
  450. $this->status = FALSE;
  451. $this->errors['DEL_CGI'] = array(
  452. $result['error_code'] => $result['error_message']
  453. );
  454. }
  455. }
  456. }
  457. if ($_old['ELOG'] != $_new['ELOG'])
  458. {
  459. if ($_new['ELOG'] == true)
  460. {
  461. $result = array();
  462. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ELOG, array(
  463. 'USER' => $_user,
  464. 'DOMAIN' => $_DOMAIN
  465. ));
  466. if (!$result['status'])
  467. {
  468. $this->status = FALSE;
  469. $this->errors['ADD_ELOG'] = array(
  470. $result['error_code'] => $result['error_message']
  471. );
  472. }
  473. }
  474. if ($_new['ELOG'] == false)
  475. {
  476. $result = array();
  477. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ELOG, array(
  478. 'USER' => $_user,
  479. 'DOMAIN' => $_DOMAIN
  480. ));
  481. if (!$result['status'])
  482. {
  483. $this->status = FALSE;
  484. $this->errors['DEL_ELOG'] = array(
  485. $result['error_code'] => $result['error_message']
  486. );
  487. }
  488. }
  489. }
  490. return $this->reply($result['status'], $result['data']);
  491. }
  492. /**
  493. * Suspend entry
  494. *
  495. * @param Request $request
  496. * @return
  497. */
  498. public function suspendExecute($request)
  499. {
  500. $r = new Request();
  501. $_s = $r->getSpell();
  502. $_user = 'vesta';
  503. $params = array(
  504. 'USER' => $_user,
  505. 'DOMAIN' => $_s['DOMAIN']
  506. );
  507. $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, $params);
  508. if (!$result['status'])
  509. {
  510. $this->errors[] = array(
  511. $result['error_code'] => $result['error_message']
  512. );
  513. }
  514. return $this->reply($result['status'], $result['data']);
  515. }
  516. /**
  517. * Unsuspend entry
  518. *
  519. * @param Request $request
  520. * @return
  521. */
  522. public function unsuspendExecute($request)
  523. {
  524. $r = new Request();
  525. $_s = $r->getSpell();
  526. $_user = 'vesta';
  527. $params = array(
  528. 'USER' => $_user,
  529. 'DOMAIN' => $_s['DOMAIN']
  530. );
  531. $result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, $params);
  532. if (!$result['status'])
  533. {
  534. $this->errors[] = array(
  535. $result['error_code'] => $result['error_message']
  536. );
  537. }
  538. return $this->reply($result['status'], $result['data']);
  539. }
  540. /**
  541. * Batch suspend entries
  542. *
  543. * @param Request $request
  544. * @return
  545. */
  546. public function suspendAllExecute($request)
  547. {
  548. $r = new Request();
  549. $_s = $r->getSpell();
  550. $_user = 'vesta';
  551. $params = array(
  552. 'USER' => $_user
  553. );
  554. $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAINS, $params);
  555. if (!$result['status'])
  556. {
  557. $this->errors[] = array(
  558. $result['error_code'] => $result['error_message']
  559. );
  560. }
  561. return $this->reply($result['status'], $result['data']);
  562. }
  563. /**
  564. * Batch unsuspend entry
  565. *
  566. * @param Request $request
  567. * @return
  568. */
  569. public function unsuspendAllExecute($request)
  570. {
  571. $r = new Request();
  572. $_s = $r->getSpell();
  573. $_user = 'vesta';
  574. $params = array(
  575. 'USER' => $_user
  576. );
  577. $result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAINS, $params);
  578. if (!$result['status'])
  579. {
  580. $this->errors[] = array(
  581. $result['error_code'] => $result['error_message']
  582. );
  583. }
  584. return $this->reply($result['status'], $result['data']);
  585. }
  586. }