@@ -18,6 +18,7 @@ class MAIN extends AjaxHandler
1818{
1919
2020 protected $ templates = null ;
21+ protected $ data = array ();
2122
2223 public function aboutExecute ($ request )
2324 {
@@ -165,7 +166,9 @@ public function downloadBackupExecute(Request $request)
165166 public function getInitialExecute (Request $ request )
166167 {
167168 $ user = VestaSession::getInstance ()->getUser ();
169+
168170 $ global_data = array ();
171+
169172 $ totals = array (
170173 'USER ' => array ('total ' => 0 , 'blocked ' => 0 ),
171174 'WEB_DOMAIN ' => array ('total ' => 0 , 'blocked ' => 0 ),
@@ -175,21 +178,82 @@ public function getInitialExecute(Request $request)
175178 'IP ' => array ('total ' => 0 , 'blocked ' => 0 ),
176179 'CRON ' => array ('total ' => 0 , 'blocked ' => 0 )
177180 );
178-
181+
182+ $ params = Vesta::execute (Vesta::V_LIST_SYS_USER , array ('USER ' => $ user ['uid ' ]), self ::JSON );
183+ $ init = $ params ['data ' ][$ user ['uid ' ]];
184+
185+
186+ $ totals = array (
187+ 'USER ' => array ( 'total ' => (int )$ init ['U_USERS ' ],
188+ 'blocked ' => (int )$ init ['SUSPENDED_USERS ' ]),
189+
190+ 'WEB_DOMAIN ' => array ( 'total ' => (int )$ init ['U_WEB_DOMAIN ' ],
191+ 'ssl ' => (int )$ init ['U_WEB_SSL ' ],
192+ 'alias ' => (int )$ init ['U_WEB_ALIASES ' ],
193+ 'blocked ' => (int )$ init ['SUSPENDED_WEB ' ]),
194+
195+ 'MAIL ' => array ( 'total ' => (int )$ init ['U_MAIL_DOMAINS ' ],
196+ 'accounts ' => (int )$ init ['U_MAIL_ACCOUNTS ' ],
197+ 'blocked ' => (int )$ init ['SUSPENDED_MAIL ' ]),
198+
199+ 'DB ' => array ( 'total ' => (int )$ init ['U_DATABASES ' ],
200+ 'blocked ' => (int )$ init ['SUSPENDED_DB ' ]),
201+
202+ 'DNS ' => array ( 'total ' => (int )$ init ['U_DNS_DOMAINS ' ],
203+ 'records ' => (int )$ init ['U_DNS_RECORDS ' ],
204+ 'blocked ' => (int )$ init ['SUSPENDED_DNS ' ]),
205+
206+ 'IP ' => array ( 'total ' => (int )$ init ['IP_AVAIL ' ],
207+ 'owned ' => (int )$ init ['IP_OWNED ' ]),
208+
209+ 'CRON ' => array ( 'total ' => (int )$ init ['U_CRON_JOBS ' ],
210+ 'blocked ' => (int )$ init ['SUSPENDED_CRON ' ])
211+ );
212+
213+
179214 // users
180215 $ rs = Vesta::execute (Vesta::V_LIST_SYS_USERS , null , self ::JSON );
181216 $ data_user = $ rs ['data ' ];
182217 $ global_data ['users ' ] = array ();
183218 foreach ($ data_user as $ login_name => $ usr ) {
184- $ totals ['USER ' ]['total ' ] += 1 ;
219+ // $totals['USER']['total'] += 1;
185220 if ($ usr ['SUSPENDED ' ] != 'yes ' ) {
186- $ global_data ['users ' ][ $ login_name] = $ login_name ;
221+ $ this -> data ['users ' ] = array ( $ login_name => $ login_name) ;
187222 }
188223 else {
189- $ totals ['USER ' ]['blocked ' ] += 1 ;
224+ // $totals['USER']['blocked'] += 1;
190225 }
191226 }
192227
228+
229+ // ip
230+ $ global_data ['ips ' ] = array ();
231+ $ rs = Vesta::execute (Vesta::V_LIST_SYS_IPS , null , self ::JSON );
232+ $ data_ip = $ rs ['data ' ];
233+ foreach ($ data_ip as $ ip => $ obj ) {
234+ // $totals['IP']['total'] += 1;
235+ $ this ->data ['ips ' ] = array ($ ip => $ ip );
236+ }
237+
238+
239+ $ reply = array (
240+ 'auth_user ' => array ('uid ' => $ user , 'admin ' => !!VestaSession::getUserRole ()),
241+ 'user_data ' => array ('BANDWIDTH ' => (int )$ init ['BANDWIDTH ' ], 'DISK_QUOTA ' => (int )$ init ['DISK_QUOTA ' ]),
242+ 'WEB_DOMAIN ' => $ this ->getWebDomainParams (),
243+ 'CRON ' => $ this ->getCronParams (),
244+ 'IP ' => $ this ->getIpParams (),
245+ 'DNS ' => $ this ->getDnsParams (),
246+ 'DB ' => $ this ->getDbParams (),
247+ 'USERS ' => $ this ->getUsersParams (),
248+ 'totals ' => $ totals ,
249+ 'PROFILE ' => $ user ,
250+ 'real_user ' => $ _SESSION ['real_user ' ] ? $ _SESSION ['real_user ' ] : NULL
251+ );
252+
253+
254+ return $ this ->reply (true , $ reply );
255+
256+
193257 // web_domains
194258 $ rs = Vesta::execute (Vesta::V_LIST_WEB_DOMAINS , array ('USER ' => $ user ['uid ' ]), self ::JSON );
195259 $ data_web_domain = $ rs ['data ' ];
@@ -241,9 +305,9 @@ public function getInitialExecute(Request $request)
241305 'user_data ' => array ('BANDWIDTH ' => (int )$ bandwidth , 'DISK_QUOTA ' => (int )$ disk_quota ),
242306 'WEB_DOMAIN ' => $ this ->getWebDomainParams ($ data_web_domain , $ global_data ),
243307 'CRON ' => $ this ->getCronParams (),
244- 'IP ' => $ this ->getIpParams ($ data_ip , $ global_data ),
308+ 'IP ' => $ this ->getIpParams (),
245309 'DNS ' => $ this ->getDnsParams (),
246- 'DB ' => $ this ->getDbParams ($ data_db ),
310+ 'DB ' => $ this ->getDbParams (),
247311 'USERS ' => $ this ->getUsersParams ($ data_user ),
248312 'totals ' => $ totals ,
249313 'PROFILE ' => $ user ,
@@ -277,28 +341,22 @@ protected function getTemplates()
277341 * @params array $data
278342 * @return array
279343 */
280- public function getWebDomainParams ($ data , $ global_data )
344+ public function getWebDomainParams ()
281345 {
282346 $ user = $ this ->getLoggedUser ();
283- $ ips = array ();
284- $ result = Vesta::execute (Vesta::V_LIST_USER_IPS , array ('USER ' => $ user ['uid ' ]), self ::JSON );
285- foreach ($ result ['data ' ] as $ sys_ip => $ ip_data ) {
286- $ ips [$ sys_ip ] = $ sys_ip ;
287- }
288-
289- if (empty ($ ips )) {
290- $ ips ['No available IP ' ] = 'No available IP ' ;
347+ if (empty ($ this ->data ['ips ' ])) {
348+ $ this ->data ['ips ' ]['No available IP ' ] = 'No available IP ' ;
291349 }
292350
293351 return array (
294352 'TPL ' => $ this ->getTemplates (),
295353 'ALIAS ' => array (),
296354 'STAT ' => array (
297- 'none ' => 'none ' ,
298- 'webalizer ' => 'webalizer ' ,
299- 'awstats ' => 'awstats '
300- ),
301- 'IP ' => $ ips
355+ 'none ' => 'none ' ,
356+ 'webalizer ' => 'webalizer ' ,
357+ 'awstats ' => 'awstats '
358+ ),
359+ 'IP ' => $ this -> data [ ' ips ' ]
302360 );
303361 }
304362
@@ -319,23 +377,22 @@ public function getCronParams($data = array())
319377 * @params array $data
320378 * @return array
321379 */
322- public function getIpParams ($ data = array (), $ global_data = array () )
380+ public function getIpParams ()
323381 {
324- $ ifaces = array ();
325- $ result = Vesta::execute (Vesta::V_LIST_SYS_INTERFACES , array (Config::get ('response_type ' )));
326-
327- foreach ($ result ['data ' ] as $ iface ) {
328- $ ifaces [$ iface ] = $ iface ;
329- }
382+ $ ifaces = array ();
383+ $ result = Vesta::execute (Vesta::V_LIST_SYS_INTERFACES , array (Config::get ('response_type ' )));
384+ foreach ($ result ['data ' ] as $ iface ) {
385+ $ this ->data ['ifaces ' ] = array ($ iface => $ iface );
386+ }
330387
331388 return array (
332- 'SYS_USERS ' => $ global_data ['users ' ],
389+ 'SYS_USERS ' => $ this -> data ['users ' ],
333390 'STATUSES ' => array (
334391 'shared ' => 'shared ' ,
335392 'exclusive ' => 'exclusive '
336393 ),
337- 'INTERFACES ' => $ ifaces ,
338- 'OWNER ' => $ global_data ['users ' ],
394+ 'INTERFACES ' => $ this -> data [ ' ifaces ' ] ,
395+ 'OWNER ' => $ this -> data ['users ' ],
339396 'MASK ' => array (
340397 '255.255.255.0 ' => '255.255.255.0 ' ,
341398 '255.255.255.128 ' => '255.255.255.128 ' ,
@@ -359,22 +416,23 @@ public function getDnsParams($data = array())
359416 {
360417 $ dns_templates = array ();
361418 $ user = $ this ->getLoggedUser ();
419+
362420 $ this ->templates = array ();
363421 $ result = Vesta::execute (Vesta::V_LIST_DNS_TEMPLATES , null , self ::JSON );
364422 // TODO: handle errors!
365423 foreach ($ result ['data ' ] as $ tpl => $ description ) {
366- $ dns_templates [ $ tpl] = $ description ;
424+ $ this -> data [ ' dns_templates ' ] = array ( $ tpl => $ description) ;
367425 }
368426
369427 return array (
370- 'IP ' => @ $ data ['ips ' ],
371- 'TPL ' => $ dns_templates ,
428+ 'IP ' => $ this -> data ['ips ' ],
429+ 'TPL ' => $ this -> data [ ' dns_templates ' ] ,
372430 'EXP ' => array (),
373431 'SOA ' => array (),
374432 'TTL ' => array (),
375433 'record ' => array (
376434 'RECORD ' => array (),
377- 'RECORD_TYPE ' => array ('A ' => 'A ' , 'NS ' => 'NS ' , 'MX ' => 'MX ' , 'TXT ' => 'TXT ' ),
435+ 'RECORD_TYPE ' => array ('A ' => 'A ' , 'NS ' => 'NS ' , 'MX ' => 'MX ' , 'TXT ' => 'TXT ' , ' MAIL ' => ' MAIL ' ),
378436 'RECORD_VALUE ' => array ()
379437 )
380438 );
@@ -386,11 +444,11 @@ public function getDnsParams($data = array())
386444 * @params array $data
387445 * @return array
388446 */
389- public function getDbParams ($ data = array () )
447+ public function getDbParams ()
390448 {
391449 $ db_types = $ this ->getDBTypes ();
392450 $ db_hosts = $ this ->getDBHosts ();
393- $ result = Vesta:: execute (Vesta:: V_LIST_DNS_TEMPLATES , null , self :: JSON );
451+
394452 return array (
395453 'TYPE ' => $ db_types ,
396454 'HOST ' => $ db_hosts ,
@@ -467,16 +525,15 @@ public function getDBHosts()
467525 * @params array $data
468526 * @return array
469527 */
470- public function getUsersParams ($ data = array (), $ global_data = array () )
528+ public function getUsersParams ()
471529 {
472- $ pckg = array ();
473- // json
474- $ result = Vesta::execute (Vesta::V_LIST_USER_PACKAGES , null , self ::JSON );
530+ $ result = Vesta::execute (Vesta::V_LIST_USER_PACKAGES , null , self ::JSON );
475531 foreach ($ result ['data ' ] as $ pckg_name => $ pckg_data ) {
476- $ pckg [ $ pckg_name] = $ pckg_name ;
532+ $ this -> data [ ' user_packages ' ] = array ( $ pckg_name => $ pckg_name) ;
477533 }
534+
478535 return array (
479- 'PACKAGE ' => $ pckg ,
536+ 'PACKAGE ' => $ this -> data [ ' user_packages ' ] ,
480537 'SHELL ' => array (
481538 'sh ' => 'sh ' ,
482539 'bash ' => 'bash ' ,
0 commit comments