WEB_DOMAIN.class.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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' => @str_replace(",", ", ", $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. 'SSL_KEY' => $record['SSL_KEY'],
  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. $web_details['STAT'] == '' ? $web_details['STAT'] = 'none' : true;
  45. $reply[$web_domain] = $web_details;
  46. }
  47. if (!$result['status']) {
  48. $this->errors[] = array($result['error_code'] => $result['error_message']);
  49. }
  50. return $this->reply($result['status'], $reply);
  51. }
  52. public function addExecute(Request $request)
  53. {
  54. $_s = $request->getParameter('spell');
  55. $user = $this->getLoggedUser();
  56. $params = array(
  57. 'USER' => $user['uid'],
  58. 'DOMAIN' => $_s['DOMAIN'],
  59. 'IP' => $_s['IP']
  60. );
  61. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN, $params);
  62. if (!$result['status']) {
  63. $this->errors[] = array($result['error_code'] => $result['error_message']);
  64. }
  65. if (!empty($_s['TPL'])) {
  66. $params = array(
  67. 'USER' => $user['uid'],
  68. 'DOMAIN' => $_s['DOMAIN'],
  69. 'TPL' => $_s['TPL']
  70. );
  71. $result = 0;
  72. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_TPL, $params);
  73. if (!$result['status']) {
  74. $this->errors['CHANGE_TPL'] = array($result['error_code'] => $result['error_message']);
  75. }
  76. }
  77. if (!empty($_s['ALIAS'])) {
  78. $alias = str_replace("\n", "", $_s['ALIAS']);
  79. $alias = str_replace("\n", "", $alias);
  80. foreach ($alias_arr as $alias) {
  81. $params = array(
  82. 'USER' => $user['uid'],
  83. 'DOMAIN' => $_s['DOMAIN'],
  84. 'ALIAS' => trim($alias)
  85. );
  86. $result = 0;
  87. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ALIAS, $params);
  88. if (!$result['status']) {
  89. $this->errors['ALIAS'] = array($result['error_code'] => $result['error_message']);
  90. }
  91. }
  92. }
  93. if (!empty($_s['STATS']) && @$_s['STATS'] != 'none') {
  94. $params = array(
  95. 'USER' => $user['uid'],
  96. 'DOMAIN' => $_s['DOMAIN'],
  97. 'STAT' => $_s['STAT']);
  98. $result = 0;
  99. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT, $params);
  100. if (!$result['status']) {
  101. $this->errors['STATS'] = array($result['error_code'] => $result['error_message']);
  102. }
  103. }
  104. if (!empty($_s['STAT_AUTH']) && @Utils::getCheckboxBooleanValue($_s['STATS_AUTH'])) {
  105. $params = array(
  106. 'USER' => $user['uid'],
  107. 'DOMAIN' => $_s['DOMAIN'],
  108. 'STAT_USER' => $_s['STAT_USER'],
  109. 'STAT_PASSWORS' => $_s['STAT_PASSWORD']
  110. );
  111. $result = 0;
  112. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT_AUTH, $params);
  113. if(!$result['status'])
  114. $this->errors['STAT_AUTH'] = array($result['error_code'] => $result['error_message']);
  115. }
  116. if (!empty($_new['CGI'])) {
  117. if (Utils::getCheckboxBooleanValue($_new['CGI'])) {
  118. $result = array();
  119. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_CGI, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  120. if (!$result['status']) {
  121. $this->status = FALSE;
  122. $this->errors['ADD_CGI'] = array($result['error_code'] => $result['error_message']);
  123. }
  124. }
  125. }
  126. if (!empty($_new['ELOG'])) {
  127. if (Utils::getCheckboxBooleanValue($_new['ELOG'])) {
  128. $result = array();
  129. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ELOG, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  130. if (!$result['status']) {
  131. $this->status = FALSE;
  132. $this->errors['ADD_ELOG'] = array($result['error_code'] => $result['error_message']);
  133. }
  134. }
  135. }
  136. /* if ($_s['SSL']) {
  137. $params = array(
  138. 'USER' => $user['uid'],
  139. 'DOMAIN' => $_s['DOMAIN'],
  140. 'SSL_CERT' => $_s['SSL_CERT']
  141. );
  142. if ($_s['SSL_HOME']) {
  143. $params['SSL_HOME'] = $_s['SSL_HOME'];
  144. }
  145. $result = 0;
  146. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
  147. if (!$result['status']) {
  148. $this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
  149. }
  150. }
  151. if ($_s['SSL_HOME']) {
  152. }*/
  153. /*if (!empty($_s['DNS'])) {
  154. $params = array(
  155. 'USER' => $user['uid'],
  156. 'DNS_DOMAIN' => $_s['DOMAIN'],
  157. 'IP' => $_s['IP']
  158. );
  159. require_once V_ROOT_DIR . 'api/DNS.class.php';
  160. $dns = new DNS();
  161. $result = 0;
  162. $result = $dns->addExecute($params);
  163. if (!$result['status']) {
  164. $this->errors['DNS_DOMAIN'] = array($result['error_code'] => $result['error_message']);
  165. }
  166. }*/
  167. /*if (!empty($_s['MAIL'])) {
  168. $params = array(
  169. 'USER' => $_user,
  170. 'MAIL_DOMAIN' => $_s['DOMAIN'],
  171. 'IP' => $_s['IP']
  172. );
  173. require_once V_ROOT_DIR . 'api/MAIL.class.php';
  174. $mail = new MAIL();
  175. $result = 0;
  176. $result = $mail->addExecute($params);
  177. if (!$result['status'])
  178. $this->errors['MAIL_DOMAIN'] = array($result['error_code'] => $result['error_message']);
  179. }*/
  180. if ($_s['SUSPEND'] == 'on') {
  181. if($result['status']){
  182. $result = array();
  183. $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'JOB' => $_s['DOMAIN']));
  184. if (!$result['status']) {
  185. $this->status = FALSE;
  186. $this->errors['SUSPEND'] = array($result['error_code'] => $result['error_message']);
  187. }
  188. }
  189. }
  190. return $this->reply($result['status'], $result['data']);
  191. }
  192. public function deleteExecute(Request $request)
  193. {
  194. $_s = $request->getParameter('spell');
  195. $user = $this->getLoggedUser();
  196. $params = array(
  197. 'USER' => $user['uid'],
  198. 'DOMAIN' => $_s['DOMAIN']
  199. );
  200. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN, $params);
  201. if (!$result['status']) {
  202. $this->errors[] = array($result['error_code'] => $result['error_message']);
  203. }
  204. $params = array(
  205. 'USER' => $_user,
  206. 'DNS_DOMAIN' => $_s['DOMAIN']
  207. );
  208. return $this->reply($result['status'], $result['data']);
  209. }
  210. public function changeExecute(Request $request)
  211. {
  212. $_s = $request->getParameter('spell');
  213. $_old = $request->getParameter('old');
  214. $_new = $request->getParameter('new');
  215. $_old['ELOG'] = $_old['ELOG'] == 'yes' ? 'on' : 'off';
  216. $_old['CGI'] = $_old['CGI'] == 'yes' ? 'on' : 'off';
  217. $_old['AUTH'] = $_old['AUTH'] == 'yes' ? 'on' : 'off';
  218. $_old['SSL'] = $_old['SSL'] == 'yes' ? 'on' : 'off';
  219. $user = $this->getLoggedUser();
  220. $_DOMAIN = $_new['DOMAIN'];
  221. if ($_new['SUSPEND'] == 'on') {
  222. $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  223. return $this->reply($result['status']);
  224. }
  225. else {
  226. $result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  227. }
  228. if ($_old['IP'] != $_new['IP']) {
  229. $result = array();
  230. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_IP, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'IP' => $_new['IP']));
  231. if (!$result['status']) {
  232. $this->status = FALSE;
  233. $this->errors['IP_ADDRESS'] = array($result['error_code'] => $result['error_message']);
  234. }
  235. }
  236. if ($_old['TPL'] != $_new['TPL']) {
  237. $result = array();
  238. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_TPL, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'TPL' => $_new['TPL']));
  239. if (!$result['status']) {
  240. $this->status = FALSE;
  241. $this->errors['TPL'] = array($result['error_code'] => $result['error_message']);
  242. }
  243. }
  244. if ($_old['ALIAS'] != $_new['ALIAS']) {
  245. $result = array();
  246. $old_arr_raw = preg_split('/[,\s]/', $_old['ALIAS']);
  247. $new_arr_raw = preg_split('/[,\s]/', $_new['ALIAS']);
  248. $old_arr = array();
  249. $new_arr = array();
  250. foreach ($old_arr_raw as $alias) {
  251. if ('' != trim($alias)) {
  252. $old_arr[] = $alias;
  253. }
  254. }
  255. foreach ($new_arr_raw as $alias) {
  256. if ('' != trim($alias)) {
  257. $new_arr[] = $alias;
  258. }
  259. }
  260. $added = array_diff($new_arr, $old_arr);
  261. $deleted = array_diff($old_arr, $new_arr);
  262. foreach ($deleted as $alias) {
  263. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ALIAS, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'ALIAS' => $alias));
  264. if (!$result['status']) {
  265. $this->status = FALSE;
  266. $this->errors['DEL_ALIAS'] = array($result['error_code'] => $result['error_message']);
  267. }
  268. }
  269. foreach ($added as $alias) {
  270. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ALIAS, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'ALIAS' => $alias));
  271. if (!$result['status']) {
  272. $this->status = FALSE;
  273. $this->errors['ADD_ALIAS'] = array($result['error_code'] => $result['error_message']);
  274. }
  275. }
  276. }
  277. if (($_old['STAT_AUTH'] != $_new['STAT_AUTH']) && !empty($_s['STAT_AUTH']) && @Utils::getCheckboxBooleanValue($_s['STATS_AUTH'])) {
  278. $params = array(
  279. 'USER' => $user['uid'],
  280. 'DOMAIN' => $_DOMAIN,
  281. 'STAT_USER' => $_new['STAT_USER'],
  282. 'STAT_PASSWORS' => $_new['STAT_PASSWORD']
  283. );
  284. $result = 0;
  285. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT_AUTH, $params);
  286. if(!$result['status']) {
  287. $this->errors['STAT_AUTH'] = array($result['error_code'] => $result['error_message']);
  288. }
  289. }
  290. if (($_old['STAT'] != $_new['STAT'])) {
  291. if ($_new['STAT'] != 'none') {
  292. $result = array();
  293. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'STAT' => $_new['STAT']));
  294. if (!$result['status']) {
  295. $this->status = FALSE;
  296. $this->errors['ADD_STAT'] = array($result['error_code'] => $result['error_message']);
  297. }
  298. }
  299. else {
  300. $result = array();
  301. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  302. if (!$result['status']) {
  303. $this->status = FALSE;
  304. $this->errors['DEL_STAT'] = array($result['error_code'] => $result['error_message']);
  305. }
  306. $result = array();
  307. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT_AUTH, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'STAT_USER' => $_new['STAT_USER']));
  308. if (!$result['status']) {
  309. $this->status = FALSE;
  310. $this->errors['DEL_STAT_AUTH'] = array($result['error_code'] => $result['error_message']);
  311. }
  312. }
  313. }
  314. if (($_old['CGI'] != $_new['CGI'])) {
  315. if (Utils::getCheckboxBooleanValue($_new['CGI'])) {
  316. $result = array();
  317. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_CGI, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  318. if (!$result['status']) {
  319. $this->status = FALSE;
  320. $this->errors['ADD_CGI'] = array($result['error_code'] => $result['error_message']);
  321. }
  322. }
  323. else {
  324. $result = array();
  325. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_CGI, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  326. if (!$result['status']) {
  327. $this->status = FALSE;
  328. $this->errors['DEL_CGI'] = array($result['error_code'] => $result['error_message']);
  329. }
  330. }
  331. }
  332. if (($_old['ELOG'] != $_new['ELOG'])) {
  333. if (Utils::getCheckboxBooleanValue($_new['ELOG'])) {
  334. $result = array();
  335. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ELOG, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  336. if (!$result['status']) {
  337. $this->status = FALSE;
  338. $this->errors['ADD_ELOG'] = array($result['error_code'] => $result['error_message']);
  339. }
  340. }
  341. else {
  342. $result = array();
  343. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ELOG, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  344. if (!$result['status']) {
  345. $this->status = FALSE;
  346. $this->errors['DEL_ELOG'] = array($result['error_code'] => $result['error_message']);
  347. }
  348. }
  349. }
  350. if ($_new['SSL']) {
  351. $params = array(
  352. 'USER' => $user['uid'],
  353. 'DOMAIN' => $_new['DOMAIN'],
  354. 'SSL_CERT' => $_new['SSL_CERT']
  355. );
  356. if ($_new['SSL_HOME']) {
  357. $params['SSL_HOME'] = $_new['SSL_HOME'];
  358. }
  359. $result = 0;
  360. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
  361. if (!$result['status']) {
  362. $this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
  363. }
  364. }
  365. if ($_s['SSL_KEY']) {
  366. $params = array(
  367. 'USER' => $user['uid'],
  368. 'DOMAIN' => $_s['DOMAIN'],
  369. 'SSL_KEY' => $_s['SSL_KEY']
  370. );
  371. if ($_s['SSL_HOME']) {
  372. $params['SSL_HOME'] = $_s['SSL_HOME'];
  373. }
  374. $result = 0;
  375. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
  376. if (!$result['status']) {
  377. $this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
  378. }
  379. }
  380. return $this->reply($result['status'], $result['data']);
  381. }
  382. public function suspendExecute(Request $request)
  383. {
  384. $_s = $request->getParameter('spell');
  385. $user = $this->getLoggedUser();
  386. $params = array(
  387. 'USER' => $user['uid'],
  388. 'DOMAIN' => $_s['DOMAIN']
  389. );
  390. $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, $params);
  391. if (!$result['status']) {
  392. $this->errors[] = array($result['error_code'] => $result['error_message']);
  393. }
  394. return $this->reply($result['status'], $result['data']);
  395. }
  396. public function unsuspendExecute(Request $request)
  397. {
  398. $_s = $request->getParameter('spell');
  399. $user = $this->getLoggedUser();
  400. $params = array(
  401. 'USER' => $user['uid'],
  402. 'DOMAIN' => $_s['DOMAIN']
  403. );
  404. $result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, $params);
  405. if (!$result['status']) {
  406. $this->errors[] = array($result['error_code'] => $result['error_message']);
  407. }
  408. return $this->reply($result['status'], $result['data']);
  409. }
  410. }