| 1 | <?php | 
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
| 3 | # | 
|---|
| 4 | # This file is part of Dotclear 2. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear | 
|---|
| 7 | # Licensed under the GPL version 2.0 license. | 
|---|
| 8 | # See LICENSE file or | 
|---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html | 
|---|
| 10 | # | 
|---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- | 
|---|
| 12 |  | 
|---|
| 13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; | 
|---|
| 14 |  | 
|---|
| 15 | if (!defined('DC_BACKUP_PATH')) { | 
|---|
| 16 |      define('DC_BACKUP_PATH',DC_ROOT); | 
|---|
| 17 | } | 
|---|
| 18 |  | 
|---|
| 19 | dcPage::checkSuper(); | 
|---|
| 20 |  | 
|---|
| 21 | if (!is_readable(DC_DIGESTS)) { | 
|---|
| 22 |      dcPage::open(__('Dotclear update')); | 
|---|
| 23 |      echo '<h2>Access denied</h2>'; | 
|---|
| 24 |      dcPage::close(); | 
|---|
| 25 |      exit; | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); | 
|---|
| 29 | $new_v = $updater->check(DC_VERSION); | 
|---|
| 30 | $zip_file = $new_v ? DC_BACKUP_PATH.'/'.basename($updater->getFileURL()) : ''; | 
|---|
| 31 | $version_info = $new_v ? $updater->getInfoURL() : ''; | 
|---|
| 32 |  | 
|---|
| 33 | # Hide "update me" message | 
|---|
| 34 | if (!empty($_GET['hide_msg'])) { | 
|---|
| 35 |      $updater->setNotify(false); | 
|---|
| 36 |      http::redirect('index.php'); | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | $p_url = 'update.php'; | 
|---|
| 40 |  | 
|---|
| 41 | $step = isset($_GET['step']) ? $_GET['step'] : ''; | 
|---|
| 42 | $step = in_array($step,array('check','download','backup','unzip')) ? $step : ''; | 
|---|
| 43 |  | 
|---|
| 44 | $archives = array(); | 
|---|
| 45 | foreach (files::scanDir(DC_BACKUP_PATH) as $v) { | 
|---|
| 46 |      if (preg_match('/backup-([0-9A-Za-z\.-]+).zip/',$v)) { | 
|---|
| 47 |           $archives[] = $v; | 
|---|
| 48 |      } | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 51 | # Revert or delete backup file | 
|---|
| 52 | if (!empty($_POST['backup_file']) && in_array($_POST['backup_file'],$archives)) | 
|---|
| 53 | { | 
|---|
| 54 |      $b_file = $_POST['backup_file']; | 
|---|
| 55 |       | 
|---|
| 56 |      try | 
|---|
| 57 |      { | 
|---|
| 58 |           if (!empty($_POST['b_del'])) | 
|---|
| 59 |           { | 
|---|
| 60 |                if (!@unlink(DC_BACKUP_PATH.'/'.$b_file)) { | 
|---|
| 61 |                     throw new Exception(sprintf(__('Unable to delete file %s'),html::escapeHTML($b_file))); | 
|---|
| 62 |                } | 
|---|
| 63 |                http::redirect($p_url); | 
|---|
| 64 |           } | 
|---|
| 65 |            | 
|---|
| 66 |           if (!empty($_POST['b_revert'])) | 
|---|
| 67 |           { | 
|---|
| 68 |                $zip = new fileUnzip(DC_BACKUP_PATH.'/'.$b_file); | 
|---|
| 69 |                $zip->unzipAll(DC_BACKUP_PATH.'/'); | 
|---|
| 70 |                @unlink(DC_BACKUP_PATH.'/'.$b_file); | 
|---|
| 71 |                http::redirect($p_url); | 
|---|
| 72 |           } | 
|---|
| 73 |      } | 
|---|
| 74 |      catch (Exception $e) | 
|---|
| 75 |      { | 
|---|
| 76 |           $core->error->add($e->getMessage()); | 
|---|
| 77 |      } | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | # Upgrade process | 
|---|
| 81 | if ($new_v && $step) | 
|---|
| 82 | { | 
|---|
| 83 |      try | 
|---|
| 84 |      { | 
|---|
| 85 |           $updater->setForcedFiles('inc/digests'); | 
|---|
| 86 |            | 
|---|
| 87 |           switch ($step) | 
|---|
| 88 |           { | 
|---|
| 89 |                case 'check': | 
|---|
| 90 |                     $updater->checkIntegrity(DC_ROOT.'/inc/digests',DC_ROOT); | 
|---|
| 91 |                     http::redirect($p_url.'?step=download'); | 
|---|
| 92 |                     break; | 
|---|
| 93 |                case 'download': | 
|---|
| 94 |                     $updater->download($zip_file); | 
|---|
| 95 |                     if (!$updater->checkDownload($zip_file)) { | 
|---|
| 96 |                          throw new Exception( | 
|---|
| 97 |                               sprintf(__('Downloaded Dotclear archive seems to be corrupted. '. | 
|---|
| 98 |                               'Try <a %s>download it</a> again.'),'href="'.$p_url.'?step=download"') | 
|---|
| 99 |                          ); | 
|---|
| 100 |                     } | 
|---|
| 101 |                     http::redirect($p_url.'?step=backup'); | 
|---|
| 102 |                     break; | 
|---|
| 103 |                case 'backup': | 
|---|
| 104 |                     $updater->backup( | 
|---|
| 105 |                          $zip_file, 'dotclear/inc/digests', | 
|---|
| 106 |                          DC_ROOT, DC_ROOT.'/inc/digests', | 
|---|
| 107 |                          DC_BACKUP_PATH.'/backup-'.DC_VERSION.'.zip' | 
|---|
| 108 |                     ); | 
|---|
| 109 |                     http::redirect($p_url.'?step=unzip'); | 
|---|
| 110 |                     break; | 
|---|
| 111 |                case 'unzip': | 
|---|
| 112 |                     $updater->performUpgrade( | 
|---|
| 113 |                          $zip_file, 'dotclear/inc/digests', 'dotclear', | 
|---|
| 114 |                          DC_ROOT, DC_ROOT.'/inc/digests' | 
|---|
| 115 |                     ); | 
|---|
| 116 |                     break; | 
|---|
| 117 |           } | 
|---|
| 118 |      } | 
|---|
| 119 |      catch (Exception $e) | 
|---|
| 120 |      { | 
|---|
| 121 |           $msg = $e->getMessage(); | 
|---|
| 122 |           if ($e->getCode() == dcUpdate::ERR_FILES_CHANGED) | 
|---|
| 123 |           { | 
|---|
| 124 |                $msg = | 
|---|
| 125 |                __('The following files of your Dotclear installation '. | 
|---|
| 126 |                'have been modified so we won\'t try to update your installation. '. | 
|---|
| 127 |                'Please try to <a href="http://dotclear.org/download">update manually</a>.'); | 
|---|
| 128 |           } | 
|---|
| 129 |           elseif ($e->getCode() == dcUpdate::ERR_FILES_UNREADABLE) | 
|---|
| 130 |           { | 
|---|
| 131 |                $msg = | 
|---|
| 132 |                sprintf(__('The following files of your Dotclear installation are not readable. '. | 
|---|
| 133 |                'Please fix this or try to make a backup file named %s manually.'), | 
|---|
| 134 |                '<strong>backup-'.DC_VERSION.'.zip</strong>'); | 
|---|
| 135 |           } | 
|---|
| 136 |           elseif ($e->getCode() == dcUpdate::ERR_FILES_UNWRITALBE) | 
|---|
| 137 |           { | 
|---|
| 138 |                $msg = | 
|---|
| 139 |                __('The following files of your Dotclear installation cannot be written. '. | 
|---|
| 140 |                'Please fix this or try to <a href="http://dotclear.org/download">update manually</a>.'); | 
|---|
| 141 |           } | 
|---|
| 142 |            | 
|---|
| 143 |           if (isset($e->bad_files)) { | 
|---|
| 144 |                $msg .= | 
|---|
| 145 |                '<ul><li><strong>'. | 
|---|
| 146 |                implode('</strong></li><li><strong>',$e->bad_files). | 
|---|
| 147 |                '</strong></li></ul>'; | 
|---|
| 148 |           } | 
|---|
| 149 |            | 
|---|
| 150 |           $core->error->add($msg); | 
|---|
| 151 |      } | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 | /* DISPLAY Main page | 
|---|
| 155 | -------------------------------------------------------- */ | 
|---|
| 156 | dcPage::open(__('Dotclear update')); | 
|---|
| 157 |  | 
|---|
| 158 | if (!$core->error->flag()) { | 
|---|
| 159 |      echo '<h2>'.__('Dotclear update').'</h2>'; | 
|---|
| 160 | } | 
|---|
| 161 |  | 
|---|
| 162 | if (!$step) | 
|---|
| 163 | { | 
|---|
| 164 |      if (empty($new_v)) | 
|---|
| 165 |      { | 
|---|
| 166 |           echo '<p><strong>'.__('No newer Dotclear version available.').'</strong></p>'; | 
|---|
| 167 |      } | 
|---|
| 168 |      else | 
|---|
| 169 |      { | 
|---|
| 170 |           echo | 
|---|
| 171 |                '<p class="static-msg">'.sprintf(__('Dotclear %s is available.'),$new_v). | 
|---|
| 172 |                     ($version_info ? ' <a href="'.$version_info.'">('.__('information about this version').')</a>' : ''). | 
|---|
| 173 |                     '</p>'. | 
|---|
| 174 |            | 
|---|
| 175 |           '<p>'.__('To upgrade your Dotclear installation simply click on the following button. '. | 
|---|
| 176 |                'A backup file of your current installation will be created in your root directory.').'</p>'. | 
|---|
| 177 |           '<form action="'.$p_url.'" method="get">'. | 
|---|
| 178 |           '<p><input type="hidden" name="step" value="check" />'. | 
|---|
| 179 |           '<input type="submit" value="'.__('Update Dotclear').'" /></p>'. | 
|---|
| 180 |           '</form>'; | 
|---|
| 181 |      } | 
|---|
| 182 |       | 
|---|
| 183 |      if (!empty($archives)) | 
|---|
| 184 |      { | 
|---|
| 185 |           echo | 
|---|
| 186 |           '<h3>'.__('Update backup files').'</h3>'. | 
|---|
| 187 |           '<p>'.__('The following files are backups of previously updates. '. | 
|---|
| 188 |           'You can revert your previous installation or delete theses files.').'</p>'; | 
|---|
| 189 |            | 
|---|
| 190 |           echo '<form action="'.$p_url.'" method="post">'; | 
|---|
| 191 |            | 
|---|
| 192 |           foreach ($archives as $v) { | 
|---|
| 193 |                echo | 
|---|
| 194 |                '<p><label class="classic">'.form::radio(array('backup_file'),html::escapeHTML($v)).' '. | 
|---|
| 195 |                html::escapeHTML($v).'</label></p>'; | 
|---|
| 196 |           } | 
|---|
| 197 |            | 
|---|
| 198 |           echo | 
|---|
| 199 |           '<p><strong>'.__('Please note that reverting your Dotclear version may have some '. | 
|---|
| 200 |           'unwanted side-effects. Consider reverting only if you experience strong issues with this new version.').'</strong> '. | 
|---|
| 201 |           sprintf(__('You should not revert to version prior to last one (%s).'),end($archives)). | 
|---|
| 202 |           '</p>'. | 
|---|
| 203 |           '<p><input type="submit" class="delete" name="b_del" value="'.__('Delete selected file').'" /> '. | 
|---|
| 204 |           '<input type="submit" name="b_revert" value="'.__('Revert to selected file').'" />'. | 
|---|
| 205 |           $core->formNonce().'</p>'. | 
|---|
| 206 |           '</form>'; | 
|---|
| 207 |      } | 
|---|
| 208 | } | 
|---|
| 209 | elseif ($step == 'unzip' && !$core->error->flag()) | 
|---|
| 210 | { | 
|---|
| 211 |      echo | 
|---|
| 212 |      '<p class="message">'. | 
|---|
| 213 |      __("Congratulations, you're one click away from the end of the update."). | 
|---|
| 214 |      ' <strong><a href="index.php?logout=1">'.__('Finish the update.').'</a></strong>'. | 
|---|
| 215 |      '</p>'; | 
|---|
| 216 | } | 
|---|
| 217 |  | 
|---|
| 218 | dcPage::close(); | 
|---|
| 219 | ?> | 
|---|