Files
VestaCP/web/vesta/api/IP.class.php

207 lines
5.5 KiB
PHP
Raw Normal View History

2011-06-14 00:22:25 +03:00
<?php
/**
* IP
*
* @author Naumov-Socolov <naumov.socolov@gmail.com>
* @author Malishev Dima <dima.malishev@gmail.com>
2011-06-14 00:22:25 +03:00
* @author vesta, http://vestacp.com/
* @copyright vesta 2010-2011
2011-06-14 00:22:25 +03:00
*/
class IP extends AjaxHandler
{
2011-06-21 13:32:26 +03:00
/**
* List entries
*
* @param Request $request
* @return
*/
public function getListExecute($request)
2011-06-14 00:22:25 +03:00
{
$reply = array();
2011-06-21 13:32:26 +03:00
2011-06-14 00:22:25 +03:00
$result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
foreach ($result['data'] as $ip => $details)
{
2011-06-21 13:32:26 +03:00
$reply[] = array_merge(array(
'IP_ADDRESS' => $ip,
'DATE' => date(Config::get('ui_date_format', strtotime($details['DATE'])))
), $details);
2011-06-14 00:22:25 +03:00
}
2011-06-21 13:32:26 +03:00
if (!$result['status'])
2011-06-21 13:32:26 +03:00
{
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
return $this->reply($result['status'], $reply);
2011-06-14 00:22:25 +03:00
}
2011-06-21 13:32:26 +03:00
/**
* List user ips entries
*
* @param Request $request
* @return
*/
public function getListUserIpsExecute($request)
2011-06-14 00:22:25 +03:00
{
$reply = array();
2011-06-21 13:32:26 +03:00
2011-06-14 00:22:25 +03:00
$result = Vesta::execute(Vesta::V_LIST_SYS_IPS, array(Config::get('response_type')));
foreach ($result['data'] as $ip => $details)
{
2011-06-21 13:32:26 +03:00
$reply[] = array_merge(array(
'IP_ADDRESS' => $ip,
'DATE' => date(Config::get('ui_date_format', strtotime($details['DATE'])))
), $details);
2011-06-14 00:22:25 +03:00
}
2011-06-21 13:32:26 +03:00
if (!$result['status'])
2011-06-21 13:32:26 +03:00
{
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
return $this->reply($result['status'], $reply);
2011-06-14 00:22:25 +03:00
}
2011-06-21 13:32:26 +03:00
/**
* Add entry
*
* @param Request $request
* @return
*/
public function addExecute($request)
2011-06-14 00:22:25 +03:00
{
2011-06-21 13:32:26 +03:00
$r = new Request();
$_s = $r->getSpell();
$_user = 'vesta';
2011-06-21 13:32:26 +03:00
$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']
);
2011-06-21 13:32:26 +03:00
$result = Vesta::execute(Vesta::V_ADD_SYS_IP, $params);
2011-06-21 13:32:26 +03:00
if (!$result['status'])
{
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
2011-06-21 13:32:26 +03:00
return $this->reply($result['status'], $result['data']);
2011-06-14 00:22:25 +03:00
}
2011-06-21 13:32:26 +03:00
/**
* Delete entry
*
* @param Request $request
* @return
*/
public function delExecute($request)
2011-06-14 00:22:25 +03:00
{
2011-06-21 13:32:26 +03:00
$r = new Request();
$_s = $r->getSpell();
$_user = 'vesta';
2011-06-14 00:22:25 +03:00
2011-06-21 13:32:26 +03:00
$params = array(
'IP_ADDRESS' => $_s['IP_ADDRESS']
);
2011-06-14 00:22:25 +03:00
2011-06-21 13:32:26 +03:00
$result = Vesta::execute(Vesta::V_DEL_SYS_IP, $params);
2011-06-14 00:22:25 +03:00
2011-06-21 13:32:26 +03:00
if (!$result['status'])
{
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
2011-06-14 00:22:25 +03:00
2011-06-21 13:32:26 +03:00
return $this->reply($result['status'], $result['data']);
}
2011-06-14 00:22:25 +03:00
2011-06-21 13:32:26 +03:00
/**
* Change entry
*
* @param Request $request
* @return
*/
public function changeExecute($request)
2011-06-14 00:22:25 +03:00
{
2011-06-21 13:32:26 +03:00
$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']);
}
2011-06-21 13:32:26 +03:00
/**
* Get sys interfaces
*
* @param Request $request
* @return
*/
public function getSysInterfacesExecute($request)
{
2011-06-21 13:32:26 +03:00
$reply = array();
2011-06-21 13:32:26 +03:00
$result = Vesta::execute(Vesta::V_LIST_SYS_INTERFACES, array(Config::get('response_type')));
2011-06-21 13:32:26 +03:00
foreach ($result['data'] as $iface)
{
$reply[$iface] = $iface;
}
2011-06-21 13:32:26 +03:00
if (!$result['status'])
{
$this->errors[] = array($result['error_code'] => $result['error_message']);
}
return $this->reply($result['status'], $reply);
2011-06-14 00:22:25 +03:00
}
}