install.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. $optional_properties_to_check = array(
  224. array( "name" => "PHP BCMath Extension", "type" => "f", "value" => "bcadd" ),
  225. );
  226. echo "<h3>".get_lang('checking_required_modules').":</h3>\n<table class='install'>";
  227. foreach ( $properties_to_check as $propertie ) {
  228. if(preReqInstalled($propertie)){
  229. echo "<tr><td>".$propertie['name']."</td><td><span class='success'>".get_lang('found')."</span></td></tr>";
  230. }else{
  231. echo "<tr><td>".$propertie['name']."</td><td><span class='failure'>".get_lang('not_found')."</span></td></tr>";
  232. $failed = true;
  233. }
  234. }
  235. echo "<tr><td>Pear XXTEA</td><td>";
  236. $xxtea_found = false;
  237. $pear_found = false;
  238. // Lets search for XXTEA pear module from include path.
  239. $include_paths = explode(PATH_SEPARATOR, get_include_path());
  240. foreach ( $include_paths as $include_path )
  241. {
  242. if ( file_exists( $include_path."/"."Crypt/XXTEA.php") )
  243. $xxtea_found = true;
  244. // Pear always includes System.php file that should be found from the include path.
  245. if ( file_exists( $include_path."/"."System.php") )
  246. $pear_found = true;
  247. }
  248. if ( $xxtea_found )
  249. {
  250. print_success(get_lang('found'));
  251. }
  252. else
  253. {
  254. print_failure(get_lang('not_found'));
  255. echo "<p class='info'>".get_lang('pear_xxtea_info')."</p>";
  256. $failed = true;
  257. }
  258. echo "</td></tr>";
  259. echo "<tr><td>Pear</td><td>";
  260. if ( $pear_found )
  261. {
  262. print_success(get_lang('found'));
  263. }
  264. else
  265. {
  266. print_failure(get_lang('not_found'));
  267. $failed = true;
  268. }
  269. echo "</td></tr>";
  270. echo "<tr><td>file_get_contents()</td><td>";
  271. if ( is_function_available('file_get_contents') )
  272. {
  273. print_success(get_lang('found'));
  274. }
  275. else
  276. {
  277. print_failure(get_lang('not_found'));
  278. $failed = true;
  279. }
  280. echo "</td></tr>";
  281. echo "<tr><td>allow_url_fopen=on</td><td>";
  282. if ( is_function_available('allow_url_fopen') )
  283. {
  284. print_success(get_lang('found'));
  285. }
  286. else
  287. {
  288. print_failure(get_lang('not_found'));
  289. $failed = true;
  290. }
  291. echo "</td></tr>";
  292. echo "</table>\n";
  293. echo "<h3>".get_lang('checking_optional_modules').":</h3>\n<table class='install'>";
  294. foreach ( $optional_properties_to_check as $propertie ) {
  295. if(preReqInstalled($propertie)){
  296. echo "<tr><td>".$propertie['name']."</td><td><span class='success'>".get_lang('found')."</span></td></tr>";
  297. }else{
  298. echo "<tr><td>".$propertie['name']."</td><td><span class='warning'>".get_lang('not_found')."</span></td></tr>";
  299. }
  300. }
  301. echo "</table>\n";
  302. if ( $failed ) {
  303. echo "<p><a href='?'>".get_lang('refresh')."</a></p>\n";
  304. } else {
  305. echo "<p><a href='?step=1'>".get_lang('next')."</a></p>\n";
  306. }
  307. echo "</td></tr></table>\n";
  308. }
  309. else if ( $step == "1" )
  310. {
  311. echo "<table class='install'><tr><td>\n";
  312. if ( is_readable('includes/config.inc.php') )
  313. require_once "includes/config.inc.php";
  314. echo "<form name='setup' method='post' action='?step=2'>";
  315. echo "<table class='install'>\n";
  316. echo "<tr><td colspan='2'><div id=\"install-title\" style=\"margin-left:-21px; margin-top:-7px;\">".get_lang('database_settings')."</div></td></tr>
  317. <tr><td>".get_lang('database_type').":</td><td>MySQL</td></tr>
  318. <tr><td>".get_lang('database_hostname').":</td>
  319. <td><input type='text' value='";
  320. $OS = strtoupper(substr(PHP_OS, 0, 3));
  321. echo isset( $db_host ) ? $db_host : (($OS === 'WIN' || $OS === 'CYG') ? "127.0.0.1" : "localhost");
  322. echo "' name='db_host' class='textbox' /></td></tr>
  323. <tr><td>".get_lang('database_username').":</td>
  324. <td><input type='text' value='";
  325. echo isset( $db_user ) ? $db_user : "" ;
  326. echo "' name='db_user' class='textbox' /></td></tr>
  327. <tr><td>".get_lang('database_password').":</td>
  328. <td><input type='password' value='";
  329. echo isset( $db_pass ) ? $db_pass : "" ;
  330. echo "' name='db_pass' class='textbox' /></td></tr>
  331. <tr><td>".get_lang('database_name').":</td>
  332. <td><input type='text' value='";
  333. echo isset( $db_name ) ? $db_name : "" ;
  334. echo "' name='db_name' class='textbox' /></td></tr>";
  335. echo "<tr><td>".get_lang('database_prefix').":</td>
  336. <td><input type='text' value='";
  337. echo isset( $table_prefix ) ? $table_prefix : "ogp_";
  338. echo "' name='table_prefix' class='textbox' /></td></tr>";
  339. echo "</table>\n
  340. <p><input type='submit' name='next' value='".
  341. get_lang('next')."' class='button' /></p></form>";
  342. echo "<p><a href='?step=0'>".get_lang('back')."</a></p>";
  343. echo "</td></tr></table>\n";
  344. }
  345. else if ($step == "2")
  346. {
  347. echo "<table class='install'><tr><td>\n";
  348. if ( isset($_POST['db_host']) )
  349. {
  350. $db_host = stripinput($_POST['db_host']);
  351. $db_user = stripinput($_POST['db_user']);
  352. $db_pass = stripinput($_POST['db_pass']);
  353. $db_name = stripinput($_POST['db_name']);
  354. $table_prefix = stripinput($_POST['table_prefix']);
  355. $db_type = "mysql";
  356. $config = "<?php\n".
  357. "###############################################\n".
  358. "# Site configuration\n".
  359. "###############################################\n".
  360. "\$db_host=\"".$db_host."\";\n".
  361. "\$db_user=\"".$db_user."\";\n".
  362. "\$db_pass=\"".$db_pass."\";\n".
  363. "\$db_name=\"".$db_name."\";\n".
  364. "\$table_prefix=\"".$table_prefix."\";\n".
  365. "\$db_type=\"".$db_type."\";\n".
  366. "?>";
  367. $temp = @fopen("includes/config.inc.php","w");
  368. if (!@fwrite($temp, $config))
  369. {
  370. print_failure(get_lang('unable_to_write_config'));
  371. echo "<p><a href='?step=0'>".get_lang('back')."</a></p>";
  372. fclose($temp);
  373. return;
  374. }
  375. fclose($temp);
  376. }
  377. require_once "includes/config.inc.php";
  378. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  379. $error_text = "";
  380. if ( get_db_error_text($db,$error_text) )
  381. {
  382. print_failure($error_text);
  383. echo "<p><a href='?step=1'>".get_lang('back')."</a></p>";
  384. return;
  385. }
  386. $fail = false;
  387. // These belong to module manager, but they need to be created before other modules can be "installed".
  388. $result = $db->query("DROP TABLE IF EXISTS ".$table_prefix."modules");
  389. $result = $db->query("CREATE TABLE IF NOT EXISTS `".$table_prefix."modules` (
  390. `id` smallint(5) unsigned NOT NULL auto_increment,
  391. `title` varchar(100) NOT NULL default '',
  392. `folder` varchar(100) NOT NULL default '',
  393. `version` varchar(10) NOT NULL default '0',
  394. `db_version` int(10) NOT NULL default '0',
  395. PRIMARY KEY (`id`),
  396. UNIQUE KEY `folder` (`folder`)
  397. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
  398. $result = $db->query("DROP TABLE IF EXISTS ".$table_prefix."module_menus");
  399. $result = $db->query("CREATE TABLE IF NOT EXISTS `".$table_prefix."module_menus` (
  400. `module_id` int(11) NOT NULL COMMENT 'This references to modules.id',
  401. `subpage` varchar(64) NOT NULL default '',
  402. `group` varchar(32) NOT NULL,
  403. `menu_name` varchar(128) NOT NULL,
  404. `pos` INT UNSIGNED NOT NULL,
  405. PRIMARY KEY (`module_id`,`subpage`,`group`)
  406. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
  407. if (!$result) $fail = true;
  408. // Install modules.
  409. require_once("modules/modulemanager/module_handling.php");
  410. @add_lang_module('modulemanager');
  411. $modules = list_available_modules();
  412. foreach ( $modules as $module )
  413. {
  414. $fail = $fail || install_module($db,$module,FALSE) < 0;
  415. }
  416. if ( $fail ) {
  417. print_failure(get_lang('database_setup_failure'));
  418. echo "<p><a href='?step=1'>".get_lang('back')."</a></p>";
  419. echo "<p>".get_lang('unable_to_resolve').
  420. " <a href='http://www.opengamepanel.org/'>http://www.opengamepanel.org</a></p>";
  421. return;
  422. }
  423. print_success(get_lang('config_written'));
  424. print_success(get_lang('database_created'));
  425. echo "<form name='setup' method='post' action='?'>\n
  426. <input type='hidden' name='step' value='3' />";
  427. echo "<table class='install'>\n";
  428. echo "<tr><td colspan='2'><div id=\"install-title\" style=\"margin-left:-21px;\">".get_lang('admin_login_details')."</div>";
  429. echo "<p>".get_lang('admin_login_details_info')."</p></td></tr>";
  430. echo "<tr><td>".get_lang('username').
  431. ":</td><td><input type='text' name='username' maxlength='30' class='textbox' /></td></tr>";
  432. echo "<tr><td>".get_lang('password').
  433. ":</td><td><input type='password' name='password1' maxlength='20' class='textbox' /></td></tr>";
  434. echo "<tr><td>".get_lang('repeat_password').
  435. ":</td><td><input type='password' name='password2' maxlength='20' class='textbox' /></td></tr>";
  436. echo "<tr><td>".get_lang('email').
  437. ":</td><td><input type='text' name='email' maxlength='100' class='textbox' /></td></tr>";
  438. echo "</table>\n";
  439. echo "<p><input type='submit' name='next' value='".get_lang('next')."' class='button' /></p></form>\n";
  440. echo "<p><a href='?step=1'>".get_lang('back')."</a></p>";
  441. echo "</td></tr></table>\n";
  442. }
  443. else if ($step == "3") {
  444. echo "<table class='install'><tr><td>\n";
  445. require_once "includes/config.inc.php";
  446. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  447. $error = "";
  448. $username = stripinput($_POST['username']);
  449. $password1 = stripinput($_POST['password1']);
  450. $password2 = stripinput($_POST['password2']);
  451. $email = stripinput($_POST['email']);
  452. if (!preg_match("/^[-0-9A-Z_@\s]+$/i", $username))
  453. {
  454. print_failure(get_lang('invalid_username'));
  455. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  456. return;
  457. }
  458. // TODO: replace with a constant
  459. if (strlen($password1) < 6) {
  460. print_failure(get_lang_f('password_too_short', 6));
  461. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  462. return;
  463. }
  464. if (!preg_match("/^[0-9A-Z@]{6,20}$/i", $password1))
  465. {
  466. print_failure(get_lang('password_contains_invalid_characters'));
  467. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  468. return;
  469. }
  470. if ( $password1 != $password2 )
  471. {
  472. print_failure(get_lang('password_mismatch'));
  473. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  474. return;
  475. }
  476. if (!preg_match("/^[-0-9A-Z_\.]{1,50}@([-0-9A-Z_\.]+\.){1,50}([0-9A-Z]){2,4}$/i", $email))
  477. {
  478. print_failure(get_lang('invalid_email_address'));
  479. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  480. return;
  481. }
  482. //detect nighly builds, if not its SVN
  483. if (file_exists("version.txt")) {
  484. $file = "version.txt";
  485. $contents = file($file);
  486. $nversion = implode($contents);
  487. $nversion2 = substr($nversion ,60);
  488. $nversion2 = trim($nversion2);
  489. $site_settings = array("title"=>"Open Game Panel",
  490. "slogan" => "".get_lang('slogan')."",
  491. "ogp_version" => "$nversion2",
  492. "version_type" => "SVN",
  493. "theme" => "Revolution",
  494. "welcome_title" => "1",
  495. "welcome_title_message" => "<h0>".get_lang('default_welcome_title_message')."</h0>",
  496. "page_auto_refresh" => "1");
  497. unlink('version.txt');
  498. } else {
  499. $site_settings = array("title"=>"Open Game Panel",
  500. "slogan" => "".get_lang('slogan')."",
  501. "ogp_version" => "0",
  502. "version_type" => "SVN",
  503. "theme" => "Revolution",
  504. "welcome_title" => "1",
  505. "welcome_title_message" => "<h0>".get_lang('default_welcome_title_message')."</h0>",
  506. "page_auto_refresh" => "1");
  507. }
  508. $result = $db->setSettings($site_settings);
  509. $result = $db->addUser($username,$password1,"admin",$email);
  510. $result = updateGameConfigsPostInstall();
  511. print_success(get_lang('setup_complete'));
  512. echo "<p class='note'>".get_lang('remove_install_and_secure_config')."</p>";
  513. echo "<p class='note'><a href='index.php'>".get_lang('go_to_panel')."</a></p>";
  514. echo "</td></tr></table>\n";
  515. echo "</div>\n";
  516. }
  517. }
  518. $view->printView();
  519. ?>