File inc/bug.inc.php changed (mode: 100644) (index 5451e46..87fb889) |
... |
... |
require_once($INC . "/sql.inc.php"); |
5 |
5 |
require_once($INC . "/user.inc.php"); |
require_once($INC . "/user.inc.php"); |
6 |
6 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
7 |
7 |
require_once($INC . "/prof.inc.php"); |
require_once($INC . "/prof.inc.php"); |
|
8 |
|
require_once($INC . "/mail.inc.php"); |
8 |
9 |
require_once($INC . "/events.inc.php"); |
require_once($INC . "/events.inc.php"); |
9 |
10 |
require_once($INC . "/watch.inc.php"); |
require_once($INC . "/watch.inc.php"); |
10 |
11 |
|
|
|
... |
... |
function rg_bug_event_add_one($db, $event) |
50 |
51 |
|
|
51 |
52 |
$ret = FALSE; |
$ret = FALSE; |
52 |
53 |
while (1) { |
while (1) { |
53 |
|
if ($event['debug'] == 1) { |
|
54 |
|
rg_cache_set('DEBUG::bug_event_add_one', $event, 0); |
|
55 |
|
$ret = array(); |
|
56 |
|
break; |
|
57 |
|
} |
|
58 |
|
|
|
59 |
54 |
// lookup user email |
// lookup user email |
60 |
55 |
$ui = rg_user_info($db, $event['ui']['uid'], '', ''); |
$ui = rg_user_info($db, $event['ui']['uid'], '', ''); |
61 |
56 |
if ($ui['exists'] != 1) { |
if ($ui['exists'] != 1) { |
|
... |
... |
function rg_bug_event_note_add_one($db, $event) |
133 |
128 |
|
|
134 |
129 |
$ret = FALSE; |
$ret = FALSE; |
135 |
130 |
while (1) { |
while (1) { |
136 |
|
if ($event['debug'] == 1) { |
|
137 |
|
rg_cache_set('DEBUG::bug_event_note_add_one', $event, 0); |
|
138 |
|
$ret = array(); |
|
139 |
|
break; |
|
140 |
|
} |
|
141 |
|
|
|
142 |
131 |
// lookup user email |
// lookup user email |
143 |
132 |
$ui = rg_user_info($db, $event['ui']['uid'], '', ''); |
$ui = rg_user_info($db, $event['ui']['uid'], '', ''); |
144 |
133 |
if ($ui['exists'] != 1) { |
if ($ui['exists'] != 1) { |
File inc/keys.inc.php changed (mode: 100644) (index a7a062c..c2e75a2) |
2 |
2 |
require_once($INC . "/sql.inc.php"); |
require_once($INC . "/sql.inc.php"); |
3 |
3 |
require_once($INC . "/state.inc.php"); |
require_once($INC . "/state.inc.php"); |
4 |
4 |
require_once($INC . "/prof.inc.php"); |
require_once($INC . "/prof.inc.php"); |
|
5 |
|
require_once($INC . "/mail.inc.php"); |
5 |
6 |
require_once($INC . "/events.inc.php"); |
require_once($INC . "/events.inc.php"); |
6 |
7 |
|
|
7 |
8 |
$rg_keys_error = ""; |
$rg_keys_error = ""; |
|
... |
... |
function rg_keys_event_notify_user($db, $event) |
103 |
104 |
|
|
104 |
105 |
$ret = FALSE; |
$ret = FALSE; |
105 |
106 |
while (1) { |
while (1) { |
106 |
|
if ($event['debug'] == 1) { |
|
107 |
|
rg_cache_set('DEBUG::keys_event_notify_user', $event, 0); |
|
108 |
|
$ret = array(); |
|
109 |
|
break; |
|
110 |
|
} |
|
111 |
|
|
|
112 |
107 |
$r = rg_mail_template("mail/user/key/" . $event['op'], $event); |
$r = rg_mail_template("mail/user/key/" . $event['op'], $event); |
113 |
108 |
if ($r === FALSE) |
if ($r === FALSE) |
114 |
109 |
break; |
break; |
File inc/mail.inc.php added (mode: 100644) (index 0000000..24dc5b0) |
|
1 |
|
<?php |
|
2 |
|
require_once($INC . "/prof.inc.php"); |
|
3 |
|
require_once($INC . "/log.inc.php"); |
|
4 |
|
require_once($INC . "/util.inc.php"); |
|
5 |
|
|
|
6 |
|
|
|
7 |
|
$rg_mail_error = ""; |
|
8 |
|
|
|
9 |
|
function rg_mail_set_error($str) |
|
10 |
|
{ |
|
11 |
|
global $rg_mail_error; |
|
12 |
|
$rg_mail_error = $str; |
|
13 |
|
} |
|
14 |
|
|
|
15 |
|
function rg_mail_error() |
|
16 |
|
{ |
|
17 |
|
global $rg_mail_error; |
|
18 |
|
return $rg_mail_error; |
|
19 |
|
} |
|
20 |
|
|
|
21 |
|
/* |
|
22 |
|
* Function to send e-mails |
|
23 |
|
* TODO: Replace mail() with rg_mail everywhere. |
|
24 |
|
*/ |
|
25 |
|
function rg_mail_template($template, $more) |
|
26 |
|
{ |
|
27 |
|
global $rg_admin_name, $rg_admin_email; |
|
28 |
|
|
|
29 |
|
rg_prof_start("mail_template"); |
|
30 |
|
rg_log("mail_template: $template, more=" . rg_array2string($more)); |
|
31 |
|
|
|
32 |
|
// Account was not confirmed, so do not send mail |
|
33 |
|
if (empty($more['ui']['email'])) |
|
34 |
|
return TRUE; |
|
35 |
|
|
|
36 |
|
$more['HTML:rg_admin_email'] = $rg_admin_email; |
|
37 |
|
$more['HTML:utf8_rg_admin_name'] = "=?UTF-8?B?" |
|
38 |
|
. base64_encode($rg_admin_name) . "?="; |
|
39 |
|
|
|
40 |
|
$subject = rg_template($template . ".subj.txt", $more, FALSE /*xss*/); |
|
41 |
|
$subject = trim($subject); |
|
42 |
|
$subject = str_replace("\r", '', $subject); |
|
43 |
|
$subject = str_replace("\n", '', $subject); |
|
44 |
|
// TODO: do not encode it as UTF-8 if not needed |
|
45 |
|
$subject = "=?UTF-8?B?" . base64_encode($subject) . "?="; |
|
46 |
|
|
|
47 |
|
$header = rg_template("mail/common.head.txt", $more, FALSE /*xss*/); |
|
48 |
|
$header .= rg_template($template . ".head.txt", $more, FALSE /*xss*/); |
|
49 |
|
$header = trim($header); |
|
50 |
|
|
|
51 |
|
$body = rg_template($template . ".body.txt", $more, FALSE /*xss*/); |
|
52 |
|
|
|
53 |
|
rg_log("CHECK: mail_template(" . $more['ui']['email'] . ", |
|
54 |
|
$subject, $body, $header, -f $rg_admin_email"); |
|
55 |
|
if ($more['debug'] == 1) { |
|
56 |
|
rg_cache_set('DEBUG::' . $more['ui']['uid'] . '::mail', |
|
57 |
|
array( |
|
58 |
|
'header' => $header, |
|
59 |
|
'subject' => $subject, |
|
60 |
|
'to' => $more['ui']['email'], |
|
61 |
|
'body' => $body |
|
62 |
|
), RG_SOCKET_NO_WAIT); |
|
63 |
|
$ret = TRUE; |
|
64 |
|
} else { |
|
65 |
|
$ret = mail($more['ui']['email'], $subject, $body, $header, |
|
66 |
|
"-f $rg_admin_email"); |
|
67 |
|
} |
|
68 |
|
if ($ret === FALSE) |
|
69 |
|
rg_log("Sending mail failed to=" . $more['ui']['email'] |
|
70 |
|
. " subject=$subject!"); |
|
71 |
|
|
|
72 |
|
rg_prof_end("mail_template"); |
|
73 |
|
return $ret; |
|
74 |
|
} |
|
75 |
|
|
|
76 |
|
?> |
File inc/repo.inc.php changed (mode: 100644) (index 0b62a2d..b1ecc06) |
... |
... |
require_once($INC . "/user.inc.php"); |
6 |
6 |
require_once($INC . "/git.inc.php"); |
require_once($INC . "/git.inc.php"); |
7 |
7 |
require_once($INC . "/rights.inc.php"); |
require_once($INC . "/rights.inc.php"); |
8 |
8 |
require_once($INC . "/prof.inc.php"); |
require_once($INC . "/prof.inc.php"); |
|
9 |
|
require_once($INC . "/mail.inc.php"); |
9 |
10 |
require_once($INC . "/events.inc.php"); |
require_once($INC . "/events.inc.php"); |
10 |
11 |
require_once($INC . "/webhooks.inc.php"); |
require_once($INC . "/webhooks.inc.php"); |
11 |
12 |
|
|
|
... |
... |
function rg_repo_event_notify_user($db, $event) |
476 |
477 |
|
|
477 |
478 |
$ret = FALSE; |
$ret = FALSE; |
478 |
479 |
while (1) { |
while (1) { |
479 |
|
if ($event['debug'] == 1) { |
|
480 |
|
rg_cache_set('DEBUG::repo_event_notify_user', $event, 0); |
|
481 |
|
$ret = array(); |
|
482 |
|
break; |
|
483 |
|
} |
|
484 |
|
|
|
485 |
480 |
$r = rg_mail_template("mail/user/repo/" . $event['op'], $event); |
$r = rg_mail_template("mail/user/repo/" . $event['op'], $event); |
486 |
481 |
if ($r === FALSE) |
if ($r === FALSE) |
487 |
482 |
break; |
break; |
File inc/user.inc.php changed (mode: 100644) (index bcc3b10..aeb083f) |
... |
... |
require_once($INC . "/sess.inc.php"); |
7 |
7 |
require_once($INC . "/rights.inc.php"); |
require_once($INC . "/rights.inc.php"); |
8 |
8 |
require_once($INC . "/events.inc.php"); |
require_once($INC . "/events.inc.php"); |
9 |
9 |
require_once($INC . "/cache.inc.php"); |
require_once($INC . "/cache.inc.php"); |
|
10 |
|
require_once($INC . "/mail.inc.php"); |
10 |
11 |
require_once($INC . "/plan.inc.php"); |
require_once($INC . "/plan.inc.php"); |
11 |
12 |
require_once($INC . "/totp.inc.php"); |
require_once($INC . "/totp.inc.php"); |
12 |
13 |
|
|
|
... |
... |
function rg_user_event_notify_user($db, $event) |
92 |
93 |
{ |
{ |
93 |
94 |
rg_log("user_event_notify_user: event=" . rg_array2string($event)); |
rg_log("user_event_notify_user: event=" . rg_array2string($event)); |
94 |
95 |
|
|
95 |
|
if ($event['debug'] == 1) { |
|
96 |
|
rg_cache_set('DEBUG::user_event_notify_user', $event, 0); |
|
97 |
|
return array(); |
|
98 |
|
} |
|
99 |
|
|
|
100 |
96 |
if (strcmp($event['op'], "rename") == 0) { |
if (strcmp($event['op'], "rename") == 0) { |
101 |
97 |
$r = rg_mail_template("mail/user/rename", $event); |
$r = rg_mail_template("mail/user/rename", $event); |
102 |
98 |
} else { |
} else { |
|
... |
... |
function rg_user_edit($db, $d) |
524 |
520 |
$event = array('category' => 2000, 'prio' => 50, |
$event = array('category' => 2000, 'prio' => 50, |
525 |
521 |
'ui' => array( |
'ui' => array( |
526 |
522 |
'uid' => $row['uid'], |
'uid' => $row['uid'], |
|
523 |
|
'realname' => $d['realname'], |
527 |
524 |
'username' => $d['username'], |
'username' => $d['username'], |
528 |
525 |
'email' => $d['confirmed'] > 0 ? $d['email'] : "", |
'email' => $d['confirmed'] > 0 ? $d['email'] : "", |
529 |
526 |
'confirm_token' => $d['confirm_token'] |
'confirm_token' => $d['confirm_token'] |
File inc/util.inc.php changed (mode: 100644) (index 9f4ebdf..fc68b0f) |
... |
... |
function rg_date2ts_last_second($s) |
1345 |
1345 |
return gmmktime(0, 0, 0, $f[1], $f[2] + 1, $f[0]) - 1; |
return gmmktime(0, 0, 0, $f[1], $f[2] + 1, $f[0]) - 1; |
1346 |
1346 |
} |
} |
1347 |
1347 |
|
|
1348 |
|
/* |
|
1349 |
|
* Function to send e-mails |
|
1350 |
|
* TODO: Replace mail() with rg_mail everywhere. |
|
1351 |
|
*/ |
|
1352 |
|
function rg_mail_template($template, $more) |
|
1353 |
|
{ |
|
1354 |
|
global $rg_admin_name, $rg_admin_email; |
|
1355 |
|
|
|
1356 |
|
rg_prof_start("mail_template"); |
|
1357 |
|
rg_log("mail_template: $template, more=" . rg_array2string($more)); |
|
1358 |
|
|
|
1359 |
|
// Account was not confirmed, so do not send mail |
|
1360 |
|
if (empty($more['ui']['email'])) |
|
1361 |
|
return TRUE; |
|
1362 |
|
|
|
1363 |
|
$more['HTML:rg_admin_email'] = $rg_admin_email; |
|
1364 |
|
$more['HTML:utf8_rg_admin_name'] = "=?UTF-8?B?" |
|
1365 |
|
. base64_encode($rg_admin_name) . "?="; |
|
1366 |
|
|
|
1367 |
|
$subject = rg_template($template . ".subj.txt", $more, FALSE /*xss*/); |
|
1368 |
|
$subject = trim($subject); |
|
1369 |
|
$subject = str_replace("\r", '', $subject); |
|
1370 |
|
$subject = str_replace("\n", '', $subject); |
|
1371 |
|
// TODO: do not encode it as UTF-8 if not needed |
|
1372 |
|
$subject = "=?UTF-8?B?" . base64_encode($subject) . "?="; |
|
1373 |
|
|
|
1374 |
|
$header = rg_template("mail/common.head.txt", $more, FALSE /*xss*/); |
|
1375 |
|
$header .= rg_template($template . ".head.txt", $more, FALSE /*xss*/); |
|
1376 |
|
$header = trim($header); |
|
1377 |
|
|
|
1378 |
|
$body = rg_template($template . ".body.txt", $more, FALSE /*xss*/); |
|
1379 |
|
|
|
1380 |
|
rg_log("CHECK: mail_template(" . $more['ui']['email'] . ", |
|
1381 |
|
$subject, $body, $header, -f $rg_admin_email"); |
|
1382 |
|
$ret = mail($more['ui']['email'], $subject, $body, $header, |
|
1383 |
|
"-f $rg_admin_email"); |
|
1384 |
|
if ($ret === FALSE) |
|
1385 |
|
rg_log("Sending mail failed to=" . $more['ui']['email'] |
|
1386 |
|
. " subject=$subject!"); |
|
1387 |
|
|
|
1388 |
|
rg_prof_end("mail_template"); |
|
1389 |
|
return $ret; |
|
1390 |
|
} |
|
1391 |
|
|
|
1392 |
1348 |
/* |
/* |
1393 |
1349 |
* Special implode, with prefix/postfix |
* Special implode, with prefix/postfix |
1394 |
1350 |
*/ |
*/ |
File inc/webhooks.inc.php changed (mode: 100644) (index 16d1ff3..4306a6f) |
... |
... |
function rg_wh_send_one($db, $event) |
119 |
119 |
rg_log_ml('Debug: ' . print_r($_info, TRUE)); |
rg_log_ml('Debug: ' . print_r($_info, TRUE)); |
120 |
120 |
|
|
121 |
121 |
if ($event['debug'] == 1) |
if ($event['debug'] == 1) |
122 |
|
rg_cache_set('DEBUG::webhooks::' . $event['ui']['uid'] |
|
123 |
|
. '::' . $info['opaque'] |
|
|
122 |
|
rg_cache_set('DEBUG::' . $event['ui']['uid'] |
|
123 |
|
. '::webhooks::' . $info['opaque'] |
124 |
124 |
. '::' . $wh['id'], |
. '::' . $wh['id'], |
125 |
125 |
'BAD', RG_SOCKET_NO_WAIT); |
'BAD', RG_SOCKET_NO_WAIT); |
126 |
126 |
break; |
break; |
|
... |
... |
function rg_wh_send_one($db, $event) |
129 |
129 |
rg_log_ml('Answer: ' . print_r($r, TRUE)); |
rg_log_ml('Answer: ' . print_r($r, TRUE)); |
130 |
130 |
|
|
131 |
131 |
if ($event['debug'] == 1) |
if ($event['debug'] == 1) |
132 |
|
rg_cache_set('DEBUG::webhooks::' . $event['ui']['uid'] |
|
133 |
|
. '::' . $info['opaque'] |
|
|
132 |
|
rg_cache_set('DEBUG::' . $event['ui']['uid'] |
|
133 |
|
. '::webhooks::' . $info['opaque'] |
134 |
134 |
. '::' . $wh['id'], |
. '::' . $wh['id'], |
135 |
135 |
'OK', RG_SOCKET_NO_WAIT); |
'OK', RG_SOCKET_NO_WAIT); |
136 |
136 |
|
|
File tests/email.php changed (mode: 100644) (index 6cd2534..baf34aa) |
... |
... |
$INC = dirname(__FILE__) . "/../inc"; |
6 |
6 |
require_once(dirname(__FILE__) . "/config.php"); |
require_once(dirname(__FILE__) . "/config.php"); |
7 |
7 |
require_once($INC . "/init.inc.php"); |
require_once($INC . "/init.inc.php"); |
8 |
8 |
require_once($INC . "/util.inc.php"); |
require_once($INC . "/util.inc.php"); |
|
9 |
|
require_once("helpers.inc.php"); |
9 |
10 |
|
|
10 |
11 |
rg_log_set_file("email.log"); |
rg_log_set_file("email.log"); |
11 |
12 |
|
|
|
13 |
|
$rg_sql = "host=localhost user=rocketgit dbname=rocketgit connect_timeout=10"; |
12 |
14 |
$rg_no_db = TRUE; |
$rg_no_db = TRUE; |
13 |
15 |
require_once("common.php"); |
require_once("common.php"); |
14 |
16 |
|
|
|
17 |
|
$_testns = 'email'; |
|
18 |
|
$rg_cache_enable = TRUE; |
|
19 |
|
|
15 |
20 |
$rg_scripts = "../"; |
$rg_scripts = "../"; |
16 |
21 |
$rg_theme = "default"; |
$rg_theme = "default"; |
|
22 |
|
$rg_event_socket = "/var/lib/rocketgit/sockets/event.sock"; |
17 |
23 |
|
|
18 |
24 |
rg_log_set_file("email.log"); |
rg_log_set_file("email.log"); |
19 |
25 |
|
|
20 |
|
$more = array( |
|
21 |
|
"to" => "xxx@embedromix.ro" |
|
22 |
|
); |
|
|
26 |
|
// This will trigger an e-mail |
|
27 |
|
rg_test_create_user($db, $rg_ui); |
|
28 |
|
|
|
29 |
|
|
|
30 |
|
rg_log(''); |
|
31 |
|
rg_log('Trying to get the cache info...'); |
|
32 |
|
$key = 'DEBUG::' . $rg_ui['uid']; |
|
33 |
|
$tries = 10; |
|
34 |
|
while ($tries--) { |
|
35 |
|
$r = rg_cache_get($key); |
|
36 |
|
if ($r === FALSE) { |
|
37 |
|
sleep(1); |
|
38 |
|
continue; |
|
39 |
|
} |
|
40 |
|
|
|
41 |
|
break; |
|
42 |
|
} |
|
43 |
|
if ($r === FALSE) { |
|
44 |
|
rg_log('DEBUG key was not set!'); |
|
45 |
|
exit(1); |
|
46 |
|
} |
|
47 |
|
if (!strstr($r['mail']['body'], 'Dear ' . $rg_ui['realname'])) { |
|
48 |
|
rg_log_ml('body: ' . print_r($r['mail']['body'], TRUE)); |
|
49 |
|
rg_log('realname was specified bu not found in e-mail!'); |
|
50 |
|
exit(1); |
|
51 |
|
} |
|
52 |
|
|
|
53 |
|
|
|
54 |
|
rg_log(''); |
|
55 |
|
rg_log('Testing without specifying a realname'); |
|
56 |
|
$rg_ui = array('realname' => ''); |
|
57 |
|
rg_test_create_user($db, $rg_ui); |
|
58 |
|
|
|
59 |
|
|
|
60 |
|
rg_log(''); |
|
61 |
|
rg_log('Trying to get the cache info...'); |
|
62 |
|
$key = 'DEBUG::' . $rg_ui['uid']; |
|
63 |
|
$tries = 10; |
|
64 |
|
while ($tries--) { |
|
65 |
|
$r = rg_cache_get($key); |
|
66 |
|
if ($r === FALSE) { |
|
67 |
|
sleep(1); |
|
68 |
|
continue; |
|
69 |
|
} |
|
70 |
|
|
|
71 |
|
break; |
|
72 |
|
} |
|
73 |
|
if ($r === FALSE) { |
|
74 |
|
rg_log('DEBUG key was not set!'); |
|
75 |
|
exit(1); |
|
76 |
|
} |
|
77 |
|
if (!strstr($r['mail']['body'], 'Dear ' . $rg_ui['username'])) { |
|
78 |
|
rg_log_ml('body: ' . print_r($r['mail']['body'], TRUE)); |
|
79 |
|
rg_log('realname was specified bu not found in e-mail!'); |
|
80 |
|
exit(1); |
|
81 |
|
} |
|
82 |
|
|
23 |
83 |
|
|
24 |
|
$r = rg_mail_template("mail/user/key/new", $more); |
|
25 |
|
print_r($r); |
|
|
84 |
|
rg_log('OK'); |
26 |
85 |
?> |
?> |
File tests/wh.php changed (mode: 100644) (index cc5443e..0bbf288) |
... |
... |
rg_log('Started stunnel with pid ' . $pid); |
89 |
89 |
rg_log(''); |
rg_log(''); |
90 |
90 |
rg_log("Creating a user..."); |
rg_log("Creating a user..."); |
91 |
91 |
rg_test_create_user($db, $rg_ui); |
rg_test_create_user($db, $rg_ui); |
92 |
|
$key1 = 'DEBUG::webhooks::' . $rg_ui['uid'] . '::' . $port1; |
|
93 |
|
$key2 = 'DEBUG::webhooks::' . $rg_ui['uid'] . '::' . $port2; |
|
|
92 |
|
$key1 = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $port1; |
|
93 |
|
$key2 = 'DEBUG::' . $rg_ui['uid'] . '::webhooks::' . $port2; |
94 |
94 |
|
|
95 |
95 |
|
|
96 |
96 |
rg_log(''); |
rg_log(''); |