@@ -5,36 +5,36 @@ discard block |
||
5 | 5 | $net = new \dautkom\ipv4\IPv4(); |
6 | 6 | |
7 | 7 | $_ = $_POST['genere']; |
8 | -if ( ($tables["$_"]['field']=='email') AND ($_POST['Value']!='ALL') ) |
|
8 | +if (($tables["$_"]['field'] == 'email') AND ($_POST['Value'] != 'ALL')) |
|
9 | 9 | if (!(filter_var($_POST['Value'], FILTER_VALIDATE_EMAIL))) |
10 | 10 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid email address.</pre>'); |
11 | 11 | |
12 | -if ( ($tables["$_"]['field']=='domain') AND ($_POST['Value']!='ALL') ) |
|
12 | +if (($tables["$_"]['field'] == 'domain') AND ($_POST['Value'] != 'ALL')) |
|
13 | 13 | if (!(filter_var(gethostbyname($_POST['Value']), FILTER_VALIDATE_IP))) |
14 | 14 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid domain.</pre>'); |
15 | 15 | |
16 | -if ( ($tables["$_"]['field']=='ip') AND ($_POST['Value']!='ALL') ) |
|
16 | +if (($tables["$_"]['field'] == 'ip') AND ($_POST['Value'] != 'ALL')) |
|
17 | 17 | if (!(filter_var($_POST['Value'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))) |
18 | 18 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid IP address.</pre>'); |
19 | 19 | |
20 | -if ( ($tables["$_"]['field']=='network') AND ($_POST['Value']!='ALL') ) { |
|
21 | - $value = explode('/',$_POST['Value']); |
|
20 | +if (($tables["$_"]['field'] == 'network') AND ($_POST['Value'] != 'ALL')) { |
|
21 | + $value = explode('/', $_POST['Value']); |
|
22 | 22 | if (count($value) != 2) |
23 | 23 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask pair.</pre>'); |
24 | 24 | if (!$net->address($value[0])->mask($value[1])->isValid(1)) |
25 | 25 | exit ('<pre><'.$_POST['Value'].'> is NOT a valid Network/Netmask.</pre>'); |
26 | 26 | } |
27 | 27 | |
28 | -if ( ($tables["$_"]['field']=='username') AND ($_POST['Value']!='ALL') ) { |
|
29 | - if ( preg_match( '/[^\x20-\x7f]/', $_POST['Value']) ) |
|
28 | +if (($tables["$_"]['field'] == 'username') AND ($_POST['Value'] != 'ALL')) { |
|
29 | + if (preg_match('/[^\x20-\x7f]/', $_POST['Value'])) |
|
30 | 30 | exit('<pre><'.$_POST['Value'].'> contains NON ASCII chars.</pre>'); |
31 | - if ( preg_match( '/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value']) ) |
|
31 | + if (preg_match('/[$~=#*+%,{}()\/\\<>;:\"`\[\]&?\s]/', $_POST['Value'])) |
|
32 | 32 | exit('<pre><'.$_POST['Value'].'> contains invalid ASCII chars.</pre>'); |
33 | - switch ( $_POST['Value'] ) { |
|
33 | + switch ($_POST['Value']) { |
|
34 | 34 | case 'anonymous': |
35 | 35 | case 'anybody': |
36 | 36 | case 'anyone': |
37 | - case ( preg_match( '/^anyone@/',$_POST['Value']) == TRUE ) : |
|
37 | + case (preg_match('/^anyone@/', $_POST['Value']) == TRUE) : |
|
38 | 38 | exit('<pre><'.$_POST['Value'].'> is not allowed.</pre>'); |
39 | 39 | } |
40 | 40 | } |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | |
50 | 50 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); |
51 | 51 | if ($mysqli->connect_error) { |
52 | - syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
52 | + syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
53 | 53 | . $mysqli->connect_error); |
54 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
54 | + exit ($user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
55 | 55 | . $mysqli->connect_error); |
56 | 56 | } |
57 | 57 | |
58 | -syslog(LOG_INFO, $user.': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
59 | -rlookup($mysqli,username(),$admins,$_POST['Value'],$_POST['genere'],$tables); |
|
58 | +syslog(LOG_INFO, $user.': Successfully mysql connected to '.$mysqli->host_info); |
|
59 | +rlookup($mysqli, username(), $admins, $_POST['Value'], $_POST['genere'], $tables); |
|
60 | 60 | $mysqli->close(); |
61 | 61 | closelog(); |
62 | 62 | ?> |
@@ -14,10 +14,10 @@ discard block |
||
14 | 14 | require_once('function.php'); |
15 | 15 | |
16 | 16 | |
17 | -if ( $require_auth ) if ( username() == 'unknown' ) exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
17 | +if ($require_auth) if (username() == 'unknown') exit ("<p>You MUST configure your server to use authentication.</p>"); |
|
18 | 18 | |
19 | 19 | |
20 | -if ( $imapListActive ) |
|
20 | +if ($imapListActive) |
|
21 | 21 | print ' <p style="text-align: right"><a href="/spamreport" target="_new">SPAM Learn Observer</a></p>'; |
22 | 22 | |
23 | 23 | print <<<END |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | END; |
27 | 27 | |
28 | 28 | |
29 | -$option=NULL; |
|
29 | +$option = NULL; |
|
30 | 30 | $desc = array_keys($tables); |
31 | 31 | foreach ($desc as $description) { |
32 | - $disabled = $tables["$description"]['active']==TRUE ? '' : ' disabled'; |
|
32 | + $disabled = $tables["$description"]['active'] == TRUE ? '' : ' disabled'; |
|
33 | 33 | $option .= '<option value="'.$description."\"$disabled>$description</option>"; |
34 | 34 | } |
35 | 35 |
@@ -1,24 +1,24 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$version='1.9d'; |
|
3 | +$version = '1.9d'; |
|
4 | 4 | |
5 | 5 | function username() { |
6 | 6 | if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
7 | 7 | else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
8 | - else $user='unknown'; |
|
8 | + else $user = 'unknown'; |
|
9 | 9 | return $user; |
10 | 10 | } |
11 | 11 | |
12 | 12 | |
13 | -function addtolist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason) { |
|
13 | +function addtolist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason) { |
|
14 | 14 | // See MySQL manual for $expQ and $expUnit at |
15 | 15 | // https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampadd |
16 | 16 | |
17 | - $result=FALSE; |
|
17 | + $result = FALSE; |
|
18 | 18 | |
19 | 19 | switch ($type) { |
20 | 20 | case 'ip': |
21 | - $query= sprintf("INSERT INTO `$table` ( |
|
21 | + $query = sprintf("INSERT INTO `$table` ( |
|
22 | 22 | `$type` , |
23 | 23 | `date` , |
24 | 24 | `exp` , |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | VALUES ( |
30 | 30 | INET_ATON( '%s' ) , |
31 | 31 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
32 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
32 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
33 | 33 | break; |
34 | 34 | |
35 | 35 | case 'network': |
36 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
37 | - $query= sprintf("INSERT INTO `$table` ( |
|
36 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
37 | + $query = sprintf("INSERT INTO `$table` ( |
|
38 | 38 | `$type` , |
39 | 39 | `netmask`, |
40 | 40 | `date` , |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | VALUES ( |
47 | 47 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
48 | 48 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
49 | - )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
|
49 | + )", $sub['net'], $sub['mask'], $expUnit, $expQ, $user, $myreason); |
|
50 | 50 | break; |
51 | 51 | |
52 | 52 | default: |
53 | - $query= sprintf("INSERT INTO `$table` ( |
|
53 | + $query = sprintf("INSERT INTO `$table` ( |
|
54 | 54 | `$type` , |
55 | 55 | `date` , |
56 | 56 | `exp` , |
@@ -61,61 +61,61 @@ discard block |
||
61 | 61 | VALUES ( |
62 | 62 | '%s' , |
63 | 63 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
64 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
64 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | if ($myconn->query($query) === TRUE) { |
68 | 68 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
69 | - $result=TRUE; |
|
69 | + $result = TRUE; |
|
70 | 70 | } |
71 | 71 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
72 | 72 | return $result; |
73 | 73 | } |
74 | 74 | |
75 | -function relist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason) { |
|
75 | +function relist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason) { |
|
76 | 76 | |
77 | - $result=FALSE; |
|
77 | + $result = FALSE; |
|
78 | 78 | |
79 | 79 | switch ($type) { |
80 | 80 | case 'ip': |
81 | - $query= sprintf("UPDATE `$table` SET |
|
81 | + $query = sprintf("UPDATE `$table` SET |
|
82 | 82 | `active` = '1', |
83 | 83 | `user` = '%s', |
84 | 84 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
85 | 85 | `nlist` = `nlist` + 1, |
86 | 86 | `reason` = '%s' |
87 | - WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
|
87 | + WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $expUnit, $expQ, $myreason, $value); |
|
88 | 88 | break; |
89 | 89 | case 'network': |
90 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
91 | - $query= sprintf("UPDATE `$table` SET |
|
90 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
91 | + $query = sprintf("UPDATE `$table` SET |
|
92 | 92 | `active` = '1', |
93 | 93 | `user` = '%s', |
94 | 94 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
95 | 95 | `nlist` = `nlist` + 1, |
96 | 96 | `reason` = '%s' |
97 | - WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']); |
|
97 | + WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $expUnit, $expQ, $myreason, $sub['net'], $sub['mask']); |
|
98 | 98 | break; |
99 | 99 | default: |
100 | - $query= sprintf("UPDATE `$table` SET |
|
100 | + $query = sprintf("UPDATE `$table` SET |
|
101 | 101 | `active` = '1', |
102 | 102 | `user` = '%s', |
103 | 103 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
104 | 104 | `nlist` = `nlist` + 1, |
105 | 105 | `reason` = '%s' |
106 | - WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
|
106 | + WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $expUnit, $expQ, $myreason, $value); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | if ($myconn->query($query) === TRUE) { |
110 | 110 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
111 | - $result=TRUE; |
|
111 | + $result = TRUE; |
|
112 | 112 | } |
113 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
113 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
114 | 114 | return $result; |
115 | 115 | } |
116 | 116 | |
117 | -function remove ($myconn,$user,$value,$type,$table) { |
|
118 | - $result=FALSE; |
|
117 | +function remove($myconn, $user, $value, $type, $table) { |
|
118 | + $result = FALSE; |
|
119 | 119 | |
120 | 120 | switch ($type) { |
121 | 121 | case 'ip': |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); |
124 | 124 | break; |
125 | 125 | case 'network': |
126 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
126 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
127 | 127 | $query = sprintf("DELETE FROM `$table` WHERE |
128 | 128 | `$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s') LIMIT 1", |
129 | - $sub['net'],$sub['mask']); |
|
129 | + $sub['net'], $sub['mask']); |
|
130 | 130 | break; |
131 | 131 | default: |
132 | 132 | $query = sprintf("DELETE FROM `$table` WHERE |
@@ -134,38 +134,38 @@ discard block |
||
134 | 134 | } |
135 | 135 | |
136 | 136 | |
137 | - if ($return=$myconn->query($query) === TRUE) |
|
137 | + if ($return = $myconn->query($query) === TRUE) |
|
138 | 138 | syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
139 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
139 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
140 | 140 | |
141 | 141 | return $return; |
142 | 142 | } |
143 | 143 | |
144 | 144 | |
145 | -function changestatus ($myconn,$user,$value,$status,$type,$table) { |
|
145 | +function changestatus($myconn, $user, $value, $status, $type, $table) { |
|
146 | 146 | |
147 | 147 | switch ($type) { |
148 | 148 | case 'ip': |
149 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); |
|
149 | + $query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $value); |
|
150 | 150 | break; |
151 | 151 | case 'network': |
152 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
153 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user, $sub['net'],$sub['mask']); |
|
152 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
153 | + $query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $sub['net'], $sub['mask']); |
|
154 | 154 | break; |
155 | 155 | default: |
156 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); |
|
156 | + $query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $value); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ($return=$myconn->query($query) === TRUE) { |
|
159 | + if ($return = $myconn->query($query) === TRUE) { |
|
160 | 160 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
161 | 161 | } |
162 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
162 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
163 | 163 | return $return; |
164 | 164 | } |
165 | 165 | |
166 | 166 | |
167 | -function expire ($myconn,$user,$tables,$expireTime) { |
|
168 | - $return=TRUE; |
|
167 | +function expire($myconn, $user, $tables, $expireTime) { |
|
168 | + $return = TRUE; |
|
169 | 169 | $desc = array_keys($tables); |
170 | 170 | foreach ($desc as $tdesc) { |
171 | 171 | /* QUERY */ |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | } while ($myconn->next_result()); |
185 | 185 | } |
186 | 186 | else { |
187 | - syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
|
187 | + syslog(LOG_ERR, "Expire job - Error: ".$myconn->error); |
|
188 | 188 | $return = FALSE; |
189 | 189 | } |
190 | 190 | } |
191 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
191 | + if (!($return)) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
192 | 192 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
193 | 193 | return $return; |
194 | 194 | } |
@@ -196,21 +196,21 @@ discard block |
||
196 | 196 | |
197 | 197 | function isListed($row) { |
198 | 198 | |
199 | - $exp=new DateTime($row['exp']); |
|
200 | - $now=new DateTime('NOW'); |
|
201 | - if (($exp > $now) and ($row['active'])) return true; |
|
199 | + $exp = new DateTime($row['exp']); |
|
200 | + $now = new DateTime('NOW'); |
|
201 | + if (($exp>$now) and ($row['active'])) return true; |
|
202 | 202 | else return false; |
203 | 203 | |
204 | 204 | } |
205 | 205 | |
206 | 206 | |
207 | -function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { |
|
207 | +function ask($myconn, $id, $what, $alltables, $typedesc, $value, $lock, $user, $adm) { |
|
208 | 208 | |
209 | 209 | switch ($what) { |
210 | 210 | case 'Ok': |
211 | 211 | if ($lock) return NULL; |
212 | - if (in_array($user,array_keys($adm))) |
|
213 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
212 | + if (in_array($user, array_keys($adm))) |
|
213 | + if (consistentListing($myconn, $alltables, $typedesc, $value, $whynot)) return require('relistButton.php'); |
|
214 | 214 | return htmlspecialchars($whynot); |
215 | 215 | case 'Listed': |
216 | 216 | case 'WhiteListed': |
@@ -219,17 +219,17 @@ discard block |
||
219 | 219 | } |
220 | 220 | |
221 | 221 | |
222 | -function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
|
222 | +function consistentListing($myconn, $alltables, $typed, $value, &$warn) { |
|
223 | 223 | /* Check if there are no pending mislisting */ |
224 | 224 | $warn = NULL; |
225 | 225 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
226 | - if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
|
226 | + if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field']) { |
|
227 | 227 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
228 | 228 | return FALSE; |
229 | 229 | } |
230 | - $entry = searchentry($myconn,$value,$alltables["$listdep"]); |
|
231 | - if ( $entry->num_rows ) { |
|
232 | - if ( $entry->num_rows == 1 ) { |
|
230 | + $entry = searchentry($myconn, $value, $alltables["$listdep"]); |
|
231 | + if ($entry->num_rows) { |
|
232 | + if ($entry->num_rows == 1) { |
|
233 | 233 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
234 | 234 | if (isListed($riga)) { |
235 | 235 | $warn = "<$value> is already present in <$listdep> list!"; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | return FALSE; |
238 | 238 | } |
239 | 239 | } |
240 | - if ( $entry->num_rows > 1 ) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!";} |
|
240 | + if ($entry->num_rows>1) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!"; } |
|
241 | 241 | } |
242 | 242 | $entry->free(); |
243 | 243 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | return TRUE; |
246 | 246 | } |
247 | 247 | |
248 | -function searchentry ($myconn,$value,$tablelist) { |
|
248 | +function searchentry($myconn, $value, $tablelist) { |
|
249 | 249 | /* Make a MYSQL query and return result */ |
250 | 250 | |
251 | 251 | $type = $tablelist['field']; |
@@ -255,24 +255,24 @@ discard block |
||
255 | 255 | else { |
256 | 256 | switch ($type) { |
257 | 257 | case 'ip': |
258 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
258 | + $query = "select * from $table where $type = INET_ATON('$value')"; |
|
259 | 259 | break; |
260 | 260 | case 'network': |
261 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
262 | - $query= 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; |
|
261 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
262 | + $query = 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; |
|
263 | 263 | break; |
264 | 264 | default: |
265 | - $query= "select * from $table where $type = '$value'"; |
|
265 | + $query = "select * from $table where $type = '$value'"; |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | |
269 | 269 | $result = $myconn->query($query); |
270 | - if($result === false) |
|
270 | + if ($result === false) |
|
271 | 271 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
272 | 272 | return $result; |
273 | 273 | } |
274 | 274 | |
275 | -function countListed ($myconn,$table) { |
|
275 | +function countListed($myconn, $table) { |
|
276 | 276 | /* Return number of current listed items into a rbl table */ |
277 | 277 | $number = 0; |
278 | 278 | $query = "SELECT COUNT(*) as `count` FROM `$table` WHERE (`active`=1 AND TIMESTAMPDIFF(MICROSECOND,NOW(),`exp`)>0) GROUP BY `active` ORDER BY `count` DESC LIMIT 1"; |
@@ -284,37 +284,37 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | |
287 | -function isFull($myconn,$typedesc,$alltables) { |
|
287 | +function isFull($myconn, $typedesc, $alltables) { |
|
288 | 288 | if (isset($alltables["$typedesc"]['limit'])) { |
289 | - if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) |
|
289 | + if (countListed($myconn, $alltables["$typedesc"]['name'])>=$alltables["$typedesc"]['limit']) |
|
290 | 290 | return TRUE; |
291 | 291 | } |
292 | 292 | return FALSE; |
293 | 293 | } |
294 | 294 | |
295 | -function rlookup ($myconn,$user,$adm,$value,$typedesc,$tables) { |
|
295 | +function rlookup($myconn, $user, $adm, $value, $typedesc, $tables) { |
|
296 | 296 | |
297 | 297 | $type = $tables["$typedesc"]['field']; |
298 | 298 | $table = $tables["$typedesc"]['name']; |
299 | 299 | |
300 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
300 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); |
|
301 | 301 | if ($result) { |
302 | 302 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
303 | 303 | |
304 | 304 | /* Check for limit in number of listed items */ |
305 | - $full = isFull($myconn,$typedesc,$tables); |
|
305 | + $full = isFull($myconn, $typedesc, $tables); |
|
306 | 306 | if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
307 | 307 | |
308 | 308 | if ($result->num_rows) { |
309 | 309 | print '<table><thead><tr><th>'.$type.'</th><th title="The date this object has been listed for the first time">DateAdd</th><th>DateMod</th><th>Exp</th><th>Status</th><th title="Number of times this object has been listed">#List</th><th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
310 | - $i=0; |
|
310 | + $i = 0; |
|
311 | 311 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
312 | 312 | if (isListed($riga)) { |
313 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
314 | - else $listed='WhiteListed'; |
|
313 | + if ($tables["$typedesc"]['bl']) $listed = 'Listed'; |
|
314 | + else $listed = 'WhiteListed'; |
|
315 | 315 | } |
316 | 316 | else |
317 | - $listed='Ok'; |
|
317 | + $listed = 'Ok'; |
|
318 | 318 | |
319 | 319 | switch ($type) { |
320 | 320 | case 'ip': |
@@ -327,15 +327,15 @@ discard block |
||
327 | 327 | $element = $riga["$type"]; |
328 | 328 | } |
329 | 329 | |
330 | - printf ("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm)); |
|
330 | + printf("<tr id=id$i><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], $riga['user'], htmlspecialchars($riga['reason']), ask($myconn, $i, $listed, $tables, $typedesc, $element, $full, $user, $adm)); |
|
331 | 331 | $i++; |
332 | 332 | } |
333 | 333 | print '</tbody></table>'; |
334 | 334 | } |
335 | 335 | else { |
336 | 336 | print "<pre>$type <$value> is not listed!\n</pre>"; |
337 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
338 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
337 | + if (in_array($user, array_keys($adm)) AND ($value != 'ALL')) |
|
338 | + if ((!$full) AND (consistentListing($myconn, $tables, $typedesc, $value, $whynot))) require_once('listForm.php'); |
|
339 | 339 | else print '<p>'.htmlspecialchars($whynot).'</p>'; |
340 | 340 | |
341 | 341 | } |
@@ -345,12 +345,12 @@ discard block |
||
345 | 345 | } |
346 | 346 | |
347 | 347 | |
348 | -function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
|
348 | +function sendEmailWarn($tplf, $from, $to, $sbj, $emailListed, $intervalToExpire, $detail) { |
|
349 | 349 | $now = time(); |
350 | - setlocale (LC_TIME, 'it_IT'); |
|
351 | - $date = date("r",$now); |
|
352 | - $messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"]; |
|
353 | - $mua = 'PHP/' . phpversion(); |
|
350 | + setlocale(LC_TIME, 'it_IT'); |
|
351 | + $date = date("r", $now); |
|
352 | + $messageID = md5(uniqid($now, 1)).'@'.$_SERVER["HOSTNAME"]; |
|
353 | + $mua = 'PHP/'.phpversion(); |
|
354 | 354 | |
355 | 355 | /* Parsing headers */ |
356 | 356 | if (!file_exists($tplf['header'])) { |
@@ -359,10 +359,10 @@ discard block |
||
359 | 359 | } |
360 | 360 | |
361 | 361 | $head_tmpl = file_get_contents($tplf['header']); |
362 | - $arr_tpl_vars = array('{from}','{to}','{date}','{messageID}','{mua}'); |
|
363 | - $arr_tpl_data = array($from,$to,$date,$messageID,$mua); |
|
362 | + $arr_tpl_vars = array('{from}', '{to}', '{date}', '{messageID}', '{mua}'); |
|
363 | + $arr_tpl_data = array($from, $to, $date, $messageID, $mua); |
|
364 | 364 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
365 | - $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
|
365 | + $headers = preg_replace('/\r|\n/', "\r\n", $headers); |
|
366 | 366 | |
367 | 367 | /* Parsing body */ |
368 | 368 | |
@@ -372,63 +372,63 @@ discard block |
||
372 | 372 | } |
373 | 373 | |
374 | 374 | $body_tmpl = file_get_contents($tplf['body']); |
375 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
376 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
375 | + $arr_tpl_vars = array('{emailListed}', '{expInterval}', '{reason}'); |
|
376 | + $arr_tpl_data = array($emailListed, $intervalToExpire, $detail); |
|
377 | 377 | $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
378 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
379 | - $body = wordwrap ( $body, 75 , "\r\n" ); |
|
378 | + $body = preg_replace("/\r|\n/", "\r\n", $body); |
|
379 | + $body = wordwrap($body, 75, "\r\n"); |
|
380 | 380 | |
381 | 381 | /* Send the mail! */ |
382 | 382 | $params = NULL; |
383 | - if ( strlen(ini_get("safe_mode"))< 1) { |
|
383 | + if (strlen(ini_get("safe_mode"))<1) { |
|
384 | 384 | $old_mailfrom = ini_get("sendmail_from"); |
385 | 385 | ini_set("sendmail_from", $from); |
386 | 386 | $params = sprintf("-oi -f %s", '<>'); |
387 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
388 | - else $flag=TRUE; |
|
387 | + if (!(mail($to, $sbj, $body, $headers, $params))) $flag = FALSE; |
|
388 | + else $flag = TRUE; |
|
389 | 389 | if (isset($old_mailfrom)) |
390 | 390 | ini_set("sendmail_from", $old_mailfrom); |
391 | 391 | } |
392 | 392 | else { |
393 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
394 | - else $flag=TRUE; |
|
393 | + if (!(mail($to, $sbj, $body, $headers))) $flag = FALSE; |
|
394 | + else $flag = TRUE; |
|
395 | 395 | } |
396 | 396 | return $flag; |
397 | 397 | } |
398 | 398 | |
399 | -function emailToNotify($notify_file,$dom) { |
|
399 | +function emailToNotify($notify_file, $dom) { |
|
400 | 400 | $ini_array = parse_ini_file($notify_file); |
401 | - if (in_array($dom,array_keys($ini_array))) |
|
401 | + if (in_array($dom, array_keys($ini_array))) |
|
402 | 402 | return $ini_array["$dom"]; |
403 | 403 | else return FALSE; |
404 | 404 | } |
405 | 405 | |
406 | 406 | |
407 | -function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
|
407 | +function searchAndList($myconn, $loguser, $tables, $typedesc, $value, $unit, &$quantity, $reason) { |
|
408 | 408 | |
409 | 409 | /* Search and list value */ |
410 | 410 | $type = $tables["$typedesc"]['field']; |
411 | 411 | $table = $tables["$typedesc"]['name']; |
412 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
412 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); |
|
413 | 413 | |
414 | 414 | /* Manage abnormal conditions */ |
415 | 415 | /* Value already present in db more than once. This is absurd. Panic! */ |
416 | - if ($result->num_rows > 1) { |
|
417 | - syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
416 | + if ($result->num_rows>1) { |
|
417 | + syslog(LOG_EMERG, "$loguser: PANIC! Select for $type '$value' returned ".$result->num_rows." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
418 | 418 | $result->free(); |
419 | 419 | return FALSE; |
420 | 420 | } |
421 | 421 | |
422 | 422 | /* Value already present in db or not present: to list anyway */ |
423 | - if ($result->num_rows >= 0) { |
|
423 | + if ($result->num_rows>=0) { |
|
424 | 424 | /* First, check for limit in number of listed items */ |
425 | - if (isFull($myconn,$typedesc,$tables)) { |
|
426 | - syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
425 | + if (isFull($myconn, $typedesc, $tables)) { |
|
426 | + syslog(LOG_EMERG, "$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
427 | 427 | $result->free(); |
428 | 428 | return FALSE; |
429 | 429 | } |
430 | 430 | /* Second, check if the (re)list would be consistent now */ |
431 | - if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
431 | + if (!consistentListing($myconn, $tables, $typedesc, $value, $whynot)) { |
|
432 | 432 | syslog(LOG_ERR, $loguser.': '.$whynot); |
433 | 433 | $result->free(); |
434 | 434 | return FALSE; |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | /* Relist value if already present */ |
444 | 444 | case 1: |
445 | 445 | /* Entry already listed */ |
446 | - if ( isListed($thisentry) ) { |
|
446 | + if (isListed($thisentry)) { |
|
447 | 447 | syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.'); |
448 | 448 | $result->free(); |
449 | 449 | return FALSE; |
@@ -452,13 +452,13 @@ discard block |
||
452 | 452 | /* Entry delisted */ |
453 | 453 | $result->free(); |
454 | 454 | $quantity *= $thisentry['nlist']; |
455 | - return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
455 | + return relist($myconn, $loguser, $value, $type, $table, $unit, $quantity, $reason); |
|
456 | 456 | |
457 | 457 | |
458 | 458 | /* First time list value */ |
459 | 459 | case 0: |
460 | 460 | $result->free(); |
461 | - return addtolist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
461 | + return addtolist($myconn, $loguser, $value, $type, $table, $unit, $quantity, $reason); |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 |
@@ -1,22 +1,22 @@ |
||
1 | 1 | <?php |
2 | 2 | require_once('config.php'); |
3 | 3 | require_once('function.php'); |
4 | -$typedesc=$_POST['type']; |
|
5 | -$type = $tables["$typedesc"]['field']; |
|
4 | +$typedesc = $_POST['type']; |
|
5 | +$type = $tables["$typedesc"]['field']; |
|
6 | 6 | $table = $tables["$typedesc"]['name']; |
7 | 7 | |
8 | 8 | openlog($tag, LOG_PID, $fac); |
9 | 9 | $user = username(); |
10 | 10 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); |
11 | 11 | if ($mysqli->connect_error) { |
12 | - syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
12 | + syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
13 | 13 | . $mysqli->connect_error); |
14 | - die($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
14 | + die($user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
15 | 15 | . $mysqli->connect_error); |
16 | 16 | } |
17 | -syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); |
|
17 | +syslog(LOG_INFO, $user.': Successfully connected to '.$mysqli->host_info); |
|
18 | 18 | |
19 | -if (remove ($_POST['value'],$type,$table)) |
|
19 | +if (remove($_POST['value'], $type, $table)) |
|
20 | 20 | print 'OK '.$typedesc.' <'.$_POST['value'].'> permanently REMOVED!'; |
21 | 21 | else |
22 | 22 | print 'Delete operation ERROR on '.$typedesc.' <'.$_POST['value'].'>; check log.'; |
@@ -1,26 +1,26 @@ |
||
1 | 1 | <?php |
2 | 2 | require_once('config.php'); |
3 | 3 | require_once('function.php'); |
4 | -$typedesc=$_POST['type']; |
|
4 | +$typedesc = $_POST['type']; |
|
5 | 5 | $type = $tables["$typedesc"]['field']; |
6 | 6 | $table = $tables["$typedesc"]['name']; |
7 | 7 | |
8 | 8 | openlog($tag, LOG_PID, $fac); |
9 | 9 | if (empty($_POST['reason'])) die ("<p>Please, specify a reason!</p>"); |
10 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) |
|
11 | - exit('<p>ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</p>'); |
|
10 | +if (preg_match('/[^\x20-\x7f]/', $_POST['reason'])) |
|
11 | + exit('<p>ERROR: <'.htmlentities($_POST['reason'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</p>'); |
|
12 | 12 | $user = username(); |
13 | 13 | |
14 | 14 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); |
15 | 15 | if ($mysqli->connect_error) { |
16 | - syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
16 | + syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
17 | 17 | . $mysqli->connect_error); |
18 | - die($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
18 | + die($user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
19 | 19 | . $mysqli->connect_error); |
20 | 20 | } |
21 | -syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); |
|
21 | +syslog(LOG_INFO, $user.': Successfully connected to '.$mysqli->host_info); |
|
22 | 22 | |
23 | -if (addtolist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) |
|
23 | +if (addtolist($mysqli, username(), $_POST['value'], $type, $table, $_POST['unit'], $_POST['quantity'], $_POST['reason'])) |
|
24 | 24 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> first time listed for '.$_POST['quantity'].$_POST['unit'].'.'; |
25 | 25 | else |
26 | 26 | print 'List operation ERROR; check log.'; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | require_once('config.php'); |
3 | 3 | require_once('function.php'); |
4 | -$typedesc=$_POST['type']; |
|
4 | +$typedesc = $_POST['type']; |
|
5 | 5 | $type = $tables["$typedesc"]['field']; |
6 | 6 | $table = $tables["$typedesc"]['name']; |
7 | 7 | ?> |
@@ -9,21 +9,21 @@ discard block |
||
9 | 9 | <?php |
10 | 10 | openlog($tag, LOG_PID, $fac); |
11 | 11 | if (empty($_POST['reason'])) die ("Specify a reason, please!</td>"); |
12 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) |
|
13 | - exit('ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</td>'); |
|
12 | +if (preg_match('/[^\x20-\x7f]/', $_POST['reason'])) |
|
13 | + exit('ERROR: <'.htmlentities($_POST['reason'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</td>'); |
|
14 | 14 | $user = username(); |
15 | 15 | |
16 | 16 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); |
17 | 17 | if ($mysqli->connect_error) { |
18 | - syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
18 | + syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
19 | 19 | . $mysqli->connect_error); |
20 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
20 | + exit ($user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
21 | 21 | . $mysqli->connect_error); |
22 | 22 | } |
23 | -syslog(LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info) ; |
|
23 | +syslog(LOG_INFO, $user.': Successfully connected to '.$mysqli->host_info); |
|
24 | 24 | |
25 | -if (isFull($mysqli,$typedesc,$tables)) die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.') ); |
|
26 | -if (relist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) |
|
25 | +if (isFull($mysqli, $typedesc, $tables)) die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.')); |
|
26 | +if (relist($mysqli, username(), $_POST['value'], $type, $table, $_POST['unit'], $_POST['quantity'], $_POST['reason'])) |
|
27 | 27 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> relisted for '.$_POST['quantity'].$_POST['unit']; |
28 | 28 | else |
29 | 29 | print 'ERROR in relist; check log'; |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | -if (in_array($user,array_keys(array_filter($adm)))) $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
2 | +if (in_array($user, array_keys(array_filter($adm)))) $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
3 | 3 | else $extopt = NULL; |
4 | 4 | ?> |
5 | 5 | <form style="margin:0; text-align: left;" name='ListButton<?php echo $type ?>' enctype="text/plain" method="post" target="_self" action="list.php" onSubmit="xmlhttpPost('list.php', 'ListButton<?php echo $type ?>', 'Risultato', '<img src=\'/include/pleasewait.gif\'>'); return false;" /> |
6 | 6 | |
7 | 7 | List <?php echo $typedesc.' <'.$value.'>'; ?> for <input name="type" type="hidden" value="<?php echo $typedesc; ?>" /><input name="value" type="hidden" class="input_text" value="<?php echo $value; ?>" /> |
8 | - <select name="quantity" class="input_text" size="1"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="20">20</option></select><select class="input_text" name="unit" size="1"><option value="DAY">DAYS</option><option value="WEEK">WEEKS</option><?php echo $extopt;?></select> Reason:<input maxlength="128" name="reason" size="30" type="text" class="input_text" /><input name="List" class="button" id="bwarn" type="submit" value="List"/></form> |
|
8 | + <select name="quantity" class="input_text" size="1"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="20">20</option></select><select class="input_text" name="unit" size="1"><option value="DAY">DAYS</option><option value="WEEK">WEEKS</option><?php echo $extopt; ?></select> Reason:<input maxlength="128" name="reason" size="30" type="text" class="input_text" /><input name="List" class="button" id="bwarn" type="submit" value="List"/></form> |
@@ -10,33 +10,33 @@ discard block |
||
10 | 10 | # |
11 | 11 | */ |
12 | 12 | |
13 | -$shortopts = "c:"; // Required value |
|
13 | +$shortopts = "c:"; // Required value |
|
14 | 14 | $options = getopt($shortopts); |
15 | -if ( !isset($options['c']) ) exit ("\n\nUSAGE: ${_SERVER['SCRIPT_NAME']} -c <file.conf>\n\n"); |
|
16 | -if ( !file_exists(dirname(__FILE__) . '/' . $options['c']) ) exit ("\n\nThe file <".$options['c']."> doesn't exists.\nExiting...\n\n"); |
|
15 | +if (!isset($options['c'])) exit ("\n\nUSAGE: ${_SERVER['SCRIPT_NAME']} -c <file.conf>\n\n"); |
|
16 | +if (!file_exists(dirname(__FILE__).'/'.$options['c'])) exit ("\n\nThe file <".$options['c']."> doesn't exists.\nExiting...\n\n"); |
|
17 | 17 | |
18 | 18 | /************** Start of conf ************************/ |
19 | 19 | require_once('config.php'); |
20 | 20 | |
21 | 21 | /* Syslog */ |
22 | -$tag .= 'SplunkLister'; |
|
22 | +$tag .= 'SplunkLister'; |
|
23 | 23 | |
24 | -$conf = parse_ini_file( dirname(__FILE__) . '/' . $options['c'] ); |
|
24 | +$conf = parse_ini_file(dirname(__FILE__).'/'.$options['c']); |
|
25 | 25 | |
26 | 26 | /* Splunk inherited parameters */ |
27 | -$threshold = $conf['threshold']; /* Threshold value on trigger condition; the same which engage the alert */ |
|
28 | -$splfile = $argv[10]; /* Full path of result Splunk file, see at |
|
27 | +$threshold = $conf['threshold']; /* Threshold value on trigger condition; the same which engage the alert */ |
|
28 | +$splfile = $argv[10]; /* Full path of result Splunk file, see at |
|
29 | 29 | http://docs.splunk.com/Documentation/Splunk/6.2.2/Alert/Configuringscriptedalerts |
30 | 30 | It is 8+2 because of -c <conf> */ |
31 | 31 | /* Blacklist name */ |
32 | -$typedesc = $conf['typedesc']; |
|
32 | +$typedesc = $conf['typedesc']; |
|
33 | 33 | |
34 | 34 | /* How long to list's parameters */ |
35 | -$unit = $conf['unit']; /* MySQL language ;) */ |
|
35 | +$unit = $conf['unit']; /* MySQL language ;) */ |
|
36 | 36 | $quantity = $conf['quantity']; |
37 | 37 | |
38 | 38 | /* Syslog */ |
39 | -$tag .= $conf['tag']; |
|
39 | +$tag .= $conf['tag']; |
|
40 | 40 | |
41 | 41 | /************** End of conf *************************/ |
42 | 42 | |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | $user = 'Splunk'; |
48 | 48 | |
49 | 49 | /* check you select a blocklist */ |
50 | -if ( !$tables["$typedesc"]['bl'] ) { |
|
51 | - syslog(LOG_EMERG,"$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
50 | +if (!$tables["$typedesc"]['bl']) { |
|
51 | + syslog(LOG_EMERG, "$user: <$typedesc> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue."); |
|
52 | 52 | exit (254); |
53 | 53 | } |
54 | 54 | |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | |
69 | 69 | $tolist = array(); |
70 | 70 | |
71 | -if ( !file_exists($splfile) ) { |
|
72 | - syslog(LOG_ERR,"$user: File <$splfile> not found! Exit."); |
|
71 | +if (!file_exists($splfile)) { |
|
72 | + syslog(LOG_ERR, "$user: File <$splfile> not found! Exit."); |
|
73 | 73 | exit (254); |
74 | 74 | } |
75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $thisVal = $data[1]; |
82 | 82 | unset($data[1]); |
83 | 83 | $data = array_values($data); |
84 | - if ( !in_array($thisVal,array_keys($tolist)) ) |
|
84 | + if (!in_array($thisVal, array_keys($tolist))) |
|
85 | 85 | $tolist["$thisVal"] = $data; |
86 | 86 | else if ($data[3]>$tolist[$thisVal][3]) |
87 | 87 | $tolist["$thisVal"] = $data; |
@@ -93,46 +93,46 @@ discard block |
||
93 | 93 | |
94 | 94 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); |
95 | 95 | if ($mysqli->connect_error) { |
96 | - syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
96 | + syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
97 | 97 | . $mysqli->connect_error); |
98 | 98 | exit (254); |
99 | 99 | |
100 | 100 | } |
101 | 101 | |
102 | -syslog(LOG_INFO, $user.': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
102 | +syslog(LOG_INFO, $user.': Successfully mysql connected to '.$mysqli->host_info); |
|
103 | 103 | |
104 | -foreach ( array_keys($tolist) as $value) { |
|
104 | +foreach (array_keys($tolist) as $value) { |
|
105 | 105 | $reason = 'On ['.$tolist["$value"][0]."] <$value> sent ".$tolist["$value"][1].' messages to '.$tolist["$value"][2].' recipients.'; |
106 | - if ( $tolist["$value"][3] >= $threshold ) { |
|
107 | - if ( searchAndList ($mysqli,$user,$tables,$typedesc,$value,$unit,$quantity,$reason) ) { |
|
108 | - syslog (LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
106 | + if ($tolist["$value"][3]>=$threshold) { |
|
107 | + if (searchAndList($mysqli, $user, $tables, $typedesc, $value, $unit, $quantity, $reason)) { |
|
108 | + syslog(LOG_INFO, "$user: ".'Listing reason: '.$reason); |
|
109 | 109 | /* Send a email to domain admin if you list an email */ |
110 | - if ( ( $tables["$typedesc"]['field'] == 'email' ) OR ( $tables["$typedesc"]['field'] == 'username' ) ) { |
|
110 | + if (($tables["$typedesc"]['field'] == 'email') OR ($tables["$typedesc"]['field'] == 'username')) { |
|
111 | 111 | /* Sometime uid are in the form of <user>@<domain> ... */ |
112 | - if ( strpos($value, '@') !== FALSE ) { |
|
113 | - $domain = array_pop(explode('@',$value,2)); |
|
114 | - if ( strpos($domain, '@') === FALSE ) { |
|
115 | - $recip = emailToNotify($domainNotify_file,$domain); |
|
112 | + if (strpos($value, '@') !== FALSE) { |
|
113 | + $domain = array_pop(explode('@', $value, 2)); |
|
114 | + if (strpos($domain, '@') === FALSE) { |
|
115 | + $recip = emailToNotify($domainNotify_file, $domain); |
|
116 | 116 | $subject = sprintf('%s <%s> is now blocked because exceedes limits on outgoing emails', |
117 | 117 | $tables["$typedesc"]['field'], $value); |
118 | 118 | if (!empty($recip)) |
119 | - if ( sendEmailWarn($tplfile,'[email protected]',$recip, |
|
120 | - $subject,$value,"$quantity $unit",$reason) ) |
|
119 | + if (sendEmailWarn($tplfile, '[email protected]', $recip, |
|
120 | + $subject, $value, "$quantity $unit", $reason)) |
|
121 | 121 | syslog(LOG_INFO, "$user: \"$recip\" was notified about the \"$value\" abuse."); |
122 | 122 | } |
123 | - else syslog(LOG_ERR,"$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
123 | + else syslog(LOG_ERR, "$user: <$domain> contains the '@' char. Notification cannot be sent."); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
128 | 128 | else { |
129 | 129 | $reason .= " But it has NOT been listed because it doesn't apply to the trigger condition."; |
130 | - syslog (LOG_INFO, "$user: ".$reason); |
|
130 | + syslog(LOG_INFO, "$user: ".$reason); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
134 | 134 | /* Close connection */ |
135 | -syslog (LOG_INFO, "$user: ".'Successfully end of session.'); |
|
135 | +syslog(LOG_INFO, "$user: ".'Successfully end of session.'); |
|
136 | 136 | $mysqli->close(); |
137 | 137 | closelog(); |
138 | 138 |
@@ -19,74 +19,74 @@ discard block |
||
19 | 19 | $user = username(); |
20 | 20 | |
21 | 21 | $opts = getopt('f:t:'); |
22 | -if ( isset($opts['f']) ) { |
|
22 | +if (isset($opts['f'])) { |
|
23 | 23 | $filetemplate = $opts['f']; |
24 | -} else { |
|
24 | +}else { |
|
25 | 25 | print "\nNo option for '-f' given.\n"; |
26 | - exit ( usage() ); |
|
26 | + exit (usage()); |
|
27 | 27 | } |
28 | 28 | |
29 | -if ( isset($opts['t']) ) { |
|
29 | +if (isset($opts['t'])) { |
|
30 | 30 | $tablename = $opts['t']; |
31 | -} else { |
|
31 | +}else { |
|
32 | 32 | print "\nNo option for '-t' given.\n"; |
33 | - exit ( usage() ); |
|
33 | + exit (usage()); |
|
34 | 34 | } |
35 | 35 | |
36 | -if ( ($typedescN = array_search( $tablename, array_column($tables, 'name'))) === FALSE ) { |
|
36 | +if (($typedescN = array_search($tablename, array_column($tables, 'name'))) === FALSE) { |
|
37 | 37 | print "\nDB <$tablename> doesn't exist!\n"; |
38 | - syslog (LOG_EMERG, "$user: DB <$tablename> doesn't exist!"); |
|
39 | - exit ( usage() ); |
|
38 | + syslog(LOG_EMERG, "$user: DB <$tablename> doesn't exist!"); |
|
39 | + exit (usage()); |
|
40 | 40 | } |
41 | 41 | $typedesc = array_keys($tables)[$typedescN]; |
42 | 42 | |
43 | -if (! file_exists($filetemplate) ) { |
|
43 | +if (!file_exists($filetemplate)) { |
|
44 | 44 | print "\nFile <$filetemplate> doesn't exists!\n"; |
45 | - syslog (LOG_EMERG, "$user: File <$filetemplate> doesn't exist!"); |
|
46 | - exit ( usage() ); |
|
45 | + syslog(LOG_EMERG, "$user: File <$filetemplate> doesn't exist!"); |
|
46 | + exit (usage()); |
|
47 | 47 | } |
48 | 48 | |
49 | -if (! in_array( $typedesc, array_keys($tables) ) ) { |
|
49 | +if (!in_array($typedesc, array_keys($tables))) { |
|
50 | 50 | print "\nUnknown list <$typedesc>. Please provide an existent list name.\n"; |
51 | - exit ( usage() ); |
|
51 | + exit (usage()); |
|
52 | 52 | } |
53 | 53 | |
54 | -if (! $tables["$typedesc"]['active'] ) { |
|
54 | +if (!$tables["$typedesc"]['active']) { |
|
55 | 55 | print "\nList <$typedesc> is not active. Please provide an active list name.\n"; |
56 | - exit ( usage() ); |
|
56 | + exit (usage()); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | |
60 | 60 | |
61 | -$now=new DateTime('NOW'); |
|
61 | +$now = new DateTime('NOW'); |
|
62 | 62 | $timeunix = $now->format('U'); |
63 | 63 | $dateRFC822 = $now->format('r'); |
64 | 64 | $year = $now->format('Y'); |
65 | -$rbltype= ($tables["$typedesc"]['bl']) ? 'Blocklist' : 'Whitelist'; |
|
65 | +$rbltype = ($tables["$typedesc"]['bl']) ? 'Blocklist' : 'Whitelist'; |
|
66 | 66 | |
67 | 67 | |
68 | 68 | $tmpl = file_get_contents($filetemplate); |
69 | -$arr_tpl_vars = array('{rblname}','{rbltype}','{date822}','{year}','{unixtimestamp}','{rblname64}','{hostname}'); |
|
70 | -$arr_tpl_data = array($typedesc,$rbltype,$dateRFC822,$year,$timeunix,base64_encode($typedesc),gethostname()); |
|
69 | +$arr_tpl_vars = array('{rblname}', '{rbltype}', '{date822}', '{year}', '{unixtimestamp}', '{rblname64}', '{hostname}'); |
|
70 | +$arr_tpl_data = array($typedesc, $rbltype, $dateRFC822, $year, $timeunix, base64_encode($typedesc), gethostname()); |
|
71 | 71 | $headerList = str_replace($arr_tpl_vars, $arr_tpl_data, $tmpl); |
72 | 72 | |
73 | 73 | |
74 | 74 | $mysqli = new mysqli($dbhost, $userdb, $pwd, $db, $dbport); |
75 | 75 | if ($mysqli->connect_error) { |
76 | - syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
76 | + syslog(LOG_EMERG, $user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
77 | 77 | . $mysqli->connect_error); |
78 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
78 | + exit ($user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
79 | 79 | . $mysqli->connect_error); |
80 | 80 | } |
81 | 81 | |
82 | -syslog(LOG_INFO, $user.': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
82 | +syslog(LOG_INFO, $user.': Successfully mysql connected to '.$mysqli->host_info); |
|
83 | 83 | |
84 | -$result = searchentry ($mysqli,'ALL',$tables["$typedesc"]); |
|
84 | +$result = searchentry($mysqli, 'ALL', $tables["$typedesc"]); |
|
85 | 85 | if ($result->num_rows) { |
86 | 86 | $element = array(); |
87 | 87 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
88 | 88 | if (isListed($riga)) { |
89 | - switch ( $tables["$typedesc"]['field'] ) { |
|
89 | + switch ($tables["$typedesc"]['field']) { |
|
90 | 90 | case 'ip': |
91 | 91 | $element[] = long2ip($riga['ip']); |
92 | 92 | break; |
@@ -104,6 +104,6 @@ discard block |
||
104 | 104 | $mysqli->close(); |
105 | 105 | |
106 | 106 | /* Print to file */ |
107 | -file_put_contents( $tables["$typedesc"]['name'], $headerList . implode("\n",$element) ); |
|
107 | +file_put_contents($tables["$typedesc"]['name'], $headerList.implode("\n", $element)); |
|
108 | 108 | closelog(); |
109 | 109 | ?> |