IP.class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. //'IP_NAME' => $spell['NAME']
  73. );
  74. $result = Vesta::execute(Vesta::V_ADD_SYS_IP, $params);
  75. if (!$result['status']) {
  76. $this->errors[] = array($result['error_code'] => $result['error_message']);
  77. }
  78. return $this->reply($result['status'], $result['data']);
  79. }
  80. /**
  81. * Delete IP entry
  82. *
  83. * @param Request $request
  84. * @return string - Ajax Reply
  85. */
  86. public function deleteExecute(Request $request)
  87. {
  88. $spell = $request->getParameter('spell');
  89. $user = $this->getLoggedUser();
  90. $params = array(
  91. 'IP_ADDRESS' => $spell['IP_ADDRESS']
  92. );
  93. $result = Vesta::execute(Vesta::V_DEL_SYS_IP, $params);
  94. if (!$result['status']) {
  95. $this->errors[] = array($result['error_code'] => $result['error_message']);
  96. }
  97. return $this->reply($result['status'], $result['data']);
  98. }
  99. /**
  100. * Change IP entry
  101. *
  102. * @param Request $request
  103. * @return string - Ajax Reply
  104. */
  105. public function changeExecute(Request $request)
  106. {
  107. $user = $this->getLoggedUser();
  108. $_old = $request->getParameter('old');
  109. $_new = $request->getParameter('new');
  110. if ($_old['OWNER'] != $_new['OWNER']) {
  111. $result = array();
  112. $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_OWNER, array('OWNER' => $_new['OWNER'], 'IP' => $_new['IP_ADDRESS']));
  113. if (!$result['status']) {
  114. $this->status = FALSE;
  115. $this->errors['OWNER'] = array($result['error_code'] => $result['error_message']);
  116. }
  117. }
  118. // TODO: Handle NAME parameter
  119. /*if ($_old['NAME'] != $_new['NAME']) {
  120. $result = array();
  121. $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_NAME, array('IP' => $_new['IP_ADDRESS'], 'NAME' => $_new['NAME']));
  122. if (!$result['status']) {
  123. $this->status = FALSE;
  124. $this->errors['NAME'] = array($result['error_code'] => $result['error_message']);
  125. }
  126. }*/
  127. if ($_old['IP_STATUS'] != $_new['IP_STATUS']) {
  128. $result = array();
  129. $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_STATUS, array('IP' => $_new['IP_ADDRESS'], 'IP_STATUS' => $_new['IP_STATUS']));
  130. if (!$result['status']) {
  131. $this->status = FALSE;
  132. $this->errors['IP_STATUS'] = array($result['error_code'] => $result['error_message']);
  133. }
  134. }
  135. if (!$result['status']) {
  136. $this->errors[] = array($result['error_code'] => $result['error_message']);
  137. }
  138. return $this->reply($result['status'], $result['data']);
  139. }
  140. /**
  141. * Get Sys interfaces
  142. *
  143. * @param Request $request
  144. * @return string - Ajax Reply
  145. */
  146. public function getSysInterfacesExecute($request)
  147. {
  148. $reply = array();
  149. $result = Vesta::execute(Vesta::V_LIST_SYS_INTERFACES, array(Config::get('response_type')));
  150. foreach ($result['data'] as $iface) {
  151. $reply[$iface] = $iface;
  152. }
  153. if (!$result['status']) {
  154. $this->errors[] = array($result['error_code'] => $result['error_message']);
  155. }
  156. return $this->reply($result['status'], $reply);
  157. }
  158. }