PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/update.php

https://github.com/Dratone/EveBB
PHP | 216 lines | 122 code | 57 blank | 37 comment | 22 complexity | 936187ea956001ff91680f02eef017e5 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * 03/03/2011
  4. * update.php
  5. * WisdomPanda
  6. */
  7. define('PUN_ROOT', dirname(__FILE__).'/');
  8. require PUN_ROOT.'include/common.php';
  9. $base_url = 'http://www.eve-bb.com/updates/'.EVE_BB_VERSION.'/';
  10. $fetch_url = 'http://www.eve-bb.com/updates/get_file.php?file='.EVE_BB_VERSION.'/';
  11. if ($pun_user['g_id'] != PUN_ADMIN) {
  12. message('You must be an admin to do this.');
  13. } //End if.
  14. /**
  15. * This changed in 1.0.0, so we must provide a copy with the updater.
  16. */
  17. function redirect_no_back($destination_url, $message, $link_back = true)
  18. {
  19. global $db, $pun_config, $lang_common, $pun_user;
  20. // Prefix with o_base_url (unless there's already a valid URI)
  21. if (strpos($destination_url, 'http://') !== 0 && strpos($destination_url, 'https://') !== 0 && strpos($destination_url, '/') !== 0)
  22. $destination_url = $pun_config['o_base_url'].'/'.$destination_url;
  23. // Do a little spring cleaning
  24. $destination_url = preg_replace('/([\r\n])|(%0[ad])|(;\s*data\s*:)/i', '', $destination_url);
  25. // If the delay is 0 seconds, we might as well skip the redirect all together
  26. if ($pun_config['o_redirect_delay'] == '0')
  27. header('Location: '.str_replace('&amp;', '&', $destination_url));
  28. // Send no-cache headers
  29. header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
  30. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  31. header('Cache-Control: post-check=0, pre-check=0', false);
  32. header('Pragma: no-cache'); // For HTTP/1.0 compatibility
  33. // Send the Content-type header in case the web server is setup to send something else
  34. header('Content-type: text/html; charset=utf-8');
  35. if (file_exists(PUN_ROOT.'style/'.$pun_user['style'].'/redirect.tpl'))
  36. {
  37. $tpl_file = PUN_ROOT.'style/'.$pun_user['style'].'/redirect.tpl';
  38. $tpl_inc_dir = PUN_ROOT.'style/'.$pun_user['style'].'/';
  39. }
  40. else
  41. {
  42. $tpl_file = PUN_ROOT.'include/template/redirect.tpl';
  43. $tpl_inc_dir = PUN_ROOT.'include/user/';
  44. }
  45. $tpl_redir = file_get_contents($tpl_file);
  46. // START SUBST - <pun_include "*">
  47. preg_match_all('#<pun_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">#', $tpl_redir, $pun_includes, PREG_SET_ORDER);
  48. foreach ($pun_includes as $cur_include)
  49. {
  50. ob_start();
  51. // Allow for overriding user includes, too.
  52. if (file_exists($tpl_inc_dir.$cur_include[1].'.'.$cur_include[2]))
  53. require $tpl_inc_dir.$cur_include[1].'.'.$cur_include[2];
  54. else if (file_exists(PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2]))
  55. require PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2];
  56. else
  57. error(sprintf($lang_common['Pun include error'], htmlspecialchars($cur_include[0]), basename($tpl_file)));
  58. $tpl_temp = ob_get_contents();
  59. $tpl_redir = str_replace($cur_include[0], $tpl_temp, $tpl_redir);
  60. ob_end_clean();
  61. }
  62. // END SUBST - <pun_include "*">
  63. // START SUBST - <pun_language>
  64. $tpl_redir = str_replace('<pun_language>', $lang_common['lang_identifier'], $tpl_redir);
  65. // END SUBST - <pun_language>
  66. // START SUBST - <pun_content_direction>
  67. $tpl_redir = str_replace('<pun_content_direction>', $lang_common['lang_direction'], $tpl_redir);
  68. // END SUBST - <pun_content_direction>
  69. // START SUBST - <pun_head>
  70. ob_start();
  71. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_common['Redirecting']);
  72. ?>
  73. <meta http-equiv="refresh" content="<?php echo $pun_config['o_redirect_delay'] ?>;URL=<?php echo str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $destination_url) ?>" />
  74. <title><?php echo generate_page_title($page_title) ?></title>
  75. <link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
  76. <?php
  77. $tpl_temp = trim(ob_get_contents());
  78. $tpl_redir = str_replace('<pun_head>', $tpl_temp, $tpl_redir);
  79. ob_end_clean();
  80. // END SUBST - <pun_head>
  81. // START SUBST - <pun_redir_main>
  82. ob_start();
  83. ?>
  84. <div class="block">
  85. <h2><?php echo $lang_common['Redirecting'] ?></h2>
  86. <div class="box">
  87. <div class="inbox">
  88. <p><?php echo $message.($link_back ? '<br /><br /><a href="'.$destination_url.'">'.$lang_common['Click redirect'].'</a>' : '') ?></p>
  89. </div>
  90. </div>
  91. </div>
  92. <?php
  93. $tpl_temp = trim(ob_get_contents());
  94. $tpl_redir = str_replace('<pun_redir_main>', $tpl_temp, $tpl_redir);
  95. ob_end_clean();
  96. // END SUBST - <pun_redir_main>
  97. // START SUBST - <pun_footer>
  98. ob_start();
  99. // End the transaction
  100. $db->end_transaction();
  101. // Display executed queries (if enabled)
  102. if (defined('PUN_SHOW_QUERIES'))
  103. display_saved_queries();
  104. $tpl_temp = trim(ob_get_contents());
  105. $tpl_redir = str_replace('<pun_footer>', $tpl_temp, $tpl_redir);
  106. ob_end_clean();
  107. // END SUBST - <pun_footer>
  108. // Close the db connection (and free up any result data)
  109. $db->close();
  110. exit($tpl_redir);
  111. }
  112. if (isset($_GET['patch'])) {
  113. //The patch file needed a breather, most likely from large SQL queries, we pass it strait back.
  114. include(FORUM_CACHE_DIR.'patch.php');
  115. } else {
  116. //Not in patch, lets run the check.
  117. //Lets see if they need to update, using the existing code from admin_index.php, but not using short if format. (Messy IMO.)
  118. $latest_version = trim(@$pun_request->get('http://www.eve-bb.com/latest_version'));
  119. if (empty($latest_version)) {
  120. message('Update check failed.');
  121. } //End if.
  122. if (version_compare(EVE_BB_VERSION, $latest_version, '>=')) {
  123. message('Your EveBB install is up to date!');
  124. } //End if.
  125. echo "Newer version found, starting upgrade proccess.<br/>\n";
  126. //Let's get the md5 sum of the updater script, then download the file and check it!
  127. echo "Fetching MD5 sum...";
  128. if (!fetch_file($fetch_url.'patch.md5', EVE_BB_VERSION.'patch.md5')) {
  129. echo "<br/>\nUnable to download the checksum for the patch file.<br/>\n";
  130. exit;
  131. } //End if.
  132. echo "Done.<br/>\n";
  133. echo "Fetching patch file...";
  134. if (!fetch_file($fetch_url.'patch.php', 'patch.php')) {
  135. echo "<br/>\nUnable to download the latest patch.<br/>\n";
  136. exit;
  137. } //End if.
  138. echo "Done.<br/>\n";
  139. //Do they match?
  140. $md5 = file_get_contents(FORUM_CACHE_DIR.EVE_BB_VERSION.'patch.md5');
  141. if ($md5 != md5_file(FORUM_CACHE_DIR.'patch.php')) {
  142. echo "Patch file [".md5(FORUM_CACHE_DIR.'patch.php')."] does not match the MD5 checksum. [".$md5."] Please restart the update.<br/>\n";
  143. exit;
  144. } //End if.
  145. @unlink(FORUM_CACHE_DIR.EVE_BB_VERSION.'patch.md5');
  146. //Ok, now we hand control over to our patch file. This will download any extra files required and update the DB according to the new scheme.
  147. echo "Patch verified, starting patching process.<br/>\n";
  148. //Redirect to make it prettier.
  149. redirect_no_back("update.php?patch&step=0", "Patch verified, starting patching process. This may take a few minutes.", false);
  150. } //End if - else.
  151. if (defined('PATCH_SUCCESS')) {
  152. //For now, just message it, we may change this functionality later.
  153. message('Patch successful! <a href="index.php">Your EveBB install is ready to use.</a><br/>
  154. <br/>
  155. The file permissions may have been changed. It is suggested - but not required - that you verify the permissions of the files on the server.<br/>
  156. <br/>
  157. If you are unsure how they should be configured, please contact your systems administrator.', true);
  158. } //End if.
  159. ?>