source: trunk/client/modules.php@ 392

Last change on this file since 392 was 362, checked in by roby, 3 years ago

Ritocchi e sistemazioni varie di completamento delle mofifiche precedenti

File size: 9.9 KB
Line 
1<?php
2
3/************************************************************************/
4/* Eleonline - Raccolta e diffusione dei dati elettorali */
5/* by Luciano Apolito & Roberto Gigli */
6/* http://www.eleonline.it */
7/* info@eleonline.it luciano@aniene.net rgigli@libero.it */
8/************************************************************************/
9
10define('MODULE_FILE', true);
11
12// Additional security (Union, CLike, XSS)
13// We want to use the function stripos,
14// but thats only available since PHP5.
15// So we cloned the function...
16if(!function_exists('stripos')) {
17 function stripos_clone($haystack, $needle, $offset=0) {
18 return strpos(strtoupper($haystack), strtoupper($needle), $offset);
19 }
20} else {
21// But when this is PHP5, we use the original function
22 function stripos_clone($haystack, $needle, $offset=0) {
23 return stripos($haystack, $needle, $offset=0);
24 }
25}
26
27 if(isset($_SERVER['QUERY_STRING']) && (!stripos_clone($_SERVER['QUERY_STRING'], "ad_click") || !stripos_clone($_SERVER['QUERY_STRING'], "url"))) {
28 $queryString = $_SERVER['QUERY_STRING'];
29 if (stripos_clone($queryString,'%20union%20') OR stripos_clone($queryString,'..') OR stripos_clone($queryString,'+') OR stripos_clone($queryString,'/*') OR stripos_clone($queryString,'*/union/*') OR stripos_clone($queryString,'c2nyaxb0') OR stripos_clone($queryString,'+union+') OR stripos_clone($queryString,'http://') OR (stripos_clone($queryString,'cmd=') AND !stripos_clone($queryString,'&cmd')) OR (stripos_clone($queryString,'exec') AND !stripos_clone($queryString,'execu')) OR stripos_clone($queryString,'concat')) {
30 die('Operazione non consentita');
31 }
32 }
33
34foreach ($_GET as $sec_key => $secvalue) {
35 if ((preg_match("/<[^>]*script*\"?[^>]*>/i",$secvalue)) ||
36 (preg_match("/<[^>]*object*\"?[^>]*>/i", $secvalue)) ||
37 (preg_match("/<[^>]*iframe*\"?[^>]*>/i", $secvalue)) ||
38 (preg_match("/<[^>]*applet*\"?[^>]*>/i", $secvalue)) ||
39 (preg_match("/<[^>]*meta*\"?[^>]*>/i", $secvalue)) ||
40 (preg_match("/<[^>]*style*\"?[^>]*>/i", $secvalue)) ||
41 (preg_match("/<[^>]*form*\"?[^>]*>/i", $secvalue)) ||
42 (preg_match("/<[^>]*img*\"?[^>]*>/i", $secvalue)) ||
43 (preg_match("/<[^>]*onmouseover*\"?[^>]*>/i", $secvalue)) ||
44 (preg_match("/<[^>]*body*\"?[^>]*>/i", $secvalue)) ||
45 (preg_match("/\([^>]*\"?[^)]*\)/", $secvalue)) ||
46 (preg_match("/\"/", $secvalue)) ||
47 (preg_match("/inside_mod/i", $sec_key))) {
48 die ("Operazione non consentita");
49 }
50 }
51
52 foreach ($_POST as $secvalue) {
53 if ((preg_match("/<[^>]*onmouseover*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]script*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]*body*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]style*\"?[^>]*>/i", $secvalue))) {
54 die ($htmltags);
55 }
56 }
57
58// Posting from other servers in not allowed
59// Fix by Quake
60// Bug found by PeNdEjO
61if ($_SERVER['REQUEST_METHOD'] == "POST") {
62 if (isset($_SERVER['HTTP_REFERER'])) {
63 if (!stripos_clone($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])) {
64 die('Posting da un altro server non consentito!');
65 } else {
66# die('<b>Attenzione:</b> il tuo browser non puo inviare gli header HTTP_REFERER al website.<br/>');
67 }
68 }
69}
70
71function jsexist(){ // controlla javascript by l.apolito 2008
72global $op,$name;
73if(!isset($_GET['js'])){
74$querystring= @preg_replace('/'.$_SERVER['DOCUMENT_ROOT'].'/i','http://'.$_SERVER['HTTP_HOST'].'/',$_SERVER['SCRIPT_FILENAME']);
75if (preg_match("/modules.php/i",$_SERVER['SCRIPT_NAME'])) $pagina="name=$name"; // reindirizza
76if (preg_match("/admin.php/i",$_SERVER['SCRIPT_NAME'])) $pagina="op=$op"; // reindirizza
77 echo "<noscript><meta http-equiv=\"refresh\" content=\"0; url=".$querystring."?js=b&amp;$pagina\"/></noscript>";
78 }
79$js=$_GET['js'];
80return $js;
81}
82
83
84
85
86
87
88session_start();//MODIFICHE PER GESTIONE SESSIONI
89// apre database
90////////////////////////
91if (file_exists("config.php")) { @require_once("config.php");$install="";}else{ $install="1";}
92
93
94
95# verifica se effettuata la configurazione
96if(empty($dbname) || $install=="1") {
97 die("<html><body><div style=\"text-align:center\"><br /><br /><img src=\"modules/Elezioni/images/logo.jpg\" alt=\"Eleonline\" title=\"Eleonline\"><br /><br /><strong>Sembra che <a href='http://www.eleonline.it' title='Eleonline'>Eleonline</a> non sia stato ancora installato.<br /><br />Puoi procedere <a href='../install/index.php'>cliccando qui</a> per iniziare l'installazione</strong></div></body></html>");
98}
99
100
101$dbi = new PDO("mysql:host=$dbhost;charset=utf8", $dbuname, $dbpass, array(PDO::ATTR_EMULATE_PREPARES => false,
102 PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
103$sql = "use $dbname";
104$dbi->exec($sql);
105 $sth = $dbi->prepare("SET SESSION character_set_connection = 'utf8' ");
106 $sth->execute();
107 $sth = $dbi->prepare("SET SESSION character_set_client = 'utf8' ");
108 $sth->execute();
109 $sth = $dbi->prepare("SET SESSION character_set_database = 'utf8' ");
110 $sth->execute();
111 $sth = $dbi->prepare("SET CHARACTER SET utf8");
112 $sth->execute();
113
114 $sth = $dbi->prepare("SET NAMES 'utf8'");
115 $sth->execute();
116
117# protezione csrf ottobre 2012 - by l.apolito
118if (file_exists("inc/csrf-magic/csrf-magic.php")) {
119 include_once 'inc/csrf-magic/csrf-magic.php';
120}
121
122
123
124
125
126
127# carica i parametri di default sulla tabella
128$sql = $dbi->prepare("SELECT * FROM ".$prefix."_config");
129$sql->execute();
130while($riga = $sql->fetchAll(PDO::FETCH_ASSOC)){$row=$riga[0];
131$sitename = stripslashes($row['sitename']);
132$siteurl = $row['siteurl'];
133$site_logo = $row['site_logo'];
134$startdate = $row['startdate'];
135$adminmail = $row['adminmail'];
136$tema = $row['tema'];
137$language = $row['language'];
138$blocco = intval($row['blocco']);
139$fileout = intval($row['fileout']);
140$copyright = $row['copyright'];
141$Versione = $row['versione'];
142$patch = $row['patch'];
143$siteistat = intval($row['siteistat']);
144$multicomune = intval($row['multicomune']);
145$flash = intval($row['flash']);
146$displayerrors = $row['displayerrors'];
147$gkey = $row['gkey'];
148$googlemaps = intval($row['googlemaps']);
149$editor = intval($row['editor']);
150$tema_on = intval($row['tema_on']);
151$ed_user = $row['ed_user'];
152#tema mobile
153}
154
155
156
157# altre config
158$sql = $dbi->prepare("SELECT * FROM ".$prefix."_ele_comuni where id_comune='$siteistat' ");
159$sql->execute();
160$riga = $sql->fetchAll(PDO::FETCH_ASSOC);
161$row=$riga[0];
162$id_cons_pred = intval($row['id_cons']);
163if($id_cons_pred=='0')$id_cons_pred='';
164if(!isset($id_cons_gen)) $id_cons_gen=$id_cons_pred;
165# carica il metodo d'hontd
166##$sql = $dbi->prepare("SELECT * FROM ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_gen' ");
167##$sql->execute();
168
169$param=strip_tags(strtolower($_SERVER['REQUEST_METHOD'])) == 'get' ? $_GET : $_POST;
170////////////////////
171#funzione di backup
172if (isset($param['op']) and $param['op']=='backup')
173{
174$id_cons_bak=intval($param['id_cons_gen']);
175if (isset($param['id_comune'])) $id_combak=intval($param['id_comune']); else $id_combak=$_SESSION['id_comune'];
176$sql = $dbi->prepare("SELECT id_cons,id_conf FROM ".$prefix."_ele_cons_comune where id_cons_gen='$id_cons_bak' and id_comune='$id_combak'");
177$sql->execute();
178list($id_cons,$hondt) = $sql->fetch(PDO::FETCH_NUM);
179
180// incluso in consiglieri.php, ma io carico le vecchie variabili per compatibilit'a all'indietro
181if($hondt>=1){
182# proiezione consiglio
183 $res2 = $dbi->prepare("SELECT * FROM ".$prefix."_ele_conf where id_conf='$hondt'");
184 $res2->execute();
185 $row=$res2->fetch(PDO::FETCH_ASSOC);
186
187 $descrizione_consiglio = $row['descrizione'];
188 $LIMITE = intval($row['limite']);
189 $CONSIN = intval($row['consin']);
190 $INFPREMIO=intval($row['infpremio']);
191 $SUPSBARRAMENTO=intval($row['supsbarramento']);
192 $SUPMINPREMIO=intval($row['supminpremio']);
193 $SUPPREMIO=intval($row['suppremio']);
194 $LISTINFSBAR=intval($row['listinfsbar']);
195 $LISTINFCONTA=intval($row['listinfconta']);
196 $LISTSUPCONTA=intval($row['listsupconta']);
197 $SUPMINPREMIO=intval($row['supminpremio']);
198 $INFMINPREMIO=intval($row['infminpremio']);
199}
200
201
202include("modules/Elezioni/backup.php");
203die();
204}
205///////////////////
206// lingua x demo
207if (isset($param['newl'])){
208 $newl=$param['newl'];
209 if (file_exists("modules/Elezioni/language/lang-$newl.php")){ $lang=$newl;$_SESSION['newl']="$lang";
210 }
211}
212
213// seesioni per flash, blocco e linguaggio, tour
214
215if (isset($param['block'])){
216 $blocco=$param['block'];
217 $_SESSION['newblock']="$blocco";
218 }
219if (isset($_SESSION['newblock'])) $blocco=$_SESSION['newblock'];
220
221
222
223// linguaggio
224if (isset($_SESSION['newl'])) $lang=$_SESSION['newl'];
225//else $lang=$lang;
226if (! isset($lang)) $lang=$language;
227if (strlen($lang)!=2) $lang=$language;
228
229// flash x demo
230if (isset($param['flash'])){
231 $flash=$param['flash'];
232 $_SESSION['newflash']="$flash";
233 }
234if (isset($_SESSION['newflash'])) $flash=$_SESSION['newflash'];
235
236if (isset($param['tema'])){
237 $tema=$param['tema'];
238 $tema=htmlentities($tema); // evita xss
239 if(preg_match("/%/i", $tema)) $tema="default";// evita xss
240 $_SESSION['newtema']="$tema";
241
242 }
243if (isset($_SESSION['newtema'])) {
244 $tema=$_SESSION['newtema'];
245 if (preg_match("/%/i",$_SESSION['newtema'])) $_SESSION['newtema']="default"; // xss
246}
247
248//ritorno disabilita tema cellulare dal file backtoapp e dal footer lo riattiva
249if (isset($param['nocell'])){
250$nocell=$param['nocell'];
251$_SESSION['newcell']="$nocell";
252}
253if (isset($_SESSION['newcell'])) $nocell=$_SESSION['newcell'];
254
255
256
257
258
259$PHP_SELF=$_SERVER['PHP_SELF'];
260$file=(isset($_GET['file'])) ? htmlentities($_GET['file']):"index";
261$name=(isset($_GET['name'])) ? htmlentities($_GET['name']):"Elezioni";
262$op=(isset($_GET['op'])) ? htmlentities($_GET['op']):"gruppo";
263if (!isset($_GET['op'])) $_GET['op']="gruppo";
264
265$modpath = "modules/$name/$file.php";
266if (file_exists($modpath)) {
267 include($modpath);
268} else {
269 die ("Sorry, such file doesn't exist...:$modpath");
270}
271
272
273
274
275
276
277
278?>
Note: See TracBrowser for help on using the repository browser.