IP.class.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * IP
  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 IP extends AjaxHandler
  11. {
  12. /**
  13. * Get IP entries
  14. *
  15. * @param Request $request
  16. * @return string - Ajax Reply
  17. */
  18. public function getListExecute(Request $request)
  19. {
  20. $reply = array();
  21. $result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
  22. foreach ($result['data'] as $ip => $details) {
  23. $reply[] = array_merge(
  24. array(
  25. 'IP_ADDRESS' => $ip,
  26. 'DATE' => date(Config::get('ui_date_format', strtotime($details['DATE'])))
  27. ), $details);
  28. }
  29. if (!$result['status']) {
  30. $this->errors[] = array($result['error_code'] => $result['error_message']);
  31. }
  32. return $this->reply($result['status'], $reply);
  33. }
  34. /**
  35. * Get user's IPs
  36. *
  37. * @param Request $request
  38. * @return string - Ajax Reply
  39. */
  40. public function getListUserIpsExecute(Request $request)
  41. {
  42. $reply = array();
  43. $result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
  44. foreach ($result['data'] as $ip => $details) {
  45. $reply[] = array_merge(
  46. array(
  47. 'IP_ADDRESS' => $ip,
  48. 'DATE' => date(Config::get('ui_date_format', strtotime($details['DATE'])))
  49. ), $details);
  50. }
  51. if (!$result['status']) {
  52. $this->errors[] = array($result['error_code'] => $result['error_message']);
  53. }
  54. return $this->reply($result['status'], $reply);
  55. }
  56. /**
  57. * Add IP entry
  58. *
  59. * @param Request $request
  60. * @return string - Ajax Reply
  61. */
  62. public function addExecute(Request $request)
  63. {
  64. $user = $this->getLoggedUser();
  65. $spell = $request->getParameter('spell');
  66. $params = array(
  67. 'IP_ADDRESS' => $spell['IP_ADDRESS'],
  68. 'MASK' => $spell['NETMASK'],
  69. 'INTERFACE' => $spell['INTERFACE'],
  70. 'OWNER' => $spell['OWNER'],
  71. 'IP_STATUS' => $spell['STATUS']
  72. );
  73. $result = Vesta::execute(Vesta::V_ADD_SYS_IP, $params);
  74. if (!$result['status']) {
  75. $this->errors[] = array($result['error_code'] => $result['error_message']);
  76. }
  77. return $this->reply($result['status'], $result['data']);
  78. }
  79. /**
  80. * Delete IP entry
  81. *
  82. * @param Request $request
  83. * @return string - Ajax Reply
  84. */
  85. public function deleteExecute(Request $request)
  86. {
  87. $spell = $request->getParameter('spell');
  88. $user = $this->getLoggedUser();
  89. $params = array(
  90. 'IP_ADDRESS' => $spell['IP_ADDRESS']
  91. );
  92. $result = Vesta::execute(Vesta::V_DEL_SYS_IP, $params);
  93. if (!$result['status']) {
  94. $this->errors[] = array($result['error_code'] => $result['error_message']);
  95. }
  96. return $this->reply($result['status'], $result['data']);
  97. }
  98. /**
  99. * Change IP entry
  100. *
  101. * @param Request $request
  102. * @return string - Ajax Reply
  103. */
  104. public function changeExecute(Request $request)
  105. {
  106. $user = $this->getLoggedUser();
  107. $_old = $request->getParameter('old');
  108. $_new = $request->getParameter('new');
  109. $this->status = TRUE;
  110. $this->errors = array();
  111. if ($_old['OWNER'] != $_new['OWNER']) {
  112. $result = array();
  113. $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_OWNER, array('OWNER' => $_new['OWNER'], 'IP' => $_new['IP_ADDRESS']));
  114. if (!$result['status']) {
  115. $this->status = FALSE;
  116. $this->errors['OWNER'] = array($result['error_code'] => $result['error_message']);
  117. }
  118. }
  119. // TODO: Handle NAME parameter
  120. /*if ($_old['NAME'] != $_new['NAME']) {
  121. $result = array();
  122. $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_NAME, array('IP' => $_new['IP_ADDRESS'], 'NAME' => $_new['NAME']));
  123. if (!$result['status']) {
  124. $this->status = FALSE;
  125. $this->errors['NAME'] = array($result['error_code'] => $result['error_message']);
  126. }
  127. }*/
  128. if ($_old['IP_STATUS'] != $_new['IP_STATUS']) {
  129. $result = array();
  130. $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_STATUS, array('IP' => $_new['IP_ADDRESS'], 'IP_STATUS' => $_new['IP_STATUS']));
  131. if (!$result['status']) {
  132. $this->status = FALSE;
  133. $this->errors['IP_STATUS'] = array($result['error_code'] => $result['error_message']);
  134. }
  135. }
  136. if (!$result['status']) {
  137. $this->errors[] = array($result['error_code'] => $result['error_message']);
  138. }
  139. return $this->reply($this->status, $this->errors);
  140. }
  141. /**
  142. * Get Sys interfaces
  143. *
  144. * @param Request $request
  145. * @return string - Ajax Reply
  146. */
  147. public function getSysInterfacesExecute(Request $request)
  148. {
  149. $reply = array();
  150. $result = Vesta::execute(Vesta::V_LIST_SYS_INTERFACES, array(Config::get('response_type')));
  151. foreach ($result['data'] as $iface) {
  152. $reply[$iface] = $iface;
  153. }
  154. if (!$result['status']) {
  155. $this->errors[] = array($result['error_code'] => $result['error_message']);
  156. }
  157. return $this->reply($result['status'], $reply);
  158. }
  159. }