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 |
|
---|
16 | global $dbi;
|
---|
17 | $aid=$_SESSION['aid'];
|
---|
18 | $prefix=$_SESSION['prefix'];
|
---|
19 | $id_comune=$_SESSION['id_comune'];
|
---|
20 | $param=strtolower($_SERVER['REQUEST_METHOD']) == 'get' ? $_GET : $_POST;
|
---|
21 | if(isset($param['id_cons_gen'])) $id_cons_gen=intval($param['id_cons_gen']); else $id_cons_gen=0;
|
---|
22 | $perms=ChiSei(0);
|
---|
23 | include("modules/Elezioni/ele.php");
|
---|
24 |
|
---|
25 | //if ($perms<128 or !$id_cons_gen) die("$perms Non hai i permessi per inserire dati, o non hai scelto la consultazione!");
|
---|
26 | if (isset($param['errmex'])) $mex=htmlspecialchars($param['errmex']); else $mex='';
|
---|
27 | if (isset($param['procedi'])) $procedi=intval($param['procedi']); else $procedi=0;
|
---|
28 | if ($perms!=256) $mex = "Non hai i permessi per avviare un aggiornamento!";
|
---|
29 | if($mex!='') { ele(); echo "<hr><br><h2 style=\"text-align:center;\">$mex</h2><br><hr>"; include("footer.php");die();}
|
---|
30 | if(phpversion()<5.6) $host="http://80.211.143.127";
|
---|
31 | else $host="https://trac.eleonline.it";
|
---|
32 | $headers=get_headers("$host/ele3/changeset/");
|
---|
33 | $testurl=strlen($headers[0])>0?true:false;
|
---|
34 | if($testurl){
|
---|
35 | $file = file("$host/ele3/changeset/");
|
---|
36 | $cntFile = count($file);
|
---|
37 | $fine=0;
|
---|
38 | $currentLine=0;
|
---|
39 | foreach ($file as $line_num => $line) {
|
---|
40 | if(strpos($line,'<title>') ) {$fine=1; continue;}
|
---|
41 | if ($fine){
|
---|
42 | $newrev=(int) filter_var($line, FILTER_SANITIZE_NUMBER_INT);
|
---|
43 | $_SESSION['remoterev']=$newrev;
|
---|
44 | break;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | unset($file);
|
---|
48 | }else{
|
---|
49 | $errmex="Non c'Ú connessione con il server";
|
---|
50 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
51 | }
|
---|
52 | #$newrev=$_SESSION['remoterev'];
|
---|
53 | $myrev=$_SESSION['localrev'];
|
---|
54 | if (isset($_SESSION['forzadb'])) $myrev=378;
|
---|
55 | if($newrev==$myrev) {
|
---|
56 | $errmex="Non sono disponibili nuovi aggiornamenti";
|
---|
57 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
58 | }
|
---|
59 | echo "<style>
|
---|
60 | body
|
---|
61 | {
|
---|
62 | width:100%;
|
---|
63 | margin:0 auto;
|
---|
64 | padding:0px;
|
---|
65 | font-family:helvetica;
|
---|
66 | background-color:#A9D0F5;
|
---|
67 | }
|
---|
68 | #wrapper
|
---|
69 | {
|
---|
70 | text-align:left;
|
---|
71 | margin-left:20px;
|
---|
72 | padding:0px;
|
---|
73 | width:995px;
|
---|
74 | }
|
---|
75 | #wrapperleft
|
---|
76 | {
|
---|
77 | text-align:center;
|
---|
78 | margin:0 auto;
|
---|
79 | padding:0px;
|
---|
80 | width:995px;
|
---|
81 | }
|
---|
82 | #wrapper h1
|
---|
83 | {
|
---|
84 | margin-top:100px;
|
---|
85 | font-size:40px;
|
---|
86 | }
|
---|
87 | #wrapper h1 p
|
---|
88 | {
|
---|
89 | font-size:17px;
|
---|
90 | }
|
---|
91 | #wrapper #feed_div
|
---|
92 | {
|
---|
93 | background-color:white;
|
---|
94 | width:550px;
|
---|
95 | height:320px;
|
---|
96 | overflow-y:scroll;
|
---|
97 | margin-left:20px;
|
---|
98 | margin-top:20px;
|
---|
99 | text-align:left;
|
---|
100 | border:1px solid silver;
|
---|
101 | padding:10px;
|
---|
102 | }
|
---|
103 | #wrapper #feed_div h2
|
---|
104 | {
|
---|
105 | font-size:17px;
|
---|
106 | }
|
---|
107 | #wrapper #feed_div .title a
|
---|
108 | {
|
---|
109 | text-decoration:none;
|
---|
110 | color:#0080FF;
|
---|
111 | }
|
---|
112 | </style>";
|
---|
113 | if(!$procedi){
|
---|
114 | ele();
|
---|
115 | if (isset($_SESSION['forzadb']))
|
---|
116 | echo "<hr><br><h2 style=\"text-align:center;\">E' necessario riallineare il DB, confermare l'aggiornamento.";
|
---|
117 | else
|
---|
118 | echo "<hr><br><h2 style=\"text-align:center;\">Revisione installata: $myrev";
|
---|
119 | echo "<br>Revisione disponibile: $newrev</h2><br><hr>";
|
---|
120 |
|
---|
121 | unset($_SESSION['forzadb']);
|
---|
122 |
|
---|
123 | #####
|
---|
124 |
|
---|
125 | echo "<div id=\"wrapper\">";
|
---|
126 | echo "<br><br><p>Log delle modifiche (massimo 100 righe)</p>";
|
---|
127 | echo "<div id=\"feed_div\">";
|
---|
128 | $myrev++;
|
---|
129 | $rss = simplexml_load_file("$host/ele3/log?format=rss&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&format=rss&max=100&verbose=on#");
|
---|
130 | #$rss = simplexml_load_file("$host/ele3/log?action=follow_copy&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&limit=100&verbose=on#");
|
---|
131 |
|
---|
132 | echo '<h2>'. $rss->channel->title . '</h2>';
|
---|
133 | foreach ($rss->channel->item as $item)
|
---|
134 | {
|
---|
135 | echo '<p class="title"><a href="'. $item->link .'">' . $item->title . "</a></p>";
|
---|
136 | #$str=preg_replace("--", "<br>--", $item->description );
|
---|
137 | $str=preg_replace('/\s\--/','<br>--',$item->description);
|
---|
138 | #$str=preg_replace("[^A-Za-z0-9\-]", "<br>", $item->description );
|
---|
139 | # $str=preg_replace('/\s\`echo "\040"`/','<br>--',$item->description);
|
---|
140 | # $str=htmlentities($item->description);
|
---|
141 | echo "<p class='desc'>" . $str . "</p>";
|
---|
142 | }
|
---|
143 | echo "</div>";
|
---|
144 | echo "</div>";
|
---|
145 | #####
|
---|
146 | $file = file("$host/ele3/log/?format=changelog&limit=100&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&verbose=off");
|
---|
147 | # echo "<br>Procedo con l'aggiornamento? ";
|
---|
148 | echo "<form name=\"conferma\" action=\"admin.php\"><input type=\"hidden\" name=\"op\" value=\"aggiorna\">";
|
---|
149 | echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"procedi\" value=\"1\">";
|
---|
150 | 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>";
|
---|
151 | /* echo "<br><textarea name=\"log\" rows=\"15\" cols=\"150\">";
|
---|
152 | foreach ($file as $line_num => $line) echo "$line";
|
---|
153 |
|
---|
154 | echo "</textarea>";
|
---|
155 | ############Ã */
|
---|
156 | $filename = "$host/ele3/changeset?format=zip&new=$newrev&new_path=%2F&old=$myrev&old_path=%2F";
|
---|
157 |
|
---|
158 | $za = new ZipArchive();
|
---|
159 | $path = "./files/";
|
---|
160 | $righe='';
|
---|
161 | if(file_exists($path)) {
|
---|
162 | if (!is_dir($path)) {
|
---|
163 | $errmex="E' presente un file di nome $path nella cartella admin, va cancellato per poter aggiornare";
|
---|
164 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
165 | }
|
---|
166 | else
|
---|
167 | $righe.= "<br>La cartella $path Ú già presente, procedo con l'aggiornamento";
|
---|
168 | }else{
|
---|
169 | $righe.= "<br>La cartella $path non Ú presente, procedo con la creazione";
|
---|
170 | mkdir($path, 0777, true);
|
---|
171 | }
|
---|
172 | /* $newfile=$path."aggiornamento".$newrev;
|
---|
173 | copy($filename,$newfile);
|
---|
174 | $za->open($newfile);
|
---|
175 | echo "<br>prima";
|
---|
176 | for( $i = 0; $i < $za->numFiles; $i++ ){
|
---|
177 | echo "<br>$i - dentro";
|
---|
178 | $stat = $za->statIndex( $i );
|
---|
179 | print_r( $stat['name'] . PHP_EOL );
|
---|
180 | }
|
---|
181 | */ ############
|
---|
182 | include("footer.php");die();
|
---|
183 | }
|
---|
184 | $admin = '../admin';
|
---|
185 | $client = '../client';
|
---|
186 | # $path = "/tmp/files";
|
---|
187 | $backup = "backup".$myrev;
|
---|
188 | $path = "./files/";
|
---|
189 | $righe='';
|
---|
190 | /* if(file_exists($path)) {
|
---|
191 | $i=1;
|
---|
192 | $ispath=$path;
|
---|
193 | while(file_exists($ispath))
|
---|
194 | $ispath=$path.$i++;
|
---|
195 | $path.=--$i.'/';
|
---|
196 | }else $path.='/';
|
---|
197 | if (!is_dir($path)) {
|
---|
198 | if(false===rename($path,$path."_da_".$myrev."_a_".$newrev)) {
|
---|
199 | $errmex="E' presente un file di nome $path nella cartella admin, va cancellato per poter aggiornare";
|
---|
200 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
201 | }
|
---|
202 | $righe.= "<br>La cartella $path non Ú presente, procedo con la creazione";
|
---|
203 | mkdir($path, 0777, true);
|
---|
204 | }
|
---|
205 | else
|
---|
206 | $righe.= "<br>La cartella $path Ú già presente, procedo con l'aggiornamento";
|
---|
207 | }else{
|
---|
208 | $righe.= "<br>Creo la cartella $path";
|
---|
209 | mkdir($path, 0777, true);*/
|
---|
210 | $trunk=$path.'trunk';
|
---|
211 | $trunkadm=$trunk.'/admin';
|
---|
212 | $trunkcli=$trunk.'/client';
|
---|
213 | # }
|
---|
214 | # if(!file_exists($trunk)) if (false === mkdir($trunk)) { die("Impossibile creare la cartella trunk, il programma viene interrotto");}
|
---|
215 | # if(!copy($file,$trunkadm)){ $righe.= "<br>Errore durante la copia del pacchetto di aggiornamento<br>";}
|
---|
216 | // Nome del file zip : https://trac.eleonline.it/ele3/changeset?format=zip&new=377&new_path=%2F&old=360&old_path=%2F
|
---|
217 | # https://trac.eleonline.it/ele3/browser/trunk?format=zip&rev=377
|
---|
218 |
|
---|
219 | $filename = "$host/ele3/changeset?format=zip&new=$newrev&new_path=%2F&old=$myrev&old_path=%2F";
|
---|
220 | $newfile=$path."aggiornamento".$newrev;
|
---|
221 | if(!copy($filename,$newfile)){
|
---|
222 | $errmex="Errore durante la copia del pacchetto $newfile - aggiornamento interrotto";
|
---|
223 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
224 | }
|
---|
225 | $zip = new ZipArchive;
|
---|
226 | $res = $zip->open($newfile);
|
---|
227 | ############
|
---|
228 | #$za = new ZipArchive();
|
---|
229 |
|
---|
230 | #$za->open('theZip.zip');
|
---|
231 | # $za->open($newfile);
|
---|
232 | /*
|
---|
233 | for( $i = 0; $i < $za->numFiles; $i++ ){
|
---|
234 | $stat = $za->statIndex( $i );
|
---|
235 | print_r( basename( $stat['name'] ) . PHP_EOL );
|
---|
236 | }
|
---|
237 | die(); */
|
---|
238 | ################
|
---|
239 | $righe.= "<br>$newfile scaricato";
|
---|
240 | if ($res === TRUE) {
|
---|
241 | $zip->extractTo($path);
|
---|
242 | $zip->close();
|
---|
243 | $righe.= '<br>File zip estratto';
|
---|
244 | } else {
|
---|
245 | $errmex= "Errore nell'estrazione del file zip! Aggiornamento interrotto";
|
---|
246 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
247 | }
|
---|
248 | if(file_exists($path.$backup)) {
|
---|
249 | $i=1;
|
---|
250 | $isback=$path.$backup;
|
---|
251 | while(file_exists($isback))
|
---|
252 | $isback=$path.$backup.$i++;
|
---|
253 | $backup=$path.$backup.$i.'/';
|
---|
254 | } else $backup=$path.$backup.'/';
|
---|
255 | /* if(false===rename($backup,$backup."_a_".$myrev)) {
|
---|
256 | $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";
|
---|
257 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
258 | }
|
---|
259 | }else{ */
|
---|
260 | $righe.= "<br>Creo la cartella di backup: $backup";
|
---|
261 | mkdir($backup, 0755);
|
---|
262 | # }
|
---|
263 | $righe.= "<br><br><b>Copio i nuovi files nell'installazione di amministrazione locale</b>";
|
---|
264 | recurse_copy($trunkadm,$admin,$backup.'/admin/');
|
---|
265 | $righe.= "<br>Files di aggiornamento copiati correttamente.";
|
---|
266 | $righe.= "<br><br><b>Copio i nuovi files nell'installazione client locale</b>";
|
---|
267 | recurse_copy($trunkcli,$client,$backup.'/client/');
|
---|
268 | $righe.= "<br>Files di aggiornamento copiati correttamente.";
|
---|
269 | function recurse_copy($src,$dst,$bck) {
|
---|
270 | $dir = opendir($src);
|
---|
271 | if(!file_exists($dst))
|
---|
272 | if(@mkdir($dst)==false) {
|
---|
273 | $errmex= "Errore durante la creazione della directory $dst (controllare i permessi), aggiornamento interrotto";
|
---|
274 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
275 | }
|
---|
276 | if(!file_exists($bck))
|
---|
277 | if(mkdir($bck,0777,true)==false) {
|
---|
278 | $errmex= "Errore durante la creazione della directory $bck (controllare i permessi), aggiornamento interrotto";
|
---|
279 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
280 | }
|
---|
281 | while(false !== ( $file = readdir($dir)) ) {
|
---|
282 | if (( $file != '.' ) && ( $file != '..' )) {
|
---|
283 | if ( is_dir($src . '/' . $file) ) {
|
---|
284 | recurse_copy($src . '/' . $file,$dst . '/' . $file,$bck . '/' . $file);
|
---|
285 | }
|
---|
286 | else {
|
---|
287 | if(file_exists($dst . '/' . $file))
|
---|
288 | if(false===copy($dst . '/' . $file,$bck . '/' . $file)) {
|
---|
289 | $errmex= "Errore durante la copia del file".$bck . '/' . $file."(controllare i permessi), aggiornamento interrotto";
|
---|
290 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
291 | }
|
---|
292 | if(!copy($src . '/' . $file,$dst . '/' . $file)) {
|
---|
293 | $errmex= "Errore durante la copia del file".$dst . '/' . $file."(controllare i permessi), aggiornamento interrotto";
|
---|
294 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
295 | }
|
---|
296 | }
|
---|
297 | }
|
---|
298 | }
|
---|
299 | closedir($dir);
|
---|
300 | }
|
---|
301 | $righedb='';
|
---|
302 | if(file_exists($trunkadm."/modules/Elezioni/aggiornadb.php")) {
|
---|
303 | $ctrlerr=0;
|
---|
304 | ob_start();
|
---|
305 | include ('modules/Elezioni/aggiornadb.php');
|
---|
306 | $righedb=ob_get_contents();
|
---|
307 | ob_end_clean();
|
---|
308 | }
|
---|
309 | #$dir = "./files/";
|
---|
310 | if(file_exists($path)){
|
---|
311 | $di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
|
---|
312 | $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
|
---|
313 | foreach ( $ri as $file ) {
|
---|
314 | chmod($file, 0777);
|
---|
315 | $file->isDir() ? rmdir($file) : unlink($file);
|
---|
316 | }
|
---|
317 | }
|
---|
318 | $_SESSION['localrev']=$newrev;
|
---|
319 | ele();
|
---|
320 | if($ctrlerr)
|
---|
321 | echo "<hr><br><h2 style=\"text-align:center;color:red;\">Aggiornamento completato con errori<br>Controllare i log di aggiornamento del database</h2><hr>";
|
---|
322 | else
|
---|
323 | echo "<hr><br><h2 style=\"text-align:center;\">Aggiornamento completato</h2><br><hr>";
|
---|
324 | echo "<br><h3>Log delle operazioni</h3>";
|
---|
325 |
|
---|
326 | echo $righe;
|
---|
327 | echo "<div id=\"wrapper\">";
|
---|
328 | echo "<br><p>Operazioni effettuate sul db: </p>";
|
---|
329 | echo "<div id=\"feed_div\">";
|
---|
330 | echo $righedb;
|
---|
331 | echo "</div>";
|
---|
332 | echo "</div>";
|
---|
333 | echo "<br><b>Operazioni di aggiornamento concluse.</b><br>";
|
---|
334 | include("footer.php");
|
---|
335 | die();
|
---|
336 |
|
---|
337 | ?>
|
---|