[378] | 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 | /************************************************************************/
|
---|
[379] | 11 | if (!defined('ADMIN_FILE')) {
|
---|
| 12 | die ("You can't access this file directly...");
|
---|
| 13 | }
|
---|
[378] | 14 |
|
---|
[379] | 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 | $id_cons_gen=intval($param['id_cons_gen']);
|
---|
| 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!");
|
---|
[380] | 26 | if (isset($param['errmex'])) $mex=htmlspecialchars($param['errmex']); else $mex='';
|
---|
| 27 | if (isset($param['procedi'])) $procedi=intval($param['procedi']); else $procedi=0;
|
---|
[379] | 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();}
|
---|
[380] | 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'];
|
---|
[379] | 53 | $myrev=$_SESSION['localrev'];
|
---|
| 54 | if($newrev==$myrev) {
|
---|
| 55 | $errmex="Non sono disponibili nuovi aggiornamenti";
|
---|
| 56 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 57 | }
|
---|
[380] | 58 | if(!$procedi){
|
---|
| 59 | ele();
|
---|
| 60 | echo "<hr><br><h2 style=\"text-align:center;\">Revisione installata: $myrev<br>Revisione disponibile: $newrev</h2><br><hr>";
|
---|
[381] | 61 | $file = file("$host/ele3/log/?format=changelog&limit=100&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&verbose=off");
|
---|
[380] | 62 | # echo "<br>Procedo con l'aggiornamento? ";
|
---|
| 63 | echo "<form name=\"conferma\" action=\"admin.php\"><input type=\"hidden\" name=\"op\" value=\"aggiorna\">";
|
---|
| 64 | echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"procedi\" value=\"1\">";
|
---|
| 65 | 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>";
|
---|
| 66 | echo "<br><br><p>Log delle modifiche (massimo 100 righe)</p>";
|
---|
| 67 | echo "<br><textarea name=\"log\" rows=\"15\" cols=\"150\">";
|
---|
| 68 | foreach ($file as $line_num => $line) echo "$line";
|
---|
[381] | 69 |
|
---|
[380] | 70 | echo "</textarea>";
|
---|
[381] | 71 | ############Ã
|
---|
| 72 | $filename = "$host/ele3/changeset?format=zip&new=$newrev&new_path=%2F&old=$myrev&old_path=%2F";
|
---|
| 73 |
|
---|
| 74 | $za = new ZipArchive();
|
---|
[378] | 75 | $path = "./files/";
|
---|
[382] | 76 | $righe='';
|
---|
[379] | 77 | if(file_exists($path)) {
|
---|
| 78 | if (!is_dir($path)) {
|
---|
| 79 | $errmex="E' presente un file di nome $path nella cartella admin, va cancellato per poter aggiornare";
|
---|
| 80 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 81 | }
|
---|
| 82 | else
|
---|
| 83 | $righe.= "<br>La cartella $path Ú già presente, procedo con l'aggiornamento";
|
---|
| 84 | }else{
|
---|
[378] | 85 | $righe.= "<br>La cartella $path non Ú presente, procedo con la creazione";
|
---|
| 86 | mkdir($path, 0777, true);
|
---|
| 87 | }
|
---|
[381] | 88 | $newfile=$path."aggiornamento".$newrev;
|
---|
| 89 | copy($filename,$newfile);
|
---|
| 90 | $za->open($newfile);
|
---|
| 91 | echo "<br>prima";
|
---|
| 92 | for( $i = 0; $i < $za->numFiles; $i++ ){
|
---|
| 93 | echo "<br>$i - dentro";
|
---|
| 94 | $stat = $za->statIndex( $i );
|
---|
| 95 | print_r( $stat['name'] . PHP_EOL );
|
---|
| 96 | }
|
---|
| 97 | ############
|
---|
| 98 | include("footer.php");die();
|
---|
| 99 | }
|
---|
| 100 | $admin = '../admin';
|
---|
| 101 | $client = '../client';
|
---|
| 102 | # $path = "/tmp/files";
|
---|
| 103 | $backup = "./backup".$myrev;
|
---|
[382] | 104 | $path = "./files/";
|
---|
| 105 | $righe='';
|
---|
[381] | 106 | /* if(file_exists($path)) {
|
---|
| 107 | $i=1;
|
---|
| 108 | $ispath=$path;
|
---|
| 109 | while(file_exists($ispath))
|
---|
| 110 | $ispath=$path.$i++;
|
---|
| 111 | $path.=--$i.'/';
|
---|
| 112 | }else $path.='/';
|
---|
| 113 | if (!is_dir($path)) {
|
---|
| 114 | if(false===rename($path,$path."_da_".$myrev."_a_".$newrev)) {
|
---|
| 115 | $errmex="E' presente un file di nome $path nella cartella admin, va cancellato per poter aggiornare";
|
---|
| 116 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 117 | }
|
---|
| 118 | $righe.= "<br>La cartella $path non Ú presente, procedo con la creazione";
|
---|
| 119 | mkdir($path, 0777, true);
|
---|
| 120 | }
|
---|
| 121 | else
|
---|
| 122 | $righe.= "<br>La cartella $path Ú già presente, procedo con l'aggiornamento";
|
---|
| 123 | }else{
|
---|
| 124 | $righe.= "<br>Creo la cartella $path";
|
---|
| 125 | mkdir($path, 0777, true);*/
|
---|
| 126 | $trunk=$path.'trunk';
|
---|
| 127 | $trunkadm=$trunk.'/admin';
|
---|
| 128 | $trunkcli=$trunk.'/client';
|
---|
| 129 | # }
|
---|
[378] | 130 | # if(!file_exists($trunk)) if (false === mkdir($trunk)) { die("Impossibile creare la cartella trunk, il programma viene interrotto");}
|
---|
| 131 | # if(!copy($file,$trunkadm)){ $righe.= "<br>Errore durante la copia del pacchetto di aggiornamento<br>";}
|
---|
| 132 | // Nome del file zip : https://trac.eleonline.it/ele3/changeset?format=zip&new=377&new_path=%2F&old=360&old_path=%2F
|
---|
| 133 | # https://trac.eleonline.it/ele3/browser/trunk?format=zip&rev=377
|
---|
| 134 |
|
---|
| 135 | $filename = "$host/ele3/changeset?format=zip&new=$newrev&new_path=%2F&old=$myrev&old_path=%2F";
|
---|
[381] | 136 | $newfile=$path."aggiornamento".$newrev;
|
---|
[379] | 137 | if(!copy($filename,$newfile)){
|
---|
[382] | 138 | $errmex="Errore durante la copia del pacchetto $newfile - aggiornamento interrotto";
|
---|
[379] | 139 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 140 | }
|
---|
[382] | 141 | $zip = new ZipArchive;
|
---|
| 142 | $res = $zip->open($newfile);
|
---|
| 143 | ############
|
---|
| 144 | #$za = new ZipArchive();
|
---|
[381] | 145 |
|
---|
| 146 | #$za->open('theZip.zip');
|
---|
[382] | 147 | # $za->open($newfile);
|
---|
| 148 | /*
|
---|
[381] | 149 | for( $i = 0; $i < $za->numFiles; $i++ ){
|
---|
| 150 | $stat = $za->statIndex( $i );
|
---|
| 151 | print_r( basename( $stat['name'] ) . PHP_EOL );
|
---|
| 152 | }
|
---|
[382] | 153 | die(); */
|
---|
[381] | 154 | ################
|
---|
[378] | 155 | $righe.= "<br>$newfile scaricato";
|
---|
| 156 | if ($res === TRUE) {
|
---|
| 157 | $zip->extractTo($path);
|
---|
| 158 | $zip->close();
|
---|
| 159 | $righe.= '<br>File zip estratto';
|
---|
| 160 | } else {
|
---|
[381] | 161 | $errmex= "Errore nell'estrazione del file zip! Aggiornamento interrotto";
|
---|
[379] | 162 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
[378] | 163 | }
|
---|
[381] | 164 | if(file_exists($path.$backup)) {
|
---|
| 165 | $i=1;
|
---|
| 166 | $isback=$path.$backup;
|
---|
| 167 | while(file_exists($isback))
|
---|
| 168 | $isback=$path.$backup.$i++;
|
---|
| 169 | $backup=$path.$backup.$i.'/';
|
---|
| 170 | } else $backup=$path.$backup.'/';
|
---|
| 171 | /* if(false===rename($backup,$backup."_a_".$myrev)) {
|
---|
| 172 | $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";
|
---|
[380] | 173 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
[381] | 174 | }
|
---|
| 175 | }else{ */
|
---|
| 176 | $righe.= "<br>Creo la cartella di backup: $backup";
|
---|
| 177 | mkdir($backup, 0755);
|
---|
| 178 | # }
|
---|
[378] | 179 | $righe.= "<br><br><b>Copio i nuovi files nell'installazione di amministrazione locale</b>";
|
---|
[381] | 180 | recurse_copy($trunkadm,$admin,$backup.'/admin/');
|
---|
[378] | 181 | $righe.= "<br>Files di aggiornamento copiati correttamente.";
|
---|
| 182 | $righe.= "<br><br><b>Copio i nuovi files nell'installazione client locale</b>";
|
---|
[381] | 183 | recurse_copy($trunkcli,$client,$backup.'/client/');
|
---|
[378] | 184 | $righe.= "<br>Files di aggiornamento copiati correttamente.";
|
---|
[380] | 185 | function recurse_copy($src,$dst,$bck) {
|
---|
[378] | 186 | $dir = opendir($src);
|
---|
[379] | 187 | if(!file_exists($dst))
|
---|
| 188 | if(@mkdir($dst)==false) {
|
---|
[381] | 189 | $errmex= "Errore durante la creazione della directory $dst (controllare i permessi), aggiornamento interrotto";
|
---|
[379] | 190 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 191 | }
|
---|
[380] | 192 | if(!file_exists($bck))
|
---|
[381] | 193 | if(mkdir($bck,0777,true)==false) {
|
---|
| 194 | $errmex= "Errore durante la creazione della directory $bck (controllare i permessi), aggiornamento interrotto";
|
---|
[380] | 195 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 196 | }
|
---|
[378] | 197 | while(false !== ( $file = readdir($dir)) ) {
|
---|
| 198 | if (( $file != '.' ) && ( $file != '..' )) {
|
---|
| 199 | if ( is_dir($src . '/' . $file) ) {
|
---|
[380] | 200 | recurse_copy($src . '/' . $file,$dst . '/' . $file,$bck . '/' . $file);
|
---|
[378] | 201 | }
|
---|
| 202 | else {
|
---|
[381] | 203 | if(file_exists($dst . '/' . $file))
|
---|
| 204 | if(false===copy($dst . '/' . $file,$bck . '/' . $file)) {
|
---|
| 205 | $errmex= "Errore durante la copia del file".$bck . '/' . $file."(controllare i permessi), aggiornamento interrotto";
|
---|
| 206 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 207 | }
|
---|
[380] | 208 | if(!copy($src . '/' . $file,$dst . '/' . $file)) {
|
---|
[381] | 209 | $errmex= "Errore durante la copia del file".$dst . '/' . $file."(controllare i permessi), aggiornamento interrotto";
|
---|
[379] | 210 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 211 | }
|
---|
[378] | 212 | }
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 | closedir($dir);
|
---|
| 216 | }
|
---|
| 217 | $righedb='';
|
---|
[379] | 218 | if(file_exists('./files/trunk/admin/modules/Elezioni/aggiornadb.php')) {
|
---|
[378] | 219 | $righe.= "<br><br><b>Aggiornamento del database</b>";
|
---|
| 220 | ob_start();
|
---|
[380] | 221 | include ('modules/Elezioni/aggiornadb.php');
|
---|
[378] | 222 | $righedb=ob_get_contents();
|
---|
| 223 | ob_end_clean();
|
---|
| 224 | }
|
---|
| 225 | $righe.=$righedb;
|
---|
[381] | 226 | $righe.= "<br><br><b>Operazioni di aggiornamento concluse.</b>";
|
---|
[378] | 227 | $dir = "./files/";
|
---|
| 228 | if(file_exists($dir)){
|
---|
| 229 | $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
|
---|
| 230 | $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
|
---|
| 231 | foreach ( $ri as $file ) {
|
---|
[381] | 232 | chmod($file, 0777);
|
---|
[378] | 233 | $file->isDir() ? rmdir($file) : unlink($file);
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
[380] | 236 | $_SESSION['localrev']=$newrev;
|
---|
[379] | 237 | ele();
|
---|
[380] | 238 | echo "<hr><br><h2 style=\"text-align:center;\">Aggiornamento completato</h2><br><hr>";
|
---|
| 239 | echo "<br><br><h3>Log delle operazioni</h3>";
|
---|
[379] | 240 | echo $righe;
|
---|
| 241 | include("footer.php");
|
---|
| 242 | die();
|
---|
[378] | 243 |
|
---|
| 244 | ?>
|
---|