Dotclear

source: plugins/fakemeup/index.php @ 3405

Revision 3405, 6.5 KB checked in by brol, 6 years ago (diff)

1.6 pour compatibilité dc2.11

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

Sites map