lang-check.php 7.7 KB

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