Fossil SCM
New debugging option for /announce shows the SMTP transcript when the notification type is "relay".
Commit
bbfca4cb6433df721d23440638e8bc61224f2379213e67c53bdb1e9b0513ab6d
Parent
3fc9b90587ea488…
1 file changed
+45
-14
+45
-14
| --- src/alerts.c | ||
| +++ src/alerts.c | ||
| @@ -634,18 +634,24 @@ | ||
| 634 | 634 | emailerGetSetting(p, &p->zCmd, "email-send-command"); |
| 635 | 635 | }else if( fossil_strcmp(p->zDest, "dir")==0 ){ |
| 636 | 636 | emailerGetSetting(p, &p->zDir, "email-send-dir"); |
| 637 | 637 | }else if( fossil_strcmp(p->zDest, "blob")==0 ){ |
| 638 | 638 | blob_init(&p->out, 0, 0); |
| 639 | - }else if( fossil_strcmp(p->zDest, "relay")==0 ){ | |
| 639 | + }else if( fossil_strcmp(p->zDest, "relay")==0 | |
| 640 | + || fossil_strcmp(p->zDest, "debug-relay")==0 | |
| 641 | + ){ | |
| 640 | 642 | const char *zRelay = 0; |
| 641 | 643 | emailerGetSetting(p, &zRelay, "email-send-relayhost"); |
| 642 | 644 | if( zRelay ){ |
| 643 | 645 | u32 smtpFlags = SMTP_DIRECT; |
| 644 | 646 | if( mFlags & ALERT_TRACE ) smtpFlags |= SMTP_TRACE_STDOUT; |
| 647 | + blob_init(&p->out, 0, 0); | |
| 645 | 648 | p->pSmtp = smtp_session_new(domain_of_addr(p->zFrom), zRelay, |
| 646 | 649 | smtpFlags, 0); |
| 650 | + if( p->zDest[0]=='d' ){ | |
| 651 | + smtp_session_config(p->pSmtp, SMTP_TRACE_BLOB, &p->out); | |
| 652 | + } | |
| 647 | 653 | smtp_client_startup(p->pSmtp); |
| 648 | 654 | } |
| 649 | 655 | } |
| 650 | 656 | return p; |
| 651 | 657 | } |
| @@ -3440,16 +3446,28 @@ | ||
| 3440 | 3446 | char *zSubject = PT("subject"); |
| 3441 | 3447 | int bAll = PB("all"); |
| 3442 | 3448 | int bAA = PB("aa"); |
| 3443 | 3449 | int bMods = PB("mods"); |
| 3444 | 3450 | const char *zSub = db_get("email-subname", "[Fossil Repo]"); |
| 3445 | - int bTest2 = fossil_strcmp(P("name"),"test2")==0; | |
| 3451 | + const char *zName = P("name"); /* Debugging options */ | |
| 3452 | + const char *zDest = 0; /* How to send the announcement */ | |
| 3453 | + int bTest = 0; | |
| 3446 | 3454 | Blob hdr, body; |
| 3455 | + | |
| 3456 | + if( fossil_strcmp(zName, "test2")==0 ){ | |
| 3457 | + bTest = 2; | |
| 3458 | + zDest = "blob"; | |
| 3459 | + }else if( fossil_strcmp(zName, "test3")==0 ){ | |
| 3460 | + bTest = 3; | |
| 3461 | + if( fossil_strcmp(db_get("email-send-method",""),"relay")==0 ){ | |
| 3462 | + zDest = "debug-relay"; | |
| 3463 | + } | |
| 3464 | + } | |
| 3447 | 3465 | blob_init(&body, 0, 0); |
| 3448 | 3466 | blob_init(&hdr, 0, 0); |
| 3449 | 3467 | blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/); |
| 3450 | - pSender = alert_sender_new(bTest2 ? "blob" : 0, 0); | |
| 3468 | + pSender = alert_sender_new(zDest, 0); | |
| 3451 | 3469 | if( zTo[0] ){ |
| 3452 | 3470 | blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject); |
| 3453 | 3471 | alert_send(pSender, &hdr, &body, 0); |
| 3454 | 3472 | } |
| 3455 | 3473 | if( bAll || bAA || bMods ){ |
| @@ -3483,17 +3501,18 @@ | ||
| 3483 | 3501 | } |
| 3484 | 3502 | alert_send(pSender, &hdr, &body, 0); |
| 3485 | 3503 | } |
| 3486 | 3504 | db_finalize(&q); |
| 3487 | 3505 | } |
| 3488 | - if( bTest2 ){ | |
| 3506 | + if( bTest ){ | |
| 3489 | 3507 | /* If the URL is /announce/test2 instead of just /announce, then no |
| 3490 | 3508 | ** email is actually sent. Instead, the text of the email that would |
| 3491 | 3509 | ** have been sent is displayed in the result window. */ |
| 3492 | - @ <pre style='border: 2px solid blue; padding: 1ex'> | |
| 3510 | + @ <pre style='border: 2px solid blue; padding: 1ex;'> | |
| 3493 | 3511 | @ %h(blob_str(&pSender->out)) |
| 3494 | 3512 | @ </pre> |
| 3513 | + blob_reset(&pSender->out); | |
| 3495 | 3514 | } |
| 3496 | 3515 | zErr = pSender->zErr; |
| 3497 | 3516 | pSender->zErr = 0; |
| 3498 | 3517 | alert_sender_free(pSender); |
| 3499 | 3518 | return zErr; |
| @@ -3509,24 +3528,31 @@ | ||
| 3509 | 3528 | ** also send a message to an arbitrary email address and/or to all |
| 3510 | 3529 | ** subscribers regardless of whether or not they have elected to |
| 3511 | 3530 | ** receive announcements. |
| 3512 | 3531 | */ |
| 3513 | 3532 | void announce_page(void){ |
| 3514 | - const char *zAction = "announce" | |
| 3515 | - /* Maintenance reminder: we need an explicit action=THIS_PAGE on the | |
| 3516 | - ** form element to avoid that a URL arg of to=... passed to this | |
| 3517 | - ** page ends up overwriting the form-posted "to" value. This | |
| 3518 | - ** action value differs for the test1 request path. | |
| 3519 | - */; | |
| 3520 | - | |
| 3533 | + const char *zAction = "announce"; | |
| 3534 | + const char *zName = PD("name",""); | |
| 3535 | + /* | |
| 3536 | + ** Debugging Notes: | |
| 3537 | + ** | |
| 3538 | + ** /announce/test1 -> Shows query parameter values | |
| 3539 | + ** /announce/test2 -> Shows the formatted message but does | |
| 3540 | + ** not send it. | |
| 3541 | + ** /announce/test3 -> Sends the message, but also shows | |
| 3542 | + ** the SMTP transcript. | |
| 3543 | + */ | |
| 3521 | 3544 | login_check_credentials(); |
| 3522 | 3545 | if( !g.perm.Announce ){ |
| 3523 | 3546 | login_needed(0); |
| 3524 | 3547 | return; |
| 3525 | 3548 | } |
| 3549 | + if( !g.perm.Setup ){ | |
| 3550 | + zName = 0; /* Disable debugging feature for non-admin users */ | |
| 3551 | + } | |
| 3526 | 3552 | style_set_current_feature("alerts"); |
| 3527 | - if( fossil_strcmp(P("name"),"test1")==0 ){ | |
| 3553 | + if( fossil_strcmp(zName,"test1")==0 ){ | |
| 3528 | 3554 | /* Visit the /announce/test1 page to see the CGI variables */ |
| 3529 | 3555 | zAction = "announce/test1"; |
| 3530 | 3556 | @ <p style='border: 1px solid black; padding: 1ex;'> |
| 3531 | 3557 | cgi_print_all(0, 0, 0); |
| 3532 | 3558 | @ </p> |
| @@ -3553,10 +3579,15 @@ | ||
| 3553 | 3579 | return; |
| 3554 | 3580 | } |
| 3555 | 3581 | |
| 3556 | 3582 | style_header("Send Announcement"); |
| 3557 | 3583 | alert_submenu_common(); |
| 3584 | + if( fossil_strcmp(zName,"test2")==0 ){ | |
| 3585 | + zAction = "announce/test2"; | |
| 3586 | + }else if( fossil_strcmp(zName,"test3")==0 ){ | |
| 3587 | + zAction = "announce/test3"; | |
| 3588 | + } | |
| 3558 | 3589 | @ <form method="POST" action="%R/%s(zAction)"> |
| 3559 | 3590 | login_insert_csrf_secret(); |
| 3560 | 3591 | @ <table class="subscribe"> |
| 3561 | 3592 | if( g.perm.Admin ){ |
| 3562 | 3593 | int aa = PB("aa"); |
| @@ -3589,15 +3620,15 @@ | ||
| 3589 | 3620 | @ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\ |
| 3590 | 3621 | @ %h(PT("msg"))</textarea> |
| 3591 | 3622 | @ </tr> |
| 3592 | 3623 | @ <tr> |
| 3593 | 3624 | @ <td></td> |
| 3594 | - if( fossil_strcmp(P("name"),"test2")==0 ){ | |
| 3625 | + if( fossil_strcmp(zName,"test2")==0 ){ | |
| 3595 | 3626 | @ <td><input type="submit" name="submit" value="Dry Run"> |
| 3596 | 3627 | }else{ |
| 3597 | 3628 | @ <td><input type="submit" name="submit" value="Send Message"> |
| 3598 | 3629 | } |
| 3599 | 3630 | @ </tr> |
| 3600 | 3631 | @ </table> |
| 3601 | 3632 | @ </form> |
| 3602 | 3633 | style_finish_page(); |
| 3603 | 3634 | } |
| 3604 | 3635 |
| --- src/alerts.c | |
| +++ src/alerts.c | |
| @@ -634,18 +634,24 @@ | |
| 634 | emailerGetSetting(p, &p->zCmd, "email-send-command"); |
| 635 | }else if( fossil_strcmp(p->zDest, "dir")==0 ){ |
| 636 | emailerGetSetting(p, &p->zDir, "email-send-dir"); |
| 637 | }else if( fossil_strcmp(p->zDest, "blob")==0 ){ |
| 638 | blob_init(&p->out, 0, 0); |
| 639 | }else if( fossil_strcmp(p->zDest, "relay")==0 ){ |
| 640 | const char *zRelay = 0; |
| 641 | emailerGetSetting(p, &zRelay, "email-send-relayhost"); |
| 642 | if( zRelay ){ |
| 643 | u32 smtpFlags = SMTP_DIRECT; |
| 644 | if( mFlags & ALERT_TRACE ) smtpFlags |= SMTP_TRACE_STDOUT; |
| 645 | p->pSmtp = smtp_session_new(domain_of_addr(p->zFrom), zRelay, |
| 646 | smtpFlags, 0); |
| 647 | smtp_client_startup(p->pSmtp); |
| 648 | } |
| 649 | } |
| 650 | return p; |
| 651 | } |
| @@ -3440,16 +3446,28 @@ | |
| 3440 | char *zSubject = PT("subject"); |
| 3441 | int bAll = PB("all"); |
| 3442 | int bAA = PB("aa"); |
| 3443 | int bMods = PB("mods"); |
| 3444 | const char *zSub = db_get("email-subname", "[Fossil Repo]"); |
| 3445 | int bTest2 = fossil_strcmp(P("name"),"test2")==0; |
| 3446 | Blob hdr, body; |
| 3447 | blob_init(&body, 0, 0); |
| 3448 | blob_init(&hdr, 0, 0); |
| 3449 | blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/); |
| 3450 | pSender = alert_sender_new(bTest2 ? "blob" : 0, 0); |
| 3451 | if( zTo[0] ){ |
| 3452 | blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject); |
| 3453 | alert_send(pSender, &hdr, &body, 0); |
| 3454 | } |
| 3455 | if( bAll || bAA || bMods ){ |
| @@ -3483,17 +3501,18 @@ | |
| 3483 | } |
| 3484 | alert_send(pSender, &hdr, &body, 0); |
| 3485 | } |
| 3486 | db_finalize(&q); |
| 3487 | } |
| 3488 | if( bTest2 ){ |
| 3489 | /* If the URL is /announce/test2 instead of just /announce, then no |
| 3490 | ** email is actually sent. Instead, the text of the email that would |
| 3491 | ** have been sent is displayed in the result window. */ |
| 3492 | @ <pre style='border: 2px solid blue; padding: 1ex'> |
| 3493 | @ %h(blob_str(&pSender->out)) |
| 3494 | @ </pre> |
| 3495 | } |
| 3496 | zErr = pSender->zErr; |
| 3497 | pSender->zErr = 0; |
| 3498 | alert_sender_free(pSender); |
| 3499 | return zErr; |
| @@ -3509,24 +3528,31 @@ | |
| 3509 | ** also send a message to an arbitrary email address and/or to all |
| 3510 | ** subscribers regardless of whether or not they have elected to |
| 3511 | ** receive announcements. |
| 3512 | */ |
| 3513 | void announce_page(void){ |
| 3514 | const char *zAction = "announce" |
| 3515 | /* Maintenance reminder: we need an explicit action=THIS_PAGE on the |
| 3516 | ** form element to avoid that a URL arg of to=... passed to this |
| 3517 | ** page ends up overwriting the form-posted "to" value. This |
| 3518 | ** action value differs for the test1 request path. |
| 3519 | */; |
| 3520 | |
| 3521 | login_check_credentials(); |
| 3522 | if( !g.perm.Announce ){ |
| 3523 | login_needed(0); |
| 3524 | return; |
| 3525 | } |
| 3526 | style_set_current_feature("alerts"); |
| 3527 | if( fossil_strcmp(P("name"),"test1")==0 ){ |
| 3528 | /* Visit the /announce/test1 page to see the CGI variables */ |
| 3529 | zAction = "announce/test1"; |
| 3530 | @ <p style='border: 1px solid black; padding: 1ex;'> |
| 3531 | cgi_print_all(0, 0, 0); |
| 3532 | @ </p> |
| @@ -3553,10 +3579,15 @@ | |
| 3553 | return; |
| 3554 | } |
| 3555 | |
| 3556 | style_header("Send Announcement"); |
| 3557 | alert_submenu_common(); |
| 3558 | @ <form method="POST" action="%R/%s(zAction)"> |
| 3559 | login_insert_csrf_secret(); |
| 3560 | @ <table class="subscribe"> |
| 3561 | if( g.perm.Admin ){ |
| 3562 | int aa = PB("aa"); |
| @@ -3589,15 +3620,15 @@ | |
| 3589 | @ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\ |
| 3590 | @ %h(PT("msg"))</textarea> |
| 3591 | @ </tr> |
| 3592 | @ <tr> |
| 3593 | @ <td></td> |
| 3594 | if( fossil_strcmp(P("name"),"test2")==0 ){ |
| 3595 | @ <td><input type="submit" name="submit" value="Dry Run"> |
| 3596 | }else{ |
| 3597 | @ <td><input type="submit" name="submit" value="Send Message"> |
| 3598 | } |
| 3599 | @ </tr> |
| 3600 | @ </table> |
| 3601 | @ </form> |
| 3602 | style_finish_page(); |
| 3603 | } |
| 3604 |
| --- src/alerts.c | |
| +++ src/alerts.c | |
| @@ -634,18 +634,24 @@ | |
| 634 | emailerGetSetting(p, &p->zCmd, "email-send-command"); |
| 635 | }else if( fossil_strcmp(p->zDest, "dir")==0 ){ |
| 636 | emailerGetSetting(p, &p->zDir, "email-send-dir"); |
| 637 | }else if( fossil_strcmp(p->zDest, "blob")==0 ){ |
| 638 | blob_init(&p->out, 0, 0); |
| 639 | }else if( fossil_strcmp(p->zDest, "relay")==0 |
| 640 | || fossil_strcmp(p->zDest, "debug-relay")==0 |
| 641 | ){ |
| 642 | const char *zRelay = 0; |
| 643 | emailerGetSetting(p, &zRelay, "email-send-relayhost"); |
| 644 | if( zRelay ){ |
| 645 | u32 smtpFlags = SMTP_DIRECT; |
| 646 | if( mFlags & ALERT_TRACE ) smtpFlags |= SMTP_TRACE_STDOUT; |
| 647 | blob_init(&p->out, 0, 0); |
| 648 | p->pSmtp = smtp_session_new(domain_of_addr(p->zFrom), zRelay, |
| 649 | smtpFlags, 0); |
| 650 | if( p->zDest[0]=='d' ){ |
| 651 | smtp_session_config(p->pSmtp, SMTP_TRACE_BLOB, &p->out); |
| 652 | } |
| 653 | smtp_client_startup(p->pSmtp); |
| 654 | } |
| 655 | } |
| 656 | return p; |
| 657 | } |
| @@ -3440,16 +3446,28 @@ | |
| 3446 | char *zSubject = PT("subject"); |
| 3447 | int bAll = PB("all"); |
| 3448 | int bAA = PB("aa"); |
| 3449 | int bMods = PB("mods"); |
| 3450 | const char *zSub = db_get("email-subname", "[Fossil Repo]"); |
| 3451 | const char *zName = P("name"); /* Debugging options */ |
| 3452 | const char *zDest = 0; /* How to send the announcement */ |
| 3453 | int bTest = 0; |
| 3454 | Blob hdr, body; |
| 3455 | |
| 3456 | if( fossil_strcmp(zName, "test2")==0 ){ |
| 3457 | bTest = 2; |
| 3458 | zDest = "blob"; |
| 3459 | }else if( fossil_strcmp(zName, "test3")==0 ){ |
| 3460 | bTest = 3; |
| 3461 | if( fossil_strcmp(db_get("email-send-method",""),"relay")==0 ){ |
| 3462 | zDest = "debug-relay"; |
| 3463 | } |
| 3464 | } |
| 3465 | blob_init(&body, 0, 0); |
| 3466 | blob_init(&hdr, 0, 0); |
| 3467 | blob_appendf(&body, "%s", PT("msg")/*safe-for-%s*/); |
| 3468 | pSender = alert_sender_new(zDest, 0); |
| 3469 | if( zTo[0] ){ |
| 3470 | blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject); |
| 3471 | alert_send(pSender, &hdr, &body, 0); |
| 3472 | } |
| 3473 | if( bAll || bAA || bMods ){ |
| @@ -3483,17 +3501,18 @@ | |
| 3501 | } |
| 3502 | alert_send(pSender, &hdr, &body, 0); |
| 3503 | } |
| 3504 | db_finalize(&q); |
| 3505 | } |
| 3506 | if( bTest ){ |
| 3507 | /* If the URL is /announce/test2 instead of just /announce, then no |
| 3508 | ** email is actually sent. Instead, the text of the email that would |
| 3509 | ** have been sent is displayed in the result window. */ |
| 3510 | @ <pre style='border: 2px solid blue; padding: 1ex;'> |
| 3511 | @ %h(blob_str(&pSender->out)) |
| 3512 | @ </pre> |
| 3513 | blob_reset(&pSender->out); |
| 3514 | } |
| 3515 | zErr = pSender->zErr; |
| 3516 | pSender->zErr = 0; |
| 3517 | alert_sender_free(pSender); |
| 3518 | return zErr; |
| @@ -3509,24 +3528,31 @@ | |
| 3528 | ** also send a message to an arbitrary email address and/or to all |
| 3529 | ** subscribers regardless of whether or not they have elected to |
| 3530 | ** receive announcements. |
| 3531 | */ |
| 3532 | void announce_page(void){ |
| 3533 | const char *zAction = "announce"; |
| 3534 | const char *zName = PD("name",""); |
| 3535 | /* |
| 3536 | ** Debugging Notes: |
| 3537 | ** |
| 3538 | ** /announce/test1 -> Shows query parameter values |
| 3539 | ** /announce/test2 -> Shows the formatted message but does |
| 3540 | ** not send it. |
| 3541 | ** /announce/test3 -> Sends the message, but also shows |
| 3542 | ** the SMTP transcript. |
| 3543 | */ |
| 3544 | login_check_credentials(); |
| 3545 | if( !g.perm.Announce ){ |
| 3546 | login_needed(0); |
| 3547 | return; |
| 3548 | } |
| 3549 | if( !g.perm.Setup ){ |
| 3550 | zName = 0; /* Disable debugging feature for non-admin users */ |
| 3551 | } |
| 3552 | style_set_current_feature("alerts"); |
| 3553 | if( fossil_strcmp(zName,"test1")==0 ){ |
| 3554 | /* Visit the /announce/test1 page to see the CGI variables */ |
| 3555 | zAction = "announce/test1"; |
| 3556 | @ <p style='border: 1px solid black; padding: 1ex;'> |
| 3557 | cgi_print_all(0, 0, 0); |
| 3558 | @ </p> |
| @@ -3553,10 +3579,15 @@ | |
| 3579 | return; |
| 3580 | } |
| 3581 | |
| 3582 | style_header("Send Announcement"); |
| 3583 | alert_submenu_common(); |
| 3584 | if( fossil_strcmp(zName,"test2")==0 ){ |
| 3585 | zAction = "announce/test2"; |
| 3586 | }else if( fossil_strcmp(zName,"test3")==0 ){ |
| 3587 | zAction = "announce/test3"; |
| 3588 | } |
| 3589 | @ <form method="POST" action="%R/%s(zAction)"> |
| 3590 | login_insert_csrf_secret(); |
| 3591 | @ <table class="subscribe"> |
| 3592 | if( g.perm.Admin ){ |
| 3593 | int aa = PB("aa"); |
| @@ -3589,15 +3620,15 @@ | |
| 3620 | @ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\ |
| 3621 | @ %h(PT("msg"))</textarea> |
| 3622 | @ </tr> |
| 3623 | @ <tr> |
| 3624 | @ <td></td> |
| 3625 | if( fossil_strcmp(zName,"test2")==0 ){ |
| 3626 | @ <td><input type="submit" name="submit" value="Dry Run"> |
| 3627 | }else{ |
| 3628 | @ <td><input type="submit" name="submit" value="Send Message"> |
| 3629 | } |
| 3630 | @ </tr> |
| 3631 | @ </table> |
| 3632 | @ </form> |
| 3633 | style_finish_page(); |
| 3634 | } |
| 3635 |