[3177] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2 "Fake Me Up" plugin. |
---|
| 5 | # |
---|
| 6 | # Copyright (c) 2010 Bruno Hondelatte, and contributors. |
---|
| 7 | # Many, many thanks to Olivier Meunier and the Dotclear Team. |
---|
| 8 | # Licensed under the GPL version 2.0 license. |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
| 12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
| 13 | //define('DC_DIGESTS',DC_ROOT.'/inc/digests'); |
---|
| 14 | define('DC_DIGESTS_BACKUP',DC_ROOT.'/inc/digests.bak'); |
---|
| 15 | |
---|
| 16 | function check_config($root,$digests_file) |
---|
| 17 | { |
---|
| 18 | if (!is_readable($digests_file)) { |
---|
| 19 | throw new Exception(__('Unable to read digests file.')); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | $opts = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES; |
---|
| 23 | $contents = file($digests_file,$opts); |
---|
| 24 | |
---|
| 25 | $changed = array(); |
---|
| 26 | $same = array(); |
---|
| 27 | $removed = array(); |
---|
| 28 | |
---|
| 29 | foreach ($contents as $digest) |
---|
| 30 | { |
---|
| 31 | if (!preg_match('#^([\da-f]{32})\s+(.+?)$#',$digest,$m)) { |
---|
| 32 | continue; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | $md5 = $m[1]; |
---|
| 36 | $filename = $root.'/'.$m[2]; |
---|
| 37 | |
---|
| 38 | # Invalid checksum |
---|
| 39 | if (is_readable($filename)) { |
---|
| 40 | $md5_new = md5_file($filename); |
---|
| 41 | if ($md5 == $md5_new) { |
---|
| 42 | $same[$m[2]] = $md5; |
---|
| 43 | } else { |
---|
| 44 | $changed[$m[2]] = array("old"=>$md5,"new"=>$md5_new); |
---|
| 45 | } |
---|
| 46 | } else { |
---|
| 47 | $removed[$m[2]] = true; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | # No checksum found in digests file |
---|
| 53 | if (empty($md5)) { |
---|
| 54 | throw new Exception(__('Invalid digests file.')); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | return array("same"=>$same,"changed"=>$changed,"removed" => $removed); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | function backup ($changes) { |
---|
| 61 | $core =& $GLOBALS['core']; |
---|
| 62 | if (preg_match('#^http(s)?://#',$core->blog->settings->system->public_url)) { |
---|
| 63 | $public_root = $core->blog->settings->system->public_url; |
---|
| 64 | } else { |
---|
| 65 | $public_root = $core->blog->host.path::clean($core->blog->settings->system->public_url); |
---|
| 66 | } |
---|
| 67 | $zip_name = sprintf("fmu_backup_%s.zip",date("YmdHis")); |
---|
| 68 | $zip_file = sprintf("%s/%s",$GLOBALS['core']->blog->public_path,$zip_name); |
---|
| 69 | $zip_uri = sprintf("%s/%s",$public_root,$zip_name); |
---|
| 70 | $checksum_file= sprintf("%s/fmu_checksum_%s.txt",$GLOBALS['core']->blog->public_path,date("Ymd")); |
---|
| 71 | |
---|
| 72 | $c_data = 'Fake Me Up Checksum file - '.date("d/m/Y H:i:s")."\n\n". |
---|
| 73 | 'Dotclear version : '.DC_VERSION."\n\n"; |
---|
| 74 | if (count($changes["removed"])) { |
---|
| 75 | $c_data .= "== Removed files ==\n"; |
---|
| 76 | foreach ($changes["removed"] as $k=>$v) { |
---|
| 77 | $c_data .= sprintf(" * %s\n",$k); |
---|
| 78 | } |
---|
| 79 | $c_data .= "\n"; |
---|
| 80 | } |
---|
| 81 | if (file_exists($zip_file)) |
---|
| 82 | @unlink($zip_file); |
---|
| 83 | $b_fp = @fopen($zip_file,'wb'); |
---|
| 84 | if ($b_fp === false) { |
---|
| 85 | return false; |
---|
| 86 | } |
---|
| 87 | $b_zip = new fileZip($b_fp); |
---|
| 88 | if (count($changes["changed"])) { |
---|
| 89 | $c_data .= "== Invalid checksum files ==\n"; |
---|
| 90 | foreach ($changes["changed"] as $k => $v) { |
---|
| 91 | $name = substr($k,2); |
---|
| 92 | $c_data .= sprintf(" * %s [expected: %s ; current: %s]\n",$k,$v['old'],$v['new']); |
---|
| 93 | try { |
---|
| 94 | $b_zip->addFile(DC_ROOT.'/'.$name,$name); |
---|
| 95 | } catch (Exception $e) { |
---|
| 96 | $c_data .= $e->getMessage(); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | file_put_contents($checksum_file,$c_data); |
---|
| 102 | $b_zip->addFile($checksum_file,basename($checksum_file)); |
---|
| 103 | $b_zip->write(); |
---|
| 104 | fclose($b_fp); |
---|
| 105 | $b_zip->close(); |
---|
| 106 | @unlink($checksum_file); |
---|
| 107 | return $zip_uri; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | ?> |
---|
| 111 | <html> |
---|
| 112 | <head><title><?php echo __('Fake Me Up'); ?></title> |
---|
| 113 | </head> |
---|
| 114 | <body> |
---|
| 115 | <?php |
---|
| 116 | |
---|
[3178] | 117 | echo dcPage::breadcrumb( |
---|
| 118 | array( |
---|
| 119 | __('System') => '', |
---|
| 120 | '<span class="page-title">'.__('Fake Me Up').'</span>' => '' |
---|
| 121 | )); |
---|
| 122 | |
---|
[3177] | 123 | if (isset($_POST['erase_backup'])) { |
---|
| 124 | @unlink(DC_DIGESTS_BACKUP); |
---|
| 125 | } |
---|
| 126 | if (isset($_POST['override'])) { |
---|
| 127 | $helpus = l10n::getFilePath(dirname(__FILE__).'/locales','helpus.html',$GLOBALS['_lang']); |
---|
| 128 | $changes = check_config(DC_ROOT,DC_DIGESTS); |
---|
| 129 | |
---|
| 130 | $arr=$changes["same"]; |
---|
| 131 | foreach ($changes["changed"] as $k=>$v) { |
---|
| 132 | $arr[$k]=$v['new']; |
---|
| 133 | } |
---|
| 134 | ksort($arr); |
---|
| 135 | $digest=''; |
---|
| 136 | foreach ($arr as $k=>$v) { |
---|
| 137 | $digest .= sprintf("%s %s\n",$v,$k); |
---|
| 138 | } |
---|
| 139 | rename(DC_DIGESTS,DC_DIGESTS_BACKUP); |
---|
| 140 | file_put_contents(DC_DIGESTS,$digest); |
---|
| 141 | $uri = backup($changes); |
---|
[3190] | 142 | echo '<div class="success">'; |
---|
[3177] | 143 | if ($uri !== false) { |
---|
| 144 | printf(file_get_contents($helpus),$uri,"fakemeup@dotclear.org"); |
---|
| 145 | } else { |
---|
| 146 | echo '<p>'.__("The updates have been performed.").'</p>'; |
---|
| 147 | } |
---|
| 148 | echo '<p><a href="update.php">'.__('Update Dotclear').'</a></p>'. |
---|
| 149 | '</div>'; |
---|
| 150 | } elseif (isset($_POST['disclaimer_ok'])) { |
---|
| 151 | $changes = check_config(DC_ROOT,DC_DIGESTS); |
---|
| 152 | if (count($changes["changed"])==0 && count($changes["removed"])==0) { |
---|
| 153 | echo '<p class="message">'.__('No changed filed have been found, nothing to do!').'</p>'; |
---|
| 154 | } else { |
---|
| 155 | echo '<div class="message">'; |
---|
| 156 | if (count($changes["changed"]) != 0) { |
---|
| 157 | echo '<p>'.__('The following files will have their checksum faked:').'</p>'. |
---|
| 158 | '<ul>'; |
---|
| 159 | foreach ($changes["changed"] as $k => $v) { |
---|
| 160 | printf('<li> %s [old:%s, new:%s]</li>',$k,$v['old'],$v['new']); |
---|
| 161 | } |
---|
| 162 | echo '</ul>'; |
---|
| 163 | } |
---|
| 164 | if (count($changes["removed"]) != 0) { |
---|
| 165 | echo '<p>'.__('The following files digests will have their checksum cleaned:').'</p>'. |
---|
| 166 | '<ul>'; |
---|
| 167 | foreach ($changes["removed"] as $k => $v) { |
---|
| 168 | printf('<li> %s</li>',$k); |
---|
| 169 | } |
---|
| 170 | echo '</ul>'; |
---|
| 171 | } |
---|
| 172 | echo '<form action="'.$p_url.'" method="post"><p>'. |
---|
| 173 | $core->formNonce(). |
---|
| 174 | form::hidden("override",1). |
---|
| 175 | '<input type="submit" name="confirm" value="'.__('Still ok to continue').'"/></p></form></div>'; |
---|
| 176 | } |
---|
| 177 | } else { |
---|
| 178 | if (file_exists(DC_DIGESTS_BACKUP)) { |
---|
| 179 | echo '<div class="error"><p>'.__('Fake Me Up has already been run once.').'</p>'. |
---|
| 180 | '<form action="'.$p_url.'" method="post">'. |
---|
| 181 | '<p><input type="checkbox" name="erase_backup" id="erase_backup" class="classic" /> '. |
---|
| 182 | '<label for="erase_backup" class="classic">'.__("Remove the backup digest file, I want to play again").'</label>'. |
---|
| 183 | $core->formNonce(). |
---|
| 184 | '</p>'. |
---|
| 185 | '<p><input type="submit" name="confirm" id="confirm" value="'.__('Continue').'"/></p>'. |
---|
| 186 | '</form></div>'; |
---|
| 187 | } else { |
---|
| 188 | $disclaimer = l10n::getFilePath(dirname(__FILE__).'/locales','disclaimer.html',$GLOBALS['_lang']); |
---|
| 189 | echo '<p class="error">'.__('Please read carefully the following disclaimer before proceeding!').'</p>'; |
---|
| 190 | echo '<div class="message">'.file_get_contents($disclaimer); |
---|
| 191 | echo '<form action="'.$p_url.'" method="post">'. |
---|
| 192 | '<p><input type="checkbox" name="disclaimer_ok" id="disclaimer_ok" /> '. |
---|
| 193 | '<label for="disclaimer_ok" class="classic">'.__("I have read and understood the disclaimer and wish to continue anyway.").'</label>'. |
---|
| 194 | $core->formNonce(). |
---|
| 195 | '</p>'. |
---|
| 196 | '<p><input type="submit" name="confirm" id="confirm" value="'.__('Continue').'"/></p>'. |
---|
| 197 | '</form></div>'; |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | echo '<p><a class="back" href="index.php">'.__('back').'</a></p>'; |
---|
| 201 | ?> |
---|
| 202 | |
---|
| 203 | </body> |
---|