@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | //timezone var, need to setup before any other tasks |
| 14 | 14 | $timezone = getParameter("tmz");
|
| 15 | 15 | |
| 16 | -if(!$timezone) $timezone = date_default_timezone_get(); |
|
| 16 | +if (!$timezone) $timezone = date_default_timezone_get(); |
|
| 17 | 17 | @date_default_timezone_set($timezone); |
| 18 | 18 | |
| 19 | 19 | $cdate = new tc_date(); |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | $slm = getParameter("selected_month");
|
| 24 | 24 | $sly = getParameter("selected_year");
|
| 25 | 25 | |
| 26 | -if(!is_numeric($sld)) $sld = "00"; |
|
| 27 | -if(!is_numeric($slm)) $slm = "00"; |
|
| 28 | -if(!is_numeric($sly)) $sly = "0000"; |
|
| 26 | +if (!is_numeric($sld)) $sld = "00"; |
|
| 27 | +if (!is_numeric($slm)) $slm = "00"; |
|
| 28 | +if (!is_numeric($sly)) $sly = "0000"; |
|
| 29 | 29 | |
| 30 | 30 | $year_start = getParameter("year_start", "number", 0);
|
| 31 | 31 | $year_end = getParameter("year_end", "number", 0);
|
@@ -73,63 +73,63 @@ discard block |
||
| 73 | 73 | $theme = getParameter("thm");
|
| 74 | 74 | |
| 75 | 75 | //check year to be select in case of date_allow is set |
| 76 | -if(!$show_not_allow){
|
|
| 76 | +if (!$show_not_allow) {
|
|
| 77 | 77 | if ($ta1_set && $cdate->validDate($time_allow1)) $year_start = $cdate->getDate('Y', $time_allow1);
|
| 78 | 78 | if ($ta2_set && $cdate->validDate($time_allow2)) $year_end = $cdate->getDate('Y', $time_allow2);
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | -if(isset($_REQUEST["m"])) |
|
| 81 | +if (isset($_REQUEST["m"])) |
|
| 82 | 82 | $m = getParameter("m", "number");
|
| 83 | -else{
|
|
| 84 | - if($slm != "00"){
|
|
| 83 | +else {
|
|
| 84 | + if ($slm != "00") {
|
|
| 85 | 85 | $m = $slm; |
| 86 | - }else{
|
|
| 87 | - if($ta2_set && $year_end > 0){
|
|
| 86 | + }else {
|
|
| 87 | + if ($ta2_set && $year_end>0) {
|
|
| 88 | 88 | //compare which one is more |
| 89 | 89 | $year_allow2 = $cdate->getDate('Y', $time_allow2);
|
| 90 | - if($year_allow2 >= $year_end){
|
|
| 90 | + if ($year_allow2>=$year_end) {
|
|
| 91 | 91 | //use time_allow2 |
| 92 | 92 | $m = ($cdate->dateBefore($time_allow2)) ? $cdate->getDate("m") : $cdate->getDate('m', $time_allow2);
|
| 93 | - }else{
|
|
| 93 | + }else {
|
|
| 94 | 94 | //use year_end |
| 95 | - $m = ($year_end > $cdate->getDate("Y")) ? $cdate->getDate("m") : 12;
|
|
| 95 | + $m = ($year_end>$cdate->getDate("Y")) ? $cdate->getDate("m") : 12;
|
|
| 96 | 96 | } |
| 97 | - }elseif($ta2_set){
|
|
| 97 | + }elseif ($ta2_set) {
|
|
| 98 | 98 | $m = ($cdate->dateBefore($time_allow2)) ? $cdate->getDate("m") : $cdate->getDate('m', $time_allow2);
|
| 99 | - }elseif($year_end > 0){
|
|
| 100 | - $m = ($year_end > $cdate->getDate("Y")) ? $cdate->getDate("m") : 12; //date('m')
|
|
| 101 | - }else{
|
|
| 99 | + }elseif ($year_end>0) {
|
|
| 100 | + $m = ($year_end>$cdate->getDate("Y")) ? $cdate->getDate("m") : 12; //date('m')
|
|
| 101 | + }else {
|
|
| 102 | 102 | $m = $cdate->getDate("m");
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | -if($m < 1 && $m > 12) $m = $cdate->getDate("m");
|
|
| 107 | +if ($m<1 && $m>12) $m = $cdate->getDate("m");
|
|
| 108 | 108 | |
| 109 | 109 | $m = str_pad($m, 2, "0", STR_PAD_LEFT); |
| 110 | 110 | |
| 111 | 111 | $cyr = ($sly != "0000") ? true : false; |
| 112 | -if($cyr && $sly && $sly < $year_start) $sly = $year_start; |
|
| 113 | -if($cyr && $sly && $sly > $year_end) $sly = $year_end; |
|
| 112 | +if ($cyr && $sly && $sly<$year_start) $sly = $year_start; |
|
| 113 | +if ($cyr && $sly && $sly>$year_end) $sly = $year_end; |
|
| 114 | 114 | |
| 115 | -if(isset($_REQUEST["y"])) |
|
| 115 | +if (isset($_REQUEST["y"])) |
|
| 116 | 116 | $y = getParameter("y", "number");
|
| 117 | 117 | else |
| 118 | 118 | $y = ($cyr) ? $sly : $cdate->getDate("Y");
|
| 119 | 119 | |
| 120 | -if($y <= 0) $y = $cdate->getDate("Y");
|
|
| 120 | +if ($y<=0) $y = $cdate->getDate("Y");
|
|
| 121 | 121 | |
| 122 | 122 | // ensure m-y fits date allow range |
| 123 | 123 | if (!$show_not_allow) {
|
| 124 | 124 | if ($ta1_set) {
|
| 125 | 125 | $m1 = $cdate->getDate('m', $time_allow1);
|
| 126 | 126 | $y1 = $cdate->getDate('Y', $time_allow1);
|
| 127 | - if ($y == $y1 && (int)$m < (int)$m1) $m = $m1; |
|
| 127 | + if ($y == $y1 && (int) $m<(int) $m1) $m = $m1; |
|
| 128 | 128 | } |
| 129 | 129 | if ($ta2_set) {
|
| 130 | 130 | $m2 = $cdate->getDate('m', $time_allow2);
|
| 131 | 131 | $y2 = $cdate->getDate('Y', $time_allow2);
|
| 132 | - if ($y == $y2 && (int)$m > (int)$m2) $m = $m2; |
|
| 132 | + if ($y == $y2 && (int) $m>(int) $m2) $m = $m2; |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
@@ -147,15 +147,15 @@ discard block |
||
| 147 | 147 | $cobj->setTimezone($timezone); //set for further usage, nothing for now |
| 148 | 148 | |
| 149 | 149 | $theme_path = ($theme != "") ? $cobj->getThemePath($theme) : ""; |
| 150 | -if(!is_file($theme_path)) $theme_path = ""; |
|
| 150 | +if (!is_file($theme_path)) $theme_path = ""; |
|
| 151 | 151 | |
| 152 | 152 | //check and show default calendar month and year on valid range of date_allow |
| 153 | -if(!isset($_REQUEST["m"])){
|
|
| 154 | - if($time_allow1 != ""){
|
|
| 153 | +if (!isset($_REQUEST["m"])) {
|
|
| 154 | + if ($time_allow1 != "") {
|
|
| 155 | 155 | //get date of time allow1 |
| 156 | - if($cdate->validDate($time_allow1)){
|
|
| 156 | + if ($cdate->validDate($time_allow1)) {
|
|
| 157 | 157 | //check valid if today is after date_allow1 |
| 158 | - if(!$cdate->dateAfter($time_allow1, $today)){
|
|
| 158 | + if (!$cdate->dateAfter($time_allow1, $today)) {
|
|
| 159 | 159 | //reset default calendar display |
| 160 | 160 | $y = $cdate->getDate('Y', $time_allow1);
|
| 161 | 161 | $m = $cdate->getDate('m', $time_allow1);
|
@@ -168,23 +168,23 @@ discard block |
||
| 168 | 168 | $year_end = $cobj->year_end; |
| 169 | 169 | |
| 170 | 170 | //check year display in valid range |
| 171 | -if($y >= $year_end) $y = $year_end; |
|
| 172 | -if($y <= $year_start) $y = $year_start; |
|
| 171 | +if ($y>=$year_end) $y = $year_end; |
|
| 172 | +if ($y<=$year_start) $y = $year_start; |
|
| 173 | 173 | |
| 174 | 174 | $total_thismonth = $cobj->total_days($m, $y); |
| 175 | 175 | |
| 176 | -if($m == 1){
|
|
| 176 | +if ($m == 1) {
|
|
| 177 | 177 | $previous_month = 12; |
| 178 | 178 | $previous_year = $y-1; |
| 179 | -}else{
|
|
| 179 | +}else {
|
|
| 180 | 180 | $previous_month = $m-1; |
| 181 | 181 | $previous_year = $y; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | -if($m == 12){
|
|
| 184 | +if ($m == 12) {
|
|
| 185 | 185 | $next_month = 1; |
| 186 | 186 | $next_year = $y+1; |
| 187 | -}else{
|
|
| 187 | +}else {
|
|
| 188 | 188 | $next_month = $m+1; |
| 189 | 189 | $next_year = $y; |
| 190 | 190 | } |
@@ -193,13 +193,13 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | $firstdate = $cdate->getDayOfWeek($y."-".$m."-1"); //first date of month, 0 (for Sunday) through 6 (for Saturday) |
| 195 | 195 | |
| 196 | -if($firstdate == $startDate){
|
|
| 196 | +if ($firstdate == $startDate) {
|
|
| 197 | 197 | //skip last month |
| 198 | 198 | $startwrite = $total_lastmonth+1; |
| 199 | -}elseif($firstdate < $startDate){
|
|
| 200 | - $startwrite = $total_lastmonth - (6-($startDate-$firstdate)); |
|
| 201 | -}else{
|
|
| 202 | - $startwrite = $total_lastmonth - ($firstdate - $startDate - 1); |
|
| 199 | +}elseif ($firstdate<$startDate) {
|
|
| 200 | + $startwrite = $total_lastmonth-(6-($startDate-$firstdate)); |
|
| 201 | +}else {
|
|
| 202 | + $startwrite = $total_lastmonth-($firstdate-$startDate-1); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | //-------------------------------- |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $row_count = 0; |
| 213 | 213 | |
| 214 | 214 | //write previous month |
| 215 | -for($day=$startwrite; $day<=$total_lastmonth; $day++){
|
|
| 215 | +for ($day = $startwrite; $day<=$total_lastmonth; $day++) {
|
|
| 216 | 216 | $calendar_rows[$row_count][] = array($day, "", "othermonth", ""); |
| 217 | 217 | $dayinweek_counter++; |
| 218 | 218 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $prev_d = $y."-".$prev_m."-".$day; |
| 221 | 221 | |
| 222 | 222 | $wknum = $cdate->getWeekNumber($prev_d); |
| 223 | - if(!isset($week_rows[$row_count][$wknum])){
|
|
| 223 | + if (!isset($week_rows[$row_count][$wknum])) {
|
|
| 224 | 224 | $week_rows[$row_count][$wknum] = 1; |
| 225 | 225 | }else $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
| 226 | 226 | } |
@@ -228,31 +228,31 @@ discard block |
||
| 228 | 228 | $pvMonthTime = $previous_year."-".$previous_month."-".$total_lastmonth; |
| 229 | 229 | |
| 230 | 230 | //check lastmonth is on allowed date |
| 231 | -if($ta1_set && !$show_not_allow){
|
|
| 232 | - if($cdate->dateBefore($pvMonthTime, $time_allow1)){
|
|
| 231 | +if ($ta1_set && !$show_not_allow) {
|
|
| 232 | + if ($cdate->dateBefore($pvMonthTime, $time_allow1)) {
|
|
| 233 | 233 | $show_previous = true; |
| 234 | 234 | }else $show_previous = false; |
| 235 | 235 | }else $show_previous = true; //always show when not set |
| 236 | 236 | |
| 237 | 237 | $date_num = $cdate->getDayOfWeek(($previous_year."-".$previous_month."-".$total_lastmonth)); |
| 238 | -if(($startDate == 0 && $date_num == 6) || ($startDate > 0 && $date_num == $startDate-1) && $startwrite<$total_lastmonth){
|
|
| 239 | - if(isset($calendar_rows[0])) $row_count++; |
|
| 238 | +if (($startDate == 0 && $date_num == 6) || ($startDate>0 && $date_num == $startDate-1) && $startwrite<$total_lastmonth) {
|
|
| 239 | + if (isset($calendar_rows[0])) $row_count++; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | $dp_time = ($date_pair_value) ? $date_pair_value : ""; |
| 243 | 243 | |
| 244 | 244 | $select_days = array(); |
| 245 | -if($sld>0 && $slm>0 && $sly>0){
|
|
| 245 | +if ($sld>0 && $slm>0 && $sly>0) {
|
|
| 246 | 246 | $sldate = "$sly-$slm-$sld"; |
| 247 | 247 | |
| 248 | - for($i=0; $i<$interval; $i++){
|
|
| 248 | + for ($i = 0; $i<$interval; $i++) {
|
|
| 249 | 249 | $this_day = $cdate->addDay("Y-m-d", $i, $sldate);
|
| 250 | 250 | $select_days[] = $this_day; |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | //write current month |
| 255 | -for($day=1; $day<=$total_thismonth; $day++){
|
|
| 255 | +for ($day = 1; $day<=$total_thismonth; $day++) {
|
|
| 256 | 256 | $date_str = $y."-".str_pad($m, 2, "0", STR_PAD_LEFT)."-".str_pad($day, 2, "0", STR_PAD_LEFT); |
| 257 | 257 | |
| 258 | 258 | $date_num = $cdate->getDayOfWeek($date_str); |
@@ -267,40 +267,40 @@ discard block |
||
| 267 | 267 | $dateLink = true; |
| 268 | 268 | |
| 269 | 269 | //check date allowed |
| 270 | - if($ta1_set && $ta2_set){
|
|
| 270 | + if ($ta1_set && $ta2_set) {
|
|
| 271 | 271 | //both date specified |
| 272 | 272 | $dateLink = ($cdate->dateBefore($date_str, $time_allow1) && $cdate->dateAfter($date_str, $time_allow2)) ? true : false; |
| 273 | - }elseif($ta1_set){
|
|
| 273 | + }elseif ($ta1_set) {
|
|
| 274 | 274 | //only date 1 specified |
| 275 | 275 | $dateLink = $cdate->dateBefore($date_str, $time_allow1) ? true : false; |
| 276 | - }elseif($ta2_set){
|
|
| 276 | + }elseif ($ta2_set) {
|
|
| 277 | 277 | //only date 2 specified |
| 278 | 278 | $dateLink = $cdate->dateAfter($date_str, $time_allow2) ? true : false; |
| 279 | - }else{
|
|
| 279 | + }else {
|
|
| 280 | 280 | //no date allow specified, assume show all |
| 281 | 281 | $dateLink = true; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if($dateLink){
|
|
| 284 | + if ($dateLink) {
|
|
| 285 | 285 | //check for disable days |
| 286 | - if(in_array(strtolower($day_txt), $cobj->dsb_days) !== false){
|
|
| 286 | + if (in_array(strtolower($day_txt), $cobj->dsb_days) !== false) {
|
|
| 287 | 287 | $dateLink = false; |
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | //check specific date |
| 292 | - if($dateLink){
|
|
| 293 | - if(is_array($sp_dates) && sizeof($sp_dates) > 0){
|
|
| 292 | + if ($dateLink) {
|
|
| 293 | + if (is_array($sp_dates) && sizeof($sp_dates)>0) {
|
|
| 294 | 294 | //check if it is current date |
| 295 | 295 | $sp_found = false; |
| 296 | 296 | |
| 297 | 297 | //check on yearly recursive |
| 298 | - if(isset($sp_dates[2]) && is_array($sp_dates[2])){
|
|
| 299 | - foreach($sp_dates[2] as $sp_time){
|
|
| 300 | - if($sp_time != ""){
|
|
| 301 | - $sp_time_md = (int)$cdate->getDate('md', $sp_time); //date('md', $sp_time);
|
|
| 302 | - $this_md = (int)$cdate->getDate('md', $date_str); //date('md', $currentTime);
|
|
| 303 | - if($sp_time_md == $this_md){
|
|
| 298 | + if (isset($sp_dates[2]) && is_array($sp_dates[2])) {
|
|
| 299 | + foreach ($sp_dates[2] as $sp_time) {
|
|
| 300 | + if ($sp_time != "") {
|
|
| 301 | + $sp_time_md = (int) $cdate->getDate('md', $sp_time); //date('md', $sp_time);
|
|
| 302 | + $this_md = (int) $cdate->getDate('md', $date_str); //date('md', $currentTime);
|
|
| 303 | + if ($sp_time_md == $this_md) {
|
|
| 304 | 304 | $sp_found = true; |
| 305 | 305 | break; |
| 306 | 306 | } |
@@ -309,11 +309,11 @@ discard block |
||
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | //check on monthly recursive |
| 312 | - if(isset($sp_dates[1]) && is_array($sp_dates[1]) && !$sp_found){
|
|
| 313 | - foreach($sp_dates[1] as $sp_time){
|
|
| 314 | - if($sp_time != "" && $sp_time > 0){
|
|
| 315 | - $sp_time_d = (int)$cdate->getDate('d', $sp_time); //date('d', $sp_time);
|
|
| 316 | - if($sp_time_d == $day){
|
|
| 312 | + if (isset($sp_dates[1]) && is_array($sp_dates[1]) && !$sp_found) {
|
|
| 313 | + foreach ($sp_dates[1] as $sp_time) {
|
|
| 314 | + if ($sp_time != "" && $sp_time>0) {
|
|
| 315 | + $sp_time_d = (int) $cdate->getDate('d', $sp_time); //date('d', $sp_time);
|
|
| 316 | + if ($sp_time_d == $day) {
|
|
| 317 | 317 | $sp_found = true; |
| 318 | 318 | break; |
| 319 | 319 | } |
@@ -322,11 +322,11 @@ discard block |
||
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | //check on no recursive |
| 325 | - if(isset($sp_dates[0]) && is_array($sp_dates[0]) && !$sp_found){
|
|
| 325 | + if (isset($sp_dates[0]) && is_array($sp_dates[0]) && !$sp_found) {
|
|
| 326 | 326 | $sp_found = in_array($date_str, $sp_dates[0]); |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - switch($sp_type){
|
|
| 329 | + switch ($sp_type) {
|
|
| 330 | 330 | case 0: |
| 331 | 331 | default: |
| 332 | 332 | //disabled specific and enabled others |
@@ -340,23 +340,23 @@ discard block |
||
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if($date_pair_value){
|
|
| 343 | + if ($date_pair_value) {
|
|
| 344 | 344 | //check date_pair1 & 2 |
| 345 | - if($date_pair1 && $date_pair_value != "0000-00-00" && $cdate->dateAfter($date_pair_value, $date_str) && (($slm>0 && $sld>0 && $sly>0) && $cdate->dateBefore("$sly-$slm-$sld", $date_str))){ //set date only after date_pair1
|
|
| 346 | - if(!in_array("select", $htmlClass))
|
|
| 345 | + if ($date_pair1 && $date_pair_value != "0000-00-00" && $cdate->dateAfter($date_pair_value, $date_str) && (($slm>0 && $sld>0 && $sly>0) && $cdate->dateBefore("$sly-$slm-$sld", $date_str))) { //set date only after date_pair1
|
|
| 346 | + if (!in_array("select", $htmlClass))
|
|
| 347 | 347 | $htmlClass[] = "select"; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - if($date_pair2 && $date_pair_value != "0000-00-00" && $cdate->dateBefore($date_pair_value, $date_str) && (($slm>0 && $sld>0 && $sly>0) && $cdate->dateAfter("$sly-$slm-$sld", $date_str))){ //set date only before date_pair2
|
|
| 351 | - if(!in_array("select", $htmlClass))
|
|
| 350 | + if ($date_pair2 && $date_pair_value != "0000-00-00" && $cdate->dateBefore($date_pair_value, $date_str) && (($slm>0 && $sld>0 && $sly>0) && $cdate->dateAfter("$sly-$slm-$sld", $date_str))) { //set date only before date_pair2
|
|
| 351 | + if (!in_array("select", $htmlClass))
|
|
| 352 | 352 | $htmlClass[] = "select"; |
| 353 | 353 | } |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | $htmlClass[] = strtolower($day_txt); |
| 357 | 357 | |
| 358 | - if($dateLink){
|
|
| 359 | - if(in_array($date_str, $select_days) && !in_array("select", $htmlClass)){
|
|
| 358 | + if ($dateLink) {
|
|
| 359 | + if (in_array($date_str, $select_days) && !in_array("select", $htmlClass)) {
|
|
| 360 | 360 | $htmlClass[] = "select"; |
| 361 | 361 | } |
| 362 | 362 | |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | $class = implode(" ", $htmlClass);
|
| 365 | 365 | |
| 366 | 366 | $calendar_rows[$row_count][] = array($day, "javascript:selectDay('".str_pad($day, 2, "0", STR_PAD_LEFT)."');", $class, "$y".str_pad($m, 2, "0", STR_PAD_LEFT).str_pad($day, 2, "0", STR_PAD_LEFT));
|
| 367 | - }else{
|
|
| 367 | + }else {
|
|
| 368 | 368 | $htmlClass[] = "disabledate"; |
| 369 | 369 | $class = implode(" ", $htmlClass);
|
| 370 | 370 | |
@@ -372,12 +372,12 @@ discard block |
||
| 372 | 372 | $calendar_rows[$row_count][] = array($day, "", $class, "$y".str_pad($m, 2, "0", STR_PAD_LEFT).str_pad($day, 2, "0", STR_PAD_LEFT)); |
| 373 | 373 | |
| 374 | 374 | //check if selected date is a disabled date |
| 375 | - if($date_str == $sly."-".str_pad($slm, 2, "0", STR_PAD_LEFT)."-".str_pad($sld, 2, "0", STR_PAD_LEFT)){
|
|
| 375 | + if ($date_str == $sly."-".str_pad($slm, 2, "0", STR_PAD_LEFT)."-".str_pad($sld, 2, "0", STR_PAD_LEFT)) {
|
|
| 376 | 376 | //disabled |
| 377 | 377 | //$sly = $slm = $sld = ""; |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | - if(($startDate == 0 && $date_num == 6) || ($startDate > 0 && $date_num == $startDate-1)){
|
|
| 380 | + if (($startDate == 0 && $date_num == 6) || ($startDate>0 && $date_num == $startDate-1)) {
|
|
| 381 | 381 | $row_count++; |
| 382 | 382 | |
| 383 | 383 | $dayinweek_counter = 0; |
@@ -385,19 +385,19 @@ discard block |
||
| 385 | 385 | |
| 386 | 386 | $wknum = $cdate->getWeekNumber(($y."-".$m."-".$day)); |
| 387 | 387 | |
| 388 | - if(!isset($week_rows[$row_count][$wknum])){
|
|
| 388 | + if (!isset($week_rows[$row_count][$wknum])) {
|
|
| 389 | 389 | $week_rows[$row_count][$wknum] = 1; |
| 390 | 390 | }else $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | //write next other month |
| 394 | 394 | $write_end_days = (6-$dayinweek_counter)+1; |
| 395 | -if($write_end_days > 0){
|
|
| 396 | - for($day=1; $day<=$write_end_days; $day++){
|
|
| 395 | +if ($write_end_days>0) {
|
|
| 396 | + for ($day = 1; $day<=$write_end_days; $day++) {
|
|
| 397 | 397 | $calendar_rows[$row_count][] = array($day, "", "othermonth", ""); |
| 398 | 398 | |
| 399 | 399 | $wknum = $cdate->getWeekNumber($cdate->addMonth("Y-m-d", 1, ($y."-".$m."-".$day))); //date('W', mktime(0,0,0, $m+1, $day, $y));
|
| 400 | - if(!isset($week_rows[$row_count][$wknum])){
|
|
| 400 | + if (!isset($week_rows[$row_count][$wknum])) {
|
|
| 401 | 401 | $week_rows[$row_count][$wknum] = 1; |
| 402 | 402 | }else $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
| 403 | 403 | } |
@@ -405,14 +405,14 @@ discard block |
||
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | //write fulfil row to 6 rows |
| 408 | -for($day=$row_count; $day<6; $day++){
|
|
| 408 | +for ($day = $row_count; $day<6; $day++) {
|
|
| 409 | 409 | $tmpday = $write_end_days+1; |
| 410 | - for($f=$tmpday; $f<=($tmpday+6); $f++){
|
|
| 410 | + for ($f = $tmpday; $f<=($tmpday+6); $f++) {
|
|
| 411 | 411 | $calendar_rows[$row_count][] = array($f, "", "othermonth", ""); |
| 412 | 412 | |
| 413 | 413 | $wknum = $cdate->getWeekNumber($cdate->addMonth("Y-m-d", 1, ($y."-".$m."-".$f))); //date('W', mktime(0,0,0, $m+1, $f, $y));
|
| 414 | 414 | |
| 415 | - if(!isset($week_rows[$row_count][$wknum])){
|
|
| 415 | + if (!isset($week_rows[$row_count][$wknum])) {
|
|
| 416 | 416 | $week_rows[$row_count][$wknum] = 1; |
| 417 | 417 | }else $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
| 418 | 418 | } |
@@ -420,20 +420,20 @@ discard block |
||
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | //check next month is on allowed date |
| 423 | -if($ta2_set && !$show_not_allow){
|
|
| 423 | +if ($ta2_set && !$show_not_allow) {
|
|
| 424 | 424 | $nxMonthTime = $next_year."-".$next_month."-1"; |
| 425 | - if($cdate->dateAfter($nxMonthTime, $time_allow2)){
|
|
| 425 | + if ($cdate->dateAfter($nxMonthTime, $time_allow2)) {
|
|
| 426 | 426 | $show_next = true; |
| 427 | 427 | }else $show_next = false; |
| 428 | 428 | }else $show_next = true; //always show when not set |
| 429 | 429 | ?> |
| 430 | 430 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 431 | -<html xmlns="http://www.w3.org/1999/xhtml"<?php if($rtl) echo(" dir=\"rtl\""); ?>>
|
|
| 431 | +<html xmlns="http://www.w3.org/1999/xhtml"<?php if ($rtl) echo(" dir=\"rtl\""); ?>>
|
|
| 432 | 432 | <head> |
| 433 | 433 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 434 | 434 | <title>TriConsole.com - PHP Calendar Date Picker</title> |
| 435 | 435 | <link href="calendar.css" rel="stylesheet" type="text/css" /> |
| 436 | -<?php if($theme_path){ ?>
|
|
| 436 | +<?php if ($theme_path) { ?>
|
|
| 437 | 437 | <link href="<?php echo($theme_path); ?>" rel="stylesheet" type="text/css" /> |
| 438 | 438 | <?php } ?> |
| 439 | 439 | <script type="text/javascript"> |
@@ -442,8 +442,8 @@ discard block |
||
| 442 | 442 | var today_month = "<?php echo($cdate->getDate('m')); ?>";
|
| 443 | 443 | var today_year = "<?php echo($cdate->getDate('Y')); ?>";
|
| 444 | 444 | var obj_name = "<?php echo($objname); ?>"; |
| 445 | -var current_month = "<?php echo($m);?>"; |
|
| 446 | -var current_year = "<?php echo($y);?>"; |
|
| 445 | +var current_month = "<?php echo($m); ?>"; |
|
| 446 | +var current_year = "<?php echo($y); ?>"; |
|
| 447 | 447 | |
| 448 | 448 | var this_time = "<?php echo(date("F d, Y H:i:s", time())); ?>";
|
| 449 | 449 | //--> |
@@ -454,12 +454,12 @@ discard block |
||
| 454 | 454 | function submitNow(dvalue, mvalue, yvalue){
|
| 455 | 455 | <?php |
| 456 | 456 | //write auto submit script |
| 457 | - if($auto_submit){
|
|
| 457 | + if ($auto_submit) {
|
|
| 458 | 458 | echo("if(yvalue>0 && mvalue>0 && dvalue>0){\n");
|
| 459 | - if($form_name){
|
|
| 459 | + if ($form_name) {
|
|
| 460 | 460 | //submit value by post form |
| 461 | 461 | echo("window.parent.document.".$form_name.".submit();\n");
|
| 462 | - }elseif($target_url){
|
|
| 462 | + }elseif ($target_url) {
|
|
| 463 | 463 | //submit value by get method |
| 464 | 464 | echo("var date_selected = yvalue + \"-\" + mvalue + \"-\" + dvalue;\n");
|
| 465 | 465 | echo("window.parent.location.href='".$target_url."?".$objname."='+date_selected;\n");
|
@@ -474,25 +474,25 @@ discard block |
||
| 474 | 474 | <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> |
| 475 | 475 | <span id="calendar-page" class="font"> |
| 476 | 476 | <div id="calendar-header" align="center"> |
| 477 | - <?php if($show_calendar_info) include("calendar_info.php"); ?>
|
|
| 478 | - <?php if($dp && !$auto_hide){ ?>
|
|
| 477 | + <?php if ($show_calendar_info) include("calendar_info.php"); ?>
|
|
| 478 | + <?php if ($dp && !$auto_hide) { ?>
|
|
| 479 | 479 | <div style="float: right;" class="closeme"><a href="javascript:closeMe();"><img src="images/close.gif" border="0" alt="Close" title="Close" /></a></div> |
| 480 | 480 | <?php } ?> |
| 481 | 481 | |
| 482 | 482 | <?php |
| 483 | - if(sizeof($cobj->warning_msgs)>0){
|
|
| 483 | + if (sizeof($cobj->warning_msgs)>0) {
|
|
| 484 | 484 | echo("<div id=\"calendar-alert\">".implode(", ", $cobj->warning_msgs)."</div>");
|
| 485 | 485 | } |
| 486 | 486 | ?> |
| 487 | 487 | |
| 488 | - <form id="calendarform" name="calendarform" method="post" action="<?php echo($thispage);?>"> |
|
| 488 | + <form id="calendarform" name="calendarform" method="post" action="<?php echo($thispage); ?>"> |
|
| 489 | 489 | <table align="center" cellpadding="1" cellspacing="0"> |
| 490 | 490 | <tr> |
| 491 | 491 | <td align="right"><select name="m" onchange="javascript:submitCalendar();" class="font"> |
| 492 | 492 | <?php |
| 493 | 493 | $monthnames = $cobj->getMonthNames(); |
| 494 | - for($f=1; $f<=sizeof($monthnames); $f++){
|
|
| 495 | - $selected = ($f == (int)$m) ? " selected='selected'" : ""; |
|
| 494 | + for ($f = 1; $f<=sizeof($monthnames); $f++) {
|
|
| 495 | + $selected = ($f == (int) $m) ? " selected='selected'" : ""; |
|
| 496 | 496 | echo("<option value=\"".str_pad($f, 2, "0", STR_PAD_LEFT)."\"".$selected.">".$monthnames[$f-1]."</option>");
|
| 497 | 497 | } |
| 498 | 498 | ?> |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | $thisyear = $cdate->getDate('Y');
|
| 502 | 502 | |
| 503 | 503 | //write year options |
| 504 | - for($year=$year_end; $year>=$year_start; $year--){
|
|
| 504 | + for ($year = $year_end; $year>=$year_start; $year--) {
|
|
| 505 | 505 | $selected = ($year == $y) ? " selected='selected'" : ""; |
| 506 | 506 | echo("<option value=\"".$year."\"".$selected.">".$year."</option>");
|
| 507 | 507 | } |
@@ -510,44 +510,44 @@ discard block |
||
| 510 | 510 | </td> |
| 511 | 511 | </tr> |
| 512 | 512 | </table> |
| 513 | - <input name="selected_day" type="hidden" id="selected_day" value="<?php echo($sld);?>" /> |
|
| 514 | - <input name="selected_month" type="hidden" id="selected_month" value="<?php echo($slm);?>" /> |
|
| 515 | - <input name="selected_year" type="hidden" id="selected_year" value="<?php echo($sly);?>" /> |
|
| 516 | - <input name="year_start" type="hidden" id="year_start" value="<?php echo($cobj->year_start_input);?>" /> |
|
| 517 | - <input name="year_end" type="hidden" id="year_end" value="<?php echo($cobj->year_end_input);?>" /> |
|
| 518 | - <input name="objname" type="hidden" id="objname" value="<?php echo($objname);?>" /> |
|
| 519 | - <input name="dp" type="hidden" id="dp" value="<?php echo($dp);?>" /> |
|
| 520 | - |
|
| 521 | - <input name="da1" type="hidden" id="da1" value="<?php echo($time_allow1);?>" /> |
|
| 522 | - <input name="da2" type="hidden" id="da2" value="<?php echo($time_allow2);?>" /> |
|
| 523 | - <input name="sna" type="hidden" id="sna" value="<?php echo($show_not_allow);?>" /> |
|
| 524 | - <input name="aut" type="hidden" id="aut" value="<?php echo($auto_submit);?>" /> |
|
| 525 | - <input name="frm" type="hidden" id="frm" value="<?php echo($form_name);?>" /> |
|
| 526 | - <input name="tar" type="hidden" id="tar" value="<?php echo($target_url);?>" /> |
|
| 527 | - <input name="inp" type="hidden" id="inp" value="<?php echo($show_input);?>" /> |
|
| 528 | - <input name="fmt" type="hidden" id="fmt" value="<?php echo($date_format);?>" /> |
|
| 529 | - <input name="dis" type="hidden" id="dis" value="<?php echo($dsb_txt);?>" /> |
|
| 530 | - |
|
| 531 | - <input name="pr1" type="hidden" id="pr1" value="<?php echo($date_pair1);?>" /> |
|
| 532 | - <input name="pr2" type="hidden" id="pr2" value="<?php echo($date_pair2);?>" /> |
|
| 533 | - <input name="prv" type="hidden" id="prv" value="<?php echo($date_pair_value);?>" /> |
|
| 534 | - <input name="pth" type="hidden" id="pth" value="<?php echo($path);?>" /> |
|
| 535 | - |
|
| 536 | - <input name="spd" type="hidden" id="spd" value="<?php echo(htmlspecialchars($cobj->check_json_encode($sp_dates), ENT_QUOTES));?>" /> |
|
| 537 | - <input name="spt" type="hidden" id="spt" value="<?php echo($sp_type);?>" /> |
|
| 538 | - |
|
| 539 | - <input name="och" type="hidden" id="och" value="<?php echo(urldecode($tc_onchanged));?>" /> |
|
| 540 | - |
|
| 541 | - <input name="str" type="hidden" id="str" value="<?php echo($startDate);?>" /> |
|
| 542 | - <input name="rtl" type="hidden" id="rtl" value="<?php echo($rtl);?>" /> |
|
| 543 | - <input name="wks" type="hidden" id="wks" value="<?php echo($show_weeks);?>" /> |
|
| 544 | - <input name="int" type="hidden" id="int" value="<?php echo($interval);?>" /> |
|
| 545 | - |
|
| 546 | - <input name="hid" type="hidden" id="hid" value="<?php echo($auto_hide);?>" /> |
|
| 547 | - <input name="hdt" type="hidden" id="hdt" value="<?php echo($auto_hide_time);?>" /> |
|
| 548 | - |
|
| 549 | - <input name="tmz" type="hidden" id="tmz" value="<?php echo($timezone);?>" /> |
|
| 550 | - <input name="thm" type="hidden" id="thm" value="<?php echo($theme);?>" /> |
|
| 513 | + <input name="selected_day" type="hidden" id="selected_day" value="<?php echo($sld); ?>" /> |
|
| 514 | + <input name="selected_month" type="hidden" id="selected_month" value="<?php echo($slm); ?>" /> |
|
| 515 | + <input name="selected_year" type="hidden" id="selected_year" value="<?php echo($sly); ?>" /> |
|
| 516 | + <input name="year_start" type="hidden" id="year_start" value="<?php echo($cobj->year_start_input); ?>" /> |
|
| 517 | + <input name="year_end" type="hidden" id="year_end" value="<?php echo($cobj->year_end_input); ?>" /> |
|
| 518 | + <input name="objname" type="hidden" id="objname" value="<?php echo($objname); ?>" /> |
|
| 519 | + <input name="dp" type="hidden" id="dp" value="<?php echo($dp); ?>" /> |
|
| 520 | + |
|
| 521 | + <input name="da1" type="hidden" id="da1" value="<?php echo($time_allow1); ?>" /> |
|
| 522 | + <input name="da2" type="hidden" id="da2" value="<?php echo($time_allow2); ?>" /> |
|
| 523 | + <input name="sna" type="hidden" id="sna" value="<?php echo($show_not_allow); ?>" /> |
|
| 524 | + <input name="aut" type="hidden" id="aut" value="<?php echo($auto_submit); ?>" /> |
|
| 525 | + <input name="frm" type="hidden" id="frm" value="<?php echo($form_name); ?>" /> |
|
| 526 | + <input name="tar" type="hidden" id="tar" value="<?php echo($target_url); ?>" /> |
|
| 527 | + <input name="inp" type="hidden" id="inp" value="<?php echo($show_input); ?>" /> |
|
| 528 | + <input name="fmt" type="hidden" id="fmt" value="<?php echo($date_format); ?>" /> |
|
| 529 | + <input name="dis" type="hidden" id="dis" value="<?php echo($dsb_txt); ?>" /> |
|
| 530 | + |
|
| 531 | + <input name="pr1" type="hidden" id="pr1" value="<?php echo($date_pair1); ?>" /> |
|
| 532 | + <input name="pr2" type="hidden" id="pr2" value="<?php echo($date_pair2); ?>" /> |
|
| 533 | + <input name="prv" type="hidden" id="prv" value="<?php echo($date_pair_value); ?>" /> |
|
| 534 | + <input name="pth" type="hidden" id="pth" value="<?php echo($path); ?>" /> |
|
| 535 | + |
|
| 536 | + <input name="spd" type="hidden" id="spd" value="<?php echo(htmlspecialchars($cobj->check_json_encode($sp_dates), ENT_QUOTES)); ?>" /> |
|
| 537 | + <input name="spt" type="hidden" id="spt" value="<?php echo($sp_type); ?>" /> |
|
| 538 | + |
|
| 539 | + <input name="och" type="hidden" id="och" value="<?php echo(urldecode($tc_onchanged)); ?>" /> |
|
| 540 | + |
|
| 541 | + <input name="str" type="hidden" id="str" value="<?php echo($startDate); ?>" /> |
|
| 542 | + <input name="rtl" type="hidden" id="rtl" value="<?php echo($rtl); ?>" /> |
|
| 543 | + <input name="wks" type="hidden" id="wks" value="<?php echo($show_weeks); ?>" /> |
|
| 544 | + <input name="int" type="hidden" id="int" value="<?php echo($interval); ?>" /> |
|
| 545 | + |
|
| 546 | + <input name="hid" type="hidden" id="hid" value="<?php echo($auto_hide); ?>" /> |
|
| 547 | + <input name="hdt" type="hidden" id="hdt" value="<?php echo($auto_hide_time); ?>" /> |
|
| 548 | + |
|
| 549 | + <input name="tmz" type="hidden" id="tmz" value="<?php echo($timezone); ?>" /> |
|
| 550 | + <input name="thm" type="hidden" id="thm" value="<?php echo($theme); ?>" /> |
|
| 551 | 551 | |
| 552 | 552 | <!-- focus var //--> |
| 553 | 553 | <input name="fcs" type="hidden" id="fcs" value="0" /> |
@@ -564,15 +564,15 @@ discard block |
||
| 564 | 564 | if ($show_weeks) echo("<td align=\"center\" class=\"header wk-hdr\"><div>".$cobj->week_hdr."</div></td>");
|
| 565 | 565 | |
| 566 | 566 | //write calendar day header |
| 567 | - foreach($day_headers as $dh){
|
|
| 567 | + foreach ($day_headers as $dh) {
|
|
| 568 | 568 | echo("<td align=\"center\" class=\"header\"><div>".$dh."</div></td>");
|
| 569 | 569 | } |
| 570 | 570 | echo("</tr>");
|
| 571 | 571 | |
| 572 | - for($row=0; $row<sizeof($calendar_rows); $row++){
|
|
| 572 | + for ($row = 0; $row<sizeof($calendar_rows); $row++) {
|
|
| 573 | 573 | echo("<tr>");
|
| 574 | 574 | |
| 575 | - if ($show_weeks){
|
|
| 575 | + if ($show_weeks) {
|
|
| 576 | 576 | asort($week_rows[$row]); |
| 577 | 577 | |
| 578 | 578 | //get week number with highest member |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | echo("<td align=\"center\" class=\"wk\"><div>".$cw_keys[(sizeof($cw_keys)-1)]."</div></td>");
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - foreach($calendar_rows[$row] as $column){
|
|
| 584 | + foreach ($calendar_rows[$row] as $column) {
|
|
| 585 | 585 | $this_day = isset($column[0]) ? $column[0] : ""; |
| 586 | 586 | $this_link = isset($column[1]) ? $column[1] : ""; |
| 587 | 587 | $this_class = isset($column[2]) ? $column[2] : ""; |
@@ -589,9 +589,9 @@ discard block |
||
| 589 | 589 | |
| 590 | 590 | $id_str = ($this_id) ? " id=\"".$this_id."\"" : ""; |
| 591 | 591 | |
| 592 | - if($this_link){
|
|
| 592 | + if ($this_link) {
|
|
| 593 | 593 | echo("<td".$id_str." align=\"center\" class=\"".$this_class."\"><div><a href=\"".$this_link."\">".$this_day."</a></div></td>");
|
| 594 | - }else{
|
|
| 594 | + }else {
|
|
| 595 | 595 | echo("<td".$id_str." align=\"center\" class=\"".$this_class."\"><div>".$this_day."</div></td>");
|
| 596 | 596 | } |
| 597 | 597 | } |
@@ -602,21 +602,21 @@ discard block |
||
| 602 | 602 | </div> |
| 603 | 603 | |
| 604 | 604 | <?php |
| 605 | - if(($previous_year >= $year_start || $next_year <= $year_end) && ($show_previous || $show_next)){
|
|
| 605 | + if (($previous_year>=$year_start || $next_year<=$year_end) && ($show_previous || $show_next)) {
|
|
| 606 | 606 | ?> |
| 607 | 607 | <div id="calendar-footer"> |
| 608 | 608 | <div style="float: <?php echo($rtl ? "right" : "left"); ?>;" class="btn"> |
| 609 | 609 | <?php |
| 610 | - if($previous_year >= $year_start && $show_previous){
|
|
| 611 | - ?><a href="javascript:move('<?php echo(str_pad($previous_month, 2, "0", STR_PAD_LEFT));?>', '<?php echo($previous_year);?>');"><img src="images/btn_<?php echo($rtl ? "next" : "previous"); ?>.gif" width="16" height="16" border="0" alt="Previous" title="Previous" /></a>
|
|
| 610 | + if ($previous_year>=$year_start && $show_previous) {
|
|
| 611 | + ?><a href="javascript:move('<?php echo(str_pad($previous_month, 2, "0", STR_PAD_LEFT)); ?>', '<?php echo($previous_year); ?>');"><img src="images/btn_<?php echo($rtl ? "next" : "previous"); ?>.gif" width="16" height="16" border="0" alt="Previous" title="Previous" /></a>
|
|
| 612 | 612 | <?php |
| 613 | 613 | }else echo(" ");
|
| 614 | 614 | ?> |
| 615 | 615 | </div> |
| 616 | 616 | <div style="float: <?php echo($rtl ? "left" : "right"); ?>;" class="btn"> |
| 617 | 617 | <?php |
| 618 | - if($next_year <= $year_end && $show_next){
|
|
| 619 | - ?><a href="javascript:move('<?php echo(str_pad($next_month, 2, "0", STR_PAD_LEFT));?>', '<?php echo($next_year);?>');"><img src="images/btn_<?php echo($rtl ? "previous" : "next"); ?>.gif" width="16" height="16" border="0" alt="Next" title="Next" /></a>
|
|
| 618 | + if ($next_year<=$year_end && $show_next) {
|
|
| 619 | + ?><a href="javascript:move('<?php echo(str_pad($next_month, 2, "0", STR_PAD_LEFT)); ?>', '<?php echo($next_year); ?>');"><img src="images/btn_<?php echo($rtl ? "previous" : "next"); ?>.gif" width="16" height="16" border="0" alt="Next" title="Next" /></a>
|
|
| 620 | 620 | <?php |
| 621 | 621 | }else echo(" ");
|
| 622 | 622 | ?> |
@@ -625,13 +625,13 @@ discard block |
||
| 625 | 625 | <?php |
| 626 | 626 | $footer_links = array(); |
| 627 | 627 | |
| 628 | - if($cobj->validTodayDate() && ($m != $cdate->getDate('m') || $y != $cdate->getDate('Y')))
|
|
| 628 | + if ($cobj->validTodayDate() && ($m != $cdate->getDate('m') || $y != $cdate->getDate('Y')))
|
|
| 629 | 629 | $footer_links[] = "<a href=\"javascript:today();\" class=\"txt\" alt=\"Today\" title=\"Today\">Today</a>"; |
| 630 | 630 | |
| 631 | - if($sld>0 && $slm>0 && $sly>0) |
|
| 631 | + if ($sld>0 && $slm>0 && $sly>0) |
|
| 632 | 632 | $footer_links[] = "<a href=\"javascript:unsetValue();\" class=\"txt\" alt=\"Unset\" title=\"Unset\">Unset</a>"; |
| 633 | 633 | |
| 634 | - if(sizeof($footer_links)>0){
|
|
| 634 | + if (sizeof($footer_links)>0) {
|
|
| 635 | 635 | echo(implode(" | ", $footer_links));
|
| 636 | 636 | } |
| 637 | 637 | ?> |
@@ -13,7 +13,9 @@ discard block |
||
| 13 | 13 | //timezone var, need to setup before any other tasks |
| 14 | 14 | $timezone = getParameter("tmz");
|
| 15 | 15 | |
| 16 | -if(!$timezone) $timezone = date_default_timezone_get(); |
|
| 16 | +if(!$timezone) { |
|
| 17 | + $timezone = date_default_timezone_get(); |
|
| 18 | +} |
|
| 17 | 19 | @date_default_timezone_set($timezone); |
| 18 | 20 | |
| 19 | 21 | $cdate = new tc_date(); |
@@ -23,9 +25,15 @@ discard block |
||
| 23 | 25 | $slm = getParameter("selected_month");
|
| 24 | 26 | $sly = getParameter("selected_year");
|
| 25 | 27 | |
| 26 | -if(!is_numeric($sld)) $sld = "00"; |
|
| 27 | -if(!is_numeric($slm)) $slm = "00"; |
|
| 28 | -if(!is_numeric($sly)) $sly = "0000"; |
|
| 28 | +if(!is_numeric($sld)) { |
|
| 29 | + $sld = "00"; |
|
| 30 | +} |
|
| 31 | +if(!is_numeric($slm)) { |
|
| 32 | + $slm = "00"; |
|
| 33 | +} |
|
| 34 | +if(!is_numeric($sly)) { |
|
| 35 | + $sly = "0000"; |
|
| 36 | +} |
|
| 29 | 37 | |
| 30 | 38 | $year_start = getParameter("year_start", "number", 0);
|
| 31 | 39 | $year_end = getParameter("year_end", "number", 0);
|
@@ -74,62 +82,79 @@ discard block |
||
| 74 | 82 | |
| 75 | 83 | //check year to be select in case of date_allow is set |
| 76 | 84 | if(!$show_not_allow){
|
| 77 | - if ($ta1_set && $cdate->validDate($time_allow1)) $year_start = $cdate->getDate('Y', $time_allow1);
|
|
| 78 | - if ($ta2_set && $cdate->validDate($time_allow2)) $year_end = $cdate->getDate('Y', $time_allow2);
|
|
| 79 | -} |
|
| 80 | - |
|
| 81 | -if(isset($_REQUEST["m"])) |
|
| 82 | - $m = getParameter("m", "number");
|
|
| 83 | -else{
|
|
| 85 | + if ($ta1_set && $cdate->validDate($time_allow1)) { |
|
| 86 | + $year_start = $cdate->getDate('Y', $time_allow1); |
|
| 87 | + } |
|
| 88 | + if ($ta2_set && $cdate->validDate($time_allow2)) { |
|
| 89 | + $year_end = $cdate->getDate('Y', $time_allow2); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | +if(isset($_REQUEST["m"])) { |
|
| 94 | + $m = getParameter("m", "number"); |
|
| 95 | +} else{
|
|
| 84 | 96 | if($slm != "00"){
|
| 85 | 97 | $m = $slm; |
| 86 | - }else{
|
|
| 98 | + } else{
|
|
| 87 | 99 | if($ta2_set && $year_end > 0){
|
| 88 | 100 | //compare which one is more |
| 89 | 101 | $year_allow2 = $cdate->getDate('Y', $time_allow2);
|
| 90 | 102 | if($year_allow2 >= $year_end){
|
| 91 | 103 | //use time_allow2 |
| 92 | 104 | $m = ($cdate->dateBefore($time_allow2)) ? $cdate->getDate("m") : $cdate->getDate('m', $time_allow2);
|
| 93 | - }else{
|
|
| 105 | + } else{
|
|
| 94 | 106 | //use year_end |
| 95 | 107 | $m = ($year_end > $cdate->getDate("Y")) ? $cdate->getDate("m") : 12;
|
| 96 | 108 | } |
| 97 | - }elseif($ta2_set){
|
|
| 109 | + } elseif($ta2_set){
|
|
| 98 | 110 | $m = ($cdate->dateBefore($time_allow2)) ? $cdate->getDate("m") : $cdate->getDate('m', $time_allow2);
|
| 99 | - }elseif($year_end > 0){
|
|
| 111 | + } elseif($year_end > 0){
|
|
| 100 | 112 | $m = ($year_end > $cdate->getDate("Y")) ? $cdate->getDate("m") : 12; //date('m')
|
| 101 | - }else{
|
|
| 113 | + } else{
|
|
| 102 | 114 | $m = $cdate->getDate("m");
|
| 103 | 115 | } |
| 104 | 116 | } |
| 105 | 117 | } |
| 106 | 118 | |
| 107 | -if($m < 1 && $m > 12) $m = $cdate->getDate("m");
|
|
| 119 | +if($m < 1 && $m > 12) { |
|
| 120 | + $m = $cdate->getDate("m"); |
|
| 121 | +} |
|
| 108 | 122 | |
| 109 | 123 | $m = str_pad($m, 2, "0", STR_PAD_LEFT); |
| 110 | 124 | |
| 111 | 125 | $cyr = ($sly != "0000") ? true : false; |
| 112 | -if($cyr && $sly && $sly < $year_start) $sly = $year_start; |
|
| 113 | -if($cyr && $sly && $sly > $year_end) $sly = $year_end; |
|
| 114 | - |
|
| 115 | -if(isset($_REQUEST["y"])) |
|
| 116 | - $y = getParameter("y", "number");
|
|
| 117 | -else |
|
| 118 | - $y = ($cyr) ? $sly : $cdate->getDate("Y");
|
|
| 119 | - |
|
| 120 | -if($y <= 0) $y = $cdate->getDate("Y");
|
|
| 126 | +if($cyr && $sly && $sly < $year_start) { |
|
| 127 | + $sly = $year_start; |
|
| 128 | +} |
|
| 129 | +if($cyr && $sly && $sly > $year_end) { |
|
| 130 | + $sly = $year_end; |
|
| 131 | +} |
|
| 132 | + |
|
| 133 | +if(isset($_REQUEST["y"])) { |
|
| 134 | + $y = getParameter("y", "number"); |
|
| 135 | +} else { |
|
| 136 | + $y = ($cyr) ? $sly : $cdate->getDate("Y"); |
|
| 137 | +} |
|
| 138 | + |
|
| 139 | +if($y <= 0) { |
|
| 140 | + $y = $cdate->getDate("Y"); |
|
| 141 | +} |
|
| 121 | 142 | |
| 122 | 143 | // ensure m-y fits date allow range |
| 123 | 144 | if (!$show_not_allow) {
|
| 124 | 145 | if ($ta1_set) {
|
| 125 | 146 | $m1 = $cdate->getDate('m', $time_allow1);
|
| 126 | 147 | $y1 = $cdate->getDate('Y', $time_allow1);
|
| 127 | - if ($y == $y1 && (int)$m < (int)$m1) $m = $m1; |
|
| 148 | + if ($y == $y1 && (int)$m < (int)$m1) { |
|
| 149 | + $m = $m1; |
|
| 150 | + } |
|
| 128 | 151 | } |
| 129 | 152 | if ($ta2_set) {
|
| 130 | 153 | $m2 = $cdate->getDate('m', $time_allow2);
|
| 131 | 154 | $y2 = $cdate->getDate('Y', $time_allow2);
|
| 132 | - if ($y == $y2 && (int)$m > (int)$m2) $m = $m2; |
|
| 155 | + if ($y == $y2 && (int)$m > (int)$m2) { |
|
| 156 | + $m = $m2; |
|
| 157 | + } |
|
| 133 | 158 | } |
| 134 | 159 | } |
| 135 | 160 | |
@@ -147,7 +172,9 @@ discard block |
||
| 147 | 172 | $cobj->setTimezone($timezone); //set for further usage, nothing for now |
| 148 | 173 | |
| 149 | 174 | $theme_path = ($theme != "") ? $cobj->getThemePath($theme) : ""; |
| 150 | -if(!is_file($theme_path)) $theme_path = ""; |
|
| 175 | +if(!is_file($theme_path)) { |
|
| 176 | + $theme_path = ""; |
|
| 177 | +} |
|
| 151 | 178 | |
| 152 | 179 | //check and show default calendar month and year on valid range of date_allow |
| 153 | 180 | if(!isset($_REQUEST["m"])){
|
@@ -168,15 +195,19 @@ discard block |
||
| 168 | 195 | $year_end = $cobj->year_end; |
| 169 | 196 | |
| 170 | 197 | //check year display in valid range |
| 171 | -if($y >= $year_end) $y = $year_end; |
|
| 172 | -if($y <= $year_start) $y = $year_start; |
|
| 198 | +if($y >= $year_end) { |
|
| 199 | + $y = $year_end; |
|
| 200 | +} |
|
| 201 | +if($y <= $year_start) { |
|
| 202 | + $y = $year_start; |
|
| 203 | +} |
|
| 173 | 204 | |
| 174 | 205 | $total_thismonth = $cobj->total_days($m, $y); |
| 175 | 206 | |
| 176 | 207 | if($m == 1){
|
| 177 | 208 | $previous_month = 12; |
| 178 | 209 | $previous_year = $y-1; |
| 179 | -}else{
|
|
| 210 | +} else{
|
|
| 180 | 211 | $previous_month = $m-1; |
| 181 | 212 | $previous_year = $y; |
| 182 | 213 | } |
@@ -184,7 +215,7 @@ discard block |
||
| 184 | 215 | if($m == 12){
|
| 185 | 216 | $next_month = 1; |
| 186 | 217 | $next_year = $y+1; |
| 187 | -}else{
|
|
| 218 | +} else{
|
|
| 188 | 219 | $next_month = $m+1; |
| 189 | 220 | $next_year = $y; |
| 190 | 221 | } |
@@ -196,9 +227,9 @@ discard block |
||
| 196 | 227 | if($firstdate == $startDate){
|
| 197 | 228 | //skip last month |
| 198 | 229 | $startwrite = $total_lastmonth+1; |
| 199 | -}elseif($firstdate < $startDate){
|
|
| 230 | +} elseif($firstdate < $startDate){
|
|
| 200 | 231 | $startwrite = $total_lastmonth - (6-($startDate-$firstdate)); |
| 201 | -}else{
|
|
| 232 | +} else{
|
|
| 202 | 233 | $startwrite = $total_lastmonth - ($firstdate - $startDate - 1); |
| 203 | 234 | } |
| 204 | 235 | |
@@ -222,8 +253,10 @@ discard block |
||
| 222 | 253 | $wknum = $cdate->getWeekNumber($prev_d); |
| 223 | 254 | if(!isset($week_rows[$row_count][$wknum])){
|
| 224 | 255 | $week_rows[$row_count][$wknum] = 1; |
| 225 | - }else $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
|
| 226 | -} |
|
| 256 | + } else { |
|
| 257 | + $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
|
| 258 | + } |
|
| 259 | + } |
|
| 227 | 260 | |
| 228 | 261 | $pvMonthTime = $previous_year."-".$previous_month."-".$total_lastmonth; |
| 229 | 262 | |
@@ -231,13 +264,20 @@ discard block |
||
| 231 | 264 | if($ta1_set && !$show_not_allow){
|
| 232 | 265 | if($cdate->dateBefore($pvMonthTime, $time_allow1)){
|
| 233 | 266 | $show_previous = true; |
| 234 | - }else $show_previous = false; |
|
| 235 | -}else $show_previous = true; //always show when not set |
|
| 267 | + } else { |
|
| 268 | + $show_previous = false; |
|
| 269 | + } |
|
| 270 | + } else { |
|
| 271 | + $show_previous = true; |
|
| 272 | +} |
|
| 273 | +//always show when not set |
|
| 236 | 274 | |
| 237 | 275 | $date_num = $cdate->getDayOfWeek(($previous_year."-".$previous_month."-".$total_lastmonth)); |
| 238 | 276 | if(($startDate == 0 && $date_num == 6) || ($startDate > 0 && $date_num == $startDate-1) && $startwrite<$total_lastmonth){
|
| 239 | - if(isset($calendar_rows[0])) $row_count++; |
|
| 240 | -} |
|
| 277 | + if(isset($calendar_rows[0])) { |
|
| 278 | + $row_count++; |
|
| 279 | + } |
|
| 280 | + } |
|
| 241 | 281 | |
| 242 | 282 | $dp_time = ($date_pair_value) ? $date_pair_value : ""; |
| 243 | 283 | |
@@ -270,13 +310,13 @@ discard block |
||
| 270 | 310 | if($ta1_set && $ta2_set){
|
| 271 | 311 | //both date specified |
| 272 | 312 | $dateLink = ($cdate->dateBefore($date_str, $time_allow1) && $cdate->dateAfter($date_str, $time_allow2)) ? true : false; |
| 273 | - }elseif($ta1_set){
|
|
| 313 | + } elseif($ta1_set){
|
|
| 274 | 314 | //only date 1 specified |
| 275 | 315 | $dateLink = $cdate->dateBefore($date_str, $time_allow1) ? true : false; |
| 276 | - }elseif($ta2_set){
|
|
| 316 | + } elseif($ta2_set){
|
|
| 277 | 317 | //only date 2 specified |
| 278 | 318 | $dateLink = $cdate->dateAfter($date_str, $time_allow2) ? true : false; |
| 279 | - }else{
|
|
| 319 | + } else{
|
|
| 280 | 320 | //no date allow specified, assume show all |
| 281 | 321 | $dateLink = true; |
| 282 | 322 | } |
@@ -343,13 +383,15 @@ discard block |
||
| 343 | 383 | if($date_pair_value){
|
| 344 | 384 | //check date_pair1 & 2 |
| 345 | 385 | if($date_pair1 && $date_pair_value != "0000-00-00" && $cdate->dateAfter($date_pair_value, $date_str) && (($slm>0 && $sld>0 && $sly>0) && $cdate->dateBefore("$sly-$slm-$sld", $date_str))){ //set date only after date_pair1
|
| 346 | - if(!in_array("select", $htmlClass))
|
|
| 347 | - $htmlClass[] = "select"; |
|
| 386 | + if(!in_array("select", $htmlClass)) { |
|
| 387 | + $htmlClass[] = "select"; |
|
| 388 | + } |
|
| 348 | 389 | } |
| 349 | 390 | |
| 350 | 391 | if($date_pair2 && $date_pair_value != "0000-00-00" && $cdate->dateBefore($date_pair_value, $date_str) && (($slm>0 && $sld>0 && $sly>0) && $cdate->dateAfter("$sly-$slm-$sld", $date_str))){ //set date only before date_pair2
|
| 351 | - if(!in_array("select", $htmlClass))
|
|
| 352 | - $htmlClass[] = "select"; |
|
| 392 | + if(!in_array("select", $htmlClass)) { |
|
| 393 | + $htmlClass[] = "select"; |
|
| 394 | + } |
|
| 353 | 395 | } |
| 354 | 396 | } |
| 355 | 397 | |
@@ -364,7 +406,7 @@ discard block |
||
| 364 | 406 | $class = implode(" ", $htmlClass);
|
| 365 | 407 | |
| 366 | 408 | $calendar_rows[$row_count][] = array($day, "javascript:selectDay('".str_pad($day, 2, "0", STR_PAD_LEFT)."');", $class, "$y".str_pad($m, 2, "0", STR_PAD_LEFT).str_pad($day, 2, "0", STR_PAD_LEFT));
|
| 367 | - }else{
|
|
| 409 | + } else{
|
|
| 368 | 410 | $htmlClass[] = "disabledate"; |
| 369 | 411 | $class = implode(" ", $htmlClass);
|
| 370 | 412 | |
@@ -381,14 +423,18 @@ discard block |
||
| 381 | 423 | $row_count++; |
| 382 | 424 | |
| 383 | 425 | $dayinweek_counter = 0; |
| 384 | - }else $dayinweek_counter++; |
|
| 426 | + } else { |
|
| 427 | + $dayinweek_counter++; |
|
| 428 | + } |
|
| 385 | 429 | |
| 386 | 430 | $wknum = $cdate->getWeekNumber(($y."-".$m."-".$day)); |
| 387 | 431 | |
| 388 | 432 | if(!isset($week_rows[$row_count][$wknum])){
|
| 389 | 433 | $week_rows[$row_count][$wknum] = 1; |
| 390 | - }else $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
|
| 391 | -} |
|
| 434 | + } else { |
|
| 435 | + $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
|
| 436 | + } |
|
| 437 | + } |
|
| 392 | 438 | |
| 393 | 439 | //write next other month |
| 394 | 440 | $write_end_days = (6-$dayinweek_counter)+1; |
@@ -399,7 +445,9 @@ discard block |
||
| 399 | 445 | $wknum = $cdate->getWeekNumber($cdate->addMonth("Y-m-d", 1, ($y."-".$m."-".$day))); //date('W', mktime(0,0,0, $m+1, $day, $y));
|
| 400 | 446 | if(!isset($week_rows[$row_count][$wknum])){
|
| 401 | 447 | $week_rows[$row_count][$wknum] = 1; |
| 402 | - }else $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
|
| 448 | + } else { |
|
| 449 | + $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
|
| 450 | + } |
|
| 403 | 451 | } |
| 404 | 452 | $row_count++; |
| 405 | 453 | } |
@@ -414,7 +462,9 @@ discard block |
||
| 414 | 462 | |
| 415 | 463 | if(!isset($week_rows[$row_count][$wknum])){
|
| 416 | 464 | $week_rows[$row_count][$wknum] = 1; |
| 417 | - }else $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
|
| 465 | + } else { |
|
| 466 | + $week_rows[$row_count][$wknum] = $week_rows[$row_count][$wknum]+1; |
|
| 467 | + } |
|
| 418 | 468 | } |
| 419 | 469 | $write_end_days += 6; |
| 420 | 470 | } |
@@ -424,11 +474,19 @@ discard block |
||
| 424 | 474 | $nxMonthTime = $next_year."-".$next_month."-1"; |
| 425 | 475 | if($cdate->dateAfter($nxMonthTime, $time_allow2)){
|
| 426 | 476 | $show_next = true; |
| 427 | - }else $show_next = false; |
|
| 428 | -}else $show_next = true; //always show when not set |
|
| 477 | + } else { |
|
| 478 | + $show_next = false; |
|
| 479 | + } |
|
| 480 | + } else { |
|
| 481 | + $show_next = true; |
|
| 482 | +} |
|
| 483 | +//always show when not set |
|
| 429 | 484 | ?> |
| 430 | 485 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 431 | -<html xmlns="http://www.w3.org/1999/xhtml"<?php if($rtl) echo(" dir=\"rtl\""); ?>>
|
|
| 486 | +<html xmlns="http://www.w3.org/1999/xhtml"<?php if($rtl) { |
|
| 487 | + echo(" dir=\"rtl\""); |
|
| 488 | +} |
|
| 489 | +?>> |
|
| 432 | 490 | <head> |
| 433 | 491 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 434 | 492 | <title>TriConsole.com - PHP Calendar Date Picker</title> |
@@ -459,7 +517,7 @@ discard block |
||
| 459 | 517 | if($form_name){
|
| 460 | 518 | //submit value by post form |
| 461 | 519 | echo("window.parent.document.".$form_name.".submit();\n");
|
| 462 | - }elseif($target_url){
|
|
| 520 | + } elseif($target_url){
|
|
| 463 | 521 | //submit value by get method |
| 464 | 522 | echo("var date_selected = yvalue + \"-\" + mvalue + \"-\" + dvalue;\n");
|
| 465 | 523 | echo("window.parent.location.href='".$target_url."?".$objname."='+date_selected;\n");
|
@@ -474,7 +532,10 @@ discard block |
||
| 474 | 532 | <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> |
| 475 | 533 | <span id="calendar-page" class="font"> |
| 476 | 534 | <div id="calendar-header" align="center"> |
| 477 | - <?php if($show_calendar_info) include("calendar_info.php"); ?>
|
|
| 535 | + <?php if($show_calendar_info) { |
|
| 536 | + include("calendar_info.php"); |
|
| 537 | +} |
|
| 538 | +?> |
|
| 478 | 539 | <?php if($dp && !$auto_hide){ ?>
|
| 479 | 540 | <div style="float: right;" class="closeme"><a href="javascript:closeMe();"><img src="images/close.gif" border="0" alt="Close" title="Close" /></a></div> |
| 480 | 541 | <?php } ?> |
@@ -561,7 +622,9 @@ discard block |
||
| 561 | 622 | |
| 562 | 623 | echo("<tr>");
|
| 563 | 624 | |
| 564 | - if ($show_weeks) echo("<td align=\"center\" class=\"header wk-hdr\"><div>".$cobj->week_hdr."</div></td>");
|
|
| 625 | + if ($show_weeks) { |
|
| 626 | + echo("<td align=\"center\" class=\"header wk-hdr\"><div>".$cobj->week_hdr."</div></td>"); |
|
| 627 | + } |
|
| 565 | 628 | |
| 566 | 629 | //write calendar day header |
| 567 | 630 | foreach($day_headers as $dh){
|
@@ -591,7 +654,7 @@ discard block |
||
| 591 | 654 | |
| 592 | 655 | if($this_link){
|
| 593 | 656 | echo("<td".$id_str." align=\"center\" class=\"".$this_class."\"><div><a href=\"".$this_link."\">".$this_day."</a></div></td>");
|
| 594 | - }else{
|
|
| 657 | + } else{
|
|
| 595 | 658 | echo("<td".$id_str." align=\"center\" class=\"".$this_class."\"><div>".$this_day."</div></td>");
|
| 596 | 659 | } |
| 597 | 660 | } |
@@ -610,7 +673,9 @@ discard block |
||
| 610 | 673 | if($previous_year >= $year_start && $show_previous){
|
| 611 | 674 | ?><a href="javascript:move('<?php echo(str_pad($previous_month, 2, "0", STR_PAD_LEFT));?>', '<?php echo($previous_year);?>');"><img src="images/btn_<?php echo($rtl ? "next" : "previous"); ?>.gif" width="16" height="16" border="0" alt="Previous" title="Previous" /></a>
|
| 612 | 675 | <?php |
| 613 | - }else echo(" ");
|
|
| 676 | + } else { |
|
| 677 | + echo(" "); |
|
| 678 | + } |
|
| 614 | 679 | ?> |
| 615 | 680 | </div> |
| 616 | 681 | <div style="float: <?php echo($rtl ? "left" : "right"); ?>;" class="btn"> |
@@ -618,18 +683,22 @@ discard block |
||
| 618 | 683 | if($next_year <= $year_end && $show_next){
|
| 619 | 684 | ?><a href="javascript:move('<?php echo(str_pad($next_month, 2, "0", STR_PAD_LEFT));?>', '<?php echo($next_year);?>');"><img src="images/btn_<?php echo($rtl ? "previous" : "next"); ?>.gif" width="16" height="16" border="0" alt="Next" title="Next" /></a>
|
| 620 | 685 | <?php |
| 621 | - }else echo(" ");
|
|
| 686 | + } else { |
|
| 687 | + echo(" "); |
|
| 688 | + } |
|
| 622 | 689 | ?> |
| 623 | 690 | </div> |
| 624 | 691 | <div class="links"> |
| 625 | 692 | <?php |
| 626 | 693 | $footer_links = array(); |
| 627 | 694 | |
| 628 | - if($cobj->validTodayDate() && ($m != $cdate->getDate('m') || $y != $cdate->getDate('Y')))
|
|
| 629 | - $footer_links[] = "<a href=\"javascript:today();\" class=\"txt\" alt=\"Today\" title=\"Today\">Today</a>"; |
|
| 695 | + if($cobj->validTodayDate() && ($m != $cdate->getDate('m') || $y != $cdate->getDate('Y'))) { |
|
| 696 | + $footer_links[] = "<a href=\"javascript:today();\" class=\"txt\" alt=\"Today\" title=\"Today\">Today</a>"; |
|
| 697 | + } |
|
| 630 | 698 | |
| 631 | - if($sld>0 && $slm>0 && $sly>0) |
|
| 632 | - $footer_links[] = "<a href=\"javascript:unsetValue();\" class=\"txt\" alt=\"Unset\" title=\"Unset\">Unset</a>"; |
|
| 699 | + if($sld>0 && $slm>0 && $sly>0) { |
|
| 700 | + $footer_links[] = "<a href=\"javascript:unsetValue();\" class=\"txt\" alt=\"Unset\" title=\"Unset\">Unset</a>"; |
|
| 701 | + } |
|
| 633 | 702 | |
| 634 | 703 | if(sizeof($footer_links)>0){
|
| 635 | 704 | echo(implode(" | ", $footer_links));
|
@@ -5,10 +5,10 @@ discard block |
||
| 5 | 5 | include_once($path.'config.php'); |
| 6 | 6 | require_once($path.'function.php'); |
| 7 | 7 | if ( !isset($version) ) { |
| 8 | - openlog('myRBLemergency', LOG_PID, LOG_LOCAL0); |
|
| 9 | - syslog (LOG_EMERG, 'unknown: I can\'t read the config files. Do you have configured the $path in getip.php?'); |
|
| 10 | - closelog(); |
|
| 11 | - exit(255); |
|
| 8 | + openlog('myRBLemergency', LOG_PID, LOG_LOCAL0); |
|
| 9 | + syslog (LOG_EMERG, 'unknown: I can\'t read the config files. Do you have configured the $path in getip.php?'); |
|
| 10 | + closelog(); |
|
| 11 | + exit(255); |
|
| 12 | 12 | } |
| 13 | 13 | include_once(dirname(__FILE__) . '/function.php'); |
| 14 | 14 | $conf = parse_ini_file($confImap_file); |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | /* check you select a right list */ |
| 37 | 37 | if ( !$tables[$conf['list']['spam']]['bl'] ) { |
| 38 | - syslog(LOG_EMERG, $conf['user'].': <'.$conf['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.'); |
|
| 39 | - exit (254); |
|
| 38 | + syslog(LOG_EMERG, $conf['user'].': <'.$conf['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.'); |
|
| 39 | + exit (254); |
|
| 40 | 40 | } |
| 41 | 41 | if ( $tables[$conf['list']['ham']]['bl'] ) { |
| 42 | - syslog(LOG_EMERG, $conf['user'].': <'.$conf['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); |
|
| 43 | - exit (254); |
|
| 42 | + syslog(LOG_EMERG, $conf['user'].': <'.$conf['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); |
|
| 43 | + exit (254); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /* Make MYSQL connection Array */ |
@@ -1,16 +1,16 @@ discard block |
||
| 1 | 1 | #!/usr/bin/php |
| 2 | 2 | <?php |
| 3 | 3 | /* Config */ |
| 4 | -$path='/web/RBL/'; |
|
| 4 | +$path = '/web/RBL/'; |
|
| 5 | 5 | include_once($path.'config.php'); |
| 6 | 6 | require_once($path.'function.php'); |
| 7 | -if ( !isset($version) ) { |
|
| 7 | +if (!isset($version)) { |
|
| 8 | 8 | openlog('myRBLemergency', LOG_PID, LOG_LOCAL0); |
| 9 | - syslog (LOG_EMERG, 'unknown: I can\'t read the config files. Do you have configured the $path in getip.php?'); |
|
| 9 | + syslog(LOG_EMERG, 'unknown: I can\'t read the config files. Do you have configured the $path in getip.php?'); |
|
| 10 | 10 | closelog(); |
| 11 | 11 | exit(255); |
| 12 | 12 | } |
| 13 | -include_once(dirname(__FILE__) . '/function.php'); |
|
| 13 | +include_once(dirname(__FILE__).'/function.php'); |
|
| 14 | 14 | $conf = parse_ini_file($confImap_file); |
| 15 | 15 | |
| 16 | 16 | |
@@ -19,8 +19,8 @@ discard block |
||
| 19 | 19 | openlog($tag, LOG_PID, $fac); |
| 20 | 20 | |
| 21 | 21 | |
| 22 | -if ( !$imapListActive ) { |
|
| 23 | - syslog (LOG_INFO, $conf['user'].': This plugin isn\'t active.'); |
|
| 22 | +if (!$imapListActive) { |
|
| 23 | + syslog(LOG_INFO, $conf['user'].': This plugin isn\'t active.'); |
|
| 24 | 24 | closelog(); |
| 25 | 25 | exit(255); |
| 26 | 26 | } |
@@ -31,20 +31,20 @@ discard block |
||
| 31 | 31 | $arr_tpl_data = array(date("Y-m-d", time())); |
| 32 | 32 | |
| 33 | 33 | |
| 34 | -if ( !$conf['onlyReport'] ) { |
|
| 34 | +if (!$conf['onlyReport']) { |
|
| 35 | 35 | |
| 36 | 36 | /* check you select a right list */ |
| 37 | - if ( !$tables[$conf['list']['spam']]['bl'] ) { |
|
| 37 | + if (!$tables[$conf['list']['spam']]['bl']) { |
|
| 38 | 38 | syslog(LOG_EMERG, $conf['user'].': <'.$conf['list']['spam'].'> is not a blocklist. Are you stupid? Do you want to whitelist a spammer? I refuse to continue.'); |
| 39 | 39 | exit (254); |
| 40 | 40 | } |
| 41 | - if ( $tables[$conf['list']['ham']]['bl'] ) { |
|
| 41 | + if ($tables[$conf['list']['ham']]['bl']) { |
|
| 42 | 42 | syslog(LOG_EMERG, $conf['user'].': <'.$conf['list']['ham'].'> is a blocklist. Are you stupid? Do you want to block a legitimate sender? I refuse to continue.'); |
| 43 | 43 | exit (254); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /* Make MYSQL connection Array */ |
| 47 | - $mysqlconf= array( |
|
| 47 | + $mysqlconf = array( |
|
| 48 | 48 | 'dbhost' => $dbhost, |
| 49 | 49 | 'userdb' => $userdb, |
| 50 | 50 | 'pwd' => $pwd, |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | else { |
| 57 | 57 | $mysqlconf = NULL; |
| 58 | - syslog(LOG_INFO, $conf['user'].': Report only, no listing activated in configuration.') ; |
|
| 58 | + syslog(LOG_INFO, $conf['user'].': Report only, no listing activated in configuration.'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | |
@@ -67,16 +67,16 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | /* The hard work has hidden in imapReport */ |
| 70 | -$learnfromArray = array('ham','spam'); |
|
| 71 | -foreach ( $learnfromArray as $learnfrom ) { |
|
| 70 | +$learnfromArray = array('ham', 'spam'); |
|
| 71 | +foreach ($learnfromArray as $learnfrom) { |
|
| 72 | 72 | $conf['reportFile']["$learnfrom"] = str_replace($arr_tpl_vars, $arr_tpl_data, $conf['reportFile']["$learnfrom"]); |
| 73 | 73 | $conf['badreportFile']["$learnfrom"] = str_replace($arr_tpl_vars, $arr_tpl_data, $conf['badreportFile']["$learnfrom"]); |
| 74 | - imapReport ($conf,$mysqlconf,$splservice,$tables,$learnfrom); |
|
| 74 | + imapReport($conf, $mysqlconf, $splservice, $tables, $learnfrom); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | -if ( !$conf['onlyReport'] ) { |
|
| 77 | +if (!$conf['onlyReport']) { |
|
| 78 | 78 | /* Close connection */ |
| 79 | - syslog (LOG_INFO, $conf['user'].': Successfully end of session.'); |
|
| 79 | + syslog(LOG_INFO, $conf['user'].': Successfully end of session.'); |
|
| 80 | 80 | } |
| 81 | 81 | closelog(); |
| 82 | 82 | ?> |
@@ -51,9 +51,7 @@ |
||
| 51 | 51 | 'db' => $db, |
| 52 | 52 | 'dbport' => $dbport |
| 53 | 53 | ); |
| 54 | -} |
|
| 55 | - |
|
| 56 | -else { |
|
| 54 | +} else { |
|
| 57 | 55 | $mysqlconf = NULL; |
| 58 | 56 | syslog(LOG_INFO, $conf['user'].': Report only, no listing activated in configuration.') ; |
| 59 | 57 | } |
@@ -15,10 +15,10 @@ |
||
| 15 | 15 | openlog($tag, LOG_PID, $fac); |
| 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 . ') ' |
|
| 19 | - . $mysqli->connect_error); |
|
| 20 | - die($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 21 | - . $mysqli->connect_error); |
|
| 18 | + syslog (LOG_EMERG, $user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 19 | + . $mysqli->connect_error); |
|
| 20 | + die($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 21 | + . $mysqli->connect_error); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); |
@@ -15,15 +15,15 @@ |
||
| 15 | 15 | openlog($tag, LOG_PID, $fac); |
| 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 | - die($user.': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 20 | + die($user.': Connect Error ('.$mysqli->connect_errno.') ' |
|
| 21 | 21 | . $mysqli->connect_error); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | -syslog (LOG_INFO, $user.': Successfully connected to ' . $mysqli->host_info ); |
|
| 24 | +syslog(LOG_INFO, $user.': Successfully connected to '.$mysqli->host_info); |
|
| 25 | 25 | |
| 26 | -expire($mysqli,$user,$tables,$expireTime); |
|
| 26 | +expire($mysqli, $user, $tables, $expireTime); |
|
| 27 | 27 | $mysqli->close(); |
| 28 | 28 | closelog(); |
| 29 | 29 | ?> |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | <h1> DNSBL Lookup</h1> |
| 12 | 12 | <?php |
| 13 | 13 | |
| 14 | -$_POST['Value'] = str_replace('_','.',array_keys($_GET)[0]); |
|
| 14 | +$_POST['Value'] = str_replace('_', '.', array_keys($_GET)[0]); |
|
| 15 | 15 | $_POST['genere'] = 'Spam IP'; |
| 16 | 16 | require_once('result.php'); |
| 17 | 17 | ?> |
@@ -1,4 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | +/** |
|
| 3 | + * @param string $header |
|
| 4 | + */ |
|
| 2 | 5 | function getIP($header,$mxserver,$msa) { |
| 3 | 6 | /* Get submission server's IP from header's mail */ |
| 4 | 7 | /* Each line must end with /r/n */ |
@@ -28,11 +31,24 @@ discard block |
||
| 28 | 31 | return array($ip,$host,$dateR,$dateC['date'],$mid['mid']); |
| 29 | 32 | } |
| 30 | 33 | |
| 34 | +/** |
|
| 35 | + * @param string|false $ip |
|
| 36 | + * @param string $hostname |
|
| 37 | + * @param string $dateC |
|
| 38 | + * @param string|null $msgid |
|
| 39 | + * @param string|false $dateL |
|
| 40 | + */ |
|
| 31 | 41 | function updateReport ($ip,$uid,$ipcount,$uidcount,$hostname,$dateC,$msgid,$dateL) { |
| 32 | 42 | |
| 33 | 43 | return sprintf ('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td>%u</td><td>%u</td><td>%s</td><td>%s</td></tr>'."\n",$dateL,$dateC,$uid,$ip,$uidcount,$ipcount,$hostname,htmlentities($msgid) ); |
| 34 | 44 | } |
| 35 | 45 | |
| 46 | +/** |
|
| 47 | + * @param string $dateC |
|
| 48 | + * @param string|null $msgid |
|
| 49 | + * @param false|string $dateL |
|
| 50 | + * @param string $text |
|
| 51 | + */ |
|
| 36 | 52 | function updatebadReport ( $uid,$dateC,$msgid,$dateL,$text ) { |
| 37 | 53 | return sprintf ('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td nowrap>%s</td></tr>'."\n",$dateL,$dateC,$uid,htmlentities($msgid),$text ); |
| 38 | 54 | } |
@@ -84,6 +100,9 @@ discard block |
||
| 84 | 100 | } |
| 85 | 101 | |
| 86 | 102 | |
| 103 | +/** |
|
| 104 | + * @param null|mysqli $myconn |
|
| 105 | + */ |
|
| 87 | 106 | function summaryReportAndList ($cf,$myconn,$tables,$category,$ipvet) { |
| 88 | 107 | $nips = $ipvet['count']; |
| 89 | 108 | |
@@ -154,6 +173,10 @@ discard block |
||
| 154 | 173 | } |
| 155 | 174 | |
| 156 | 175 | |
| 176 | +/** |
|
| 177 | + * @param string $message_id |
|
| 178 | + * @param string $date |
|
| 179 | + */ |
|
| 157 | 180 | function splunksearch ($service,$message_id,$date) { |
| 158 | 181 | |
| 159 | 182 | // Run a blocking search |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | # print "Examine ".$received[0][$i]."\n"; |
| 13 | 13 | if ( preg_match($msa,$received['host'][$i]) ) |
| 14 | 14 | $dateR = $received['date'][$i]; |
| 15 | - foreach ($mxserver as $mx) { |
|
| 16 | - if (!$ip) |
|
| 15 | + foreach ($mxserver as $mx) { |
|
| 16 | + if (!$ip) |
|
| 17 | 17 | if ($mx == $received['host'][$i]) { |
| 18 | 18 | $host = $received['host'][$i]; |
| 19 | 19 | $ip = $received['ip'][$i]; |
| 20 | - } |
|
| 21 | - } |
|
| 22 | - } |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | 23 | } |
| 24 | 24 | if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) |
| 25 | 25 | $dateC['date'] = 'Not found'; |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | function summaryBadReport ($uidvet) { |
| 42 | - $nuid = $uidvet['count']; |
|
| 43 | - if ( empty($uidvet) ) return NULL; |
|
| 44 | - $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
|
| 42 | + $nuid = $uidvet['count']; |
|
| 43 | + if ( empty($uidvet) ) return NULL; |
|
| 44 | + $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
|
| 45 | 45 | |
| 46 | - /* Remove count index */ |
|
| 47 | - $uids = array_keys($uidvet['uid']); |
|
| 46 | + /* Remove count index */ |
|
| 47 | + $uids = array_keys($uidvet['uid']); |
|
| 48 | 48 | $totlearn = 0; |
| 49 | 49 | |
| 50 | - foreach ( $uids as $uid ) { |
|
| 50 | + foreach ( $uids as $uid ) { |
|
| 51 | 51 | $totlearn += $uidvet['uid']["$uid"]['count'];; |
| 52 | 52 | $return .= sprintf ('<tr><td>%s</td><td>%u</td></tr>',$uid,$uidvet['uid']["$uid"]['count']); |
| 53 | 53 | } |
@@ -60,26 +60,26 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | function array_msort($array, $cols) |
| 62 | 62 | { |
| 63 | - $colarr = array(); |
|
| 64 | - foreach ($cols as $col => $order) { |
|
| 65 | - $colarr[$col] = array(); |
|
| 66 | - foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } |
|
| 67 | - } |
|
| 68 | - $eval = 'array_multisort('; |
|
| 69 | - foreach ($cols as $col => $order) { |
|
| 70 | - $eval .= '$colarr[\''.$col.'\'],'.$order.','; |
|
| 71 | - } |
|
| 72 | - $eval = substr($eval,0,-1).');'; |
|
| 73 | - eval($eval); |
|
| 74 | - $ret = array(); |
|
| 75 | - foreach ($colarr as $col => $arr) { |
|
| 76 | - foreach ($arr as $k => $v) { |
|
| 77 | - $k = substr($k,1); |
|
| 78 | - if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
|
| 79 | - if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - return $ret; |
|
| 63 | + $colarr = array(); |
|
| 64 | + foreach ($cols as $col => $order) { |
|
| 65 | + $colarr[$col] = array(); |
|
| 66 | + foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } |
|
| 67 | + } |
|
| 68 | + $eval = 'array_multisort('; |
|
| 69 | + foreach ($cols as $col => $order) { |
|
| 70 | + $eval .= '$colarr[\''.$col.'\'],'.$order.','; |
|
| 71 | + } |
|
| 72 | + $eval = substr($eval,0,-1).');'; |
|
| 73 | + eval($eval); |
|
| 74 | + $ret = array(); |
|
| 75 | + foreach ($colarr as $col => $arr) { |
|
| 76 | + foreach ($arr as $k => $v) { |
|
| 77 | + $k = substr($k,1); |
|
| 78 | + if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
|
| 79 | + if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + return $ret; |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | foreach ( $ips as $ip ) { |
| 96 | 96 | if ( $ip == 'count' ) continue; |
| 97 | - $nlearn = $ipvet['ip']["$ip"]['count']; |
|
| 98 | - unset($ipvet['ip']["$ip"]['count']); |
|
| 97 | + $nlearn = $ipvet['ip']["$ip"]['count']; |
|
| 98 | + unset($ipvet['ip']["$ip"]['count']); |
|
| 99 | 99 | $quantity = $cf['quantity']["$category"]; /* In searchAndList this value is passed by reference and modified */ |
| 100 | 100 | $nuid = count($ipvet['ip']["$ip"]); |
| 101 | 101 | if ( !$cf['onlyReport'] ) { |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | $return .='<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; |
| 124 | 124 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nuid.'">%u</td><td rowspan="'.$nuid.'" '.$nowlist["$listed"]['style'].'>%s</td></tr>',$ipvet['ip']["$ip"][0],$nlearn,$nowlist["$listed"]['name']); |
| 125 | 125 | $rowuid=NULL; |
| 126 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 126 | + for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 127 | 127 | array_shift($ipvet['ip']["$ip"]); |
| 128 | - $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); |
|
| 128 | + $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); |
|
| 129 | 129 | |
| 130 | 130 | } |
| 131 | 131 | $return .= sprintf ('<tr><th title="unique ips">%u</th><th title="unique uids">%u</th><th>%u</th></table>',$ipvet['ip']['count'],$ipvet['uid']['count'],$nips); |
@@ -135,20 +135,20 @@ discard block |
||
| 135 | 135 | /* Not used for listing purpose, but useful to you! */ |
| 136 | 136 | $return .= '<h3>Statistics by UID</h3><table><tr><th>UID</th><th>IP learned</th><th>Learned times</th></tr>'."\n"; |
| 137 | 137 | $uids = array_keys($ipvet['uid']); |
| 138 | - foreach ( $uids as $uid ) { |
|
| 138 | + foreach ( $uids as $uid ) { |
|
| 139 | 139 | if ( $uid == 'count' ) continue; |
| 140 | - $nlearn = $ipvet['uid']["$uid"]['count']; |
|
| 141 | - unset ( $ipvet['uid']["$uid"]['count'] ); |
|
| 140 | + $nlearn = $ipvet['uid']["$uid"]['count']; |
|
| 141 | + unset ( $ipvet['uid']["$uid"]['count'] ); |
|
| 142 | 142 | $nip = count($ipvet['uid']["$uid"]); |
| 143 | 143 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
| 144 | 144 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$ipvet['uid']["$uid"][0],$nlearn); |
| 145 | - $rowuid=NULL; |
|
| 146 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 147 | - array_shift($ipvet['uid']["$uid"]); |
|
| 148 | - $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); |
|
| 145 | + $rowuid=NULL; |
|
| 146 | + for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 147 | + array_shift($ipvet['uid']["$uid"]); |
|
| 148 | + $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); |
|
| 149 | 149 | |
| 150 | - } |
|
| 151 | - $return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique ips">%u</th><th>%u</th></table>',$ipvet['uid']['count'],$ipvet['ip']['count'],$nips); |
|
| 150 | + } |
|
| 151 | + $return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique ips">%u</th><th>%u</th></table>',$ipvet['uid']['count'],$ipvet['ip']['count'],$nips); |
|
| 152 | 152 | |
| 153 | 153 | |
| 154 | 154 | return $return; |
@@ -176,50 +176,50 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | |
| 178 | 178 | // A one shot search |
| 179 | - $searchParams = array( |
|
| 180 | - 'earliest_time' => date("c",strtotime ($date)-120), |
|
| 181 | - 'latest_time' => date("c",strtotime ($date)+60) |
|
| 182 | - ); |
|
| 179 | + $searchParams = array( |
|
| 180 | + 'earliest_time' => date("c",strtotime ($date)-120), |
|
| 181 | + 'latest_time' => date("c",strtotime ($date)+60) |
|
| 182 | + ); |
|
| 183 | 183 | |
| 184 | - // Run a oneshot search that returns the job's results |
|
| 185 | - $resultsStream = $service->oneshotSearch($searchQueryBlocking, $searchParams); |
|
| 186 | - $resultSearch = new Splunk_ResultsReader($resultsStream); |
|
| 184 | + // Run a oneshot search that returns the job's results |
|
| 185 | + $resultsStream = $service->oneshotSearch($searchQueryBlocking, $searchParams); |
|
| 186 | + $resultSearch = new Splunk_ResultsReader($resultsStream); |
|
| 187 | 187 | |
| 188 | 188 | // Use the built-in XML parser to display the job results |
| 189 | 189 | foreach ($resultSearch as $result) |
| 190 | 190 | { |
| 191 | - if ($result instanceof Splunk_ResultsFieldOrder) |
|
| 192 | - { |
|
| 193 | - // More than one field attribute returned by search |
|
| 194 | - // You must redefine the search |
|
| 195 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 196 | - } |
|
| 197 | - else if ($result instanceof Splunk_ResultsMessage) |
|
| 198 | - { |
|
| 199 | - // I don't want messages in my search |
|
| 200 | - return FALSE; |
|
| 201 | - } |
|
| 202 | - else if (is_array($result)) |
|
| 203 | - { |
|
| 204 | - // Process a row |
|
| 205 | - foreach ($result as $key => $valueOrValues) |
|
| 206 | - { |
|
| 207 | - if (is_array($valueOrValues)) |
|
| 208 | - { |
|
| 209 | - return FALSE; |
|
| 210 | - } |
|
| 211 | - else |
|
| 212 | - { |
|
| 213 | - return $valueOrValues; |
|
| 214 | - #print " {$key} => {$value}\r\n"; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - else |
|
| 219 | - { |
|
| 220 | - #print "Unknow result type"; |
|
| 221 | - return FALSE; |
|
| 222 | - } |
|
| 191 | + if ($result instanceof Splunk_ResultsFieldOrder) |
|
| 192 | + { |
|
| 193 | + // More than one field attribute returned by search |
|
| 194 | + // You must redefine the search |
|
| 195 | + if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 196 | + } |
|
| 197 | + else if ($result instanceof Splunk_ResultsMessage) |
|
| 198 | + { |
|
| 199 | + // I don't want messages in my search |
|
| 200 | + return FALSE; |
|
| 201 | + } |
|
| 202 | + else if (is_array($result)) |
|
| 203 | + { |
|
| 204 | + // Process a row |
|
| 205 | + foreach ($result as $key => $valueOrValues) |
|
| 206 | + { |
|
| 207 | + if (is_array($valueOrValues)) |
|
| 208 | + { |
|
| 209 | + return FALSE; |
|
| 210 | + } |
|
| 211 | + else |
|
| 212 | + { |
|
| 213 | + return $valueOrValues; |
|
| 214 | + #print " {$key} => {$value}\r\n"; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + else |
|
| 219 | + { |
|
| 220 | + #print "Unknow result type"; |
|
| 221 | + return FALSE; |
|
| 222 | + } |
|
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | |
@@ -228,26 +228,26 @@ discard block |
||
| 228 | 228 | $file = dirname(__FILE__) . '/' . $cf['reportFile']["$type"]; |
| 229 | 229 | $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; |
| 230 | 230 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) |
| 231 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 231 | + or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 232 | 232 | if ( !$m_mail ) exit(254); |
| 233 | 233 | |
| 234 | 234 | |
| 235 | 235 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); |
| 236 | 236 | //get all messages |
| 237 | 237 | $dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['oldestday'].' days' ) ); |
| 238 | - $dateN = date ( "d-M-Y", strToTime ( "now" ) ); |
|
| 239 | - $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); |
|
| 238 | + $dateN = date ( "d-M-Y", strToTime ( "now" ) ); |
|
| 239 | + $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); |
|
| 240 | 240 | |
| 241 | 241 | |
| 242 | 242 | // Order results starting from newest message |
| 243 | 243 | if ( empty($m_search) ) { |
| 244 | 244 | syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); |
| 245 | - if ( $ierr = imap_errors() ) |
|
| 246 | - foreach ( $ierr as $thiserr ) |
|
| 247 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 248 | - if ( $ierr = imap_alerts() ) |
|
| 249 | - foreach ( $ierr as $thiserr ) |
|
| 250 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 245 | + if ( $ierr = imap_errors() ) |
|
| 246 | + foreach ( $ierr as $thiserr ) |
|
| 247 | + syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 248 | + if ( $ierr = imap_alerts() ) |
|
| 249 | + foreach ( $ierr as $thiserr ) |
|
| 250 | + syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 251 | 251 | imap_close( $m_mail ); |
| 252 | 252 | if ( file_exists( $file ) ) unlink ($file); |
| 253 | 253 | if ( file_exists( $fileb ) ) unlink ($fileb); |
@@ -280,16 +280,16 @@ discard block |
||
| 280 | 280 | $uidbad['count'] = 0; |
| 281 | 281 | $uidbad['uid'] = array(); |
| 282 | 282 | |
| 283 | - // loop for each message |
|
| 283 | + // loop for each message |
|
| 284 | 284 | foreach ($m_search as $onem) { |
| 285 | 285 | |
| 286 | - //get imap header info for obj thang |
|
| 287 | - //$headers = imap_headerinfo($m_mail, $onem); |
|
| 288 | - //$head = imap_fetchheader($m_mail, $headers->Msgno); |
|
| 286 | + //get imap header info for obj thang |
|
| 287 | + //$headers = imap_headerinfo($m_mail, $onem); |
|
| 288 | + //$head = imap_fetchheader($m_mail, $headers->Msgno); |
|
| 289 | 289 | $head = imap_fetchheader($m_mail, $onem ); |
| 290 | - //$obj = imap_rfc822_parse_headers( $head); |
|
| 290 | + //$obj = imap_rfc822_parse_headers( $head); |
|
| 291 | 291 | |
| 292 | - list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx'],$cf['msalearn'] ); |
|
| 292 | + list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx'],$cf['msalearn'] ); |
|
| 293 | 293 | if (empty($mid)) { |
| 294 | 294 | $uid='NA'; |
| 295 | 295 | syslog (LOG_ERR, $cf['user'].": Error retrieving data for empty Message-ID."); |
@@ -304,11 +304,11 @@ discard block |
||
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - /* Update count of each ip */ |
|
| 308 | - if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers and learned by valid uid */ |
|
| 307 | + /* Update count of each ip */ |
|
| 308 | + if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers and learned by valid uid */ |
|
| 309 | 309 | $ipuid['count']++; //number of right messages |
| 310 | 310 | |
| 311 | - if (in_array($uid,array_keys($ipuid['uid']))) { |
|
| 311 | + if (in_array($uid,array_keys($ipuid['uid']))) { |
|
| 312 | 312 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
| 313 | 313 | if (!in_array($ip,$ipuid['uid']["$uid"])) |
| 314 | 314 | $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid |
@@ -319,29 +319,29 @@ discard block |
||
| 319 | 319 | $ipuid['uid']['count']++; //number of unique uids |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if (in_array($ip,array_keys($ipuid['ip']))) { |
|
| 323 | - $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
|
| 322 | + if (in_array($ip,array_keys($ipuid['ip']))) { |
|
| 323 | + $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
|
| 324 | 324 | if (!in_array($uid,$ipuid['ip']["$ip"])) |
| 325 | 325 | $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip |
| 326 | 326 | } |
| 327 | - else { |
|
| 328 | - $ipuid['ip']["$ip"]['count'] = 1; |
|
| 327 | + else { |
|
| 328 | + $ipuid['ip']["$ip"]['count'] = 1; |
|
| 329 | 329 | $ipuid['ip']["$ip"][]=$uid; |
| 330 | 330 | $ipuid['ip']['count']++; //number of unique ips |
| 331 | - } |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - /* Update HTML report */ |
|
| 334 | - fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
|
| 333 | + /* Update HTML report */ |
|
| 334 | + fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
|
| 335 | 335 | } |
| 336 | - else { /* Bad learn */ |
|
| 336 | + else { /* Bad learn */ |
|
| 337 | 337 | |
| 338 | - if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 339 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 340 | - else { |
|
| 341 | - $uidbad['uid']["$uid"]['count'] = 1; |
|
| 338 | + if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 339 | + $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 340 | + else { |
|
| 341 | + $uidbad['uid']["$uid"]['count'] = 1; |
|
| 342 | 342 | $uidbad['uid']["$uid"][]=$uid; |
| 343 | - $uidbad['count']++; //numeber of unique bad uids |
|
| 344 | - } |
|
| 343 | + $uidbad['count']++; //numeber of unique bad uids |
|
| 344 | + } |
|
| 345 | 345 | /* The reason of bad report */ |
| 346 | 346 | if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; |
| 347 | 347 | if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; |
@@ -363,17 +363,17 @@ discard block |
||
| 363 | 363 | fwrite($fp, '</table>'); |
| 364 | 364 | fwrite($fp, '<hr><h2>Summary Report</h2><h5>Listing policy: ip must be learned at least '.$cf['thresholdip']["$type"].' times from at least '.$cf['thresholduid']["$type"].' different valid uids.</h5>' ); |
| 365 | 365 | |
| 366 | - /* Make MYSQL connection */ |
|
| 366 | + /* Make MYSQL connection */ |
|
| 367 | 367 | if ( $cf['onlyReport'] ) |
| 368 | 368 | $mysqli = NULL; |
| 369 | 369 | else { |
| 370 | - $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
|
| 371 | - if ($mysqli->connect_error) { |
|
| 372 | - syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 373 | - . $mysqli->connect_error); |
|
| 374 | - exit (254); |
|
| 375 | - } |
|
| 376 | - syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
| 370 | + $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
|
| 371 | + if ($mysqli->connect_error) { |
|
| 372 | + syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 373 | + . $mysqli->connect_error); |
|
| 374 | + exit (254); |
|
| 375 | + } |
|
| 376 | + syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
| 377 | 377 | } |
| 378 | 378 | /***********************/ |
| 379 | 379 | |
@@ -393,8 +393,8 @@ discard block |
||
| 393 | 393 | foreach ( $ierr as $thiserr ) |
| 394 | 394 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
| 395 | 395 | if ( $ierr = imap_alerts() ) |
| 396 | - foreach ( $ierr as $thiserr ) |
|
| 397 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 396 | + foreach ( $ierr as $thiserr ) |
|
| 397 | + syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 398 | 398 | imap_close($m_mail); |
| 399 | 399 | } |
| 400 | 400 | ?> |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -function getIP($header,$mxserver,$msa) { |
|
| 2 | +function getIP($header, $mxserver, $msa) { |
|
| 3 | 3 | /* Get submission server's IP from header's mail */ |
| 4 | 4 | /* Each line must end with /r/n */ |
| 5 | 5 | /* IP is the first one written by your mxserver */ |
@@ -7,10 +7,10 @@ discard block |
||
| 7 | 7 | $ip = FALSE; |
| 8 | 8 | $host = FALSE; |
| 9 | 9 | $dateR = FALSE; |
| 10 | - if ( preg_match_all('/^Received:\sfrom(?:.|\r\n\s)*?[\[\(]\s*(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\]\)](?:.|\r\n\s)+\s+by(?:\s|\r\n\s+)(?P<host>\S+).*(?:\s|\r\n\s\s)+.*;\s+(?P<date>.*)/m',$header,$received) ) { |
|
| 11 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 10 | + if (preg_match_all('/^Received:\sfrom(?:.|\r\n\s)*?[\[\(]\s*(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\]\)](?:.|\r\n\s)+\s+by(?:\s|\r\n\s+)(?P<host>\S+).*(?:\s|\r\n\s\s)+.*;\s+(?P<date>.*)/m', $header, $received)) { |
|
| 11 | + for ($i = count($received[0])-1; $i>=0; $i--) { |
|
| 12 | 12 | # print "Examine ".$received[0][$i]."\n"; |
| 13 | - if ( preg_match($msa,$received['host'][$i]) ) |
|
| 13 | + if (preg_match($msa, $received['host'][$i])) |
|
| 14 | 14 | $dateR = $received['date'][$i]; |
| 15 | 15 | foreach ($mxserver as $mx) { |
| 16 | 16 | if (!$ip) |
@@ -21,38 +21,38 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) |
|
| 24 | + if (preg_match('/\r\nDate:\s(?P<date>.*)\r\n/', $header, $dateC) != 1) |
|
| 25 | 25 | $dateC['date'] = 'Not found'; |
| 26 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) |
|
| 26 | + if (preg_match('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/', $header, $mid) != 1) |
|
| 27 | 27 | $mid['mid'] = NULL; |
| 28 | - return array($ip,$host,$dateR,$dateC['date'],$mid['mid']); |
|
| 28 | + return array($ip, $host, $dateR, $dateC['date'], $mid['mid']); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | -function updateReport ($ip,$uid,$ipcount,$uidcount,$hostname,$dateC,$msgid,$dateL) { |
|
| 31 | +function updateReport($ip, $uid, $ipcount, $uidcount, $hostname, $dateC, $msgid, $dateL) { |
|
| 32 | 32 | |
| 33 | - return sprintf ('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td>%u</td><td>%u</td><td>%s</td><td>%s</td></tr>'."\n",$dateL,$dateC,$uid,$ip,$uidcount,$ipcount,$hostname,htmlentities($msgid) ); |
|
| 33 | + return sprintf('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td>%u</td><td>%u</td><td>%s</td><td>%s</td></tr>'."\n", $dateL, $dateC, $uid, $ip, $uidcount, $ipcount, $hostname, htmlentities($msgid)); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | -function updatebadReport ( $uid,$dateC,$msgid,$dateL,$text ) { |
|
| 37 | - return sprintf ('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td nowrap>%s</td></tr>'."\n",$dateL,$dateC,$uid,htmlentities($msgid),$text ); |
|
| 36 | +function updatebadReport($uid, $dateC, $msgid, $dateL, $text) { |
|
| 37 | + return sprintf('<tr><td nowrap>%s</td><td nowrap>%s</td><td>%s</td><td>%s</td><td nowrap>%s</td></tr>'."\n", $dateL, $dateC, $uid, htmlentities($msgid), $text); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
| 41 | -function summaryBadReport ($uidvet) { |
|
| 41 | +function summaryBadReport($uidvet) { |
|
| 42 | 42 | $nuid = $uidvet['count']; |
| 43 | - if ( empty($uidvet) ) return NULL; |
|
| 43 | + if (empty($uidvet)) return NULL; |
|
| 44 | 44 | $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
| 45 | 45 | |
| 46 | 46 | /* Remove count index */ |
| 47 | 47 | $uids = array_keys($uidvet['uid']); |
| 48 | 48 | $totlearn = 0; |
| 49 | 49 | |
| 50 | - foreach ( $uids as $uid ) { |
|
| 51 | - $totlearn += $uidvet['uid']["$uid"]['count'];; |
|
| 52 | - $return .= sprintf ('<tr><td>%s</td><td>%u</td></tr>',$uid,$uidvet['uid']["$uid"]['count']); |
|
| 50 | + foreach ($uids as $uid) { |
|
| 51 | + $totlearn += $uidvet['uid']["$uid"]['count']; ; |
|
| 52 | + $return .= sprintf('<tr><td>%s</td><td>%u</td></tr>', $uid, $uidvet['uid']["$uid"]['count']); |
|
| 53 | 53 | } |
| 54 | - $return .= sprintf ('<tr><th>%s</th><th>%u</th></tr></table>','TOT',$totlearn); |
|
| 55 | - $return .= sprintf ('<p>%s : %u</p>','Unique UID',$nuid); |
|
| 54 | + $return .= sprintf('<tr><th>%s</th><th>%u</th></tr></table>', 'TOT', $totlearn); |
|
| 55 | + $return .= sprintf('<p>%s : %u</p>', 'Unique UID', $nuid); |
|
| 56 | 56 | |
| 57 | 57 | return $return; |
| 58 | 58 | } |
@@ -69,12 +69,12 @@ discard block |
||
| 69 | 69 | foreach ($cols as $col => $order) { |
| 70 | 70 | $eval .= '$colarr[\''.$col.'\'],'.$order.','; |
| 71 | 71 | } |
| 72 | - $eval = substr($eval,0,-1).');'; |
|
| 72 | + $eval = substr($eval, 0, -1).');'; |
|
| 73 | 73 | eval($eval); |
| 74 | 74 | $ret = array(); |
| 75 | 75 | foreach ($colarr as $col => $arr) { |
| 76 | 76 | foreach ($arr as $k => $v) { |
| 77 | - $k = substr($k,1); |
|
| 77 | + $k = substr($k, 1); |
|
| 78 | 78 | if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
| 79 | 79 | if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; |
| 80 | 80 | } |
@@ -84,29 +84,29 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
| 87 | -function summaryReportAndList ($cf,$myconn,$tables,$category,$ipvet) { |
|
| 87 | +function summaryReportAndList($cf, $myconn, $tables, $category, $ipvet) { |
|
| 88 | 88 | $nips = $ipvet['count']; |
| 89 | 89 | |
| 90 | - if ( empty($ipvet) ) return NULL; |
|
| 90 | + if (empty($ipvet)) return NULL; |
|
| 91 | 91 | $return = '<h3>Statistics by IP</h3><table><tr><th>IP</th><th>Learned by</th><th>Learned times</th><th title="This field doesn\'t say if this ip is currently listed, but it says if this IP has listed now!">Listed Now</th></tr>'."\n"; |
| 92 | 92 | |
| 93 | 93 | $ips = array_keys($ipvet['ip']); |
| 94 | 94 | |
| 95 | - foreach ( $ips as $ip ) { |
|
| 96 | - if ( $ip == 'count' ) continue; |
|
| 95 | + foreach ($ips as $ip) { |
|
| 96 | + if ($ip == 'count') continue; |
|
| 97 | 97 | $nlearn = $ipvet['ip']["$ip"]['count']; |
| 98 | 98 | unset($ipvet['ip']["$ip"]['count']); |
| 99 | 99 | $quantity = $cf['quantity']["$category"]; /* In searchAndList this value is passed by reference and modified */ |
| 100 | 100 | $nuid = count($ipvet['ip']["$ip"]); |
| 101 | - if ( !$cf['onlyReport'] ) { |
|
| 102 | - if ( ($nlearn >= $cf['thresholdip']["$category"])&&($nuid >= $cf['thresholduid']["$category"]) ) { |
|
| 101 | + if (!$cf['onlyReport']) { |
|
| 102 | + if (($nlearn>=$cf['thresholdip']["$category"]) && ($nuid>=$cf['thresholduid']["$category"])) { |
|
| 103 | 103 | $reason = "The IP <$ip> has been listed because was marked $nlearn times as $category by $nuid different accounts during last ".$cf['oldestday'].' days.'; |
| 104 | - $listed = searchAndList ($myconn,$cf['user'],$tables,$cf['list']["$category"],$ip,$cf['unit']["$category"],$quantity,$reason); |
|
| 104 | + $listed = searchAndList($myconn, $cf['user'], $tables, $cf['list']["$category"], $ip, $cf['unit']["$category"], $quantity, $reason); |
|
| 105 | 105 | } |
| 106 | 106 | else $listed = FALSE; |
| 107 | 107 | } |
| 108 | 108 | else $listed = FALSE; |
| 109 | - $nowlist = array( TRUE => array( |
|
| 109 | + $nowlist = array(TRUE => array( |
|
| 110 | 110 | 'style' => 'id=\'ipfound\'', |
| 111 | 111 | 'name' => 'YES', |
| 112 | 112 | ), |
@@ -120,45 +120,45 @@ discard block |
||
| 120 | 120 | ) |
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | - $return .='<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; |
|
| 124 | - $return .= sprintf ('<td>%s</td><td rowspan="'.$nuid.'">%u</td><td rowspan="'.$nuid.'" '.$nowlist["$listed"]['style'].'>%s</td></tr>',$ipvet['ip']["$ip"][0],$nlearn,$nowlist["$listed"]['name']); |
|
| 125 | - $rowuid=NULL; |
|
| 126 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 123 | + $return .= '<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; |
|
| 124 | + $return .= sprintf('<td>%s</td><td rowspan="'.$nuid.'">%u</td><td rowspan="'.$nuid.'" '.$nowlist["$listed"]['style'].'>%s</td></tr>', $ipvet['ip']["$ip"][0], $nlearn, $nowlist["$listed"]['name']); |
|
| 125 | + $rowuid = NULL; |
|
| 126 | + for ($j = 1; $j<$nuid; $j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 127 | 127 | array_shift($ipvet['ip']["$ip"]); |
| 128 | - $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); |
|
| 128 | + $return .= vsprintf($rowuid, $ipvet['ip']["$ip"]); |
|
| 129 | 129 | |
| 130 | 130 | } |
| 131 | - $return .= sprintf ('<tr><th title="unique ips">%u</th><th title="unique uids">%u</th><th>%u</th></table>',$ipvet['ip']['count'],$ipvet['uid']['count'],$nips); |
|
| 131 | + $return .= sprintf('<tr><th title="unique ips">%u</th><th title="unique uids">%u</th><th>%u</th></table>', $ipvet['ip']['count'], $ipvet['uid']['count'], $nips); |
|
| 132 | 132 | |
| 133 | 133 | |
| 134 | 134 | /* Statistics by UID */ |
| 135 | 135 | /* Not used for listing purpose, but useful to you! */ |
| 136 | 136 | $return .= '<h3>Statistics by UID</h3><table><tr><th>UID</th><th>IP learned</th><th>Learned times</th></tr>'."\n"; |
| 137 | 137 | $uids = array_keys($ipvet['uid']); |
| 138 | - foreach ( $uids as $uid ) { |
|
| 139 | - if ( $uid == 'count' ) continue; |
|
| 138 | + foreach ($uids as $uid) { |
|
| 139 | + if ($uid == 'count') continue; |
|
| 140 | 140 | $nlearn = $ipvet['uid']["$uid"]['count']; |
| 141 | - unset ( $ipvet['uid']["$uid"]['count'] ); |
|
| 141 | + unset ($ipvet['uid']["$uid"]['count']); |
|
| 142 | 142 | $nip = count($ipvet['uid']["$uid"]); |
| 143 | - $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
|
| 144 | - $return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$ipvet['uid']["$uid"][0],$nlearn); |
|
| 145 | - $rowuid=NULL; |
|
| 146 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 143 | + $return .= '<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
|
| 144 | + $return .= sprintf('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>', $ipvet['uid']["$uid"][0], $nlearn); |
|
| 145 | + $rowuid = NULL; |
|
| 146 | + for ($j = 1; $j<$nip; $j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 147 | 147 | array_shift($ipvet['uid']["$uid"]); |
| 148 | - $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); |
|
| 148 | + $return .= vsprintf($rowuid, $ipvet['uid']["$uid"]); |
|
| 149 | 149 | |
| 150 | 150 | } |
| 151 | - $return .= sprintf ('<tr><th title="unique uids">%u</th><th title="unique ips">%u</th><th>%u</th></table>',$ipvet['uid']['count'],$ipvet['ip']['count'],$nips); |
|
| 151 | + $return .= sprintf('<tr><th title="unique uids">%u</th><th title="unique ips">%u</th><th>%u</th></table>', $ipvet['uid']['count'], $ipvet['ip']['count'], $nips); |
|
| 152 | 152 | |
| 153 | 153 | |
| 154 | 154 | return $return; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
| 158 | -function splunksearch ($service,$message_id,$date) { |
|
| 158 | +function splunksearch($service, $message_id, $date) { |
|
| 159 | 159 | |
| 160 | 160 | // Run a blocking search |
| 161 | - $searchQueryBlocking = 'search (message_id="'. addslashes( $message_id ) . |
|
| 161 | + $searchQueryBlocking = 'search (message_id="'.addslashes($message_id). |
|
| 162 | 162 | '" OR sasl_username) | transaction message_id queue_id maxspan=3m maxpause=2m | search sasl_username message_id=* | table sasl_username'; |
| 163 | 163 | |
| 164 | 164 | /* Doesn't work on Splunk 6.6 for HTTP exceptions |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | // A one shot search |
| 179 | 179 | $searchParams = array( |
| 180 | - 'earliest_time' => date("c",strtotime ($date)-120), |
|
| 181 | - 'latest_time' => date("c",strtotime ($date)+60) |
|
| 180 | + 'earliest_time' => date("c", strtotime($date)-120), |
|
| 181 | + 'latest_time' => date("c", strtotime($date)+60) |
|
| 182 | 182 | ); |
| 183 | 183 | |
| 184 | 184 | // Run a oneshot search that returns the job's results |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | { |
| 193 | 193 | // More than one field attribute returned by search |
| 194 | 194 | // You must redefine the search |
| 195 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 195 | + if (count($result->getFieldNames())>1) return FALSE; |
|
| 196 | 196 | } |
| 197 | 197 | else if ($result instanceof Splunk_ResultsMessage) |
| 198 | 198 | { |
@@ -224,51 +224,51 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
| 227 | -function imapReport ($cf,$myconnArray,$splunkconn,$tables,$type) { |
|
| 228 | - $file = dirname(__FILE__) . '/' . $cf['reportFile']["$type"]; |
|
| 229 | - $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; |
|
| 230 | - $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) |
|
| 231 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 232 | - if ( !$m_mail ) exit(254); |
|
| 227 | +function imapReport($cf, $myconnArray, $splunkconn, $tables, $type) { |
|
| 228 | + $file = dirname(__FILE__).'/'.$cf['reportFile']["$type"]; |
|
| 229 | + $fileb = dirname(__FILE__).'/'.$cf['badreportFile']["$type"]; |
|
| 230 | + $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'], $cf['authpassword'], OP_READONLY) |
|
| 231 | + or syslog(LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: '.imap_last_error()); |
|
| 232 | + if (!$m_mail) exit(254); |
|
| 233 | 233 | |
| 234 | 234 | |
| 235 | - syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); |
|
| 235 | + syslog(LOG_INFO, $cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); |
|
| 236 | 236 | //get all messages |
| 237 | - $dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['oldestday'].' days' ) ); |
|
| 238 | - $dateN = date ( "d-M-Y", strToTime ( "now" ) ); |
|
| 239 | - $m_search=imap_search ($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\"" ); |
|
| 237 | + $dateTh = date("d-M-Y", strToTime('-'.$cf['oldestday'].' days')); |
|
| 238 | + $dateN = date("d-M-Y", strToTime("now")); |
|
| 239 | + $m_search = imap_search($m_mail, "SINCE \"$dateTh\" BEFORE \"$dateN\""); |
|
| 240 | 240 | |
| 241 | 241 | |
| 242 | 242 | // Order results starting from newest message |
| 243 | - if ( empty($m_search) ) { |
|
| 244 | - syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); |
|
| 245 | - if ( $ierr = imap_errors() ) |
|
| 246 | - foreach ( $ierr as $thiserr ) |
|
| 247 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 248 | - if ( $ierr = imap_alerts() ) |
|
| 249 | - foreach ( $ierr as $thiserr ) |
|
| 250 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 251 | - imap_close( $m_mail ); |
|
| 252 | - if ( file_exists( $file ) ) unlink ($file); |
|
| 253 | - if ( file_exists( $fileb ) ) unlink ($fileb); |
|
| 243 | + if (empty($m_search)) { |
|
| 244 | + syslog(LOG_INFO, $cf['user'].": No mail found in $type folder. No reports written for $type."); |
|
| 245 | + if ($ierr = imap_errors()) |
|
| 246 | + foreach ($ierr as $thiserr) |
|
| 247 | + syslog(LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 248 | + if ($ierr = imap_alerts()) |
|
| 249 | + foreach ($ierr as $thiserr) |
|
| 250 | + syslog(LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 251 | + imap_close($m_mail); |
|
| 252 | + if (file_exists($file)) unlink($file); |
|
| 253 | + if (file_exists($fileb)) unlink($fileb); |
|
| 254 | 254 | return FALSE; |
| 255 | 255 | } |
| 256 | - $nmes = count ($m_search); |
|
| 257 | - syslog (LOG_INFO,$cf['user'].": Found $nmes mail in $type folder."); |
|
| 256 | + $nmes = count($m_search); |
|
| 257 | + syslog(LOG_INFO, $cf['user'].": Found $nmes mail in $type folder."); |
|
| 258 | 258 | if ($nmes>0) rsort($m_search); |
| 259 | 259 | |
| 260 | 260 | // Create report file |
| 261 | 261 | |
| 262 | 262 | $fp = fopen($file, 'w'); |
| 263 | - $fpb= fopen($fileb, 'w'); |
|
| 264 | - $lastup = "Last Update: " . date ("d F Y H:i", time()); |
|
| 265 | - fwrite( $fp, file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
|
| 266 | - fwrite( $fp,"<h1> Report of IP sending $type</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
|
| 267 | - if ($cf['onlyReport']) fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
| 268 | - fwrite( $fp,'<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>IP</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned IP appears in different mails">#IP</th><th nowrap>Received by</th><th>Message-Id</th></tr>' ); |
|
| 269 | - fwrite( $fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
|
| 270 | - fwrite( $fpb,"<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
|
| 271 | - fwrite( $fpb,'<table><tr><th title="taken from Received header" nowrap>Date Learn</th><th title="taken from Date header" nowrap>Date Received</th><th nowrap>UID</th><th>Message-Id</th><th title="Why is this a bad report?">Reason</th></tr>' ); |
|
| 263 | + $fpb = fopen($fileb, 'w'); |
|
| 264 | + $lastup = "Last Update: ".date("d F Y H:i", time()); |
|
| 265 | + fwrite($fp, file_get_contents(dirname(__FILE__).'/'.$cf['reportTemplateHeader'])); |
|
| 266 | + fwrite($fp, "<h1> Report of IP sending $type</h1><h5>$lastup</h5><h2>Detailed Report</h2>"); |
|
| 267 | + if ($cf['onlyReport']) fwrite($fp, '<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
| 268 | + fwrite($fp, '<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>IP</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned IP appears in different mails">#IP</th><th nowrap>Received by</th><th>Message-Id</th></tr>'); |
|
| 269 | + fwrite($fpb, file_get_contents(dirname(__FILE__).'/'.$cf['reportTemplateHeader'])); |
|
| 270 | + fwrite($fpb, "<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>"); |
|
| 271 | + fwrite($fpb, '<table><tr><th title="taken from Received header" nowrap>Date Learn</th><th title="taken from Date header" nowrap>Date Received</th><th nowrap>UID</th><th>Message-Id</th><th title="Why is this a bad report?">Reason</th></tr>'); |
|
| 272 | 272 | |
| 273 | 273 | $ipuid = array(); |
| 274 | 274 | $ipuid['count'] = 0; |
@@ -286,69 +286,69 @@ discard block |
||
| 286 | 286 | //get imap header info for obj thang |
| 287 | 287 | //$headers = imap_headerinfo($m_mail, $onem); |
| 288 | 288 | //$head = imap_fetchheader($m_mail, $headers->Msgno); |
| 289 | - $head = imap_fetchheader($m_mail, $onem ); |
|
| 289 | + $head = imap_fetchheader($m_mail, $onem); |
|
| 290 | 290 | //$obj = imap_rfc822_parse_headers( $head); |
| 291 | 291 | |
| 292 | - list ($ip,$host,$dateReceived,$dateClient,$mid) = getIP( $head,$cf['mx'],$cf['msalearn'] ); |
|
| 292 | + list ($ip, $host, $dateReceived, $dateClient, $mid) = getIP($head, $cf['mx'], $cf['msalearn']); |
|
| 293 | 293 | if (empty($mid)) { |
| 294 | - $uid='NA'; |
|
| 295 | - syslog (LOG_ERR, $cf['user'].": Error retrieving data for empty Message-ID."); |
|
| 296 | - } else { |
|
| 294 | + $uid = 'NA'; |
|
| 295 | + syslog(LOG_ERR, $cf['user'].": Error retrieving data for empty Message-ID."); |
|
| 296 | + }else { |
|
| 297 | 297 | if ($dateReceived === FALSE) { |
| 298 | - $uid='unauthenticated'; |
|
| 299 | - syslog (LOG_ERR, $cf['user'].": Error retrieving date for $mid. Maybe this mail was not submitted to Learner MSA"); |
|
| 300 | - } else |
|
| 301 | - if ( !($uid = splunksearch ($splunkconn, trim($mid,'<>'), $dateReceived)) ) { |
|
| 302 | - syslog (LOG_ERR, $cf['user'].": Error retrieving uid from Splunk log for $mid."); |
|
| 303 | - $uid='unknown'; |
|
| 298 | + $uid = 'unauthenticated'; |
|
| 299 | + syslog(LOG_ERR, $cf['user'].": Error retrieving date for $mid. Maybe this mail was not submitted to Learner MSA"); |
|
| 300 | + }else |
|
| 301 | + if (!($uid = splunksearch($splunkconn, trim($mid, '<>'), $dateReceived))) { |
|
| 302 | + syslog(LOG_ERR, $cf['user'].": Error retrieving uid from Splunk log for $mid."); |
|
| 303 | + $uid = 'unknown'; |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /* Update count of each ip */ |
| 308 | - if ($host and ($uid!='NA') and ($uid!='unauthenticated') and ($uid!='unknown')) { /* IP is received by MX servers and learned by valid uid */ |
|
| 309 | - $ipuid['count']++; //number of right messages |
|
| 308 | + if ($host and ($uid != 'NA') and ($uid != 'unauthenticated') and ($uid != 'unknown')) { /* IP is received by MX servers and learned by valid uid */ |
|
| 309 | + $ipuid['count']++; //number of right messages |
|
| 310 | 310 | |
| 311 | - if (in_array($uid,array_keys($ipuid['uid']))) { |
|
| 312 | - $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
|
| 313 | - if (!in_array($ip,$ipuid['uid']["$uid"])) |
|
| 314 | - $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid |
|
| 311 | + if (in_array($uid, array_keys($ipuid['uid']))) { |
|
| 312 | + $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
|
| 313 | + if (!in_array($ip, $ipuid['uid']["$uid"])) |
|
| 314 | + $ipuid['uid']["$uid"][] = $ip; //ips learned by this uid |
|
| 315 | 315 | } |
| 316 | 316 | else { |
| 317 | 317 | $ipuid['uid']["$uid"]['count'] = 1; |
| 318 | - $ipuid['uid']["$uid"][]=$ip; |
|
| 319 | - $ipuid['uid']['count']++; //number of unique uids |
|
| 318 | + $ipuid['uid']["$uid"][] = $ip; |
|
| 319 | + $ipuid['uid']['count']++; //number of unique uids |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if (in_array($ip,array_keys($ipuid['ip']))) { |
|
| 323 | - $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
|
| 324 | - if (!in_array($uid,$ipuid['ip']["$ip"])) |
|
| 325 | - $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip |
|
| 322 | + if (in_array($ip, array_keys($ipuid['ip']))) { |
|
| 323 | + $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
|
| 324 | + if (!in_array($uid, $ipuid['ip']["$ip"])) |
|
| 325 | + $ipuid['ip']["$ip"][] = $uid; //uids that learned this ip |
|
| 326 | 326 | } |
| 327 | 327 | else { |
| 328 | 328 | $ipuid['ip']["$ip"]['count'] = 1; |
| 329 | - $ipuid['ip']["$ip"][]=$uid; |
|
| 330 | - $ipuid['ip']['count']++; //number of unique ips |
|
| 329 | + $ipuid['ip']["$ip"][] = $uid; |
|
| 330 | + $ipuid['ip']['count']++; //number of unique ips |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /* Update HTML report */ |
| 334 | - fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
|
| 334 | + fwrite($fp, updateReport($ip, $uid, $ipuid['ip']["$ip"]['count'], $ipuid['uid']["$uid"]['count'], $host, $dateClient, $mid, $dateReceived)); |
|
| 335 | 335 | } |
| 336 | 336 | else { /* Bad learn */ |
| 337 | 337 | |
| 338 | - if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 339 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 338 | + if (in_array($uid, array_keys($uidbad['uid']))) |
|
| 339 | + $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 340 | 340 | else { |
| 341 | 341 | $uidbad['uid']["$uid"]['count'] = 1; |
| 342 | - $uidbad['uid']["$uid"][]=$uid; |
|
| 343 | - $uidbad['count']++; //numeber of unique bad uids |
|
| 342 | + $uidbad['uid']["$uid"][] = $uid; |
|
| 343 | + $uidbad['count']++; //numeber of unique bad uids |
|
| 344 | 344 | } |
| 345 | 345 | /* The reason of bad report */ |
| 346 | 346 | if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; |
| 347 | 347 | if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; |
| 348 | - if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log'; |
|
| 348 | + if ($uid == 'unknown') $reason = 'The uid of this mail was not found in splunk log'; |
|
| 349 | 349 | if (!isset($reason)) $reason = '?'; |
| 350 | 350 | |
| 351 | - fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) ); |
|
| 351 | + fwrite($fpb, updatebadReport($uid, $dateClient, $mid, $dateReceived, $reason)); |
|
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
@@ -356,45 +356,45 @@ discard block |
||
| 356 | 356 | //close report file and mailbox |
| 357 | 357 | |
| 358 | 358 | /* Summary Report */ |
| 359 | - $ipuid['ip'] = array_msort( $ipuid['ip'], array('count'=>SORT_DESC) ); |
|
| 360 | - $ipuid['uid'] = array_msort( $ipuid['uid'], array('count'=>SORT_DESC) ); |
|
| 361 | - $uidbad['uid'] = array_msort( $uidbad['uid'], array('count'=>SORT_DESC) ); |
|
| 359 | + $ipuid['ip'] = array_msort($ipuid['ip'], array('count'=>SORT_DESC)); |
|
| 360 | + $ipuid['uid'] = array_msort($ipuid['uid'], array('count'=>SORT_DESC)); |
|
| 361 | + $uidbad['uid'] = array_msort($uidbad['uid'], array('count'=>SORT_DESC)); |
|
| 362 | 362 | |
| 363 | 363 | fwrite($fp, '</table>'); |
| 364 | - fwrite($fp, '<hr><h2>Summary Report</h2><h5>Listing policy: ip must be learned at least '.$cf['thresholdip']["$type"].' times from at least '.$cf['thresholduid']["$type"].' different valid uids.</h5>' ); |
|
| 364 | + fwrite($fp, '<hr><h2>Summary Report</h2><h5>Listing policy: ip must be learned at least '.$cf['thresholdip']["$type"].' times from at least '.$cf['thresholduid']["$type"].' different valid uids.</h5>'); |
|
| 365 | 365 | |
| 366 | 366 | /* Make MYSQL connection */ |
| 367 | - if ( $cf['onlyReport'] ) |
|
| 367 | + if ($cf['onlyReport']) |
|
| 368 | 368 | $mysqli = NULL; |
| 369 | 369 | else { |
| 370 | 370 | $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
| 371 | 371 | if ($mysqli->connect_error) { |
| 372 | - syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
|
| 372 | + syslog(LOG_EMERG, $cf['user'].': Connect Error ('.$mysqli->connect_errno.') ' |
|
| 373 | 373 | . $mysqli->connect_error); |
| 374 | 374 | exit (254); |
| 375 | 375 | } |
| 376 | - syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to ' . $mysqli->host_info) ; |
|
| 376 | + syslog(LOG_INFO, $cf['user'].': Successfully mysql connected to '.$mysqli->host_info); |
|
| 377 | 377 | } |
| 378 | 378 | /***********************/ |
| 379 | 379 | |
| 380 | - fwrite($fp, summaryReportAndList ($cf,$mysqli,$tables,$type,$ipuid) ); |
|
| 381 | - if ( !$cf['onlyReport'] ) |
|
| 380 | + fwrite($fp, summaryReportAndList($cf, $mysqli, $tables, $type, $ipuid)); |
|
| 381 | + if (!$cf['onlyReport']) |
|
| 382 | 382 | $mysqli->close(); |
| 383 | - fwrite($fp,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateFooter'])); |
|
| 383 | + fwrite($fp, file_get_contents(dirname(__FILE__).'/'.$cf['reportTemplateFooter'])); |
|
| 384 | 384 | fclose($fp); |
| 385 | 385 | |
| 386 | 386 | fwrite($fpb, '</table>'); |
| 387 | - fwrite( $fpb,summaryBadReport( $uidbad ) ); |
|
| 388 | - fwrite($fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateFooter'])); |
|
| 387 | + fwrite($fpb, summaryBadReport($uidbad)); |
|
| 388 | + fwrite($fpb, file_get_contents(dirname(__FILE__).'/'.$cf['reportTemplateFooter'])); |
|
| 389 | 389 | fclose($fpb); |
| 390 | - syslog (LOG_INFO,$cf['user'].': Report files written. Listing job for '.$type.' terminated.'); |
|
| 391 | - |
|
| 392 | - if ( $ierr = imap_errors() ) |
|
| 393 | - foreach ( $ierr as $thiserr ) |
|
| 394 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 395 | - if ( $ierr = imap_alerts() ) |
|
| 396 | - foreach ( $ierr as $thiserr ) |
|
| 397 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 390 | + syslog(LOG_INFO, $cf['user'].': Report files written. Listing job for '.$type.' terminated.'); |
|
| 391 | + |
|
| 392 | + if ($ierr = imap_errors()) |
|
| 393 | + foreach ($ierr as $thiserr) |
|
| 394 | + syslog(LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 395 | + if ($ierr = imap_alerts()) |
|
| 396 | + foreach ($ierr as $thiserr) |
|
| 397 | + syslog(LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 398 | 398 | imap_close($m_mail); |
| 399 | 399 | } |
| 400 | 400 | ?> |
@@ -10,21 +10,25 @@ discard block |
||
| 10 | 10 | if ( preg_match_all('/^Received:\sfrom(?:.|\r\n\s)*?[\[\(]\s*(?P<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})[\]\)](?:.|\r\n\s)+\s+by(?:\s|\r\n\s+)(?P<host>\S+).*(?:\s|\r\n\s\s)+.*;\s+(?P<date>.*)/m',$header,$received) ) { |
| 11 | 11 | for ($i = count($received[0])-1;$i>=0;$i--) { |
| 12 | 12 | # print "Examine ".$received[0][$i]."\n"; |
| 13 | - if ( preg_match($msa,$received['host'][$i]) ) |
|
| 14 | - $dateR = $received['date'][$i]; |
|
| 13 | + if ( preg_match($msa,$received['host'][$i]) ) { |
|
| 14 | + $dateR = $received['date'][$i]; |
|
| 15 | + } |
|
| 15 | 16 | foreach ($mxserver as $mx) { |
| 16 | - if (!$ip) |
|
| 17 | - if ($mx == $received['host'][$i]) { |
|
| 17 | + if (!$ip) { |
|
| 18 | + if ($mx == $received['host'][$i]) { |
|
| 18 | 19 | $host = $received['host'][$i]; |
| 20 | + } |
|
| 19 | 21 | $ip = $received['ip'][$i]; |
| 20 | 22 | } |
| 21 | 23 | } |
| 22 | 24 | } |
| 23 | 25 | } |
| 24 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) |
|
| 25 | - $dateC['date'] = 'Not found'; |
|
| 26 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) |
|
| 27 | - $mid['mid'] = NULL; |
|
| 26 | + if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$dateC) != 1) { |
|
| 27 | + $dateC['date'] = 'Not found'; |
|
| 28 | + } |
|
| 29 | + if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$mid) != 1) { |
|
| 30 | + $mid['mid'] = NULL; |
|
| 31 | + } |
|
| 28 | 32 | return array($ip,$host,$dateR,$dateC['date'],$mid['mid']); |
| 29 | 33 | } |
| 30 | 34 | |
@@ -40,7 +44,9 @@ discard block |
||
| 40 | 44 | |
| 41 | 45 | function summaryBadReport ($uidvet) { |
| 42 | 46 | $nuid = $uidvet['count']; |
| 43 | - if ( empty($uidvet) ) return NULL; |
|
| 47 | + if ( empty($uidvet) ) { |
|
| 48 | + return NULL; |
|
| 49 | + } |
|
| 44 | 50 | $return = '<hr><h3>Statistics by UID</h3><table><tr><th>UID</th><th>Learned times</th></tr>'."\n"; |
| 45 | 51 | |
| 46 | 52 | /* Remove count index */ |
@@ -75,8 +81,12 @@ discard block |
||
| 75 | 81 | foreach ($colarr as $col => $arr) { |
| 76 | 82 | foreach ($arr as $k => $v) { |
| 77 | 83 | $k = substr($k,1); |
| 78 | - if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
|
| 79 | - if (isset ($array[$k][$col])) $ret[$k][$col] = $array[$k][$col]; |
|
| 84 | + if (!isset($ret[$k])) { |
|
| 85 | + $ret[$k] = $array[$k]; |
|
| 86 | + } |
|
| 87 | + if (isset ($array[$k][$col])) { |
|
| 88 | + $ret[$k][$col] = $array[$k][$col]; |
|
| 89 | + } |
|
| 80 | 90 | } |
| 81 | 91 | } |
| 82 | 92 | return $ret; |
@@ -87,13 +97,17 @@ discard block |
||
| 87 | 97 | function summaryReportAndList ($cf,$myconn,$tables,$category,$ipvet) { |
| 88 | 98 | $nips = $ipvet['count']; |
| 89 | 99 | |
| 90 | - if ( empty($ipvet) ) return NULL; |
|
| 100 | + if ( empty($ipvet) ) { |
|
| 101 | + return NULL; |
|
| 102 | + } |
|
| 91 | 103 | $return = '<h3>Statistics by IP</h3><table><tr><th>IP</th><th>Learned by</th><th>Learned times</th><th title="This field doesn\'t say if this ip is currently listed, but it says if this IP has listed now!">Listed Now</th></tr>'."\n"; |
| 92 | 104 | |
| 93 | 105 | $ips = array_keys($ipvet['ip']); |
| 94 | 106 | |
| 95 | 107 | foreach ( $ips as $ip ) { |
| 96 | - if ( $ip == 'count' ) continue; |
|
| 108 | + if ( $ip == 'count' ) { |
|
| 109 | + continue; |
|
| 110 | + } |
|
| 97 | 111 | $nlearn = $ipvet['ip']["$ip"]['count']; |
| 98 | 112 | unset($ipvet['ip']["$ip"]['count']); |
| 99 | 113 | $quantity = $cf['quantity']["$category"]; /* In searchAndList this value is passed by reference and modified */ |
@@ -102,10 +116,12 @@ discard block |
||
| 102 | 116 | if ( ($nlearn >= $cf['thresholdip']["$category"])&&($nuid >= $cf['thresholduid']["$category"]) ) { |
| 103 | 117 | $reason = "The IP <$ip> has been listed because was marked $nlearn times as $category by $nuid different accounts during last ".$cf['oldestday'].' days.'; |
| 104 | 118 | $listed = searchAndList ($myconn,$cf['user'],$tables,$cf['list']["$category"],$ip,$cf['unit']["$category"],$quantity,$reason); |
| 119 | + } else { |
|
| 120 | + $listed = FALSE; |
|
| 105 | 121 | } |
| 106 | - else $listed = FALSE; |
|
| 122 | + } else { |
|
| 123 | + $listed = FALSE; |
|
| 107 | 124 | } |
| 108 | - else $listed = FALSE; |
|
| 109 | 125 | $nowlist = array( TRUE => array( |
| 110 | 126 | 'style' => 'id=\'ipfound\'', |
| 111 | 127 | 'name' => 'YES', |
@@ -123,7 +139,9 @@ discard block |
||
| 123 | 139 | $return .='<tr><td rowspan="'.$nuid.'">'.$ip.'</td>'; |
| 124 | 140 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nuid.'">%u</td><td rowspan="'.$nuid.'" '.$nowlist["$listed"]['style'].'>%s</td></tr>',$ipvet['ip']["$ip"][0],$nlearn,$nowlist["$listed"]['name']); |
| 125 | 141 | $rowuid=NULL; |
| 126 | - for ($j=1;$j<$nuid;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 142 | + for ($j=1;$j<$nuid;$j++) { |
|
| 143 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 144 | + } |
|
| 127 | 145 | array_shift($ipvet['ip']["$ip"]); |
| 128 | 146 | $return .= vsprintf ($rowuid,$ipvet['ip']["$ip"]); |
| 129 | 147 | |
@@ -136,14 +154,18 @@ discard block |
||
| 136 | 154 | $return .= '<h3>Statistics by UID</h3><table><tr><th>UID</th><th>IP learned</th><th>Learned times</th></tr>'."\n"; |
| 137 | 155 | $uids = array_keys($ipvet['uid']); |
| 138 | 156 | foreach ( $uids as $uid ) { |
| 139 | - if ( $uid == 'count' ) continue; |
|
| 157 | + if ( $uid == 'count' ) { |
|
| 158 | + continue; |
|
| 159 | + } |
|
| 140 | 160 | $nlearn = $ipvet['uid']["$uid"]['count']; |
| 141 | 161 | unset ( $ipvet['uid']["$uid"]['count'] ); |
| 142 | 162 | $nip = count($ipvet['uid']["$uid"]); |
| 143 | 163 | $return .='<tr><td rowspan="'.$nip.'">'.$uid.'</td>'; |
| 144 | 164 | $return .= sprintf ('<td>%s</td><td rowspan="'.$nip.'">%u</td></tr>',$ipvet['uid']["$uid"][0],$nlearn); |
| 145 | 165 | $rowuid=NULL; |
| 146 | - for ($j=1;$j<$nip;$j++) $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 166 | + for ($j=1;$j<$nip;$j++) { |
|
| 167 | + $rowuid .= '<tr><td>%s</td></tr>'; |
|
| 168 | + } |
|
| 147 | 169 | array_shift($ipvet['uid']["$uid"]); |
| 148 | 170 | $return .= vsprintf ($rowuid,$ipvet['uid']["$uid"]); |
| 149 | 171 | |
@@ -192,14 +214,14 @@ discard block |
||
| 192 | 214 | { |
| 193 | 215 | // More than one field attribute returned by search |
| 194 | 216 | // You must redefine the search |
| 195 | - if ( count($result->getFieldNames()) > 1 ) return FALSE; |
|
| 196 | - } |
|
| 197 | - else if ($result instanceof Splunk_ResultsMessage) |
|
| 217 | + if ( count($result->getFieldNames()) > 1 ) { |
|
| 218 | + return FALSE; |
|
| 219 | + } |
|
| 220 | + } else if ($result instanceof Splunk_ResultsMessage) |
|
| 198 | 221 | { |
| 199 | 222 | // I don't want messages in my search |
| 200 | 223 | return FALSE; |
| 201 | - } |
|
| 202 | - else if (is_array($result)) |
|
| 224 | + } else if (is_array($result)) |
|
| 203 | 225 | { |
| 204 | 226 | // Process a row |
| 205 | 227 | foreach ($result as $key => $valueOrValues) |
@@ -207,15 +229,13 @@ discard block |
||
| 207 | 229 | if (is_array($valueOrValues)) |
| 208 | 230 | { |
| 209 | 231 | return FALSE; |
| 210 | - } |
|
| 211 | - else |
|
| 232 | + } else |
|
| 212 | 233 | { |
| 213 | 234 | return $valueOrValues; |
| 214 | 235 | #print " {$key} => {$value}\r\n"; |
| 215 | 236 | } |
| 216 | 237 | } |
| 217 | - } |
|
| 218 | - else |
|
| 238 | + } else |
|
| 219 | 239 | { |
| 220 | 240 | #print "Unknow result type"; |
| 221 | 241 | return FALSE; |
@@ -229,7 +249,9 @@ discard block |
||
| 229 | 249 | $fileb= dirname(__FILE__) . '/' . $cf['badreportFile']["$type"]; |
| 230 | 250 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$cf['folder']["$type"], $cf['account'],$cf['authpassword'], OP_READONLY) |
| 231 | 251 | or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
| 232 | - if ( !$m_mail ) exit(254); |
|
| 252 | + if ( !$m_mail ) { |
|
| 253 | + exit(254); |
|
| 254 | + } |
|
| 233 | 255 | |
| 234 | 256 | |
| 235 | 257 | syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading $type messages of last ".$cf['oldestday'].' days...'); |
@@ -242,20 +264,28 @@ discard block |
||
| 242 | 264 | // Order results starting from newest message |
| 243 | 265 | if ( empty($m_search) ) { |
| 244 | 266 | syslog (LOG_INFO,$cf['user'].": No mail found in $type folder. No reports written for $type."); |
| 245 | - if ( $ierr = imap_errors() ) |
|
| 246 | - foreach ( $ierr as $thiserr ) |
|
| 267 | + if ( $ierr = imap_errors() ) { |
|
| 268 | + foreach ( $ierr as $thiserr ) |
|
| 247 | 269 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
| 248 | - if ( $ierr = imap_alerts() ) |
|
| 249 | - foreach ( $ierr as $thiserr ) |
|
| 270 | + } |
|
| 271 | + if ( $ierr = imap_alerts() ) { |
|
| 272 | + foreach ( $ierr as $thiserr ) |
|
| 250 | 273 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
| 274 | + } |
|
| 251 | 275 | imap_close( $m_mail ); |
| 252 | - if ( file_exists( $file ) ) unlink ($file); |
|
| 253 | - if ( file_exists( $fileb ) ) unlink ($fileb); |
|
| 276 | + if ( file_exists( $file ) ) { |
|
| 277 | + unlink ($file); |
|
| 278 | + } |
|
| 279 | + if ( file_exists( $fileb ) ) { |
|
| 280 | + unlink ($fileb); |
|
| 281 | + } |
|
| 254 | 282 | return FALSE; |
| 255 | 283 | } |
| 256 | 284 | $nmes = count ($m_search); |
| 257 | 285 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in $type folder."); |
| 258 | - if ($nmes>0) rsort($m_search); |
|
| 286 | + if ($nmes>0) { |
|
| 287 | + rsort($m_search); |
|
| 288 | + } |
|
| 259 | 289 | |
| 260 | 290 | // Create report file |
| 261 | 291 | |
@@ -264,7 +294,9 @@ discard block |
||
| 264 | 294 | $lastup = "Last Update: " . date ("d F Y H:i", time()); |
| 265 | 295 | fwrite( $fp, file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
| 266 | 296 | fwrite( $fp,"<h1> Report of IP sending $type</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
| 267 | - if ($cf['onlyReport']) fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
| 297 | + if ($cf['onlyReport']) { |
|
| 298 | + fwrite( $fp,'<p>None of the below IP has been listed because listing is not active in configuration.</p>'); |
|
| 299 | + } |
|
| 268 | 300 | fwrite( $fp,'<table><tr><th title="taken from Received header" nowrap>Date of Learn</th><th title="taken from Date header" nowrap>Date of Write</th><th nowrap>UID</th><th nowrap>IP</th><th title="How many times this uid learns">#UID</th><th title="Number of times this learned IP appears in different mails">#IP</th><th nowrap>Received by</th><th>Message-Id</th></tr>' ); |
| 269 | 301 | fwrite( $fpb,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateHeader']) ); |
| 270 | 302 | fwrite( $fpb,"<h1> Report of bad reported $type mails</h1><h5>$lastup</h5><h2>Detailed Report</h2>" ); |
@@ -310,10 +342,11 @@ discard block |
||
| 310 | 342 | |
| 311 | 343 | if (in_array($uid,array_keys($ipuid['uid']))) { |
| 312 | 344 | $ipuid['uid']["$uid"]['count']++; //number of learn by this uid |
| 313 | - if (!in_array($ip,$ipuid['uid']["$uid"])) |
|
| 314 | - $ipuid['uid']["$uid"][]=$ip; //ips learned by this uid |
|
| 315 | - } |
|
| 316 | - else { |
|
| 345 | + if (!in_array($ip,$ipuid['uid']["$uid"])) { |
|
| 346 | + $ipuid['uid']["$uid"][]=$ip; |
|
| 347 | + } |
|
| 348 | + //ips learned by this uid |
|
| 349 | + } else { |
|
| 317 | 350 | $ipuid['uid']["$uid"]['count'] = 1; |
| 318 | 351 | $ipuid['uid']["$uid"][]=$ip; |
| 319 | 352 | $ipuid['uid']['count']++; //number of unique uids |
@@ -321,10 +354,11 @@ discard block |
||
| 321 | 354 | |
| 322 | 355 | if (in_array($ip,array_keys($ipuid['ip']))) { |
| 323 | 356 | $ipuid['ip']["$ip"]['count']++; //number of time this ip appears in different messages |
| 324 | - if (!in_array($uid,$ipuid['ip']["$ip"])) |
|
| 325 | - $ipuid['ip']["$ip"][]=$uid; //uids that learned this ip |
|
| 326 | - } |
|
| 327 | - else { |
|
| 357 | + if (!in_array($uid,$ipuid['ip']["$ip"])) { |
|
| 358 | + $ipuid['ip']["$ip"][]=$uid; |
|
| 359 | + } |
|
| 360 | + //uids that learned this ip |
|
| 361 | + } else { |
|
| 328 | 362 | $ipuid['ip']["$ip"]['count'] = 1; |
| 329 | 363 | $ipuid['ip']["$ip"][]=$uid; |
| 330 | 364 | $ipuid['ip']['count']++; //number of unique ips |
@@ -332,21 +366,30 @@ discard block |
||
| 332 | 366 | |
| 333 | 367 | /* Update HTML report */ |
| 334 | 368 | fwrite($fp,updateReport ( $ip,$uid,$ipuid['ip']["$ip"]['count'],$ipuid['uid']["$uid"]['count'],$host,$dateClient,$mid,$dateReceived) ); |
| 335 | - } |
|
| 336 | - else { /* Bad learn */ |
|
| 369 | + } else { /* Bad learn */ |
|
| 337 | 370 | |
| 338 | - if (in_array($uid,array_keys($uidbad['uid']))) |
|
| 339 | - $uidbad['uid']["$uid"]['count']++; //number of bad learn by this uid |
|
| 371 | + if (in_array($uid,array_keys($uidbad['uid']))) { |
|
| 372 | + $uidbad['uid']["$uid"]['count']++; |
|
| 373 | + } |
|
| 374 | + //number of bad learn by this uid |
|
| 340 | 375 | else { |
| 341 | 376 | $uidbad['uid']["$uid"]['count'] = 1; |
| 342 | 377 | $uidbad['uid']["$uid"][]=$uid; |
| 343 | 378 | $uidbad['count']++; //numeber of unique bad uids |
| 344 | 379 | } |
| 345 | 380 | /* The reason of bad report */ |
| 346 | - if ($host === FALSE) $reason = 'This mail was not received by recognized MX host'; |
|
| 347 | - if ($dateReceived === FALSE) $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
| 348 | - if ($uid=='unknown') $reason = 'The uid of this mail was not found in splunk log'; |
|
| 349 | - if (!isset($reason)) $reason = '?'; |
|
| 381 | + if ($host === FALSE) { |
|
| 382 | + $reason = 'This mail was not received by recognized MX host'; |
|
| 383 | + } |
|
| 384 | + if ($dateReceived === FALSE) { |
|
| 385 | + $reason = 'This mail was not submitted to recognized MSA for learn'; |
|
| 386 | + } |
|
| 387 | + if ($uid=='unknown') { |
|
| 388 | + $reason = 'The uid of this mail was not found in splunk log'; |
|
| 389 | + } |
|
| 390 | + if (!isset($reason)) { |
|
| 391 | + $reason = '?'; |
|
| 392 | + } |
|
| 350 | 393 | |
| 351 | 394 | fwrite( $fpb,updatebadReport ( $uid,$dateClient,$mid,$dateReceived,$reason ) ); |
| 352 | 395 | } |
@@ -364,9 +407,9 @@ discard block |
||
| 364 | 407 | fwrite($fp, '<hr><h2>Summary Report</h2><h5>Listing policy: ip must be learned at least '.$cf['thresholdip']["$type"].' times from at least '.$cf['thresholduid']["$type"].' different valid uids.</h5>' ); |
| 365 | 408 | |
| 366 | 409 | /* Make MYSQL connection */ |
| 367 | - if ( $cf['onlyReport'] ) |
|
| 368 | - $mysqli = NULL; |
|
| 369 | - else { |
|
| 410 | + if ( $cf['onlyReport'] ) { |
|
| 411 | + $mysqli = NULL; |
|
| 412 | + } else { |
|
| 370 | 413 | $mysqli = new mysqli($myconnArray['dbhost'], $myconnArray['userdb'], $myconnArray['pwd'], $myconnArray['db'], $myconnArray['dbport']); |
| 371 | 414 | if ($mysqli->connect_error) { |
| 372 | 415 | syslog (LOG_EMERG, $cf['user'].': Connect Error (' . $mysqli->connect_errno . ') ' |
@@ -378,8 +421,9 @@ discard block |
||
| 378 | 421 | /***********************/ |
| 379 | 422 | |
| 380 | 423 | fwrite($fp, summaryReportAndList ($cf,$mysqli,$tables,$type,$ipuid) ); |
| 381 | - if ( !$cf['onlyReport'] ) |
|
| 382 | - $mysqli->close(); |
|
| 424 | + if ( !$cf['onlyReport'] ) { |
|
| 425 | + $mysqli->close(); |
|
| 426 | + } |
|
| 383 | 427 | fwrite($fp,file_get_contents(dirname(__FILE__) . '/' . $cf['reportTemplateFooter'])); |
| 384 | 428 | fclose($fp); |
| 385 | 429 | |
@@ -389,12 +433,14 @@ discard block |
||
| 389 | 433 | fclose($fpb); |
| 390 | 434 | syslog (LOG_INFO,$cf['user'].': Report files written. Listing job for '.$type.' terminated.'); |
| 391 | 435 | |
| 392 | - if ( $ierr = imap_errors() ) |
|
| 393 | - foreach ( $ierr as $thiserr ) |
|
| 436 | + if ( $ierr = imap_errors() ) { |
|
| 437 | + foreach ( $ierr as $thiserr ) |
|
| 394 | 438 | syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
| 395 | - if ( $ierr = imap_alerts() ) |
|
| 396 | - foreach ( $ierr as $thiserr ) |
|
| 439 | + } |
|
| 440 | + if ( $ierr = imap_alerts() ) { |
|
| 441 | + foreach ( $ierr as $thiserr ) |
|
| 397 | 442 | syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
| 443 | + } |
|
| 398 | 444 | imap_close($m_mail); |
| 399 | 445 | } |
| 400 | 446 | ?> |
@@ -226,6 +226,9 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
| 229 | +/** |
|
| 230 | + * @param integer $id |
|
| 231 | + */ |
|
| 229 | 232 | function askMilter($myconn,$id,$obj,$typedesc,$miltId,$value,$user,$adm) { |
| 230 | 233 | $milts = readMiltName($myconn,$user); |
| 231 | 234 | $size = count($milts); |
@@ -256,6 +259,11 @@ discard block |
||
| 256 | 259 | } |
| 257 | 260 | |
| 258 | 261 | |
| 262 | +/** |
|
| 263 | + * @param integer $id |
|
| 264 | + * @param string $what |
|
| 265 | + * @param boolean $lock |
|
| 266 | + */ |
|
| 259 | 267 | function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { |
| 260 | 268 | |
| 261 | 269 | $whynot=NULL; |
@@ -514,6 +522,9 @@ discard block |
||
| 514 | 522 | } |
| 515 | 523 | |
| 516 | 524 | |
| 525 | +/** |
|
| 526 | + * @param string $reason |
|
| 527 | + */ |
|
| 517 | 528 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
| 518 | 529 | |
| 519 | 530 | /* Search and list value */ |
@@ -580,6 +591,9 @@ discard block |
||
| 580 | 591 | return array_map('long2ip', range( ip2long($range[0]), ip2long($range[1]) ) ); |
| 581 | 592 | } |
| 582 | 593 | |
| 594 | +/** |
|
| 595 | + * @param string $netA |
|
| 596 | + */ |
|
| 583 | 597 | function isIn($netA, $netB) { |
| 584 | 598 | /* TRUE if an IP of $netA is contained in netB */ |
| 585 | 599 | list($addressA,$maskA) = explode('/', $netA); |
@@ -4,18 +4,18 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | function username() { |
| 6 | 6 | if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
| 7 | - else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | - else $user='unknown'; |
|
| 7 | + else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | + else $user='unknown'; |
|
| 9 | 9 | return $user; |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) { |
| 14 | - $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
| 14 | + $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
| 15 | 15 | $mysqli = new mysqli($host, $user, $pass, $db, $port); |
| 16 | - if ($mysqli->connect_error) { |
|
| 17 | - syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
| 18 | - . $mysqli->connect_error); |
|
| 16 | + if ($mysqli->connect_error) { |
|
| 17 | + syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
| 18 | + . $mysqli->connect_error); |
|
| 19 | 19 | return FALSE; |
| 20 | 20 | } |
| 21 | 21 | syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | list($sub['net'],$sub['mask'])=explode('/',$value); |
| 59 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 59 | + $query= sprintf("INSERT INTO `$table` ( |
|
| 60 | 60 | `$type` , |
| 61 | 61 | `netmask`, |
| 62 | 62 | `date` , |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
| 70 | 70 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 71 | 71 | )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
| 72 | - break; |
|
| 72 | + break; |
|
| 73 | 73 | |
| 74 | 74 | default: |
| 75 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 75 | + $query= sprintf("INSERT INTO `$table` ( |
|
| 76 | 76 | `$type` , |
| 77 | 77 | `date` , |
| 78 | 78 | `exp` , |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | if ($myconn->query($query) === TRUE) { |
| 90 | - syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
| 91 | - $result=TRUE; |
|
| 90 | + syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
|
| 91 | + $result=TRUE; |
|
| 92 | 92 | } |
| 93 | 93 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
| 94 | 94 | return $result; |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | $result=FALSE; |
| 100 | 100 | |
| 101 | - switch ($type) { |
|
| 101 | + switch ($type) { |
|
| 102 | 102 | case 'ip': |
| 103 | - $query= sprintf("UPDATE `$table` SET |
|
| 103 | + $query= sprintf("UPDATE `$table` SET |
|
| 104 | 104 | `active` = '1', |
| 105 | 105 | `user` = '%s', |
| 106 | 106 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | `reason` = '%s' |
| 109 | 109 | WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
| 110 | 110 | break; |
| 111 | - case 'network': |
|
| 111 | + case 'network': |
|
| 112 | 112 | list($sub['net'],$sub['mask'])=explode('/',$value); |
| 113 | - $query= sprintf("UPDATE `$table` SET |
|
| 113 | + $query= sprintf("UPDATE `$table` SET |
|
| 114 | 114 | `active` = '1', |
| 115 | 115 | `user` = '%s', |
| 116 | 116 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']); |
| 120 | 120 | break; |
| 121 | 121 | default: |
| 122 | - $query= sprintf("UPDATE `$table` SET |
|
| 122 | + $query= sprintf("UPDATE `$table` SET |
|
| 123 | 123 | `active` = '1', |
| 124 | 124 | `user` = '%s', |
| 125 | 125 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
@@ -128,18 +128,18 @@ discard block |
||
| 128 | 128 | WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if ($myconn->query($query) === TRUE) { |
|
| 132 | - syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
|
| 131 | + if ($myconn->query($query) === TRUE) { |
|
| 132 | + syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
|
| 133 | 133 | $result=TRUE; |
| 134 | - } |
|
| 135 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 134 | + } |
|
| 135 | + else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 136 | 136 | return $result; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | function remove ($myconn,$user,$value,$type,$table) { |
| 140 | 140 | |
| 141 | - switch ($type) { |
|
| 142 | - case 'ip': |
|
| 141 | + switch ($type) { |
|
| 142 | + case 'ip': |
|
| 143 | 143 | $query = sprintf("DELETE FROM `$table` WHERE |
| 144 | 144 | `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); |
| 145 | 145 | break; |
@@ -155,18 +155,18 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
| 158 | - if ($return=$myconn->query($query) === TRUE) |
|
| 159 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 160 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 158 | + if ($return=$myconn->query($query) === TRUE) |
|
| 159 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 160 | + else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 161 | 161 | |
| 162 | - return $return; |
|
| 162 | + return $return; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
| 166 | 166 | function changestatus ($myconn,$user,$value,$status,$type,$table) { |
| 167 | 167 | |
| 168 | 168 | switch ($type) { |
| 169 | - case 'ip': |
|
| 169 | + case 'ip': |
|
| 170 | 170 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); |
| 171 | 171 | break; |
| 172 | 172 | case 'network': |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if ($return=$myconn->query($query) === TRUE) { |
|
| 181 | - syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
| 182 | - } |
|
| 183 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 180 | + if ($return=$myconn->query($query) === TRUE) { |
|
| 181 | + syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
|
| 182 | + } |
|
| 183 | + else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 184 | 184 | return $return; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
| 188 | 188 | function expire ($myconn,$user,$tables,$expireTime) { |
| 189 | - $return=TRUE; |
|
| 189 | + $return=TRUE; |
|
| 190 | 190 | $log=array(); |
| 191 | 191 | $desc = array_keys($tables); |
| 192 | 192 | foreach ($desc as $tdesc) { |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | /* END OF QUERY */ |
| 197 | 197 | $log[0] = 'expired for'; |
| 198 | 198 | $log[1] = 'disabled for'; |
| 199 | - if ($myconn->multi_query($query)) { |
|
| 199 | + if ($myconn->multi_query($query)) { |
|
| 200 | 200 | $j = 0; |
| 201 | 201 | do { |
| 202 | - $numdel = $myconn->affected_rows; |
|
| 203 | - syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
| 202 | + $numdel = $myconn->affected_rows; |
|
| 203 | + syslog(LOG_INFO, "Expire job - <$user> Permanently DELETED $numdel records ".$log[$j]." $expireTime YEARS from <".$tables["$tdesc"]['name'].'>.'); |
|
| 204 | 204 | $j++; |
| 205 | 205 | |
| 206 | 206 | } while ($myconn->next_result()); |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | } |
| 213 | 213 | if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
| 214 | 214 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
| 215 | - return $return; |
|
| 215 | + return $return; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | if ( $entry->num_rows ) { |
| 286 | 286 | if ( $entry->num_rows == 1 ) { |
| 287 | 287 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
| 288 | - if (isListed($riga)) { |
|
| 288 | + if (isListed($riga)) { |
|
| 289 | 289 | $warn = "<$value> is already present in <$listdep> list!"; |
| 290 | 290 | $entry->free(); |
| 291 | 291 | return FALSE; |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | function searchentry ($myconn,$value,$tablelist) { |
| 303 | 303 | /* Make a MYSQL query and return result */ |
| 304 | 304 | |
| 305 | - $type = $tablelist['field']; |
|
| 305 | + $type = $tablelist['field']; |
|
| 306 | 306 | |
| 307 | 307 | if ( $tablelist['milter'] ) { |
| 308 | 308 | $table = milterTable($type); |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | case 'ip': |
| 327 | 327 | $query = sprintf('SELECT * FROM ( |
| 328 | 328 | SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id)' . |
| 329 | - 'WHERE `ip` = INET_ATON(\'%s\') |
|
| 329 | + 'WHERE `ip` = INET_ATON(\'%s\') |
|
| 330 | 330 | ) AS val WHERE val.ip IS NOT null', $table, $table, $value); |
| 331 | 331 | break; |
| 332 | 332 | default: |
@@ -337,33 +337,33 @@ discard block |
||
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | else { |
| 340 | - $table = $tablelist['name']; |
|
| 341 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 342 | - else { |
|
| 343 | - switch ($type) { |
|
| 344 | - case 'ip': |
|
| 345 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 346 | - break; |
|
| 347 | - case 'network': |
|
| 348 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 349 | - $query= sprintf('select * from `%s` |
|
| 340 | + $table = $tablelist['name']; |
|
| 341 | + if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 342 | + else { |
|
| 343 | + switch ($type) { |
|
| 344 | + case 'ip': |
|
| 345 | + $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 346 | + break; |
|
| 347 | + case 'network': |
|
| 348 | + list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 349 | + $query= sprintf('select * from `%s` |
|
| 350 | 350 | WHERE ( |
| 351 | 351 | inet_aton(\'%s\') >= network AND |
| 352 | 352 | ( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) ) |
| 353 | 353 | <= network | ( netmask ^ (power(2,32)-1) ) |
| 354 | 354 | )', $table, $sub['net'], $sub['net'], $sub['mask']); |
| 355 | 355 | ; |
| 356 | - break; |
|
| 357 | - default: |
|
| 358 | - $query= "select * from $table where $type = '$value'"; |
|
| 359 | - } |
|
| 360 | - } |
|
| 356 | + break; |
|
| 357 | + default: |
|
| 358 | + $query= "select * from $table where $type = '$value'"; |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | $result = $myconn->query($query); |
| 364 | 364 | if($result === false) |
| 365 | 365 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
| 366 | - return $result; |
|
| 366 | + return $result; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | function countListed ($myconn,$table) { |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | |
| 379 | 379 | |
| 380 | 380 | function isFull($myconn,$typedesc,$alltables) { |
| 381 | - if (isset($alltables["$typedesc"]['limit'])) { |
|
| 381 | + if (isset($alltables["$typedesc"]['limit'])) { |
|
| 382 | 382 | if ( $alltables["$typedesc"]['milter'] ) |
| 383 | 383 | $tab = 'net'; |
| 384 | 384 | else |
| 385 | 385 | $tab = $alltables["$typedesc"]['name']; |
| 386 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 387 | - return TRUE; |
|
| 388 | - } |
|
| 386 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 387 | + return TRUE; |
|
| 388 | + } |
|
| 389 | 389 | return FALSE; |
| 390 | 390 | } |
| 391 | 391 | |
@@ -405,14 +405,14 @@ discard block |
||
| 405 | 405 | if ($result) { |
| 406 | 406 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
| 407 | 407 | |
| 408 | - /* Check for limit in number of listed items */ |
|
| 408 | + /* Check for limit in number of listed items */ |
|
| 409 | 409 | $full = isFull($myconn,$typedesc,$tables); |
| 410 | 410 | if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
| 411 | 411 | |
| 412 | 412 | if ($result->num_rows) { |
| 413 | 413 | print $tabhtm; |
| 414 | 414 | $i=0; |
| 415 | - while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 415 | + while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 416 | 416 | if (isListed($riga)) { |
| 417 | 417 | if ($tables["$typedesc"]['bl']) $listed='Listed'; |
| 418 | 418 | else $listed='WhiteListed'; |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | 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", |
| 439 | 439 | $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)); |
| 440 | 440 | $i++; |
| 441 | - } |
|
| 441 | + } |
|
| 442 | 442 | print '</tbody></table>'; |
| 443 | 443 | } |
| 444 | 444 | else { |
@@ -458,15 +458,15 @@ discard block |
||
| 458 | 458 | |
| 459 | 459 | function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
| 460 | 460 | $now = time(); |
| 461 | - setlocale (LC_TIME, 'it_IT'); |
|
| 462 | - $date = date("r",$now); |
|
| 461 | + setlocale (LC_TIME, 'it_IT'); |
|
| 462 | + $date = date("r",$now); |
|
| 463 | 463 | $messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"]; |
| 464 | 464 | $mua = 'PHP/' . phpversion(); |
| 465 | 465 | |
| 466 | 466 | /* Parsing headers */ |
| 467 | 467 | if (!file_exists($tplf['header'])) { |
| 468 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
| 469 | - exit; |
|
| 468 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['header'].'> not found!'); |
|
| 469 | + exit; |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | $head_tmpl = file_get_contents($tplf['header']); |
@@ -475,35 +475,35 @@ discard block |
||
| 475 | 475 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
| 476 | 476 | $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
| 477 | 477 | |
| 478 | - /* Parsing body */ |
|
| 478 | + /* Parsing body */ |
|
| 479 | 479 | |
| 480 | - if (!file_exists($tplf['body'])) { |
|
| 481 | - syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
| 482 | - exit; |
|
| 483 | - } |
|
| 480 | + if (!file_exists($tplf['body'])) { |
|
| 481 | + syslog(LOG_ERR, 'Sending email... template file <'.$tplf['body'].'> not found!'); |
|
| 482 | + exit; |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | - $body_tmpl = file_get_contents($tplf['body']); |
|
| 486 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 487 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 488 | - $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
| 489 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 485 | + $body_tmpl = file_get_contents($tplf['body']); |
|
| 486 | + $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 487 | + $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 488 | + $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
|
| 489 | + $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 490 | 490 | $body = wordwrap ( $body, 75 , "\r\n" ); |
| 491 | 491 | |
| 492 | 492 | /* Send the mail! */ |
| 493 | - if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 494 | - $old_mailfrom = ini_get("sendmail_from"); |
|
| 495 | - ini_set("sendmail_from", $from); |
|
| 496 | - $params = sprintf("-oi -f %s", '<>'); |
|
| 497 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 498 | - else $flag=TRUE; |
|
| 499 | - if (isset($old_mailfrom)) |
|
| 500 | - ini_set("sendmail_from", $old_mailfrom); |
|
| 501 | - } |
|
| 502 | - else { |
|
| 503 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 504 | - else $flag=TRUE; |
|
| 505 | - } |
|
| 506 | - return $flag; |
|
| 493 | + if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 494 | + $old_mailfrom = ini_get("sendmail_from"); |
|
| 495 | + ini_set("sendmail_from", $from); |
|
| 496 | + $params = sprintf("-oi -f %s", '<>'); |
|
| 497 | + if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 498 | + else $flag=TRUE; |
|
| 499 | + if (isset($old_mailfrom)) |
|
| 500 | + ini_set("sendmail_from", $old_mailfrom); |
|
| 501 | + } |
|
| 502 | + else { |
|
| 503 | + if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 504 | + else $flag=TRUE; |
|
| 505 | + } |
|
| 506 | + return $flag; |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | function emailToNotify($notify_file,$dom) { |
@@ -517,59 +517,59 @@ discard block |
||
| 517 | 517 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
| 518 | 518 | |
| 519 | 519 | /* Search and list value */ |
| 520 | - $type = $tables["$typedesc"]['field']; |
|
| 521 | - $table = $tables["$typedesc"]['name']; |
|
| 522 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 523 | - |
|
| 524 | - /* Manage abnormal conditions */ |
|
| 525 | - /* Value already present in db more than once. This is absurd. Panic! */ |
|
| 526 | - if ($result->num_rows > 1) { |
|
| 527 | - syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 528 | - $result->free(); |
|
| 529 | - return FALSE; |
|
| 530 | - } |
|
| 520 | + $type = $tables["$typedesc"]['field']; |
|
| 521 | + $table = $tables["$typedesc"]['name']; |
|
| 522 | + $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 523 | + |
|
| 524 | + /* Manage abnormal conditions */ |
|
| 525 | + /* Value already present in db more than once. This is absurd. Panic! */ |
|
| 526 | + if ($result->num_rows > 1) { |
|
| 527 | + syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 528 | + $result->free(); |
|
| 529 | + return FALSE; |
|
| 530 | + } |
|
| 531 | 531 | |
| 532 | - /* Value already present in db or not present: to list anyway */ |
|
| 533 | - if ($result->num_rows >= 0) { |
|
| 534 | - /* First, check for limit in number of listed items */ |
|
| 535 | - if (isFull($myconn,$typedesc,$tables)) { |
|
| 536 | - syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 537 | - $result->free(); |
|
| 538 | - return FALSE; |
|
| 539 | - } |
|
| 540 | - /* Second, check if the (re)list would be consistent now */ |
|
| 541 | - if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 542 | - syslog(LOG_ERR, $loguser.': '.$whynot); |
|
| 543 | - $result->free(); |
|
| 544 | - return FALSE; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - /* End of abnormal conditions */ |
|
| 532 | + /* Value already present in db or not present: to list anyway */ |
|
| 533 | + if ($result->num_rows >= 0) { |
|
| 534 | + /* First, check for limit in number of listed items */ |
|
| 535 | + if (isFull($myconn,$typedesc,$tables)) { |
|
| 536 | + syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 537 | + $result->free(); |
|
| 538 | + return FALSE; |
|
| 539 | + } |
|
| 540 | + /* Second, check if the (re)list would be consistent now */ |
|
| 541 | + if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 542 | + syslog(LOG_ERR, $loguser.': '.$whynot); |
|
| 543 | + $result->free(); |
|
| 544 | + return FALSE; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + /* End of abnormal conditions */ |
|
| 548 | 548 | |
| 549 | 549 | |
| 550 | - /* Finally, here I can list the value! */ |
|
| 550 | + /* Finally, here I can list the value! */ |
|
| 551 | 551 | $thisentry = $result->fetch_array(MYSQLI_ASSOC); |
| 552 | - switch ($result->num_rows) { |
|
| 553 | - /* Relist value if already present */ |
|
| 554 | - case 1: |
|
| 555 | - /* Entry already listed */ |
|
| 556 | - if ( isListed($thisentry) ) { |
|
| 557 | - syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.'); |
|
| 558 | - $result->free(); |
|
| 559 | - return FALSE; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - /* Entry delisted */ |
|
| 563 | - $result->free(); |
|
| 552 | + switch ($result->num_rows) { |
|
| 553 | + /* Relist value if already present */ |
|
| 554 | + case 1: |
|
| 555 | + /* Entry already listed */ |
|
| 556 | + if ( isListed($thisentry) ) { |
|
| 557 | + syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.'); |
|
| 558 | + $result->free(); |
|
| 559 | + return FALSE; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /* Entry delisted */ |
|
| 563 | + $result->free(); |
|
| 564 | 564 | $quantity *= $thisentry['nlist']; |
| 565 | - return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 565 | + return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 566 | 566 | |
| 567 | 567 | |
| 568 | - /* First time list value */ |
|
| 569 | - case 0: |
|
| 570 | - $result->free(); |
|
| 571 | - return addtolist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 572 | - } |
|
| 568 | + /* First time list value */ |
|
| 569 | + case 0: |
|
| 570 | + $result->free(); |
|
| 571 | + return addtolist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 572 | + } |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | return FALSE; |
| 603 | 603 | } |
| 604 | 604 | $result = searchentry ($myconn,'ALL',$tabletype); |
| 605 | - if ($result->num_rows) { |
|
| 605 | + if ($result->num_rows) { |
|
| 606 | 606 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
| 607 | 607 | $thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']); |
| 608 | 608 | if ( isIn($thisNet, $net) ) { |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | /* For miltermap */ |
| 623 | 623 | function checkMilterConf($table) { |
| 624 | 624 | if (isset($table['milter'])) { |
| 625 | - if ($table['milter'] === TRUE) { |
|
| 625 | + if ($table['milter'] === TRUE) { |
|
| 626 | 626 | switch ( $table['field'] ) { |
| 627 | 627 | case 'network': |
| 628 | 628 | case 'ip': |
@@ -645,15 +645,15 @@ discard block |
||
| 645 | 645 | |
| 646 | 646 | function milterTable($t) { |
| 647 | 647 | /* Return the milter object table for type t or FALSE on error */ |
| 648 | - switch ($t) { |
|
| 649 | - case 'network': |
|
| 650 | - return 'net'; |
|
| 651 | - case 'ip': |
|
| 652 | - return 'ips'; |
|
| 653 | - default: |
|
| 648 | + switch ($t) { |
|
| 649 | + case 'network': |
|
| 650 | + return 'net'; |
|
| 651 | + case 'ip': |
|
| 652 | + return 'ips'; |
|
| 653 | + default: |
|
| 654 | 654 | syslog(LOG_EMERG, "ALERT: type <$t> not allowed in configuration. "); |
| 655 | - return FALSE; |
|
| 656 | - } |
|
| 655 | + return FALSE; |
|
| 656 | + } |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | |
@@ -661,9 +661,9 @@ discard block |
||
| 661 | 661 | $milters=array(); |
| 662 | 662 | $query = 'SELECT `name` FROM `config`'; |
| 663 | 663 | |
| 664 | - $result = $myconn->query($query); |
|
| 665 | - if($result === false) { |
|
| 666 | - syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
|
| 664 | + $result = $myconn->query($query); |
|
| 665 | + if($result === false) { |
|
| 666 | + syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
|
| 667 | 667 | return FALSE; |
| 668 | 668 | } |
| 669 | 669 | if ($result->num_rows) { |
@@ -5,36 +5,36 @@ discard block |
||
| 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 | 13 | function myConnect($host, $user, $pass, $db, $port, $tablelist, $typedesc, $loguser) { |
| 14 | - $db = ( $tablelist["$typedesc"]['milter'] ) ? $tablelist["$typedesc"]['name'] : $db; |
|
| 14 | + $db = ($tablelist["$typedesc"]['milter']) ? $tablelist["$typedesc"]['name'] : $db; |
|
| 15 | 15 | $mysqli = new mysqli($host, $user, $pass, $db, $port); |
| 16 | 16 | if ($mysqli->connect_error) { |
| 17 | - syslog (LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> (' . $mysqli->connect_errno . ') ' |
|
| 17 | + syslog(LOG_EMERG, $loguser.': Connect Error to DB <'.$db.'> ('.$mysqli->connect_errno.') ' |
|
| 18 | 18 | . $mysqli->connect_error); |
| 19 | 19 | return FALSE; |
| 20 | 20 | } |
| 21 | - syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to ' . $mysqli->host_info) ; |
|
| 21 | + syslog(LOG_INFO, $loguser.': Successfully MySQL connected at DB <'.$db.'> to '.$mysqli->host_info); |
|
| 22 | 22 | return $mysqli; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -function addtolist ($myconn,$user,$value,$tabledesc,$expUnit,$expQ,$myreason,&$err) { |
|
| 25 | +function addtolist($myconn, $user, $value, $tabledesc, $expUnit, $expQ, $myreason, &$err) { |
|
| 26 | 26 | // See MySQL manual for $expQ and $expUnit at |
| 27 | 27 | // https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampadd |
| 28 | 28 | |
| 29 | - $result=FALSE; |
|
| 30 | - $sub=array(); |
|
| 29 | + $result = FALSE; |
|
| 30 | + $sub = array(); |
|
| 31 | 31 | $type = $tabledesc['field']; |
| 32 | 32 | $milt = $tabledesc['milter']; |
| 33 | 33 | $table = ($milt) ? milterTable($type) : $tabledesc['name']; |
| 34 | 34 | |
| 35 | 35 | switch ($type) { |
| 36 | 36 | case 'ip': |
| 37 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 37 | + $query = sprintf("INSERT INTO `$table` ( |
|
| 38 | 38 | `$type` , |
| 39 | 39 | `date` , |
| 40 | 40 | `exp` , |
@@ -45,18 +45,18 @@ discard block |
||
| 45 | 45 | VALUES ( |
| 46 | 46 | INET_ATON( '%s' ) , |
| 47 | 47 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 48 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
| 48 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
| 49 | 49 | break; |
| 50 | 50 | |
| 51 | 51 | case 'network': |
| 52 | 52 | if (!$milt) { |
| 53 | - if ( netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user) ) { |
|
| 53 | + if (netOverlap($myconn, $tabledesc, $value, $overlappedNet, $user)) { |
|
| 54 | 54 | $err = "<$value> overlaps the existing network <$overlappedNet>"; |
| 55 | 55 | return FALSE; |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 59 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 58 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 59 | + $query = sprintf("INSERT INTO `$table` ( |
|
| 60 | 60 | `$type` , |
| 61 | 61 | `netmask`, |
| 62 | 62 | `date` , |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | VALUES ( |
| 69 | 69 | INET_ATON( '%s' ) , INET_ATON( '%s' ) , |
| 70 | 70 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 71 | - )" ,$sub['net'],$sub['mask'],$expUnit,$expQ,$user,$myreason); |
|
| 71 | + )", $sub['net'], $sub['mask'], $expUnit, $expQ, $user, $myreason); |
|
| 72 | 72 | break; |
| 73 | 73 | |
| 74 | 74 | default: |
| 75 | - $query= sprintf("INSERT INTO `$table` ( |
|
| 75 | + $query = sprintf("INSERT INTO `$table` ( |
|
| 76 | 76 | `$type` , |
| 77 | 77 | `date` , |
| 78 | 78 | `exp` , |
@@ -83,60 +83,60 @@ discard block |
||
| 83 | 83 | VALUES ( |
| 84 | 84 | '%s' , |
| 85 | 85 | CURRENT_TIMESTAMP , TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), '1', '%s', '%s' |
| 86 | - )" ,$value,$expUnit,$expQ,$user,$myreason); |
|
| 86 | + )", $value, $expUnit, $expQ, $user, $myreason); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | if ($myconn->query($query) === TRUE) { |
| 90 | 90 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
| 91 | - $result=TRUE; |
|
| 91 | + $result = TRUE; |
|
| 92 | 92 | } |
| 93 | 93 | else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
| 94 | 94 | return $result; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | -function relist ($myconn,$user,$value,$type,$table,$expUnit,$expQ,$myreason) { |
|
| 97 | +function relist($myconn, $user, $value, $type, $table, $expUnit, $expQ, $myreason) { |
|
| 98 | 98 | |
| 99 | - $result=FALSE; |
|
| 99 | + $result = FALSE; |
|
| 100 | 100 | |
| 101 | 101 | switch ($type) { |
| 102 | 102 | case 'ip': |
| 103 | - $query= sprintf("UPDATE `$table` SET |
|
| 103 | + $query = sprintf("UPDATE `$table` SET |
|
| 104 | 104 | `active` = '1', |
| 105 | 105 | `user` = '%s', |
| 106 | 106 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
| 107 | 107 | `nlist` = `nlist` + 1, |
| 108 | 108 | `reason` = '%s' |
| 109 | - WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
|
| 109 | + WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $expUnit, $expQ, $myreason, $value); |
|
| 110 | 110 | break; |
| 111 | 111 | case 'network': |
| 112 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 113 | - $query= sprintf("UPDATE `$table` SET |
|
| 112 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 113 | + $query = sprintf("UPDATE `$table` SET |
|
| 114 | 114 | `active` = '1', |
| 115 | 115 | `user` = '%s', |
| 116 | 116 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
| 117 | 117 | `nlist` = `nlist` + 1, |
| 118 | 118 | `reason` = '%s' |
| 119 | - WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$sub['net'],$sub['mask']); |
|
| 119 | + WHERE (`$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s')) LIMIT 1", $user, $expUnit, $expQ, $myreason, $sub['net'], $sub['mask']); |
|
| 120 | 120 | break; |
| 121 | 121 | default: |
| 122 | - $query= sprintf("UPDATE `$table` SET |
|
| 122 | + $query = sprintf("UPDATE `$table` SET |
|
| 123 | 123 | `active` = '1', |
| 124 | 124 | `user` = '%s', |
| 125 | 125 | `exp` = TIMESTAMPADD(%s,%d,CURRENT_TIMESTAMP), |
| 126 | 126 | `nlist` = `nlist` + 1, |
| 127 | 127 | `reason` = '%s' |
| 128 | - WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user,$expUnit,$expQ,$myreason,$value); |
|
| 128 | + WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $expUnit, $expQ, $myreason, $value); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if ($myconn->query($query) === TRUE) { |
| 132 | 132 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
| 133 | - $result=TRUE; |
|
| 133 | + $result = TRUE; |
|
| 134 | 134 | } |
| 135 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 135 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 136 | 136 | return $result; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | -function remove ($myconn,$user,$value,$type,$table) { |
|
| 139 | +function remove($myconn, $user, $value, $type, $table) { |
|
| 140 | 140 | |
| 141 | 141 | switch ($type) { |
| 142 | 142 | case 'ip': |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | `$table`.`$type` = INET_ATON('%s') LIMIT 1", $value); |
| 145 | 145 | break; |
| 146 | 146 | case 'network': |
| 147 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 147 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 148 | 148 | $query = sprintf("DELETE FROM `$table` WHERE |
| 149 | 149 | `$table`.`$type` = INET_ATON('%s') AND `$table`.`netmask` = INET_ATON('%s') LIMIT 1", |
| 150 | - $sub['net'],$sub['mask']); |
|
| 150 | + $sub['net'], $sub['mask']); |
|
| 151 | 151 | break; |
| 152 | 152 | default: |
| 153 | 153 | $query = sprintf("DELETE FROM `$table` WHERE |
@@ -155,39 +155,39 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
| 158 | - if ($return=$myconn->query($query) === TRUE) |
|
| 158 | + if ($return = $myconn->query($query) === TRUE) |
|
| 159 | 159 | syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
| 160 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 160 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 161 | 161 | |
| 162 | 162 | return $return; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
| 166 | -function changestatus ($myconn,$user,$value,$status,$type,$table) { |
|
| 166 | +function changestatus($myconn, $user, $value, $status, $type, $table) { |
|
| 167 | 167 | |
| 168 | 168 | switch ($type) { |
| 169 | 169 | case 'ip': |
| 170 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1" ,$user, $value); |
|
| 170 | + $query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = INET_ATON('%s') LIMIT 1", $user, $value); |
|
| 171 | 171 | break; |
| 172 | 172 | case 'network': |
| 173 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 174 | - $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']); |
|
| 173 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 174 | + $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']); |
|
| 175 | 175 | break; |
| 176 | 176 | default: |
| 177 | - $query= sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1" ,$user, $value); |
|
| 177 | + $query = sprintf("UPDATE `$table` SET `active` = '$status', `user` = '%s' WHERE `$table`.`$type` = '%s' LIMIT 1", $user, $value); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if ($return=$myconn->query($query) === TRUE) { |
|
| 180 | + if ($return = $myconn->query($query) === TRUE) { |
|
| 181 | 181 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
| 182 | 182 | } |
| 183 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 183 | + else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 184 | 184 | return $return; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
| 188 | -function expire ($myconn,$user,$tables,$expireTime) { |
|
| 189 | - $return=TRUE; |
|
| 190 | - $log=array(); |
|
| 188 | +function expire($myconn, $user, $tables, $expireTime) { |
|
| 189 | + $return = TRUE; |
|
| 190 | + $log = array(); |
|
| 191 | 191 | $desc = array_keys($tables); |
| 192 | 192 | foreach ($desc as $tdesc) { |
| 193 | 193 | /* QUERY */ |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | } while ($myconn->next_result()); |
| 207 | 207 | } |
| 208 | 208 | else { |
| 209 | - syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
|
| 209 | + syslog(LOG_ERR, "Expire job - Error: ".$myconn->error); |
|
| 210 | 210 | $return = FALSE; |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 213 | + if (!($return)) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 214 | 214 | else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
| 215 | 215 | return $return; |
| 216 | 216 | } |
@@ -218,18 +218,18 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | function isListed($row) { |
| 220 | 220 | |
| 221 | - $exp=new DateTime($row['exp']); |
|
| 222 | - $now=new DateTime('NOW'); |
|
| 223 | - if (($exp > $now) and ($row['active'])) return true; |
|
| 221 | + $exp = new DateTime($row['exp']); |
|
| 222 | + $now = new DateTime('NOW'); |
|
| 223 | + if (($exp>$now) and ($row['active'])) return true; |
|
| 224 | 224 | else return false; |
| 225 | 225 | |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
| 229 | -function askMilter($myconn,$id,$obj,$typedesc,$miltId,$value,$user,$adm) { |
|
| 230 | - $milts = readMiltName($myconn,$user); |
|
| 229 | +function askMilter($myconn, $id, $obj, $typedesc, $miltId, $value, $user, $adm) { |
|
| 230 | + $milts = readMiltName($myconn, $user); |
|
| 231 | 231 | $size = count($milts); |
| 232 | - if (in_array($user,array_keys($adm))) { |
|
| 232 | + if (in_array($user, array_keys($adm))) { |
|
| 233 | 233 | $button = <<<END |
| 234 | 234 | <form style="margin:0; display:inline;" name="Milter$id" enctype="text/plain" method="post" target="_self" action="changeMilter.php" onSubmit="xmlhttpPost('changeMilter.php', 'Milter$id', 'id$id', '<img src=\'/include/pleasewait.gif\'>'); return false;" /> |
| 235 | 235 | <input name="object" type="hidden" value="$obj" /><input name="oldvalues" type="hidden" value="$value" /> |
@@ -239,12 +239,12 @@ discard block |
||
| 239 | 239 | <div class="noscroll"> |
| 240 | 240 | <select class="input_text" name="newvalues[]" multiple size="$size"> |
| 241 | 241 | END; |
| 242 | - $activeMilts = explode(',',$value); |
|
| 243 | - foreach ( $milts as $milter ) { |
|
| 244 | - if ( in_array($milter, $activeMilts) ) |
|
| 245 | - $selected= 'selected'; |
|
| 242 | + $activeMilts = explode(',', $value); |
|
| 243 | + foreach ($milts as $milter) { |
|
| 244 | + if (in_array($milter, $activeMilts)) |
|
| 245 | + $selected = 'selected'; |
|
| 246 | 246 | else |
| 247 | - $selected= NULL; |
|
| 247 | + $selected = NULL; |
|
| 248 | 248 | $button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter); |
| 249 | 249 | } |
| 250 | 250 | $button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>'; |
@@ -256,14 +256,14 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
| 259 | -function ask($myconn,$id,$what,$alltables,$typedesc,$value,$lock,$user,$adm) { |
|
| 259 | +function ask($myconn, $id, $what, $alltables, $typedesc, $value, $lock, $user, $adm) { |
|
| 260 | 260 | |
| 261 | - $whynot=NULL; |
|
| 261 | + $whynot = NULL; |
|
| 262 | 262 | switch ($what) { |
| 263 | 263 | case 'Ok': |
| 264 | 264 | if ($lock) return NULL; |
| 265 | - if (in_array($user,array_keys($adm))) |
|
| 266 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 265 | + if (in_array($user, array_keys($adm))) |
|
| 266 | + if (consistentListing($myconn, $alltables, $typedesc, $value, $whynot)) return require('relistButton.php'); |
|
| 267 | 267 | return htmlspecialchars($whynot); |
| 268 | 268 | case 'Listed': |
| 269 | 269 | case 'WhiteListed': |
@@ -272,18 +272,18 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | |
| 275 | -function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
|
| 275 | +function consistentListing($myconn, $alltables, $typed, $value, &$warn) { |
|
| 276 | 276 | /* Check if there are no pending mislisting */ |
| 277 | 277 | $warn = NULL; |
| 278 | - if (! isset($alltables["$typed"]['depend']) ) return TRUE; |
|
| 278 | + if (!isset($alltables["$typed"]['depend'])) return TRUE; |
|
| 279 | 279 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
| 280 | - if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
|
| 280 | + if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field']) { |
|
| 281 | 281 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
| 282 | 282 | return FALSE; |
| 283 | 283 | } |
| 284 | - $entry = searchentry($myconn,$value,$alltables["$listdep"]); |
|
| 285 | - if ( $entry->num_rows ) { |
|
| 286 | - if ( $entry->num_rows == 1 ) { |
|
| 284 | + $entry = searchentry($myconn, $value, $alltables["$listdep"]); |
|
| 285 | + if ($entry->num_rows) { |
|
| 286 | + if ($entry->num_rows == 1) { |
|
| 287 | 287 | $riga = $entry->fetch_array(MYSQLI_ASSOC); |
| 288 | 288 | if (isListed($riga)) { |
| 289 | 289 | $warn = "<$value> is already present in <$listdep> list!"; |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | return FALSE; |
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | - if ( $entry->num_rows > 1 ) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!";} |
|
| 294 | + if ($entry->num_rows>1) {$warn = "<$value> seems to be present more than once in <$listdep>. Contact a sysadmin NOW!"; } |
|
| 295 | 295 | } |
| 296 | 296 | $entry->free(); |
| 297 | 297 | } |
@@ -299,20 +299,20 @@ discard block |
||
| 299 | 299 | return TRUE; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | -function searchentry ($myconn,$value,$tablelist) { |
|
| 302 | +function searchentry($myconn, $value, $tablelist) { |
|
| 303 | 303 | /* Make a MYSQL query and return result */ |
| 304 | 304 | |
| 305 | 305 | $type = $tablelist['field']; |
| 306 | 306 | |
| 307 | - if ( $tablelist['milter'] ) { |
|
| 307 | + if ($tablelist['milter']) { |
|
| 308 | 308 | $table = milterTable($type); |
| 309 | 309 | if ($value == 'ALL') |
| 310 | 310 | $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
| 311 | - $table,$table); |
|
| 311 | + $table, $table); |
|
| 312 | 312 | else { |
| 313 | 313 | switch ($type) { |
| 314 | 314 | case 'network': |
| 315 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 315 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 316 | 316 | $query = sprintf('SELECT * FROM ( |
| 317 | 317 | SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) |
| 318 | 318 | WHERE ( |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | ) AS val WHERE val.ip IS NOT null', $table, $table, $value); |
| 331 | 331 | break; |
| 332 | 332 | default: |
| 333 | - syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.' ); |
|
| 333 | + syslog(LOG_EMERG, 'ALERT: The type <'.$type.'> is not allowed for milter lists.'); |
|
| 334 | 334 | return FALSE; |
| 335 | 335 | } |
| 336 | 336 | } |
@@ -342,11 +342,11 @@ discard block |
||
| 342 | 342 | else { |
| 343 | 343 | switch ($type) { |
| 344 | 344 | case 'ip': |
| 345 | - $query= "select * from $table where $type = INET_ATON('$value')"; |
|
| 345 | + $query = "select * from $table where $type = INET_ATON('$value')"; |
|
| 346 | 346 | break; |
| 347 | 347 | case 'network': |
| 348 | - list($sub['net'],$sub['mask'])=explode('/',$value); |
|
| 349 | - $query= sprintf('select * from `%s` |
|
| 348 | + list($sub['net'], $sub['mask']) = explode('/', $value); |
|
| 349 | + $query = sprintf('select * from `%s` |
|
| 350 | 350 | WHERE ( |
| 351 | 351 | inet_aton(\'%s\') >= network AND |
| 352 | 352 | ( inet_aton(\'%s\') | ( inet_aton(\'%s\') ^ (power(2,32)-1) ) ) |
@@ -355,18 +355,18 @@ discard block |
||
| 355 | 355 | ; |
| 356 | 356 | break; |
| 357 | 357 | default: |
| 358 | - $query= "select * from $table where $type = '$value'"; |
|
| 358 | + $query = "select * from $table where $type = '$value'"; |
|
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | $result = $myconn->query($query); |
| 364 | - if($result === false) |
|
| 364 | + if ($result === false) |
|
| 365 | 365 | syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
| 366 | 366 | return $result; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | -function countListed ($myconn,$table) { |
|
| 369 | +function countListed($myconn, $table) { |
|
| 370 | 370 | /* Return number of current listed items into a rbl table */ |
| 371 | 371 | $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"; |
| 372 | 372 | $row = $myconn->query($query); |
@@ -377,48 +377,48 @@ discard block |
||
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | |
| 380 | -function isFull($myconn,$typedesc,$alltables) { |
|
| 380 | +function isFull($myconn, $typedesc, $alltables) { |
|
| 381 | 381 | if (isset($alltables["$typedesc"]['limit'])) { |
| 382 | - if ( $alltables["$typedesc"]['milter'] ) |
|
| 382 | + if ($alltables["$typedesc"]['milter']) |
|
| 383 | 383 | $tab = 'net'; |
| 384 | 384 | else |
| 385 | 385 | $tab = $alltables["$typedesc"]['name']; |
| 386 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 386 | + if (countListed($myconn, $tab)>=$alltables["$typedesc"]['limit']) |
|
| 387 | 387 | return TRUE; |
| 388 | 388 | } |
| 389 | 389 | return FALSE; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | -function rlookup ($myconn,$user,$adm,$value,$typedesc,$tables) { |
|
| 392 | +function rlookup($myconn, $user, $adm, $value, $typedesc, $tables) { |
|
| 393 | 393 | |
| 394 | 394 | $type = $tables["$typedesc"]['field']; |
| 395 | - $whynot=NULL; |
|
| 395 | + $whynot = NULL; |
|
| 396 | 396 | |
| 397 | 397 | $tabhtm = <<<END |
| 398 | 398 | <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> |
| 399 | 399 | END; |
| 400 | - if ( $tables["$typedesc"]['milter'] ) |
|
| 400 | + if ($tables["$typedesc"]['milter']) |
|
| 401 | 401 | $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
| 402 | 402 | $tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
| 403 | 403 | |
| 404 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 404 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); |
|
| 405 | 405 | if ($result) { |
| 406 | 406 | printf("<pre>Your request for $type <$value> returned %d items.\n</pre>", $result->num_rows); |
| 407 | 407 | |
| 408 | 408 | /* Check for limit in number of listed items */ |
| 409 | - $full = isFull($myconn,$typedesc,$tables); |
|
| 409 | + $full = isFull($myconn, $typedesc, $tables); |
|
| 410 | 410 | if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
| 411 | 411 | |
| 412 | 412 | if ($result->num_rows) { |
| 413 | 413 | print $tabhtm; |
| 414 | - $i=0; |
|
| 414 | + $i = 0; |
|
| 415 | 415 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
| 416 | 416 | if (isListed($riga)) { |
| 417 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
| 418 | - else $listed='WhiteListed'; |
|
| 417 | + if ($tables["$typedesc"]['bl']) $listed = 'Listed'; |
|
| 418 | + else $listed = 'WhiteListed'; |
|
| 419 | 419 | } |
| 420 | 420 | else |
| 421 | - $listed='Ok'; |
|
| 421 | + $listed = 'Ok'; |
|
| 422 | 422 | |
| 423 | 423 | switch ($type) { |
| 424 | 424 | case 'ip': |
@@ -431,20 +431,20 @@ discard block |
||
| 431 | 431 | $element = $riga["$type"]; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) |
|
| 435 | - 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 nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 436 | - $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], askMilter($myconn,$i,$element,$typedesc,$riga['idmilt'],$riga['miltnames'],$user,$adm), $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm)); |
|
| 434 | + if ($tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"])) |
|
| 435 | + 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 nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 436 | + $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], askMilter($myconn, $i, $element, $typedesc, $riga['idmilt'], $riga['miltnames'], $user, $adm), $riga['user'], htmlspecialchars($riga['reason']), ask($myconn, $i, $listed, $tables, $typedesc, $element, $full, $user, $adm)); |
|
| 437 | 437 | else |
| 438 | - 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", |
|
| 439 | - $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)); |
|
| 438 | + 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", |
|
| 439 | + $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)); |
|
| 440 | 440 | $i++; |
| 441 | 441 | } |
| 442 | 442 | print '</tbody></table>'; |
| 443 | 443 | } |
| 444 | 444 | else { |
| 445 | 445 | print "<pre>$type <$value> is not listed!\n</pre>"; |
| 446 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
| 447 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 446 | + if (in_array($user, array_keys($adm)) AND ($value != 'ALL')) |
|
| 447 | + if ((!$full) AND (consistentListing($myconn, $tables, $typedesc, $value, $whynot))) require_once('listForm.php'); |
|
| 448 | 448 | else print '<p>'.htmlspecialchars($whynot).'</p>'; |
| 449 | 449 | |
| 450 | 450 | } |
@@ -456,12 +456,12 @@ discard block |
||
| 456 | 456 | |
| 457 | 457 | |
| 458 | 458 | |
| 459 | -function sendEmailWarn($tplf,$from,$to,$sbj,$emailListed,$intervalToExpire,$detail) { |
|
| 459 | +function sendEmailWarn($tplf, $from, $to, $sbj, $emailListed, $intervalToExpire, $detail) { |
|
| 460 | 460 | $now = time(); |
| 461 | - setlocale (LC_TIME, 'it_IT'); |
|
| 462 | - $date = date("r",$now); |
|
| 463 | - $messageID = md5(uniqid($now,1)) . '@' . $_SERVER["HOSTNAME"]; |
|
| 464 | - $mua = 'PHP/' . phpversion(); |
|
| 461 | + setlocale(LC_TIME, 'it_IT'); |
|
| 462 | + $date = date("r", $now); |
|
| 463 | + $messageID = md5(uniqid($now, 1)).'@'.$_SERVER["HOSTNAME"]; |
|
| 464 | + $mua = 'PHP/'.phpversion(); |
|
| 465 | 465 | |
| 466 | 466 | /* Parsing headers */ |
| 467 | 467 | if (!file_exists($tplf['header'])) { |
@@ -470,10 +470,10 @@ discard block |
||
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | $head_tmpl = file_get_contents($tplf['header']); |
| 473 | - $arr_tpl_vars = array('{from}','{to}','{date}','{messageID}','{mua}'); |
|
| 474 | - $arr_tpl_data = array($from,$to,$date,$messageID,$mua); |
|
| 473 | + $arr_tpl_vars = array('{from}', '{to}', '{date}', '{messageID}', '{mua}'); |
|
| 474 | + $arr_tpl_data = array($from, $to, $date, $messageID, $mua); |
|
| 475 | 475 | $headers = str_replace($arr_tpl_vars, $arr_tpl_data, $head_tmpl); |
| 476 | - $headers = preg_replace( '/\r|\n/', "\r\n", $headers ); |
|
| 476 | + $headers = preg_replace('/\r|\n/', "\r\n", $headers); |
|
| 477 | 477 | |
| 478 | 478 | /* Parsing body */ |
| 479 | 479 | |
@@ -483,62 +483,62 @@ discard block |
||
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | $body_tmpl = file_get_contents($tplf['body']); |
| 486 | - $arr_tpl_vars = array('{emailListed}','{expInterval}','{reason}'); |
|
| 487 | - $arr_tpl_data = array($emailListed,$intervalToExpire,$detail); |
|
| 486 | + $arr_tpl_vars = array('{emailListed}', '{expInterval}', '{reason}'); |
|
| 487 | + $arr_tpl_data = array($emailListed, $intervalToExpire, $detail); |
|
| 488 | 488 | $body = str_replace($arr_tpl_vars, $arr_tpl_data, $body_tmpl); |
| 489 | - $body = preg_replace( "/\r|\n/", "\r\n", $body ); |
|
| 490 | - $body = wordwrap ( $body, 75 , "\r\n" ); |
|
| 489 | + $body = preg_replace("/\r|\n/", "\r\n", $body); |
|
| 490 | + $body = wordwrap($body, 75, "\r\n"); |
|
| 491 | 491 | |
| 492 | 492 | /* Send the mail! */ |
| 493 | - if ( strlen(ini_get("safe_mode"))< 1) { |
|
| 493 | + if (strlen(ini_get("safe_mode"))<1) { |
|
| 494 | 494 | $old_mailfrom = ini_get("sendmail_from"); |
| 495 | 495 | ini_set("sendmail_from", $from); |
| 496 | 496 | $params = sprintf("-oi -f %s", '<>'); |
| 497 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 498 | - else $flag=TRUE; |
|
| 497 | + if (!(mail($to, $sbj, $body, $headers, $params))) $flag = FALSE; |
|
| 498 | + else $flag = TRUE; |
|
| 499 | 499 | if (isset($old_mailfrom)) |
| 500 | 500 | ini_set("sendmail_from", $old_mailfrom); |
| 501 | 501 | } |
| 502 | 502 | else { |
| 503 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 504 | - else $flag=TRUE; |
|
| 503 | + if (!(mail($to, $sbj, $body, $headers))) $flag = FALSE; |
|
| 504 | + else $flag = TRUE; |
|
| 505 | 505 | } |
| 506 | 506 | return $flag; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | -function emailToNotify($notify_file,$dom) { |
|
| 509 | +function emailToNotify($notify_file, $dom) { |
|
| 510 | 510 | $ini_array = parse_ini_file($notify_file); |
| 511 | - if (in_array($dom,array_keys($ini_array))) |
|
| 511 | + if (in_array($dom, array_keys($ini_array))) |
|
| 512 | 512 | return $ini_array["$dom"]; |
| 513 | 513 | else return FALSE; |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | |
| 517 | -function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
|
| 517 | +function searchAndList($myconn, $loguser, $tables, $typedesc, $value, $unit, &$quantity, $reason) { |
|
| 518 | 518 | |
| 519 | 519 | /* Search and list value */ |
| 520 | 520 | $type = $tables["$typedesc"]['field']; |
| 521 | 521 | $table = $tables["$typedesc"]['name']; |
| 522 | - $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
|
| 522 | + $result = searchentry($myconn, $value, $tables["$typedesc"]); |
|
| 523 | 523 | |
| 524 | 524 | /* Manage abnormal conditions */ |
| 525 | 525 | /* Value already present in db more than once. This is absurd. Panic! */ |
| 526 | - if ($result->num_rows > 1) { |
|
| 527 | - syslog(LOG_EMERG,"$loguser: PANIC! Select for $type '$value' returned ". $result->num_rows ." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 526 | + if ($result->num_rows>1) { |
|
| 527 | + syslog(LOG_EMERG, "$loguser: PANIC! Select for $type '$value' returned ".$result->num_rows." items instead of one. Abnormal. Contact a sysadmin or a developer."); |
|
| 528 | 528 | $result->free(); |
| 529 | 529 | return FALSE; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | /* Value already present in db or not present: to list anyway */ |
| 533 | - if ($result->num_rows >= 0) { |
|
| 533 | + if ($result->num_rows>=0) { |
|
| 534 | 534 | /* First, check for limit in number of listed items */ |
| 535 | - if (isFull($myconn,$typedesc,$tables)) { |
|
| 536 | - syslog(LOG_EMERG,"$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 535 | + if (isFull($myconn, $typedesc, $tables)) { |
|
| 536 | + syslog(LOG_EMERG, "$loguser: $typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items. Abnormal exit.'); |
|
| 537 | 537 | $result->free(); |
| 538 | 538 | return FALSE; |
| 539 | 539 | } |
| 540 | 540 | /* Second, check if the (re)list would be consistent now */ |
| 541 | - if (! consistentListing($myconn,$tables,$typedesc,$value,$whynot) ) { |
|
| 541 | + if (!consistentListing($myconn, $tables, $typedesc, $value, $whynot)) { |
|
| 542 | 542 | syslog(LOG_ERR, $loguser.': '.$whynot); |
| 543 | 543 | $result->free(); |
| 544 | 544 | return FALSE; |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | /* Relist value if already present */ |
| 554 | 554 | case 1: |
| 555 | 555 | /* Entry already listed */ |
| 556 | - if ( isListed($thisentry) ) { |
|
| 556 | + if (isListed($thisentry)) { |
|
| 557 | 557 | syslog(LOG_INFO, $loguser.': '.$value.' already listed. Nothing to do.'); |
| 558 | 558 | $result->free(); |
| 559 | 559 | return FALSE; |
@@ -562,34 +562,34 @@ discard block |
||
| 562 | 562 | /* Entry delisted */ |
| 563 | 563 | $result->free(); |
| 564 | 564 | $quantity *= $thisentry['nlist']; |
| 565 | - return relist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 565 | + return relist($myconn, $loguser, $value, $type, $table, $unit, $quantity, $reason); |
|
| 566 | 566 | |
| 567 | 567 | |
| 568 | 568 | /* First time list value */ |
| 569 | 569 | case 0: |
| 570 | 570 | $result->free(); |
| 571 | - return addtolist ($myconn,$loguser,$value,$type,$table,$unit,$quantity,$reason); |
|
| 571 | + return addtolist($myconn, $loguser, $value, $type, $table, $unit, $quantity, $reason); |
|
| 572 | 572 | } |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | |
| 576 | 576 | /*************** Functions to check if two net overlap each other ********************/ |
| 577 | 577 | |
| 578 | -function ipRange ($range) { |
|
| 578 | +function ipRange($range) { |
|
| 579 | 579 | /* List IP in range */ |
| 580 | - return array_map('long2ip', range( ip2long($range[0]), ip2long($range[1]) ) ); |
|
| 580 | + return array_map('long2ip', range(ip2long($range[0]), ip2long($range[1]))); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | function isIn($netA, $netB) { |
| 584 | 584 | /* TRUE if an IP of $netA is contained in netB */ |
| 585 | - list($addressA,$maskA) = explode('/', $netA); |
|
| 586 | - list($addressB,$maskB) = explode('/', $netB); |
|
| 585 | + list($addressA, $maskA) = explode('/', $netA); |
|
| 586 | + list($addressB, $maskB) = explode('/', $netB); |
|
| 587 | 587 | require_once 'vendor/autoload.php'; |
| 588 | 588 | $net = new \dautkom\ipv4\IPv4(); |
| 589 | 589 | $range = $net->address($addressA)->mask($maskA)->getRange(); |
| 590 | 590 | $ips = ipRange($range); |
| 591 | - foreach ( $ips as $ip ) |
|
| 592 | - if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 591 | + foreach ($ips as $ip) |
|
| 592 | + if ($net->address($addressB)->mask($maskB)->has($ip)) |
|
| 593 | 593 | return TRUE; |
| 594 | 594 | return FALSE; |
| 595 | 595 | } |
@@ -601,11 +601,11 @@ discard block |
||
| 601 | 601 | syslog(LOG_ERR, $loguser.': '.$tabletype['name'].' is not a network list.'); |
| 602 | 602 | return FALSE; |
| 603 | 603 | } |
| 604 | - $result = searchentry ($myconn,'ALL',$tabletype); |
|
| 604 | + $result = searchentry($myconn, 'ALL', $tabletype); |
|
| 605 | 605 | if ($result->num_rows) { |
| 606 | 606 | while ($row = $result->fetch_array(MYSQLI_ASSOC)) { |
| 607 | 607 | $thisNet = long2ip($row['network']).'/'.long2ip($row['netmask']); |
| 608 | - if ( isIn($thisNet, $net) ) { |
|
| 608 | + if (isIn($thisNet, $net)) { |
|
| 609 | 609 | $result->free(); |
| 610 | 610 | syslog(LOG_INFO, "$loguser: the net <$net> overlaps the existing network <$thisNet>."); |
| 611 | 611 | return TRUE; |
@@ -622,8 +622,8 @@ discard block |
||
| 622 | 622 | /* For miltermap */ |
| 623 | 623 | function checkMilterConf($table) { |
| 624 | 624 | if (isset($table['milter'])) { |
| 625 | - if ($table['milter'] === TRUE) { |
|
| 626 | - switch ( $table['field'] ) { |
|
| 625 | + if ($table['milter'] === TRUE) { |
|
| 626 | + switch ($table['field']) { |
|
| 627 | 627 | case 'network': |
| 628 | 628 | case 'ip': |
| 629 | 629 | return TRUE; |
@@ -657,12 +657,12 @@ discard block |
||
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | |
| 660 | -function readMiltName($myconn,$loguser) { |
|
| 661 | - $milters=array(); |
|
| 660 | +function readMiltName($myconn, $loguser) { |
|
| 661 | + $milters = array(); |
|
| 662 | 662 | $query = 'SELECT `name` FROM `config`'; |
| 663 | 663 | |
| 664 | 664 | $result = $myconn->query($query); |
| 665 | - if($result === false) { |
|
| 665 | + if ($result === false) { |
|
| 666 | 666 | syslog(LOG_EMERG, "$loguser: ALERT: Query <$query> failed: ".$myconn->error); |
| 667 | 667 | return FALSE; |
| 668 | 668 | } |
@@ -674,27 +674,27 @@ discard block |
||
| 674 | 674 | return $milters; |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | -function changeMilter ($myconn,$loguser,$miltVal,$table,$miltID) { |
|
| 677 | +function changeMilter($myconn, $loguser, $miltVal, $table, $miltID) { |
|
| 678 | 678 | $query = array(); |
| 679 | - foreach ( $miltVal as $value => $action ) { |
|
| 680 | - switch ( $action ) { |
|
| 679 | + foreach ($miltVal as $value => $action) { |
|
| 680 | + switch ($action) { |
|
| 681 | 681 | case 'keep': |
| 682 | 682 | break; |
| 683 | 683 | case 'add': |
| 684 | - $query[] = sprintf( "INSERT INTO `milt` ( |
|
| 684 | + $query[] = sprintf("INSERT INTO `milt` ( |
|
| 685 | 685 | `id` , |
| 686 | 686 | `name` |
| 687 | 687 | ) |
| 688 | 688 | VALUES ( |
| 689 | 689 | %d , |
| 690 | 690 | '%s' |
| 691 | - )",$miltID,$value); |
|
| 691 | + )",$miltID, $value); |
|
| 692 | 692 | break; |
| 693 | 693 | case 'del': |
| 694 | 694 | $query[] = "DELETE FROM `milt` WHERE (`id` = '$miltID' AND `name` = '$value')"; |
| 695 | 695 | } |
| 696 | 696 | } |
| 697 | - if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 697 | + if (count($query)) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 698 | 698 | /* I update datemod because the user couldn't change */ |
| 699 | 699 | $query[] = sprintf('UPDATE `%s` SET |
| 700 | 700 | `user`=\'%s\', |
@@ -706,18 +706,18 @@ discard block |
||
| 706 | 706 | $myconn->autocommit(FALSE); |
| 707 | 707 | $myconn->begin_transaction(MYSQLI_TRANS_START_READ_ONLY); |
| 708 | 708 | $ok = TRUE; |
| 709 | - foreach ( $query as $q ) { |
|
| 709 | + foreach ($query as $q) { |
|
| 710 | 710 | if ($myconn->query($q) !== TRUE) { |
| 711 | 711 | $ok = FALSE; |
| 712 | 712 | syslog(LOG_ERR, "$loguser: Error: ".$myconn->error); |
| 713 | 713 | } |
| 714 | 714 | } |
| 715 | - if ( $ok ) { |
|
| 716 | - if ( $myconn->commit() ) |
|
| 715 | + if ($ok) { |
|
| 716 | + if ($myconn->commit()) |
|
| 717 | 717 | syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
| 718 | 718 | else { |
| 719 | 719 | syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error."); |
| 720 | - if ( $myconn->rollback() ) |
|
| 720 | + if ($myconn->rollback()) |
|
| 721 | 721 | syslog(LOG_INFO, "$loguser: rollback succeeded."); |
| 722 | 722 | else |
| 723 | 723 | syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
@@ -3,9 +3,13 @@ discard block |
||
| 3 | 3 | ini_set('error_log', 'syslog'); |
| 4 | 4 | |
| 5 | 5 | function username() { |
| 6 | - if (isset ($_SERVER['REMOTE_USER'])) $user = $_SERVER['REMOTE_USER']; |
|
| 7 | - else if (isset ($_SERVER['USER'])) $user = $_SERVER['USER']; |
|
| 8 | - else $user='unknown'; |
|
| 6 | + if (isset ($_SERVER['REMOTE_USER'])) { |
|
| 7 | + $user = $_SERVER['REMOTE_USER']; |
|
| 8 | + } else if (isset ($_SERVER['USER'])) { |
|
| 9 | + $user = $_SERVER['USER']; |
|
| 10 | + } else { |
|
| 11 | + $user='unknown'; |
|
| 12 | + } |
|
| 9 | 13 | return $user; |
| 10 | 14 | } |
| 11 | 15 | |
@@ -89,8 +93,9 @@ discard block |
||
| 89 | 93 | if ($myconn->query($query) === TRUE) { |
| 90 | 94 | syslog(LOG_INFO, "$user: $type <$value> successfully listed on <$table> for $expQ $expUnit."); |
| 91 | 95 | $result=TRUE; |
| 96 | + } else { |
|
| 97 | + syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 92 | 98 | } |
| 93 | - else syslog(LOG_ERR, "$user: Error: ".$myconn->error); |
|
| 94 | 99 | return $result; |
| 95 | 100 | } |
| 96 | 101 | |
@@ -131,8 +136,9 @@ discard block |
||
| 131 | 136 | if ($myconn->query($query) === TRUE) { |
| 132 | 137 | syslog(LOG_INFO, "$user: relist $type <$value> on <$table> for $expQ $expUnit."); |
| 133 | 138 | $result=TRUE; |
| 139 | + } else { |
|
| 140 | + syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 134 | 141 | } |
| 135 | - else syslog (LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 136 | 142 | return $result; |
| 137 | 143 | } |
| 138 | 144 | |
@@ -155,9 +161,11 @@ discard block |
||
| 155 | 161 | } |
| 156 | 162 | |
| 157 | 163 | |
| 158 | - if ($return=$myconn->query($query) === TRUE) |
|
| 159 | - syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 160 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 164 | + if ($return=$myconn->query($query) === TRUE) { |
|
| 165 | + syslog(LOG_INFO, "$user: permanently DELETED $type <$value> from <$table>."); |
|
| 166 | + } else { |
|
| 167 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 168 | + } |
|
| 161 | 169 | |
| 162 | 170 | return $return; |
| 163 | 171 | } |
@@ -179,8 +187,9 @@ discard block |
||
| 179 | 187 | |
| 180 | 188 | if ($return=$myconn->query($query) === TRUE) { |
| 181 | 189 | syslog(LOG_INFO, "$user: change status of $type <$value>. The status is now <$status>"); |
| 190 | + } else { |
|
| 191 | + syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 182 | 192 | } |
| 183 | - else syslog(LOG_ERR, "$user: Error: ". $myconn->error); |
|
| 184 | 193 | return $return; |
| 185 | 194 | } |
| 186 | 195 | |
@@ -204,14 +213,16 @@ discard block |
||
| 204 | 213 | $j++; |
| 205 | 214 | |
| 206 | 215 | } while ($myconn->next_result()); |
| 207 | - } |
|
| 208 | - else { |
|
| 216 | + } else { |
|
| 209 | 217 | syslog(LOG_ERR, "Expire job - Error: ". $myconn->error); |
| 210 | 218 | $return = FALSE; |
| 211 | 219 | } |
| 212 | 220 | } |
| 213 | - if ( !($return) ) syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 214 | - else syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 221 | + if ( !($return) ) { |
|
| 222 | + syslog(LOG_EMERG, 'End of Expire job with error. See above logs. SQL Connection terminated'); |
|
| 223 | + } else { |
|
| 224 | + syslog(LOG_INFO, 'Successfully End of Expire job. SQL Connection successfully terminated.'); |
|
| 225 | + } |
|
| 215 | 226 | return $return; |
| 216 | 227 | } |
| 217 | 228 | |
@@ -220,8 +231,11 @@ discard block |
||
| 220 | 231 | |
| 221 | 232 | $exp=new DateTime($row['exp']); |
| 222 | 233 | $now=new DateTime('NOW'); |
| 223 | - if (($exp > $now) and ($row['active'])) return true; |
|
| 224 | - else return false; |
|
| 234 | + if (($exp > $now) and ($row['active'])) { |
|
| 235 | + return true; |
|
| 236 | + } else { |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 225 | 239 | |
| 226 | 240 | } |
| 227 | 241 | |
@@ -241,10 +255,11 @@ discard block |
||
| 241 | 255 | END; |
| 242 | 256 | $activeMilts = explode(',',$value); |
| 243 | 257 | foreach ( $milts as $milter ) { |
| 244 | - if ( in_array($milter, $activeMilts) ) |
|
| 245 | - $selected= 'selected'; |
|
| 246 | - else |
|
| 247 | - $selected= NULL; |
|
| 258 | + if ( in_array($milter, $activeMilts) ) { |
|
| 259 | + $selected= 'selected'; |
|
| 260 | + } else { |
|
| 261 | + $selected= NULL; |
|
| 262 | + } |
|
| 248 | 263 | $button .= sprintf('<option value="%s" %s>%s</option>', $milter, $selected, $milter); |
| 249 | 264 | } |
| 250 | 265 | $button .= '</select></div><input class="button" name="Change" type="submit" value="Change" /></form>'; |
@@ -261,9 +276,12 @@ discard block |
||
| 261 | 276 | $whynot=NULL; |
| 262 | 277 | switch ($what) { |
| 263 | 278 | case 'Ok': |
| 264 | - if ($lock) return NULL; |
|
| 265 | - if (in_array($user,array_keys($adm))) |
|
| 266 | - if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 279 | + if ($lock) { |
|
| 280 | + return NULL; |
|
| 281 | + } |
|
| 282 | + if (in_array($user,array_keys($adm))) { |
|
| 283 | + if ( consistentListing($myconn,$alltables,$typedesc,$value,$whynot) ) return require('relistButton.php'); |
|
| 284 | + } |
|
| 267 | 285 | return htmlspecialchars($whynot); |
| 268 | 286 | case 'Listed': |
| 269 | 287 | case 'WhiteListed': |
@@ -275,7 +293,9 @@ discard block |
||
| 275 | 293 | function consistentListing($myconn,$alltables,$typed,$value,&$warn) { |
| 276 | 294 | /* Check if there are no pending mislisting */ |
| 277 | 295 | $warn = NULL; |
| 278 | - if (! isset($alltables["$typed"]['depend']) ) return TRUE; |
|
| 296 | + if (! isset($alltables["$typed"]['depend']) ) { |
|
| 297 | + return TRUE; |
|
| 298 | + } |
|
| 279 | 299 | foreach ($alltables["$typed"]['depend'] as $listdep) { |
| 280 | 300 | if ($alltables["$typed"]['field'] != $alltables["$listdep"]['field'] ) { |
| 281 | 301 | $warn = "Config ERROR: <$typed> and <$listdep> are of different types! I can't check consistency!"; |
@@ -306,10 +326,10 @@ discard block |
||
| 306 | 326 | |
| 307 | 327 | if ( $tablelist['milter'] ) { |
| 308 | 328 | $table = milterTable($type); |
| 309 | - if ($value == 'ALL') |
|
| 310 | - $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
| 329 | + if ($value == 'ALL') { |
|
| 330 | + $query = sprintf('SELECT *, GROUP_CONCAT(milt.name) as miltnames FROM `%s` LEFT JOIN milt ON (%s.idmilt=milt.id) GROUP by idmilt', |
|
| 311 | 331 | $table,$table); |
| 312 | - else { |
|
| 332 | + } else { |
|
| 313 | 333 | switch ($type) { |
| 314 | 334 | case 'network': |
| 315 | 335 | list($sub['net'],$sub['mask'])=explode('/',$value); |
@@ -334,12 +354,11 @@ discard block |
||
| 334 | 354 | return FALSE; |
| 335 | 355 | } |
| 336 | 356 | } |
| 337 | - } |
|
| 338 | - |
|
| 339 | - else { |
|
| 357 | + } else { |
|
| 340 | 358 | $table = $tablelist['name']; |
| 341 | - if ($value == 'ALL') $query = 'select * from '.$table; |
|
| 342 | - else { |
|
| 359 | + if ($value == 'ALL') { |
|
| 360 | + $query = 'select * from '.$table; |
|
| 361 | + } else { |
|
| 343 | 362 | switch ($type) { |
| 344 | 363 | case 'ip': |
| 345 | 364 | $query= "select * from $table where $type = INET_ATON('$value')"; |
@@ -361,8 +380,9 @@ discard block |
||
| 361 | 380 | } |
| 362 | 381 | |
| 363 | 382 | $result = $myconn->query($query); |
| 364 | - if($result === false) |
|
| 365 | - syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 383 | + if($result === false) { |
|
| 384 | + syslog(LOG_EMERG, "ALERT: Query <$query> failed: ".$myconn->error); |
|
| 385 | + } |
|
| 366 | 386 | return $result; |
| 367 | 387 | } |
| 368 | 388 | |
@@ -379,12 +399,14 @@ discard block |
||
| 379 | 399 | |
| 380 | 400 | function isFull($myconn,$typedesc,$alltables) { |
| 381 | 401 | if (isset($alltables["$typedesc"]['limit'])) { |
| 382 | - if ( $alltables["$typedesc"]['milter'] ) |
|
| 383 | - $tab = 'net'; |
|
| 384 | - else |
|
| 385 | - $tab = $alltables["$typedesc"]['name']; |
|
| 386 | - if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) |
|
| 387 | - return TRUE; |
|
| 402 | + if ( $alltables["$typedesc"]['milter'] ) { |
|
| 403 | + $tab = 'net'; |
|
| 404 | + } else { |
|
| 405 | + $tab = $alltables["$typedesc"]['name']; |
|
| 406 | + } |
|
| 407 | + if ( countListed($myconn,$tab) >= $alltables["$typedesc"]['limit'] ) { |
|
| 408 | + return TRUE; |
|
| 409 | + } |
|
| 388 | 410 | } |
| 389 | 411 | return FALSE; |
| 390 | 412 | } |
@@ -397,8 +419,9 @@ discard block |
||
| 397 | 419 | $tabhtm = <<<END |
| 398 | 420 | <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> |
| 399 | 421 | END; |
| 400 | - if ( $tables["$typedesc"]['milter'] ) |
|
| 401 | - $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
| 422 | + if ( $tables["$typedesc"]['milter'] ) { |
|
| 423 | + $tabhtm .= '<th title="Milter active for this object">Milters</th>'; |
|
| 424 | + } |
|
| 402 | 425 | $tabhtm .= '<th>Authored by</th><th width="250">Reason</th><th>Action</th></tr></thead><tfoot><tr></tr></tfoot><tbody>'."\n"; |
| 403 | 426 | |
| 404 | 427 | $result = searchentry ($myconn,$value,$tables["$typedesc"]); |
@@ -407,18 +430,23 @@ discard block |
||
| 407 | 430 | |
| 408 | 431 | /* Check for limit in number of listed items */ |
| 409 | 432 | $full = isFull($myconn,$typedesc,$tables); |
| 410 | - if ($full) print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 433 | + if ($full) { |
|
| 434 | + print '<p>'.htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.').'</p>'; |
|
| 435 | + } |
|
| 411 | 436 | |
| 412 | 437 | if ($result->num_rows) { |
| 413 | 438 | print $tabhtm; |
| 414 | 439 | $i=0; |
| 415 | 440 | while ($riga = $result->fetch_array(MYSQLI_ASSOC)) { |
| 416 | 441 | if (isListed($riga)) { |
| 417 | - if ($tables["$typedesc"]['bl']) $listed='Listed'; |
|
| 418 | - else $listed='WhiteListed'; |
|
| 419 | - } |
|
| 420 | - else |
|
| 421 | - $listed='Ok'; |
|
| 442 | + if ($tables["$typedesc"]['bl']) { |
|
| 443 | + $listed='Listed'; |
|
| 444 | + } else { |
|
| 445 | + $listed='WhiteListed'; |
|
| 446 | + } |
|
| 447 | + } else { |
|
| 448 | + $listed='Ok'; |
|
| 449 | + } |
|
| 422 | 450 | |
| 423 | 451 | switch ($type) { |
| 424 | 452 | case 'ip': |
@@ -431,27 +459,30 @@ discard block |
||
| 431 | 459 | $element = $riga["$type"]; |
| 432 | 460 | } |
| 433 | 461 | |
| 434 | - if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) |
|
| 435 | - 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 nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 462 | + if ( $tables["$typedesc"]['milter'] AND checkMilterConf($tables["$typedesc"]) ) { |
|
| 463 | + 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 nowrap id='status$listed'>%s</td><td id='status$listed'>%s</td><td id='status$listed'>%s</td><td>%s</td></tr>\n", |
|
| 436 | 464 | $element, $riga['date'], $riga['datemod'], $riga['exp'], $riga['active'], $riga['nlist'], askMilter($myconn,$i,$element,$typedesc,$riga['idmilt'],$riga['miltnames'],$user,$adm), $riga['user'],htmlspecialchars($riga['reason']),ask($myconn,$i,$listed,$tables,$typedesc,$element,$full,$user,$adm)); |
| 437 | - else |
|
| 438 | - 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", |
|
| 465 | + } else { |
|
| 466 | + 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", |
|
| 439 | 467 | $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)); |
| 468 | + } |
|
| 440 | 469 | $i++; |
| 441 | 470 | } |
| 442 | 471 | print '</tbody></table>'; |
| 443 | - } |
|
| 444 | - else { |
|
| 472 | + } else { |
|
| 445 | 473 | print "<pre>$type <$value> is not listed!\n</pre>"; |
| 446 | - if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) |
|
| 447 | - if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 448 | - else print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 474 | + if ( in_array($user,array_keys($adm)) AND ($value != 'ALL') ) { |
|
| 475 | + if ( (!$full) AND (consistentListing($myconn,$tables,$typedesc,$value,$whynot)) ) require_once('listForm.php'); |
|
| 476 | + } else { |
|
| 477 | + print '<p>'.htmlspecialchars($whynot).'</p>'; |
|
| 478 | + } |
|
| 449 | 479 | |
| 450 | 480 | } |
| 451 | 481 | $result->free(); |
| 482 | + } else { |
|
| 483 | + print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 484 | + } |
|
| 452 | 485 | } |
| 453 | - else print '<pre>Query error or something wrong in DB schema'."\n</pre>"; |
|
| 454 | -} |
|
| 455 | 486 | |
| 456 | 487 | |
| 457 | 488 | |
@@ -494,24 +525,32 @@ discard block |
||
| 494 | 525 | $old_mailfrom = ini_get("sendmail_from"); |
| 495 | 526 | ini_set("sendmail_from", $from); |
| 496 | 527 | $params = sprintf("-oi -f %s", '<>'); |
| 497 | - if (!(mail($to,$sbj, $body,$headers,$params))) $flag=FALSE; |
|
| 498 | - else $flag=TRUE; |
|
| 499 | - if (isset($old_mailfrom)) |
|
| 500 | - ini_set("sendmail_from", $old_mailfrom); |
|
| 501 | - } |
|
| 502 | - else { |
|
| 503 | - if (!(mail($to,$sbj, $body,$headers))) $flag=FALSE; |
|
| 504 | - else $flag=TRUE; |
|
| 528 | + if (!(mail($to,$sbj, $body,$headers,$params))) { |
|
| 529 | + $flag=FALSE; |
|
| 530 | + } else { |
|
| 531 | + $flag=TRUE; |
|
| 532 | + } |
|
| 533 | + if (isset($old_mailfrom)) { |
|
| 534 | + ini_set("sendmail_from", $old_mailfrom); |
|
| 535 | + } |
|
| 536 | + } else { |
|
| 537 | + if (!(mail($to,$sbj, $body,$headers))) { |
|
| 538 | + $flag=FALSE; |
|
| 539 | + } else { |
|
| 540 | + $flag=TRUE; |
|
| 541 | + } |
|
| 505 | 542 | } |
| 506 | 543 | return $flag; |
| 507 | 544 | } |
| 508 | 545 | |
| 509 | 546 | function emailToNotify($notify_file,$dom) { |
| 510 | 547 | $ini_array = parse_ini_file($notify_file); |
| 511 | - if (in_array($dom,array_keys($ini_array))) |
|
| 512 | - return $ini_array["$dom"]; |
|
| 513 | - else return FALSE; |
|
| 514 | -} |
|
| 548 | + if (in_array($dom,array_keys($ini_array))) { |
|
| 549 | + return $ini_array["$dom"]; |
|
| 550 | + } else { |
|
| 551 | + return FALSE; |
|
| 552 | + } |
|
| 553 | + } |
|
| 515 | 554 | |
| 516 | 555 | |
| 517 | 556 | function searchAndList ($myconn,$loguser,$tables,$typedesc,$value,$unit,&$quantity,$reason) { |
@@ -588,9 +627,10 @@ discard block |
||
| 588 | 627 | $net = new \dautkom\ipv4\IPv4(); |
| 589 | 628 | $range = $net->address($addressA)->mask($maskA)->getRange(); |
| 590 | 629 | $ips = ipRange($range); |
| 591 | - foreach ( $ips as $ip ) |
|
| 592 | - if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 630 | + foreach ( $ips as $ip ) { |
|
| 631 | + if ( $net->address($addressB)->mask($maskB)->has($ip) ) |
|
| 593 | 632 | return TRUE; |
| 633 | + } |
|
| 594 | 634 | return FALSE; |
| 595 | 635 | } |
| 596 | 636 | |
@@ -667,8 +707,9 @@ discard block |
||
| 667 | 707 | return FALSE; |
| 668 | 708 | } |
| 669 | 709 | if ($result->num_rows) { |
| 670 | - while ($milt = $result->fetch_array(MYSQLI_ASSOC)) |
|
| 671 | - $milters[] = $milt['name']; |
|
| 710 | + while ($milt = $result->fetch_array(MYSQLI_ASSOC)) { |
|
| 711 | + $milters[] = $milt['name']; |
|
| 712 | + } |
|
| 672 | 713 | } |
| 673 | 714 | $result->free(); |
| 674 | 715 | return $milters; |
@@ -694,12 +735,14 @@ discard block |
||
| 694 | 735 | $query[] = "DELETE FROM `milt` WHERE (`id` = '$miltID' AND `name` = '$value')"; |
| 695 | 736 | } |
| 696 | 737 | } |
| 697 | - if ( count($query) ) /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 738 | + if ( count($query) ) { |
|
| 739 | + /* This "if" is redundant, because if I call this I already checked there is a change */ |
|
| 698 | 740 | /* I update datemod because the user couldn't change */ |
| 699 | 741 | $query[] = sprintf('UPDATE `%s` SET |
| 700 | 742 | `user`=\'%s\', |
| 701 | 743 | `datemod`= CURRENT_TIMESTAMP |
| 702 | 744 | WHERE `idmilt`=%d', $table, $loguser, $miltID); |
| 745 | + } |
|
| 703 | 746 | |
| 704 | 747 | |
| 705 | 748 | /* Start a safe transaction: it commits only if all queries happen */ |
@@ -713,19 +756,20 @@ discard block |
||
| 713 | 756 | } |
| 714 | 757 | } |
| 715 | 758 | if ( $ok ) { |
| 716 | - if ( $myconn->commit() ) |
|
| 717 | - syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
| 718 | - else { |
|
| 759 | + if ( $myconn->commit() ) { |
|
| 760 | + syslog(LOG_INFO, "$loguser: Milter setting changed successfully."); |
|
| 761 | + } else { |
|
| 719 | 762 | syslog(LOG_ERR, "$loguser: Milter setting NOT changed for an unpredictable COMMIT error."); |
| 720 | - if ( $myconn->rollback() ) |
|
| 721 | - syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
| 722 | - else |
|
| 723 | - syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
| 763 | + if ( $myconn->rollback() ) { |
|
| 764 | + syslog(LOG_INFO, "$loguser: rollback succeeded."); |
|
| 765 | + } else { |
|
| 766 | + syslog(LOG_ERR, "$loguser: rollback failed. Your db could be compromized. Check it!"); |
|
| 767 | + } |
|
| 724 | 768 | $ok = FALSE; |
| 725 | 769 | } |
| 770 | + } else { |
|
| 771 | + syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
| 726 | 772 | } |
| 727 | - else |
|
| 728 | - syslog(LOG_ERR, "$loguser: Error: Milter setting NOT changed. See at above errors."); |
|
| 729 | 773 | return $ok; |
| 730 | 774 | |
| 731 | 775 | } |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | if (! empty($old) ) { |
| 46 | 46 | foreach ($old as $item) { |
| 47 | - if (! in_array($item, $new) ) { |
|
| 48 | - $values["$item"] = 'del'; |
|
| 47 | + if (! in_array($item, $new) ) { |
|
| 48 | + $values["$item"] = 'del'; |
|
| 49 | 49 | $logs[] = "<$item>: ". $values["$item"]; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | /* Store new values */ |
| 65 | 65 | if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
| 66 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 66 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 67 | 67 | |
| 68 | 68 | if (changeMilter ($mysqli,$user,$values,$col,$_POST['miltId'])) |
| 69 | 69 | print 'OK milter setting changed.'; |
@@ -1,10 +1,10 @@ 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 | $col = milterTable($type); |
| 7 | -if ( $col === FALSE ) |
|
| 7 | +if ($col === FALSE) |
|
| 8 | 8 | exit ("<p>Error in you config at field <b>$type</b>.</p>"); |
| 9 | 9 | ?> |
| 10 | 10 | <td colspan="10" style="text-align: center"> |
@@ -18,54 +18,54 @@ discard block |
||
| 18 | 18 | $new = $_POST['newvalues']; |
| 19 | 19 | else |
| 20 | 20 | $new = array(); |
| 21 | -if (! empty($_POST['oldvalues'])) |
|
| 21 | +if (!empty($_POST['oldvalues'])) |
|
| 22 | 22 | $old = explode(',', $_POST['oldvalues']); |
| 23 | 23 | else |
| 24 | - $old=array(); |
|
| 25 | -$values=array(); |
|
| 26 | -$logs=array(); |
|
| 24 | + $old = array(); |
|
| 25 | +$values = array(); |
|
| 26 | +$logs = array(); |
|
| 27 | 27 | |
| 28 | 28 | print '<pre>'; |
| 29 | 29 | /* Check need to disable all milters, removing unnecessary setting */ |
| 30 | -if ( in_array('DISABLE ALL', $new) ) |
|
| 30 | +if (in_array('DISABLE ALL', $new)) |
|
| 31 | 31 | $new = array('DISABLE ALL'); |
| 32 | 32 | |
| 33 | 33 | /* Compare the values determining what to do */ |
| 34 | 34 | if (count(array_diff(array_merge($new, $old), array_intersect($new, $old))) !== 0) { |
| 35 | 35 | /* New and old are different (we assume we don't have duplicate values) */ |
| 36 | - if (! empty($new) ) { |
|
| 36 | + if (!empty($new)) { |
|
| 37 | 37 | foreach ($new as $item) { |
| 38 | - if ( in_array($item, $old) ) |
|
| 38 | + if (in_array($item, $old)) |
|
| 39 | 39 | $values["$item"] = 'keep'; |
| 40 | 40 | else |
| 41 | 41 | $values["$item"] = 'add'; |
| 42 | - $logs[] = "<$item>: ". $values["$item"]; |
|
| 42 | + $logs[] = "<$item>: ".$values["$item"]; |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | - if (! empty($old) ) { |
|
| 45 | + if (!empty($old)) { |
|
| 46 | 46 | foreach ($old as $item) { |
| 47 | - if (! in_array($item, $new) ) { |
|
| 47 | + if (!in_array($item, $new)) { |
|
| 48 | 48 | $values["$item"] = 'del'; |
| 49 | - $logs[] = "<$item>: ". $values["$item"]; |
|
| 49 | + $logs[] = "<$item>: ".$values["$item"]; |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /* Logging */ |
| 56 | -if ( empty($values) ) |
|
| 56 | +if (empty($values)) |
|
| 57 | 57 | print 'No values to change.'; |
| 58 | 58 | else { |
| 59 | - $msg = sprintf('%s: Changing Milter setting on list <%s> for %s <%s>.',$user,$typedesc,$type, $_POST['object']); |
|
| 59 | + $msg = sprintf('%s: Changing Milter setting on list <%s> for %s <%s>.', $user, $typedesc, $type, $_POST['object']); |
|
| 60 | 60 | syslog(LOG_INFO, $msg); |
| 61 | 61 | foreach ($logs as $log) |
| 62 | 62 | syslog(LOG_INFO, "$user: milter $log"); |
| 63 | 63 | |
| 64 | 64 | /* Store new values */ |
| 65 | - if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 66 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 65 | + if (($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE) |
|
| 66 | + exit ($user.': Connect Error ('.$mysqli->connect_errno.') '.$mysqli->connect_error); |
|
| 67 | 67 | |
| 68 | - if (changeMilter ($mysqli,$user,$values,$col,$_POST['miltId'])) |
|
| 68 | + if (changeMilter($mysqli, $user, $values, $col, $_POST['miltId'])) |
|
| 69 | 69 | print 'OK milter setting changed.'; |
| 70 | 70 | else |
| 71 | 71 | print 'ERROR updating milter setting; check your syslog. No changes made.'; |
@@ -4,8 +4,9 @@ discard block |
||
| 4 | 4 | $typedesc=$_POST['type']; |
| 5 | 5 | $type = $tables["$typedesc"]['field']; |
| 6 | 6 | $col = milterTable($type); |
| 7 | -if ( $col === FALSE ) |
|
| 7 | +if ( $col === FALSE ) { |
|
| 8 | 8 | exit ("<p>Error in you config at field <b>$type</b>.</p>"); |
| 9 | +} |
|
| 9 | 10 | ?> |
| 10 | 11 | <td colspan="10" style="text-align: center"> |
| 11 | 12 | |
@@ -14,31 +15,35 @@ discard block |
||
| 14 | 15 | $user = $_POST['user']; |
| 15 | 16 | |
| 16 | 17 | /* Compare old values with new ones */ |
| 17 | -if (isset($_POST['newvalues'])) |
|
| 18 | +if (isset($_POST['newvalues'])) { |
|
| 18 | 19 | $new = $_POST['newvalues']; |
| 19 | -else |
|
| 20 | +} else { |
|
| 20 | 21 | $new = array(); |
| 21 | -if (! empty($_POST['oldvalues'])) |
|
| 22 | +} |
|
| 23 | +if (! empty($_POST['oldvalues'])) { |
|
| 22 | 24 | $old = explode(',', $_POST['oldvalues']); |
| 23 | -else |
|
| 25 | +} else { |
|
| 24 | 26 | $old=array(); |
| 27 | +} |
|
| 25 | 28 | $values=array(); |
| 26 | 29 | $logs=array(); |
| 27 | 30 | |
| 28 | 31 | print '<pre>'; |
| 29 | 32 | /* Check need to disable all milters, removing unnecessary setting */ |
| 30 | -if ( in_array('DISABLE ALL', $new) ) |
|
| 33 | +if ( in_array('DISABLE ALL', $new) ) { |
|
| 31 | 34 | $new = array('DISABLE ALL'); |
| 35 | +} |
|
| 32 | 36 | |
| 33 | 37 | /* Compare the values determining what to do */ |
| 34 | 38 | if (count(array_diff(array_merge($new, $old), array_intersect($new, $old))) !== 0) { |
| 35 | 39 | /* New and old are different (we assume we don't have duplicate values) */ |
| 36 | 40 | if (! empty($new) ) { |
| 37 | 41 | foreach ($new as $item) { |
| 38 | - if ( in_array($item, $old) ) |
|
| 39 | - $values["$item"] = 'keep'; |
|
| 40 | - else |
|
| 41 | - $values["$item"] = 'add'; |
|
| 42 | + if ( in_array($item, $old) ) { |
|
| 43 | + $values["$item"] = 'keep'; |
|
| 44 | + } else { |
|
| 45 | + $values["$item"] = 'add'; |
|
| 46 | + } |
|
| 42 | 47 | $logs[] = "<$item>: ". $values["$item"]; |
| 43 | 48 | } |
| 44 | 49 | } |
@@ -53,22 +58,25 @@ discard block |
||
| 53 | 58 | } |
| 54 | 59 | |
| 55 | 60 | /* Logging */ |
| 56 | -if ( empty($values) ) |
|
| 61 | +if ( empty($values) ) { |
|
| 57 | 62 | print 'No values to change.'; |
| 58 | -else { |
|
| 63 | +} else { |
|
| 59 | 64 | $msg = sprintf('%s: Changing Milter setting on list <%s> for %s <%s>.',$user,$typedesc,$type, $_POST['object']); |
| 60 | 65 | syslog(LOG_INFO, $msg); |
| 61 | - foreach ($logs as $log) |
|
| 62 | - syslog(LOG_INFO, "$user: milter $log"); |
|
| 66 | + foreach ($logs as $log) { |
|
| 67 | + syslog(LOG_INFO, "$user: milter $log"); |
|
| 68 | + } |
|
| 63 | 69 | |
| 64 | 70 | /* Store new values */ |
| 65 | - if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 66 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 71 | + if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
| 72 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 73 | + } |
|
| 67 | 74 | |
| 68 | - if (changeMilter ($mysqli,$user,$values,$col,$_POST['miltId'])) |
|
| 69 | - print 'OK milter setting changed.'; |
|
| 70 | - else |
|
| 71 | - print 'ERROR updating milter setting; check your syslog. No changes made.'; |
|
| 75 | + if (changeMilter ($mysqli,$user,$values,$col,$_POST['miltId'])) { |
|
| 76 | + print 'OK milter setting changed.'; |
|
| 77 | + } else { |
|
| 78 | + print 'ERROR updating milter setting; check your syslog. No changes made.'; |
|
| 79 | + } |
|
| 72 | 80 | |
| 73 | 81 | $mysqli->close(); |
| 74 | 82 | } |
@@ -1,18 +1,18 @@ |
||
| 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 | -if ( $tables["$typedesc"]['milter'] ) { |
|
| 6 | - if ( checkMilterConf($tables["$typedesc"]) ) |
|
| 5 | +if ($tables["$typedesc"]['milter']) { |
|
| 6 | + if (checkMilterConf($tables["$typedesc"])) |
|
| 7 | 7 | print '<p>This is a milter table. Please, first add your item as usual. Then you will be able to customize the milter settings.</p>'; |
| 8 | 8 | else { |
| 9 | 9 | $err = "Error in config about <$typedesc>. Check at your config.php."; |
| 10 | - syslog (LOG_EMERG, $err); |
|
| 11 | - printf ('<p>%s</p>', htmlspecialchars($err) ); |
|
| 10 | + syslog(LOG_EMERG, $err); |
|
| 11 | + printf('<p>%s</p>', htmlspecialchars($err)); |
|
| 12 | 12 | } |
| 13 | 13 | } |
| 14 | 14 | ?> |
| 15 | 15 | <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;" /> |
| 16 | 16 | |
| 17 | 17 | 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; ?>" /> |
| 18 | - <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> |
|
| 18 | + <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> |
|
@@ -1,11 +1,14 @@ |
||
| 1 | 1 | <?php |
| 2 | -if (in_array($user,array_keys(array_filter($adm)))) $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
| 3 | -else $extopt = NULL; |
|
| 2 | +if (in_array($user,array_keys(array_filter($adm)))) { |
|
| 3 | + $extopt = '<option value="MONTH">MONTHS</option><option value="YEAR">YEARS</option>'; |
|
| 4 | +} else { |
|
| 5 | + $extopt = NULL; |
|
| 6 | +} |
|
| 4 | 7 | |
| 5 | 8 | if ( $tables["$typedesc"]['milter'] ) { |
| 6 | - if ( checkMilterConf($tables["$typedesc"]) ) |
|
| 7 | - print '<p>This is a milter table. Please, first add your item as usual. Then you will be able to customize the milter settings.</p>'; |
|
| 8 | - else { |
|
| 9 | + if ( checkMilterConf($tables["$typedesc"]) ) { |
|
| 10 | + print '<p>This is a milter table. Please, first add your item as usual. Then you will be able to customize the milter settings.</p>'; |
|
| 11 | + } else { |
|
| 9 | 12 | $err = "Error in config about <$typedesc>. Check at your config.php."; |
| 10 | 13 | syslog (LOG_EMERG, $err); |
| 11 | 14 | printf ('<p>%s</p>', htmlspecialchars($err) ); |
@@ -11,11 +11,11 @@ |
||
| 11 | 11 | openlog($tag, LOG_PID, $fac); |
| 12 | 12 | if (empty($_POST['reason'])) die ("Specify a reason, please!</td>"); |
| 13 | 13 | if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) |
| 14 | - exit('ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</td>'); |
|
| 14 | + exit('ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</td>'); |
|
| 15 | 15 | $user = username(); |
| 16 | 16 | |
| 17 | 17 | if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
| 18 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 18 | + exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 19 | 19 | |
| 20 | 20 | if (isFull($mysqli,$typedesc,$tables)) die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.') ); |
| 21 | 21 | if (relist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) |
@@ -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"]['milter']) ? milterTable($type) : $tables["$typedesc"]['name']; |
| 7 | 7 | $cl = ($tables["$typedesc"]['milter']) ? 10 : 9; |
@@ -10,15 +10,15 @@ discard block |
||
| 10 | 10 | <?php |
| 11 | 11 | openlog($tag, LOG_PID, $fac); |
| 12 | 12 | if (empty($_POST['reason'])) die ("Specify a reason, please!</td>"); |
| 13 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) |
|
| 14 | - exit('ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</td>'); |
|
| 13 | +if (preg_match('/[^\x20-\x7f]/', $_POST['reason'])) |
|
| 14 | + exit('ERROR: <'.htmlentities($_POST['reason'], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</td>'); |
|
| 15 | 15 | $user = username(); |
| 16 | 16 | |
| 17 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 18 | - exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
|
| 17 | +if (($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE) |
|
| 18 | + exit ($user.': Connect Error ('.$mysqli->connect_errno.') '.$mysqli->connect_error); |
|
| 19 | 19 | |
| 20 | -if (isFull($mysqli,$typedesc,$tables)) die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.') ); |
|
| 21 | -if (relist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) |
|
| 20 | +if (isFull($mysqli, $typedesc, $tables)) die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.')); |
|
| 21 | +if (relist($mysqli, username(), $_POST['value'], $type, $table, $_POST['unit'], $_POST['quantity'], $_POST['reason'])) |
|
| 22 | 22 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> relisted for '.$_POST['quantity'].$_POST['unit']; |
| 23 | 23 | else |
| 24 | 24 | print 'ERROR in relist; check log'; |
@@ -9,19 +9,26 @@ |
||
| 9 | 9 | <td colspan="<?php echo $cl; ?>" style="text-align: center"> |
| 10 | 10 | <?php |
| 11 | 11 | openlog($tag, LOG_PID, $fac); |
| 12 | -if (empty($_POST['reason'])) die ("Specify a reason, please!</td>"); |
|
| 13 | -if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) |
|
| 12 | +if (empty($_POST['reason'])) { |
|
| 13 | + die ("Specify a reason, please!</td>"); |
|
| 14 | +} |
|
| 15 | +if (preg_match( '/[^\x20-\x7f]/', $_POST['reason'])) { |
|
| 14 | 16 | exit('ERROR: <'.htmlentities($_POST['reason'],ENT_COMPAT | ENT_HTML401, 'ISO-8859-1').'> contains NON ASCII chars.</td>'); |
| 17 | +} |
|
| 15 | 18 | $user = username(); |
| 16 | 19 | |
| 17 | -if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
| 20 | +if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) { |
|
| 18 | 21 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
| 22 | +} |
|
| 19 | 23 | |
| 20 | -if (isFull($mysqli,$typedesc,$tables)) die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.') ); |
|
| 21 | -if (relist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) |
|
| 24 | +if (isFull($mysqli,$typedesc,$tables)) { |
|
| 25 | + die("ERROR in relist: ".htmlspecialchars("$typedesc has reached maximum value of ".$tables["$typedesc"]['limit'].' listed items.') ); |
|
| 26 | +} |
|
| 27 | +if (relist ($mysqli,username(),$_POST['value'],$type,$table,$_POST['unit'],$_POST['quantity'],$_POST['reason'])) { |
|
| 22 | 28 | print 'OK '.$_POST["type"].' <'.$_POST['value'].'> relisted for '.$_POST['quantity'].$_POST['unit']; |
| 23 | -else |
|
| 29 | +} else { |
|
| 24 | 30 | print 'ERROR in relist; check log'; |
| 31 | +} |
|
| 25 | 32 | $mysqli->close(); |
| 26 | 33 | closelog(); |
| 27 | 34 | print '</td>'; |