blacklist.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <script type="text/javascript" src="js/modules/update.js"></script>
  2. <?php
  3. /*
  4. *
  5. * OGP - Open Game Panel
  6. * Copyright (C) Copyright (C) 2008 - 2013 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. $curren_blacklist = array();
  64. $blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;');
  65. if($blacklisted_files !== FALSE)
  66. {
  67. $curren_blacklist = array();
  68. foreach($blacklisted_files as $blacklisted_file)
  69. {
  70. $curren_blacklist[] = $blacklisted_file['file_path'];
  71. }
  72. }
  73. if( isset( $_POST['save_to_blacklist'] ) )
  74. {
  75. foreach($_POST['blacklist'] as $file)
  76. {
  77. $db->query("INSERT INTO `OGP_DB_PREFIXupdate_blacklist` SET file_path='$file';");
  78. }
  79. foreach($_POST['folder_files'] as $file)
  80. {
  81. if(in_array($file,$curren_blacklist))
  82. {
  83. if(!in_array($file,$_POST['blacklist']))
  84. {
  85. $db->query("DELETE FROM `OGP_DB_PREFIXupdate_blacklist` WHERE file_path='$file';");
  86. }
  87. }
  88. }
  89. $blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;');
  90. if($blacklisted_files !== FALSE)
  91. {
  92. $curren_blacklist = array();
  93. foreach($blacklisted_files as $blacklisted_file)
  94. {
  95. $curren_blacklist[] = $blacklisted_file['file_path'];
  96. }
  97. }
  98. }
  99. $curren_blacklist = array_merge($curren_blacklist,$blacklist);
  100. path_check();
  101. echo "<h2>";
  102. echo get_lang('blacklist_files');
  103. echo "</h2>";
  104. $baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
  105. $path = clean_path($baseDir."/".@$_SESSION['fm_cwd']);
  106. if (!file_exists($path))
  107. {
  108. while(!file_exists($path))
  109. {
  110. $path = dirname($path);
  111. $_SESSION['fm_cwd'] = dirname($_SESSION['fm_cwd']);
  112. if($path == clean_path($baseDir))
  113. {
  114. print_failure(get_lang_f("dir_not_found",$path));
  115. break;
  116. }
  117. }
  118. }
  119. echo "<table class='center' style='width:100%;' ><tr>\n".
  120. "<td colspan='3' ><h3>".
  121. get_lang_f('currently_viewing',$path)."</h3></td>".
  122. "</tr></table>";
  123. $dirlist = scandir($path);
  124. if (!is_array($dirlist))
  125. {
  126. if($dirlist === -1)
  127. {
  128. if ( $path != $baseDir . "/" )
  129. $view->refresh('?m='.$_GET['m'].'&amp;p=blacklist',0);
  130. else
  131. 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.');
  132. }
  133. else
  134. {
  135. if (file_exists($path))
  136. {
  137. if(strpos($path, '/') !== FALSE)
  138. {
  139. $ePath = explode('/', $path);
  140. $filename = end($ePath);
  141. }
  142. else if(strpos($path, '\\') !== FALSE)
  143. {
  144. $ePath = explode('\\', $path);
  145. $filename = end($ePath);
  146. }
  147. $_SESSION['fm_cwd'] = str_replace( "\\", "", dirname( $_SESSION['fm_cwd'] ) );
  148. $view->refresh('?m='.$_GET['m'].'&amp;p=blacklist'.'&amp;path='.$filename,0);
  149. }
  150. else
  151. {
  152. print_failure(get_lang("failed_list"));
  153. }
  154. }
  155. return;
  156. }
  157. if ( empty($dirlist) )
  158. {
  159. print_lang('empty_directory');
  160. }
  161. else
  162. {
  163. echo "<form method=POST>".
  164. "<table class='center' style='width:100%;' >\n"
  165. .show_back().
  166. "<tr>\n".
  167. "<td style='width:10px;' >\n".
  168. "<input type='checkbox' onclick='toggleChecked(this.checked)'>\n".
  169. "</td>\n".
  170. "<td align=left>\n".
  171. get_lang('filename').
  172. "\n</td>\n".
  173. "</tr>\n";
  174. $directorys = array();
  175. $files = array();
  176. $x = 0;
  177. $basedir_path = rtrim($_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['SCRIPT_NAME']),DIRECTORY_SEPARATOR);
  178. $preg_basedir_path = preg_quote($basedir_path,"/");
  179. foreach( $dirlist as $item )
  180. {
  181. # dirlist FM returns an array. Each element has 5 fields separated by the | character
  182. if($item == "." or $item == "..")
  183. continue;
  184. $filename = $item;
  185. $filepath = clean_path( $path . "/" . $filename );
  186. // Directory
  187. if(is_dir($filepath))
  188. {
  189. $directorys[$x]['filename'] = $filename;
  190. }
  191. // File
  192. else
  193. {
  194. $files[$x]['filename'] = $filename;
  195. $files[$x]['filepath'] = preg_replace("/^".$preg_basedir_path."/","",$filepath);
  196. }
  197. $x++;
  198. }
  199. foreach($directorys as $directory)
  200. {
  201. echo "<tr>\n".
  202. "<td>".
  203. "</td>".
  204. "<td align=left>".
  205. "<img class=\"viewitem\" src=\"images/folder.png\" alt=\"Directory\" /> ".
  206. "<a href=\"?m=".$_GET['m']."&amp;p=blacklist&amp;path=" . $directory['filename'] . "\">".
  207. $directory['filename'] . "</a></td></tr>\n";
  208. }
  209. $i = 0;
  210. $unchecked = array();
  211. foreach($files as $file)
  212. {
  213. $checked = in_array($file['filepath'],$curren_blacklist) ? "checked='checked'" : "";
  214. echo "<tr>\n".
  215. "<td>".
  216. "<input type=checkbox name='blacklist[$i]' value='" . $file['filepath'] . "' class='item' $checked/>\n".
  217. "<input type=hidden name='folder_files[$i]' value='" . $file['filepath'] . "' />\n".
  218. "</td>".
  219. "<td align=left>";
  220. echo "<img class=\"viewitem\" src=\"images/txt.png\" alt=\"Text file\" /> ".
  221. $file['filename'] . "</td>\n".
  222. "</tr>\n";
  223. $i++;
  224. }
  225. echo "</table>\n".
  226. "<input type=submit name='save_to_blacklist' value='".get_lang('save_to_blacklist')."' />\n".
  227. "</form>\n";
  228. }
  229. echo create_back_button($_GET['m']);
  230. }
  231. ?>