| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- /**
- * IP
- *
- * @author Naumov-Socolov <naumov.socolov@gmail.com>
- * @author Malishev Dima <dima.malishev@gmail.com>
- * @author vesta, http://vestacp.com/
- * @copyright vesta 2010-2011
- */
- class IP extends AjaxHandler
- {
- /**
- * List entries
- *
- * @param Request $request
- * @return
- */
- public function getListExecute($request)
- {
- $reply = array();
-
- $result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
- foreach ($result['data'] as $ip => $details)
- {
- $reply[] = array_merge(array(
- 'IP_ADDRESS' => $ip,
- 'DATE' => date(Config::get('ui_date_format', strtotime($details['DATE'])))
- ), $details);
- }
-
- if (!$result['status'])
- {
- $this->errors[] = array($result['error_code'] => $result['error_message']);
- }
-
- return $this->reply($result['status'], $reply);
- }
- /**
- * List user ips entries
- *
- * @param Request $request
- * @return
- */
- public function getListUserIpsExecute($request)
- {
- $reply = array();
-
- $result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
- foreach ($result['data'] as $ip => $details)
- {
- $reply[] = array_merge(array(
- 'IP_ADDRESS' => $ip,
- 'DATE' => date(Config::get('ui_date_format', strtotime($details['DATE'])))
- ), $details);
- }
-
- if (!$result['status'])
- {
- $this->errors[] = array($result['error_code'] => $result['error_message']);
- }
-
- return $this->reply($result['status'], $reply);
- }
-
- /**
- * Add entry
- *
- * @param Request $request
- * @return
- */
- public function addExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
- $params = array(
- 'IP_ADDRESS' => $_s['IP_ADDRESS'],
- 'MASK' => $_s['MASK'],
- 'INTERFACE' => $_s['INTERFACE'],
- 'OWNER' => $_s['OWNER'],
- 'IP_STATUS' => $_s['IP_STATUS'],
- 'IP_NAME' => $_s['IP_NAME']
- );
- $result = Vesta::execute(Vesta::V_ADD_SYS_IP, $params);
- if (!$result['status'])
- {
- $this->errors[] = array($result['error_code'] => $result['error_message']);
- }
- return $this->reply($result['status'], $result['data']);
- }
- /**
- * Delete entry
- *
- * @param Request $request
- * @return
- */
- public function delExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
- $_user = 'vesta';
- $params = array(
- 'IP_ADDRESS' => $_s['IP_ADDRESS']
- );
- $result = Vesta::execute(Vesta::V_DEL_SYS_IP, $params);
- if (!$result['status'])
- {
- $this->errors[] = array($result['error_code'] => $result['error_message']);
- }
- return $this->reply($result['status'], $result['data']);
- }
- /**
- * Change entry
- *
- * @param Request $request
- * @return
- */
- public function changeExecute($request)
- {
- $r = new Request();
- $_s = $r->getSpell();
- $_old = $_s['old'];
- $_new = $_s['new'];
- $_user = 'vesta';
- if ($_old['OWNER'] != $_new['OWNER'])
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_OWNER, array('OWNER' => $_new['OWNER'], 'IP' => $_new['IP_ADDRESS']));
- if(!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['OWNER'] = array($result['error_code'] => $result['error_message']);
- }
- }
- if ($_old['NAME'] != $_new['NAME'])
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_NAME, array('IP' => $_new['IP_ADDRESS'], 'NAME' => $_new['NAME']));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['NAME'] = array($result['error_code'] => $result['error_message']);
- }
- }
- if ($_old['IP_STATUS'] != $_new['IP_STATUS'])
- {
- $result = array();
- $result = Vesta::execute(Vesta::V_CHANGE_SYS_IP_STATUS, array('IP' => $_new['IP_ADDRESS'], 'IP_STATUS' => $_new['IP_STATUS']));
- if (!$result['status'])
- {
- $this->status = FALSE;
- $this->errors['IP_STATUS'] = array($result['error_code'] => $result['error_message']);
- }
- }
- if (!$result['status'])
- {
- $this->errors[] = array($result['error_code'] => $result['error_message']);
- }
- return $this->reply($result['status'], $result['data']);
- }
-
- /**
- * Get sys interfaces
- *
- * @param Request $request
- * @return
- */
- public function getSysInterfacesExecute($request)
- {
- $reply = array();
- $result = Vesta::execute(Vesta::V_LIST_SYS_INTERFACES, array(Config::get('response_type')));
- foreach ($result['data'] as $iface)
- {
- $reply[$iface] = $iface;
- }
- if (!$result['status'])
- {
- $this->errors[] = array($result['error_code'] => $result['error_message']);
- }
-
- return $this->reply($result['status'], $reply);
- }
-
- }
|