IP.class.php 5.7 KB

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