MAIN.class.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. /**
  3. * Main entity class
  4. * Provides usefull methods (utils), shared for sub entities (DNS, IP etc)
  5. * Subentities should be extended from MAIN class
  6. *
  7. * Details:
  8. * - methods, used for ajax executions must be postfixed with execute keyword
  9. * Eg.: getDnsInformationExecute()
  10. *
  11. * @author vesta, http://vestacp.com/
  12. * @author Dmitry Malishev <dima.malishev@gmail.com>
  13. * @author Dmitry Naumov-Socolov <naumov.socolov@gmail.com>
  14. * @copyright vesta 2010-2011
  15. */
  16. class MAIN extends AjaxHandler
  17. {
  18. /**
  19. * Get Version
  20. *
  21. * @param Request $request
  22. * @return string - Ajax Reply
  23. */
  24. public function versionExecute(Request $request)
  25. {
  26. $result = array(
  27. 'version' => '1.0',
  28. 'author' => 'http://vestacp.com/',
  29. 'docs' => 'http://vestacp.com/docs'
  30. );
  31. return $this->reply(true, $result);
  32. }
  33. /**
  34. * Get Initial params.
  35. * Global constants / variables / configs
  36. *
  37. * @param Request $request
  38. * @return string - Ajax Reply
  39. */
  40. public function getInitialExecute(Request $request)
  41. {
  42. /*require_once V_ROOT_DIR . 'api/IP.class.php';
  43. require_once V_ROOT_DIR . 'api/USER.class.php';
  44. // IP
  45. $ip_obj = new IP();
  46. $user_ips = json_decode($ip_obj->getListUserIpsExecute($request), TRUE);
  47. foreach ($user_ips['data'] as $ip) {
  48. $ips[$ip['IP_ADDRESS']] = $ip['IP_ADDRESS'];
  49. }
  50. // USER
  51. $user_obj = new USER();
  52. $users = json_decode($user_obj->getListExecute($request), TRUE);
  53. $user_names = array_keys($users['data']);
  54. $interfaces_arr = json_decode($ip_obj->getSysInterfacesExecute($request), TRUE);
  55. $interfaces = $interfaces_arr['data'];
  56. $data_web_domain = array('ips' => $ips);
  57. $data_ip = array('user_names' => $user_names, 'interfaces' => $interfaces);
  58. $data_dns = array('ips' => $ips);
  59. $data_db = array('db_types' => $this->getDBTypes());
  60. $data_users = array('user_names' => $user_names);*/
  61. $user = VestaSession::getInstance()->getUser();
  62. $global_data = array();
  63. $totals = array(
  64. 'USER' => array('total' => 0, 'blocked' => 0),
  65. 'WEB_DOMAIN' => array('total' => 0, 'blocked' => 0),
  66. 'MAIL' => array('total' => 0),
  67. 'DB' => array('total' => 0, 'blocked' => 0),
  68. 'DNS' => array('total' => 0, 'blocked' => 0),
  69. 'IP' => array('total' => 0, 'blocked' => 0),
  70. 'CRON' => array('total' => 0, 'blocked' => 0)
  71. );
  72. // users
  73. $rs = Vesta::execute(Vesta::V_LIST_SYS_USERS, null, self::JSON);
  74. $data_user = $rs['data'];
  75. $global_data['users'] = array();
  76. foreach ($data_user as $login_name => $usr) {
  77. $totals['USER']['total'] += 1;
  78. if ($usr['SUSPENDED'] != 'yes') {
  79. $global_data['users'][$login_name] = $login_name;
  80. }
  81. else {
  82. $totals['USER']['blocked'] += 1;
  83. }
  84. }
  85. // web_domains
  86. $rs = Vesta::execute(Vesta::V_LIST_WEB_DOMAINS, array('USER' => $user['uid']), self::JSON);
  87. $data_web_domain = $rs['data'];
  88. foreach ($data_web_domain as $web) {
  89. $totals['WEB_DOMAIN']['total'] += 1;
  90. }
  91. // db
  92. $rs = Vesta::execute(Vesta::V_LIST_DB_BASES, array('USER' => $user['uid']), self::JSON);
  93. $data_db = $rs['data'];
  94. foreach ($data_db as $db) {
  95. $totals['DB']['total'] += 1;
  96. //$db['SUSPENDED'] == 'yes' ? $totals['DB']['blocked'] += 1 : false;
  97. }
  98. // dns
  99. $rs = Vesta::execute(Vesta::V_LIST_DNS_DOMAINS, array('USER' => $user['uid']), self::JSON);
  100. $data_dns = $rs['data'];
  101. foreach ($data_dns as $dns) {
  102. $totals['DNS']['total'] += 1;
  103. }
  104. // ip
  105. $global_data['ips'] = array();
  106. $rs = Vesta::execute(Vesta::V_LIST_SYS_IPS, null, self::JSON);
  107. $data_ip = $rs['data'];
  108. foreach ($data_ip as $ip => $obj) {
  109. $totals['IP']['total'] += 1;
  110. $global_data['ips'][$ip] = $ip;
  111. }
  112. // cron
  113. $rs = Vesta::execute(Vesta::V_LIST_CRON_JOBS, array('USER' => $user['uid']), self::JSON);
  114. $data_cron = $rs['data'];
  115. foreach ($data_cron as $cron) {
  116. $totals['CRON']['total'] += 1;
  117. $cron['SUSPEND'] == 'yes' ? $totals['CRON']['blocked'] += 1 : false;
  118. }
  119. $reply = array(
  120. 'WEB_DOMAIN' => $this->getWebDomainParams($data_web_domin, $global_data),
  121. 'CRON' => $this->getCronParams(),
  122. 'IP' => $this->getIpParams($data_ip, $global_data),
  123. 'DNS' => $this->getDnsParams(),
  124. 'DB' => $this->getDbParams($data_db),
  125. 'USERS' => $this->getUsersParams($data_user),
  126. 'totals' => $totals
  127. );
  128. return $this->reply(true, $reply);
  129. }
  130. /**
  131. * WEB DOMAIN initial params
  132. *
  133. * @params array $data
  134. * @return array
  135. */
  136. public function getWebDomainParams($data, $global_data)
  137. {
  138. $user = $this->getLoggedUser();
  139. $ips = array();
  140. //v_list_sys_user_ips vesta
  141. $result = Vesta::execute(Vesta::V_LIST_SYS_USER_IPS, array('USER' => $user['uid']), self::JSON);
  142. foreach ($result['data'] as $sys_ip => $ip_data) {
  143. $ips[$sys_ip] = $sys_ip;
  144. }
  145. return array(
  146. 'TPL' => array('default' => 'default'),
  147. 'ALIAS' => array(),
  148. 'STAT' => array(
  149. 'webalizer' => 'webalizer',
  150. 'awstats' => 'awstats'
  151. ),
  152. 'IP' => $ips
  153. );
  154. }
  155. /**
  156. * CRON initial params
  157. *
  158. * @params array $data
  159. * @return array
  160. */
  161. public function getCronParams($data = array())
  162. {
  163. return array();
  164. }
  165. /**
  166. * IP initial params
  167. *
  168. * @params array $data
  169. * @return array
  170. */
  171. public function getIpParams($data = array(), $global_data = array())
  172. {
  173. $ifaces = array();
  174. $result = Vesta::execute(Vesta::V_LIST_SYS_INTERFACES, array(Config::get('response_type')));
  175. foreach ($result['data'] as $iface) {
  176. $ifaces[$iface] = $iface;
  177. }
  178. return array(
  179. 'SYS_USERS' => $users,
  180. 'STATUSES' => array(
  181. 'shared' => 'shared',
  182. 'exclusive' => 'exclusive'
  183. ),
  184. 'INTERFACES' => $ifaces,
  185. 'OWNER' => $global_data['users'],
  186. 'MASK' => array(
  187. '255.255.255.0' => '255.255.255.0',
  188. '255.255.255.128' => '255.255.255.128',
  189. '255.255.255.192' => '255.255.255.192',
  190. '255.255.255.224' => '255.255.255.224',
  191. '255.255.255.240' => '255.255.255.240',
  192. '255.255.255.248' => '255.255.255.248',
  193. '255.255.255.252' => '255.255.255.252',
  194. '255.255.255.255' => '255.255.255.255'
  195. )
  196. );
  197. }
  198. /**
  199. * DNS initial params
  200. *
  201. * @params array $data
  202. * @return array
  203. */
  204. public function getDnsParams($data = array())
  205. {
  206. return array(
  207. 'IP' => @$data['ips'],
  208. 'TPL' => array('default' => 'default'),
  209. 'EXP' => array(),
  210. 'SOA' => array(),
  211. 'TTL' => array(),
  212. 'record' => array(
  213. 'RECORD' => array(),
  214. 'RECORD_TYPE' => array('A' => 'A', 'NS' => 'NS', 'MX' => 'MX', 'TXT' => 'TXT'),
  215. 'RECORD_VALUE' => array()
  216. )
  217. );
  218. }
  219. /**
  220. * DB initial params
  221. *
  222. * @params array $data
  223. * @return array
  224. */
  225. public function getDbParams($data = array())
  226. {
  227. $db_types = $this->getDBTypes();
  228. return array(
  229. 'TYPE' => $db_types,
  230. 'HOST' => array('vestacp.com' => 'vestacp.com', 'askcow.org' => 'askcow.org')
  231. );
  232. }
  233. public function getDBTypes()
  234. {
  235. return array('mysql' => 'mysql', 'postgre' => 'postgre');
  236. }
  237. /**
  238. * Users initial params
  239. *
  240. * @params array $data
  241. * @return array
  242. */
  243. public function getUsersParams($data = array())
  244. {
  245. return array(
  246. 'ROLE' => array('user' => 'user'),
  247. 'OWNER' => $data['user_names'],
  248. 'PACKAGE' => array('default' => 'default'),
  249. 'SHELL' => array(
  250. 'sh' => 'sh',
  251. 'bash' => 'bash',
  252. 'nologin' => 'nologin',
  253. 'tcsh' => 'tcsh',
  254. 'csh' => 'csh')
  255. );
  256. }
  257. }