1
0

get_dump.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. require_once('includes/lib_remote.php');
  3. if ( function_exists('mysqli_connect') )
  4. require_once("modules/mysql/mysqli_database.php");
  5. else
  6. require_once("modules/mysql/mysql_database.php");
  7. function exec_ogp_module() {
  8. $modDb = new MySQLModuleDatabase();
  9. require("includes/config.inc.php");
  10. $modDb->connect($db_host,$db_user,$db_pass,$db_name,$table_prefix);
  11. global $db;
  12. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  13. if( $isAdmin )
  14. $game_home = $db->getGameHome($_REQUEST['home_id']);
  15. else
  16. $game_home = $db->getUserGameHome($_SESSION['user_id'],$_GET['home_id']);
  17. if ( ! $game_home and ! $isAdmin )
  18. return;
  19. $home_dbs = $modDb->getMysqlDBsbyHomeId($game_home['home_id']);
  20. if(empty($home_dbs))
  21. {
  22. return;
  23. }
  24. $db_id = $_REQUEST['db_id'];
  25. $mysql_db = $modDb->getMysqlHomeDBbyId($game_home['home_id'],$db_id);
  26. if(!$mysql_db)
  27. return;
  28. $command = 'mysqldump --host='.$mysql_db['mysql_ip'].' --port='.$mysql_db['mysql_port'].' --user='.$mysql_db['db_user'].
  29. ' --password='.$mysql_db['db_passwd'].' '.$mysql_db['db_name']/* .'>backup-' . date("d-m-Y") . '.sql && cat backup-' . date("d-m-Y") . '.sql' */;
  30. if($mysql_db['remote_server_id'] != "0")
  31. {
  32. $remote_server = $db->getRemoteServer($mysql_db['remote_server_id']);
  33. $remote = new OGPRemoteLibrary($remote_server['agent_ip'],$remote_server['agent_port'],$remote_server['encryption_key'],$remote_server['timeout']);
  34. $host_stat = $remote->status_chk();
  35. if($host_stat === 1 )
  36. {
  37. $dump = $remote->exec($command,$output);
  38. }
  39. }
  40. else
  41. {
  42. $dump = system($command);
  43. }
  44. header( "Content-Type: text/plain" );
  45. header( 'Content-Disposition: attachment; filename="backup-' . $mysql_db['db_name'] . '-' . date("d-m-Y") . '.sql"' );
  46. echo $dump;
  47. }