MAIN.class.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. $reply = array(
  62. 'WEB_DOMAIN' => $this->getWebDomainParams($data_web_domain),
  63. 'CRON' => $this->getCronParams(),
  64. 'IP' => $this->getIpParams($data_ip),
  65. 'DNS' => $this->getDnsParams(),
  66. 'DB' => $this->getDbParams($data_db),
  67. 'USERS' => $this->getUsersParams($data_users),
  68. 'totals' => $this->getTotals()
  69. );
  70. return $this->reply(true, $reply);
  71. }
  72. //
  73. //
  74. //
  75. public function getTotals($data = array())
  76. {
  77. return array(
  78. 'USER' => array('total' => 7, 'blocked' => 0),
  79. 'WEB_DOMAIN' => array('total' => 4, 'blocked' => 0),
  80. 'MAIL' => array('total' => 0),
  81. 'DB' => array('total' => 4, 'blocked' => 0),
  82. 'DNS' => array('total' => 4, 'blocked' => 0),
  83. 'IP' => array('total' => 2, 'blocked' => 0),
  84. 'CRON' => array('total' => 5, 'blocked' => 0)
  85. );
  86. }
  87. /**
  88. * WEB DOMAIN initial params
  89. *
  90. * @params array $data
  91. * @return array
  92. */
  93. public function getWebDomainParams($data = array())
  94. {
  95. return array(
  96. 'TPL' => array('default' => 'default'),
  97. 'ALIAS' => array(),
  98. 'STAT' => array(
  99. 'webalizer' => 'webalizer',
  100. 'awstats' => 'awstats'
  101. ),
  102. 'IP' => $data['ips']
  103. );
  104. }
  105. /**
  106. * CRON initial params
  107. *
  108. * @params array $data
  109. * @return array
  110. */
  111. public function getCronParams($data = array())
  112. {
  113. return array();
  114. }
  115. /**
  116. * IP initial params
  117. *
  118. * @params array $data
  119. * @return array
  120. */
  121. public function getIpParams($data = array())
  122. {
  123. $users = array();
  124. foreach ((array)$data['user_names'] as $user) {
  125. $users[$user] = $user;
  126. }
  127. return array(
  128. 'SYS_USERS' => $users,
  129. 'STATUSES' => array(
  130. 'shared' => 'shared',
  131. 'exclusive' => 'exclusive'
  132. ),
  133. 'INTERFACES' => $data['interfaces'],
  134. 'MASK' => array(
  135. '255.255.255.0' => '255.255.255.0',
  136. '255.255.255.128' => '255.255.255.128',
  137. '255.255.255.192' => '255.255.255.192',
  138. '255.255.255.224' => '255.255.255.224',
  139. '255.255.255.240' => '255.255.255.240',
  140. '255.255.255.248' => '255.255.255.248',
  141. '255.255.255.252' => '255.255.255.252',
  142. '255.255.255.255' => '255.255.255.255'
  143. ),
  144. 'OWNER' => array('Chuck Norris' => 'Chuck Norris')
  145. );
  146. }
  147. /**
  148. * DNS initial params
  149. *
  150. * @params array $data
  151. * @return array
  152. */
  153. public function getDnsParams($data = array())
  154. {
  155. return array(
  156. 'IP' => @$data['ips'],
  157. 'TPL' => array('default' => 'default'),
  158. 'EXP' => array(),
  159. 'SOA' => array(),
  160. 'TTL' => array(),
  161. 'record' => array(
  162. 'RECORD' => array(),
  163. 'RECORD_TYPE' => array('A' => 'A', 'NS' => 'NS', 'MX' => 'MX', 'TXT' => 'TXT'),
  164. 'RECORD_VALUE' => array()
  165. )
  166. );
  167. }
  168. /**
  169. * DB initial params
  170. *
  171. * @params array $data
  172. * @return array
  173. */
  174. public function getDbParams($data = array())
  175. {
  176. $db_types = $this->getDBTypes();
  177. return array(
  178. 'TYPE' => $db_types,
  179. 'HOST' => array('vestacp.com' => 'vestacp.com', 'askcow.org' => 'askcow.org')
  180. );
  181. }
  182. public function getDBTypes()
  183. {
  184. return array('mysql' => 'mysql', 'postgre' => 'postgre');
  185. }
  186. /**
  187. * Users initial params
  188. *
  189. * @params array $data
  190. * @return array
  191. */
  192. public function getUsersParams($data = array())
  193. {
  194. return array(
  195. 'ROLE' => array('user' => 'user'),
  196. 'OWNER' => $data['user_names'],
  197. 'PACKAGE' => array('default' => 'default'),
  198. 'NS1' => array('' => ''),
  199. 'NS2' => array('' => ''),
  200. 'SHELL' => array(
  201. '/bin/sh' => '/bin/sh',
  202. '/bin/bash' => '/bin/bash',
  203. '/sbin/nologin' => '/sbin/nologin',
  204. '/bin/tcsh' => '/bin/tcsh',
  205. '/bin/csh' => '/bin/csh')
  206. );
  207. }
  208. }