IP.class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * IP
  4. *
  5. * @author Naumov-Socolov <naumov.socolov@gmail.com>
  6. * @author Malishev Dima <dima.malishev@gmail.com>
  7. * @author vesta, http://vestacp.com/
  8. * @copyright vesta 2010-2011
  9. */
  10. class IP extends AjaxHandler
  11. {
  12. /**
  13. * List entries
  14. *
  15. * @param Request $request
  16. * @return
  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. {
  24. $reply[] = array_merge(array(
  25. 'IP_ADDRESS' => $ip,
  26. 'DATE' => date(Config::get('ui_date_format', strtotime($details['DATE'])))
  27. ), $details);
  28. }
  29. if (!$result['status'])
  30. {
  31. $this->errors[] = array($result['error_code'] => $result['error_message']);
  32. }
  33. return $this->reply($result['status'], $reply);
  34. }
  35. /**
  36. * List user ips entries
  37. *
  38. * @param Request $request
  39. * @return
  40. */
  41. public function getListUserIpsExecute($request)
  42. {
  43. $reply = array();
  44. $result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
  45. foreach ($result['data'] as $ip => $details)
  46. {
  47. $reply[] = array_merge(array(
  48. 'IP_ADDRESS' => $ip,
  49. 'DATE' => date(Config::get('ui_date_format', strtotime($details['DATE'])))
  50. ), $details);
  51. }
  52. if (!$result['status'])
  53. {
  54. $this->errors[] = array($result['error_code'] => $result['error_message']);
  55. }
  56. return $this->reply($result['status'], $reply);
  57. }
  58. /**
  59. * Add entry
  60. *
  61. * @param Request $request
  62. * @return
  63. */
  64. public function addExecute($request)
  65. {
  66. $r = new Request();
  67. $_s = $r->getSpell();
  68. $_user = 'vesta';
  69. $params = array(
  70. 'IP_ADDRESS' => $_s['IP_ADDRESS'],
  71. 'MASK' => $_s['MASK'],
  72. 'INTERFACE' => $_s['INTERFACE'],
  73. 'OWNER' => $_s['OWNER'],
  74. 'IP_STATUS' => $_s['IP_STATUS'],
  75. 'IP_NAME' => $_s['IP_NAME']
  76. );
  77. $result = Vesta::execute(Vesta::V_ADD_SYS_IP, $params);
  78. if (!$result['status'])
  79. {
  80. $this->errors[] = array($result['error_code'] => $result['error_message']);
  81. }
  82. return $this->reply($result['status'], $result['data']);
  83. }
  84. /**
  85. * Delete entry
  86. *
  87. * @param Request $request
  88. * @return
  89. */
  90. public function delExecute($request)
  91. {
  92. $r = new Request();
  93. $_s = $r->getSpell();
  94. $_user = 'vesta';
  95. $params = array(
  96. 'IP_ADDRESS' => $_s['IP_ADDRESS']
  97. );
  98. $result = Vesta::execute(Vesta::V_DEL_SYS_IP, $params);
  99. if (!$result['status'])
  100. {
  101. $this->errors[] = array($result['error_code'] => $result['error_message']);
  102. }
  103. return $this->reply($result['status'], $result['data']);
  104. }
  105. /**
  106. * Change entry
  107. *
  108. * @param Request $request
  109. * @return
  110. */
  111. public function changeExecute($request)
  112. {
  113. $r = new Request();
  114. $_s = $r->getSpell();
  115. $_old = $_s['old'];
  116. $_new = $_s['new'];
  117. $_user = 'vesta';
  118. if ($_old['OWNER'] != $_new['OWNER'])
  119. {
  120. $result = array();
  121. $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_OWNER, array('OWNER' => $_new['OWNER'], 'IP' => $_new['IP_ADDRESS']));
  122. if(!$result['status'])
  123. {
  124. $this->status = FALSE;
  125. $this->errors['OWNER'] = array($result['error_code'] => $result['error_message']);
  126. }
  127. }
  128. if ($_old['NAME'] != $_new['NAME'])
  129. {
  130. $result = array();
  131. $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_NAME, array('IP' => $_new['IP_ADDRESS'], 'NAME' => $_new['NAME']));
  132. if (!$result['status'])
  133. {
  134. $this->status = FALSE;
  135. $this->errors['NAME'] = array($result['error_code'] => $result['error_message']);
  136. }
  137. }
  138. if ($_old['IP_STATUS'] != $_new['IP_STATUS'])
  139. {
  140. $result = array();
  141. $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_STATUS, array('IP' => $_new['IP_ADDRESS'], 'IP_STATUS' => $_new['IP_STATUS']));
  142. if (!$result['status'])
  143. {
  144. $this->status = FALSE;
  145. $this->errors['IP_STATUS'] = array($result['error_code'] => $result['error_message']);
  146. }
  147. }
  148. if (!$result['status'])
  149. {
  150. $this->errors[] = array($result['error_code'] => $result['error_message']);
  151. }
  152. return $this->reply($result['status'], $result['data']);
  153. }
  154. /**
  155. * Get sys interfaces
  156. *
  157. * @param Request $request
  158. * @return
  159. */
  160. public function getSysInterfacesExecute($request)
  161. {
  162. $reply = array();
  163. $result = Vesta::execute(Vesta::V_LIST_SYS_INTERFACES, array(Config::get('response_type')));
  164. foreach ($result['data'] as $iface)
  165. {
  166. $reply[$iface] = $iface;
  167. }
  168. if (!$result['status'])
  169. {
  170. $this->errors[] = array($result['error_code'] => $result['error_message']);
  171. }
  172. return $this->reply($result['status'], $reply);
  173. }
  174. }