get_file.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. function exec_ogp_module()
  25. {
  26. require_once(MODULES."/litefm/litefm.php");
  27. $home_id = $_REQUEST['home_id'];
  28. if (empty($home_id))
  29. return;
  30. global $db;
  31. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  32. if($isAdmin)
  33. $home_cfg = $db->getGameHome($home_id);
  34. else
  35. $home_cfg = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  36. if ($home_cfg === FALSE)
  37. return;
  38. if ( preg_match("/f/",$home_cfg['access_rights']) != 1 )
  39. return;
  40. $downloads_folder = "modules/litefm/downloads";
  41. if(isset($_GET['remove_did']))
  42. {
  43. $did = $_GET['remove_did'];
  44. if(file_exists("$downloads_folder/$did"))
  45. unlink("$downloads_folder/$did");
  46. if(isset($_SESSION['download'][$did]))
  47. unset($_SESSION['download'][$did]);
  48. return;
  49. }
  50. if(!file_exists($downloads_folder))
  51. {
  52. if(!mkdir($downloads_folder))
  53. return;
  54. }
  55. else
  56. {
  57. if(!is_writable($downloads_folder))
  58. return;
  59. }
  60. $did = $_GET['did'];
  61. if(!isset($_SESSION['download'][$did]))
  62. {
  63. if (litefm_check($home_id) === FALSE)
  64. return;
  65. $_SESSION['download'][$did]['fileph'] = $_SESSION['fm_cwd_'.$home_id];
  66. $_SESSION['fm_cwd_'.$home_id] = dirname($_SESSION['fm_cwd_'.$home_id]);
  67. $_SESSION['download'][$did]['offset'] = 0;
  68. }
  69. set_time_limit(0);
  70. $remote = new OGPRemoteLibrary($home_cfg['agent_ip'], $home_cfg['agent_port'], $home_cfg['encryption_key'], $home_cfg['timeout']);
  71. $fp = fopen("$downloads_folder/$did", "w");
  72. $_SESSION['download'][$did]['offset'] = $remote->remote_get_file_part($home_cfg['home_path']."/".$_SESSION['download'][$did]['fileph'], $_SESSION['download'][$did]['offset'], $data);
  73. if($_SESSION['download'][$did]['offset'] != -1)
  74. fwrite($fp,$data);
  75. fclose($fp);
  76. header("Location: $downloads_folder/$did");
  77. }
  78. ?>