1 | <?php
|
---|
2 | /************************************************************************/
|
---|
3 | /* Eleonline - Raccolta e diffusione dei dati elettorali */
|
---|
4 | /* by Roberto Gigli & Luciano Apolito */
|
---|
5 | /* http://www.eleonline.it */
|
---|
6 | /* info@eleonline.it luciano@aniene.net rgigli@libero.it */
|
---|
7 | /************************************************************************/
|
---|
8 | /* Modulo Inserimento dati */
|
---|
9 | /* Amministrazione */
|
---|
10 | /************************************************************************/
|
---|
11 | if (!defined('ADMIN_FILE')) {
|
---|
12 | die ("You can't access this file directly...");
|
---|
13 | }
|
---|
14 |
|
---|
15 | echo "<style>
|
---|
16 | body
|
---|
17 | {
|
---|
18 | width:100%;
|
---|
19 | margin:0 auto;
|
---|
20 | padding:0px;
|
---|
21 | font-family:helvetica;
|
---|
22 | background-color:#A9D0F5;
|
---|
23 | }
|
---|
24 | #wrapper
|
---|
25 | {
|
---|
26 | text-align:left;
|
---|
27 | margin-left:20px;
|
---|
28 | padding:0px;
|
---|
29 | width:995px;
|
---|
30 | }
|
---|
31 | #wrapperleft
|
---|
32 | {
|
---|
33 | text-align:center;
|
---|
34 | margin:0 auto;
|
---|
35 | padding:0px;
|
---|
36 | width:995px;
|
---|
37 | }
|
---|
38 | #wrapper h1
|
---|
39 | {
|
---|
40 | margin-top:100px;
|
---|
41 | font-size:40px;
|
---|
42 | }
|
---|
43 | #wrapper h1 p
|
---|
44 | {
|
---|
45 | font-size:17px;
|
---|
46 | }
|
---|
47 | #wrapper #feed_div
|
---|
48 | {
|
---|
49 | background-color:white;
|
---|
50 | width:550px;
|
---|
51 | height:320px;
|
---|
52 | overflow-y:scroll;
|
---|
53 | margin-left:20px;
|
---|
54 | margin-top:20px;
|
---|
55 | text-align:left;
|
---|
56 | border:1px solid silver;
|
---|
57 | padding:10px;
|
---|
58 | }
|
---|
59 | #wrapper #feed_div h2
|
---|
60 | {
|
---|
61 | font-size:17px;
|
---|
62 | }
|
---|
63 | #wrapper #feed_div .title a
|
---|
64 | {
|
---|
65 | text-decoration:none;
|
---|
66 | color:#0080FF;
|
---|
67 | }
|
---|
68 | </style>";
|
---|
69 |
|
---|
70 | global $dbi;
|
---|
71 | $aid=$_SESSION['aid'];
|
---|
72 | $prefix=$_SESSION['prefix'];
|
---|
73 | $id_comune=$_SESSION['id_comune'];
|
---|
74 | $param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
|
---|
75 | if(isset($param['id_cons_gen'])) $id_cons_gen=intval($param['id_cons_gen']); else $id_cons_gen=0;
|
---|
76 | $perms=ChiSei(0);
|
---|
77 | if ($perms!=256) return; # $mex = htmlspecialchars("Non sono disponibili nuovi aggiornamenti");
|
---|
78 |
|
---|
79 | include("modules/Elezioni/ele.php");
|
---|
80 | global $righe,$righedb;
|
---|
81 |
|
---|
82 | function aggiornadb(){
|
---|
83 | global $righedb,$prefix,$dbi,$dbname;
|
---|
84 | $righedb='';
|
---|
85 | global $ctrlerr;
|
---|
86 | $ctrlerr=0;
|
---|
87 | if(file_exists(dirname(__FILE__)."/aggiornadb.php")) {
|
---|
88 | ob_start();
|
---|
89 | include (dirname(__FILE__).'/aggiornadb.php');
|
---|
90 | $righedb=ob_get_contents();
|
---|
91 | ob_end_clean();
|
---|
92 | }
|
---|
93 | }
|
---|
94 | function risultati()
|
---|
95 | {
|
---|
96 | global $ctrlerr,$righe,$righedb;
|
---|
97 | if($ctrlerr)
|
---|
98 | echo "<hr><br><h2 style=\"text-align:center;color:red;\">Aggiornamento completato con errori<br>Controllare i log di aggiornamento del database</h2><hr>";
|
---|
99 | else
|
---|
100 | echo "<hr><br><h2 style=\"text-align:center;\">Aggiornamento completato</h2><br><hr>";
|
---|
101 | echo "<br><h3>Log delle operazioni</h3>";
|
---|
102 |
|
---|
103 | echo $righe;
|
---|
104 | echo "<div id=\"wrapper\">";
|
---|
105 | echo "<br><p>Operazioni effettuate sul db: </p>";
|
---|
106 | echo "<div id=\"feed_div\">";
|
---|
107 | echo $righedb;
|
---|
108 | echo "</div>";
|
---|
109 | echo "</div>";
|
---|
110 | echo "<br><b>Operazioni di aggiornamento concluse.</b><br>";
|
---|
111 | }
|
---|
112 | //if ($perms<128 or !$id_cons_gen) die("$perms Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
|
---|
113 | if(isset($param['file'])) $pfile=$param['file']; else $pfile='';
|
---|
114 | if (isset($param['errmex'])) {
|
---|
115 | switch ($param['errmex']) {
|
---|
116 | case 1:
|
---|
117 | $mex='Non sono disponibili nuovi aggiornamenti';
|
---|
118 | break;
|
---|
119 | case 2:
|
---|
120 | $mex="Non c'Ú connessione con il server";
|
---|
121 | break;
|
---|
122 | case 3:
|
---|
123 | $mex="E' presente un file di nome $pfile nella cartella admin, va cancellato per poter aggiornare";
|
---|
124 | break;
|
---|
125 | case 4:
|
---|
126 | $mex="Errore durante la copia del pacchetto $pfile - aggiornamento interrotto";
|
---|
127 | break;
|
---|
128 | case 5:
|
---|
129 | $mex="Errore nell'estrazione del file zip! Aggiornamento interrotto";
|
---|
130 | break;
|
---|
131 | case 6:
|
---|
132 | $mex="Errore durante la creazione della directory $pfile (controllare i permessi), aggiornamento interrotto";
|
---|
133 | break;
|
---|
134 | case 7:
|
---|
135 | $mex="Errore durante la creazione della directory $pfile (controllare i permessi), aggiornamento interrotto";
|
---|
136 | break;
|
---|
137 | case 8:
|
---|
138 | $mex="Errore durante la copia del file $pfile (controllare i permessi), aggiornamento interrotto";
|
---|
139 | break;
|
---|
140 | default:
|
---|
141 | $mex='';
|
---|
142 | }
|
---|
143 | } else $mex='';
|
---|
144 |
|
---|
145 | if (isset($param['procedi'])) $procedi=intval($param['procedi']); else $procedi=0;
|
---|
146 | if(isset($param['errmex']) and $param['errmex']<3) {
|
---|
147 | ele();
|
---|
148 | if(!$procedi){
|
---|
149 | echo "<hr><br><h2 style=\"text-align:center;\">$mex</h2><br><hr>";
|
---|
150 | echo "<form name=\"conferma\" action=\"admin.php\"><input type=\"hidden\" name=\"errmex\" value=\"1\"><input type=\"hidden\" name=\"op\" value=\"aggiorna\">";
|
---|
151 | echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"procedi\" value=\"1\">";
|
---|
152 | echo "<br><table align=\"center\"><tr><td><h3>Procedo con verifica e aggiornamento del solo db (all'ultima versione scaricata)?<br><i>E' consigliato procedere solo dopo aver prodotto una copia di backup</i></h3></td><td><input type=\"submit\" name=\"vai\" value=\""._OK."\"></td></tr></table></form>";
|
---|
153 | }else{
|
---|
154 | aggiornadb();
|
---|
155 | risultati();
|
---|
156 | }
|
---|
157 | include("footer.php");
|
---|
158 | die();
|
---|
159 | }
|
---|
160 | if(phpversion()<5.6) $host="http://80.211.143.127";
|
---|
161 | else $host="https://trac.eleonline.it";
|
---|
162 | ######################
|
---|
163 | $rev=0;
|
---|
164 | if ($stream = fopen('http://mail.eleonline.it/version/risposta.php', 'r')) {
|
---|
165 | $rev= stream_get_contents($stream, 4);
|
---|
166 | fclose($stream);
|
---|
167 |
|
---|
168 | $newrev=(int) filter_var($rev, FILTER_SANITIZE_NUMBER_INT);
|
---|
169 | $_SESSION['remoterev']=$newrev;
|
---|
170 | }else{
|
---|
171 | $errmex=2;
|
---|
172 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
173 | }
|
---|
174 | #$newrev=$_SESSION['remoterev'];
|
---|
175 | #$myrev=$_SESSION['localrev'];
|
---|
176 | include('versione.php');
|
---|
177 | $myrev=intval(substr($versione,-4,4));
|
---|
178 | $_SESSION['localrev']=$myrev;
|
---|
179 |
|
---|
180 | if (isset($_SESSION['forzadb'])) $myrev=378;
|
---|
181 | if($newrev<=$myrev) {
|
---|
182 | $errmex=1;
|
---|
183 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
184 | }
|
---|
185 | #####
|
---|
186 | if(!$procedi){
|
---|
187 | ele();
|
---|
188 | if (isset($_SESSION['forzadb']))
|
---|
189 | echo "<hr><br><h2 style=\"text-align:center;\">E' necessario riallineare il DB, confermare l'aggiornamento.";
|
---|
190 | else
|
---|
191 | echo "<hr><br><h2 style=\"text-align:center;\">Revisione installata: $myrev";
|
---|
192 | echo "<br>Revisione disponibile: $newrev</h2><br><hr>";
|
---|
193 |
|
---|
194 | unset($_SESSION['forzadb']);
|
---|
195 |
|
---|
196 | #####
|
---|
197 |
|
---|
198 | echo "<div id=\"wrapper\">";
|
---|
199 | echo "<br><br><p>Log delle modifiche (massimo 100 righe)</p>";
|
---|
200 | echo "<div id=\"feed_div\">";
|
---|
201 | $myrev++;
|
---|
202 | $rss = simplexml_load_file("$host/ele3/log?format=rss&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&format=rss&max=100&verbose=on#");
|
---|
203 | #$rss = simplexml_load_file("$host/ele3/log?action=follow_copy&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&limit=100&verbose=on#");
|
---|
204 |
|
---|
205 | echo '<h2>'. $rss->channel->title . '</h2>';
|
---|
206 | foreach ($rss->channel->item as $item)
|
---|
207 | {
|
---|
208 | echo '<p class="title"><a href="'. $item->link .'">' . $item->title . "</a></p>";
|
---|
209 | $str=preg_replace('/\s\--/','<br>--',$item->description);
|
---|
210 | echo "<p class='desc'>" . $str . "</p>";
|
---|
211 | }
|
---|
212 | echo "</div>";
|
---|
213 | echo "</div>";
|
---|
214 | #####
|
---|
215 | $file = file("$host/ele3/log/?format=changelog&limit=100&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&verbose=off");
|
---|
216 | # echo "<br>Procedo con l'aggiornamento? ";
|
---|
217 | echo "<form name=\"conferma\" action=\"admin.php\"><input type=\"hidden\" name=\"op\" value=\"aggiorna\">";
|
---|
218 | echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"procedi\" value=\"1\">";
|
---|
219 | echo "<br><table align=\"center\"><tr><td><h3>Procedo con l'aggiornamento?</h3></td><td><input type=\"submit\" name=\"vai\" value=\""._OK."\"></td></tr></table></form>";
|
---|
220 | $filename = "$host/ele3/changeset?format=zip&new=$newrev&new_path=%2F&old=$myrev&old_path=%2F";
|
---|
221 |
|
---|
222 | $za = new ZipArchive();
|
---|
223 | $path = "./files/";
|
---|
224 | $righe='';
|
---|
225 | if(file_exists($path)) {
|
---|
226 | if (!is_dir($path)) {
|
---|
227 | $errmex=3;
|
---|
228 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex&file=$path"); exit;
|
---|
229 | }
|
---|
230 | else
|
---|
231 | $righe.= "<br>La cartella $path Ú già presente, procedo con l'aggiornamento";
|
---|
232 | }else{
|
---|
233 | $righe.= "<br>La cartella $path non Ú presente, procedo con la creazione";
|
---|
234 | mkdir($path, 0777, true);
|
---|
235 | }
|
---|
236 | /* $newfile=$path."aggiornamento".$newrev;
|
---|
237 | copy($filename,$newfile);
|
---|
238 | $za->open($newfile);
|
---|
239 | echo "<br>prima";
|
---|
240 | for( $i = 0; $i < $za->numFiles; $i++ ){
|
---|
241 | echo "<br>$i - dentro";
|
---|
242 | $stat = $za->statIndex( $i );
|
---|
243 | print_r( $stat['name'] . PHP_EOL );
|
---|
244 | }
|
---|
245 | */ ############
|
---|
246 | include("footer.php");die();
|
---|
247 | }
|
---|
248 | $admin = '../admin';
|
---|
249 | $client = '../client';
|
---|
250 | # $path = "/tmp/files";
|
---|
251 | $backup = "backup".$myrev;
|
---|
252 | $path = "./files/";
|
---|
253 | $righe='';
|
---|
254 | /* if(file_exists($path)) {
|
---|
255 | $i=1;
|
---|
256 | $ispath=$path;
|
---|
257 | while(file_exists($ispath))
|
---|
258 | $ispath=$path.$i++;
|
---|
259 | $path.=--$i.'/';
|
---|
260 | }else $path.='/';
|
---|
261 | if (!is_dir($path)) {
|
---|
262 | if(false===rename($path,$path."_da_".$myrev."_a_".$newrev)) {
|
---|
263 | $errmex="E' presente un file di nome $path nella cartella admin, va cancellato per poter aggiornare";
|
---|
264 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
265 | }
|
---|
266 | $righe.= "<br>La cartella $path non Ú presente, procedo con la creazione";
|
---|
267 | mkdir($path, 0777, true);
|
---|
268 | }
|
---|
269 | else
|
---|
270 | $righe.= "<br>La cartella $path Ú già presente, procedo con l'aggiornamento";
|
---|
271 | }else{
|
---|
272 | $righe.= "<br>Creo la cartella $path";
|
---|
273 | mkdir($path, 0777, true);*/
|
---|
274 | $trunk=$path.'trunk';
|
---|
275 | $trunkadm=$trunk.'/admin';
|
---|
276 | $trunkcli=$trunk.'/client';
|
---|
277 | # }
|
---|
278 | # if(!file_exists($trunk)) if (false === mkdir($trunk)) { die("Impossibile creare la cartella trunk, il programma viene interrotto");}
|
---|
279 | # if(!copy($file,$trunkadm)){ $righe.= "<br>Errore durante la copia del pacchetto di aggiornamento<br>";}
|
---|
280 | // Nome del file zip : https://trac.eleonline.it/ele3/changeset?format=zip&new=377&new_path=%2F&old=360&old_path=%2F
|
---|
281 | # https://trac.eleonline.it/ele3/browser/trunk?format=zip&rev=377
|
---|
282 |
|
---|
283 | $filename = "$host/ele3/changeset?format=zip&new=$newrev&new_path=%2F&old=$myrev&old_path=%2F";
|
---|
284 | $newfile=$path."aggiornamento".$newrev;
|
---|
285 | if(!copy($filename,$newfile)){
|
---|
286 | $errmex=4;
|
---|
287 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex&file=$newfile"); exit;
|
---|
288 | }
|
---|
289 | $zip = new ZipArchive;
|
---|
290 | $res = $zip->open($newfile);
|
---|
291 | ############
|
---|
292 | #$za = new ZipArchive();
|
---|
293 |
|
---|
294 | #$za->open('theZip.zip');
|
---|
295 | # $za->open($newfile);
|
---|
296 | /*
|
---|
297 | for( $i = 0; $i < $za->numFiles; $i++ ){
|
---|
298 | $stat = $za->statIndex( $i );
|
---|
299 | print_r( basename( $stat['name'] ) . PHP_EOL );
|
---|
300 | }
|
---|
301 | die(); */
|
---|
302 | ################
|
---|
303 | $righe.= "<br>$newfile scaricato";
|
---|
304 | if ($res === TRUE) {
|
---|
305 | $zip->extractTo($path);
|
---|
306 | $zip->close();
|
---|
307 | $righe.= '<br>File zip estratto';
|
---|
308 | } else {
|
---|
309 | $errmex= 5;
|
---|
310 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
311 | }
|
---|
312 | if(file_exists($path.$backup)) {
|
---|
313 | $i=1;
|
---|
314 | $isback=$path.$backup;
|
---|
315 | while(file_exists($isback))
|
---|
316 | $isback=$path.$backup.$i++;
|
---|
317 | $backup=$path.$backup.$i.'/';
|
---|
318 | } else $backup=$path.$backup.'/';
|
---|
319 | /* if(false===rename($backup,$backup."_a_".$myrev)) {
|
---|
320 | $errmex="E' presente un file di nome $backup_a_$myrev nella cartella admin e non posso rinominare l'ultimo eseguito, va fatto a mano per poter aggiornare";
|
---|
321 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
322 | }
|
---|
323 | }else{ */
|
---|
324 | $righe.= "<br>Creo la cartella di backup: $backup";
|
---|
325 | mkdir($backup, 0755);
|
---|
326 | # }
|
---|
327 | $righe.= "<br><br><b>Copio i nuovi files nell'installazione di amministrazione locale</b>";
|
---|
328 | recurse_copy($trunkadm,$admin,$backup.'/admin/');
|
---|
329 | $righe.= "<br>Files di aggiornamento copiati correttamente.";
|
---|
330 | $righe.= "<br><br><b>Copio i nuovi files nell'installazione client locale</b>";
|
---|
331 | recurse_copy($trunkcli,$client,$backup.'/client/');
|
---|
332 | $righe.= "<br>Files di aggiornamento copiati correttamente.";
|
---|
333 | function recurse_copy($src,$dst,$bck) {
|
---|
334 | $dir = opendir($src);
|
---|
335 | if(!file_exists($dst))
|
---|
336 | if(@mkdir($dst)==false) {
|
---|
337 | $errmex= 6;
|
---|
338 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex&file=$dst"); exit;
|
---|
339 | }
|
---|
340 | if(!file_exists($bck))
|
---|
341 | if(mkdir($bck,0777,true)==false) {
|
---|
342 | $errmex= 7;
|
---|
343 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex&file=$bck"); exit;
|
---|
344 | }
|
---|
345 | while(false !== ( $file = readdir($dir)) ) {
|
---|
346 | if (( $file != '.' ) && ( $file != '..' )) {
|
---|
347 | if ( is_dir($src . '/' . $file) ) {
|
---|
348 | recurse_copy($src . '/' . $file,$dst . '/' . $file,$bck . '/' . $file);
|
---|
349 | }
|
---|
350 | else {
|
---|
351 | if(file_exists($dst . '/' . $file))
|
---|
352 | if(false===copy($dst . '/' . $file,$bck . '/' . $file)) {
|
---|
353 | $errmex= 8;
|
---|
354 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex&file=$bck/$file"); exit;
|
---|
355 | }
|
---|
356 | if(!copy($src . '/' . $file,$dst . '/' . $file)) {
|
---|
357 | $errmex= 8;
|
---|
358 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex&file=".$dst . '/' . $file); exit;
|
---|
359 | }
|
---|
360 | }
|
---|
361 | }
|
---|
362 | }
|
---|
363 | closedir($dir);
|
---|
364 | }
|
---|
365 |
|
---|
366 | $righedb='';
|
---|
367 | global $ctrlerr;
|
---|
368 | $ctrlerr=0;
|
---|
369 | if(file_exists($trunkadm."/modules/Elezioni/aggiornadb.php")) {
|
---|
370 | ob_start();
|
---|
371 | include ('modules/Elezioni/aggiornadb.php');
|
---|
372 | $righedb=ob_get_contents();
|
---|
373 | ob_end_clean();
|
---|
374 | }
|
---|
375 | #$dir = "./files/";
|
---|
376 | if(file_exists($path)){
|
---|
377 | $di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
|
---|
378 | $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
|
---|
379 | foreach ( $ri as $file ) {
|
---|
380 | chmod($file, 0777);
|
---|
381 | $file->isDir() ? rmdir($file) : unlink($file);
|
---|
382 | }
|
---|
383 | }
|
---|
384 | $_SESSION['localrev']=$newrev;
|
---|
385 | ele();
|
---|
386 | if($ctrlerr)
|
---|
387 | echo "<hr><br><h2 style=\"text-align:center;color:red;\">Aggiornamento completato con errori<br>Controllare i log di aggiornamento del database</h2><hr>";
|
---|
388 | else
|
---|
389 | echo "<hr><br><h2 style=\"text-align:center;\">Aggiornamento completato</h2><br><hr>";
|
---|
390 | echo "<br><h3>Log delle operazioni</h3>";
|
---|
391 |
|
---|
392 | echo $righe;
|
---|
393 | echo "<div id=\"wrapper\">";
|
---|
394 | echo "<br><p>Operazioni effettuate sul db: </p>";
|
---|
395 | echo "<div id=\"feed_div\">";
|
---|
396 | echo $righedb;
|
---|
397 | echo "</div>";
|
---|
398 | echo "</div>";
|
---|
399 | echo "<br><b>Operazioni di aggiornamento concluse.</b><br>";
|
---|
400 | include("footer.php");
|
---|
401 | die();
|
---|
402 |
|
---|
403 | ?>
|
---|