MAIN.class.php 6.9 KB

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