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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
<?
/* RemSaint
*
* (c) 2002 Peter Palfrader <pp@3node.com>
*/
/**
* RemSaint
*
* @author Peter Palfrader/3node
* @version $Id$
*/
require_once("../include/Namespace.inc");
require_once("../include/Tools.inc");
require_once("../include/Template.inc");
$namespace = new Namespace(
array( have_database => 1,
have_session => 1,
have_user => 1 )
) or
die("Nobody loves me. I don't even have space for a name.");
$message = '';
$username = '';
if (! $namespace->user->check_login()) {
$message = 'Not logged in. Nothing done.';
} else {
$username = $namespace->session->data['user']['username'];
$rules = Array();
$rules['subscription']['ref'] = array(type => 'anything');
$refs = param_check($GLOBALS, $rules);
$rules = Array();
foreach ($refs['ref'] as $ref) {
if (! is_int($ref + 0) ) {
$message = 'Wrong refs';
break;
} else {
$rules['subscription']['warning_'.$ref] = array(type => 'boolean');
$rules['subscription']['critical_'.$ref] = array(type => 'boolean');
$rules['subscription']['recovery_'.$ref] = array(type => 'boolean');
};
};
if ($message == '') {
$arguments = param_check($GLOBALS, $rules);
$user_ref = $namespace->session->data['user']['ref'];
foreach ($refs['ref'] as $ref) {
if ($arguments['warning_'.$ref] ||
$arguments['critical_'.$ref] ||
$arguments['recovery_'.$ref])
$user_subs[$ref] = array (
notify_warning => $arguments['warning_'.$ref],
notify_critical => $arguments['critical_'.$ref],
notify_recovery => $arguments['recovery_'.$ref],
);
}
$db_subs = $namespace->database->query_all("SELECT remailer.nick, subscription.ref, subscription.remailer_ref, subscription.notify_warning, subscription.notify_critical, subscription.notify_recovery FROM remailer JOIN subscription ON remailer.ref=subscription.remailer_ref WHERE subscription.account_ref=?", array($user_ref));
foreach ($db_subs as $sub) {
if (isset ($user_subs[$sub['remailer_ref']])) {
$user_sub = $user_subs[$sub['remailer_ref']];
$sub['notify_warning'] = $sub['notify_warning'] == 't' ? 1 : false;
$sub['notify_critical'] = $sub['notify_critical'] == 't' ? 1 : false;
$sub['notify_recovery'] = $sub['notify_recovery'] == 't' ? 1 : false;
if (($sub['notify_warning'] == $user_sub['notify_warning']) &&
($sub['notify_critical'] == $user_sub['notify_critical']) &&
($sub['notify_recovery'] == $user_sub['notify_recovery'])) {
$message .= 'Not changing subscription to remailer '.$sub['nick'].".<BR>\n";
} else {
$user = ($user_sub['notify_warning'] ? 'W' : '_') .
($user_sub['notify_critical'] ? 'C' : '_') .
($user_sub['notify_recovery'] ? 'R' : '_');
$db = ($sub['notify_warning'] ? 'W' : '_') .
($sub['notify_critical'] ? 'C' : '_') .
($sub['notify_recovery'] ? 'R' : '_');
$message .= 'Changing subscription to remailer '.$sub['nick']." from $db to $user: ";
$s = array();
$s['notify_warning'] = $user_sub['notify_warning'] ? 'T' : 'F';
$s['notify_critical'] = $user_sub['notify_critical'] ? 'T' : 'F';
$s['notify_recovery'] = $user_sub['notify_recovery'] ? 'T' : 'F';
$res = $namespace->database->update('subscription', $sub['ref'], $s);
$message .= ($res ? 'OK' : 'FAILED')."<BR>\n";
}
} else {
$message .= 'Deleting subscription to remailer '.$sub['nick'].': ';
$res = $namespace->database->delete_row('subscription', $sub['ref']);
$message .= ($res ? 'OK' : 'FAILED')."<BR>\n";
};
unset($user_subs[$sub['remailer_ref']]);
}
foreach ($user_subs as $ref => $sub) {
$rem = $namespace->database->query_row("SELECT remailer.nick FROM remailer WHERE ref=?", array($ref));
if ($rem) {
$s = array();
$s['remailer_ref'] = $ref;
$s['account_ref'] = $user_ref;
$s['notify_warning'] = $sub['notify_warning'] ? 'T' : 'F';
$s['notify_critical'] = $sub['notify_critical'] ? 'T' : 'F';
$s['notify_recovery'] = $sub['notify_recovery'] ? 'T' : 'F';
$message .= 'Adding subscription to remailer '.$rem['nick'].': ';
$res = $namespace->database->insert('subscription', $s);
$message .= ($res ? 'OK' : 'FAILED')."<BR>\n";
} else {
$message .= 'Remailer '.$rem."does not exist.<BR>\n";
}
}
$message .= 'done.<BR>';
}
}
$data = array();
$data['message'] = $message;
$data['user'] = $username;
$template = new Template('remsaint-subscription.html', $namespace->config->template_path);
$template->parse($data);
print $template->output();
$namespace->stop();
# vim:set ts=4:
# vim:set shiftwidth=4:
?>
|