summaryrefslogtreecommitdiff
path: root/scripts/cron/permissionreview.php
blob: c35787d93f639768f89840b7ece45b9da95cffdf (plain)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/php -q
<?php
/*
LibreSSL - CAcert web application
Copyright (C) 2004-2012  CAcert Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

require_once(dirname(__FILE__).'/../../includes/mysql.php');

$BOARD_PRIVATE = 'cacert-board-private@lists.cacert.org';
$ASSURANCE_OFFICER = 'ao@cacert.org';
$ORGANISATION_ASSURANCE_OFFICER = 'oao@cacert.org';


//defines to whom to send the lists
$flags = array(
	'admin' => array(
			'name'    => 'Support Engineer',
			'own'     => false, //Don't send twice
			'board'   => true,
			'support' => true,
			'ao'      => false,
			'oao'     => false
			),
	
	'orgadmin' => array(
			'name'    => 'Organisation Assurer',
			'own'     => true,
			'board'   => true,
			'support' => true,
			'ao'      => true,
			'oao'     => true
			),
	
	'board' => array(
			'name'    => 'Board Member',
			'own'     => false,
			'board'   => true,
			'support' => true,
			'ao'      => true,
			'oao'     => false
			),
	
	'ttpadmin' => array(
			'name'    => 'Trusted Third Party Admin',
			'own'     => true,
			'board'   => true,
			'support' => true,
			'ao'      => true,
			'oao'     => true
			),
	
	'tverify' => array(
			'name'    => 'Tverify Admin',
			'own'     => false,
			'board'   => true,
			'support' => true,
			'ao'      => true,
			'oao'     => false
			),
	
	'locadmin' => array(
			'name'    => 'Location Admin',
			'own'     => false,
			'board'   => true,
			'support' => true,
			'ao'      => false,
			'oao'     => false
			),
	);


// Build up list of various admins
$adminlist = array();
foreach ($flags as $flag => $flag_properties) {
	$query = "select `fname`, `lname`, `email` from `users` where `$flag` = 1";
	if(! $res = mysql_query($query) ) {
		fwrite(STDERR,
				"MySQL query for flag $flag failed:\n".
				"\"$query\"\n".
				mysql_error()
			);
		
		continue;
	}
	
	$adminlist[$flag] = array();
	
	while ($row = mysql_fetch_assoc($res)) {
		$adminlist[$flag][] = $row;
	}
	
	
	// Send mail to admins of this group if 'own' is set
	if ($flag_properties['own']) {
		foreach ($adminlist[$flag] as $admin) {
			$message = <<<EOF
Hello $admin[fname],

you get this message, because you are listed as $flag_properties[name] on
CAcert.org. Please review the following list of persons with the same privilege
and report to the responsible team leader or board
($BOARD_PRIVATE) if you spot any errors.


EOF;
			
			foreach ($adminlist[$flag] as $colleague) {
				$message .= "$colleague[fname] $colleague[lname] $colleague[email]\n";
			}
			
			$message .= <<<EOF


Best Regards,
CAcert Support
EOF;
			
			sendmail($admin['email'], "Permissions Review", $message, 'support@cacert.org');
		}
	}
}



// Send to support engineers
$message = <<<EOF
Dear Support Engineers,

it's time for the permission review again. Here is the list of privileged users
in the CAcert web application. Please review them.


EOF;

foreach ($flags as $flag => $flag_properties) {
	if ($flag_properties['support']) {
		$message .= "List of $flag_properties[name]s:\n";
		foreach ($adminlist[$flag] as $colleague) {
			$message .= "$colleague[fname] $colleague[lname] $colleague[email]\n";
		}
	}
}

$message .= <<<EOF

Best Regards,
CAcert Support
EOF;

foreach ($adminlist['admin'] as $support_engineer) {
	sendmail(
			$support_engineer['email'],
			"Permissions Review",
			$message,
			'support@cacert.org');
}


// Send to one-email addresses
foreach (array(
			'ao' => array(
					'description' => 'Assurance Officer',
					'email' => $ASSURANCE_OFFICER),
			'oao' => array(
					'description' => 'Organisation Assurance Officer',
					'email' => $ORGANISATION_ASSURANCE_OFFICER),
			'board' => array(
					'description' => 'Board Members',
					'email' => $BOARD_PRIVATE)
		) as $key => $values) {
	$message = <<<EOF
Dear $values[description],

it's time for the permission review again. Here is the list of privileged users
in the CAcert web application. Please review them and also ask the persons 
responsible for an up-to-date copy of access lists not directly recorded in the
web application (critical admins, software assessors etc.) 



EOF;
	
	foreach ($flags as $flag => $flag_properties) {
		if ($flag_properties[$key]) {
			$message .= "List of $flag_properties[name]s:\n\n";
			foreach ($adminlist[$flag] as $colleague) {
				$message .= "$colleague[fname] $colleague[lname] $colleague[email]\n";
			}
		}
	}
	
	$message .= <<<EOF


Best Regards,
CAcert Support
EOF;
	
	sendmail($values['email'], "Permissions Review", $message, 'support@cacert.org');
}