lang-check.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. error_reporting(E_ERROR);
  25. chdir("..");
  26. require_once("includes/helpers.php");
  27. require_once("includes/config.inc.php");
  28. require_once("includes/lang.php");
  29. require_once("includes/functions.php");
  30. define("CONFIG_FILE", __dir__ . "/../includes/config.inc.php");
  31. require_once CONFIG_FILE;
  32. // Connect to the database server and select database.
  33. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  34. function curPageURL() {
  35. $pageURL = ( isset($_SERVER['HTTPS']) and get_true_boolean($_SERVER['HTTPS']) ) ? "https://" : "http://";
  36. $serverName = $_SERVER["SERVER_NAME"];
  37. if($serverName == "_"){
  38. $serverName = "localhost";
  39. }
  40. if ($_SERVER["SERVER_PORT"] != "80")
  41. $pageURL .= $serverName.":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  42. else
  43. $pageURL .= $serverName.$_SERVER["REQUEST_URI"];
  44. return $pageURL;
  45. }
  46. if(isset($_GET['file']) && isset($_GET['apiKey']) && isset($_GET['userId'])) // Don't allow remote URLs
  47. {
  48. // Check API key
  49. $isAdminUser = $db->isAdmin($_GET['userId']);
  50. $apiKey = $db->getApiToken($_GET['userId']);
  51. if($isAdminUser){
  52. if($apiKey == $_GET['apiKey']){
  53. if(!filter_var($_GET['file'], FILTER_VALIDATE_URL)){
  54. $file = urldecode($_GET['file']);
  55. if(file_exists(__dir__ . "/" . $file)){
  56. include(__dir__ . "/" . $file);
  57. $constants = get_defined_constants(true);
  58. echo base64_encode(serialize($constants['user']));
  59. exit();
  60. }else{
  61. echo "FILE DOESNT EXIST " . $file;
  62. exit();
  63. }
  64. }else{
  65. echo "FILE IS URL - NOT ALLOWED";
  66. exit();
  67. }
  68. }else{
  69. echo "NO MATCH";
  70. exit();
  71. }
  72. }else{
  73. echo "NOT ADMIN";
  74. exit();
  75. }
  76. }
  77. startSession();
  78. if(!isset($_SESSION['user_id']) || !$db->isAdmin($_SESSION['user_id'])){
  79. die("You must be logged in and an admin user to use this page!");
  80. }else{
  81. $apiKey = $db->getApiToken($_SESSION['user_id']);
  82. }
  83. ?>
  84. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  85. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  86. <html>
  87. <head>
  88. <title>OGP Lang Check</title>
  89. <style type='text/css'>
  90. .missing_lang {
  91. float: left;
  92. width: 100%;
  93. }
  94. .extra_lang {
  95. float: left;
  96. margin-left: 2em;
  97. }
  98. div h4 {
  99. padding: 0;
  100. margin: 0;
  101. }
  102. .clear {
  103. clear: both;
  104. }
  105. .file_vars {
  106. padding: 0;
  107. margin: 0;
  108. }
  109. .file_var h3 {
  110. margin: 0;
  111. padding: 0;
  112. }
  113. .lang {
  114. border: 1px dashed black;
  115. margin: 1em;
  116. padding: 1em;
  117. }
  118. .success {
  119. color: green;
  120. }
  121. .failure {
  122. color: red;
  123. }
  124. textarea {
  125. width: 80%;
  126. }
  127. </style>
  128. </head>
  129. <body>
  130. <h1>Open Game Panel - Language check</h1>
  131. <p>This page can be used to check what variables there are missing or there is extra compared to the
  132. default language (English).</p>
  133. <?php
  134. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  135. $error_text = "";
  136. if (get_db_error_text($db,$error_text))
  137. {
  138. print_failure($error_text);
  139. return;
  140. }
  141. chdir("lang");
  142. $COMPARISON_LANG = "English";
  143. $global_comparison_lang_files = array();
  144. $gclf_tmp = glob($COMPARISON_LANG."/*.php");
  145. // Remove the directory from filename.
  146. foreach ( $gclf_tmp as $tmp )
  147. {
  148. $array_tmp = explode("/",$tmp);
  149. array_push($global_comparison_lang_files,$array_tmp[1]);
  150. }
  151. $gclf_tmp = glob($COMPARISON_LANG."/modules/*.php");
  152. foreach ( $gclf_tmp as $tmp )
  153. {
  154. $array_tmp = explode("/",$tmp);
  155. array_push($global_comparison_lang_files,"modules/".$array_tmp[2]);
  156. }
  157. $locale_files = makefilelist("./", ".|..|.svn", true, "folders");
  158. echo "<ul id='lang_list'>";
  159. foreach ($locale_files as $lang_name)
  160. {
  161. echo "<li><a href='#$lang_name'>$lang_name</a></li>\n";
  162. }
  163. echo "</ul>";
  164. if ( isset($_SESSION['users_login']) )
  165. {
  166. $userInfo = $db->getUser($_SESSION['users_login']);
  167. if( $db->isAdmin($_SESSION['user_id']) AND isset($_SESSION['users_passwd']) AND !empty($_SESSION['users_passwd']) AND $_SESSION['users_passwd'] == $userInfo['users_passwd'])
  168. {
  169. if( !empty( $_POST ) )
  170. {
  171. foreach ($locale_files as $lang_name)
  172. {
  173. if ( $lang_name == $COMPARISON_LANG ) continue;
  174. $lang_ok = true;
  175. foreach ( $global_comparison_lang_files as $glf )
  176. {
  177. $file = $lang_name."/".$glf;
  178. if( isset( $_POST[str_replace(".", "_", $file)] ) )
  179. {
  180. echo "<h2>".$lang_name."</h2>\n";
  181. echo $file."\n Values Added.";
  182. $add_values = '<?php '."\n";
  183. foreach ( $_POST as $var => $value )
  184. {
  185. if( $var != str_replace(".", "_", $file) )
  186. $add_values .= 'define(\''.$var.'\', "'.$value.'");'."\n";
  187. }
  188. $add_values .= '?>';
  189. $fh = fopen($file, 'a') or die("can't open file");
  190. fwrite($fh, $add_values);
  191. fclose($fh);
  192. }
  193. }
  194. }
  195. }
  196. }
  197. }
  198. $current_url = curPageURL();
  199. foreach ($global_comparison_lang_files as $glf)
  200. {
  201. $file = $COMPARISON_LANG."/".$glf;
  202. $contents = file_get_contents($current_url.'?file='.$file . '&apiKey=' . $apiKey . "&userId=" . $_SESSION['user_id']);
  203. $lang[$glf] = unserialize(base64_decode($contents));
  204. }
  205. // Check every lang.
  206. foreach ($locale_files as $lang_name)
  207. {
  208. if ( $lang_name == $COMPARISON_LANG ) continue;
  209. echo "<div id='$lang_name' class='lang'><h2>".$lang_name."</h2>\n";
  210. $lang_ok = true;
  211. foreach ( $global_comparison_lang_files as $glf )
  212. {
  213. $file = $lang_name."/".$glf;
  214. if ( !is_file($file) )
  215. {
  216. echo "<h3>File $file is missing</h3>\n";
  217. $lang_ok = false;
  218. continue;
  219. }
  220. $compare_lang = array();
  221. $contents = file_get_contents($current_url . "?file=" . $file . "&apiKey=" . $apiKey . "&userId=" . $_SESSION['user_id']);
  222. $compare_lang = unserialize(base64_decode($contents));
  223. if(!is_array($compare_lang))
  224. die("Errors where found at $file");
  225. $extra_lang_vars = @array_diff_key($compare_lang,$lang[$glf]);
  226. $missing_lang_vars = @array_diff_key($lang[$glf],$compare_lang);
  227. if(isset($extra_lang_vars['']))
  228. unset($extra_lang_vars['']);
  229. // If there is nothign wrong with the file lest skip it.
  230. if ( empty($missing_lang_vars) && empty($extra_lang_vars) )
  231. continue;
  232. echo "<div class='file_vars'>\n";
  233. echo "<h3>File: $file</h3>
  234. <form action='' method='POST' name='".str_replace(".", "_", $file)."' >\n";
  235. if ( !empty($missing_lang_vars) )
  236. {
  237. echo "<div class='missing_lang'><h4>Missing lang vars:</h4>\n";
  238. echo "<br>";
  239. foreach ( $missing_lang_vars as $var => $value )
  240. {
  241. echo "<label for='$var' >$var</label><br><textarea id='$var' name='$var'>".$lang[$glf][$var]."</textarea><br>\n";
  242. }
  243. echo "<input name='".str_replace(".", "_", $file)."' type='submit' />
  244. </form>
  245. </div>\n";
  246. $lang_ok = false;
  247. }
  248. if ( !empty($extra_lang_vars) )
  249. {
  250. echo "<div class='extra_lang'><h4>Extra lang vars:</h4>\n";
  251. echo "<ul>";
  252. foreach ( $extra_lang_vars as $var => $value )
  253. {
  254. echo "<li>$var</li>";
  255. }
  256. echo "</ul></div>";
  257. $lang_ok = false;
  258. }
  259. echo "</div><div class='clear'></div>\n";
  260. }
  261. if ( $lang_ok )
  262. {
  263. echo "<p class='success'>Lang is $lang_name is OK.</p>\n";
  264. }
  265. else
  266. {
  267. echo "<p class='failure'>Errors found from lang $lang_name.</p>\n";
  268. }
  269. echo "<div class='clear'></div> </div>\n";
  270. }
  271. ?>
  272. </html>