blacklist.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <script type="text/javascript" src="js/modules/update.js"></script>
  2. <?php
  3. /*
  4. *
  5. * OGP - Open Game Panel
  6. * Copyright (C) 2008 - 2018 The OGP Development Team
  7. *
  8. * http://www.opengamepanel.org/
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. *
  24. */
  25. function show_back()
  26. {
  27. if( isset($_SESSION['fm_cwd']) && preg_match("/^\/*$/",$_SESSION['fm_cwd']) == 0 )
  28. return "<tr>\n".
  29. "<td align=left colspan='2' >\n".
  30. "<a href=\"?m=".$_GET['m']."&amp;p=blacklist&amp;back\" style='padding-left:5px;' > ..&nbsp;&nbsp;".get_lang("level_up")."</a>\n".
  31. "</td>\n".
  32. "</tr>\n";
  33. }
  34. function path_check()
  35. {
  36. if (isset($_GET['path']) and !isset( $_POST['save_to_blacklist'] ))
  37. {
  38. $path = $_GET['path'];
  39. // Make sure nobody tries to get outside thier game server by referencing the .. directory
  40. if(preg_match("/\.\.|\||;/", $path))
  41. {
  42. print_failure(get_lang("unallowed_char"));
  43. $_SESSION['fm_cwd'] = NULL;
  44. return FALSE;
  45. }
  46. else
  47. {
  48. $_SESSION['fm_cwd'] = @$_SESSION['fm_cwd'] . "/" . $path;
  49. }
  50. }
  51. // To go back a dir, we just use dirname to strip the last directory or file off the path
  52. if (isset($_GET['back']) and !isset( $_POST['save_to_blacklist'] ))
  53. {
  54. $_SESSION['fm_cwd'] = str_replace( "\\", "", dirname( $_SESSION['fm_cwd'] ) );
  55. }
  56. return TRUE;
  57. }
  58. function exec_ogp_module()
  59. {
  60. global $db, $view;
  61. $blacklist = array ('/install.php',
  62. '/modules/gamemanager/rsync_sites_local.list');
  63. $current_blacklist = array();
  64. $blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;');
  65. if($blacklisted_files !== FALSE)
  66. {
  67. $current_blacklist = array();
  68. foreach($blacklisted_files as $blacklisted_file)
  69. {
  70. $current_blacklist[] = $blacklisted_file['file_path'];
  71. }
  72. }
  73. if( isset( $_POST['save_to_blacklist'] ) )
  74. {
  75. foreach($_POST['blacklist'] as $file)
  76. {
  77. $file = $db->real_escape_string($file);
  78. $db->query("INSERT INTO `OGP_DB_PREFIXupdate_blacklist` SET file_path='$file';");
  79. }
  80. foreach($_POST['folder_files'] as $file)
  81. {
  82. if(is_array($current_blacklist) && in_array($file,$current_blacklist))
  83. {
  84. if(is_array($_POST['blacklist']) && !in_array($file,$_POST['blacklist']))
  85. {
  86. $file = $db->real_escape_string($file);
  87. $db->query("DELETE FROM `OGP_DB_PREFIXupdate_blacklist` WHERE file_path='$file';");
  88. }
  89. }
  90. }
  91. $blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;');
  92. if($blacklisted_files !== FALSE)
  93. {
  94. $current_blacklist = array();
  95. foreach($blacklisted_files as $blacklisted_file)
  96. {
  97. $current_blacklist[] = $blacklisted_file['file_path'];
  98. }
  99. }
  100. }
  101. $current_blacklist = array_merge($current_blacklist,$blacklist);
  102. path_check();
  103. echo "<h2>";
  104. echo get_lang('blacklist_files');
  105. echo "</h2>";
  106. $baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
  107. $path = clean_path($baseDir."/".@$_SESSION['fm_cwd']);
  108. if (!file_exists($path))
  109. {
  110. while(!file_exists($path))
  111. {
  112. $path = dirname($path);
  113. $_SESSION['fm_cwd'] = dirname($_SESSION['fm_cwd']);
  114. if($path == clean_path($baseDir))
  115. {
  116. print_failure(get_lang_f("dir_not_found",$path));
  117. break;
  118. }
  119. }
  120. }
  121. echo "<table class='center' style='width:100%;' ><tr>\n".
  122. "<td colspan='3' ><h3>".
  123. get_lang_f('currently_viewing',$path)."</h3></td>".
  124. "</tr></table>";
  125. $dirlist = scandir($path);
  126. if (!is_array($dirlist))
  127. {
  128. if($dirlist === -1)
  129. {
  130. if ( $path != $baseDir . "/" )
  131. $view->refresh('?m='.$_GET['m'].'&amp;p=blacklist',0);
  132. else
  133. print_failure('The path is too long or there is a file with a very long name inside of your game server\'s home folder.');
  134. }
  135. else
  136. {
  137. if (file_exists($path))
  138. {
  139. if(strpos($path, '/') !== FALSE)
  140. {
  141. $ePath = explode('/', $path);
  142. $filename = end($ePath);
  143. }
  144. else if(strpos($path, '\\') !== FALSE)
  145. {
  146. $ePath = explode('\\', $path);
  147. $filename = end($ePath);
  148. }
  149. $_SESSION['fm_cwd'] = str_replace( "\\", "", dirname( $_SESSION['fm_cwd'] ) );
  150. $view->refresh('?m='.$_GET['m'].'&amp;p=blacklist'.'&amp;path='.$filename,0);
  151. }
  152. else
  153. {
  154. print_failure(get_lang("failed_list"));
  155. }
  156. }
  157. return;
  158. }
  159. if ( empty($dirlist) )
  160. {
  161. print_lang('empty_directory');
  162. }
  163. else
  164. {
  165. echo "<form method=POST>".
  166. "<table class='center' style='width:100%;' >\n"
  167. .show_back().
  168. "<tr>\n".
  169. "<td style='width:10px;' >\n".
  170. "<input type='checkbox' onclick='toggleChecked(this.checked)'>\n".
  171. "</td>\n".
  172. "<td align=left>\n".
  173. get_lang('filename').
  174. "\n</td>\n".
  175. "</tr>\n";
  176. $directorys = array();
  177. $files = array();
  178. $x = 0;
  179. $basedir_path = rtrim($_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['SCRIPT_NAME']),DIRECTORY_SEPARATOR);
  180. $preg_basedir_path = preg_quote($basedir_path,"/");
  181. foreach( $dirlist as $item )
  182. {
  183. # dirlist FM returns an array. Each element has 5 fields separated by the | character
  184. if($item == "." or $item == "..")
  185. continue;
  186. $filename = $item;
  187. $filepath = clean_path( $path . "/" . $filename );
  188. // Directory
  189. if(is_dir($filepath))
  190. {
  191. $directorys[$x]['filename'] = $filename;
  192. }
  193. // File
  194. else
  195. {
  196. $files[$x]['filename'] = $filename;
  197. $files[$x]['filepath'] = preg_replace("/^".$preg_basedir_path."/","",$filepath);
  198. }
  199. $x++;
  200. }
  201. foreach($directorys as $directory)
  202. {
  203. echo "<tr>\n".
  204. "<td>".
  205. "</td>".
  206. "<td align=left>".
  207. "<img class=\"viewitem\" src=\"images/folder.png\" alt=\"Directory\" /> ".
  208. "<a href=\"?m=".$_GET['m']."&amp;p=blacklist&amp;path=" . $directory['filename'] . "\">".
  209. $directory['filename'] . "</a></td></tr>\n";
  210. }
  211. $i = 0;
  212. $unchecked = array();
  213. foreach($files as $file)
  214. {
  215. $checked = in_array($file['filepath'],$current_blacklist) ? "checked='checked'" : "";
  216. echo "<tr>\n".
  217. "<td>".
  218. "<input type=checkbox name='blacklist[$i]' value='" . $file['filepath'] . "' class='item' $checked/>\n".
  219. "<input type=hidden name='folder_files[$i]' value='" . $file['filepath'] . "' />\n".
  220. "</td>".
  221. "<td align=left>";
  222. echo "<img class=\"viewitem\" src=\"images/txt.png\" alt=\"Text file\" /> ".
  223. $file['filename'] . "</td>\n".
  224. "</tr>\n";
  225. $i++;
  226. }
  227. echo "</table>\n".
  228. "<input type=submit name='save_to_blacklist' value='".get_lang('save_to_blacklist')."' />\n".
  229. "</form>\n";
  230. }
  231. echo create_back_button($_GET['m']);
  232. }
  233. ?>