WEB_DOMAIN.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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(Vesta::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' => (int)$record['U_DISK'],
  27. 'U_BANDWIDTH' => (int)$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. if (!$result['status']) {
  224. $this->status = FALSE;
  225. $this->errors['SUSPEND'] = array($result['error_code'] => $result['error_message']);
  226. }
  227. // return $this->reply($result['status']);
  228. }
  229. else {
  230. $result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  231. if (!$result['status']) {
  232. $this->status = FALSE;
  233. $this->errors['UNSUSPEND'] = array($result['error_code'] => $result['error_message']);
  234. }
  235. }
  236. if ($_old['IP'] != $_new['IP']) {
  237. $result = array();
  238. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_IP, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'IP' => $_new['IP']));
  239. if (!$result['status']) {
  240. $this->status = FALSE;
  241. $this->errors['IP_ADDRESS'] = array($result['error_code'] => $result['error_message']);
  242. }
  243. }
  244. if ($_old['TPL'] != $_new['TPL']) {
  245. $result = array();
  246. $result = Vesta::execute(Vesta::V_CHANGE_WEB_DOMAIN_TPL, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'TPL' => $_new['TPL']));
  247. if (!$result['status']) {
  248. $this->status = FALSE;
  249. $this->errors['TPL'] = array($result['error_code'] => $result['error_message']);
  250. }
  251. }
  252. if ($_old['ALIAS'] != $_new['ALIAS']) {
  253. $result = array();
  254. $old_arr_raw = preg_split('/[,\s]/', $_old['ALIAS']);
  255. $new_arr_raw = preg_split('/[,\s]/', $_new['ALIAS']);
  256. $old_arr = array();
  257. $new_arr = array();
  258. foreach ($old_arr_raw as $alias) {
  259. if ('' != trim($alias)) {
  260. $old_arr[] = $alias;
  261. }
  262. }
  263. foreach ($new_arr_raw as $alias) {
  264. if ('' != trim($alias)) {
  265. $new_arr[] = $alias;
  266. }
  267. }
  268. $added = array_diff($new_arr, $old_arr);
  269. $deleted = array_diff($old_arr, $new_arr);
  270. foreach ($deleted as $alias) {
  271. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ALIAS, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'ALIAS' => $alias));
  272. if (!$result['status']) {
  273. $this->status = FALSE;
  274. $this->errors['DEL_ALIAS'] = array($result['error_code'] => $result['error_message']);
  275. }
  276. }
  277. foreach ($added as $alias) {
  278. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ALIAS, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'ALIAS' => $alias));
  279. if (!$result['status']) {
  280. $this->status = FALSE;
  281. $this->errors['ADD_ALIAS'] = array($result['error_code'] => $result['error_message']);
  282. }
  283. }
  284. }
  285. if (($_old['STAT_AUTH'] != $_new['STAT_AUTH']) && !empty($_s['STAT_AUTH']) && @Utils::getCheckboxBooleanValue($_s['STATS_AUTH'])) {
  286. $params = array(
  287. 'USER' => $user['uid'],
  288. 'DOMAIN' => $_DOMAIN,
  289. 'STAT_USER' => $_new['STAT_USER'],
  290. 'STAT_PASSWORS' => $_new['STAT_PASSWORD']
  291. );
  292. $result = 0;
  293. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT_AUTH, $params);
  294. if(!$result['status']) {
  295. $this->errors['STAT_AUTH'] = array($result['error_code'] => $result['error_message']);
  296. }
  297. }
  298. if (($_old['STAT'] != $_new['STAT'])) {
  299. if ($_new['STAT'] != 'none') {
  300. $result = array();
  301. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_STAT, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'STAT' => $_new['STAT']));
  302. if (!$result['status']) {
  303. $this->status = FALSE;
  304. $this->errors['ADD_STAT'] = array($result['error_code'] => $result['error_message']);
  305. }
  306. }
  307. else {
  308. $result = array();
  309. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  310. if (!$result['status']) {
  311. $this->status = FALSE;
  312. $this->errors['DEL_STAT'] = array($result['error_code'] => $result['error_message']);
  313. }
  314. $result = array();
  315. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_STAT_AUTH, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN, 'STAT_USER' => $_new['STAT_USER']));
  316. if (!$result['status']) {
  317. $this->status = FALSE;
  318. $this->errors['DEL_STAT_AUTH'] = array($result['error_code'] => $result['error_message']);
  319. }
  320. }
  321. }
  322. if (($_old['CGI'] != $_new['CGI'])) {
  323. if (Utils::getCheckboxBooleanValue($_new['CGI'])) {
  324. $result = array();
  325. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_CGI, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  326. if (!$result['status']) {
  327. $this->status = FALSE;
  328. $this->errors['ADD_CGI'] = array($result['error_code'] => $result['error_message']);
  329. }
  330. }
  331. else {
  332. $result = array();
  333. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_CGI, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  334. if (!$result['status']) {
  335. $this->status = FALSE;
  336. $this->errors['DEL_CGI'] = array($result['error_code'] => $result['error_message']);
  337. }
  338. }
  339. }
  340. if (($_old['ELOG'] != $_new['ELOG'])) {
  341. if (Utils::getCheckboxBooleanValue($_new['ELOG'])) {
  342. $result = array();
  343. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_ELOG, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  344. if (!$result['status']) {
  345. $this->status = FALSE;
  346. $this->errors['ADD_ELOG'] = array($result['error_code'] => $result['error_message']);
  347. }
  348. }
  349. else {
  350. $result = array();
  351. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN_ELOG, array('USER' => $user['uid'], 'DOMAIN' => $_DOMAIN));
  352. if (!$result['status']) {
  353. $this->status = FALSE;
  354. $this->errors['DEL_ELOG'] = array($result['error_code'] => $result['error_message']);
  355. }
  356. }
  357. }
  358. if ($_new['SSL']) {
  359. $params = array(
  360. 'USER' => $user['uid'],
  361. 'DOMAIN' => $_new['DOMAIN'],
  362. 'SSL_CERT' => $_new['SSL_CERT']
  363. );
  364. if ($_new['SSL_HOME']) {
  365. $params['SSL_HOME'] = $_new['SSL_HOME'];
  366. }
  367. $result = 0;
  368. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
  369. if (!$result['status']) {
  370. $this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
  371. }
  372. }
  373. if ($_s['SSL_KEY']) {
  374. $params = array(
  375. 'USER' => $user['uid'],
  376. 'DOMAIN' => $_s['DOMAIN'],
  377. 'SSL_KEY' => $_s['SSL_KEY']
  378. );
  379. if ($_s['SSL_HOME']) {
  380. $params['SSL_HOME'] = $_s['SSL_HOME'];
  381. }
  382. $result = 0;
  383. $result = Vesta::execute(Vesta::V_ADD_WEB_DOMAIN_SSL, $params);
  384. if (!$result['status']) {
  385. $this->errors['SSL'] = array($result['error_code'] => $result['error_message']);
  386. }
  387. }
  388. return $this->reply($result['status'], $result['data']);
  389. }
  390. public function suspendExecute(Request $request)
  391. {
  392. $_s = $request->getParameter('spell');
  393. $user = $this->getLoggedUser();
  394. $params = array(
  395. 'USER' => $user['uid'],
  396. 'DOMAIN' => $_s['DOMAIN']
  397. );
  398. $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, $params);
  399. if (!$result['status']) {
  400. $this->errors[] = array($result['error_code'] => $result['error_message']);
  401. }
  402. return $this->reply($result['status'], $result['data']);
  403. }
  404. public function unsuspendExecute(Request $request)
  405. {
  406. $_s = $request->getParameter('spell');
  407. $user = $this->getLoggedUser();
  408. $params = array(
  409. 'USER' => $user['uid'],
  410. 'DOMAIN' => $_s['DOMAIN']
  411. );
  412. $result = Vesta::execute(Vesta::V_UNSUSPEND_WEB_DOMAIN, $params);
  413. if (!$result['status']) {
  414. $this->errors[] = array($result['error_code'] => $result['error_message']);
  415. }
  416. return $this->reply($result['status'], $result['data']);
  417. }
  418. public function massiveSuspendExecute(Request $request)
  419. {
  420. $user = $this->getLoggedUser();
  421. $_entities = $request->getParameter('entities');
  422. foreach($_entities as $entity){
  423. $result = Vesta::execute(Vesta::V_SUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], $entity['DOMAIN']));
  424. }
  425. return $this->reply($result['status'], $result['data']);
  426. }
  427. public function massiveUnsuspendExecute(Request $request)
  428. {
  429. $user = $this->getLoggedUser();
  430. $_entities = $request->getParameter('entities');
  431. foreach($_entities as $entity){
  432. $result = Vesta::execute(Vesta::V_UNUSPEND_WEB_DOMAIN, array('USER' => $user['uid'], $entity['DOMAIN']));
  433. }
  434. return $this->reply($result['status'], $result['data']);
  435. }
  436. public function massiveDeleteExecute(Request $request)
  437. {
  438. $user = $this->getLoggedUser();
  439. $_entities = $request->getParameter('entities');
  440. foreach($_entities as $entity){
  441. $result = Vesta::execute(Vesta::V_DEL_WEB_DOMAIN, array('USER' => $user['uid'], $entity['DOMAIN']));
  442. }
  443. return $this->reply($result['status'], $result['data']);
  444. }
  445. }