[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>";
|
---|
[383] | 61 | #####
|
---|
| 62 | echo "<style>
|
---|
| 63 | body
|
---|
| 64 | {
|
---|
| 65 | width:100%;
|
---|
| 66 | margin:0 auto;
|
---|
| 67 | padding:0px;
|
---|
| 68 | font-family:helvetica;
|
---|
| 69 | background-color:#A9D0F5;
|
---|
| 70 | }
|
---|
| 71 | #wrapper
|
---|
| 72 | {
|
---|
| 73 | text-align:center;
|
---|
| 74 | margin:0 auto;
|
---|
| 75 | padding:0px;
|
---|
| 76 | width:995px;
|
---|
| 77 | }
|
---|
| 78 | #wrapper h1
|
---|
| 79 | {
|
---|
| 80 | margin-top:100px;
|
---|
| 81 | font-size:40px;
|
---|
| 82 | }
|
---|
| 83 | #wrapper h1 p
|
---|
| 84 | {
|
---|
| 85 | font-size:17px;
|
---|
| 86 | }
|
---|
| 87 | #wrapper #feed_div
|
---|
| 88 | {
|
---|
| 89 | background-color:white;
|
---|
| 90 | width:550px;
|
---|
| 91 | height:320px;
|
---|
| 92 | overflow-y:scroll;
|
---|
| 93 | margin-left:220px;
|
---|
| 94 | margin-top:20px;
|
---|
| 95 | text-align:left;
|
---|
| 96 | border:1px solid silver;
|
---|
| 97 | padding:10px;
|
---|
| 98 | }
|
---|
| 99 | #wrapper #feed_div h2
|
---|
| 100 | {
|
---|
| 101 | font-size:17px;
|
---|
| 102 | }
|
---|
| 103 | #wrapper #feed_div .title a
|
---|
| 104 | {
|
---|
| 105 | text-decoration:none;
|
---|
| 106 | color:#0080FF;
|
---|
| 107 | }
|
---|
| 108 | </style>";
|
---|
| 109 | echo "<div id=\"wrapper\">";
|
---|
| 110 | echo "<br><br><p>Log delle modifiche (massimo 100 righe)</p>";
|
---|
| 111 | echo "<div id=\"feed_div\">";
|
---|
| 112 | $rss = simplexml_load_file("$host/ele3/log?format=rss&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&format=rss&max=100&verbose=on#");
|
---|
| 113 | #$rss = simplexml_load_file("$host/ele3/log?action=follow_copy&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&limit=100&verbose=on#");
|
---|
| 114 |
|
---|
| 115 | echo '<h2>'. $rss->channel->title . '</h2>';
|
---|
| 116 | foreach ($rss->channel->item as $item)
|
---|
| 117 | {
|
---|
| 118 | echo '<p class="title"><a href="'. $item->link .'">' . $item->title . "</a></p>";
|
---|
| 119 | #$str=preg_replace("--", "<br>--", $item->description );
|
---|
| 120 | $str=preg_replace('/\s\--/','<br>--',$item->description);
|
---|
| 121 | #$str=preg_replace("[^A-Za-z0-9\-]", "<br>", $item->description );
|
---|
| 122 | # $str=preg_replace('/\s\`echo "\040"`/','<br>--',$item->description);
|
---|
| 123 | # $str=htmlentities($item->description);
|
---|
| 124 | echo "<p class='desc'>" . $str . "</p>";
|
---|
| 125 | }
|
---|
| 126 | echo "</div>";
|
---|
| 127 | echo "</div>";
|
---|
| 128 | #####
|
---|
[381] | 129 | $file = file("$host/ele3/log/?format=changelog&limit=100&mode=stop_on_copy&rev=$newrev&stop_rev=$myrev&verbose=off");
|
---|
[380] | 130 | # echo "<br>Procedo con l'aggiornamento? ";
|
---|
| 131 | echo "<form name=\"conferma\" action=\"admin.php\"><input type=\"hidden\" name=\"op\" value=\"aggiorna\">";
|
---|
| 132 | echo "<input type=\"hidden\" name=\"id_cons_gen\" value=\"$id_cons_gen\"><input type=\"hidden\" name=\"procedi\" value=\"1\">";
|
---|
| 133 | 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>";
|
---|
[383] | 134 | /* echo "<br><textarea name=\"log\" rows=\"15\" cols=\"150\">";
|
---|
[380] | 135 | foreach ($file as $line_num => $line) echo "$line";
|
---|
[381] | 136 |
|
---|
[380] | 137 | echo "</textarea>";
|
---|
[383] | 138 | ############Ã */
|
---|
[381] | 139 | $filename = "$host/ele3/changeset?format=zip&new=$newrev&new_path=%2F&old=$myrev&old_path=%2F";
|
---|
| 140 |
|
---|
| 141 | $za = new ZipArchive();
|
---|
[378] | 142 | $path = "./files/";
|
---|
[382] | 143 | $righe='';
|
---|
[379] | 144 | if(file_exists($path)) {
|
---|
| 145 | if (!is_dir($path)) {
|
---|
| 146 | $errmex="E' presente un file di nome $path nella cartella admin, va cancellato per poter aggiornare";
|
---|
| 147 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 148 | }
|
---|
| 149 | else
|
---|
| 150 | $righe.= "<br>La cartella $path Ú già presente, procedo con l'aggiornamento";
|
---|
| 151 | }else{
|
---|
[378] | 152 | $righe.= "<br>La cartella $path non Ú presente, procedo con la creazione";
|
---|
| 153 | mkdir($path, 0777, true);
|
---|
| 154 | }
|
---|
[383] | 155 | /* $newfile=$path."aggiornamento".$newrev;
|
---|
[381] | 156 | copy($filename,$newfile);
|
---|
| 157 | $za->open($newfile);
|
---|
| 158 | echo "<br>prima";
|
---|
| 159 | for( $i = 0; $i < $za->numFiles; $i++ ){
|
---|
| 160 | echo "<br>$i - dentro";
|
---|
| 161 | $stat = $za->statIndex( $i );
|
---|
| 162 | print_r( $stat['name'] . PHP_EOL );
|
---|
| 163 | }
|
---|
[383] | 164 | */ ############
|
---|
| 165 | include("footer.php");die();
|
---|
| 166 | }
|
---|
| 167 | $admin = '../admin';
|
---|
| 168 | $client = '../client';
|
---|
[381] | 169 | # $path = "/tmp/files";
|
---|
[383] | 170 | $backup = "./backup".$myrev;
|
---|
| 171 | $path = "./files/";
|
---|
| 172 | $righe='';
|
---|
[381] | 173 | /* if(file_exists($path)) {
|
---|
[383] | 174 | $i=1;
|
---|
| 175 | $ispath=$path;
|
---|
| 176 | while(file_exists($ispath))
|
---|
| 177 | $ispath=$path.$i++;
|
---|
| 178 | $path.=--$i.'/';
|
---|
| 179 | }else $path.='/';
|
---|
| 180 | if (!is_dir($path)) {
|
---|
| 181 | if(false===rename($path,$path."_da_".$myrev."_a_".$newrev)) {
|
---|
| 182 | $errmex="E' presente un file di nome $path nella cartella admin, va cancellato per poter aggiornare";
|
---|
| 183 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
[381] | 184 | }
|
---|
[383] | 185 | $righe.= "<br>La cartella $path non Ú presente, procedo con la creazione";
|
---|
| 186 | mkdir($path, 0777, true);
|
---|
[379] | 187 | }
|
---|
[383] | 188 | else
|
---|
| 189 | $righe.= "<br>La cartella $path Ú già presente, procedo con l'aggiornamento";
|
---|
| 190 | }else{
|
---|
| 191 | $righe.= "<br>Creo la cartella $path";
|
---|
| 192 | mkdir($path, 0777, true);*/
|
---|
| 193 | $trunk=$path.'trunk';
|
---|
| 194 | $trunkadm=$trunk.'/admin';
|
---|
| 195 | $trunkcli=$trunk.'/client';
|
---|
| 196 | # }
|
---|
| 197 | # if(!file_exists($trunk)) if (false === mkdir($trunk)) { die("Impossibile creare la cartella trunk, il programma viene interrotto");}
|
---|
| 198 | # if(!copy($file,$trunkadm)){ $righe.= "<br>Errore durante la copia del pacchetto di aggiornamento<br>";}
|
---|
| 199 | // Nome del file zip : https://trac.eleonline.it/ele3/changeset?format=zip&new=377&new_path=%2F&old=360&old_path=%2F
|
---|
| 200 | # https://trac.eleonline.it/ele3/browser/trunk?format=zip&rev=377
|
---|
| 201 |
|
---|
| 202 | $filename = "$host/ele3/changeset?format=zip&new=$newrev&new_path=%2F&old=$myrev&old_path=%2F";
|
---|
| 203 | $newfile=$path."aggiornamento".$newrev;
|
---|
| 204 | if(!copy($filename,$newfile)){
|
---|
| 205 | $errmex="Errore durante la copia del pacchetto $newfile - aggiornamento interrotto";
|
---|
| 206 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 207 | }
|
---|
| 208 | $zip = new ZipArchive;
|
---|
| 209 | $res = $zip->open($newfile);
|
---|
[382] | 210 | ############
|
---|
| 211 | #$za = new ZipArchive();
|
---|
[381] | 212 |
|
---|
| 213 | #$za->open('theZip.zip');
|
---|
[382] | 214 | # $za->open($newfile);
|
---|
| 215 | /*
|
---|
[381] | 216 | for( $i = 0; $i < $za->numFiles; $i++ ){
|
---|
| 217 | $stat = $za->statIndex( $i );
|
---|
| 218 | print_r( basename( $stat['name'] ) . PHP_EOL );
|
---|
| 219 | }
|
---|
[382] | 220 | die(); */
|
---|
[381] | 221 | ################
|
---|
[378] | 222 | $righe.= "<br>$newfile scaricato";
|
---|
| 223 | if ($res === TRUE) {
|
---|
| 224 | $zip->extractTo($path);
|
---|
| 225 | $zip->close();
|
---|
| 226 | $righe.= '<br>File zip estratto';
|
---|
| 227 | } else {
|
---|
[381] | 228 | $errmex= "Errore nell'estrazione del file zip! Aggiornamento interrotto";
|
---|
[379] | 229 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
[378] | 230 | }
|
---|
[381] | 231 | if(file_exists($path.$backup)) {
|
---|
| 232 | $i=1;
|
---|
| 233 | $isback=$path.$backup;
|
---|
| 234 | while(file_exists($isback))
|
---|
| 235 | $isback=$path.$backup.$i++;
|
---|
| 236 | $backup=$path.$backup.$i.'/';
|
---|
| 237 | } else $backup=$path.$backup.'/';
|
---|
| 238 | /* if(false===rename($backup,$backup."_a_".$myrev)) {
|
---|
| 239 | $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] | 240 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
[381] | 241 | }
|
---|
| 242 | }else{ */
|
---|
| 243 | $righe.= "<br>Creo la cartella di backup: $backup";
|
---|
| 244 | mkdir($backup, 0755);
|
---|
| 245 | # }
|
---|
[378] | 246 | $righe.= "<br><br><b>Copio i nuovi files nell'installazione di amministrazione locale</b>";
|
---|
[381] | 247 | recurse_copy($trunkadm,$admin,$backup.'/admin/');
|
---|
[378] | 248 | $righe.= "<br>Files di aggiornamento copiati correttamente.";
|
---|
| 249 | $righe.= "<br><br><b>Copio i nuovi files nell'installazione client locale</b>";
|
---|
[381] | 250 | recurse_copy($trunkcli,$client,$backup.'/client/');
|
---|
[378] | 251 | $righe.= "<br>Files di aggiornamento copiati correttamente.";
|
---|
[380] | 252 | function recurse_copy($src,$dst,$bck) {
|
---|
[378] | 253 | $dir = opendir($src);
|
---|
[379] | 254 | if(!file_exists($dst))
|
---|
| 255 | if(@mkdir($dst)==false) {
|
---|
[381] | 256 | $errmex= "Errore durante la creazione della directory $dst (controllare i permessi), aggiornamento interrotto";
|
---|
[379] | 257 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 258 | }
|
---|
[380] | 259 | if(!file_exists($bck))
|
---|
[381] | 260 | if(mkdir($bck,0777,true)==false) {
|
---|
| 261 | $errmex= "Errore durante la creazione della directory $bck (controllare i permessi), aggiornamento interrotto";
|
---|
[380] | 262 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 263 | }
|
---|
[378] | 264 | while(false !== ( $file = readdir($dir)) ) {
|
---|
| 265 | if (( $file != '.' ) && ( $file != '..' )) {
|
---|
| 266 | if ( is_dir($src . '/' . $file) ) {
|
---|
[380] | 267 | recurse_copy($src . '/' . $file,$dst . '/' . $file,$bck . '/' . $file);
|
---|
[378] | 268 | }
|
---|
| 269 | else {
|
---|
[381] | 270 | if(file_exists($dst . '/' . $file))
|
---|
| 271 | if(false===copy($dst . '/' . $file,$bck . '/' . $file)) {
|
---|
| 272 | $errmex= "Errore durante la copia del file".$bck . '/' . $file."(controllare i permessi), aggiornamento interrotto";
|
---|
| 273 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 274 | }
|
---|
[380] | 275 | if(!copy($src . '/' . $file,$dst . '/' . $file)) {
|
---|
[381] | 276 | $errmex= "Errore durante la copia del file".$dst . '/' . $file."(controllare i permessi), aggiornamento interrotto";
|
---|
[379] | 277 | Header("Location: admin.php?op=aggiorna&id_cons_gen=$id_cons_gen&errmex=$errmex"); exit;
|
---|
| 278 | }
|
---|
[378] | 279 | }
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 | closedir($dir);
|
---|
| 283 | }
|
---|
| 284 | $righedb='';
|
---|
[386] | 285 | if(file_exists("modules/Elezioni/aggiornadb.php")) {
|
---|
[378] | 286 | $righe.= "<br><br><b>Aggiornamento del database</b>";
|
---|
| 287 | ob_start();
|
---|
[380] | 288 | include ('modules/Elezioni/aggiornadb.php');
|
---|
[378] | 289 | $righedb=ob_get_contents();
|
---|
| 290 | ob_end_clean();
|
---|
| 291 | }
|
---|
| 292 | $righe.=$righedb;
|
---|
[381] | 293 | $righe.= "<br><br><b>Operazioni di aggiornamento concluse.</b>";
|
---|
[383] | 294 | #$dir = "./files/";
|
---|
| 295 | if(file_exists($path)){
|
---|
| 296 | $di = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
|
---|
[378] | 297 | $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
|
---|
| 298 | foreach ( $ri as $file ) {
|
---|
[381] | 299 | chmod($file, 0777);
|
---|
[378] | 300 | $file->isDir() ? rmdir($file) : unlink($file);
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
[380] | 303 | $_SESSION['localrev']=$newrev;
|
---|
[379] | 304 | ele();
|
---|
[380] | 305 | echo "<hr><br><h2 style=\"text-align:center;\">Aggiornamento completato</h2><br><hr>";
|
---|
| 306 | echo "<br><br><h3>Log delle operazioni</h3>";
|
---|
[379] | 307 | echo $righe;
|
---|
| 308 | include("footer.php");
|
---|
| 309 | die();
|
---|
[378] | 310 |
|
---|
| 311 | ?>
|
---|