install.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. 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 mbstring Extension", "type" => "x", "value" => "mbstring" ));
  222. echo "<h3>".get_lang('checking_required_modules')."</h3>\n<table class='install'>";
  223. foreach ( $properties_to_check as $propertie ) {
  224. if ( ( $propertie['type'] === "f" && function_exists($propertie['value']) ) ||
  225. ( $propertie['type'] === "c" && class_exists($propertie['value']) ) ||
  226. ( $propertie['type'] === "x" && extension_loaded($propertie['value']) ) ) {
  227. echo "<tr><td>".$propertie['name']."</td>
  228. <td><span class='success'>".get_lang('found')."</span></td></tr>";
  229. } else {
  230. echo "<tr><td>".$propertie['name']."</td>
  231. <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. if ( $failed ) {
  294. echo "<p><a href='?'>".get_lang('refresh')."</a></p>\n";
  295. } else {
  296. echo "<p><a href='?step=1'>".get_lang('next')."</a></p>\n";
  297. }
  298. echo "</td></tr></table>\n";
  299. }
  300. else if ( $step == "1" )
  301. {
  302. echo "<table class='install'><tr><td>\n";
  303. if ( is_readable('includes/config.inc.php') )
  304. require_once "includes/config.inc.php";
  305. echo "<form name='setup' method='post' action='?step=2'>";
  306. echo "<table class='install'>\n";
  307. echo "<tr><td colspan='2'><div id=\"install-title\" style=\"margin-left:-21px; margin-top:-7px;\">".get_lang('database_settings')."</div></td></tr>
  308. <tr><td>".get_lang('database_type').":</td><td>MySQL</td></tr>
  309. <tr><td>".get_lang('database_hostname').":</td>
  310. <td><input type='text' value='";
  311. echo isset( $db_host ) ? $db_host : "localhost";
  312. echo "' name='db_host' class='textbox' /></td></tr>
  313. <tr><td>".get_lang('database_username').":</td>
  314. <td><input type='text' value='";
  315. echo isset( $db_user ) ? $db_user : "" ;
  316. echo "' name='db_user' class='textbox' /></td></tr>
  317. <tr><td>".get_lang('database_password').":</td>
  318. <td><input type='password' value='";
  319. echo isset( $db_pass ) ? $db_pass : "" ;
  320. echo "' name='db_pass' class='textbox' /></td></tr>
  321. <tr><td>".get_lang('database_name').":</td>
  322. <td><input type='text' value='";
  323. echo isset( $db_name ) ? $db_name : "" ;
  324. echo "' name='db_name' class='textbox' /></td></tr>";
  325. echo "<tr><td>".get_lang('database_prefix').":</td>
  326. <td><input type='text' value='";
  327. echo isset( $table_prefix ) ? $table_prefix : "ogp_";
  328. echo "' name='table_prefix' class='textbox' /></td></tr>";
  329. echo "</table>\n
  330. <p><input type='submit' name='next' value='".
  331. get_lang('next')."' class='button' /></p></form>";
  332. echo "<p><a href='?step=0'>".get_lang('back')."</a></p>";
  333. echo "</td></tr></table>\n";
  334. }
  335. else if ($step == "2")
  336. {
  337. echo "<table class='install'><tr><td>\n";
  338. if ( isset($_POST['db_host']) )
  339. {
  340. $db_host = stripinput($_POST['db_host']);
  341. $db_user = stripinput($_POST['db_user']);
  342. $db_pass = stripinput($_POST['db_pass']);
  343. $db_name = stripinput($_POST['db_name']);
  344. $table_prefix = stripinput($_POST['table_prefix']);
  345. $db_type = "mysql";
  346. $config = "<?php\n".
  347. "###############################################\n".
  348. "# Site configuration\n".
  349. "###############################################\n".
  350. "\$db_host=\"".$db_host."\";\n".
  351. "\$db_user=\"".$db_user."\";\n".
  352. "\$db_pass=\"".$db_pass."\";\n".
  353. "\$db_name=\"".$db_name."\";\n".
  354. "\$table_prefix=\"".$table_prefix."\";\n".
  355. "\$db_type=\"".$db_type."\";\n".
  356. "?>";
  357. $temp = @fopen("includes/config.inc.php","w");
  358. if (!@fwrite($temp, $config))
  359. {
  360. print_failure(get_lang('unable_to_write_config'));
  361. echo "<p><a href='?step=0'>".get_lang('back')."</a></p>";
  362. fclose($temp);
  363. return;
  364. }
  365. fclose($temp);
  366. }
  367. require_once "includes/config.inc.php";
  368. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  369. $error_text = "";
  370. if ( get_db_error_text($db,$error_text) )
  371. {
  372. print_failure($error_text);
  373. echo "<p><a href='?step=1'>".get_lang('back')."</a></p>";
  374. return;
  375. }
  376. $fail = false;
  377. // These belong to module manager, but they need to be created before other modules can be "installed".
  378. $result = $db->query("DROP TABLE IF EXISTS ".$table_prefix."modules");
  379. $result = $db->query("CREATE TABLE IF NOT EXISTS `".$table_prefix."modules` (
  380. `id` smallint(5) unsigned NOT NULL auto_increment,
  381. `title` varchar(100) NOT NULL default '',
  382. `folder` varchar(100) NOT NULL default '',
  383. `version` varchar(10) NOT NULL default '0',
  384. `db_version` int(10) NOT NULL default '0',
  385. PRIMARY KEY (`id`),
  386. UNIQUE KEY `folder` (`folder`)
  387. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
  388. $result = $db->query("DROP TABLE IF EXISTS ".$table_prefix."module_menus");
  389. $result = $db->query("CREATE TABLE IF NOT EXISTS `".$table_prefix."module_menus` (
  390. `module_id` int(11) NOT NULL COMMENT 'This references to modules.id',
  391. `subpage` varchar(64) NOT NULL default '',
  392. `group` varchar(32) NOT NULL,
  393. `menu_name` varchar(128) NOT NULL,
  394. `pos` INT UNSIGNED NOT NULL,
  395. PRIMARY KEY (`module_id`,`subpage`,`group`)
  396. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
  397. if (!$result) $fail = true;
  398. // Install modules.
  399. require_once("modules/modulemanager/module_handling.php");
  400. @add_lang_module('modulemanager');
  401. $modules = list_available_modules();
  402. foreach ( $modules as $module )
  403. {
  404. $fail = $fail || install_module($db,$module,FALSE) < 0;
  405. }
  406. if ( $fail ) {
  407. print_failure(get_lang('database_setup_failure'));
  408. echo "<p><a href='?step=1'>".get_lang('back')."</a></p>";
  409. echo "<p>".get_lang('unable_to_resolve').
  410. " <a href='http://www.opengamepanel.org/'>http://www.opengamepanel.org</a></p>";
  411. return;
  412. }
  413. print_success(get_lang('config_written'));
  414. print_success(get_lang('database_created'));
  415. echo "<form name='setup' method='post' action='?'>\n
  416. <input type='hidden' name='step' value='3' />";
  417. echo "<table class='install'>\n";
  418. echo "<tr><td colspan='2'><div id=\"install-title\" style=\"margin-left:-21px;\">".get_lang('admin_login_details')."</div>";
  419. echo "<p>".get_lang('admin_login_details_info')."</p></td></tr>";
  420. echo "<tr><td>".get_lang('username').
  421. ":</td><td><input type='text' name='username' maxlength='30' class='textbox' /></td></tr>";
  422. echo "<tr><td>".get_lang('password').
  423. ":</td><td><input type='password' name='password1' maxlength='20' class='textbox' /></td></tr>";
  424. echo "<tr><td>".get_lang('repeat_password').
  425. ":</td><td><input type='password' name='password2' maxlength='20' class='textbox' /></td></tr>";
  426. echo "<tr><td>".get_lang('email').
  427. ":</td><td><input type='text' name='email' maxlength='100' class='textbox' /></td></tr>";
  428. echo "</table>\n";
  429. echo "<p><input type='submit' name='next' value='".get_lang('next')."' class='button' /></p></form>\n";
  430. echo "<p><a href='?step=1'>".get_lang('back')."</a></p>";
  431. echo "</td></tr></table>\n";
  432. }
  433. else if ($step == "3") {
  434. echo "<table class='install'><tr><td>\n";
  435. require_once "includes/config.inc.php";
  436. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  437. $error = "";
  438. $username = stripinput($_POST['username']);
  439. $password1 = stripinput($_POST['password1']);
  440. $password2 = stripinput($_POST['password2']);
  441. $email = stripinput($_POST['email']);
  442. if (!preg_match("/^[-0-9A-Z_@\s]+$/i", $username))
  443. {
  444. print_failure(get_lang('invalid_username'));
  445. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  446. return;
  447. }
  448. // TODO: replace with a constant
  449. if (strlen($password1) < 6) {
  450. print_failure(get_lang_f('password_too_short', 6));
  451. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  452. return;
  453. }
  454. if (!preg_match("/^[0-9A-Z@]{6,20}$/i", $password1))
  455. {
  456. print_failure(get_lang('password_contains_invalid_characters'));
  457. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  458. return;
  459. }
  460. if ( $password1 != $password2 )
  461. {
  462. print_failure(get_lang('password_mismatch'));
  463. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  464. return;
  465. }
  466. if (!preg_match("/^[-0-9A-Z_\.]{1,50}@([-0-9A-Z_\.]+\.){1,50}([0-9A-Z]){2,4}$/i", $email))
  467. {
  468. print_failure(get_lang('invalid_email_address'));
  469. echo "<p><a href='?step=2'>".get_lang('back')."</a></p>";
  470. return;
  471. }
  472. //detect nighly builds, if not its SVN
  473. if (file_exists("version.txt")) {
  474. $file = "version.txt";
  475. $contents = file($file);
  476. $nversion = implode($contents);
  477. $nversion2 = substr($nversion ,60);
  478. $nversion2 = trim($nversion2);
  479. $site_settings = array("title"=>"Open Game Panel",
  480. "slogan" => "".get_lang('slogan')."",
  481. "ogp_version" => "$nversion2",
  482. "version_type" => "SVN",
  483. "theme" => "Revolution",
  484. "welcome_title" => "1",
  485. "welcome_title_message" => "<h0>".get_lang('default_welcome_title_message')."</h0>",
  486. "page_auto_refresh" => "1");
  487. unlink('version.txt');
  488. } else {
  489. $site_settings = array("title"=>"Open Game Panel",
  490. "slogan" => "".get_lang('slogan')."",
  491. "ogp_version" => "0",
  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. }
  498. $result = $db->setSettings($site_settings);
  499. $result = $db->addUser($username,$password1,"admin",$email);
  500. $result = updateGameConfigsPostInstall();
  501. print_success(get_lang('setup_complete'));
  502. echo "<p class='note'>".get_lang('remove_install_and_secure_config')."</p>";
  503. echo "<p class='note'><a href='index.php'>".get_lang('go_to_panel')."</a></p>";
  504. echo "</td></tr></table>\n";
  505. echo "</div>\n";
  506. }
  507. }
  508. $view->printView();
  509. ?>