fm_read.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. {
  30. print_failure(get_lang('home_id_missing'));
  31. return;
  32. }
  33. global $db;
  34. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  35. if($isAdmin)
  36. $home_cfg = $db->getGameHome($home_id);
  37. else
  38. $home_cfg = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  39. if ($home_cfg === FALSE)
  40. {
  41. print_failure(get_lang('no_access_to_home'));
  42. return;
  43. }
  44. if ( preg_match("/f/",$home_cfg['access_rights']) != 1 )
  45. {
  46. print_failure( get_lang("no_rights") );
  47. echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=".$home_cfg['home_id']."'><< ". get_lang("back") ."</a></td></tr></table>";
  48. return;
  49. }
  50. $home_id = $home_cfg['home_id'];
  51. if (litefm_check($home_id) === FALSE)
  52. return;
  53. $show_path = (isset($_SESSION['fm_cwd_'.$home_id])) ? clean_path($_SESSION['fm_cwd_'.$home_id]) : "/";
  54. if($isAdmin)
  55. $show_path = clean_path($home_cfg['home_path'].$show_path);
  56. echo "<table class='center' style='width:100%;'>".show_back($home_id)."</table>";
  57. echo "<table class='center' style='width:100%;' ><tr>\n".
  58. "<td colspan='3' ><h3>$show_path</h3></td>".
  59. "</tr></table>\n";
  60. //Logic to open the file we're editing
  61. $remote = new OGPRemoteLibrary($home_cfg['agent_ip'], $home_cfg['agent_port'], $home_cfg['encryption_key'], $home_cfg['timeout']);
  62. $data = "";
  63. $rel_path = isset($_SESSION['fm_cwd_'.$home_id]) ? $_SESSION['fm_cwd_'.$home_id]:'';
  64. $filepath = clean_path($home_cfg['home_path']."/".$rel_path);
  65. $file_info = $remote->remote_readfile($filepath ,$data);
  66. if ( $file_info === 0 )
  67. {
  68. print_failure(get_lang("not_found"));
  69. return;
  70. }
  71. else if ( $file_info === -1 )
  72. {
  73. print_failure(get_lang("agent_offline"));
  74. return;
  75. }
  76. else if ( $file_info === -2 )
  77. {
  78. print_failure(get_lang("failed_read"));
  79. return;
  80. }
  81. ?>
  82. <div id="editor_wrapper" >
  83. <xmp id="editor"><?php echo $data;?></xmp>
  84. </div>
  85. <button onclick="saveToFile()"><?php echo get_lang('save'); ?></button>
  86. <link rel="stylesheet" type="text/css" href="modules/litefm/fm_read.css">
  87. <script src="modules/litefm/ace/ace.js" type="text/javascript" charset="utf-8"></script>
  88. <script src="modules/litefm/ace/ext-modelist.js" type="text/javascript" charset="utf-8"></script>
  89. <script>
  90. var editor = ace.edit("editor");
  91. editor.setTheme("ace/theme/tomorrow");
  92. (function () {
  93. var modelist = ace.require("ace/ext/modelist");
  94. var filePath = "<?php echo $rel_path; ?>";
  95. var mode = modelist.getModeForPath(filePath).mode;
  96. console.log(mode);
  97. editor.session.setMode(mode);
  98. }());
  99. function saveToFile()
  100. {
  101. var form = document.createElement("form");
  102. form.setAttribute("method", "POST");
  103. form.setAttribute("action", "?m=litefm&p=write_file");
  104. var textArea = document.createElement("textarea");
  105. textArea.setAttribute("name", "file_content");
  106. textArea.setAttribute("style", "display:none;");
  107. textArea.value = editor.getValue();
  108. form.appendChild(textArea);
  109. var hiddenField = document.createElement("input");
  110. hiddenField.setAttribute("type", "hidden");
  111. hiddenField.setAttribute("name", "home_id");
  112. hiddenField.setAttribute("value", "<?php echo $home_id; ?>");
  113. form.appendChild(hiddenField);
  114. var submitButton = document.createElement("input");
  115. submitButton.setAttribute("type", "hidden");
  116. submitButton.setAttribute("name", "save_file");
  117. submitButton.setAttribute("value", "save_file");
  118. form.appendChild(submitButton);
  119. document.body.appendChild(form);
  120. form.submit();
  121. }
  122. </script>
  123. <?php
  124. show_back($home_id);
  125. }
  126. ?>