modify.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_once('modules/editConfigurationFiles/functions.php');
  25. require_once("modules/config_games/server_config_parser.php");
  26. require_once('includes/lib_remote.php');
  27. function exec_ogp_module()
  28. {
  29. global $db, $view;
  30. $home_id = (int)$_GET['home_id'];
  31. $isAdmin = $db->isAdmin($_SESSION['user_id']);
  32. if ($isAdmin) {
  33. $server_home = $db->getGameHome($home_id);
  34. } else {
  35. $server_home = $db->getUserGameHome($_SESSION['user_id'], $home_id);
  36. }
  37. if ($server_home === false) {
  38. print_failure(get_lang('no_home'));
  39. $view->refresh("?m=gamemanager&p=game_monitor");
  40. return;
  41. }
  42. $server_xml = read_server_config(SERVER_CONFIG_LOCATION .'/'. $server_home['home_cfg_file']);
  43. $files = getFilesInXML($server_xml->configuration_files);
  44. $file = ($_SERVER['REQUEST_METHOD'] === 'POST' ? rawurldecode($_POST['file']) : rawurldecode($_GET['file']));
  45. if (array_search($file, array_column($files, 'path')) === false) {
  46. print_failure(get_lang('invalid_file'));
  47. $view->refresh("?m=editConfigurationFiles&home_id=". (int)$server_home['home_id']);
  48. return;
  49. }
  50. $remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key'], $server_home['timeout']);
  51. if ($remote->status_chk() === 0) {
  52. print_failure(get_lang('agent_offline'));
  53. $view->refresh("?m=gamemanager&p=game_monitor");
  54. return;
  55. }
  56. if ($remote->rfile_exists($server_home['home_path'] . '/' . $file) == 1) {
  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=editConfigurationFiles&home_id=". (int)$server_home['home_id']);
  62. return;
  63. } else {
  64. print_failure(get_lang('failed_write'));
  65. $view->refresh("?m=editConfigurationFiles&home_id=". (int)$server_home['home_id']);
  66. return;
  67. }
  68. } else {
  69. $file_info = $remote->remote_readfile($server_home['home_path'] . '/' . $file, $data);
  70. if ($file_info === 0) {
  71. print_failure(get_lang('file_not_found'));
  72. $view->refresh("?m=editConfigurationFiles");
  73. return;
  74. } elseif ($file_info === -2) {
  75. print_failure(get_lang('failed_read'));
  76. $view->refresh("?m=editConfigurationFiles");
  77. return;
  78. }
  79. echo '<h2>'.get_lang('editing_file').'</h2><p><b>'.htmlentities($file).'</b></p>';
  80. echo '<form action="?m=editConfigurationFiles&p=modify&home_id='.$server_home['home_id'].'" method="POST">';
  81. echo '<input type="hidden" name="file" value="'.rawurlencode($_GET['file']).'">';
  82. echo '<input type="hidden" name="action" value="save">';
  83. echo '<textarea name="file_content" style="width:98%;" rows="40">'. $data .'</textarea>';
  84. echo '<p><input type="submit" name="write" value="'. get_lang('save') . '" /></p>';
  85. echo '</form>';
  86. echo '<table class="center" style="width:100%;""><a href="?m=editConfigurationFiles&home_id='. (int)$server_home['home_id'].'">'.get_lang('go_back').'</a></table>';
  87. }
  88. } else {
  89. print_failure(get_lang('file_not_found'));
  90. $view->refresh("?m=gamemanager&p=game_monitor");
  91. return;
  92. }
  93. }