install.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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_ALL);
  25. $_GET['action'] = true;
  26. define("MODULES", "modules/");
  27. // Strip Input Function, prevents HTML in unwanted places
  28. function stripinput($text) {
  29. if (ini_get('magic_quotes_gpc')) $text = stripslashes($text);
  30. $search = array("\"", "'", "\\", '\"', "\'", "<", ">", "&nbsp;");
  31. $replace = array("&quot;", "&#39;", "&#92;", "&quot;", "&#39;", "&lt;", "&gt;", " ");
  32. $text = str_replace($search, $replace, $text);
  33. return $text;
  34. }
  35. function is_function_available($function) {
  36. $available = true;
  37. if ( ! function_exists( $function ) )
  38. {
  39. if ( ! ini_get( $function ) )
  40. {
  41. $available = false;
  42. }
  43. else
  44. {
  45. $d = ini_get('disable_functions');
  46. $s = ini_get('suhosin.executor.func.blacklist');
  47. if ("$d$s")
  48. {
  49. $array = preg_split('/,\s*/', "$d,$s");
  50. if ( in_array( $function, $array ) )
  51. {
  52. $available = false;
  53. }
  54. }
  55. }
  56. }
  57. else
  58. {
  59. $d = ini_get('disable_functions');
  60. $s = ini_get('suhosin.executor.func.blacklist');
  61. if ("$d$s")
  62. {
  63. $array = preg_split('/,\s*/', "$d,$s");
  64. if (in_array($function, $array))
  65. {
  66. $available = false;
  67. }
  68. }
  69. }
  70. return $available;
  71. }
  72. session_start();
  73. if ( !isset($_SESSION['users_lang']) )
  74. $_SESSION['users_lang'] = "English";
  75. if ( isset($_GET['localeset']) )
  76. $_SESSION['users_lang'] = $_GET['localeset'];
  77. define("REQUIRED_PHP_VERSION", "5.3");
  78. require_once("includes/helpers.php");
  79. require_once("includes/view.php");
  80. require_once("includes/lang.php");
  81. require_once("includes/html_functions.php");
  82. require_once("includes/functions.php");
  83. ogpLang();
  84. $view = new OGPView();
  85. $view->setCharset(get_lang('lang_charset'));
  86. ?>
  87. <style>
  88. body {
  89. background-image:url("images/bg.png");
  90. }
  91. #install-content {
  92. width:650px;
  93. margin:0 auto;
  94. margin-top:30px;
  95. padding:0px 15px;
  96. background-color:#FFF;
  97. border-radius:9px;
  98. -moz-border-radius: 9px;
  99. border:1px solid #C8C8C8;
  100. overflow:hidden;
  101. }
  102. #install-title {
  103. width:680px;
  104. height:30px;
  105. background:#f5f5f5;
  106. border-top-style:solid;
  107. border-top-color:#cfcfcf;
  108. border-top-width:1px;
  109. border-bottom-style:solid;
  110. border-bottom-color:#cfcfcf;
  111. border-bottom-width:1px;
  112. margin-bottom:5px;
  113. margin-top:-1px;
  114. margin-left:-18px;
  115. margin-right:-15px;
  116. padding-top:5px;
  117. font-size: 20px;
  118. text-align: center;
  119. color: #000;
  120. font-family:"Trebuchet MS"
  121. }
  122. .lang {
  123. width:100%;
  124. text-align:center;
  125. margin-left:auto;
  126. margin-right:auto;
  127. }
  128. li {
  129. list-style-type:square;
  130. }
  131. </style>
  132. <!--[if IE]>
  133. <style>
  134. #install-content { text-align:center; width:100%; }
  135. #install-title { width:100% background:#FFF; border:none; }
  136. </style>
  137. <![endif]-->
  138. <div id="install-content">
  139. <?php
  140. install();
  141. function install() {
  142. global $db;
  143. $step = (isset($_REQUEST['step']) ? $_REQUEST['step'] : "0");
  144. if ($step == "0") {
  145. $locale_files = makefilelist("lang/", ".|..|.svn", true, "folders");
  146. $counter = 0;
  147. $columns = 3;
  148. $width = round(100/$columns);
  149. echo "<div id=\"install-title\" style=\"margin-top:-4px;\">".get_lang('install_lang')."</div>";
  150. echo "<table class='lang' style=\"margin-bottom:10px;\">\n<tr>";
  151. for ($i=0;$i < count($locale_files);$i++) {
  152. if ($counter != 0 && ($counter % $columns == 0)) echo "</tr>\n<tr>\n";
  153. echo "<td style='width:".$width."%' >";
  154. if ($locale_files[$i] == $_SESSION['users_lang']) {
  155. echo "<li><b>".$locale_files[$i]."</b></li>";
  156. } else {
  157. echo "<li><a href='?localeset=".$locale_files[$i]."'>".$locale_files[$i]."</a></li>";
  158. }
  159. echo "</td>\n";
  160. $counter++;
  161. }
  162. echo "</tr>\n</table>\n";
  163. echo "<div id=\"install-title\">".get_lang('install_welcome')."</div>";
  164. echo "<h3>".get_lang('file_permission_check').":</h3>";
  165. $failed = false;
  166. echo "<table class='install'>\n";
  167. // config.inc.php is checked seperately because we need to check first if the file
  168. // exists or not.
  169. $value = 'includes/config.inc.php';
  170. if ( !is_file($value) )
  171. {
  172. @$control = fopen($value,"w+");
  173. if($control == false){
  174. echo "<tr><td>".$value."</td><td><span class='failure'>".
  175. get_lang('create_an_empty_file')."</span></td></tr>";
  176. $failed = true;
  177. }
  178. }
  179. else if ( !is_writable($value) )
  180. {
  181. echo "<tr><td>".$value."</td><td><span class='failure'>".
  182. get_lang('write_permission_required')."</span></td></tr>";
  183. $failed = true;
  184. }
  185. else
  186. {
  187. echo "<tr><td>".$value."</td><td><span class='success'>".get_lang('OK')."</span></td></tr>";
  188. }
  189. // Check if the folder "modules/TS3Admin/templates_c" is writable
  190. $value = 'modules/TS3Admin/templates_c';
  191. if ( !is_writable($value) )
  192. {
  193. echo "<tr><td>".$value."</td><td><span class='failure'>".
  194. get_lang('write_permission_required')."</span></td></tr>";
  195. $failed = true;
  196. }
  197. else
  198. {
  199. echo "<tr><td>".$value."</td><td><span class='success'>".get_lang('OK')."</span></td></tr>";
  200. }
  201. echo "</table>";
  202. echo "<h3>".get_lang('php_version_check').":</h3>\n";
  203. echo "<table class='install'>";
  204. echo "<tr><td>PHP Version >= ".REQUIRED_PHP_VERSION."</td><td>";
  205. if ( version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, ">=") )
  206. {
  207. echo "<span class='success'>".PHP_VERSION."</span>";
  208. }
  209. else
  210. {
  211. echo "<span class='failure'>".PHP_VERSION."</span>";
  212. $failed = true;
  213. }
  214. echo "</td></tr></table>";
  215. /* TODO: how to check if pear is enabled or not? */
  216. $properties_to_check = array(
  217. array( "name" => "PHP XML-RPC module", "type" => "f", "value" => "xmlrpc_server_create" ),
  218. array( "name" => "PHP Curl module", "type" => "f", "value" => "curl_init" ),
  219. array( "name" => "PHP XML Reader", "type" => "c", "value" => "XMLReader" ),
  220. array( "name" => "PHP JSON Extension", "type" => "f", "value" => "json_decode" ),
  221. array( "name" => "PHP Zip Extension", "type" => "c", "value" => "ZipArchive" ),
  222. array( "name" => "PHP mbstring Extension", "type" => "x", "value" => "mbstring" ),
  223. array( "name" => "PHP MySQLi Extension", "type" => "f", "value" => "mysqli_connect" ));
  224. $optional_properties_to_check = array(
  225. array( "name" => "PHP BCMath Extension", "type" => "f", "value" => "bcadd" ),
  226. );
  227. echo "<h3>".get_lang('checking_required_modules').":</h3>\n<table class='install'>";
  228. foreach ( $properties_to_check as $propertie ) {
  229. if(preReqInstalled($propertie)){
  230. echo "<tr><td>".$propertie['name']."</td><td><span class='success'>".get_lang('found')."</span></td></tr>";
  231. }else{
  232. echo "<tr><td>".$propertie['name']."</td><td><span class='failure'>".get_lang('not_found')."</span></td></tr>";
  233. $failed = true;
  234. }
  235. }
  236. echo "<tr><td>Pear XXTEA</td><td>";
  237. $xxtea_found = false;
  238. $pear_found = false;
  239. // Lets search for XXTEA pear module from include path.
  240. $include_paths = explode(PATH_SEPARATOR, get_include_path());
  241. foreach ( $include_paths as $include_path )
  242. {
  243. if ( file_exists( $include_path."/"."Crypt/XXTEA.php") )
  244. $xxtea_found = true;
  245. // Pear always includes System.php file that should be found from the include path.
  246. if ( file_exists( $include_path."/"."System.php") )
  247. $pear_found = true;
  248. }
  249. if ( $xxtea_found )
  250. {
  251. print_success(get_lang('found'));
  252. }
  253. else
  254. {
  255. print_failure(get_lang('not_found'));
  256. echo "<p class='info'>".get_lang('pear_xxtea_info')."</p>";
  257. $failed = true;
  258. }
  259. echo "</td></tr>";
  260. echo "<tr><td>Pear</td><td>";
  261. if ( $pear_found )
  262. {
  263. print_success(get_lang('found'));
  264. }
  265. else
  266. {
  267. print_failure(get_lang('not_found'));
  268. $failed = true;
  269. }
  270. echo "</td></tr>";
  271. echo "<tr><td>file_get_contents()</td><td>";
  272. if ( is_function_available('file_get_contents') )
  273. {
  274. print_success(get_lang('found'));
  275. }
  276. else
  277. {
  278. print_failure(get_lang('not_found'));
  279. $failed = true;
  280. }
  281. echo "</td></tr>";
  282. echo "<tr><td>allow_url_fopen=on</td><td>";
  283. if ( is_function_available('allow_url_fopen') )
  284. {
  285. print_success(get_lang('found'));
  286. }
  287. else
  288. {
  289. print_failure(get_lang('not_found'));
  290. $failed = true;
  291. }
  292. echo "</td></tr>";
  293. echo "</table>\n";
  294. echo "<h3>".get_lang('checking_optional_modules').":</h3>\n<table class='install'>";
  295. foreach ( $optional_properties_to_check as $propertie ) {
  296. if(preReqInstalled($propertie)){
  297. echo "<tr><td>".$propertie['name']."</td><td><span class='success'>".get_lang('found')."</span></td></tr>";
  298. }else{
  299. echo "<tr><td>".$propertie['name']."</td><td><span class='warning'>".get_lang('not_found')."</span></td></tr>";
  300. }
  301. }
  302. echo "</table>\n";
  303. if ( $failed ) {
  304. echo "<p><a href='?'>".get_lang('refresh')."</a></p>\n";
  305. } else {
  306. echo "<p><a href='?step=1'>".get_lang('next')."</a></p>\n";
  307. }
  308. echo "</td></tr></table>\n";
  309. }
  310. else if ( $step == "1" )
  311. {
  312. echo "<table class='install'><tr><td>\n";
  313. if ( is_readable('includes/config.inc.php') )
  314. require_once "includes/config.inc.php";
  315. echo "<form name='setup' method='post' action='?step=2'>";
  316. echo "<table class='install'>\n";
  317. echo "<tr><td colspan='2'><div id=\"install-title\" style=\"margin-left:-21px; margin-top:-7px;\">".get_lang('database_settings')."</div></td></tr>
  318. <tr><td>".get_lang('database_type').":</td><td>MySQL</td></tr>
  319. <tr><td>".get_lang('database_hostname').":</td>
  320. <td><input type='text' value='";
  321. $OS = strtoupper(substr(PHP_OS, 0, 3));
  322. echo isset( $db_host ) ? $db_host : (($OS === 'WIN' || $OS === 'CYG') ? "127.0.0.1" : "localhost");
  323. echo "' name='db_host' class='textbox' /></td></tr>
  324. <tr><td>".get_lang('database_username').":</td>
  325. <td><input type='text' value='";
  326. echo isset( $db_user ) ? $db_user : "" ;
  327. echo "' name='db_user' class='textbox' /></td></tr>
  328. <tr><td>".get_lang('database_password').":</td>
  329. <td><input type='password' value='";
  330. echo isset( $db_pass ) ? $db_pass : "" ;
  331. echo "' name='db_pass' class='textbox' /></td></tr>
  332. <tr><td>".get_lang('database_name').":</td>
  333. <td><input type='text' value='";
  334. echo isset( $db_name ) ? $db_name : "" ;
  335. echo "' name='db_name' class='textbox' /></td></tr>";
  336. echo "<tr><td>".get_lang('database_prefix').":</td>
  337. <td><input type='text' value='";
  338. echo isset( $table_prefix ) ? $table_prefix : "ogp_";
  339. echo "' name='table_prefix' class='textbox' /></td></tr>";
  340. echo "</table>\n
  341. <p><input type='submit' name='next' value='".
  342. get_lang('next')."' class='button' /></p></form>";
  343. echo "<p><a href='?step=0'>".get_lang('back')."</a></p>";
  344. echo "</td></tr></table>\n";
  345. }
  346. else if ($step == "2")
  347. {
  348. echo "<table class='install'><tr><td>\n";
  349. if ( isset($_POST['db_host']) )
  350. {
  351. $db_host = stripinput($_POST['db_host']);
  352. $db_user = stripinput($_POST['db_user']);
  353. $db_pass = stripinput($_POST['db_pass']);
  354. $db_name = stripinput($_POST['db_name']);
  355. $table_prefix = stripinput($_POST['table_prefix']);
  356. $db_type = "mysql";
  357. $config = "<?php\n".
  358. "###############################################\n".
  359. "# Site configuration\n".
  360. "###############################################\n".
  361. "\$db_host=\"".$db_host."\";\n".
  362. "\$db_user=\"".$db_user."\";\n".
  363. "\$db_pass=\"".$db_pass."\";\n".
  364. "\$db_name=\"".$db_name."\";\n".
  365. "\$table_prefix=\"".$table_prefix."\";\n".
  366. "\$db_type=\"".$db_type."\";\n".
  367. "?>";
  368. $temp = @fopen("includes/config.inc.php","w");
  369. if (!@fwrite($temp, $config))
  370. {
  371. print_failure(get_lang('unable_to_write_config'));
  372. echo "<p><a href='?step=0'>".get_lang('back')."</a></p>";
  373. fclose($temp);
  374. return;
  375. }
  376. fclose($temp);
  377. }
  378. require_once "includes/config.inc.php";
  379. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  380. $error_text = "";
  381. if ( get_db_error_text($db,$error_text) )
  382. {
  383. print_failure($error_text);
  384. echo "<p><a href='?step=1'>".get_lang('back')."</a></p>";
  385. return;
  386. }
  387. $fail = false;
  388. // These belong to module manager, but they need to be created before other modules can be "installed".
  389. $result = $db->query("DROP TABLE IF EXISTS ".$table_prefix."modules");
  390. $result = $db->query("CREATE TABLE IF NOT EXISTS `".$table_prefix."modules` (
  391. `id` smallint(5) unsigned NOT NULL auto_increment,
  392. `title` varchar(100) NOT NULL default '',
  393. `folder` varchar(100) NOT NULL default '',
  394. `version` varchar(10) NOT NULL default '0',
  395. `db_version` int(10) NOT NULL default '0',
  396. PRIMARY KEY (`id`),
  397. UNIQUE KEY `folder` (`folder`)
  398. ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;");
  399. $result = $db->query("DROP TABLE IF EXISTS ".$table_prefix."module_menus");
  400. $result = $db->query("CREATE TABLE IF NOT EXISTS `".$table_prefix."module_menus` (
  401. `module_id` int(11) NOT NULL COMMENT 'This references to modules.id',
  402. `subpage` varchar(64) NOT NULL default '',
  403. `group` varchar(32) NOT NULL,
  404. `menu_name` varchar(128) NOT NULL,
  405. `pos` INT UNSIGNED NOT NULL,
  406. PRIMARY KEY (`module_id`,`subpage`,`group`)
  407. ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;");
  408. if (!$result) $fail = true;
  409. // Install modules.
  410. require_once("modules/modulemanager/module_handling.php");
  411. @add_lang_module('modulemanager');
  412. $modules = list_available_modules();
  413. if(in_array('modulemanager', $modules))
  414. {
  415. // Install module manager first
  416. $fail = $fail || install_module($db, 'modulemanager', FALSE) < 0;
  417. }
  418. foreach ( $modules as $module )
  419. {
  420. if($module == 'modulemanager')//Has already been installed
  421. continue;
  422. $fail = $fail || install_module($db,$module,FALSE) < 0;
  423. }
  424. if ( $fail ) {
  425. print_failure(get_lang('database_setup_failure'));
  426. echo "<p><a href='?step=1'>".get_lang('back')."</a></p>";
  427. echo "<p>".get_lang('unable_to_resolve').
  428. " <a href='http://www.opengamepanel.org/'>http://www.opengamepanel.org</a></p>";
  429. return;
  430. }
  431. print_success(get_lang('config_written'));
  432. print_success(get_lang('database_created'));
  433. echo "<form name='setup' method='post' action='?'>\n
  434. <input type='hidden' name='step' value='3' />";
  435. echo "<table class='install'>\n";
  436. echo "<tr><td colspan='2'><div id=\"install-title\" style=\"margin-left:-21px;\">".get_lang('admin_login_details')."</div>";
  437. echo "<p>".get_lang('admin_login_details_info')."</p></td></tr>";
  438. echo "<tr><td>".get_lang('username').
  439. ":</td><td><input type='text' name='username' maxlength='30' class='textbox' /></td></tr>";
  440. echo "<tr><td>".get_lang('password').
  441. ":</td><td><input type='password' name='password1' maxlength='20' class='textbox' /></td></tr>";
  442. echo "<tr><td>".get_lang('repeat_password').
  443. ":</td><td><input type='password' name='password2' maxlength='20' class='textbox' /></td></tr>";
  444. echo "<tr><td>".get_lang('email').
  445. ":</td><td><input type='text' name='email' maxlength='100' class='textbox' /></td></tr>";
  446. echo "</table>\n";
  447. echo "<p><input type='submit' name='next' value='".get_lang('next')."' class='button' /></p></form>\n";
  448. echo "<p><a href='?step=1'>".get_lang('back')."</a></p>";
  449. echo "</td></tr></table>\n";
  450. }
  451. else if ($step == "3") {
  452. echo "<table class='install'><tr><td>\n";
  453. require_once "includes/config.inc.php";
  454. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  455. $error = "";
  456. $username = stripinput($_POST['username']);
  457. $password1 = stripinput($_POST['password1']);
  458. $password2 = stripinput($_POST['password2']);
  459. $email = stripinput($_POST['email']);
  460. if (!preg_match("/^[-0-9A-Z_@\s]+$/i", $username))
  461. {
  462. print_failure(get_lang('invalid_username'));
  463. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  464. return;
  465. }
  466. // TODO: replace with a constant
  467. if (strlen($password1) < 6) {
  468. print_failure(get_lang_f('password_too_short', 6));
  469. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  470. return;
  471. }
  472. if ( $password1 != $password2 )
  473. {
  474. print_failure(get_lang('password_mismatch'));
  475. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  476. return;
  477. }
  478. if (!preg_match("/^[-0-9A-Z_\.]{1,50}@([-0-9A-Z_\.]+\.){1,50}([0-9A-Z]){2,4}$/i", $email))
  479. {
  480. print_failure(get_lang('invalid_email_address'));
  481. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  482. return;
  483. }
  484. //detect nighly builds, if not its SVN
  485. if (file_exists("version.txt")) {
  486. $file = "version.txt";
  487. $contents = file($file);
  488. $nversion = implode($contents);
  489. $nversion2 = substr($nversion ,60);
  490. $nversion2 = trim($nversion2);
  491. $site_settings = array("title"=>"Open Game Panel",
  492. "slogan" => "".get_lang('slogan')."",
  493. "ogp_version" => "$nversion2",
  494. "version_type" => "SVN",
  495. "theme" => "Revolution",
  496. "welcome_title" => "1",
  497. "welcome_title_message" => "<h0>".get_lang('default_welcome_title_message')."</h0>",
  498. "page_auto_refresh" => "1");
  499. unlink('version.txt');
  500. } else {
  501. $site_settings = array("title"=>"Open Game Panel",
  502. "slogan" => "".get_lang('slogan')."",
  503. "ogp_version" => "0",
  504. "version_type" => "SVN",
  505. "theme" => "Revolution",
  506. "welcome_title" => "1",
  507. "welcome_title_message" => "<h0>".get_lang('default_welcome_title_message')."</h0>",
  508. "page_auto_refresh" => "1");
  509. }
  510. $result = $db->setSettings($site_settings);
  511. $result = $db->addUser($username,$password1,"admin",$email);
  512. $result = updateGameConfigsPostInstall();
  513. print_success(get_lang('setup_complete'));
  514. echo "<p class='note'>".get_lang('remove_install_and_secure_config')."</p>";
  515. echo "<p class='note'><a href='index.php'>".get_lang('go_to_panel')."</a></p>";
  516. echo "</td></tr></table>\n";
  517. echo "</div>\n";
  518. }
  519. }
  520. $view->printView();
  521. ?>