[php] changed main panel data source

This commit is contained in:
naumov-socolov 2012-02-24 01:18:58 +03:00
commit 9e0bc28dfc

View file

@ -18,6 +18,7 @@ class MAIN extends AjaxHandler
{ {
protected $templates = null; protected $templates = null;
protected $data = array();
public function aboutExecute($request) public function aboutExecute($request)
{ {
@ -165,7 +166,9 @@ MAIL;
public function getInitialExecute(Request $request) public function getInitialExecute(Request $request)
{ {
$user = VestaSession::getInstance()->getUser(); $user = VestaSession::getInstance()->getUser();
$global_data = array(); $global_data = array();
$totals = array( $totals = array(
'USER' => array('total' => 0, 'blocked' => 0), 'USER' => array('total' => 0, 'blocked' => 0),
'WEB_DOMAIN' => array('total' => 0, 'blocked' => 0), 'WEB_DOMAIN' => array('total' => 0, 'blocked' => 0),
@ -176,20 +179,81 @@ MAIL;
'CRON' => array('total' => 0, 'blocked' => 0) 'CRON' => array('total' => 0, 'blocked' => 0)
); );
$params = Vesta::execute(Vesta::V_LIST_SYS_USER, array('USER' => $user['uid']), self::JSON);
$init = $params['data'][$user['uid']];
$totals = array(
'USER' => array( 'total' => (int)$init['U_USERS'],
'blocked' => (int)$init['SUSPENDED_USERS']),
'WEB_DOMAIN' => array( 'total' => (int)$init['U_WEB_DOMAIN'],
'ssl' => (int)$init['U_WEB_SSL'],
'alias' => (int)$init['U_WEB_ALIASES'],
'blocked' => (int)$init['SUSPENDED_WEB']),
'MAIL' => array( 'total' => (int)$init['U_MAIL_DOMAINS'],
'accounts' => (int)$init['U_MAIL_ACCOUNTS'],
'blocked' => (int)$init['SUSPENDED_MAIL']),
'DB' => array( 'total' => (int)$init['U_DATABASES'],
'blocked' => (int)$init['SUSPENDED_DB']),
'DNS' => array( 'total' => (int)$init['U_DNS_DOMAINS'],
'records' => (int)$init['U_DNS_RECORDS'],
'blocked' => (int)$init['SUSPENDED_DNS']),
'IP' => array( 'total' => (int)$init['IP_AVAIL'],
'owned' => (int)$init['IP_OWNED']),
'CRON' => array( 'total' => (int)$init['U_CRON_JOBS'],
'blocked' => (int)$init['SUSPENDED_CRON'])
);
// users // users
$rs = Vesta::execute(Vesta::V_LIST_SYS_USERS, null, self::JSON); $rs = Vesta::execute(Vesta::V_LIST_SYS_USERS, null, self::JSON);
$data_user = $rs['data']; $data_user = $rs['data'];
$global_data['users'] = array(); $global_data['users'] = array();
foreach ($data_user as $login_name => $usr) { foreach ($data_user as $login_name => $usr) {
$totals['USER']['total'] += 1; // $totals['USER']['total'] += 1;
if ($usr['SUSPENDED'] != 'yes') { if ($usr['SUSPENDED'] != 'yes') {
$global_data['users'][$login_name] = $login_name; $this->data['users'] = array($login_name => $login_name);
} }
else { else {
$totals['USER']['blocked'] += 1; // $totals['USER']['blocked'] += 1;
} }
} }
// ip
$global_data['ips'] = array();
$rs = Vesta::execute(Vesta::V_LIST_SYS_IPS, null, self::JSON);
$data_ip = $rs['data'];
foreach ($data_ip as $ip => $obj) {
// $totals['IP']['total'] += 1;
$this->data['ips'] = array($ip => $ip);
}
$reply = array(
'auth_user' => array('uid' => $user, 'admin' => !!VestaSession::getUserRole()),
'user_data' => array('BANDWIDTH' => (int)$init['BANDWIDTH'], 'DISK_QUOTA' => (int)$init['DISK_QUOTA']),
'WEB_DOMAIN' => $this->getWebDomainParams(),
'CRON' => $this->getCronParams(),
'IP' => $this->getIpParams(),
'DNS' => $this->getDnsParams(),
'DB' => $this->getDbParams(),
'USERS' => $this->getUsersParams(),
'totals' => $totals,
'PROFILE' => $user,
'real_user' => $_SESSION['real_user'] ? $_SESSION['real_user'] : NULL
);
return $this->reply(true, $reply);
// web_domains // web_domains
$rs = Vesta::execute(Vesta::V_LIST_WEB_DOMAINS, array('USER' => $user['uid']), self::JSON); $rs = Vesta::execute(Vesta::V_LIST_WEB_DOMAINS, array('USER' => $user['uid']), self::JSON);
$data_web_domain = $rs['data']; $data_web_domain = $rs['data'];
@ -241,9 +305,9 @@ MAIL;
'user_data' => array('BANDWIDTH' => (int)$bandwidth, 'DISK_QUOTA' => (int)$disk_quota), 'user_data' => array('BANDWIDTH' => (int)$bandwidth, 'DISK_QUOTA' => (int)$disk_quota),
'WEB_DOMAIN' => $this->getWebDomainParams($data_web_domain, $global_data), 'WEB_DOMAIN' => $this->getWebDomainParams($data_web_domain, $global_data),
'CRON' => $this->getCronParams(), 'CRON' => $this->getCronParams(),
'IP' => $this->getIpParams($data_ip, $global_data), 'IP' => $this->getIpParams(),
'DNS' => $this->getDnsParams(), 'DNS' => $this->getDnsParams(),
'DB' => $this->getDbParams($data_db), 'DB' => $this->getDbParams(),
'USERS' => $this->getUsersParams($data_user), 'USERS' => $this->getUsersParams($data_user),
'totals' => $totals, 'totals' => $totals,
'PROFILE' => $user, 'PROFILE' => $user,
@ -277,28 +341,22 @@ MAIL;
* @params array $data * @params array $data
* @return array * @return array
*/ */
public function getWebDomainParams($data, $global_data) public function getWebDomainParams()
{ {
$user = $this->getLoggedUser(); $user = $this->getLoggedUser();
$ips = array(); if (empty($this->data['ips'])) {
$result = Vesta::execute(Vesta::V_LIST_USER_IPS, array('USER' => $user['uid']), self::JSON); $this->data['ips']['No available IP'] = 'No available IP';
foreach ($result['data'] as $sys_ip => $ip_data) {
$ips[$sys_ip] = $sys_ip;
}
if (empty($ips)) {
$ips['No available IP'] = 'No available IP';
} }
return array( return array(
'TPL' => $this->getTemplates(), 'TPL' => $this->getTemplates(),
'ALIAS' => array(), 'ALIAS' => array(),
'STAT' => array( 'STAT' => array(
'none' => 'none', 'none' => 'none',
'webalizer' => 'webalizer', 'webalizer' => 'webalizer',
'awstats' => 'awstats' 'awstats' => 'awstats'
), ),
'IP' => $ips 'IP' => $this->data['ips']
); );
} }
@ -319,23 +377,22 @@ MAIL;
* @params array $data * @params array $data
* @return array * @return array
*/ */
public function getIpParams($data = array(), $global_data = array()) public function getIpParams()
{ {
$ifaces = array(); $ifaces = array();
$result = Vesta::execute(Vesta::V_LIST_SYS_INTERFACES, array(Config::get('response_type'))); $result = Vesta::execute(Vesta::V_LIST_SYS_INTERFACES, array(Config::get('response_type')));
foreach ($result['data'] as $iface) { foreach ($result['data'] as $iface) {
$ifaces[$iface] = $iface; $this->data['ifaces'] = array($iface => $iface);
} }
return array( return array(
'SYS_USERS' => $global_data['users'], 'SYS_USERS' => $this->data['users'],
'STATUSES' => array( 'STATUSES' => array(
'shared' => 'shared', 'shared' => 'shared',
'exclusive' => 'exclusive' 'exclusive' => 'exclusive'
), ),
'INTERFACES' => $ifaces, 'INTERFACES' => $this->data['ifaces'],
'OWNER' => $global_data['users'], 'OWNER' => $this->data['users'],
'MASK' => array( 'MASK' => array(
'255.255.255.0' => '255.255.255.0', '255.255.255.0' => '255.255.255.0',
'255.255.255.128' => '255.255.255.128', '255.255.255.128' => '255.255.255.128',
@ -359,22 +416,23 @@ MAIL;
{ {
$dns_templates = array(); $dns_templates = array();
$user = $this->getLoggedUser(); $user = $this->getLoggedUser();
$this->templates = array(); $this->templates = array();
$result = Vesta::execute(Vesta::V_LIST_DNS_TEMPLATES, null, self::JSON); $result = Vesta::execute(Vesta::V_LIST_DNS_TEMPLATES, null, self::JSON);
// TODO: handle errors! // TODO: handle errors!
foreach ($result['data'] as $tpl => $description) { foreach ($result['data'] as $tpl => $description) {
$dns_templates[$tpl] = $description; $this->data['dns_templates'] = array($tpl => $description);
} }
return array( return array(
'IP' => @$data['ips'], 'IP' => $this->data['ips'],
'TPL' => $dns_templates, 'TPL' => $this->data['dns_templates'],
'EXP' => array(), 'EXP' => array(),
'SOA' => array(), 'SOA' => array(),
'TTL' => array(), 'TTL' => array(),
'record' => array( 'record' => array(
'RECORD' => array(), 'RECORD' => array(),
'RECORD_TYPE' => array('A' => 'A', 'NS' => 'NS', 'MX' => 'MX', 'TXT' => 'TXT'), 'RECORD_TYPE' => array('A' => 'A', 'NS' => 'NS', 'MX' => 'MX', 'TXT' => 'TXT', 'MAIL' => 'MAIL'),
'RECORD_VALUE' => array() 'RECORD_VALUE' => array()
) )
); );
@ -386,11 +444,11 @@ MAIL;
* @params array $data * @params array $data
* @return array * @return array
*/ */
public function getDbParams($data = array()) public function getDbParams()
{ {
$db_types = $this->getDBTypes(); $db_types = $this->getDBTypes();
$db_hosts = $this->getDBHosts(); $db_hosts = $this->getDBHosts();
$result = Vesta::execute(Vesta::V_LIST_DNS_TEMPLATES, null, self::JSON);
return array( return array(
'TYPE' => $db_types, 'TYPE' => $db_types,
'HOST' => $db_hosts, 'HOST' => $db_hosts,
@ -467,16 +525,15 @@ MAIL;
* @params array $data * @params array $data
* @return array * @return array
*/ */
public function getUsersParams($data = array(), $global_data = array()) public function getUsersParams()
{ {
$pckg = array();
// json
$result = Vesta::execute(Vesta::V_LIST_USER_PACKAGES, null, self::JSON); $result = Vesta::execute(Vesta::V_LIST_USER_PACKAGES, null, self::JSON);
foreach ($result['data'] as $pckg_name => $pckg_data) { foreach ($result['data'] as $pckg_name => $pckg_data) {
$pckg[$pckg_name] = $pckg_name; $this->data['user_packages'] = array($pckg_name => $pckg_name);
} }
return array( return array(
'PACKAGE' => $pckg, 'PACKAGE' => $this->data['user_packages'],
'SHELL' => array( 'SHELL' => array(
'sh' => 'sh', 'sh' => 'sh',
'bash' => 'bash', 'bash' => 'bash',