modify.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 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. require 'modules/editconfigfiles/array_column.php';
  25. require 'modules/editconfigfiles/functions.php';
  26. require 'modules/config_games/server_config_parser.php';
  27. require 'includes/lib_remote.php';
  28. function exec_ogp_module()
  29. {
  30. global $db, $view;
  31. $home_id = (int)$_GET['home_id'];
  32. $isAdmin = $db->isAdmin($_SESSION['user_id']);
  33. if ($isAdmin) {
  34. $server_home = $db->getGameHome($home_id);
  35. } else {
  36. $server_home = $db->getUserGameHome($_SESSION['user_id'], $home_id);
  37. }
  38. if ($server_home === false) {
  39. print_failure(get_lang('no_home'));
  40. $view->refresh("?m=gamemanager&p=game_monitor");
  41. return;
  42. }
  43. $server_xml = read_server_config(SERVER_CONFIG_LOCATION .'/'. $server_home['home_cfg_file']);
  44. $files = getFilesInXML($server_xml->configuration_files);
  45. $file = ($_SERVER['REQUEST_METHOD'] === 'POST' ? rawurldecode($_POST['file']) : rawurldecode($_GET['file']));
  46. if (array_search($file, array_column($files, 'path')) === false) {
  47. print_failure(get_lang('invalid_file'));
  48. $view->refresh("?m=editconfigfiles&home_id=". (int)$server_home['home_id']);
  49. return;
  50. }
  51. $remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key'], $server_home['timeout']);
  52. if ($remote->status_chk() === 0) {
  53. print_failure(get_lang('agent_offline'));
  54. $view->refresh("?m=gamemanager&p=game_monitor");
  55. return;
  56. }
  57. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  58. $file_info = $remote->remote_writefile($server_home['home_path'] . '/' . $file, strip_real_escape_string($_POST['file_content']));
  59. if ($file_info === 1) {
  60. print_success(get_lang('wrote_changes'));
  61. $view->refresh("?m=editconfigfiles&home_id=". (int)$server_home['home_id']);
  62. return;
  63. } else {
  64. print_failure(get_lang('failed_write'));
  65. $view->refresh("?m=editconfigfiles&home_id=". (int)$server_home['home_id']);
  66. return;
  67. }
  68. } else {
  69. $newFile = ($remote->rfile_exists($server_home['home_path'] . '/' . $file) == 0 ? true : false);
  70. $file_info = $remote->remote_readfile($server_home['home_path'] . '/' . $file, $data);
  71. if ($file_info !== 1) {
  72. print_failure(get_lang('failed_read'));
  73. $view->refresh("?m=editconfigfiles");
  74. return;
  75. }
  76. echo '<h2>'.get_lang('editing_file').'</h2><p><b>'.($newFile ? get_lang('new_file').':' : '') .' '. htmlentities($file).'</b></p>';
  77. echo '<form action="?m=editconfigfiles&p=modify&home_id='.$server_home['home_id'].'" method="POST">';
  78. echo '<input type="hidden" name="file" value="'.rawurlencode($_GET['file']).'">';
  79. echo '<input type="hidden" name="action" value="save">';
  80. echo '<textarea name="file_content" style="width:98%;" rows="40">'. $data .'</textarea>';
  81. echo '<p><input type="submit" name="write" value="'. get_lang('save') . '" /></p>';
  82. echo '</form>';
  83. echo '<div><a href="?m=editconfigfiles&home_id='. (int)$server_home['home_id'].'">'.get_lang('go_back').'</a></div>';
  84. }
  85. }