-
Notifications
You must be signed in to change notification settings - Fork 10
/
changeMilter.php
80 lines (70 loc) · 2.13 KB
/
changeMilter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
require_once('config.php');
require_once('function.php');
$typedesc=$_POST['type'];
$type = $tables["$typedesc"]['field'];
$col = milterTable($type);
if ( $col === FALSE )
exit ("<p>Error in you config at field <b>$type</b>.</p>");
?>
<td colspan="10" style="text-align: center">
<?php
openlog($tag, LOG_PID, $fac);
$user = $_POST['user'];
/* Compare old values with new ones */
if (isset($_POST['newvalues']))
$new = $_POST['newvalues'];
else
$new = array();
if (! empty($_POST['oldvalues']))
$old = explode(',', $_POST['oldvalues']);
else
$old=array();
$values=array();
$logs=array();
print '<pre>';
/* Check need to disable all milters, removing unnecessary setting */
if ( in_array('DISABLE ALL', $new) )
$new = array('DISABLE ALL');
/* Compare the values determining what to do */
if (count(array_diff(array_merge($new, $old), array_intersect($new, $old))) !== 0) {
/* New and old are different (we assume we don't have duplicate values) */
if (! empty($new) ) {
foreach ($new as $item) {
if ( in_array($item, $old) )
$values["$item"] = 'keep';
else
$values["$item"] = 'add';
$logs[] = "<$item>: ". $values["$item"];
}
}
if (! empty($old) ) {
foreach ($old as $item) {
if (! in_array($item, $new) ) {
$values["$item"] = 'del';
$logs[] = "<$item>: ". $values["$item"];
}
}
}
}
/* Logging */
if ( empty($values) )
print 'No values to change.';
else {
$msg = sprintf('%s: Changing Milter setting on list <%s> for %s <%s>.',$user,$typedesc,$type, $_POST['object']);
syslog(LOG_INFO, $msg);
foreach ($logs as $log)
syslog(LOG_INFO, "$user: milter $log");
/* Store new values */
if ( ($mysqli = myConnect($dbhost, $userdb, $pwd, $db, $dbport, $tables, $typedesc, $user)) === FALSE )
exit ($user.': Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error);
if (changeMilter ($mysqli,$user,$values,$col,$_POST['miltId']))
print 'OK milter setting changed.';
else
print 'ERROR updating milter setting; check your syslog. No changes made.';
$mysqli->close();
}
print ' To view the current status click again the "Check" button above.';
closelog();
?>
</td>