index.php 12 KB

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