@@ -1,25 +1,25 @@ 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; |
|
| 18 | - $sub=array(); |
|
| 17 | + $result = FALSE; |
|
| 18 | + $sub = array(); |
|
| 19 | 19 | |
| 20 | 20 | switch ($type) { |
| 21 | 21 | case 'ip': |
| 22 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 22 | + $query = sprintf("INSERT INTO `$table` ( |
|
| 23 | 23 | `$type` , |
| 24 | 24 | `date` , |
| 25 | 25 | `exp` , |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | VALUES ( |
| 31 | 31 | INET_ATON( '%s' ) , |
| 32 | 32 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 33 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
| 33 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
| 34 | 34 | break; |
| 35 | 35 | |
| 36 | 36 | case 'network': |
| 37 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 38 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 37 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 38 | + $query = sprintf("INSERT INTO `$table` ( |
|
| 39 | 39 | `$type` , |
| 40 | 40 | `netmask`, |
| 41 | 41 | `date` , |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | VALUES ( |
| 48 | 48 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
| 49 | 49 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 50 | - )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
|
| 50 | + )", $sub['net'], $sub['mask'], $expUnit, $expQ, $user, $myreason); |
|
| 51 | 51 | break; |
| 52 | 52 | |
| 53 | 53 | default: |
| 54 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 54 | + $query = sprintf("INSERT INTO `$table` ( |
|
| 55 | 55 | `$type` , |
| 56 | 56 | `date` , |
| 57 | 57 | `exp` , |
@@ -62,60 +62,60 @@ discard block |
||
| 62 | 62 | VALUES ( |
| 63 | 63 | '%s' , |
| 64 | 64 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 65 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
| 65 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | if ($myconn->query($query) === TRUE) { |
| 69 | 69 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
| 70 | - $result=TRUE; |
|
| 70 | + $result = TRUE; |
|
| 71 | 71 | } |
| 72 | 72 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
| 73 | 73 | return $result; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | -function relist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason) { |
|
| 76 | +function relist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason) { |
|
| 77 | 77 | |
| 78 | - $result=FALSE; |
|
| 78 | + $result = FALSE; |
|
| 79 | 79 | |
| 80 | 80 | switch ($type) { |
| 81 | 81 | case 'ip': |
| 82 | - $query= sprintf("UPDATE `$table` SET |
|
| 82 | + $query = sprintf("UPDATE `$table` SET |
|
| 83 | 83 | `active` = '1', |
| 84 | 84 | `user` = '%s', |
| 85 | 85 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
| 86 | 86 | `nlist` = `nlist` + 1, |
| 87 | 87 | `reason` = '%s' |
| 88 | - WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
|
| 88 | + WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $expUnit, $expQ, $myreason, $value); |
|
| 89 | 89 | break; |
| 90 | 90 | case 'network': |
| 91 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 92 | - $query= sprintf("UPDATE `$table` SET |
|
| 91 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 92 | + $query = sprintf("UPDATE `$table` SET |
|
| 93 | 93 | `active` = '1', |
| 94 | 94 | `user` = '%s', |
| 95 | 95 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
| 96 | 96 | `nlist` = `nlist` + 1, |
| 97 | 97 | `reason` = '%s' |
| 98 | - WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']); |
|
| 98 | + WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $expUnit, $expQ, $myreason, $sub['net'], $sub['mask']); |
|
| 99 | 99 | break; |
| 100 | 100 | default: |
| 101 | - $query= sprintf("UPDATE `$table` SET |
|
| 101 | + $query = sprintf("UPDATE `$table` SET |
|
| 102 | 102 | `active` = '1', |
| 103 | 103 | `user` = '%s', |
| 104 | 104 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
| 105 | 105 | `nlist` = `nlist` + 1, |
| 106 | 106 | `reason` = '%s' |
| 107 | - WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
|
| 107 | + WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $expUnit, $expQ, $myreason, $value); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | if ($myconn->query($query) === TRUE) { |
| 111 | 111 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
| 112 | - $result=TRUE; |
|
| 112 | + $result = TRUE; |
|
| 113 | 113 | } |
| 114 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 114 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 115 | 115 | return $result; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | -function remove ($myconn,$user,$value,$type,$table) { |
|
| 118 | +function remove($myconn, $user, $value, $type, $table) { |
|
| 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,39 +134,39 @@ 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; |
|
| 169 | - $log=array(); |
|
| 167 | +function expire($myconn, $user, $tables, $expireTime) { |
|
| 168 | + $return = TRUE; |
|
| 169 | + $log = array(); |
|
| 170 | 170 | $desc = array_keys($tables); |
| 171 | 171 | foreach ($desc as $tdesc) { |
| 172 | 172 | /* QUERY */ |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | } while ($myconn->next_result()); |
| 186 | 186 | } |
| 187 | 187 | else { |
| 188 | - syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
|
| 188 | + syslog(LOG_ERR, "Expire job - Error: ".$myconn->error); |
|
| 189 | 189 | $return = FALSE; |
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 192 | + if (!($return)) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 193 | 193 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
| 194 | 194 | return $return; |
| 195 | 195 | } |
@@ -197,22 +197,22 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | function isListed($row) { |
| 199 | 199 | |
| 200 | - $exp=new DateTime($row['exp']); |
|
| 201 | - $now=new DateTime('NOW'); |
|
| 202 | - if (($exp > $now) and ($row['active'])) return true; |
|
| 200 | + $exp = new DateTime($row['exp']); |
|
| 201 | + $now = new DateTime('NOW'); |
|
| 202 | + if (($exp>$now) and ($row['active'])) return true; |
|
| 203 | 203 | else return false; |
| 204 | 204 | |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
| 208 | -function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { |
|
| 208 | +function ask($myconn, $id, $what, $alltables, $typedesc, $value, $lock, $user, $adm) { |
|
| 209 | 209 | |
| 210 | - $whynot=NULL; |
|
| 210 | + $whynot = NULL; |
|
| 211 | 211 | switch ($what) { |
| 212 | 212 | case 'Ok': |
| 213 | 213 | if ($lock) return NULL; |
| 214 | - if (in_array($user,array_keys($adm))) |
|
| 215 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 214 | + if (in_array($user, array_keys($adm))) |
|
| 215 | + if (consistentListing($myconn, $alltables, $typedesc, $value, $whynot)) return require('relistButton.php'); |
|
| 216 | 216 | return htmlspecialchars($whynot); |
| 217 | 217 | case 'Listed': |
| 218 | 218 | case 'WhiteListed': |
@@ -221,17 +221,17 @@ discard block |
||
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | |
| 224 | -function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
|
| 224 | +function consistentListing($myconn, $alltables, $typed, $value, &$warn) { |
|
| 225 | 225 | /* Check if there are no pending mislisting */ |
| 226 | 226 | $warn = NULL; |
| 227 | 227 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
| 228 | - if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
|
| 228 | + if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field']) { |
|
| 229 | 229 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
| 230 | 230 | return FALSE; |
| 231 | 231 | } |
| 232 | - $entry = searchentry($myconn,$value,$alltables["$listdep"]); |
|
| 233 | - if ( $entry->num_rows ) { |
|
| 234 | - if ( $entry->num_rows == 1 ) { |
|
| 232 | + $entry = searchentry($myconn, $value, $alltables["$listdep"]); |
|
| 233 | + if ($entry->num_rows) { |
|
| 234 | + if ($entry->num_rows == 1) { |
|
| 235 | 235 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
| 236 | 236 | if (isListed($riga)) { |
| 237 | 237 | $warn = "<$value> is already present in <$listdep> list!"; |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | return FALSE; |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | - if ( $entry->num_rows > 1 ) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!";} |
|
| 242 | + if ($entry->num_rows>1) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!"; } |
|
| 243 | 243 | } |
| 244 | 244 | $entry->free(); |
| 245 | 245 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | return TRUE; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | -function searchentry ($myconn,$value,$tablelist) { |
|
| 250 | +function searchentry($myconn, $value, $tablelist) { |
|
| 251 | 251 | /* Make a MYSQL query and return result */ |
| 252 | 252 | |
| 253 | 253 | $type = $tablelist['field']; |
@@ -257,24 +257,24 @@ discard block |
||
| 257 | 257 | else { |
| 258 | 258 | switch ($type) { |
| 259 | 259 | case 'ip': |
| 260 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 260 | + $query = "select * from $table where $type = INET_ATON('$value')"; |
|
| 261 | 261 | break; |
| 262 | 262 | case 'network': |
| 263 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 264 | - $query= 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; |
|
| 263 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 264 | + $query = 'select * from '.$table.' where (((inet_aton(\''.$sub['net'].'\') | (~ inet_aton(\''.$sub['mask'].'\'))) & netmask) = network)'; |
|
| 265 | 265 | break; |
| 266 | 266 | default: |
| 267 | - $query= "select * from $table where $type = '$value'"; |
|
| 267 | + $query = "select * from $table where $type = '$value'"; |
|
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | $result = $myconn->query($query); |
| 272 | - if($result === false) |
|
| 272 | + if ($result === false) |
|
| 273 | 273 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
| 274 | 274 | return $result; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | -function countListed ($myconn,$table) { |
|
| 277 | +function countListed($myconn, $table) { |
|
| 278 | 278 | /* Return number of current listed items into a rbl table */ |
| 279 | 279 | $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"; |
| 280 | 280 | $row = $myconn->query($query); |
@@ -285,37 +285,37 @@ discard block |
||
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
| 288 | -function isFull($myconn,$typedesc,$alltables) { |
|
| 288 | +function isFull($myconn, $typedesc, $alltables) { |
|
| 289 | 289 | if (isset($alltables["$typedesc"]['limit'])) { |
| 290 | - if ( countListed($myconn,$alltables["$typedesc"]['name']) >= $alltables["$typedesc"]['limit'] ) |
|
| 290 | + if (countListed($myconn, $alltables["$typedesc"]['name'])>=$alltables["$typedesc"]['limit']) |
|
| 291 | 291 | return TRUE; |
| 292 | 292 | } |
| 293 | 293 | return FALSE; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | -function rlookup ($myconn,$user,$adm,$value,$typedesc,$tables) { |
|
| 296 | +function rlookup($myconn, $user, $adm, $value, $typedesc, $tables) { |
|
| 297 | 297 | |
| 298 | 298 | $type = $tables["$typedesc"]['field']; |
| 299 | - $whynot=NULL; |
|
| 299 | + $whynot = NULL; |
|
| 300 | 300 | |
| 301 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 301 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); |
|
| 302 | 302 | if ($result) { |
| 303 | 303 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
| 304 | 304 | |
| 305 | 305 | /* Check for limit in number of listed items */ |
| 306 | - $full = isFull($myconn,$typedesc,$tables); |
|
| 306 | + $full = isFull($myconn, $typedesc, $tables); |
|
| 307 | 307 | if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
| 308 | 308 | |
| 309 | 309 | if ($result->num_rows) { |
| 310 | 310 | 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"; |
| 311 | - $i=0; |
|
| 311 | + $i = 0; |
|
| 312 | 312 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
| 313 | 313 | if (isListed($riga)) { |
| 314 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
| 315 | - else $listed='WhiteListed'; |
|
| 314 | + if ($tables["$typedesc"]['bl']) $listed = 'Listed'; |
|
| 315 | + else $listed = 'WhiteListed'; |
|
| 316 | 316 | } |
| 317 | 317 | else |
| 318 | - $listed='Ok'; |
|
| 318 | + $listed = 'Ok'; |
|
| 319 | 319 | |
| 320 | 320 | switch ($type) { |
| 321 | 321 | case 'ip': |
@@ -328,15 +328,15 @@ discard block |
||
| 328 | 328 | $element = $riga["$type"]; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - 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 | + 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)); |
|
| 332 | 332 | $i++; |
| 333 | 333 | } |
| 334 | 334 | print '</tbody></table>'; |
| 335 | 335 | } |
| 336 | 336 | else { |
| 337 | 337 | print "<pre>$type <$value> is not listed!\n</pre>"; |
| 338 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
| 339 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 338 | + if (in_array($user, array_keys($adm)) AND ($value != 'ALL')) |
|
| 339 | + if ((!$full) AND (consistentListing($myconn, $tables, $typedesc, $value, $whynot))) require_once('listForm.php'); |
|
| 340 | 340 | else print '<p>'.htmlspecialchars($whynot).'</p>'; |
| 341 | 341 | |
| 342 | 342 | } |
@@ -346,12 +346,12 @@ discard block |
||
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | |
| 349 | -function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
|
| 349 | +function sendEmailWarn($tplf, $from, $to, $sbj, $emailListed, $intervalToExpire, $detail) { |
|
| 350 | 350 | $now = time(); |
| 351 | - setlocale (LC_TIME, 'it_IT'); |
|
| 352 | - $date = date("r",$now); |
|
| 353 | - $messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"]; |
|
| 354 | - $mua = 'PHP/' . phpversion(); |
|
| 351 | + setlocale(LC_TIME, 'it_IT'); |
|
| 352 | + $date = date("r", $now); |
|
| 353 | + $messageID = md5(uniqid($now, 1)).'@'.$_SERVER["HOSTNAME"]; |
|
| 354 | + $mua = 'PHP/'.phpversion(); |
|
| 355 | 355 | |
| 356 | 356 | /* Parsing headers */ |
| 357 | 357 | if (!file_exists($tplf['header'])) { |
@@ -360,10 +360,10 @@ discard block |
||
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | $head_tmpl = file_get_contents($tplf['header']); |
| 363 | - $arr_tpl_vars = array('{from}','{to}','{date}','{messageID}','{mua}'); |
|
| 364 | - $arr_tpl_data = array($from,$to,$date,$messageID,$mua); |
|
| 363 | + $arr_tpl_vars = array('{from}', '{to}', '{date}', '{messageID}', '{mua}'); |
|
| 364 | + $arr_tpl_data = array($from, $to, $date, $messageID, $mua); |
|
| 365 | 365 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
| 366 | - $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
|
| 366 | + $headers = preg_replace('/\r|\n/', "\r\n", $headers); |
|
| 367 | 367 | |
| 368 | 368 | /* Parsing body */ |
| 369 | 369 | |
@@ -373,62 +373,62 @@ discard block |
||
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | $body_tmpl = file_get_contents($tplf['body']); |
| 376 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 377 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 376 | + $arr_tpl_vars = array('{emailListed}', '{expInterval}', '{reason}'); |
|
| 377 | + $arr_tpl_data = array($emailListed, $intervalToExpire, $detail); |
|
| 378 | 378 | $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
| 379 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 380 | - $body = wordwrap ( $body, 75 , "\r\n" ); |
|
| 379 | + $body = preg_replace("/\r|\n/", "\r\n", $body); |
|
| 380 | + $body = wordwrap($body, 75, "\r\n"); |
|
| 381 | 381 | |
| 382 | 382 | /* Send the mail! */ |
| 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 | |
@@ -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 | ?> |
@@ -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 ($mysqli,$user,$_POST['value'],$type,$table)) |
|
| 19 | +if (remove($mysqli, $user, $_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.'; |