index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) Copyright (C) 2008 - 2013 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. // Report all PHP errors
  25. error_reporting(E_ERROR);
  26. // Path definitions
  27. define("IMAGES", "images/");
  28. define("INCLUDES", "includes/");
  29. define("MODULES", "modules/");
  30. define("CONFIG_FILE","includes/config.inc.php");
  31. require_once("includes/functions.php");
  32. require_once("includes/helpers.php");
  33. require_once("includes/html_functions.php");
  34. // Start the session valid for opengamepanel_web only
  35. startSession();
  36. // Useful for debugging :)
  37. // echo "<p>Session ID is " . session_id() . "</p>";
  38. // echo "<p>Lifetime is: " . $cookie_lifetime . "<br />Dir is " . rtrim(dirname($_SERVER["SCRIPT_NAME"]),"/") . "/" . "<br /> Session cookie domain path is " . $session_cookie_domain_path . "<br />SSL is " . $ssl . "</p>";
  39. //Config Check
  40. $config_inc_readable = is_readable(CONFIG_FILE);
  41. if ( !$config_inc_readable && file_exists("install.php") ) {
  42. header('Location: install.php');
  43. exit();
  44. }
  45. if ( '' == file_get_contents(CONFIG_FILE) ) {
  46. header('Location: install.php');
  47. exit();
  48. }
  49. require_once CONFIG_FILE;
  50. // Connect to the database server and select database.
  51. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  52. $settings = $db->getSettings();
  53. @$GLOBALS['panel_language'] = $settings['panel_language'];
  54. // Load languages.
  55. include_once("includes/lang.php");
  56. ogpLang();
  57. require_once("includes/view.php");
  58. $view = new OGPView();
  59. $view->setCharset( lang_charset );
  60. if(isset($_GET['type']) && $_GET['type'] == 'cleared')
  61. {
  62. heading(true);
  63. $view->printView(true);
  64. }
  65. else
  66. {
  67. ogpHome();
  68. $view->printView();
  69. }
  70. function heading()
  71. {
  72. global $db,$view,$settings;
  73. $view->setCharset( lang_charset );
  74. $view->setTimeZone($settings['time_zone']);
  75. if ( !file_exists(CONFIG_FILE) )
  76. {
  77. print_failure( failed_to_read_config );
  78. $view->refresh("index.php");
  79. return;
  80. }
  81. // Start Output Buffering
  82. if( isset($settings['maintenance_mode']) && $settings['maintenance_mode'] == "1" )
  83. {
  84. if ($_SESSION['users_group'] != "admin" )
  85. {
  86. echo "<h2>".$settings['maintenance_title']."</h2>";
  87. echo "<p>".$settings['maintenance_message']."</p>";
  88. $view->setTitle("OGP: Maintenance.");
  89. echo "<p class='failure'>". logging_out_10 ."...</p>";
  90. $view->refresh("index.php", 10);
  91. session_destroy();
  92. return;
  93. }
  94. }
  95. include "includes/navig.php";
  96. if(isset($maintenance))echo $maintenance;
  97. }
  98. function ogpHome()
  99. {
  100. global $db,$view,$settings;
  101. if( isset($_GET['lang']) AND $_GET['lang'] != "-")
  102. $lang = $_GET['lang'];
  103. elseif( isset($settings['panel_language']) )
  104. $lang = $settings['panel_language'];
  105. else
  106. $lang = "English";
  107. $locale_files = makefilelist("lang/", ".|..|.svn", true, "folders");
  108. $lang_sel = "<select name='lang' onchange=\"this.form.submit();\" >\n".
  109. "<option>-</option>\n";
  110. for ($i=0;$i < count($locale_files);$i++)
  111. {
  112. $selected = ( isset( $_GET['lang'] ) AND $_GET['lang'] != "-" AND $_GET['lang'] == $locale_files[$i] ) ? "selected='selected'" : "";
  113. $lang_sel .= "<option $selected value='".$locale_files[$i]."' >".$locale_files[$i]."</option>\n";
  114. }
  115. $lang_sel .= "</select>\n";
  116. $lang_switch = ( isset( $_GET['lang'] ) AND $_GET['lang'] != "-" ) ? "&amp;lang=" . $_GET['lang'] : "";
  117. ?>
  118. %top%
  119. <div class="menu-bg">
  120. <div class="menu">
  121. <ul>
  122. <li><a href="index.php<?php echo preg_replace( "/\&amp;/", "?", $lang_switch ); ?>" <?php if (!isset($_GET['m'])) echo 'class="admin_menu_link_selected"'; else echo 'class="admin_menu_link"'; ?> target="_self" ><span class="controlpanellogin"><?php echo login_title; ?></span></a></li>
  123. <?php
  124. $menus = $db->getMenusForGroup('guest');
  125. if(!empty($menus))
  126. {
  127. foreach ( $menus as $menu )
  128. {
  129. $module = $menu['module'];
  130. if ( !empty( $menu['subpage'] ) )
  131. {
  132. $subpage = "&amp;p=".$menu['subpage'];
  133. $button = $menu['subpage'];
  134. if (isset($_GET['p']) AND $_GET['p'] == $menu['subpage'] ) $menu_link_class = 'user_menu_link_selected'; else $menu_link_class = 'user_menu_link';
  135. }
  136. else
  137. {
  138. $subpage = "";
  139. $button = $menu['module'];
  140. if (isset($_GET['m']) AND $_GET['m'] == $menu['module'] ) $menu_link_class = 'user_menu_link_selected'; else $menu_link_class = 'user_menu_link';
  141. }
  142. $button_url = "?m=".$module.$subpage.$lang_switch;
  143. if ( preg_match( '/\\_?\\_/', get_lang("$button") ) )
  144. {
  145. $button_name = $menu['menu_name'];
  146. }
  147. else
  148. {
  149. $button_name = get_lang("$button");
  150. }
  151. echo "<li><a class='".$menu_link_class."' href='".$button_url."'><span class='$button'>$button_name</span></a>
  152. </li>\n";
  153. }
  154. }
  155. ?>
  156. </ul>
  157. </div>
  158. </div>
  159. %topbody%
  160. <?php
  161. if (isset($_GET['m']))
  162. {
  163. heading();
  164. //tagged for future use...
  165. /*
  166. $postdata = "";
  167. foreach($_POST as $key =>$value)
  168. $postdata .= ",'$key': '$value'";
  169. $postdata = substr($postdata,1);
  170. $postdata = "{".$postdata."}";
  171. */
  172. }
  173. else
  174. {
  175. $default_page = $db->isModuleInstalled('dashboard') ? "m=dashboard&amp;p=dashboard" : "m=gamemanager&p=game_monitor";
  176. if ( isset($_SESSION['users_login']) )
  177. {
  178. $userInfo = $db->getUser($_SESSION['users_login']);
  179. if( isset($_SESSION['users_passwd']) AND !empty($_SESSION['users_passwd']) AND $_SESSION['users_passwd'] == $userInfo['users_passwd'])
  180. {
  181. print_success( already_logged_in_redirecting_to_dashboard .".");
  182. $view->refresh("home.php?$default_page",2);
  183. echo "%botbody%
  184. %bottom%";
  185. return;
  186. }
  187. }
  188. if ( isset($_POST['login']) )
  189. {
  190. $client_ip = getClientIPAddress();
  191. $ban_list = $db->resultQuery("SHOW TABLES LIKE 'OGP_DB_PREFIXban_list';");
  192. if ( empty( $ban_list ) )
  193. {
  194. $db->query("CREATE TABLE IF NOT EXISTS `OGP_DB_PREFIXban_list` (
  195. `client_ip` varchar(255) NOT NULL,
  196. `logging_attempts` int(11) NOT NULL DEFAULT '0',
  197. `banned_until` varchar(16) NOT NULL DEFAULT '0',
  198. PRIMARY KEY (`client_ip`)
  199. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
  200. }
  201. $banlist_info = $db->resultQuery("SELECT logging_attempts, banned_until FROM `OGP_DB_PREFIXban_list` WHERE client_ip='".$client_ip."';");
  202. $login_attempts = !$banlist_info ? 0 : $banlist_info['0']['logging_attempts'];
  203. if( !$banlist_info )
  204. $db->query("INSERT INTO `OGP_DB_PREFIXban_list` (`client_ip`) VALUES('$client_ip');");
  205. if( $banlist_info AND $banlist_info['0']['banned_until'] > 0 AND $banlist_info['0']['banned_until'] <= time() )
  206. {
  207. $db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='0', banned_until='0' WHERE client_ip='$client_ip';");
  208. $login_attempts = 0;
  209. }
  210. if( $login_attempts == $settings["login_attempts_before_banned"] )
  211. {
  212. print_failure("Banned until " . date("r",$banlist_info['0']['banned_until']));
  213. echo "%botbody%
  214. %bottom%";
  215. return;
  216. }
  217. $userInfo = $db->getUser($_POST['ulogin']);
  218. // If result matched $myusername and $mypassword, table row must be 1 row
  219. if( isset($userInfo['users_passwd']) && md5($_POST['upassword']) == $userInfo['users_passwd'])
  220. {
  221. // Handle recaptcha if enabled
  222. // But admins don't have to do this :)
  223. if($settings['recaptcha_use_login'] == "1" && !empty($settings['recaptcha_site_key']) && !empty($settings['recaptcha_secret_key']) && $userInfo['users_role'] != "admin"){
  224. $gRecaptchaResponse = sanitizeInputStr($_REQUEST['g-recaptcha-response']);
  225. $sitekey = $settings['recaptcha_site_key'];
  226. $secretkey = $settings['recaptcha_secret_key'];
  227. require_once('includes/classes/recaptcha/autoload.php');
  228. $recaptcha = new \ReCaptcha\ReCaptcha($secretkey);
  229. $resp = $recaptcha->verify($gRecaptchaResponse, $client_ip);
  230. if (empty($gRecaptchaResponse) || !$resp->isSuccess()){
  231. print_failure("Recaptcha failed. Try again!");
  232. $view->refresh("index.php",5);
  233. return;
  234. }
  235. }
  236. $_SESSION['user_id'] = $userInfo['user_id'];
  237. $_SESSION['users_login'] = $userInfo['users_login'];
  238. $_SESSION['users_passwd'] = $userInfo['users_passwd'];
  239. $_SESSION['users_group'] = $userInfo['users_role'];
  240. $_SESSION['users_lang'] = isset( $_GET['lang'] ) ? $_GET['lang'] : $userInfo['users_lang'];
  241. $_SESSION['users_theme'] = $userInfo['users_theme'];
  242. print_success( logging_in ."...");
  243. $db->logger( logging_in ."...");
  244. $db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='0', banned_until='0' WHERE client_ip = '$client_ip';");
  245. $view->refresh("home.php?$default_page",2);
  246. }
  247. else
  248. {
  249. print_failure( bad_login );
  250. $login_attempts++;
  251. if( $login_attempts == $settings["login_attempts_before_banned"] )
  252. {
  253. $banned_until = time() + 300; // Five minutes banned from the panel.
  254. $banlist_info['0']['banned_until'] = $banned_until;
  255. $db->logger( bad_login . " ( Banned until " . date("r", $banned_until) . " ) [ " . login . ": $_POST[ulogin], " . password . ": $_POST[upassword] ]" );
  256. $db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='$login_attempts', banned_until='$banned_until' WHERE client_ip='$client_ip';");
  257. print_failure("Banned until " . date("r",$banlist_info['0']['banned_until']));
  258. }
  259. else
  260. {
  261. $db->logger( bad_login . " ( $login_attempts ) [ " . login . ": $_POST[ulogin], " . password . ": $_POST[upassword] ]" );
  262. $db->query("UPDATE `OGP_DB_PREFIXban_list` SET logging_attempts='$login_attempts' WHERE client_ip='$client_ip';");
  263. $view->refresh("index.php",2);
  264. }
  265. }
  266. echo "%botbody%
  267. %bottom%";
  268. return;
  269. }
  270. ?>
  271. <!-- Made for Revolution Theme v2 -->
  272. <style type="text/css">
  273. div.main-content {
  274. background:transparent;
  275. border:none;
  276. padding:0;
  277. border-radius:0px;
  278. -moz-border-radius:0px;
  279. }
  280. </style>
  281. <table style='width:200px' align='center'>
  282. <tr style='background-color:transparent;' >
  283. <td style='background-color:transparent;' >
  284. <div class='bloc' >
  285. <h4><?php print_lang('login_title'); ?></h4>
  286. <br>
  287. <form action="index.php<?php echo preg_replace( "/\&amp;/", "?", $lang_switch ); ?>" name="login_form" method="post">
  288. <table>
  289. <tr>
  290. <td><?php print_lang('lang'); ?>:</td>
  291. <td><?php echo $lang_sel; ?></td>
  292. </tr>
  293. <tr>
  294. <td><?php print_lang('login'); ?>:</td>
  295. <td><input type="text" name="ulogin" id="ulogin" value="" size="20" /></td>
  296. </tr>
  297. <tr>
  298. <td><?php print_lang('password'); ?>:</td>
  299. <td><input type="password" name="upassword" value="" size="20" /></td>
  300. </tr>
  301. <?php
  302. if($settings['recaptcha_use_login'] == "1" && !empty($settings['recaptcha_site_key']) && !empty($settings['recaptcha_secret_key'])){
  303. ?>
  304. <tr>
  305. <td><?php print_lang('solve_captcha'); ?>:</td>
  306. <td>
  307. <script src="https://www.google.com/recaptcha/api.js"></script>
  308. <div style="display: inline-block;" class="g-recaptcha" data-sitekey="<?php echo $settings['recaptcha_site_key']; ?>"></div>
  309. </td>
  310. </tr>
  311. <?php
  312. }
  313. ?>
  314. <tr>
  315. <td><input type="submit" name="login" value="<?php print_lang('login_button'); ?>" /></td>
  316. <td><a href="?m=lostpwd<?php echo $lang_switch; ?>"><?php print_lang('lost_passwd'); ?></a></td>
  317. </tr>
  318. </table>
  319. </form>
  320. <script language="JavaScript">
  321. document.login_form.ulogin.focus();
  322. </script>
  323. <br>
  324. </div>
  325. </td>
  326. </tr>
  327. </table>
  328. <?php
  329. }
  330. ?>
  331. <div class="clear"></div>
  332. %botbody%
  333. %bottom%
  334. <?php
  335. }
  336. //
  337. ?>