get_size.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. function numbersFormatting($bytes){
  3. $si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
  4. $base = 1024;
  5. $class = min((int)log($bytes , $base) , count($si_prefix) - 1);
  6. return sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class];
  7. }
  8. function exec_ogp_module()
  9. {
  10. global $db;
  11. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  12. require_once('includes/lib_remote.php');
  13. if(isset($_GET['home_id']) and $_GET['home_id'] != "total")
  14. {
  15. if( $isAdmin )
  16. $game_home = $db->getGameHome($_GET['home_id']);
  17. else
  18. $game_home = $db->getUserGameHome($_SESSION['user_id'],$_GET['home_id']);
  19. if ( ! $game_home and ! $isAdmin )
  20. return;
  21. $remote = new OGPRemoteLibrary($game_home['agent_ip'], $game_home['agent_port'], $game_home['encryption_key'], $game_home['timeout']);
  22. $r = $remote->rfile_exists($game_home['home_path']);
  23. if($r == 1)
  24. {
  25. $home_path = preg_replace("/('+)/", "'\"$1\"'", $game_home['home_path']);
  26. $size = $remote->shell_action('size', $home_path);
  27. if(isset($_GET['bytes']))
  28. echo $size;
  29. else
  30. echo numbersFormatting($size);
  31. }
  32. else
  33. {
  34. echo get_lang("does_not_exist_yet");
  35. }
  36. }
  37. elseif( $isAdmin )
  38. {
  39. $game_homes = $db->getGameHomes();
  40. $total_size = 0;
  41. foreach($game_homes as $game_home)
  42. {
  43. $remote = new OGPRemoteLibrary($game_home['agent_ip'], $game_home['agent_port'], $game_home['encryption_key'], $game_home['timeout']);
  44. $r = $remote->rfile_exists($game_home['home_path']);
  45. if($r == 1)
  46. {
  47. $home_path = preg_replace("/('+)/", "'\"$1\"'", $game_home['home_path']);
  48. $kilobytes = $remote->shell_action('size', $home_path);
  49. $total_size += $kilobytes;
  50. }
  51. }
  52. echo numbersFormatting($total_size);
  53. }
  54. }
  55. ?>