install.php 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2014 Simple Machines and individual contributors
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. $GLOBALS['current_smf_version'] = '2.1 Alpha 1';
  13. $GLOBALS['db_script_version'] = '2-1';
  14. $GLOBALS['required_php_version'] = '5.1.0';
  15. // Don't have PHP support, do you?
  16. // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
  17. // Database info.
  18. $databases = array(
  19. 'mysqli' => array(
  20. 'name' => 'MySQLi',
  21. 'version' => '5.0.3',
  22. 'version_check' => 'return min(mysqli_get_server_info($db_connection), mysqli_get_client_info());',
  23. 'supported' => function_exists('mysqli_connect'),
  24. 'default_user' => 'mysql.default_user',
  25. 'default_password' => 'mysql.default_password',
  26. 'default_host' => 'mysql.default_host',
  27. 'default_port' => 'mysql.default_port',
  28. 'utf8_support' => true,
  29. 'utf8_version' => '5.0.3',
  30. 'utf8_version_check' => 'return mysqli_get_server_info($db_connection);',
  31. 'utf8_default' => true,
  32. 'utf8_required' => true,
  33. 'alter_support' => true,
  34. 'validate_prefix' => create_function('&$value', '
  35. $value = preg_replace(\'~[^A-Za-z0-9_\$]~\', \'\', $value);
  36. return true;
  37. '),
  38. ),
  39. 'mysql' => array(
  40. 'name' => 'MySQL',
  41. 'version' => '5.0.3',
  42. 'version_check' => 'return min(mysql_get_server_info(), mysql_get_client_info());',
  43. 'supported' => function_exists('mysql_connect'),
  44. 'default_user' => 'mysql.default_user',
  45. 'default_password' => 'mysql.default_password',
  46. 'default_host' => 'mysql.default_host',
  47. 'default_port' => 'mysql.default_port',
  48. 'utf8_support' => true,
  49. 'utf8_version' => '5.0.3',
  50. 'utf8_version_check' => 'return mysql_get_server_info();',
  51. 'utf8_default' => true,
  52. 'utf8_required' => true,
  53. 'alter_support' => true,
  54. 'validate_prefix' => create_function('&$value', '
  55. $value = preg_replace(\'~[^A-Za-z0-9_\$]~\', \'\', $value);
  56. return true;
  57. '),
  58. ),
  59. 'postgresql' => array(
  60. 'name' => 'PostgreSQL',
  61. 'version' => '8.0',
  62. 'function_check' => 'pg_connect',
  63. 'version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
  64. 'supported' => function_exists('pg_connect'),
  65. 'always_has_db' => true,
  66. 'utf8_default' => true,
  67. 'utf8_required' => true,
  68. 'utf8_support' => true,
  69. 'utf8_version' => '8.0',
  70. 'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
  71. 'validate_prefix' => create_function('&$value', '
  72. $value = preg_replace(\'~[^A-Za-z0-9_\$]~\', \'\', $value);
  73. // Is it reserved?
  74. if ($value == \'pg_\')
  75. return $txt[\'error_db_prefix_reserved\'];
  76. // Is the prefix numeric?
  77. if (preg_match(\'~^\d~\', $value))
  78. return $txt[\'error_db_prefix_numeric\'];
  79. return true;
  80. '),
  81. ),
  82. 'sqlite' => array(
  83. 'name' => 'SQLite',
  84. 'version' => '1',
  85. 'function_check' => 'sqlite_open',
  86. 'version_check' => 'return 1;',
  87. 'supported' => function_exists('sqlite_open'),
  88. 'always_has_db' => true,
  89. 'utf8_default' => false,
  90. 'utf8_required' => false,
  91. 'utf8_support' => false,
  92. 'validate_prefix' => create_function('&$value', '
  93. global $incontext, $txt;
  94. $value = preg_replace(\'~[^A-Za-z0-9_\$]~\', \'\', $value);
  95. // Is it reserved?
  96. if ($value == \'sqlite_\')
  97. return $txt[\'error_db_prefix_reserved\'];
  98. // Is the prefix numeric?
  99. if (preg_match(\'~^\d~\', $value))
  100. return $txt[\'error_db_prefix_numeric\'];
  101. return true;
  102. '),
  103. ),
  104. 'sqlite3' => array(
  105. 'name' => 'SQLite3',
  106. 'version' => '1',
  107. 'function_check' => 'SQLite3::version',
  108. 'version_check' => 'return 1;',
  109. 'supported' => is_callable(array('sqlite3', 'version')),
  110. 'always_has_db' => true,
  111. 'utf8_default' => true,
  112. 'utf8_required' => true,
  113. 'utf8_support' => true,
  114. 'validate_prefix' => create_function('&$value', '
  115. global $incontext, $txt;
  116. $value = preg_replace(\'~[^A-Za-z0-9_\$]~\', \'\', $value);
  117. // Is it reserved?
  118. if ($value == \'sqlite_\')
  119. return $txt[\'error_db_prefix_reserved\'];
  120. // Is the prefix numeric?
  121. if (preg_match(\'~^\d~\', $value))
  122. return $txt[\'error_db_prefix_numeric\'];
  123. return true;
  124. '),
  125. ),
  126. );
  127. // Initialize everything and load the language files.
  128. initialize_inputs();
  129. load_lang_file();
  130. // This is what we are.
  131. $installurl = $_SERVER['PHP_SELF'];
  132. // This is where SMF is.
  133. $smfsite = 'http://www.simplemachines.org/smf';
  134. // All the steps in detail.
  135. // Number,Name,Function,Progress Weight.
  136. $incontext['steps'] = array(
  137. 0 => array(1, $txt['install_step_welcome'], 'Welcome', 0),
  138. 1 => array(2, $txt['install_step_writable'], 'CheckFilesWritable', 10),
  139. 2 => array(3, $txt['install_step_databaseset'], 'DatabaseSettings', 15),
  140. 3 => array(4, $txt['install_step_forum'], 'ForumSettings', 40),
  141. 4 => array(5, $txt['install_step_databasechange'], 'DatabasePopulation', 15),
  142. 5 => array(6, $txt['install_step_admin'], 'AdminAccount', 20),
  143. 6 => array(7, $txt['install_step_delete'], 'DeleteInstall', 0),
  144. );
  145. // Default title...
  146. $incontext['page_title'] = $txt['smf_installer'];
  147. // What step are we on?
  148. $incontext['current_step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0;
  149. // Loop through all the steps doing each one as required.
  150. $incontext['overall_percent'] = 0;
  151. foreach ($incontext['steps'] as $num => $step)
  152. {
  153. if ($num >= $incontext['current_step'])
  154. {
  155. // The current weight of this step in terms of overall progress.
  156. $incontext['step_weight'] = $step[3];
  157. // Make sure we reset the skip button.
  158. $incontext['skip'] = false;
  159. // Call the step and if it returns false that means pause!
  160. if (function_exists($step[2]) && $step[2]() === false)
  161. break;
  162. elseif (function_exists($step[2]))
  163. $incontext['current_step']++;
  164. // No warnings pass on.
  165. $incontext['warning'] = '';
  166. }
  167. $incontext['overall_percent'] += $step[3];
  168. }
  169. // Actually do the template stuff.
  170. installExit();
  171. function initialize_inputs()
  172. {
  173. global $databases, $incontext;
  174. // Just so people using older versions of PHP aren't left in the cold.
  175. if (!isset($_SERVER['PHP_SELF']))
  176. $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
  177. // Turn off magic quotes runtime and enable error reporting.
  178. if (function_exists('set_magic_quotes_runtime'))
  179. @set_magic_quotes_runtime(0);
  180. error_reporting(E_ALL);
  181. // Fun. Low PHP version...
  182. if (!isset($_GET))
  183. {
  184. $GLOBALS['_GET']['step'] = 0;
  185. return;
  186. }
  187. if (!isset($_GET['obgz']))
  188. {
  189. ob_start();
  190. if (ini_get('session.save_handler') == 'user')
  191. @ini_set('session.save_handler', 'files');
  192. if (function_exists('session_start'))
  193. @session_start();
  194. }
  195. else
  196. {
  197. ob_start('ob_gzhandler');
  198. if (ini_get('session.save_handler') == 'user')
  199. @ini_set('session.save_handler', 'files');
  200. session_start();
  201. if (!headers_sent())
  202. echo '<!DOCTYPE html>
  203. <html>
  204. <head>
  205. <title>', htmlspecialchars($_GET['pass_string']), '</title>
  206. </head>
  207. <body style="background-color: #d4d4d4; margin-top: 16%; text-align: center; font-size: 16pt;">
  208. <strong>', htmlspecialchars($_GET['pass_string']), '</strong>
  209. </body>
  210. </html>';
  211. exit;
  212. }
  213. // Are we calling the backup css file?
  214. if (isset($_GET['infile_css']))
  215. {
  216. header('Content-Type: text/css');
  217. template_css();
  218. exit;
  219. }
  220. // Anybody home?
  221. if (!isset($_GET['xml']))
  222. {
  223. $incontext['remote_files_available'] = false;
  224. $test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
  225. if ($test)
  226. $incontext['remote_files_available'] = true;
  227. @fclose($test);
  228. }
  229. // Add slashes, as long as they aren't already being added.
  230. if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
  231. foreach ($_POST as $k => $v)
  232. if (strpos($k, 'password') === false)
  233. $_POST[$k] = addslashes($v);
  234. // This is really quite simple; if ?delete is on the URL, delete the installer...
  235. if (isset($_GET['delete']))
  236. {
  237. if (isset($_SESSION['installer_temp_ftp']))
  238. {
  239. $ftp = new ftp_connection($_SESSION['installer_temp_ftp']['server'], $_SESSION['installer_temp_ftp']['port'], $_SESSION['installer_temp_ftp']['username'], $_SESSION['installer_temp_ftp']['password']);
  240. $ftp->chdir($_SESSION['installer_temp_ftp']['path']);
  241. $ftp->unlink('install.php');
  242. $ftp->unlink('webinstall.php');
  243. foreach ($databases as $key => $dummy)
  244. {
  245. $type = ($key == 'mysqli') ? 'mysql' : $key;
  246. $ftp->unlink('install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
  247. }
  248. $ftp->close();
  249. unset($_SESSION['installer_temp_ftp']);
  250. }
  251. else
  252. {
  253. @unlink(__FILE__);
  254. @unlink(dirname(__FILE__) . '/webinstall.php');
  255. foreach ($databases as $key => $dummy)
  256. {
  257. $type = ($key == 'mysqli') ? 'mysql' : $key;
  258. @unlink(dirname(__FILE__) . '/install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
  259. }
  260. }
  261. // Now just redirect to a blank.png...
  262. header('Location: http://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
  263. exit;
  264. }
  265. // PHP 5 might cry if we don't do this now.
  266. if (function_exists('date_default_timezone_set'))
  267. {
  268. $server_offset = @mktime(0, 0, 0, 1, 1, 1970);
  269. date_default_timezone_set('Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600));
  270. }
  271. // Force an integer step, defaulting to 0.
  272. $_GET['step'] = (int) @$_GET['step'];
  273. }
  274. // Load the list of language files, and the current language file.
  275. function load_lang_file()
  276. {
  277. global $txt, $incontext;
  278. $incontext['detected_languages'] = array();
  279. // Make sure the languages directory actually exists.
  280. if (file_exists(dirname(__FILE__) . '/Themes/default/languages'))
  281. {
  282. // Find all the "Install" language files in the directory.
  283. $dir = dir(dirname(__FILE__) . '/Themes/default/languages');
  284. while ($entry = $dir->read())
  285. {
  286. if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
  287. $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
  288. }
  289. $dir->close();
  290. }
  291. // Didn't find any, show an error message!
  292. if (empty($incontext['detected_languages']))
  293. {
  294. // Let's not cache this message, eh?
  295. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  296. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  297. header('Cache-Control: no-cache');
  298. echo '<!DOCTYPE html>
  299. <html>
  300. <head>
  301. <title>SMF Installer: Error!</title>
  302. </head>
  303. <body style="font-family: sans-serif;"><div style="width: 600px;">
  304. <h1 style="font-size: 14pt;">A critical error has occurred.</h1>
  305. <p>This installer was unable to find the installer\'s language file or files. They should be found under:</p>
  306. <div style="margin: 1ex; font-family: monospace; font-weight: bold;">', dirname($_SERVER['PHP_SELF']) != '/' ? dirname($_SERVER['PHP_SELF']) : '', '/Themes/default/languages</div>
  307. <p>In some cases, FTP clients do not properly upload files with this many folders. Please double check to make sure you <span style="font-weight: 600;">have uploaded all the files in the distribution</span>.</p>
  308. <p>If that doesn\'t help, please make sure this install.php file is in the same place as the Themes folder.</p>
  309. <p>If you continue to get this error message, feel free to <a href="http://support.simplemachines.org/">look to us for support</a>.</p>
  310. </div></body>
  311. </html>';
  312. die;
  313. }
  314. // Override the language file?
  315. if (isset($_GET['lang_file']))
  316. $_SESSION['installer_temp_lang'] = $_GET['lang_file'];
  317. elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
  318. $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
  319. // Make sure it exists, if it doesn't reset it.
  320. if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
  321. {
  322. // Use the first one...
  323. list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
  324. // If we have english and some other language, use the other language. We Americans hate english :P.
  325. if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
  326. list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
  327. }
  328. // And now include the actual language file itself.
  329. require_once(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']);
  330. }
  331. // This handy function loads some settings and the like.
  332. function load_database()
  333. {
  334. global $db_prefix, $db_connection, $db_character_set, $sourcedir, $language;
  335. global $smcFunc, $mbname, $scripturl, $boardurl, $modSettings, $db_type, $db_name, $db_user, $db_persist, $db_port;
  336. if (empty($sourcedir))
  337. $sourcedir = dirname(__FILE__) . '/Sources';
  338. // Need this to check whether we need the database password.
  339. require(dirname(__FILE__) . '/Settings.php');
  340. if (!defined('SMF'))
  341. define('SMF', 1);
  342. if (empty($smcFunc))
  343. $smcFunc = array();
  344. $modSettings['disableQueryCheck'] = true;
  345. // Connect the database.
  346. if (!$db_connection)
  347. {
  348. require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
  349. if (version_compare(PHP_VERSION, '5', '<'))
  350. require_once($sourcedir . '/Subs-Compat.php');
  351. $db_options = array('persist' => $db_persist);
  352. $port = '';
  353. // Figure out the port...
  354. if (!empty($_POST['db_port']))
  355. {
  356. if ($db_type == 'mysql' || $db_type == 'mysqli')
  357. {
  358. $port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
  359. }
  360. elseif ($db_type == 'postgresql')
  361. {
  362. // PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
  363. $port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
  364. }
  365. }
  366. if (!empty($port))
  367. $db_options['port'] = $port;
  368. if (!$db_connection)
  369. $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
  370. }
  371. }
  372. // This is called upon exiting the installer, for template etc.
  373. function installExit($fallThrough = false)
  374. {
  375. global $incontext, $installurl, $txt;
  376. // Send character set.
  377. header('Content-Type: text/html; charset=' . (isset($txt['lang_character_set']) ? $txt['lang_character_set'] : 'ISO-8859-1'));
  378. // We usually dump our templates out.
  379. if (!$fallThrough)
  380. {
  381. // The top install bit.
  382. template_install_above();
  383. // Call the template.
  384. if (isset($incontext['sub_template']))
  385. {
  386. $incontext['form_url'] = $installurl . '?step=' . $incontext['current_step'];
  387. call_user_func('template_' . $incontext['sub_template']);
  388. }
  389. // @todo REMOVE THIS!!
  390. else
  391. {
  392. if (function_exists('doStep' . $_GET['step']))
  393. call_user_func('doStep' . $_GET['step']);
  394. }
  395. // Show the footer.
  396. template_install_below();
  397. }
  398. // Bang - gone!
  399. die();
  400. }
  401. function Welcome()
  402. {
  403. global $incontext, $txt, $databases, $installurl;
  404. $incontext['page_title'] = $txt['install_welcome'];
  405. $incontext['sub_template'] = 'welcome_message';
  406. // Done the submission?
  407. if (isset($_POST['contbutt']))
  408. return true;
  409. // Check the PHP version.
  410. if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
  411. {
  412. $incontext['warning'] = $txt['error_php_too_low'];
  413. }
  414. // See if we think they have already installed it?
  415. if (is_readable(dirname(__FILE__) . '/Settings.php'))
  416. {
  417. $probably_installed = 0;
  418. foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
  419. {
  420. if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
  421. $probably_installed++;
  422. if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
  423. $probably_installed++;
  424. }
  425. if ($probably_installed == 2)
  426. $incontext['warning'] = $txt['error_already_installed'];
  427. }
  428. // Is some database support even compiled in?
  429. $incontext['supported_databases'] = array();
  430. foreach ($databases as $key => $db)
  431. {
  432. if ($db['supported'])
  433. {
  434. $type = ($key == 'mysqli') ? 'mysql' : $key;
  435. if (!file_exists(dirname(__FILE__) . '/install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql'))
  436. {
  437. $databases[$key]['supported'] = false;
  438. $notFoundSQLFile = true;
  439. $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
  440. }
  441. else
  442. {
  443. $db_type = $key;
  444. $incontext['supported_databases'][] = $db;
  445. }
  446. }
  447. }
  448. if (empty($incontext['supported_databases']))
  449. $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
  450. // How about session support? Some crazy sysadmin remove it?
  451. elseif (!function_exists('session_start'))
  452. $error = 'error_session_missing';
  453. // Make sure they uploaded all the files.
  454. elseif (!file_exists(dirname(__FILE__) . '/index.php'))
  455. $error = 'error_missing_files';
  456. // Very simple check on the session.save_path for Windows.
  457. // @todo Move this down later if they don't use database-driven sessions?
  458. elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
  459. $error = 'error_session_save_path';
  460. // Since each of the three messages would look the same, anyway...
  461. if (isset($error))
  462. $incontext['error'] = $txt[$error];
  463. // Mod_security blocks everything that smells funny. Let SMF handle security.
  464. if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
  465. $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
  466. return false;
  467. }
  468. function CheckFilesWritable()
  469. {
  470. global $txt, $incontext;
  471. $incontext['page_title'] = $txt['ftp_checking_writable'];
  472. $incontext['sub_template'] = 'chmod_files';
  473. $writable_files = array(
  474. 'attachments',
  475. 'avatars',
  476. 'custom_avatar',
  477. 'cache',
  478. 'Packages',
  479. 'Smileys',
  480. 'Themes',
  481. 'agreement.txt',
  482. 'Settings.php',
  483. 'Settings_bak.php'
  484. );
  485. foreach ($incontext['detected_languages'] as $lang => $temp)
  486. $extra_files[] = 'Themes/default/languages/' . $lang;
  487. // With mod_security installed, we could attempt to fix it with .htaccess.
  488. if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
  489. $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
  490. $failed_files = array();
  491. // On linux, it's easy - just use is_writable!
  492. if (substr(__FILE__, 1, 2) != ':\\')
  493. {
  494. foreach ($writable_files as $file)
  495. {
  496. if (!is_writable(dirname(__FILE__) . '/' . $file))
  497. {
  498. @chmod(dirname(__FILE__) . '/' . $file, 0755);
  499. // Well, 755 hopefully worked... if not, try 777.
  500. if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
  501. $failed_files[] = $file;
  502. }
  503. }
  504. foreach ($extra_files as $file)
  505. @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
  506. }
  507. // Windows is trickier. Let's try opening for r+...
  508. else
  509. {
  510. foreach ($writable_files as $file)
  511. {
  512. // Folders can't be opened for write... but the index.php in them can ;)
  513. if (is_dir(dirname(__FILE__) . '/' . $file))
  514. $file .= '/index.php';
  515. // Funny enough, chmod actually does do something on windows - it removes the read only attribute.
  516. @chmod(dirname(__FILE__) . '/' . $file, 0777);
  517. $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
  518. // Hmm, okay, try just for write in that case...
  519. if (!is_resource($fp))
  520. $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
  521. if (!is_resource($fp))
  522. $failed_files[] = $file;
  523. @fclose($fp);
  524. }
  525. foreach ($extra_files as $file)
  526. @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
  527. }
  528. $failure = count($failed_files) >= 1;
  529. if (!isset($_SERVER))
  530. return !$failure;
  531. // Put the list into context.
  532. $incontext['failed_files'] = $failed_files;
  533. // It's not going to be possible to use FTP on windows to solve the problem...
  534. if ($failure && substr(__FILE__, 1, 2) == ':\\')
  535. {
  536. $incontext['error'] = $txt['error_windows_chmod'] . '
  537. <ul style="margin: 2.5ex; font-family: monospace;">
  538. <li>' . implode('</li>
  539. <li>', $failed_files) . '</li>
  540. </ul>';
  541. return false;
  542. }
  543. // We're going to have to use... FTP!
  544. elseif ($failure)
  545. {
  546. // Load any session data we might have...
  547. if (!isset($_POST['ftp_username']) && isset($_SESSION['installer_temp_ftp']))
  548. {
  549. $_POST['ftp_server'] = $_SESSION['installer_temp_ftp']['server'];
  550. $_POST['ftp_port'] = $_SESSION['installer_temp_ftp']['port'];
  551. $_POST['ftp_username'] = $_SESSION['installer_temp_ftp']['username'];
  552. $_POST['ftp_password'] = $_SESSION['installer_temp_ftp']['password'];
  553. $_POST['ftp_path'] = $_SESSION['installer_temp_ftp']['path'];
  554. }
  555. $incontext['ftp_errors'] = array();
  556. if (isset($_POST['ftp_username']))
  557. {
  558. $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
  559. if ($ftp->error === false)
  560. {
  561. // Try it without /home/abc just in case they messed up.
  562. if (!$ftp->chdir($_POST['ftp_path']))
  563. {
  564. $incontext['ftp_errors'][] = $ftp->last_message;
  565. $ftp->chdir(preg_replace('~^/home[2]?/[^/]+?~', '', $_POST['ftp_path']));
  566. }
  567. }
  568. }
  569. if (!isset($ftp) || $ftp->error !== false)
  570. {
  571. if (!isset($ftp))
  572. $ftp = new ftp_connection(null);
  573. // Save the error so we can mess with listing...
  574. elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
  575. $incontext['ftp_errors'][] = $ftp->last_message;
  576. list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
  577. if (empty($_POST['ftp_path']) && $found_path)
  578. $_POST['ftp_path'] = $detect_path;
  579. if (!isset($_POST['ftp_username']))
  580. $_POST['ftp_username'] = $username;
  581. // Set the username etc, into context.
  582. $incontext['ftp'] = array(
  583. 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : 'localhost',
  584. 'port' => isset($_POST['ftp_port']) ? $_POST['ftp_port'] : '21',
  585. 'username' => isset($_POST['ftp_username']) ? $_POST['ftp_username'] : '',
  586. 'path' => isset($_POST['ftp_path']) ? $_POST['ftp_path'] : '/',
  587. 'path_msg' => !empty($found_path) ? $txt['ftp_path_found_info'] : $txt['ftp_path_info'],
  588. );
  589. return false;
  590. }
  591. else
  592. {
  593. $_SESSION['installer_temp_ftp'] = array(
  594. 'server' => $_POST['ftp_server'],
  595. 'port' => $_POST['ftp_port'],
  596. 'username' => $_POST['ftp_username'],
  597. 'password' => $_POST['ftp_password'],
  598. 'path' => $_POST['ftp_path']
  599. );
  600. $failed_files_updated = array();
  601. foreach ($failed_files as $file)
  602. {
  603. if (!is_writable(dirname(__FILE__) . '/' . $file))
  604. $ftp->chmod($file, 0755);
  605. if (!is_writable(dirname(__FILE__) . '/' . $file))
  606. $ftp->chmod($file, 0777);
  607. if (!is_writable(dirname(__FILE__) . '/' . $file))
  608. {
  609. $failed_files_updated[] = $file;
  610. $incontext['ftp_errors'][] = rtrim($ftp->last_message) . ' -> ' . $file . "\n";
  611. }
  612. }
  613. $ftp->close();
  614. // Are there any errors left?
  615. if (count($failed_files_updated) >= 1)
  616. {
  617. // Guess there are...
  618. $incontext['failed_files'] = $failed_files_updated;
  619. // Set the username etc, into context.
  620. $incontext['ftp'] = $_SESSION['installer_temp_ftp'] += array(
  621. 'path_msg' => $txt['ftp_path_info'],
  622. );
  623. return false;
  624. }
  625. }
  626. }
  627. return true;
  628. }
  629. function DatabaseSettings()
  630. {
  631. global $txt, $databases, $incontext, $smcFunc, $sourcedir;
  632. $incontext['sub_template'] = 'database_settings';
  633. $incontext['page_title'] = $txt['db_settings'];
  634. $incontext['continue'] = 1;
  635. // Set up the defaults.
  636. $incontext['db']['server'] = 'localhost';
  637. $incontext['db']['user'] = '';
  638. $incontext['db']['name'] = '';
  639. $incontext['db']['pass'] = '';
  640. $incontext['db']['type'] = '';
  641. $incontext['supported_databases'] = array();
  642. $foundOne = false;
  643. foreach ($databases as $key => $db)
  644. {
  645. // Override with the defaults for this DB if appropriate.
  646. if ($db['supported'])
  647. {
  648. $incontext['supported_databases'][$key] = $db;
  649. if (!$foundOne)
  650. {
  651. if (isset($db['default_host']))
  652. $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
  653. if (isset($db['default_user']))
  654. {
  655. $incontext['db']['user'] = ini_get($db['default_user']);
  656. $incontext['db']['name'] = ini_get($db['default_user']);
  657. }
  658. if (isset($db['default_password']))
  659. $incontext['db']['pass'] = ini_get($db['default_password']);
  660. // For simplicity and less confusion, leave the port blank by default
  661. $incontext['db']['port'] = '';
  662. $incontext['db']['type'] = $key;
  663. $foundOne = true;
  664. }
  665. }
  666. }
  667. // Override for repost.
  668. if (isset($_POST['db_user']))
  669. {
  670. $incontext['db']['user'] = $_POST['db_user'];
  671. $incontext['db']['name'] = ($_POST['db_type'] == 'sqlite' || $_POST['db_type'] == 'sqlite3') && isset($_POST['db_filename']) ? $_POST['db_filename'] : $_POST['db_name'];
  672. $incontext['db']['server'] = $_POST['db_server'];
  673. $incontext['db']['prefix'] = $_POST['db_prefix'];
  674. if (!empty($_POST['db_port']))
  675. $incontext['db']['port'] = $_POST['db_port'];
  676. }
  677. else
  678. {
  679. $incontext['db']['prefix'] = 'smf_';
  680. }
  681. // Are we submitting?
  682. if (isset($_POST['db_type']))
  683. {
  684. if (isset($_POST['db_filename']))
  685. {
  686. // You better enter enter a database name for SQLite.
  687. if (trim($_POST['db_filename']) == '')
  688. {
  689. $incontext['error'] = $txt['error_db_filename'];
  690. return false;
  691. }
  692. // Duplicate name in the same dir? Can't do that with SQLite. Weird things happen.
  693. if (file_exists($_POST['db_filename'] . (substr($_POST['db_filename'], -3) != '.db' ? '.db' : '')))
  694. {
  695. $incontext['error'] = $txt['error_db_filename_exists'];
  696. return false;
  697. }
  698. }
  699. // What type are they trying?
  700. $db_type = preg_replace('~[^A-Za-z0-9]~', '', $_POST['db_type']);
  701. $db_prefix = $_POST['db_prefix'];
  702. // Validate the prefix.
  703. $valid_prefix = $databases[$db_type]['validate_prefix']($db_prefix);
  704. if ($valid_prefix !== true)
  705. {
  706. $incontext['error'] = $valid_prefix;
  707. return false;
  708. }
  709. // Take care of these variables...
  710. $vars = array(
  711. 'db_type' => $db_type,
  712. 'db_name' => ($_POST['db_type'] == 'sqlite' || $_POST['db_type'] == 'sqlite3') && isset($_POST['db_filename']) ? $_POST['db_filename'] : $_POST['db_name'],
  713. 'db_user' => $_POST['db_user'],
  714. 'db_passwd' => isset($_POST['db_passwd']) ? $_POST['db_passwd'] : '',
  715. 'db_server' => $_POST['db_server'],
  716. 'db_prefix' => $db_prefix,
  717. // The cookiename is special; we want it to be the same if it ever needs to be reinstalled with the same info.
  718. 'cookiename' => 'SMFCookie' . abs(crc32($_POST['db_name'] . preg_replace('~[^A-Za-z0-9_$]~', '', $_POST['db_prefix'])) % 1000),
  719. );
  720. // Only set the port if we're not using the default
  721. if (!empty($_POST['db_port']))
  722. {
  723. // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
  724. if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
  725. $vars['db_port'] == (int) $_POST['db_port'];
  726. elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
  727. $vars['db_port'] == (int) $_POST['db_port'];
  728. }
  729. // God I hope it saved!
  730. if (!updateSettingsFile($vars) && substr(__FILE__, 1, 2) == ':\\')
  731. {
  732. $incontext['error'] = $txt['error_windows_chmod'];
  733. return false;
  734. }
  735. // Make sure it works.
  736. require(dirname(__FILE__) . '/Settings.php');
  737. if (empty($sourcedir))
  738. $sourcedir = dirname(__FILE__) . '/Sources';
  739. // Better find the database file!
  740. if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
  741. {
  742. $incontext['error'] = sprintf($txt['error_db_file'], 'Subs-Db-' . $db_type . '.php');
  743. return false;
  744. }
  745. // Now include it for database functions!
  746. define('SMF', 1);
  747. $modSettings['disableQueryCheck'] = true;
  748. if (empty($smcFunc))
  749. $smcFunc = array();
  750. require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
  751. // What - running PHP4? The shame!
  752. if (version_compare(PHP_VERSION, '5', '<'))
  753. require_once($sourcedir . '/Subs-Compat.php');
  754. // Attempt a connection.
  755. $needsDB = !empty($databases[$db_type]['always_has_db']);
  756. $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true, 'dont_select_db' => !$needsDB));
  757. // No dice? Let's try adding the prefix they specified, just in case they misread the instructions ;)
  758. if ($db_connection == null)
  759. {
  760. $db_error = @$smcFunc['db_error']();
  761. $db_connection = smf_db_initiate($db_server, $db_name, $_POST['db_prefix'] . $db_user, $db_passwd, $db_prefix, array('non_fatal' => true, 'dont_select_db' => !$needsDB));
  762. if ($db_connection != null)
  763. {
  764. $db_user = $_POST['db_prefix'] . $db_user;
  765. updateSettingsFile(array('db_user' => $db_user));
  766. }
  767. }
  768. // Still no connection? Big fat error message :P.
  769. if (!$db_connection)
  770. {
  771. $incontext['error'] = $txt['error_db_connect'] . '<div style="margin: 2.5ex; font-family: monospace;"><strong>' . $db_error . '</strong></div>';
  772. return false;
  773. }
  774. // Do they meet the install requirements?
  775. // @todo Old client, new server?
  776. if (version_compare($databases[$db_type]['version'], preg_replace('~^\D*|\-.+?$~', '', eval($databases[$db_type]['version_check']))) > 0)
  777. {
  778. $incontext['error'] = $txt['error_db_too_low'];
  779. return false;
  780. }
  781. // Let's try that database on for size... assuming we haven't already lost the opportunity.
  782. if ($db_name != '' && !$needsDB)
  783. {
  784. $smcFunc['db_query']('', "
  785. CREATE DATABASE IF NOT EXISTS `$db_name`",
  786. array(
  787. 'security_override' => true,
  788. 'db_error_skip' => true,
  789. ),
  790. $db_connection
  791. );
  792. // Okay, let's try the prefix if it didn't work...
  793. if (!$smcFunc['db_select_db']($db_name, $db_connection) && $db_name != '')
  794. {
  795. $smcFunc['db_query']('', "
  796. CREATE DATABASE IF NOT EXISTS `$_POST[db_prefix]$db_name`",
  797. array(
  798. 'security_override' => true,
  799. 'db_error_skip' => true,
  800. ),
  801. $db_connection
  802. );
  803. if ($smcFunc['db_select_db']($_POST['db_prefix'] . $db_name, $db_connection))
  804. {
  805. $db_name = $_POST['db_prefix'] . $db_name;
  806. updateSettingsFile(array('db_name' => $db_name));
  807. }
  808. }
  809. // Okay, now let's try to connect...
  810. if (!$smcFunc['db_select_db']($db_name, $db_connection))
  811. {
  812. $incontext['error'] = sprintf($txt['error_db_database'], $db_name);
  813. return false;
  814. }
  815. }
  816. return true;
  817. }
  818. return false;
  819. }
  820. // Let's start with basic forum type settings.
  821. function ForumSettings()
  822. {
  823. global $txt, $incontext, $databases, $smcFunc, $db_connection, $db_type, $boardurl;
  824. $incontext['sub_template'] = 'forum_settings';
  825. $incontext['page_title'] = $txt['install_settings'];
  826. // Let's see if we got the database type correct.
  827. if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
  828. $db_type = $_POST['db_type'];
  829. // Else we'd better be able to get the connection.
  830. else
  831. load_database();
  832. $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
  833. // What host and port are we on?
  834. $host = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
  835. // Now, to put what we've learned together... and add a path.
  836. $incontext['detected_url'] = 'http' . (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
  837. // Check if the database sessions will even work.
  838. $incontext['test_dbsession'] = (ini_get('session.auto_start') != 1);
  839. $incontext['utf8_default'] = $databases[$db_type]['utf8_default'];
  840. $incontext['utf8_required'] = $databases[$db_type]['utf8_required'];
  841. $incontext['continue'] = 1;
  842. // Submitting?
  843. if (isset($_POST['boardurl']))
  844. {
  845. if (substr($_POST['boardurl'], -10) == '/index.php')
  846. $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
  847. elseif (substr($_POST['boardurl'], -1) == '/')
  848. $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
  849. if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
  850. $_POST['boardurl'] = 'http://' . $_POST['boardurl'];
  851. // Save these variables.
  852. $vars = array(
  853. 'boardurl' => $_POST['boardurl'],
  854. 'boarddir' => addslashes(dirname(__FILE__)),
  855. 'sourcedir' => addslashes(dirname(__FILE__)) . '/Sources',
  856. 'cachedir' => addslashes(dirname(__FILE__)) . '/cache',
  857. 'mbname' => strtr($_POST['mbname'], array('\"' => '"')),
  858. 'language' => substr($_SESSION['installer_temp_lang'], 8, -4),
  859. );
  860. // Must save!
  861. if (!updateSettingsFile($vars) && substr(__FILE__, 1, 2) == ':\\')
  862. {
  863. $incontext['error'] = $txt['error_windows_chmod'];
  864. return false;
  865. }
  866. // Make sure it works.
  867. require(dirname(__FILE__) . '/Settings.php');
  868. // UTF-8 requires a setting to override the language charset.
  869. if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
  870. {
  871. if (!empty($databases[$db_type]['utf8_version_check']) && version_compare($databases[$db_type]['utf8_version'], preg_replace('~\-.+?$~', '', eval($databases[$db_type]['utf8_version_check'])), '>'))
  872. {
  873. $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
  874. return false;
  875. }
  876. else
  877. // Set the character set here.
  878. updateSettingsFile(array('db_character_set' => 'utf8'));
  879. }
  880. // Good, skip on.
  881. return true;
  882. }
  883. return false;
  884. }
  885. // Step one: Do the SQL thang.
  886. function DatabasePopulation()
  887. {
  888. global $db_character_set, $txt, $db_connection, $smcFunc, $databases, $modSettings, $db_type, $sourcedir, $db_prefix, $incontext, $db_name, $boardurl;
  889. $incontext['sub_template'] = 'populate_database';
  890. $incontext['page_title'] = $txt['db_populate'];
  891. $incontext['continue'] = 1;
  892. // Already done?
  893. if (isset($_POST['pop_done']))
  894. return true;
  895. // Reload settings.
  896. require(dirname(__FILE__) . '/Settings.php');
  897. load_database();
  898. // Before running any of the queries, let's make sure another version isn't already installed.
  899. $result = $smcFunc['db_query']('', '
  900. SELECT variable, value
  901. FROM {db_prefix}settings',
  902. array(
  903. 'db_error_skip' => true,
  904. )
  905. );
  906. $modSettings = array();
  907. if ($result !== false)
  908. {
  909. while ($row = $smcFunc['db_fetch_assoc']($result))
  910. $modSettings[$row['variable']] = $row['value'];
  911. $smcFunc['db_free_result']($result);
  912. // Do they match? If so, this is just a refresh so charge on!
  913. if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] != $GLOBALS['current_smf_version'])
  914. {
  915. $incontext['error'] = $txt['error_versions_do_not_match'];
  916. return false;
  917. }
  918. }
  919. $modSettings['disableQueryCheck'] = true;
  920. // If doing UTF8, select it. PostgreSQL requires passing it as a string...
  921. if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
  922. $smcFunc['db_query']('', '
  923. SET NAMES {'. ($db_type == 'postgresql' ? 'string' : 'raw') . ':utf8}',
  924. array(
  925. 'db_error_skip' => true,
  926. 'utf8' => 'utf8',
  927. )
  928. );
  929. $replaces = array(
  930. '{$db_prefix}' => $db_prefix,
  931. '{$boarddir}' => $smcFunc['db_escape_string'](dirname(__FILE__)),
  932. '{$boardurl}' => $boardurl,
  933. '{$enableCompressedOutput}' => isset($_POST['compress']) ? '1' : '0',
  934. '{$databaseSession_enable}' => isset($_POST['dbsession']) ? '1' : '0',
  935. '{$smf_version}' => $GLOBALS['current_smf_version'],
  936. '{$current_time}' => time(),
  937. '{$sched_task_offset}' => 82800 + mt_rand(0, 86399),
  938. '{$registration_method}' => isset($_POST['reg_mode']) ? $_POST['reg_mode'] : 0,
  939. );
  940. foreach ($txt as $key => $value)
  941. {
  942. if (substr($key, 0, 8) == 'default_')
  943. $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
  944. }
  945. $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
  946. // If the UTF-8 setting was enabled, add it to the table definitions.
  947. if (!empty($databases[$db_type]['utf8_support']) && (!empty($databases[$db_type]['utf8_required']) || isset($_POST['utf8'])))
  948. $replaces[') ENGINE=MyISAM;'] = ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;';
  949. // Read in the SQL. Turn this on and that off... internationalize... etc.
  950. $type = ($db_type == 'mysqli') ? 'mysql' : $db_type;
  951. $sql_lines = explode("\n", strtr(implode(' ', file(dirname(__FILE__) . '/install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql')), $replaces));
  952. // Execute the SQL.
  953. $current_statement = '';
  954. $exists = array();
  955. $incontext['failures'] = array();
  956. $incontext['sql_results'] = array(
  957. 'tables' => 0,
  958. 'inserts' => 0,
  959. 'table_dups' => 0,
  960. 'insert_dups' => 0,
  961. );
  962. foreach ($sql_lines as $count => $line)
  963. {
  964. // No comments allowed!
  965. if (substr(trim($line), 0, 1) != '#')
  966. $current_statement .= "\n" . rtrim($line);
  967. // Is this the end of the query string?
  968. if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
  969. continue;
  970. // Does this table already exist? If so, don't insert more data into it!
  971. if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
  972. {
  973. $incontext['sql_results']['insert_dups']++;
  974. $current_statement = '';
  975. continue;
  976. }
  977. if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
  978. {
  979. // Use the appropriate function based on the DB type
  980. if ($db_type == 'mysql' || $db_type =='mysqli')
  981. $db_errorno = $db_type . '_errno';
  982. // Error 1050: Table already exists!
  983. // @todo Needs to be made better!
  984. if ((($db_type != 'mysql' && $db_type != 'mysqli') || $db_errorno($db_connection) == 1050) && preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
  985. {
  986. $exists[] = $match[1];
  987. $incontext['sql_results']['table_dups']++;
  988. }
  989. // Don't error on duplicate indexes (or duplicate operators in PostgreSQL.)
  990. elseif (!preg_match('~^\s*CREATE( UNIQUE)? INDEX ([^\n\r]+?)~', $current_statement, $match) && !($db_type == 'postgresql' && preg_match('~^\s*CREATE OPERATOR (^\n\r]+?)~', $current_statement, $match)))
  991. {
  992. // MySQLi requires a connection object. It's optional with MySQL, Postgres and sqlite
  993. $incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
  994. }
  995. }
  996. else
  997. {
  998. if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
  999. $incontext['sql_results']['tables']++;
  1000. else
  1001. {
  1002. preg_match_all('~\)[,;]~', $current_statement, $matches);
  1003. if (!empty($matches[0]))
  1004. $incontext['sql_results']['inserts'] += count($matches[0]);
  1005. else
  1006. $incontext['sql_results']['inserts']++;
  1007. }
  1008. }
  1009. $current_statement = '';
  1010. }
  1011. // Sort out the context for the SQL.
  1012. foreach ($incontext['sql_results'] as $key => $number)
  1013. {
  1014. if ($number == 0)
  1015. unset($incontext['sql_results'][$key]);
  1016. else
  1017. $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
  1018. }
  1019. // Make sure UTF will be used globally.
  1020. if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
  1021. $smcFunc['db_insert']('replace',
  1022. $db_prefix . 'settings',
  1023. array(
  1024. 'variable' => 'string-255', 'value' => 'string-65534',
  1025. ),
  1026. array(
  1027. 'global_character_set', 'UTF-8',
  1028. ),
  1029. array('variable')
  1030. );
  1031. // Maybe we can auto-detect better cookie settings?
  1032. preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
  1033. if (!empty($matches))
  1034. {
  1035. // Default = both off.
  1036. $localCookies = false;
  1037. $globalCookies = false;
  1038. // Okay... let's see. Using a subdomain other than www.? (not a perfect check.)
  1039. if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
  1040. $globalCookies = true;
  1041. // If there's a / in the middle of the path, or it starts with ~... we want local.
  1042. if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
  1043. $localCookies = true;
  1044. if ($globalCookies)
  1045. $rows[] = array('globalCookies', '1');
  1046. if ($localCookies)
  1047. $rows[] = array('localCookies', '1');
  1048. if (!empty($rows))
  1049. {
  1050. $smcFunc['db_insert']('replace',
  1051. $db_prefix . 'settings',
  1052. array('variable' => 'string-255', 'value' => 'string-65534'),
  1053. $rows,
  1054. array('variable')
  1055. );
  1056. }
  1057. }
  1058. // Are we allowing stat collection?
  1059. if (isset($_POST['stats']) && strpos($_POST['boardurl'], 'http://localhost') !== 0)
  1060. {
  1061. // Attempt to register the site etc.
  1062. $fp = @fsockopen("www.simplemachines.org", 80, $errno, $errstr);
  1063. if ($fp)
  1064. {
  1065. $out = "GET /smf/stats/register_stats.php?site=" . base64_encode($_POST['boardurl']) . " HTTP/1.1\r\n";
  1066. $out .= "Host: www.simplemachines.org\r\n";
  1067. $out .= "Connection: Close\r\n\r\n";
  1068. fwrite($fp, $out);
  1069. $return_data = '';
  1070. while (!feof($fp))
  1071. $return_data .= fgets($fp, 128);
  1072. fclose($fp);
  1073. // Get the unique site ID.
  1074. preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
  1075. if (!empty($ID[1]))
  1076. $smcFunc['db_insert']('',
  1077. $db_prefix . 'settings',
  1078. array(
  1079. 'variable' => 'string-255', 'value' => 'string-65534',
  1080. ),
  1081. array(
  1082. 'allow_sm_stats', $ID[1],
  1083. ),
  1084. array('variable')
  1085. );
  1086. }
  1087. }
  1088. // As of PHP 5.1, setting a timezone is required.
  1089. if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
  1090. {
  1091. $server_offset = mktime(0, 0, 0, 1, 1, 1970);
  1092. $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600);
  1093. if (date_default_timezone_set($timezone_id))
  1094. $smcFunc['db_insert']('',
  1095. $db_prefix . 'settings',
  1096. array(
  1097. 'variable' => 'string-255', 'value' => 'string-65534',
  1098. ),
  1099. array(
  1100. 'default_timezone', $timezone_id,
  1101. ),
  1102. array('variable')
  1103. );
  1104. }
  1105. // Let's optimize those new tables.
  1106. db_extend();
  1107. $tables = $smcFunc['db_list_tables']($db_name, $db_prefix . '%');
  1108. foreach ($tables as $table)
  1109. {
  1110. $smcFunc['db_optimize_table']($table) != -1 or $db_messed = true;
  1111. // Optimizing one sqlite table, optimizes them all
  1112. if ($db_type == 'sqlite' || $db_type == 'sqlite3')
  1113. break;
  1114. if (!empty($db_messed))
  1115. {
  1116. $incontext['failures'][-1] = $smcFunc['db_error']();
  1117. break;
  1118. }
  1119. }
  1120. // Check for the ALTER privilege.
  1121. if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('', "ALTER TABLE {$db_prefix}boards ORDER BY id_board", array('security_override' => true, 'db_error_skip' => true)) === false)
  1122. {
  1123. $incontext['error'] = $txt['error_db_alter_priv'];
  1124. return false;
  1125. }
  1126. if (!empty($exists))
  1127. {
  1128. $incontext['page_title'] = $txt['user_refresh_install'];
  1129. $incontext['was_refresh'] = true;
  1130. }
  1131. return false;
  1132. }
  1133. // Ask for the administrator login information.
  1134. function AdminAccount()
  1135. {
  1136. global $txt, $db_type, $db_connection, $databases, $smcFunc, $incontext, $db_prefix, $db_passwd, $sourcedir;
  1137. $incontext['sub_template'] = 'admin_account';
  1138. $incontext['page_title'] = $txt['user_settings'];
  1139. $incontext['continue'] = 1;
  1140. // Skipping?
  1141. if (!empty($_POST['skip']))
  1142. return true;
  1143. // Need this to check whether we need the database password.
  1144. require(dirname(__FILE__) . '/Settings.php');
  1145. load_database();
  1146. // Define the sha1 function, if it doesn't exist.
  1147. if (!function_exists('sha1') || version_compare(PHP_VERSION, '5', '<'))
  1148. require_once($sourcedir . '/Subs-Compat.php');
  1149. if (!isset($_POST['username']))
  1150. $_POST['username'] = '';
  1151. if (!isset($_POST['email']))
  1152. $_POST['email'] = '';
  1153. $incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
  1154. $incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
  1155. $incontext['require_db_confirm'] = empty($db_type) || ($db_type != 'sqlite' && $db_type != 'sqlite3');
  1156. // Only allow skipping if we think they already have an account setup.
  1157. $request = $smcFunc['db_query']('', '
  1158. SELECT id_member
  1159. FROM {db_prefix}members
  1160. WHERE id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0
  1161. LIMIT 1',
  1162. array(
  1163. 'db_error_skip' => true,
  1164. 'admin_group' => 1,
  1165. )
  1166. );
  1167. if ($smcFunc['db_num_rows']($request) != 0)
  1168. $incontext['skip'] = 1;
  1169. $smcFunc['db_free_result']($request);
  1170. // Trying to create an account?
  1171. if (isset($_POST['password1']) && !empty($_POST['contbutt']))
  1172. {
  1173. // Wrong password?
  1174. if ($incontext['require_db_confirm'] && $_POST['password3'] != $db_passwd)
  1175. {
  1176. $incontext['error'] = $txt['error_db_connect'];
  1177. return false;
  1178. }
  1179. // Not matching passwords?
  1180. if ($_POST['password1'] != $_POST['password2'])
  1181. {
  1182. $incontext['error'] = $txt['error_user_settings_again_match'];
  1183. return false;
  1184. }
  1185. // No password?
  1186. if (strlen($_POST['password1']) < 4)
  1187. {
  1188. $incontext['error'] = $txt['error_user_settings_no_password'];
  1189. return false;
  1190. }
  1191. if (!file_exists($sourcedir . '/Subs.php'))
  1192. {
  1193. $incontext['error'] = $txt['error_subs_missing'];
  1194. return false;
  1195. }
  1196. // Update the main contact email?
  1197. if (!empty($_POST['email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
  1198. updateSettingsFile(array('webmaster_email' => $_POST['email']));
  1199. // Work out whether we're going to have dodgy characters and remove them.
  1200. $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
  1201. $_POST['username'] = preg_replace('~[<>&"\'=\\\]~', '', $_POST['username']);
  1202. $result = $smcFunc['db_query']('', '
  1203. SELECT id_member, password_salt
  1204. FROM {db_prefix}members
  1205. WHERE member_name = {string:username} OR email_address = {string:email}
  1206. LIMIT 1',
  1207. array(
  1208. 'username' => stripslashes($_POST['username']),
  1209. 'email' => stripslashes($_POST['email']),
  1210. 'db_error_skip' => true,
  1211. )
  1212. );
  1213. if ($smcFunc['db_num_rows']($result) != 0)
  1214. {
  1215. list ($incontext['member_id'], $incontext['member_salt']) = $smcFunc['db_fetch_row']($result);
  1216. $smcFunc['db_free_result']($result);
  1217. $incontext['account_existed'] = $txt['error_user_settings_taken'];
  1218. }
  1219. elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
  1220. {
  1221. // Try the previous step again.
  1222. $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
  1223. return false;
  1224. }
  1225. elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
  1226. {
  1227. // Try the previous step again.
  1228. $incontext['error'] = $txt['error_invalid_characters_username'];
  1229. return false;
  1230. }
  1231. elseif (empty($_POST['email']) || preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', stripslashes($_POST['email'])) === 0 || strlen(stripslashes($_POST['email'])) > 255)
  1232. {
  1233. // One step back, this time fill out a proper email address.
  1234. $incontext['error'] = sprintf($txt['error_valid_email_needed'], $_POST['username']);
  1235. return false;
  1236. }
  1237. elseif ($_POST['username'] != '')
  1238. {
  1239. $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
  1240. // Format the username properly.
  1241. $_POST['username'] = preg_replace('~[\t\n\r\x0B\0\xA0]+~', ' ', $_POST['username']);
  1242. $ip = isset($_SERVER['REMOTE_ADDR']) ? substr($_SERVER['REMOTE_ADDR'], 0, 255) : '';
  1243. $request = $smcFunc['db_insert']('',
  1244. $db_prefix . 'members',
  1245. array(
  1246. 'member_name' => 'string-25', 'real_name' => 'string-25', 'passwd' => 'string', 'email_address' => 'string',
  1247. 'id_group' => 'int', 'posts' => 'int', 'date_registered' => 'int',
  1248. 'password_salt' => 'string', 'lngfile' => 'string', 'personal_text' => 'string', 'avatar' => 'string',
  1249. 'member_ip' => 'string', 'member_ip2' => 'string', 'buddy_list' => 'string', 'pm_ignore_list' => 'string',
  1250. 'website_title' => 'string', 'website_url' => 'string',
  1251. 'signature' => 'string', 'usertitle' => 'string', 'secret_question' => 'string',
  1252. 'additional_groups' => 'string', 'ignore_boards' => 'string', 'openid_uri' => 'string',
  1253. ),
  1254. array(
  1255. stripslashes($_POST['username']), stripslashes($_POST['username']), sha1(strtolower(stripslashes($_POST['username'])) . stripslashes($_POST['password1'])), stripslashes($_POST['email']),
  1256. 1, 0, time(), 0,
  1257. $incontext['member_salt'], '', '', '',
  1258. $ip, $ip, '', '',
  1259. '', '',
  1260. '', '', '',
  1261. '', '', '',
  1262. ),
  1263. array('id_member')
  1264. );
  1265. // Awww, crud!
  1266. if ($request === false)
  1267. {
  1268. $incontext['error'] = $txt['error_user_settings_query'] . '<br>
  1269. <div style="margin: 2ex;">' . nl2br(htmlspecialchars($smcFunc['db_error']($db_connection))) . '</div>';
  1270. return false;
  1271. }
  1272. $incontext['member_id'] = $smcFunc['db_insert_id']("{$db_prefix}members", 'id_member');
  1273. }
  1274. // If we're here we're good.
  1275. return true;
  1276. }
  1277. return false;
  1278. }
  1279. // Final step, clean up and a complete message!
  1280. function DeleteInstall()
  1281. {
  1282. global $txt, $db_prefix, $db_connection, $HTTP_SESSION_VARS, $cookiename, $incontext;
  1283. global $smcFunc, $db_character_set, $mbname, $context, $scripturl, $boardurl;
  1284. global $current_smf_version, $databases, $sourcedir, $forum_version, $modSettings, $user_info, $language, $db_type;
  1285. $incontext['page_title'] = $txt['congratulations'];
  1286. $incontext['sub_template'] = 'delete_install';
  1287. $incontext['continue'] = 0;
  1288. require(dirname(__FILE__) . '/Settings.php');
  1289. load_database();
  1290. chdir(dirname(__FILE__));
  1291. require_once($sourcedir . '/Errors.php');
  1292. require_once($sourcedir . '/Logging.php');
  1293. require_once($sourcedir . '/Subs.php');
  1294. require_once($sourcedir . '/Load.php');
  1295. require_once($sourcedir . '/Security.php');
  1296. require_once($sourcedir . '/Subs-Auth.php');
  1297. // Bring a warning over.
  1298. if (!empty($incontext['account_existed']))
  1299. $incontext['warning'] = $incontext['account_existed'];
  1300. if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
  1301. $smcFunc['db_query']('', '
  1302. SET NAMES {raw:db_character_set}',
  1303. array(
  1304. 'db_character_set' => $db_character_set,
  1305. 'db_error_skip' => true,
  1306. )
  1307. );
  1308. // As track stats is by default enabled let's add some activity.
  1309. $smcFunc['db_insert']('ignore',
  1310. '{db_prefix}log_activity',
  1311. array('date' => 'date', 'topics' => 'int', 'posts' => 'int', 'registers' => 'int'),
  1312. array(strftime('%Y-%m-%d', time()), 1, 1, (!empty($incontext['member_id']) ? 1 : 0)),
  1313. array('date')
  1314. );
  1315. // We're going to want our lovely $modSettings now.
  1316. $request = $smcFunc['db_query']('', '
  1317. SELECT variable, value
  1318. FROM {db_prefix}settings',
  1319. array(
  1320. 'db_error_skip' => true,
  1321. )
  1322. );
  1323. // Only proceed if we can load the data.
  1324. if ($request)
  1325. {
  1326. while ($row = $smcFunc['db_fetch_row']($request))
  1327. $modSettings[$row[0]] = $row[1];
  1328. $smcFunc['db_free_result']($request);
  1329. }
  1330. // Automatically log them in ;)
  1331. if (isset($incontext['member_id']) && isset($incontext['member_salt']))
  1332. setLoginCookie(3153600 * 60, $incontext['member_id'], sha1(sha1(strtolower($_POST['username']) . $_POST['password1']) . $incontext['member_salt']));
  1333. $result = $smcFunc['db_query']('', '
  1334. SELECT value
  1335. FROM {db_prefix}settings
  1336. WHERE variable = {string:db_sessions}',
  1337. array(
  1338. 'db_sessions' => 'databaseSession_enable',
  1339. 'db_error_skip' => true,
  1340. )
  1341. );
  1342. if ($smcFunc['db_num_rows']($result) != 0)
  1343. list ($db_sessions) = $smcFunc['db_fetch_row']($result);
  1344. $smcFunc['db_free_result']($result);
  1345. if (empty($db_sessions))
  1346. $_SESSION['admin_time'] = time();
  1347. else
  1348. {
  1349. $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
  1350. $smcFunc['db_insert']('replace',
  1351. '{db_prefix}sessions',
  1352. array(
  1353. 'session_id' => 'string', 'last_update' => 'int', 'data' => 'string',
  1354. ),
  1355. array(
  1356. session_id(), time(), 'USER_AGENT|s:' . strlen($_SERVER['HTTP_USER_AGENT']) . ':"' . $_SERVER['HTTP_USER_AGENT'] . '";admin_time|i:' . time() . ';',
  1357. ),
  1358. array('session_id')
  1359. );
  1360. }
  1361. updateStats('member');
  1362. updateStats('message');
  1363. updateStats('topic');
  1364. // This function is needed to do the updateStats('subject') call.
  1365. $smcFunc['strtolower'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8' ? create_function('$string', '
  1366. return $string;') : 'strtolower';
  1367. $request = $smcFunc['db_query']('', '
  1368. SELECT id_msg
  1369. FROM {db_prefix}messages
  1370. WHERE id_msg = 1
  1371. AND modified_time = 0
  1372. LIMIT 1',
  1373. array(
  1374. 'db_error_skip' => true,
  1375. )
  1376. );
  1377. $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
  1378. if ($smcFunc['db_num_rows']($request) > 0)
  1379. updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
  1380. $smcFunc['db_free_result']($request);
  1381. // Now is the perfect time to fetch the SM files.
  1382. require_once($sourcedir . '/ScheduledTasks.php');
  1383. // Sanity check that they loaded earlier!
  1384. if (isset($modSettings['recycle_board']))
  1385. {
  1386. $forum_version = $current_smf_version; // The variable is usually defined in index.php so lets just use our variable to do it for us.
  1387. scheduled_fetchSMfiles(); // Now go get those files!
  1388. // We've just installed!
  1389. $user_info['ip'] = $_SERVER['REMOTE_ADDR'];
  1390. $user_info['id'] = isset($incontext['member_id']) ? $incontext['member_id'] : 0;
  1391. logAction('install', array('version' => $forum_version), 'admin');
  1392. }
  1393. // Check if we need some stupid MySQL fix.
  1394. $server_version = $smcFunc['db_server_info']();
  1395. if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
  1396. updateSettings(array('db_mysql_group_by_fix' => '1'));
  1397. // Some final context for the template.
  1398. $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
  1399. $incontext['probably_delete_install'] = isset($_SESSION['installer_temp_ftp']) || is_writable(dirname(__FILE__)) || is_writable(__FILE__);
  1400. return false;
  1401. }
  1402. // http://www.faqs.org/rfcs/rfc959.html
  1403. class ftp_connection
  1404. {
  1405. var $connection = 'no_connection', $error = false, $last_message, $pasv = array();
  1406. // Create a new FTP connection...
  1407. function ftp_connection($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
  1408. {
  1409. if ($ftp_server !== null)
  1410. $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
  1411. }
  1412. function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
  1413. {
  1414. if (substr($ftp_server, 0, 6) == 'ftp://')
  1415. $ftp_server = substr($ftp_server, 6);
  1416. elseif (substr($ftp_server, 0, 7) == 'ftps://')
  1417. $ftp_server = 'ssl://' . substr($ftp_server, 7);
  1418. if (substr($ftp_server, 0, 7) == 'http://')
  1419. $ftp_server = substr($ftp_server, 7);
  1420. $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => ''));
  1421. // Connect to the FTP server.
  1422. $this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5);
  1423. if (!$this->connection)
  1424. {
  1425. $this->error = 'bad_server';
  1426. return;
  1427. }
  1428. // Get the welcome message...
  1429. if (!$this->check_response(220))
  1430. {
  1431. $this->error = 'bad_response';
  1432. return;
  1433. }
  1434. // Send the username, it should ask for a password.
  1435. fwrite($this->connection, 'USER ' . $ftp_user . "\r\n");
  1436. if (!$this->check_response(331))
  1437. {
  1438. $this->error = 'bad_username';
  1439. return;
  1440. }
  1441. // Now send the password... and hope it goes okay.
  1442. fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n");
  1443. if (!$this->check_response(230))
  1444. {
  1445. $this->error = 'bad_password';
  1446. return;
  1447. }
  1448. }
  1449. function chdir($ftp_path)
  1450. {
  1451. if (!is_resource($this->connection))
  1452. return false;
  1453. // No slash on the end, please...
  1454. if (substr($ftp_path, -1) == '/')
  1455. $ftp_path = substr($ftp_path, 0, -1);
  1456. fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n");
  1457. if (!$this->check_response(250))
  1458. {
  1459. $this->error = 'bad_path';
  1460. return false;
  1461. }
  1462. return true;
  1463. }
  1464. function chmod($ftp_file, $chmod)
  1465. {
  1466. if (!is_resource($this->connection))
  1467. return false;
  1468. // Convert the chmod value from octal (0777) to text ("777")
  1469. fwrite($this->connection, 'SITE CHMOD ' . decoct($chmod) . ' ' . $ftp_file . "\r\n");
  1470. if (!$this->check_response(200))
  1471. {
  1472. $this->error = 'bad_file';
  1473. return false;
  1474. }
  1475. return true;
  1476. }
  1477. function unlink($ftp_file)
  1478. {
  1479. // We are actually connected, right?
  1480. if (!is_resource($this->connection))
  1481. return false;
  1482. // Delete file X.
  1483. fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n");
  1484. if (!$this->check_response(250))
  1485. {
  1486. fwrite($this->connection, 'RMD ' . $ftp_file . "\r\n");
  1487. // Still no love?
  1488. if (!$this->check_response(250))
  1489. {
  1490. $this->error = 'bad_file';
  1491. return false;
  1492. }
  1493. }
  1494. return true;
  1495. }
  1496. function check_response($desired)
  1497. {
  1498. // Wait for a response that isn't continued with -, but don't wait too long.
  1499. $time = time();
  1500. do
  1501. $this->last_message = fgets($this->connection, 1024);
  1502. while (substr($this->last_message, 3, 1) != ' ' && time() - $time < 5);
  1503. // Was the desired response returned?
  1504. return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
  1505. }
  1506. function passive()
  1507. {
  1508. // We can't create a passive data connection without a primary one first being there.
  1509. if (!is_resource($this->connection))
  1510. return false;
  1511. // Request a passive connection - this means, we'll talk to you, you don't talk to us.
  1512. @fwrite($this->connection, "PASV\r\n");
  1513. $time = time();
  1514. do
  1515. $response = fgets($this->connection, 1024);
  1516. while (substr($response, 3, 1) != ' ' && time() - $time < 5);
  1517. // If it's not 227, we weren't given an IP and port, which means it failed.
  1518. if (substr($response, 0, 4) != '227 ')
  1519. {
  1520. $this->error = 'bad_response';
  1521. return false;
  1522. }
  1523. // Snatch the IP and port information, or die horribly trying...
  1524. if (preg_match('~\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))\)~', $response, $match) == 0)
  1525. {
  1526. $this->error = 'bad_response';
  1527. return false;
  1528. }
  1529. // This is pretty simple - store it for later use ;)
  1530. $this->pasv = array('ip' => $match[1] . '.' . $match[2] . '.' . $match[3] . '.' . $match[4], 'port' => $match[5] * 256 + $match[6]);
  1531. return true;
  1532. }
  1533. function create_file($ftp_file)
  1534. {
  1535. // First, we have to be connected... very important.
  1536. if (!is_resource($this->connection))
  1537. return false;
  1538. // I'd like one passive mode, please!
  1539. if (!$this->passive())
  1540. return false;
  1541. // Seems logical enough, so far...
  1542. fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n");
  1543. // Okay, now we connect to the data port. If it doesn't work out, it's probably "file already exists", etc.
  1544. $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
  1545. if (!$fp || !$this->check_response(150))
  1546. {
  1547. $this->error = 'bad_file';
  1548. @fclose($fp);
  1549. return false;
  1550. }
  1551. // This may look strange, but we're just closing it to indicate a zero-byte upload.
  1552. fclose($fp);
  1553. if (!$this->check_response(226))
  1554. {
  1555. $this->error = 'bad_response';
  1556. return false;
  1557. }
  1558. return true;
  1559. }
  1560. function list_dir($ftp_path = '', $search = false)
  1561. {
  1562. // Are we even connected...?
  1563. if (!is_resource($this->connection))
  1564. return false;
  1565. // Passive... non-agressive...
  1566. if (!$this->passive())
  1567. return false;
  1568. // Get the listing!
  1569. fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n");
  1570. // Connect, assuming we've got a connection.
  1571. $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
  1572. if (!$fp || !$this->check_response(array(150, 125)))
  1573. {
  1574. $this->error = 'bad_response';
  1575. @fclose($fp);
  1576. return false;
  1577. }
  1578. // Read in the file listing.
  1579. $data = '';
  1580. while (!feof($fp))
  1581. $data .= fread($fp, 4096);
  1582. fclose($fp);
  1583. // Everything go okay?
  1584. if (!$this->check_response(226))
  1585. {
  1586. $this->error = 'bad_response';
  1587. return false;
  1588. }
  1589. return $data;
  1590. }
  1591. function locate($file, $listing = null)
  1592. {
  1593. if ($listing === null)
  1594. $listing = $this->list_dir('', true);
  1595. $listing = explode("\n", $listing);
  1596. @fwrite($this->connection, "PWD\r\n");
  1597. $time = time();
  1598. do
  1599. $response = fgets($this->connection, 1024);
  1600. while (substr($response, 3, 1) != ' ' && time() - $time < 5);
  1601. // Check for 257!
  1602. if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0)
  1603. $current_dir = strtr($match[1], array('""' => '"'));
  1604. else
  1605. $current_dir = '';
  1606. for ($i = 0, $n = count($listing); $i < $n; $i++)
  1607. {
  1608. if (trim($listing[$i]) == '' && isset($listing[$i + 1]))
  1609. {
  1610. $current_dir = substr(trim($listing[++$i]), 0, -1);
  1611. $i++;
  1612. }
  1613. // Okay, this file's name is:
  1614. $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]);
  1615. if (substr($file, 0, 1) == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1))
  1616. return $listing[$i];
  1617. if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1))
  1618. return $listing[$i];
  1619. if (basename($listing[$i]) == $file || $listing[$i] == $file)
  1620. return $listing[$i];
  1621. }
  1622. return false;
  1623. }
  1624. function create_dir($ftp_dir)
  1625. {
  1626. // We must be connected to the server to do something.
  1627. if (!is_resource($this->connection))
  1628. return false;
  1629. // Make this new beautiful directory!
  1630. fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n");
  1631. if (!$this->check_response(257))
  1632. {
  1633. $this->error = 'bad_file';
  1634. return false;
  1635. }
  1636. return true;
  1637. }
  1638. function detect_path($filesystem_path, $lookup_file = null)
  1639. {
  1640. $username = '';
  1641. if (isset($_SERVER['DOCUMENT_ROOT']))
  1642. {
  1643. if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
  1644. {
  1645. $username = $match[1];
  1646. $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
  1647. if (substr($path, -1) == '/')
  1648. $path = substr($path, 0, -1);
  1649. if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
  1650. $path .= dirname($_SERVER['PHP_SELF']);
  1651. }
  1652. elseif (substr($filesystem_path, 0, 9) == '/var/www/')
  1653. $path = substr($filesystem_path, 8);
  1654. else
  1655. $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
  1656. }
  1657. else
  1658. $path = '';
  1659. if (is_resource($this->connection) && $this->list_dir($path) == '')
  1660. {
  1661. $data = $this->list_dir('', true);
  1662. if ($lookup_file === null)
  1663. $lookup_file = $_SERVER['PHP_SELF'];
  1664. $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
  1665. if ($found_path == false)
  1666. $found_path = dirname($this->locate(basename($lookup_file)));
  1667. if ($found_path != false)
  1668. $path = $found_path;
  1669. }
  1670. elseif (is_resource($this->connection))
  1671. $found_path = true;
  1672. return array($username, $path, isset($found_path));
  1673. }
  1674. function close()
  1675. {
  1676. // Goodbye!
  1677. fwrite($this->connection, "QUIT\r\n");
  1678. fclose($this->connection);
  1679. return true;
  1680. }
  1681. }
  1682. function updateSettingsFile($vars)
  1683. {
  1684. // Modify Settings.php.
  1685. $settingsArray = file(dirname(__FILE__) . '/Settings.php');
  1686. // @todo Do we just want to read the file in clean, and split it this way always?
  1687. if (count($settingsArray) == 1)
  1688. $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
  1689. for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
  1690. {
  1691. // Remove the redirect...
  1692. if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 3]) == '}')
  1693. {
  1694. // Get the four lines to nothing.
  1695. $settingsArray[$i] = '';
  1696. $settingsArray[++$i] = '';
  1697. $settingsArray[++$i] = '';
  1698. $settingsArray[++$i] = '';
  1699. continue;
  1700. }
  1701. if (trim($settingsArray[$i]) == '?' . '>')
  1702. $settingsArray[$i] = '';
  1703. // Don't trim or bother with it if it's not a variable.
  1704. if (substr($settingsArray[$i], 0, 1) != '$')
  1705. continue;
  1706. $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
  1707. foreach ($vars as $var => $val)
  1708. if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
  1709. {
  1710. $comment = strstr($settingsArray[$i], '#');
  1711. $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
  1712. unset($vars[$var]);
  1713. }
  1714. }
  1715. // Uh oh... the file wasn't empty... was it?
  1716. if (!empty($vars))
  1717. {
  1718. $settingsArray[$i++] = '';
  1719. foreach ($vars as $var => $val)
  1720. $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
  1721. }
  1722. // Blank out the file - done to fix a oddity with some servers.
  1723. $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
  1724. if (!$fp)
  1725. return false;
  1726. fclose($fp);
  1727. $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
  1728. // Gotta have one of these ;)
  1729. if (trim($settingsArray[0]) != '<?php')
  1730. fwrite($fp, "<?php\n");
  1731. $lines = count($settingsArray);
  1732. for ($i = 0; $i < $lines - 1; $i++)
  1733. {
  1734. // Don't just write a bunch of blank lines.
  1735. if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
  1736. fwrite($fp, strtr($settingsArray[$i], "\r", ''));
  1737. }
  1738. fwrite($fp, $settingsArray[$i] . '?' . '>');
  1739. fclose($fp);
  1740. // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
  1741. // it seems that there are times it might not. So let's MAKE it dump the cache.
  1742. if (function_exists('opcache_invalidate'))
  1743. opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
  1744. return true;
  1745. }
  1746. function updateDbLastError()
  1747. {
  1748. // Write out the db_last_error file with the error timestamp
  1749. file_put_contents(dirname(__FILE__) . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
  1750. return true;
  1751. }
  1752. // Create an .htaccess file to prevent mod_security. SMF has filtering built-in.
  1753. function fixModSecurity()
  1754. {
  1755. $htaccess_addition = '
  1756. <IfModule mod_security.c>
  1757. # Turn off mod_security filtering. SMF is a big boy, it doesn\'t need its hands held.
  1758. SecFilterEngine Off
  1759. # The below probably isn\'t needed, but better safe than sorry.
  1760. SecFilterScanPOST Off
  1761. </IfModule>';
  1762. if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
  1763. return true;
  1764. elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
  1765. {
  1766. $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
  1767. // Only change something if mod_security hasn't been addressed yet.
  1768. if (strpos($current_htaccess, '<IfModule mod_security.c>') === false)
  1769. {
  1770. if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'a'))
  1771. {
  1772. fwrite($ht_handle, $htaccess_addition);
  1773. fclose($ht_handle);
  1774. return true;
  1775. }
  1776. else
  1777. return false;
  1778. }
  1779. else
  1780. return true;
  1781. }
  1782. elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
  1783. return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
  1784. elseif (is_writable(dirname(__FILE__)))
  1785. {
  1786. if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
  1787. {
  1788. fwrite($ht_handle, $htaccess_addition);
  1789. fclose($ht_handle);
  1790. return true;
  1791. }
  1792. else
  1793. return false;
  1794. }
  1795. else
  1796. return false;
  1797. }
  1798. function template_install_above()
  1799. {
  1800. global $incontext, $txt, $smfsite, $installurl;
  1801. echo '<!DOCTYPE html>
  1802. <html', !empty($txt['lang_rtl']) ? ' dir="rtl"' : '', '>
  1803. <head>
  1804. <meta http-equiv="Content-Type" content="text/html; charset=', isset($txt['lang_character_set']) ? $txt['lang_character_set'] : 'ISO-8859-1', '">
  1805. <meta name="robots" content="noindex">
  1806. <title>', $txt['smf_installer'], '</title>
  1807. <link rel="stylesheet" type="text/css" href="Themes/default/css/index.css?alp21">
  1808. <link rel="stylesheet" type="text/css" href="Themes/default/css/install.css?alp21">
  1809. <script src="Themes/default/scripts/script.js"></script>
  1810. </head>
  1811. <body>
  1812. <div id="header">
  1813. <div class="frame">
  1814. <h1 class="forumtitle">', $txt['smf_installer'], '</h1>
  1815. <img id="smflogo" src="Themes/default/images/smflogo.png" alt="Simple Machines Forum" title="Simple Machines Forum">
  1816. </div>
  1817. <div id="wrapper">
  1818. <div id="upper_section">
  1819. <div id="inner_section">
  1820. <div id="inner_wrap">';
  1821. // Have we got a language drop down - if so do it on the first step only.
  1822. if (!empty($incontext['detected_languages']) && count($incontext['detected_languages']) > 1 && $incontext['current_step'] == 0)
  1823. {
  1824. echo '
  1825. <div class="news">
  1826. <form action="', $installurl, '" method="get">
  1827. <label for="installer_language">', $txt['installer_language'], ':</label>
  1828. <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
  1829. foreach ($incontext['detected_languages'] as $lang => $name)
  1830. echo '
  1831. <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
  1832. echo '
  1833. </select>
  1834. <noscript><input type="submit" value="', $txt['installer_language_set'], '" class="button_submit" /></noscript>
  1835. </form>
  1836. </div>
  1837. <hr class="clear" />';
  1838. }
  1839. echo '
  1840. </div>
  1841. </div>
  1842. </div>
  1843. <div id="content_section">
  1844. <div id="main_content_section">
  1845. <div id="main_steps">
  1846. <h2>', $txt['upgrade_progress'], '</h2>
  1847. <ul>';
  1848. foreach ($incontext['steps'] as $num => $step)
  1849. echo '
  1850. <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
  1851. echo '
  1852. </ul>
  1853. </div>
  1854. <div id="progress_bar">
  1855. <div id="overall_text">', $incontext['overall_percent'], '%</div>
  1856. <div id="overall_progress" style="width: ', $incontext['overall_percent'], '%;">&nbsp;</div>
  1857. <div class="overall_progress">', $txt['upgrade_overall_progress'], '</div>
  1858. </div>
  1859. <div id="main_screen" class="clear">
  1860. <h2>', $incontext['page_title'], '</h2>
  1861. <div class="panel">';
  1862. }
  1863. function template_install_below()
  1864. {
  1865. global $incontext, $txt;
  1866. if (!empty($incontext['continue']) || !empty($incontext['skip']))
  1867. {
  1868. echo '
  1869. <div>';
  1870. if (!empty($incontext['continue']))
  1871. echo '
  1872. <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
  1873. if (!empty($incontext['skip']))
  1874. echo '
  1875. <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
  1876. echo '
  1877. </div>';
  1878. }
  1879. // Show the closing form tag and other data only if not in the last step
  1880. if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
  1881. echo '
  1882. </form>';
  1883. echo '
  1884. </div>
  1885. </div>
  1886. </div>
  1887. </div>
  1888. </div>
  1889. <div id="footer_section">
  1890. <div class="frame">
  1891. <ul class="reset">
  1892. <li class="copyright"><a href="http://www.simplemachines.org/" title="Simple Machines Forum" target="_blank" class="new_win">SMF &copy; 2014, Simple Machines</a></li>
  1893. </ul>
  1894. </div>
  1895. </div>
  1896. </body>
  1897. </html>';
  1898. }
  1899. // Welcome them to the wonderful world of SMF!
  1900. function template_welcome_message()
  1901. {
  1902. global $incontext, $installurl, $txt;
  1903. echo '
  1904. <script src="http://www.simplemachines.org/smf/current-version.js?version=' . $GLOBALS['current_smf_version'] . '"></script>
  1905. <form action="', $incontext['form_url'], '" method="post">
  1906. <p>', sprintf($txt['install_welcome_desc'], $GLOBALS['current_smf_version']), '</p>
  1907. <div id="version_warning" style="margin: 2ex; padding: 2ex; border: 2px dashed #a92174; color: black; background-color: #fbbbe2; display: none;">
  1908. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  1909. <strong style="text-decoration: underline;">', $txt['error_warning_notice'], '</strong><br />
  1910. <div style="padding-left: 6ex;">
  1911. ', sprintf($txt['error_script_outdated'], '<em id="smfVersion" style="white-space: nowrap;">??</em>', '<em id="yourVersion" style="white-space: nowrap;">' . $GLOBALS['current_smf_version'] . '</em>'), '
  1912. </div>
  1913. </div>';
  1914. // Show the warnings, or not.
  1915. if (template_warning_divs())
  1916. echo '
  1917. <h3>', $txt['install_all_lovely'], '</h3>';
  1918. // Say we want the continue button!
  1919. if (empty($incontext['error']))
  1920. $incontext['continue'] = 1;
  1921. // For the latest version stuff.
  1922. echo '
  1923. <script><!-- // --><![CDATA[
  1924. // Latest version?
  1925. function smfCurrentVersion()
  1926. {
  1927. var smfVer, yourVer;
  1928. if (!(\'smfVersion\' in window))
  1929. return;
  1930. window.smfVersion = window.smfVersion.replace(/SMF\s?/g, \'\');
  1931. smfVer = document.getElementById("smfVersion");
  1932. yourVer = document.getElementById("yourVersion");
  1933. setInnerHTML(smfVer, window.smfVersion);
  1934. var currentVersion = getInnerHTML(yourVer);
  1935. if (currentVersion < window.smfVersion)
  1936. document.getElementById(\'version_warning\').style.display = \'\';
  1937. }
  1938. addLoadEvent(smfCurrentVersion);
  1939. // ]]></script>';
  1940. }
  1941. // A shortcut for any warning stuff.
  1942. function template_warning_divs()
  1943. {
  1944. global $txt, $incontext;
  1945. // Errors are very serious..
  1946. if (!empty($incontext['error']))
  1947. echo '
  1948. <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
  1949. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  1950. <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br />
  1951. <div style="padding-left: 6ex;">
  1952. ', $incontext['error'], '
  1953. </div>
  1954. </div>';
  1955. // A warning message?
  1956. elseif (!empty($incontext['warning']))
  1957. echo '
  1958. <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
  1959. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  1960. <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
  1961. <div style="padding-left: 6ex;">
  1962. ', $incontext['warning'], '
  1963. </div>
  1964. </div>';
  1965. return empty($incontext['error']) && empty($incontext['warning']);
  1966. }
  1967. function template_chmod_files()
  1968. {
  1969. global $txt, $incontext;
  1970. echo '
  1971. <p>', $txt['ftp_setup_why_info'], '</p>
  1972. <ul style="margin: 2.5ex; font-family: monospace;">
  1973. <li>', implode('</li>
  1974. <li>', $incontext['failed_files']), '</li>
  1975. </ul>';
  1976. // This is serious!
  1977. if (!template_warning_divs())
  1978. return;
  1979. echo '
  1980. <hr />
  1981. <p>', $txt['ftp_setup_info'], '</p>';
  1982. if (!empty($incontext['ftp_errors']))
  1983. echo '
  1984. <div class="error_message">
  1985. <div style="color: red;">
  1986. ', $txt['error_ftp_no_connect'], '<br />
  1987. <br />
  1988. <code>', implode('<br />', $incontext['ftp_errors']), '</code>
  1989. </div>
  1990. </div>
  1991. <br />';
  1992. echo '
  1993. <form action="', $incontext['form_url'], '" method="post">
  1994. <table align="center" style="width: 520px; margin: 1em 0; padding: 0; border: 0">
  1995. <tr>
  1996. <td width="26%" valign="top" class="textbox"><label for="ftp_server">', $txt['ftp_server'], ':</label></td>
  1997. <td>
  1998. <div style="float: ', empty($txt['lang_rtl']) ? 'right' : 'left', '; margin-', empty($txt['lang_rtl']) ? 'right' : 'left', ': 1px;"><label for="ftp_port" class="textbox"><strong>', $txt['ftp_port'], ':&nbsp;</strong></label> <input type="text" size="3" name="ftp_port" id="ftp_port" value="', $incontext['ftp']['port'], '" class="input_text" /></div>
  1999. <input type="text" size="30" name="ftp_server" id="ftp_server" value="', $incontext['ftp']['server'], '" style="width: 70%;" class="input_text" />
  2000. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_server_info'], '</div>
  2001. </td>
  2002. </tr><tr>
  2003. <td width="26%" valign="top" class="textbox"><label for="ftp_username">', $txt['ftp_username'], ':</label></td>
  2004. <td>
  2005. <input type="text" size="50" name="ftp_username" id="ftp_username" value="', $incontext['ftp']['username'], '" style="width: 99%;" class="input_text" />
  2006. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_username_info'], '</div>
  2007. </td>
  2008. </tr><tr>
  2009. <td width="26%" valign="top" class="textbox"><label for="ftp_password">', $txt['ftp_password'], ':</label></td>
  2010. <td>
  2011. <input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" class="input_password" />
  2012. <div style="font-size: smaller; margin-bottom: 3ex;">', $txt['ftp_password_info'], '</div>
  2013. </td>
  2014. </tr><tr>
  2015. <td width="26%" valign="top" class="textbox"><label for="ftp_path">', $txt['ftp_path'], ':</label></td>
  2016. <td style="padding-bottom: 1ex;">
  2017. <input type="text" size="50" name="ftp_path" id="ftp_path" value="', $incontext['ftp']['path'], '" style="width: 99%;" class="input_text" />
  2018. <div style="font-size: smaller; margin-bottom: 2ex;">', $incontext['ftp']['path_msg'], '</div>
  2019. </td>
  2020. </tr>
  2021. </table>
  2022. <div style="margin: 1ex; margin-top: 1ex; text-align: ', empty($txt['lang_rtl']) ? 'right' : 'left', ';"><input type="submit" value="', $txt['ftp_connect'], '" onclick="return submitThisOnce(this);" class="button_submit" /></div>
  2023. </form>
  2024. <a href="', $incontext['form_url'], '">', $txt['error_message_click'], '</a> ', $txt['ftp_setup_again'];
  2025. }
  2026. // Get the database settings prepared.
  2027. function template_database_settings()
  2028. {
  2029. global $incontext, $installurl, $txt;
  2030. echo '
  2031. <form action="', $incontext['form_url'], '" method="post">
  2032. <p>', $txt['db_settings_info'], '</p>';
  2033. template_warning_divs();
  2034. echo '
  2035. <table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin: 1em 0;">';
  2036. // More than one database type?
  2037. if (count($incontext['supported_databases']) > 1)
  2038. {
  2039. echo '
  2040. <tr>
  2041. <td width="20%" valign="top" class="textbox"><label for="db_type_input">', $txt['db_settings_type'], ':</label></td>
  2042. <td>
  2043. <select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
  2044. foreach ($incontext['supported_databases'] as $key => $db)
  2045. echo '
  2046. <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
  2047. echo '
  2048. </select><div id="db_sqlite_warning" style="color: blue; display: none;" class="smalltext">', $txt['db_sqlite_warning'], '</div>
  2049. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_type_info'], '</div>
  2050. </td>
  2051. </tr>';
  2052. }
  2053. else
  2054. {
  2055. echo '
  2056. <tr style="display: none;">
  2057. <td>
  2058. <input type="hidden" name="db_type" value="', $incontext['db']['type'], '" />
  2059. </td>
  2060. </tr>';
  2061. }
  2062. echo '
  2063. <tr id="db_server_contain">
  2064. <td width="20%" valign="top" class="textbox"><label for="db_server_input">', $txt['db_settings_server'], ':</label></td>
  2065. <td>
  2066. <input type="text" name="db_server" id="db_server_input" value="', $incontext['db']['server'], '" size="30" class="input_text" /><br />
  2067. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_server_info'], '</div>
  2068. </td>
  2069. </tr><tr id="db_port_contain">
  2070. <td width="20%" valign="top" class="textbox"><label for="db_port_input">', $txt['db_settings_port'], ':</label></td>
  2071. <td>
  2072. <input type="text" name="db_port" id="db_port_input" value="', $incontext['db']['port'], '"><br>
  2073. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_port_info'], '</div>
  2074. </td>
  2075. </tr><tr id="db_user_contain">
  2076. <td valign="top" class="textbox"><label for="db_user_input">', $txt['db_settings_username'], ':</label></td>
  2077. <td>
  2078. <input type="text" name="db_user" id="db_user_input" value="', $incontext['db']['user'], '" size="30" class="input_text" /><br />
  2079. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_username_info'], '</div>
  2080. </td>
  2081. </tr><tr id="db_passwd_contain">
  2082. <td valign="top" class="textbox"><label for="db_passwd_input">', $txt['db_settings_password'], ':</label></td>
  2083. <td>
  2084. <input type="password" name="db_passwd" id="db_passwd_input" value="', $incontext['db']['pass'], '" size="30" class="input_password" /><br />
  2085. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_password_info'], '</div>
  2086. </td>
  2087. </tr><tr id="db_name_contain">
  2088. <td valign="top" class="textbox"><label for="db_name_input">', $txt['db_settings_database'], ':</label></td>
  2089. <td>
  2090. <input type="text" name="db_name" id="db_name_input" value="', empty($incontext['db']['name']) ? 'smf' : $incontext['db']['name'], '" size="30" class="input_text" /><br />
  2091. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_database_info'], '
  2092. <span id="db_name_info_warning">', $txt['db_settings_database_info_note'], '</span></div>
  2093. </td>
  2094. </tr><tr id="db_filename_contain" style="display: none;">
  2095. <td valign="top" class="textbox"><label for="db_filename_input">', $txt['db_settings_database_file'], ':</label></td>
  2096. <td>
  2097. <input type="text" name="db_filename" id="db_filename_input" value="', empty($incontext['db']['name']) ? dirname(__FILE__) . '/smf_' . substr(md5(microtime()), 0, 10) : stripslashes($incontext['db']['name']), '" size="30" class="input_text" /><br />
  2098. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_database_file_info'], '</div>
  2099. </td>
  2100. </tr><tr>
  2101. <td valign="top" class="textbox"><label for="db_prefix_input">', $txt['db_settings_prefix'], ':</label></td>
  2102. <td>
  2103. <input type="text" name="db_prefix" id="db_prefix_input" value="', $incontext['db']['prefix'], '" size="30" class="input_text" /><br />
  2104. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_prefix_info'], '</div>
  2105. </td>
  2106. </tr>
  2107. </table>';
  2108. // Allow the toggling of input boxes for SQLite etc.
  2109. echo '
  2110. <script><!-- // --><![CDATA[
  2111. function toggleDBInput()
  2112. {
  2113. // What state is it?';
  2114. if (!isset($incontext['supported_databases']['sqlite']) && !isset($incontext['supported_databases']['sqlite3']))
  2115. echo '
  2116. var showAll = true;';
  2117. elseif (count($incontext['supported_databases']) < 2)
  2118. echo '
  2119. var showAll = false;';
  2120. // If we have more than one DB including SQLite, what should we be doing?
  2121. else
  2122. echo '
  2123. var showAll = (document.getElementById(\'db_type_input\').value == \'sqlite\' || document.getElementById(\'db_type_input\').value == \'sqlite3\') ? false : true;';
  2124. echo '
  2125. document.getElementById(\'db_passwd_contain\').style.display = showAll ? \'\' : \'none\';
  2126. document.getElementById(\'db_server_contain\').style.display = showAll ? \'\' : \'none\';
  2127. document.getElementById(\'db_user_contain\').style.display = showAll ? \'\' : \'none\';
  2128. document.getElementById(\'db_name_contain\').style.display = showAll ? \'\' : \'none\';
  2129. document.getElementById(\'db_filename_contain\').style.display = !showAll ? \'\' : \'none\';
  2130. document.getElementById(\'db_sqlite_warning\').style.display = !showAll ? \'\' : \'none\';
  2131. document.getElementById(\'db_port_contain\').style.display = showAll ? \'\' : \'none\';
  2132. if (document.getElementById(\'db_type_input\').value == \'postgresql\')
  2133. document.getElementById(\'db_name_info_warning\').style.display = \'none\';
  2134. else
  2135. document.getElementById(\'db_name_info_warning\').style.display = \'\';
  2136. }
  2137. toggleDBInput();
  2138. // ]]></script>';
  2139. }
  2140. // Stick in their forum settings.
  2141. function template_forum_settings()
  2142. {
  2143. global $incontext, $installurl, $txt;
  2144. echo '
  2145. <form action="', $incontext['form_url'], '" method="post">
  2146. <h3>', $txt['install_settings_info'], '</h3>';
  2147. template_warning_divs();
  2148. echo '
  2149. <table style="width: 100%; margin: 1em 0;">
  2150. <tr>
  2151. <td class="textbox" style="width: 20%; vertical-align: top;">
  2152. <label for="mbname_input">', $txt['install_settings_name'], ':</label>
  2153. </td>
  2154. <td>
  2155. <input type="text" name="mbname" id="mbname_input" value="', $txt['install_settings_name_default'], '" size="65" class="input_text" />
  2156. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_name_info'], '</div>
  2157. </td>
  2158. </tr>
  2159. <tr>
  2160. <td class="textbox" style="vertical-align: top;">
  2161. <label for="boardurl_input">', $txt['install_settings_url'], ':</label>
  2162. </td>
  2163. <td>
  2164. <input type="text" name="boardurl" id="boardurl_input" value="', $incontext['detected_url'], '" size="65" class="input_text" />
  2165. <br />
  2166. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_url_info'], '</div>
  2167. </td>
  2168. </tr>
  2169. <tr>
  2170. <td class="textbox" style="vertical-align: top;">
  2171. <label for="reg_mode">', $txt['install_settings_reg_mode'], ':</label>
  2172. </td>
  2173. <td>
  2174. <select name="reg_mode" id="reg_mode">
  2175. <optgroup label="', $txt['install_settings_reg_modes'], ':">
  2176. <option value="0" selected>', $txt['install_settings_reg_immediate'], '</option>
  2177. <option value="1">', $txt['install_settings_reg_email'], '</option>
  2178. <option value="2">', $txt['install_settings_reg_admin'], '</option>
  2179. <option value="3">', $txt['install_settings_reg_disabled'], '</option>
  2180. </optgroup>
  2181. </select>
  2182. <br />
  2183. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_reg_mode_info'], '</div>
  2184. </td>
  2185. </tr>
  2186. <tr>
  2187. <td class="textbox" style="vertical-align: top;">', $txt['install_settings_compress'], ':</td>
  2188. <td>
  2189. <input type="checkbox" name="compress" id="compress_check" checked class="input_check" />&nbsp;
  2190. <label for="compress_check">', $txt['install_settings_compress_title'], '</label>
  2191. <br />
  2192. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_compress_info'], '</div>
  2193. </td>
  2194. </tr>
  2195. <tr>
  2196. <td class="textbox" style="vertical-align: top;">', $txt['install_settings_dbsession'], ':</td>
  2197. <td>
  2198. <input type="checkbox" name="dbsession" id="dbsession_check" checked class="input_check" />&nbsp;
  2199. <label for="dbsession_check">', $txt['install_settings_dbsession_title'], '</label>
  2200. <br />
  2201. <div style="font-size: smaller; margin-bottom: 2ex;">', $incontext['test_dbsession'] ? $txt['install_settings_dbsession_info1'] : $txt['install_settings_dbsession_info2'], '</div>
  2202. </td>
  2203. </tr>
  2204. <tr>
  2205. <td class="textbox" style="vertical-align: top;">', $txt['install_settings_utf8'], ':</td>
  2206. <td>
  2207. <input type="checkbox" name="utf8" id="utf8_check"', $incontext['utf8_default'] ? ' checked' : '', ' class="input_check"', $incontext['utf8_required'] ? ' disabled' : '', ' />&nbsp;
  2208. <label for="utf8_check">', $txt['install_settings_utf8_title'], '</label>
  2209. <br />
  2210. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_utf8_info'], '</div>
  2211. </td>
  2212. </tr>
  2213. <tr>
  2214. <td class="textbox" style="vertical-align: top;">', $txt['install_settings_stats'], ':</td>
  2215. <td>
  2216. <input type="checkbox" name="stats" id="stats_check" class="input_check" />&nbsp;
  2217. <label for="stats_check">', $txt['install_settings_stats_title'], '</label>
  2218. <br />
  2219. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['install_settings_stats_info'], '</div>
  2220. </td>
  2221. </tr>
  2222. </table>
  2223. ';
  2224. }
  2225. // Show results of the database population.
  2226. function template_populate_database()
  2227. {
  2228. global $incontext, $installurl, $txt;
  2229. echo '
  2230. <form action="', $incontext['form_url'], '" method="post">
  2231. <p>', !empty($incontext['was_refresh']) ? $txt['user_refresh_install_desc'] : $txt['db_populate_info'], '</p>';
  2232. if (!empty($incontext['sql_results']))
  2233. {
  2234. echo '
  2235. <ul>
  2236. <li>', implode('</li><li>', $incontext['sql_results']), '</li>
  2237. </ul>';
  2238. }
  2239. if (!empty($incontext['failures']))
  2240. {
  2241. echo '
  2242. <div style="color: red;">', $txt['error_db_queries'], '</div>
  2243. <ul>';
  2244. foreach ($incontext['failures'] as $line => $fail)
  2245. echo '
  2246. <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
  2247. echo '
  2248. </ul>';
  2249. }
  2250. echo '
  2251. <p>', $txt['db_populate_info2'], '</p>';
  2252. template_warning_divs();
  2253. echo '
  2254. <input type="hidden" name="pop_done" value="1" />';
  2255. }
  2256. // Create the admin account.
  2257. function template_admin_account()
  2258. {
  2259. global $incontext, $installurl, $txt;
  2260. echo '
  2261. <form action="', $incontext['form_url'], '" method="post">
  2262. <p>', $txt['user_settings_info'], '</p>';
  2263. template_warning_divs();
  2264. echo '
  2265. <table width="100%" cellspacing="0" cellpadding="0" border="0" style="margin: 2em 0;">
  2266. <tr>
  2267. <td width="18%" valign="top" class="textbox"><label for="username">', $txt['user_settings_username'], ':</label></td>
  2268. <td>
  2269. <input type="text" name="username" id="username" value="', $incontext['username'], '" size="40" class="input_text" />
  2270. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['user_settings_username_info'], '</div>
  2271. </td>
  2272. </tr><tr>
  2273. <td valign="top" class="textbox"><label for="password1">', $txt['user_settings_password'], ':</label></td>
  2274. <td>
  2275. <input type="password" name="password1" id="password1" size="40" class="input_password" />
  2276. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['user_settings_password_info'], '</div>
  2277. </td>
  2278. </tr><tr>
  2279. <td valign="top" class="textbox"><label for="password2">', $txt['user_settings_again'], ':</label></td>
  2280. <td>
  2281. <input type="password" name="password2" id="password2" size="40" class="input_password" />
  2282. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['user_settings_again_info'], '</div>
  2283. </td>
  2284. </tr><tr>
  2285. <td valign="top" class="textbox"><label for="email">', $txt['user_settings_email'], ':</label></td>
  2286. <td>
  2287. <input type="text" name="email" id="email" value="', $incontext['email'], '" size="40" class="input_text" />
  2288. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['user_settings_email_info'], '</div>
  2289. </td>
  2290. </tr>
  2291. </table>';
  2292. if ($incontext['require_db_confirm'])
  2293. echo '
  2294. <h2>', $txt['user_settings_database'], '</h2>
  2295. <p>', $txt['user_settings_database_info'], '</p>
  2296. <div style="margin-bottom: 2ex; padding-', empty($txt['lang_rtl']) ? 'left' : 'right', ': 50px;">
  2297. <input type="password" name="password3" size="30" class="input_password" />
  2298. </div>';
  2299. }
  2300. // Tell them it's done, and to delete.
  2301. function template_delete_install()
  2302. {
  2303. global $incontext, $installurl, $txt, $boardurl;
  2304. echo '
  2305. <p>', $txt['congratulations_help'], '</p>';
  2306. template_warning_divs();
  2307. // Install directory still writable?
  2308. if ($incontext['dir_still_writable'])
  2309. echo '
  2310. <em>', $txt['still_writable'], '</em><br />
  2311. <br />';
  2312. // Don't show the box if it's like 99% sure it won't work :P.
  2313. if ($incontext['probably_delete_install'])
  2314. echo '
  2315. <div style="margin: 1ex; font-weight: bold;">
  2316. <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
  2317. </div>
  2318. <script><!-- // --><![CDATA[
  2319. function doTheDelete()
  2320. {
  2321. var theCheck = document.getElementById ? document.getElementById("delete_self") : document.all.delete_self;
  2322. var tempImage = new Image();
  2323. tempImage.src = "', $installurl, '?delete=1&ts_" + (new Date().getTime());
  2324. tempImage.width = 0;
  2325. theCheck.disabled = true;
  2326. }
  2327. // ]]></script>
  2328. <br />';
  2329. echo '
  2330. ', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br />
  2331. <br />
  2332. ', $txt['good_luck'];
  2333. }
  2334. ?>