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