install.php 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723
  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. if (isset($db['default_port']))
  661. $incontext['db_port'] = ini_get($db['default_port']);
  662. elseif ($key == 'postgresql')
  663. $incontext['db_port'] = 5432;
  664. $incontext['db']['type'] = $key;
  665. $foundOne = true;
  666. }
  667. }
  668. }
  669. // Override for repost.
  670. if (isset($_POST['db_user']))
  671. {
  672. $incontext['db']['user'] = $_POST['db_user'];
  673. $incontext['db']['name'] = ($_POST['db_type'] == 'sqlite' || $_POST['db_type'] == 'sqlite3') && isset($_POST['db_filename']) ? $_POST['db_filename'] : $_POST['db_name'];
  674. $incontext['db']['server'] = $_POST['db_server'];
  675. $incontext['db']['prefix'] = $_POST['db_prefix'];
  676. $incontext['db']['port'] = empty($_POST['db_port']) ? '' : $_POST['db_port'];
  677. }
  678. else
  679. {
  680. $incontext['db']['prefix'] = 'smf_';
  681. }
  682. // Are we submitting?
  683. if (isset($_POST['db_type']))
  684. {
  685. if (isset($_POST['db_filename']))
  686. {
  687. // You better enter enter a database name for SQLite.
  688. if (trim($_POST['db_filename']) == '')
  689. {
  690. $incontext['error'] = $txt['error_db_filename'];
  691. return false;
  692. }
  693. // Duplicate name in the same dir? Can't do that with SQLite. Weird things happen.
  694. if (file_exists($_POST['db_filename'] . (substr($_POST['db_filename'], -3) != '.db' ? '.db' : '')))
  695. {
  696. $incontext['error'] = $txt['error_db_filename_exists'];
  697. return false;
  698. }
  699. }
  700. // What type are they trying?
  701. $db_type = preg_replace('~[^A-Za-z0-9]~', '', $_POST['db_type']);
  702. $db_prefix = $_POST['db_prefix'];
  703. // Validate the prefix.
  704. $valid_prefix = $databases[$db_type]['validate_prefix']($db_prefix);
  705. if ($valid_prefix !== true)
  706. {
  707. $incontext['error'] = $valid_prefix;
  708. return false;
  709. }
  710. // Take care of these variables...
  711. $vars = array(
  712. 'db_type' => $db_type,
  713. 'db_name' => ($_POST['db_type'] == 'sqlite' || $_POST['db_type'] == 'sqlite3') && isset($_POST['db_filename']) ? $_POST['db_filename'] : $_POST['db_name'],
  714. 'db_user' => $_POST['db_user'],
  715. 'db_passwd' => isset($_POST['db_passwd']) ? $_POST['db_passwd'] : '',
  716. 'db_server' => $_POST['db_server'],
  717. 'db_prefix' => $db_prefix,
  718. // The cookiename is special; we want it to be the same if it ever needs to be reinstalled with the same info.
  719. 'cookiename' => 'SMFCookie' . abs(crc32($_POST['db_name'] . preg_replace('~[^A-Za-z0-9_$]~', '', $_POST['db_prefix'])) % 1000),
  720. );
  721. // Only set the port if we're not using the default
  722. if (!empty($_POST['db_port']))
  723. {
  724. // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
  725. if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
  726. $vars['db_port'] == (int) $_POST['db_port'];
  727. elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
  728. $vars['db_port'] == (int) $_POST['db_port'];
  729. }
  730. // God I hope it saved!
  731. if (!updateSettingsFile($vars) && substr(__FILE__, 1, 2) == ':\\')
  732. {
  733. $incontext['error'] = $txt['error_windows_chmod'];
  734. return false;
  735. }
  736. // Make sure it works.
  737. require(dirname(__FILE__) . '/Settings.php');
  738. if (empty($sourcedir))
  739. $sourcedir = dirname(__FILE__) . '/Sources';
  740. // Better find the database file!
  741. if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
  742. {
  743. $incontext['error'] = sprintf($txt['error_db_file'], 'Subs-Db-' . $db_type . '.php');
  744. return false;
  745. }
  746. // Now include it for database functions!
  747. define('SMF', 1);
  748. $modSettings['disableQueryCheck'] = true;
  749. if (empty($smcFunc))
  750. $smcFunc = array();
  751. require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
  752. // What - running PHP4? The shame!
  753. if (version_compare(PHP_VERSION, '5', '<'))
  754. require_once($sourcedir . '/Subs-Compat.php');
  755. // Attempt a connection.
  756. $needsDB = !empty($databases[$db_type]['always_has_db']);
  757. $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true, 'dont_select_db' => !$needsDB));
  758. // No dice? Let's try adding the prefix they specified, just in case they misread the instructions ;)
  759. if ($db_connection == null)
  760. {
  761. $db_error = @$smcFunc['db_error']();
  762. $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));
  763. if ($db_connection != null)
  764. {
  765. $db_user = $_POST['db_prefix'] . $db_user;
  766. updateSettingsFile(array('db_user' => $db_user));
  767. }
  768. }
  769. // Still no connection? Big fat error message :P.
  770. if (!$db_connection)
  771. {
  772. $incontext['error'] = $txt['error_db_connect'] . '<div style="margin: 2.5ex; font-family: monospace;"><strong>' . $db_error . '</strong></div>';
  773. return false;
  774. }
  775. // Do they meet the install requirements?
  776. // @todo Old client, new server?
  777. if (version_compare($databases[$db_type]['version'], preg_replace('~^\D*|\-.+?$~', '', eval($databases[$db_type]['version_check']))) > 0)
  778. {
  779. $incontext['error'] = $txt['error_db_too_low'];
  780. return false;
  781. }
  782. // Let's try that database on for size... assuming we haven't already lost the opportunity.
  783. if ($db_name != '' && !$needsDB)
  784. {
  785. $smcFunc['db_query']('', "
  786. CREATE DATABASE IF NOT EXISTS `$db_name`",
  787. array(
  788. 'security_override' => true,
  789. 'db_error_skip' => true,
  790. ),
  791. $db_connection
  792. );
  793. // Okay, let's try the prefix if it didn't work...
  794. if (!$smcFunc['db_select_db']($db_name, $db_connection) && $db_name != '')
  795. {
  796. $smcFunc['db_query']('', "
  797. CREATE DATABASE IF NOT EXISTS `$_POST[db_prefix]$db_name`",
  798. array(
  799. 'security_override' => true,
  800. 'db_error_skip' => true,
  801. ),
  802. $db_connection
  803. );
  804. if ($smcFunc['db_select_db']($_POST['db_prefix'] . $db_name, $db_connection))
  805. {
  806. $db_name = $_POST['db_prefix'] . $db_name;
  807. updateSettingsFile(array('db_name' => $db_name));
  808. }
  809. }
  810. // Okay, now let's try to connect...
  811. if (!$smcFunc['db_select_db']($db_name, $db_connection))
  812. {
  813. $incontext['error'] = sprintf($txt['error_db_database'], $db_name);
  814. return false;
  815. }
  816. }
  817. return true;
  818. }
  819. return false;
  820. }
  821. // Let's start with basic forum type settings.
  822. function ForumSettings()
  823. {
  824. global $txt, $incontext, $databases, $smcFunc, $db_connection, $db_type, $boardurl;
  825. $incontext['sub_template'] = 'forum_settings';
  826. $incontext['page_title'] = $txt['install_settings'];
  827. // Let's see if we got the database type correct.
  828. if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
  829. $db_type = $_POST['db_type'];
  830. // Else we'd better be able to get the connection.
  831. else
  832. load_database();
  833. $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
  834. // What host and port are we on?
  835. $host = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
  836. // Now, to put what we've learned together... and add a path.
  837. $incontext['detected_url'] = 'http' . (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
  838. // Check if the database sessions will even work.
  839. $incontext['test_dbsession'] = (ini_get('session.auto_start') != 1);
  840. $incontext['utf8_default'] = $databases[$db_type]['utf8_default'];
  841. $incontext['utf8_required'] = $databases[$db_type]['utf8_required'];
  842. $incontext['continue'] = 1;
  843. // Submitting?
  844. if (isset($_POST['boardurl']))
  845. {
  846. if (substr($_POST['boardurl'], -10) == '/index.php')
  847. $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
  848. elseif (substr($_POST['boardurl'], -1) == '/')
  849. $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
  850. if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
  851. $_POST['boardurl'] = 'http://' . $_POST['boardurl'];
  852. // Save these variables.
  853. $vars = array(
  854. 'boardurl' => $_POST['boardurl'],
  855. 'boarddir' => addslashes(dirname(__FILE__)),
  856. 'sourcedir' => addslashes(dirname(__FILE__)) . '/Sources',
  857. 'cachedir' => addslashes(dirname(__FILE__)) . '/cache',
  858. 'mbname' => strtr($_POST['mbname'], array('\"' => '"')),
  859. 'language' => substr($_SESSION['installer_temp_lang'], 8, -4),
  860. );
  861. // Must save!
  862. if (!updateSettingsFile($vars) && substr(__FILE__, 1, 2) == ':\\')
  863. {
  864. $incontext['error'] = $txt['error_windows_chmod'];
  865. return false;
  866. }
  867. // Make sure it works.
  868. require(dirname(__FILE__) . '/Settings.php');
  869. // UTF-8 requires a setting to override the language charset.
  870. 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'])))
  871. {
  872. if (!empty($databases[$db_type]['utf8_version_check']) && version_compare($databases[$db_type]['utf8_version'], preg_replace('~\-.+?$~', '', eval($databases[$db_type]['utf8_version_check'])), '>'))
  873. {
  874. $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
  875. return false;
  876. }
  877. else
  878. // Set the character set here.
  879. updateSettingsFile(array('db_character_set' => 'utf8'));
  880. }
  881. // Good, skip on.
  882. return true;
  883. }
  884. return false;
  885. }
  886. // Step one: Do the SQL thang.
  887. function DatabasePopulation()
  888. {
  889. global $db_character_set, $txt, $db_connection, $smcFunc, $databases, $modSettings, $db_type, $sourcedir, $db_prefix, $incontext, $db_name, $boardurl;
  890. $incontext['sub_template'] = 'populate_database';
  891. $incontext['page_title'] = $txt['db_populate'];
  892. $incontext['continue'] = 1;
  893. // Already done?
  894. if (isset($_POST['pop_done']))
  895. return true;
  896. // Reload settings.
  897. require(dirname(__FILE__) . '/Settings.php');
  898. load_database();
  899. // Before running any of the queries, let's make sure another version isn't already installed.
  900. $result = $smcFunc['db_query']('', '
  901. SELECT variable, value
  902. FROM {db_prefix}settings',
  903. array(
  904. 'db_error_skip' => true,
  905. )
  906. );
  907. $modSettings = array();
  908. if ($result !== false)
  909. {
  910. while ($row = $smcFunc['db_fetch_assoc']($result))
  911. $modSettings[$row['variable']] = $row['value'];
  912. $smcFunc['db_free_result']($result);
  913. // Do they match? If so, this is just a refresh so charge on!
  914. if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] != $GLOBALS['current_smf_version'])
  915. {
  916. $incontext['error'] = $txt['error_versions_do_not_match'];
  917. return false;
  918. }
  919. }
  920. $modSettings['disableQueryCheck'] = true;
  921. // If doing UTF8, select it. PostgreSQL requires passing it as a string...
  922. if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
  923. $smcFunc['db_query']('', '
  924. SET NAMES {'. ($db_type == 'postgresql' ? 'string' : 'raw') . ':utf8}',
  925. array(
  926. 'db_error_skip' => true,
  927. 'utf8' => 'utf8',
  928. )
  929. );
  930. $replaces = array(
  931. '{$db_prefix}' => $db_prefix,
  932. '{$boarddir}' => $smcFunc['db_escape_string'](dirname(__FILE__)),
  933. '{$boardurl}' => $boardurl,
  934. '{$enableCompressedOutput}' => isset($_POST['compress']) ? '1' : '0',
  935. '{$databaseSession_enable}' => isset($_POST['dbsession']) ? '1' : '0',
  936. '{$smf_version}' => $GLOBALS['current_smf_version'],
  937. '{$current_time}' => time(),
  938. '{$sched_task_offset}' => 82800 + mt_rand(0, 86399),
  939. '{$registration_method}' => isset($_POST['reg_mode']) ? $_POST['reg_mode'] : 0,
  940. );
  941. foreach ($txt as $key => $value)
  942. {
  943. if (substr($key, 0, 8) == 'default_')
  944. $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
  945. }
  946. $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
  947. // If the UTF-8 setting was enabled, add it to the table definitions.
  948. if (!empty($databases[$db_type]['utf8_support']) && (!empty($databases[$db_type]['utf8_required']) || isset($_POST['utf8'])))
  949. $replaces[') ENGINE=MyISAM;'] = ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;';
  950. // Read in the SQL. Turn this on and that off... internationalize... etc.
  951. $type = ($db_type == 'mysqli') ? 'mysql' : $db_type;
  952. $sql_lines = explode("\n", strtr(implode(' ', file(dirname(__FILE__) . '/install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql')), $replaces));
  953. // Execute the SQL.
  954. $current_statement = '';
  955. $exists = array();
  956. $incontext['failures'] = array();
  957. $incontext['sql_results'] = array(
  958. 'tables' => 0,
  959. 'inserts' => 0,
  960. 'table_dups' => 0,
  961. 'insert_dups' => 0,
  962. );
  963. foreach ($sql_lines as $count => $line)
  964. {
  965. // No comments allowed!
  966. if (substr(trim($line), 0, 1) != '#')
  967. $current_statement .= "\n" . rtrim($line);
  968. // Is this the end of the query string?
  969. if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
  970. continue;
  971. // Does this table already exist? If so, don't insert more data into it!
  972. if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
  973. {
  974. $incontext['sql_results']['insert_dups']++;
  975. $current_statement = '';
  976. continue;
  977. }
  978. if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
  979. {
  980. // Use the appropriate function based on the DB type
  981. if ($db_type == 'mysql' || $db_type =='mysqli')
  982. $db_errorno = $db_type . '_errno';
  983. // Error 1050: Table already exists!
  984. // @todo Needs to be made better!
  985. if ((($db_type != 'mysql' && $db_type != 'mysqli') || $db_errorno($db_connection) == 1050) && preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
  986. {
  987. $exists[] = $match[1];
  988. $incontext['sql_results']['table_dups']++;
  989. }
  990. // Don't error on duplicate indexes (or duplicate operators in PostgreSQL.)
  991. 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)))
  992. {
  993. // MySQLi requires a connection object. It's optional with MySQL, Postgres and sqlite
  994. $incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
  995. }
  996. }
  997. else
  998. {
  999. if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
  1000. $incontext['sql_results']['tables']++;
  1001. else
  1002. {
  1003. preg_match_all('~\)[,;]~', $current_statement, $matches);
  1004. if (!empty($matches[0]))
  1005. $incontext['sql_results']['inserts'] += count($matches[0]);
  1006. else
  1007. $incontext['sql_results']['inserts']++;
  1008. }
  1009. }
  1010. $current_statement = '';
  1011. }
  1012. // Sort out the context for the SQL.
  1013. foreach ($incontext['sql_results'] as $key => $number)
  1014. {
  1015. if ($number == 0)
  1016. unset($incontext['sql_results'][$key]);
  1017. else
  1018. $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
  1019. }
  1020. // Make sure UTF will be used globally.
  1021. 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'])))
  1022. $smcFunc['db_insert']('replace',
  1023. $db_prefix . 'settings',
  1024. array(
  1025. 'variable' => 'string-255', 'value' => 'string-65534',
  1026. ),
  1027. array(
  1028. 'global_character_set', 'UTF-8',
  1029. ),
  1030. array('variable')
  1031. );
  1032. // Maybe we can auto-detect better cookie settings?
  1033. preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
  1034. if (!empty($matches))
  1035. {
  1036. // Default = both off.
  1037. $localCookies = false;
  1038. $globalCookies = false;
  1039. // Okay... let's see. Using a subdomain other than www.? (not a perfect check.)
  1040. if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
  1041. $globalCookies = true;
  1042. // If there's a / in the middle of the path, or it starts with ~... we want local.
  1043. if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
  1044. $localCookies = true;
  1045. if ($globalCookies)
  1046. $rows[] = array('globalCookies', '1');
  1047. if ($localCookies)
  1048. $rows[] = array('localCookies', '1');
  1049. if (!empty($rows))
  1050. {
  1051. $smcFunc['db_insert']('replace',
  1052. $db_prefix . 'settings',
  1053. array('variable' => 'string-255', 'value' => 'string-65534'),
  1054. $rows,
  1055. array('variable')
  1056. );
  1057. }
  1058. }
  1059. // Are we allowing stat collection?
  1060. if (isset($_POST['stats']) && strpos($_POST['boardurl'], 'http://localhost') !== 0)
  1061. {
  1062. // Attempt to register the site etc.
  1063. $fp = @fsockopen("www.simplemachines.org", 80, $errno, $errstr);
  1064. if ($fp)
  1065. {
  1066. $out = "GET /smf/stats/register_stats.php?site=" . base64_encode($_POST['boardurl']) . " HTTP/1.1\r\n";
  1067. $out .= "Host: www.simplemachines.org\r\n";
  1068. $out .= "Connection: Close\r\n\r\n";
  1069. fwrite($fp, $out);
  1070. $return_data = '';
  1071. while (!feof($fp))
  1072. $return_data .= fgets($fp, 128);
  1073. fclose($fp);
  1074. // Get the unique site ID.
  1075. preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
  1076. if (!empty($ID[1]))
  1077. $smcFunc['db_insert']('',
  1078. $db_prefix . 'settings',
  1079. array(
  1080. 'variable' => 'string-255', 'value' => 'string-65534',
  1081. ),
  1082. array(
  1083. 'allow_sm_stats', $ID[1],
  1084. ),
  1085. array('variable')
  1086. );
  1087. }
  1088. }
  1089. // As of PHP 5.1, setting a timezone is required.
  1090. if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
  1091. {
  1092. $server_offset = mktime(0, 0, 0, 1, 1, 1970);
  1093. $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600);
  1094. if (date_default_timezone_set($timezone_id))
  1095. $smcFunc['db_insert']('',
  1096. $db_prefix . 'settings',
  1097. array(
  1098. 'variable' => 'string-255', 'value' => 'string-65534',
  1099. ),
  1100. array(
  1101. 'default_timezone', $timezone_id,
  1102. ),
  1103. array('variable')
  1104. );
  1105. }
  1106. // Let's optimize those new tables.
  1107. db_extend();
  1108. $tables = $smcFunc['db_list_tables']($db_name, $db_prefix . '%');
  1109. foreach ($tables as $table)
  1110. {
  1111. $smcFunc['db_optimize_table']($table) != -1 or $db_messed = true;
  1112. // Optimizing one sqlite table, optimizes them all
  1113. if ($db_type == 'sqlite' || $db_type == 'sqlite3')
  1114. break;
  1115. if (!empty($db_messed))
  1116. {
  1117. $incontext['failures'][-1] = $smcFunc['db_error']();
  1118. break;
  1119. }
  1120. }
  1121. // Check for the ALTER privilege.
  1122. 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)
  1123. {
  1124. $incontext['error'] = $txt['error_db_alter_priv'];
  1125. return false;
  1126. }
  1127. if (!empty($exists))
  1128. {
  1129. $incontext['page_title'] = $txt['user_refresh_install'];
  1130. $incontext['was_refresh'] = true;
  1131. }
  1132. return false;
  1133. }
  1134. // Ask for the administrator login information.
  1135. function AdminAccount()
  1136. {
  1137. global $txt, $db_type, $db_connection, $databases, $smcFunc, $incontext, $db_prefix, $db_passwd, $sourcedir;
  1138. $incontext['sub_template'] = 'admin_account';
  1139. $incontext['page_title'] = $txt['user_settings'];
  1140. $incontext['continue'] = 1;
  1141. // Skipping?
  1142. if (!empty($_POST['skip']))
  1143. return true;
  1144. // Need this to check whether we need the database password.
  1145. require(dirname(__FILE__) . '/Settings.php');
  1146. load_database();
  1147. // Define the sha1 function, if it doesn't exist.
  1148. if (!function_exists('sha1') || version_compare(PHP_VERSION, '5', '<'))
  1149. require_once($sourcedir . '/Subs-Compat.php');
  1150. if (!isset($_POST['username']))
  1151. $_POST['username'] = '';
  1152. if (!isset($_POST['email']))
  1153. $_POST['email'] = '';
  1154. $incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
  1155. $incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
  1156. $incontext['require_db_confirm'] = empty($db_type) || ($db_type != 'sqlite' && $db_type != 'sqlite3');
  1157. // Only allow skipping if we think they already have an account setup.
  1158. $request = $smcFunc['db_query']('', '
  1159. SELECT id_member
  1160. FROM {db_prefix}members
  1161. WHERE id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0
  1162. LIMIT 1',
  1163. array(
  1164. 'db_error_skip' => true,
  1165. 'admin_group' => 1,
  1166. )
  1167. );
  1168. if ($smcFunc['db_num_rows']($request) != 0)
  1169. $incontext['skip'] = 1;
  1170. $smcFunc['db_free_result']($request);
  1171. // Trying to create an account?
  1172. if (isset($_POST['password1']) && !empty($_POST['contbutt']))
  1173. {
  1174. // Wrong password?
  1175. if ($incontext['require_db_confirm'] && $_POST['password3'] != $db_passwd)
  1176. {
  1177. $incontext['error'] = $txt['error_db_connect'];
  1178. return false;
  1179. }
  1180. // Not matching passwords?
  1181. if ($_POST['password1'] != $_POST['password2'])
  1182. {
  1183. $incontext['error'] = $txt['error_user_settings_again_match'];
  1184. return false;
  1185. }
  1186. // No password?
  1187. if (strlen($_POST['password1']) < 4)
  1188. {
  1189. $incontext['error'] = $txt['error_user_settings_no_password'];
  1190. return false;
  1191. }
  1192. if (!file_exists($sourcedir . '/Subs.php'))
  1193. {
  1194. $incontext['error'] = $txt['error_subs_missing'];
  1195. return false;
  1196. }
  1197. // Update the main contact email?
  1198. if (!empty($_POST['email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
  1199. updateSettingsFile(array('webmaster_email' => $_POST['email']));
  1200. // Work out whether we're going to have dodgy characters and remove them.
  1201. $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
  1202. $_POST['username'] = preg_replace('~[<>&"\'=\\\]~', '', $_POST['username']);
  1203. $result = $smcFunc['db_query']('', '
  1204. SELECT id_member, password_salt
  1205. FROM {db_prefix}members
  1206. WHERE member_name = {string:username} OR email_address = {string:email}
  1207. LIMIT 1',
  1208. array(
  1209. 'username' => stripslashes($_POST['username']),
  1210. 'email' => stripslashes($_POST['email']),
  1211. 'db_error_skip' => true,
  1212. )
  1213. );
  1214. if ($smcFunc['db_num_rows']($result) != 0)
  1215. {
  1216. list ($incontext['member_id'], $incontext['member_salt']) = $smcFunc['db_fetch_row']($result);
  1217. $smcFunc['db_free_result']($result);
  1218. $incontext['account_existed'] = $txt['error_user_settings_taken'];
  1219. }
  1220. elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
  1221. {
  1222. // Try the previous step again.
  1223. $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
  1224. return false;
  1225. }
  1226. elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
  1227. {
  1228. // Try the previous step again.
  1229. $incontext['error'] = $txt['error_invalid_characters_username'];
  1230. return false;
  1231. }
  1232. 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)
  1233. {
  1234. // One step back, this time fill out a proper email address.
  1235. $incontext['error'] = sprintf($txt['error_valid_email_needed'], $_POST['username']);
  1236. return false;
  1237. }
  1238. elseif ($_POST['username'] != '')
  1239. {
  1240. $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
  1241. // Format the username properly.
  1242. $_POST['username'] = preg_replace('~[\t\n\r\x0B\0\xA0]+~', ' ', $_POST['username']);
  1243. $ip = isset($_SERVER['REMOTE_ADDR']) ? substr($_SERVER['REMOTE_ADDR'], 0, 255) : '';
  1244. $request = $smcFunc['db_insert']('',
  1245. $db_prefix . 'members',
  1246. array(
  1247. 'member_name' => 'string-25', 'real_name' => 'string-25', 'passwd' => 'string', 'email_address' => 'string',
  1248. 'id_group' => 'int', 'posts' => 'int', 'date_registered' => 'int', 'hide_email' => 'int',
  1249. 'password_salt' => 'string', 'lngfile' => 'string', 'personal_text' => 'string', 'avatar' => 'string',
  1250. 'member_ip' => 'string', 'member_ip2' => 'string', 'buddy_list' => 'string', 'pm_ignore_list' => 'string',
  1251. 'website_title' => 'string', 'website_url' => 'string', 'location' => 'string',
  1252. 'aim' => 'string', 'icq' => 'string', 'skype' => 'string', 'signature' => 'string', 'usertitle' => 'string', 'secret_question' => 'string',
  1253. 'additional_groups' => 'string', 'ignore_boards' => 'string', 'openid_uri' => 'string',
  1254. ),
  1255. array(
  1256. stripslashes($_POST['username']), stripslashes($_POST['username']), sha1(strtolower(stripslashes($_POST['username'])) . stripslashes($_POST['password1'])), stripslashes($_POST['email']),
  1257. 1, 0, time(), 0,
  1258. $incontext['member_salt'], '', '', '',
  1259. $ip, $ip, '', '',
  1260. '', '', '',
  1261. '', '', '', '', '', '',
  1262. '', '', '',
  1263. ),
  1264. array('id_member')
  1265. );
  1266. // Awww, crud!
  1267. if ($request === false)
  1268. {
  1269. $incontext['error'] = $txt['error_user_settings_query'] . '<br>
  1270. <div style="margin: 2ex;">' . nl2br(htmlspecialchars($smcFunc['db_error']($db_connection))) . '</div>';
  1271. return false;
  1272. }
  1273. $incontext['member_id'] = $smcFunc['db_insert_id']("{$db_prefix}members", 'id_member');
  1274. }
  1275. // If we're here we're good.
  1276. return true;
  1277. }
  1278. return false;
  1279. }
  1280. // Final step, clean up and a complete message!
  1281. function DeleteInstall()
  1282. {
  1283. global $txt, $db_prefix, $db_connection, $HTTP_SESSION_VARS, $cookiename, $incontext;
  1284. global $smcFunc, $db_character_set, $mbname, $context, $scripturl, $boardurl;
  1285. global $current_smf_version, $databases, $sourcedir, $forum_version, $modSettings, $user_info, $language, $db_type;
  1286. $incontext['page_title'] = $txt['congratulations'];
  1287. $incontext['sub_template'] = 'delete_install';
  1288. $incontext['continue'] = 0;
  1289. require(dirname(__FILE__) . '/Settings.php');
  1290. load_database();
  1291. chdir(dirname(__FILE__));
  1292. require_once($sourcedir . '/Errors.php');
  1293. require_once($sourcedir . '/Logging.php');
  1294. require_once($sourcedir . '/Subs.php');
  1295. require_once($sourcedir . '/Load.php');
  1296. require_once($sourcedir . '/Security.php');
  1297. require_once($sourcedir . '/Subs-Auth.php');
  1298. // Bring a warning over.
  1299. if (!empty($incontext['account_existed']))
  1300. $incontext['warning'] = $incontext['account_existed'];
  1301. if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
  1302. $smcFunc['db_query']('', '
  1303. SET NAMES {raw:db_character_set}',
  1304. array(
  1305. 'db_character_set' => $db_character_set,
  1306. 'db_error_skip' => true,
  1307. )
  1308. );
  1309. // As track stats is by default enabled let's add some activity.
  1310. $smcFunc['db_insert']('ignore',
  1311. '{db_prefix}log_activity',
  1312. array('date' => 'date', 'topics' => 'int', 'posts' => 'int', 'registers' => 'int'),
  1313. array(strftime('%Y-%m-%d', time()), 1, 1, (!empty($incontext['member_id']) ? 1 : 0)),
  1314. array('date')
  1315. );
  1316. // We're going to want our lovely $modSettings now.
  1317. $request = $smcFunc['db_query']('', '
  1318. SELECT variable, value
  1319. FROM {db_prefix}settings',
  1320. array(
  1321. 'db_error_skip' => true,
  1322. )
  1323. );
  1324. // Only proceed if we can load the data.
  1325. if ($request)
  1326. {
  1327. while ($row = $smcFunc['db_fetch_row']($request))
  1328. $modSettings[$row[0]] = $row[1];
  1329. $smcFunc['db_free_result']($request);
  1330. }
  1331. // Automatically log them in ;)
  1332. if (isset($incontext['member_id']) && isset($incontext['member_salt']))
  1333. setLoginCookie(3153600 * 60, $incontext['member_id'], sha1(sha1(strtolower($_POST['username']) . $_POST['password1']) . $incontext['member_salt']));
  1334. $result = $smcFunc['db_query']('', '
  1335. SELECT value
  1336. FROM {db_prefix}settings
  1337. WHERE variable = {string:db_sessions}',
  1338. array(
  1339. 'db_sessions' => 'databaseSession_enable',
  1340. 'db_error_skip' => true,
  1341. )
  1342. );
  1343. if ($smcFunc['db_num_rows']($result) != 0)
  1344. list ($db_sessions) = $smcFunc['db_fetch_row']($result);
  1345. $smcFunc['db_free_result']($result);
  1346. if (empty($db_sessions))
  1347. $_SESSION['admin_time'] = time();
  1348. else
  1349. {
  1350. $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
  1351. $smcFunc['db_insert']('replace',
  1352. '{db_prefix}sessions',
  1353. array(
  1354. 'session_id' => 'string', 'last_update' => 'int', 'data' => 'string',
  1355. ),
  1356. array(
  1357. session_id(), time(), 'USER_AGENT|s:' . strlen($_SERVER['HTTP_USER_AGENT']) . ':"' . $_SERVER['HTTP_USER_AGENT'] . '";admin_time|i:' . time() . ';',
  1358. ),
  1359. array('session_id')
  1360. );
  1361. }
  1362. updateStats('member');
  1363. updateStats('message');
  1364. updateStats('topic');
  1365. // This function is needed to do the updateStats('subject') call.
  1366. $smcFunc['strtolower'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8' ? create_function('$string', '
  1367. return $string;') : 'strtolower';
  1368. $request = $smcFunc['db_query']('', '
  1369. SELECT id_msg
  1370. FROM {db_prefix}messages
  1371. WHERE id_msg = 1
  1372. AND modified_time = 0
  1373. LIMIT 1',
  1374. array(
  1375. 'db_error_skip' => true,
  1376. )
  1377. );
  1378. $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
  1379. if ($smcFunc['db_num_rows']($request) > 0)
  1380. updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
  1381. $smcFunc['db_free_result']($request);
  1382. // Now is the perfect time to fetch the SM files.
  1383. require_once($sourcedir . '/ScheduledTasks.php');
  1384. // Sanity check that they loaded earlier!
  1385. if (isset($modSettings['recycle_board']))
  1386. {
  1387. $forum_version = $current_smf_version; // The variable is usually defined in index.php so lets just use our variable to do it for us.
  1388. scheduled_fetchSMfiles(); // Now go get those files!
  1389. // We've just installed!
  1390. $user_info['ip'] = $_SERVER['REMOTE_ADDR'];
  1391. $user_info['id'] = isset($incontext['member_id']) ? $incontext['member_id'] : 0;
  1392. logAction('install', array('version' => $forum_version), 'admin');
  1393. }
  1394. // Check if we need some stupid MySQL fix.
  1395. $server_version = $smcFunc['db_server_info']();
  1396. if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
  1397. updateSettings(array('db_mysql_group_by_fix' => '1'));
  1398. // Some final context for the template.
  1399. $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
  1400. $incontext['probably_delete_install'] = isset($_SESSION['installer_temp_ftp']) || is_writable(dirname(__FILE__)) || is_writable(__FILE__);
  1401. return false;
  1402. }
  1403. // http://www.faqs.org/rfcs/rfc959.html
  1404. class ftp_connection
  1405. {
  1406. var $connection = 'no_connection', $error = false, $last_message, $pasv = array();
  1407. // Create a new FTP connection...
  1408. function ftp_connection($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
  1409. {
  1410. if ($ftp_server !== null)
  1411. $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
  1412. }
  1413. function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
  1414. {
  1415. if (substr($ftp_server, 0, 6) == 'ftp://')
  1416. $ftp_server = substr($ftp_server, 6);
  1417. elseif (substr($ftp_server, 0, 7) == 'ftps://')
  1418. $ftp_server = 'ssl://' . substr($ftp_server, 7);
  1419. if (substr($ftp_server, 0, 7) == 'http://')
  1420. $ftp_server = substr($ftp_server, 7);
  1421. $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => ''));
  1422. // Connect to the FTP server.
  1423. $this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5);
  1424. if (!$this->connection)
  1425. {
  1426. $this->error = 'bad_server';
  1427. return;
  1428. }
  1429. // Get the welcome message...
  1430. if (!$this->check_response(220))
  1431. {
  1432. $this->error = 'bad_response';
  1433. return;
  1434. }
  1435. // Send the username, it should ask for a password.
  1436. fwrite($this->connection, 'USER ' . $ftp_user . "\r\n");
  1437. if (!$this->check_response(331))
  1438. {
  1439. $this->error = 'bad_username';
  1440. return;
  1441. }
  1442. // Now send the password... and hope it goes okay.
  1443. fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n");
  1444. if (!$this->check_response(230))
  1445. {
  1446. $this->error = 'bad_password';
  1447. return;
  1448. }
  1449. }
  1450. function chdir($ftp_path)
  1451. {
  1452. if (!is_resource($this->connection))
  1453. return false;
  1454. // No slash on the end, please...
  1455. if (substr($ftp_path, -1) == '/')
  1456. $ftp_path = substr($ftp_path, 0, -1);
  1457. fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n");
  1458. if (!$this->check_response(250))
  1459. {
  1460. $this->error = 'bad_path';
  1461. return false;
  1462. }
  1463. return true;
  1464. }
  1465. function chmod($ftp_file, $chmod)
  1466. {
  1467. if (!is_resource($this->connection))
  1468. return false;
  1469. // Convert the chmod value from octal (0777) to text ("777")
  1470. fwrite($this->connection, 'SITE CHMOD ' . decoct($chmod) . ' ' . $ftp_file . "\r\n");
  1471. if (!$this->check_response(200))
  1472. {
  1473. $this->error = 'bad_file';
  1474. return false;
  1475. }
  1476. return true;
  1477. }
  1478. function unlink($ftp_file)
  1479. {
  1480. // We are actually connected, right?
  1481. if (!is_resource($this->connection))
  1482. return false;
  1483. // Delete file X.
  1484. fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n");
  1485. if (!$this->check_response(250))
  1486. {
  1487. fwrite($this->connection, 'RMD ' . $ftp_file . "\r\n");
  1488. // Still no love?
  1489. if (!$this->check_response(250))
  1490. {
  1491. $this->error = 'bad_file';
  1492. return false;
  1493. }
  1494. }
  1495. return true;
  1496. }
  1497. function check_response($desired)
  1498. {
  1499. // Wait for a response that isn't continued with -, but don't wait too long.
  1500. $time = time();
  1501. do
  1502. $this->last_message = fgets($this->connection, 1024);
  1503. while (substr($this->last_message, 3, 1) != ' ' && time() - $time < 5);
  1504. // Was the desired response returned?
  1505. return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
  1506. }
  1507. function passive()
  1508. {
  1509. // We can't create a passive data connection without a primary one first being there.
  1510. if (!is_resource($this->connection))
  1511. return false;
  1512. // Request a passive connection - this means, we'll talk to you, you don't talk to us.
  1513. @fwrite($this->connection, "PASV\r\n");
  1514. $time = time();
  1515. do
  1516. $response = fgets($this->connection, 1024);
  1517. while (substr($response, 3, 1) != ' ' && time() - $time < 5);
  1518. // If it's not 227, we weren't given an IP and port, which means it failed.
  1519. if (substr($response, 0, 4) != '227 ')
  1520. {
  1521. $this->error = 'bad_response';
  1522. return false;
  1523. }
  1524. // Snatch the IP and port information, or die horribly trying...
  1525. if (preg_match('~\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))\)~', $response, $match) == 0)
  1526. {
  1527. $this->error = 'bad_response';
  1528. return false;
  1529. }
  1530. // This is pretty simple - store it for later use ;)
  1531. $this->pasv = array('ip' => $match[1] . '.' . $match[2] . '.' . $match[3] . '.' . $match[4], 'port' => $match[5] * 256 + $match[6]);
  1532. return true;
  1533. }
  1534. function create_file($ftp_file)
  1535. {
  1536. // First, we have to be connected... very important.
  1537. if (!is_resource($this->connection))
  1538. return false;
  1539. // I'd like one passive mode, please!
  1540. if (!$this->passive())
  1541. return false;
  1542. // Seems logical enough, so far...
  1543. fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n");
  1544. // Okay, now we connect to the data port. If it doesn't work out, it's probably "file already exists", etc.
  1545. $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
  1546. if (!$fp || !$this->check_response(150))
  1547. {
  1548. $this->error = 'bad_file';
  1549. @fclose($fp);
  1550. return false;
  1551. }
  1552. // This may look strange, but we're just closing it to indicate a zero-byte upload.
  1553. fclose($fp);
  1554. if (!$this->check_response(226))
  1555. {
  1556. $this->error = 'bad_response';
  1557. return false;
  1558. }
  1559. return true;
  1560. }
  1561. function list_dir($ftp_path = '', $search = false)
  1562. {
  1563. // Are we even connected...?
  1564. if (!is_resource($this->connection))
  1565. return false;
  1566. // Passive... non-agressive...
  1567. if (!$this->passive())
  1568. return false;
  1569. // Get the listing!
  1570. fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n");
  1571. // Connect, assuming we've got a connection.
  1572. $fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
  1573. if (!$fp || !$this->check_response(array(150, 125)))
  1574. {
  1575. $this->error = 'bad_response';
  1576. @fclose($fp);
  1577. return false;
  1578. }
  1579. // Read in the file listing.
  1580. $data = '';
  1581. while (!feof($fp))
  1582. $data .= fread($fp, 4096);
  1583. fclose($fp);
  1584. // Everything go okay?
  1585. if (!$this->check_response(226))
  1586. {
  1587. $this->error = 'bad_response';
  1588. return false;
  1589. }
  1590. return $data;
  1591. }
  1592. function locate($file, $listing = null)
  1593. {
  1594. if ($listing === null)
  1595. $listing = $this->list_dir('', true);
  1596. $listing = explode("\n", $listing);
  1597. @fwrite($this->connection, "PWD\r\n");
  1598. $time = time();
  1599. do
  1600. $response = fgets($this->connection, 1024);
  1601. while (substr($response, 3, 1) != ' ' && time() - $time < 5);
  1602. // Check for 257!
  1603. if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0)
  1604. $current_dir = strtr($match[1], array('""' => '"'));
  1605. else
  1606. $current_dir = '';
  1607. for ($i = 0, $n = count($listing); $i < $n; $i++)
  1608. {
  1609. if (trim($listing[$i]) == '' && isset($listing[$i + 1]))
  1610. {
  1611. $current_dir = substr(trim($listing[++$i]), 0, -1);
  1612. $i++;
  1613. }
  1614. // Okay, this file's name is:
  1615. $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]);
  1616. if (substr($file, 0, 1) == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1))
  1617. return $listing[$i];
  1618. if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1))
  1619. return $listing[$i];
  1620. if (basename($listing[$i]) == $file || $listing[$i] == $file)
  1621. return $listing[$i];
  1622. }
  1623. return false;
  1624. }
  1625. function create_dir($ftp_dir)
  1626. {
  1627. // We must be connected to the server to do something.
  1628. if (!is_resource($this->connection))
  1629. return false;
  1630. // Make this new beautiful directory!
  1631. fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n");
  1632. if (!$this->check_response(257))
  1633. {
  1634. $this->error = 'bad_file';
  1635. return false;
  1636. }
  1637. return true;
  1638. }
  1639. function detect_path($filesystem_path, $lookup_file = null)
  1640. {
  1641. $username = '';
  1642. if (isset($_SERVER['DOCUMENT_ROOT']))
  1643. {
  1644. if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
  1645. {
  1646. $username = $match[1];
  1647. $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
  1648. if (substr($path, -1) == '/')
  1649. $path = substr($path, 0, -1);
  1650. if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
  1651. $path .= dirname($_SERVER['PHP_SELF']);
  1652. }
  1653. elseif (substr($filesystem_path, 0, 9) == '/var/www/')
  1654. $path = substr($filesystem_path, 8);
  1655. else
  1656. $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
  1657. }
  1658. else
  1659. $path = '';
  1660. if (is_resource($this->connection) && $this->list_dir($path) == '')
  1661. {
  1662. $data = $this->list_dir('', true);
  1663. if ($lookup_file === null)
  1664. $lookup_file = $_SERVER['PHP_SELF'];
  1665. $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
  1666. if ($found_path == false)
  1667. $found_path = dirname($this->locate(basename($lookup_file)));
  1668. if ($found_path != false)
  1669. $path = $found_path;
  1670. }
  1671. elseif (is_resource($this->connection))
  1672. $found_path = true;
  1673. return array($username, $path, isset($found_path));
  1674. }
  1675. function close()
  1676. {
  1677. // Goodbye!
  1678. fwrite($this->connection, "QUIT\r\n");
  1679. fclose($this->connection);
  1680. return true;
  1681. }
  1682. }
  1683. function updateSettingsFile($vars)
  1684. {
  1685. // Modify Settings.php.
  1686. $settingsArray = file(dirname(__FILE__) . '/Settings.php');
  1687. // @todo Do we just want to read the file in clean, and split it this way always?
  1688. if (count($settingsArray) == 1)
  1689. $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
  1690. for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
  1691. {
  1692. // Remove the redirect...
  1693. if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 3]) == '}')
  1694. {
  1695. // Get the four lines to nothing.
  1696. $settingsArray[$i] = '';
  1697. $settingsArray[++$i] = '';
  1698. $settingsArray[++$i] = '';
  1699. $settingsArray[++$i] = '';
  1700. continue;
  1701. }
  1702. if (trim($settingsArray[$i]) == '?' . '>')
  1703. $settingsArray[$i] = '';
  1704. // Don't trim or bother with it if it's not a variable.
  1705. if (substr($settingsArray[$i], 0, 1) != '$')
  1706. continue;
  1707. $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
  1708. foreach ($vars as $var => $val)
  1709. if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
  1710. {
  1711. $comment = strstr($settingsArray[$i], '#');
  1712. $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
  1713. unset($vars[$var]);
  1714. }
  1715. }
  1716. // Uh oh... the file wasn't empty... was it?
  1717. if (!empty($vars))
  1718. {
  1719. $settingsArray[$i++] = '';
  1720. foreach ($vars as $var => $val)
  1721. $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
  1722. }
  1723. // Blank out the file - done to fix a oddity with some servers.
  1724. $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
  1725. if (!$fp)
  1726. return false;
  1727. fclose($fp);
  1728. $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
  1729. // Gotta have one of these ;)
  1730. if (trim($settingsArray[0]) != '<?php')
  1731. fwrite($fp, "<?php\n");
  1732. $lines = count($settingsArray);
  1733. for ($i = 0; $i < $lines - 1; $i++)
  1734. {
  1735. // Don't just write a bunch of blank lines.
  1736. if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
  1737. fwrite($fp, strtr($settingsArray[$i], "\r", ''));
  1738. }
  1739. fwrite($fp, $settingsArray[$i] . '?' . '>');
  1740. fclose($fp);
  1741. // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
  1742. // it seems that there are times it might not. So let's MAKE it dump the cache.
  1743. if (function_exists('opcache_invalidate'))
  1744. opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
  1745. return true;
  1746. }
  1747. function updateDbLastError()
  1748. {
  1749. // Write out the db_last_error file with the error timestamp
  1750. file_put_contents(dirname(__FILE__) . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
  1751. return true;
  1752. }
  1753. // Create an .htaccess file to prevent mod_security. SMF has filtering built-in.
  1754. function fixModSecurity()
  1755. {
  1756. $htaccess_addition = '
  1757. <IfModule mod_security.c>
  1758. # Turn off mod_security filtering. SMF is a big boy, it doesn\'t need its hands held.
  1759. SecFilterEngine Off
  1760. # The below probably isn\'t needed, but better safe than sorry.
  1761. SecFilterScanPOST Off
  1762. </IfModule>';
  1763. if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
  1764. return true;
  1765. elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
  1766. {
  1767. $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
  1768. // Only change something if mod_security hasn't been addressed yet.
  1769. if (strpos($current_htaccess, '<IfModule mod_security.c>') === false)
  1770. {
  1771. if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'a'))
  1772. {
  1773. fwrite($ht_handle, $htaccess_addition);
  1774. fclose($ht_handle);
  1775. return true;
  1776. }
  1777. else
  1778. return false;
  1779. }
  1780. else
  1781. return true;
  1782. }
  1783. elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
  1784. return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
  1785. elseif (is_writable(dirname(__FILE__)))
  1786. {
  1787. if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
  1788. {
  1789. fwrite($ht_handle, $htaccess_addition);
  1790. fclose($ht_handle);
  1791. return true;
  1792. }
  1793. else
  1794. return false;
  1795. }
  1796. else
  1797. return false;
  1798. }
  1799. function template_install_above()
  1800. {
  1801. global $incontext, $txt, $smfsite, $installurl;
  1802. echo '<!DOCTYPE html>
  1803. <html', !empty($txt['lang_rtl']) ? ' dir="rtl"' : '', '>
  1804. <head>
  1805. <meta http-equiv="Content-Type" content="text/html; charset=', isset($txt['lang_character_set']) ? $txt['lang_character_set'] : 'ISO-8859-1', '">
  1806. <meta name="robots" content="noindex">
  1807. <title>', $txt['smf_installer'], '</title>
  1808. <link rel="stylesheet" type="text/css" href="Themes/default/css/index.css?alp21">
  1809. <link rel="stylesheet" type="text/css" href="Themes/default/css/install.css?alp21">
  1810. <script src="Themes/default/scripts/script.js"></script>
  1811. </head>
  1812. <body>
  1813. <div id="header">
  1814. <div class="frame">
  1815. <h1 class="forumtitle">', $txt['smf_installer'], '</h1>
  1816. <img id="smflogo" src="Themes/default/images/smflogo.png" alt="Simple Machines Forum" title="Simple Machines Forum">
  1817. </div>
  1818. <div id="wrapper">
  1819. <div id="upper_section">
  1820. <div id="inner_section">
  1821. <div id="inner_wrap">';
  1822. // Have we got a language drop down - if so do it on the first step only.
  1823. if (!empty($incontext['detected_languages']) && count($incontext['detected_languages']) > 1 && $incontext['current_step'] == 0)
  1824. {
  1825. echo '
  1826. <div class="news">
  1827. <form action="', $installurl, '" method="get">
  1828. <label for="installer_language">', $txt['installer_language'], ':</label>
  1829. <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
  1830. foreach ($incontext['detected_languages'] as $lang => $name)
  1831. echo '
  1832. <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
  1833. echo '
  1834. </select>
  1835. <noscript><input type="submit" value="', $txt['installer_language_set'], '" class="button_submit" /></noscript>
  1836. </form>
  1837. </div>
  1838. <hr class="clear" />';
  1839. }
  1840. echo '
  1841. </div>
  1842. </div>
  1843. </div>
  1844. <div id="content_section">
  1845. <div id="main_content_section">
  1846. <div id="main_steps">
  1847. <h2>', $txt['upgrade_progress'], '</h2>
  1848. <ul>';
  1849. foreach ($incontext['steps'] as $num => $step)
  1850. echo '
  1851. <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
  1852. echo '
  1853. </ul>
  1854. </div>
  1855. <div id="progress_bar">
  1856. <div id="overall_text">', $incontext['overall_percent'], '%</div>
  1857. <div id="overall_progress" style="width: ', $incontext['overall_percent'], '%;">&nbsp;</div>
  1858. <div class="overall_progress">', $txt['upgrade_overall_progress'], '</div>
  1859. </div>
  1860. <div id="main_screen" class="clear">
  1861. <h2>', $incontext['page_title'], '</h2>
  1862. <div class="panel">';
  1863. }
  1864. function template_install_below()
  1865. {
  1866. global $incontext, $txt;
  1867. if (!empty($incontext['continue']) || !empty($incontext['skip']))
  1868. {
  1869. echo '
  1870. <div>';
  1871. if (!empty($incontext['continue']))
  1872. echo '
  1873. <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
  1874. if (!empty($incontext['skip']))
  1875. echo '
  1876. <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
  1877. echo '
  1878. </div>';
  1879. }
  1880. // Show the closing form tag and other data only if not in the last step
  1881. if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
  1882. echo '
  1883. </form>';
  1884. echo '
  1885. </div>
  1886. </div>
  1887. </div>
  1888. </div>
  1889. </div>
  1890. <div id="footer_section">
  1891. <div class="frame">
  1892. <ul class="reset">
  1893. <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>
  1894. </ul>
  1895. </div>
  1896. </div>
  1897. </body>
  1898. </html>';
  1899. }
  1900. // Welcome them to the wonderful world of SMF!
  1901. function template_welcome_message()
  1902. {
  1903. global $incontext, $installurl, $txt;
  1904. echo '
  1905. <script src="http://www.simplemachines.org/smf/current-version.js?version=' . $GLOBALS['current_smf_version'] . '"></script>
  1906. <form action="', $incontext['form_url'], '" method="post">
  1907. <p>', sprintf($txt['install_welcome_desc'], $GLOBALS['current_smf_version']), '</p>
  1908. <div id="version_warning" style="margin: 2ex; padding: 2ex; border: 2px dashed #a92174; color: black; background-color: #fbbbe2; display: none;">
  1909. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  1910. <strong style="text-decoration: underline;">', $txt['error_warning_notice'], '</strong><br />
  1911. <div style="padding-left: 6ex;">
  1912. ', 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>'), '
  1913. </div>
  1914. </div>';
  1915. // Show the warnings, or not.
  1916. if (template_warning_divs())
  1917. echo '
  1918. <h3>', $txt['install_all_lovely'], '</h3>';
  1919. // Say we want the continue button!
  1920. if (empty($incontext['error']))
  1921. $incontext['continue'] = 1;
  1922. // For the latest version stuff.
  1923. echo '
  1924. <script><!-- // --><![CDATA[
  1925. // Latest version?
  1926. function smfCurrentVersion()
  1927. {
  1928. var smfVer, yourVer;
  1929. if (!(\'smfVersion\' in window))
  1930. return;
  1931. window.smfVersion = window.smfVersion.replace(/SMF\s?/g, \'\');
  1932. smfVer = document.getElementById("smfVersion");
  1933. yourVer = document.getElementById("yourVersion");
  1934. setInnerHTML(smfVer, window.smfVersion);
  1935. var currentVersion = getInnerHTML(yourVer);
  1936. if (currentVersion < window.smfVersion)
  1937. document.getElementById(\'version_warning\').style.display = \'\';
  1938. }
  1939. addLoadEvent(smfCurrentVersion);
  1940. // ]]></script>';
  1941. }
  1942. // A shortcut for any warning stuff.
  1943. function template_warning_divs()
  1944. {
  1945. global $txt, $incontext;
  1946. // Errors are very serious..
  1947. if (!empty($incontext['error']))
  1948. echo '
  1949. <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
  1950. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  1951. <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br />
  1952. <div style="padding-left: 6ex;">
  1953. ', $incontext['error'], '
  1954. </div>
  1955. </div>';
  1956. // A warning message?
  1957. elseif (!empty($incontext['warning']))
  1958. echo '
  1959. <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
  1960. <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
  1961. <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br />
  1962. <div style="padding-left: 6ex;">
  1963. ', $incontext['warning'], '
  1964. </div>
  1965. </div>';
  1966. return empty($incontext['error']) && empty($incontext['warning']);
  1967. }
  1968. function template_chmod_files()
  1969. {
  1970. global $txt, $incontext;
  1971. echo '
  1972. <p>', $txt['ftp_setup_why_info'], '</p>
  1973. <ul style="margin: 2.5ex; font-family: monospace;">
  1974. <li>', implode('</li>
  1975. <li>', $incontext['failed_files']), '</li>
  1976. </ul>';
  1977. // This is serious!
  1978. if (!template_warning_divs())
  1979. return;
  1980. echo '
  1981. <hr />
  1982. <p>', $txt['ftp_setup_info'], '</p>';
  1983. if (!empty($incontext['ftp_errors']))
  1984. echo '
  1985. <div class="error_message">
  1986. <div style="color: red;">
  1987. ', $txt['error_ftp_no_connect'], '<br />
  1988. <br />
  1989. <code>', implode('<br />', $incontext['ftp_errors']), '</code>
  1990. </div>
  1991. </div>
  1992. <br />';
  1993. echo '
  1994. <form action="', $incontext['form_url'], '" method="post">
  1995. <table align="center" style="width: 520px; margin: 1em 0; padding: 0; border: 0">
  1996. <tr>
  1997. <td width="26%" valign="top" class="textbox"><label for="ftp_server">', $txt['ftp_server'], ':</label></td>
  1998. <td>
  1999. <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>
  2000. <input type="text" size="30" name="ftp_server" id="ftp_server" value="', $incontext['ftp']['server'], '" style="width: 70%;" class="input_text" />
  2001. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_server_info'], '</div>
  2002. </td>
  2003. </tr><tr>
  2004. <td width="26%" valign="top" class="textbox"><label for="ftp_username">', $txt['ftp_username'], ':</label></td>
  2005. <td>
  2006. <input type="text" size="50" name="ftp_username" id="ftp_username" value="', $incontext['ftp']['username'], '" style="width: 99%;" class="input_text" />
  2007. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['ftp_username_info'], '</div>
  2008. </td>
  2009. </tr><tr>
  2010. <td width="26%" valign="top" class="textbox"><label for="ftp_password">', $txt['ftp_password'], ':</label></td>
  2011. <td>
  2012. <input type="password" size="50" name="ftp_password" id="ftp_password" style="width: 99%;" class="input_password" />
  2013. <div style="font-size: smaller; margin-bottom: 3ex;">', $txt['ftp_password_info'], '</div>
  2014. </td>
  2015. </tr><tr>
  2016. <td width="26%" valign="top" class="textbox"><label for="ftp_path">', $txt['ftp_path'], ':</label></td>
  2017. <td style="padding-bottom: 1ex;">
  2018. <input type="text" size="50" name="ftp_path" id="ftp_path" value="', $incontext['ftp']['path'], '" style="width: 99%;" class="input_text" />
  2019. <div style="font-size: smaller; margin-bottom: 2ex;">', $incontext['ftp']['path_msg'], '</div>
  2020. </td>
  2021. </tr>
  2022. </table>
  2023. <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>
  2024. </form>
  2025. <a href="', $incontext['form_url'], '">', $txt['error_message_click'], '</a> ', $txt['ftp_setup_again'];
  2026. }
  2027. // Get the database settings prepared.
  2028. function template_database_settings()
  2029. {
  2030. global $incontext, $installurl, $txt;
  2031. echo '
  2032. <form action="', $incontext['form_url'], '" method="post">
  2033. <p>', $txt['db_settings_info'], '</p>';
  2034. template_warning_divs();
  2035. echo '
  2036. <table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin: 1em 0;">';
  2037. // More than one database type?
  2038. if (count($incontext['supported_databases']) > 1)
  2039. {
  2040. echo '
  2041. <tr>
  2042. <td width="20%" valign="top" class="textbox"><label for="db_type_input">', $txt['db_settings_type'], ':</label></td>
  2043. <td>
  2044. <select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
  2045. foreach ($incontext['supported_databases'] as $key => $db)
  2046. echo '
  2047. <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
  2048. echo '
  2049. </select><div id="db_sqlite_warning" style="color: blue; display: none;" class="smalltext">', $txt['db_sqlite_warning'], '</div>
  2050. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_type_info'], '</div>
  2051. </td>
  2052. </tr>';
  2053. }
  2054. else
  2055. {
  2056. echo '
  2057. <tr style="display: none;">
  2058. <td>
  2059. <input type="hidden" name="db_type" value="', $incontext['db']['type'], '" />
  2060. </td>
  2061. </tr>';
  2062. }
  2063. echo '
  2064. <tr id="db_server_contain">
  2065. <td width="20%" valign="top" class="textbox"><label for="db_server_input">', $txt['db_settings_server'], ':</label></td>
  2066. <td>
  2067. <input type="text" name="db_server" id="db_server_input" value="', $incontext['db']['server'], '" size="30" class="input_text" /><br />
  2068. <div style="font-size: smaller; margin-bottom: 2ex;">', $txt['db_settings_server_info'], '</div>
  2069. </td>
  2070. </tr><tr id="db_port_contain">
  2071. <td width="20%" valign="top" class="textbox"><label for="db_port_input">', $txt['db_settings_port'], ':</label></td>
  2072. <td>
  2073. <input type="text" name="db_port" id="db_port_input" value="', $incontext['db']['port'], '</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. ?>