These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | require_once('config.php'); |
||
3 | require_once('function.php'); |
||
4 | $typedesc=$_POST['type']; |
||
5 | $type = $tables["$typedesc"]['field']; |
||
6 | $col = milterTable($type); |
||
7 | if ( $col === FALSE ) |
||
8 | exit ("<p>Error in you config at field <b>$type</b>.</p>"); |
||
9 | ?> |
||
10 | <td colspan="10" style="text-align: center"> |
||
11 | |||
12 | <?php |
||
13 | openlog($tag, LOG_PID, $fac); |
||
14 | $user = $_POST['user']; |
||
15 | |||
16 | /* Compare old values with new ones */ |
||
17 | if (isset($_POST['newvalues'])) |
||
18 | $new = $_POST['newvalues']; |
||
19 | else |
||
20 | $new = array(); |
||
21 | if (! empty($_POST['oldvalues'])) |
||
22 | $old = explode(',', $_POST['oldvalues']); |
||
23 | else |
||
24 | $old=array(); |
||
25 | $values=array(); |
||
26 | $logs=array(); |
||
27 | |||
28 | print '<pre>'; |
||
29 | /* Check need to disable all milters, removing unnecessary setting */ |
||
30 | if ( in_array('DISABLE ALL', $new) ) |
||
31 | $new = array('DISABLE ALL'); |
||
32 | |||
33 | /* Compare the values determining what to do */ |
||
34 | if (count(array_diff(array_merge($new, $old), array_intersect($new, $old))) !== 0) { |
||
35 | /* New and old are different (we assume we don't have duplicate values) */ |
||
36 | if (! empty($new) ) { |
||
37 | foreach ($new as $item) { |
||
38 | View Code Duplication | if ( in_array($item, $old) ) |
|
0 ignored issues
–
show
|
|||
39 | $values["$item"] = 'keep'; |
||
40 | else |
||
41 | $values["$item"] = 'add'; |
||
42 | $logs[] = "<$item>: ". $values["$item"]; |
||
43 | } |
||
44 | } |
||
45 | if (! empty($old) ) { |
||
46 | foreach ($old as $item) { |
||
47 | View Code Duplication | if (! in_array($item, $new) ) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
48 | $values["$item"] = 'del'; |
||
49 | $logs[] = "<$item>: ". $values["$item"]; |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | |||
55 | /* Logging */ |
||
56 | if ( empty($values) ) |
||
57 | print 'No values to change.'; |
||
58 | else { |
||
59 | $msg = sprintf('%s: Changing Milter setting on list <%s> for %s <%s>.',$user,$typedesc,$type, $_POST['object']); |
||
60 | syslog(LOG_INFO, $msg); |
||
61 | foreach ($logs as $log) |
||
62 | syslog(LOG_INFO, "$user: milter $log"); |
||
63 | |||
64 | /* Store new values */ |
||
65 | View Code Duplication | if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE ) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
66 | exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error); |
||
67 | |||
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.'; |
||
72 | |||
73 | $mysqli->close(); |
||
74 | } |
||
75 | |||
76 | print ' To view the current status click again the "Check" button above.'; |
||
77 | closelog(); |
||
78 | ?> |
||
79 | |||
80 | </td> |
||
81 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.