File inc/admin.inc.php changed (mode: 100644) (index 2cabba6..af420bb) |
... |
... |
$rg_admin_functions = array( |
12 |
12 |
6001 => "rg_admin_invite_one", |
6001 => "rg_admin_invite_one", |
13 |
13 |
// new new style |
// new new style |
14 |
14 |
'admin_invite' => 'rg_admin_invite', |
'admin_invite' => 'rg_admin_invite', |
15 |
|
'admin_invite_one' => 'rg_admin_invite_one' |
|
|
15 |
|
'admin_invite_one' => 'rg_admin_invite_one', |
|
16 |
|
'admin_mails_users' => 'rg_admin_mails_users', |
|
17 |
|
'admin_mails_users_one' => 'rg_admin_mails_users_one', |
16 |
18 |
); |
); |
17 |
19 |
rg_event_register_functions($rg_admin_functions); |
rg_event_register_functions($rg_admin_functions); |
18 |
20 |
|
|
|
21 |
|
|
|
22 |
|
/* |
|
23 |
|
* Event for invites (one e-mail version) |
|
24 |
|
*/ |
|
25 |
|
function rg_admin_invite_one($db, $event) |
|
26 |
|
{ |
|
27 |
|
global $rg_admin_email, $rg_admin_name; |
|
28 |
|
|
|
29 |
|
$admin_name = "=?UTF-8?B?" |
|
30 |
|
. base64_encode($rg_admin_name) . "?="; |
|
31 |
|
|
|
32 |
|
$rg = array(); |
|
33 |
|
$subject = str_replace('{NAME}', $event['name'], $event['subject']); |
|
34 |
|
$subject = "=?UTF-8?B?" . base64_encode(trim($subject)) . "?="; |
|
35 |
|
$header = rg_template("mail/common.head.txt", $rg, FALSE /*xss*/); |
|
36 |
|
$header = trim($header); |
|
37 |
|
$header .= "\nFrom: $admin_name <" . $rg_admin_email . ">"; |
|
38 |
|
rg_log_ml("DEBUG: header=$header"); |
|
39 |
|
$body = str_replace('{NAME}', $event['name'], $event['body']); |
|
40 |
|
|
|
41 |
|
$r = mail($event['email'], $subject, $body, $header, |
|
42 |
|
"-f $rg_admin_email"); |
|
43 |
|
|
|
44 |
|
if ($r === FALSE) |
|
45 |
|
return FALSE; |
|
46 |
|
|
|
47 |
|
return array(); |
|
48 |
|
} |
|
49 |
|
|
19 |
50 |
/* |
/* |
20 |
51 |
* Event for invites |
* Event for invites |
21 |
52 |
*/ |
*/ |
|
... |
... |
function rg_admin_invite($db, $event) |
45 |
76 |
} |
} |
46 |
77 |
|
|
47 |
78 |
/* |
/* |
48 |
|
* Event for invites (one e-mail version) |
|
|
79 |
|
* Event for mails/users (one e-mail version) |
49 |
80 |
*/ |
*/ |
50 |
|
function rg_admin_invite_one($db, $event) |
|
|
81 |
|
function rg_admin_mails_users_one($db, $ev) |
51 |
82 |
{ |
{ |
52 |
83 |
global $rg_admin_email, $rg_admin_name; |
global $rg_admin_email, $rg_admin_name; |
53 |
84 |
|
|
54 |
|
$admin_name = "=?UTF-8?B?" |
|
55 |
|
. base64_encode($rg_admin_name) . "?="; |
|
|
85 |
|
rg_log_ml('admin_mails_users_one: ev: ' . print_r($ev, TRUE)); |
|
86 |
|
|
|
87 |
|
$admin_name = '=?UTF-8?B?' |
|
88 |
|
. base64_encode($rg_admin_name) . '?='; |
56 |
89 |
|
|
57 |
90 |
$rg = array(); |
$rg = array(); |
58 |
|
$subject = str_replace('{NAME}', $event['name'], $event['subject']); |
|
59 |
|
$subject = "=?UTF-8?B?" . base64_encode(trim($subject)) . "?="; |
|
60 |
|
$header = rg_template("mail/common.head.txt", $rg, FALSE /*xss*/); |
|
|
91 |
|
$subject = '=?UTF-8?B?' . base64_encode(trim($ev['subject'])) . '?='; |
|
92 |
|
$header = rg_template('mail/common.head.txt', $rg, FALSE /*xss*/); |
61 |
93 |
$header = trim($header); |
$header = trim($header); |
62 |
|
$header .= "\nFrom: $admin_name <" . $rg_admin_email . ">"; |
|
63 |
|
rg_log_ml("DEBUG: header=$header"); |
|
64 |
|
$body = str_replace('{NAME}', $event['name'], $event['body']); |
|
|
94 |
|
$header .= "\n" . 'From: ' . $admin_name . ' <' . $rg_admin_email . '>'; |
|
95 |
|
rg_log_ml('DEBUG: header=' . $header); |
65 |
96 |
|
|
66 |
|
$r = mail($event['email'], $subject, $body, $header, |
|
67 |
|
"-f $rg_admin_email"); |
|
|
97 |
|
$r = mail($ev['email'], $subject, $ev['body'], $header, |
|
98 |
|
'-f ' . $rg_admin_email); |
68 |
99 |
|
|
69 |
100 |
if ($r === FALSE) |
if ($r === FALSE) |
70 |
101 |
return FALSE; |
return FALSE; |
|
... |
... |
function rg_admin_invite_one($db, $event) |
72 |
103 |
return array(); |
return array(); |
73 |
104 |
} |
} |
74 |
105 |
|
|
|
106 |
|
/* |
|
107 |
|
* Event for mails/users |
|
108 |
|
* TODO: add also the 'plan' field |
|
109 |
|
* TODO: Make the filtering a generic function |
|
110 |
|
*/ |
|
111 |
|
function rg_admin_mails_users($db, $ev) |
|
112 |
|
{ |
|
113 |
|
$ret = array(); |
|
114 |
|
|
|
115 |
|
//rg_log_ml('admin_mails_users: ev: ' . print_r($ev, TRUE)); |
|
116 |
|
|
|
117 |
|
$sql = 'SELECT uid, username, email, disk_used_mb' |
|
118 |
|
. ', git_mb, artifacts_mb, realname' |
|
119 |
|
. ' FROM users' |
|
120 |
|
. ' WHERE deleted = 0'; |
|
121 |
|
|
|
122 |
|
if ($ev['f']['conf'] == 0) |
|
123 |
|
$sql .= ' AND confirmed > 0'; |
|
124 |
|
else if ($ev['f']['conf'] == 1) |
|
125 |
|
$sql .= ' AND confirmed > 0'; |
|
126 |
|
|
|
127 |
|
if ($ev['f']['admin'] != 2) |
|
128 |
|
$sql .= ' AND is_admin = ' . $ev['f']['admin']; |
|
129 |
|
|
|
130 |
|
if ($ev['f']['suspended'] == 0) |
|
131 |
|
$sql .= ' AND suspended = 0'; |
|
132 |
|
else if ($ev['f']['suspended'] == 1) |
|
133 |
|
$sql .= ' AND suspended > 0'; |
|
134 |
|
|
|
135 |
|
if ($ev['f']['total_usage'] > 0) |
|
136 |
|
$sql .= ' AND disk_used_mb >= ' . $ev['f']['total_usage']; |
|
137 |
|
|
|
138 |
|
if ($ev['f']['artifact'] > 0) |
|
139 |
|
$sql .= ' AND artifacts_mb >= ' . $ev['f']['artifact']; |
|
140 |
|
|
|
141 |
|
if ($ev['f']['git'] > 0) |
|
142 |
|
$sql .= ' AND git_mb <= ' . $ev['f']['git']; |
|
143 |
|
|
|
144 |
|
$res = rg_sql_query($db, $sql); |
|
145 |
|
if ($res === FALSE) |
|
146 |
|
return FALSE; |
|
147 |
|
|
|
148 |
|
$u = array(); |
|
149 |
|
while (($row = rg_sql_fetch_array($res))) { |
|
150 |
|
if (!empty($ev['f']['username_filter']) |
|
151 |
|
&& @preg_match('/' . $ev['f']['username_filter'] . '/uD', $row['username']) === 0) |
|
152 |
|
continue; |
|
153 |
|
|
|
154 |
|
if (!empty($ev['f']['email_filter']) |
|
155 |
|
&& @preg_match('/' . $ev['f']['email_filter'] . '/uD', $row['email']) === 0) |
|
156 |
|
continue; |
|
157 |
|
|
|
158 |
|
$uid = $row['uid']; unset($row['uid']); |
|
159 |
|
$row['no_of_repos'] = 0; |
|
160 |
|
$row['no_of_webhooks'] = 0; |
|
161 |
|
if (empty($row['realname'])) |
|
162 |
|
$row['realname'] = $row['username']; |
|
163 |
|
$u[$uid] = $row; |
|
164 |
|
} |
|
165 |
|
rg_sql_free_result($res); |
|
166 |
|
|
|
167 |
|
if ($ev['f']['repo'] == 1) { |
|
168 |
|
$uids = array(); |
|
169 |
|
foreach ($u as $i) |
|
170 |
|
$uids[] = $i['uid']; |
|
171 |
|
$sql = 'SELECT uid FROM repos' |
|
172 |
|
. ' WHERE uid IN (' . implode(',', $uids) . ')'; |
|
173 |
|
$res = rg_sql_query($db, $sql); |
|
174 |
|
if ($res === FALSE) |
|
175 |
|
return FALSE; |
|
176 |
|
while (($row = rg_sql_fetch_array($res))) |
|
177 |
|
$u[$row['uid']]['no_of_repos']++; |
|
178 |
|
rg_sql_free_result($res); |
|
179 |
|
|
|
180 |
|
foreach ($u as $uid => $i) { |
|
181 |
|
if ($i['no_of_repos'] == 0) |
|
182 |
|
unset($u[$uid]); |
|
183 |
|
} |
|
184 |
|
} |
|
185 |
|
|
|
186 |
|
if ($ev['f']['webhook'] == 1) { |
|
187 |
|
$uids = array(); |
|
188 |
|
foreach ($u as $i) |
|
189 |
|
$uids[] = $i['uid']; |
|
190 |
|
|
|
191 |
|
$sql = 'SELECT uid FROM webhooks' |
|
192 |
|
. ' WHERE uid IN (' . implode(',', $uids) . ')'; |
|
193 |
|
$res = rg_sql_query($db, $sql); |
|
194 |
|
if ($res === FALSE) |
|
195 |
|
return FALSE; |
|
196 |
|
while (($row = rg_sql_fetch_array($res))) |
|
197 |
|
$u[$row['uid']]['no_of_webhooks']++; |
|
198 |
|
rg_sql_free_result($res); |
|
199 |
|
|
|
200 |
|
foreach ($u as $uid => $i) { |
|
201 |
|
if ($i['no_of_webhooks'] == 0) |
|
202 |
|
unset($u[$uid]); |
|
203 |
|
} |
|
204 |
|
} |
|
205 |
|
|
|
206 |
|
$subject = $ev['f']['subject']; |
|
207 |
|
$body = $ev['f']['body']; |
|
208 |
|
unset($ev['f']); |
|
209 |
|
|
|
210 |
|
foreach ($u as $uid => $i) { |
|
211 |
|
$k = array(); $v = array(); |
|
212 |
|
foreach ($i as $_k => $_v) { |
|
213 |
|
$k[] = '/@@' . $_k . '@@/uU'; |
|
214 |
|
$v[] = $_v; |
|
215 |
|
} |
|
216 |
|
$ev['subject'] = preg_replace($k, $v, $subject); |
|
217 |
|
$ev['body'] = preg_replace($k, $v, $body); |
|
218 |
|
|
|
219 |
|
$ret[] = array_merge($ev, |
|
220 |
|
array( |
|
221 |
|
'category' => 'admin_mails_users_one', |
|
222 |
|
'prio' => 500, |
|
223 |
|
'email' => $i['email'], |
|
224 |
|
'name' => $i['realname'] |
|
225 |
|
) |
|
226 |
|
); |
|
227 |
|
} |
|
228 |
|
|
|
229 |
|
return $ret; |
|
230 |
|
} |
|
231 |
|
|
|
232 |
|
/* |
|
233 |
|
* Deals with mails to the users |
|
234 |
|
*/ |
|
235 |
|
function rg_admin_mails_users_high_level($db, $rg) |
|
236 |
|
{ |
|
237 |
|
rg_log_enter('admin_mails_users_high_level'); |
|
238 |
|
|
|
239 |
|
$ret = ''; |
|
240 |
|
|
|
241 |
|
$f = array(); |
|
242 |
|
$f['email_filter'] = ''; |
|
243 |
|
$f['username_filter'] = ''; |
|
244 |
|
$f['conf'] = 1; |
|
245 |
|
$f['admin'] = 2; |
|
246 |
|
$f['suspended'] = 0; |
|
247 |
|
$f['repo'] = 0; |
|
248 |
|
$f['webhook'] = 0; |
|
249 |
|
$f['total_usage'] = 0; |
|
250 |
|
$f['git'] = 0; |
|
251 |
|
$f['artifact'] = 0; |
|
252 |
|
$f['subject'] = ''; |
|
253 |
|
$f['body'] = ''; |
|
254 |
|
|
|
255 |
|
$errmsg = array(); |
|
256 |
|
$show_form = TRUE; |
|
257 |
|
while (1) { |
|
258 |
|
if (rg_var_int('doit') == 0) |
|
259 |
|
break; |
|
260 |
|
|
|
261 |
|
$f['username_filter'] = rg_var_str_nocr('f::username_filter'); |
|
262 |
|
$f['email_filter'] = rg_var_str_nocr('f::email_filter'); |
|
263 |
|
$f['conf'] = rg_var_uint('f::conf'); |
|
264 |
|
$f['admin'] = rg_var_uint('f::admin'); |
|
265 |
|
$f['suspended'] = rg_var_uint('f::suspended'); |
|
266 |
|
$f['repo'] = rg_var_uint('f::repo'); |
|
267 |
|
$f['webhook'] = rg_var_uint('f::webhook'); |
|
268 |
|
$f['total_usage'] = rg_var_uint('f::total_usage'); |
|
269 |
|
$f['git'] = rg_var_uint('f::git'); |
|
270 |
|
$f['artifact'] = rg_var_uint('f::artifact'); |
|
271 |
|
$f['subject'] = rg_var_str_nocr('f::subject'); |
|
272 |
|
$f['body'] = trim(rg_var_str('f::body')); |
|
273 |
|
|
|
274 |
|
if (!rg_valid_referer()) { |
|
275 |
|
$errmsg[] = 'invalid referer; try again'; |
|
276 |
|
break; |
|
277 |
|
} |
|
278 |
|
|
|
279 |
|
if (!rg_token_valid($db, $rg, 'admin_mails_users_hl', FALSE)) { |
|
280 |
|
$errmsg[] = 'invalid token; try again'; |
|
281 |
|
break; |
|
282 |
|
} |
|
283 |
|
|
|
284 |
|
if (empty($f['subject'])) { |
|
285 |
|
$errmsg[] = 'subject is empty'; |
|
286 |
|
break; |
|
287 |
|
} |
|
288 |
|
|
|
289 |
|
if (empty($f['body'])) { |
|
290 |
|
$errmsg[] = 'body is empty'; |
|
291 |
|
break; |
|
292 |
|
} |
|
293 |
|
|
|
294 |
|
if (!empty($errmsg)) |
|
295 |
|
break; |
|
296 |
|
|
|
297 |
|
$ev = array( |
|
298 |
|
'category' => 'admin_mails_users', |
|
299 |
|
'prio' => 50, |
|
300 |
|
'ui' => $rg['login_ui'], |
|
301 |
|
'f' => $f); |
|
302 |
|
$r = rg_event_add($db, $ev); |
|
303 |
|
if ($r !== TRUE) { |
|
304 |
|
$errmsg[] = 'cannot add event (' . rg_event_error() . ')'; |
|
305 |
|
break; |
|
306 |
|
} |
|
307 |
|
rg_event_signal_daemon('', 0); |
|
308 |
|
|
|
309 |
|
$ret .= rg_template('admin/mails/users/queued.html', $rg, TRUE /*xss*/); |
|
310 |
|
$show_form = FALSE; |
|
311 |
|
break; |
|
312 |
|
} |
|
313 |
|
|
|
314 |
|
if ($show_form) { |
|
315 |
|
$rg['f'] = $f; |
|
316 |
|
|
|
317 |
|
// hints |
|
318 |
|
$hints = array(); |
|
319 |
|
$hints[]['HTML:hint'] = rg_template('hints/admin/mails_users.html', |
|
320 |
|
$rg, TRUE /*xss*/); |
|
321 |
|
$rg['HTML:hints'] = rg_template_table('hints/list', $hints, $rg); |
|
322 |
|
|
|
323 |
|
$rg['HTML:errmsg'] = rg_template_errmsg($errmsg); |
|
324 |
|
$rg['rg_form_token'] = rg_token_get($db, $rg, 'admin_mails_users_hl'); |
|
325 |
|
$ret .= rg_template('admin/mails/users/form.html', $rg, TRUE /*xss*/); |
|
326 |
|
} |
|
327 |
|
|
|
328 |
|
rg_log_exit(); |
|
329 |
|
return $ret; |
|
330 |
|
} |
|
331 |
|
|
75 |
332 |
/* |
/* |
76 |
333 |
* Deals with invites |
* Deals with invites |
77 |
334 |
*/ |
*/ |
78 |
|
function rg_admin_invites_high_level($db, $rg) |
|
|
335 |
|
function rg_admin_mails_invites_high_level($db, $rg) |
79 |
336 |
{ |
{ |
80 |
|
rg_log_enter("admin_invites_high_level"); |
|
|
337 |
|
rg_log_enter('admin_mails_invites_high_level'); |
81 |
338 |
|
|
82 |
339 |
$ret = ""; |
$ret = ""; |
83 |
340 |
|
|
|
... |
... |
function rg_admin_invites_high_level($db, $rg) |
93 |
350 |
break; |
break; |
94 |
351 |
|
|
95 |
352 |
$inv['list'] = rg_var_str('inv::list'); |
$inv['list'] = rg_var_str('inv::list'); |
96 |
|
$inv['subject'] = trim(rg_var_str('inv::subject')); |
|
|
353 |
|
$inv['subject'] = rg_var_str_nocr('inv::subject'); |
97 |
354 |
$inv['body'] = rg_var_str('inv::body'); |
$inv['body'] = rg_var_str('inv::body'); |
98 |
355 |
|
|
99 |
356 |
while (isset($_FILES['inv::file'])) { |
while (isset($_FILES['inv::file'])) { |
File root/themes/default/admin/mails/users/form.html added (mode: 100644) (index 0000000..db5e47e) |
|
1 |
|
<div class="formarea"> |
|
2 |
|
|
|
3 |
|
<div class="formarea_title">Send mails to your users</div> |
|
4 |
|
|
|
5 |
|
@@errmsg@@ |
|
6 |
|
|
|
7 |
|
<form method="post" action="/op/admin/mails/users" enctype="multipart/form-data"> |
|
8 |
|
<input type="hidden" name="doit" value="1" /> |
|
9 |
|
<input type="hidden" name="token" value="@@rg_form_token@@" /> |
|
10 |
|
|
|
11 |
|
<p> |
|
12 |
|
<label for="f_username_filter">Username filter (regex; empty = all):</label> |
|
13 |
|
<input class="form_short" type="text" name="f::username_filter" id="f_username_filter" value="@@f::username_filter@@" size="50" /> |
|
14 |
|
</p> |
|
15 |
|
|
|
16 |
|
<p> |
|
17 |
|
<label for="f_email_filter">E-mail filter (regex; empty = all):</label> |
|
18 |
|
<input class="form_short" type="text" name="f::email_filter" id="f_email_filter" value="@@f::email_filter@@" size="50" /> |
|
19 |
|
</p> |
|
20 |
|
|
|
21 |
|
<p> |
|
22 |
|
<label for="f_conf">User must have the e-mail confirmed?</label> |
|
23 |
|
<select class="form_short" name="f::conf" id="f_conf"> |
|
24 |
|
<option value="1"@@if(@@f::conf@@ == 1){{ selected="selected"}}{{}}>Yes</option> |
|
25 |
|
<option value="2"@@if(@@f::conf@@ == 2){{ selected="selected"}}{{}}>Doesn't matter</option> |
|
26 |
|
<option value="0"@@if(@@f::conf@@ == 0){{ selected="selected"}}{{}}>No</option> |
|
27 |
|
</select> |
|
28 |
|
</p> |
|
29 |
|
|
|
30 |
|
<p> |
|
31 |
|
<label for="f_admin">User must be an admin?</label> |
|
32 |
|
<select class="form_short" name="f::admin" id="f_admin"> |
|
33 |
|
<option value="2"@@if(@@f::admin@@ == 2){{ selected="selected"}}{{}}>Doesn't matter</option> |
|
34 |
|
<option value="0"@@if(@@f::admin@@ == 0){{ selected="selected"}}{{}}>No</option> |
|
35 |
|
<option value="1"@@if(@@f::admin@@ == 1){{ selected="selected"}}{{}}>Yes</option> |
|
36 |
|
</select> |
|
37 |
|
</p> |
|
38 |
|
|
|
39 |
|
<p> |
|
40 |
|
<label for="f_suspended">User must be suspended?</label> |
|
41 |
|
<select class="form_short" name="f::suspended" id="f_suspended"> |
|
42 |
|
<option value="0"@@if(@@f::suspended@@ == 0){{ selected="selected"}}{{}}>No</option> |
|
43 |
|
<option value="2"@@if(@@f::suspended@@ == 2){{ selected="selected"}}{{}}>Doesn't matter</option> |
|
44 |
|
<option value="1"@@if(@@f::suspended@@ == 1){{ selected="selected"}}{{}}>Yes</option> |
|
45 |
|
</select> |
|
46 |
|
</p> |
|
47 |
|
|
|
48 |
|
<p> |
|
49 |
|
<label for="f_repo">Minimum number of repos (0 = all):</label> |
|
50 |
|
<input class="form_short" type="text" name="f::repo" id="f_repo" value="@@f::repo@@" size="5" /> |
|
51 |
|
</p> |
|
52 |
|
|
|
53 |
|
<p> |
|
54 |
|
<label for="f_webhook">Minimum number of webhooks (0 = all):</label> |
|
55 |
|
<input class="form_short" type="text" name="f::webhook" id="f_webhook" value="@@f::webhook@@" size="5" /> |
|
56 |
|
</p> |
|
57 |
|
|
|
58 |
|
<p> |
|
59 |
|
<label for="f_total_usage">Total minimum disk usage (MiB; 0 = all):</label> |
|
60 |
|
<input class="form_short" type="text" name="f::total_usage" id="f_total_usage" value="@@f::total_usage@@" size="5" /> |
|
61 |
|
</p> |
|
62 |
|
|
|
63 |
|
<p> |
|
64 |
|
<label for="f_git">Git minimum disk usage (MiB; 0 = all):</label> |
|
65 |
|
<input class="form_short" type="text" name="f::git" id="f_git" value="@@f::git@@" size="5" /> |
|
66 |
|
</p> |
|
67 |
|
|
|
68 |
|
<p> |
|
69 |
|
<label for="f_artifact">Artifacts minimum disk usage (MiB; 0 = all):</label> |
|
70 |
|
<input class="form_short" type="text" name="f::artifact" id="f_artifact" value="@@f::artifact@@" size="5" /> |
|
71 |
|
</p> |
|
72 |
|
|
|
73 |
|
<p> |
|
74 |
|
<label for="f_subject">Subject:</label> |
|
75 |
|
<input type="text" name="f::subject" id="f_subject" value="@@f::subject@@" /> |
|
76 |
|
</p> |
|
77 |
|
|
|
78 |
|
<p> |
|
79 |
|
<label for="body">Body:</label><br /> |
|
80 |
|
<textarea name="f::body" id="f_body" rows="30">@@f::body@@</textarea> |
|
81 |
|
</p> |
|
82 |
|
|
|
83 |
|
<p> |
|
84 |
|
<input type="submit" name="button" value="Send" /> |
|
85 |
|
</p> |
|
86 |
|
|
|
87 |
|
</form> |
|
88 |
|
</div> |
|
89 |
|
|
|
90 |
|
@@hints@@ |