Fossil SCM

Continuing refinement of the web pages for handling email subscriptions.

drh 2018-06-21 22:37 UTC email-alerts
Commit 84d0d853177588ebccad753a0379b02924be02dba381dd584a4efb778f491e4e
3 files changed +54 -19 +5 +2 -2
+54 -19
--- src/email.c
+++ src/email.c
@@ -93,10 +93,29 @@
9393
if( !db_table_exists("repository", "subscriber") ){
9494
db_multi_exec(zEmailInit/*works-like:""*/);
9595
}
9696
}
9797
98
+/*
99
+** Return true if email alerts are active.
100
+*/
101
+int email_enabled(void){
102
+ if( !db_table_exists("repository", "subscriber") ) return 0;
103
+ if( fossil_strcmp(db_get("email-send-method","off"),"off")==0 ) return 0;
104
+ return 1;
105
+}
106
+
107
+/*
108
+** Insert a "Subscriber List" submenu link if the current user
109
+** is an administrator.
110
+*/
111
+void email_subscriber_list_link(void){
112
+ if( g.perm.Admin ){
113
+ style_submenu_element("Subscriber List","%R/subscribers");
114
+ }
115
+}
116
+
98117
99118
/*
100119
** WEBPAGE: setup_email
101120
**
102121
** Administrative page for configuring and controlling email notification
@@ -113,52 +132,52 @@
113132
login_needed(0);
114133
return;
115134
}
116135
db_begin_transaction();
117136
118
- style_submenu_element("Subscriber List", "%R/subscribers");
137
+ email_subscriber_list_link();
119138
style_header("Email Notification Setup");
120139
@ <form action="%R/setup_email" method="post"><div>
121140
@ <input type="submit" name="submit" value="Apply Changes" /><hr>
122141
login_insert_csrf_secret();
123
- multiple_choice_attribute("Email Send Method","email-send-method",
124
- "esm", "off", count(azSendMethods)/2, azSendMethods);
142
+ multiple_choice_attribute("Email Send Method", "email-send-method", "esm",
143
+ "off", count(azSendMethods)/2, azSendMethods);
125144
@ <p>How to send email. The "Pipe to a command"
126145
@ method is the usual choice in production.
127146
@ (Property: "email-send-method")</p>
128147
@ <hr>
129
- entry_attribute("Command To Pipe Email To", 80, "esc",
130
- "email-send-command", "sendmail -t", 0);
148
+ entry_attribute("Command To Pipe Email To", 80, "email-send-command",
149
+ "ecmd", "sendmail -t", 0);
131150
@ <p>When the send method is "pipe to a command", this is the command
132151
@ that is run. Email messages are piped into the standard input of this
133152
@ command. The command is expected to extract the sender address,
134153
@ recepient addresses, and subject from the header of the piped email
135154
@ text. (Property: "email-send-command")</p>
136155
137
- entry_attribute("Database In Which To Store Email", 60, "esdb",
138
- "email-send-db", "", 0);
156
+ entry_attribute("Database In Which To Store Email", 60, "email-send-db",
157
+ "esdb", "", 0);
139158
@ <p>When the send method is "store in a databaes", each email message is
140159
@ stored in an SQLite database file with the name given here.
141160
@ (Property: "email-send-db")</p>
142161
143
- entry_attribute("Directory In Which To Store Email", 60, "esdir",
144
- "email-send-dir", "", 0);
162
+ entry_attribute("Directory In Which To Store Email", 60, "email-send-dir",
163
+ "esdir", "", 0);
145164
@ <p>When the send method is "store in a directory", each email message is
146165
@ stored as a separate file in the directory shown here.
147166
@ (Property: "email-send-dir")</p>
148167
@ <hr>
149168
150
- entry_attribute("\"From\" email address", 40, "ef",
151
- "email-self", "", 0);
169
+ entry_attribute("\"From\" email address", 40, "email-self",
170
+ "eself", "", 0);
152171
@ <p>This is the email from which email notifications are sent. The
153172
@ system administrator should arrange for emails sent to this address
154173
@ to be handed off to the "fossil email incoming" command so that Fossil
155174
@ can handle bounces. (Property: "email-self")</p>
156175
@ <hr>
157176
158
- entry_attribute("Administrator email address", 40, "ea",
159
- "email-admin", "", 0);
177
+ entry_attribute("Administrator email address", 40, "email-admin",
178
+ "eadmin", "", 0);
160179
@ <p>This is the email for the human administrator for the system.
161180
@ Abuse and trouble reports are send here.
162181
@ (Property: "email-admin")</p>
163182
@ <hr>
164183
@ <p><input type="submit" name="submit" value="Apply Changes" /></p>
@@ -566,13 +585,14 @@
566585
&& db_exists("SELECT 1 FROM subscriber WHERE suname=%Q",g.zLogin)
567586
){
568587
/* This person is already signed up for email alerts. Jump
569588
** to the screen that lets them edit their alert preferences.
570589
*/
571
- cgi_redirect("%R/alerts");
590
+ cgi_redirectf("%R/alerts");
572591
return;
573592
}
593
+ email_subscriber_list_link();
574594
needCaptcha = !login_is_individual();
575595
if( P("submit")
576596
&& cgi_csrf_safe(1)
577597
&& subscribe_error_check(&eErr,&zErr,needCaptcha)
578598
){
@@ -682,11 +702,16 @@
682702
}
683703
@ </td>
684704
@ </tr>
685705
@ <tr>
686706
@ <td></td>
687
- @ <td><input type="submit" name="submit" value="Submit"></td>
707
+ if( needCaptcha && !email_enabled() ){
708
+ @ <td><input type="submit" name="submit" value="Submit" disabled>
709
+ @ (Email current disabled)</td>
710
+ }else{
711
+ @ <td><input type="submit" name="submit" value="Submit"></td>
712
+ }
688713
@ </tr>
689714
@ </table>
690715
if( needCaptcha ){
691716
@ <div class="captcha"><table class="captcha"><tr><td><pre>
692717
@ %h(zCaptcha)
@@ -739,10 +764,11 @@
739764
}
740765
if( zName==0 || !validate16(zName, -1) ){
741766
cgi_redirect("subscribe");
742767
return;
743768
}
769
+ email_subscriber_list_link();
744770
if( P("submit")!=0 && cgi_csrf_safe(1) ){
745771
int sdonotcall = PB("sdonotcall");
746772
int sdigest = PB("sdigest");
747773
char ssub[10];
748774
int nsub = 0;
@@ -907,23 +933,32 @@
907933
blob_append_sql(&sql,
908934
"SELECT hex(subscriberCode),"
909935
" semail,"
910936
" ssub,"
911937
" suname,"
912
- " sverified"
938
+ " sverified,"
939
+ " sdigest"
913940
" FROM subscriber"
914941
);
915942
db_prepare_blob(&q, &sql);
916
- @ <table>
943
+ @ <table border="1">
944
+ @ <tr>
945
+ @ <th>Email
946
+ @ <th>Events
947
+ @ <th>Digest-Only?
948
+ @ <th>User
949
+ @ <th>Verified?
950
+ @ </tr>
917951
while( db_step(&q)==SQLITE_ROW ){
918952
@ <tr>
919953
@ <td><a href='%R/alerts/%s(db_column_text(&q,0))'>\
920954
@ %h(db_column_text(&q,1))</a></td>
955
+ @ <td>%h(db_column_text(&q,2))</td>
956
+ @ <td>%s(db_column_int(&q,5)?"digest":"")</td>
921957
@ <td>%h(db_column_text(&q,3))</td>
922
- @ <td>%h(db_column_text(&q,4))</td>
923
- @ <td>%s(db_column_int(&q,5)?"":"unverified")</td>
958
+ @ <td>%s(db_column_int(&q,4)?"yes":"pending")</td>
924959
@ </tr>
925960
}
926961
@ </table>
927962
db_finalize(&q);
928963
style_footer();
929964
}
930965
--- src/email.c
+++ src/email.c
@@ -93,10 +93,29 @@
93 if( !db_table_exists("repository", "subscriber") ){
94 db_multi_exec(zEmailInit/*works-like:""*/);
95 }
96 }
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
99 /*
100 ** WEBPAGE: setup_email
101 **
102 ** Administrative page for configuring and controlling email notification
@@ -113,52 +132,52 @@
113 login_needed(0);
114 return;
115 }
116 db_begin_transaction();
117
118 style_submenu_element("Subscriber List", "%R/subscribers");
119 style_header("Email Notification Setup");
120 @ <form action="%R/setup_email" method="post"><div>
121 @ <input type="submit" name="submit" value="Apply Changes" /><hr>
122 login_insert_csrf_secret();
123 multiple_choice_attribute("Email Send Method","email-send-method",
124 "esm", "off", count(azSendMethods)/2, azSendMethods);
125 @ <p>How to send email. The "Pipe to a command"
126 @ method is the usual choice in production.
127 @ (Property: "email-send-method")</p>
128 @ <hr>
129 entry_attribute("Command To Pipe Email To", 80, "esc",
130 "email-send-command", "sendmail -t", 0);
131 @ <p>When the send method is "pipe to a command", this is the command
132 @ that is run. Email messages are piped into the standard input of this
133 @ command. The command is expected to extract the sender address,
134 @ recepient addresses, and subject from the header of the piped email
135 @ text. (Property: "email-send-command")</p>
136
137 entry_attribute("Database In Which To Store Email", 60, "esdb",
138 "email-send-db", "", 0);
139 @ <p>When the send method is "store in a databaes", each email message is
140 @ stored in an SQLite database file with the name given here.
141 @ (Property: "email-send-db")</p>
142
143 entry_attribute("Directory In Which To Store Email", 60, "esdir",
144 "email-send-dir", "", 0);
145 @ <p>When the send method is "store in a directory", each email message is
146 @ stored as a separate file in the directory shown here.
147 @ (Property: "email-send-dir")</p>
148 @ <hr>
149
150 entry_attribute("\"From\" email address", 40, "ef",
151 "email-self", "", 0);
152 @ <p>This is the email from which email notifications are sent. The
153 @ system administrator should arrange for emails sent to this address
154 @ to be handed off to the "fossil email incoming" command so that Fossil
155 @ can handle bounces. (Property: "email-self")</p>
156 @ <hr>
157
158 entry_attribute("Administrator email address", 40, "ea",
159 "email-admin", "", 0);
160 @ <p>This is the email for the human administrator for the system.
161 @ Abuse and trouble reports are send here.
162 @ (Property: "email-admin")</p>
163 @ <hr>
164 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
@@ -566,13 +585,14 @@
566 && db_exists("SELECT 1 FROM subscriber WHERE suname=%Q",g.zLogin)
567 ){
568 /* This person is already signed up for email alerts. Jump
569 ** to the screen that lets them edit their alert preferences.
570 */
571 cgi_redirect("%R/alerts");
572 return;
573 }
 
574 needCaptcha = !login_is_individual();
575 if( P("submit")
576 && cgi_csrf_safe(1)
577 && subscribe_error_check(&eErr,&zErr,needCaptcha)
578 ){
@@ -682,11 +702,16 @@
682 }
683 @ </td>
684 @ </tr>
685 @ <tr>
686 @ <td></td>
687 @ <td><input type="submit" name="submit" value="Submit"></td>
 
 
 
 
 
688 @ </tr>
689 @ </table>
690 if( needCaptcha ){
691 @ <div class="captcha"><table class="captcha"><tr><td><pre>
692 @ %h(zCaptcha)
@@ -739,10 +764,11 @@
739 }
740 if( zName==0 || !validate16(zName, -1) ){
741 cgi_redirect("subscribe");
742 return;
743 }
 
744 if( P("submit")!=0 && cgi_csrf_safe(1) ){
745 int sdonotcall = PB("sdonotcall");
746 int sdigest = PB("sdigest");
747 char ssub[10];
748 int nsub = 0;
@@ -907,23 +933,32 @@
907 blob_append_sql(&sql,
908 "SELECT hex(subscriberCode),"
909 " semail,"
910 " ssub,"
911 " suname,"
912 " sverified"
 
913 " FROM subscriber"
914 );
915 db_prepare_blob(&q, &sql);
916 @ <table>
 
 
 
 
 
 
 
917 while( db_step(&q)==SQLITE_ROW ){
918 @ <tr>
919 @ <td><a href='%R/alerts/%s(db_column_text(&q,0))'>\
920 @ %h(db_column_text(&q,1))</a></td>
 
 
921 @ <td>%h(db_column_text(&q,3))</td>
922 @ <td>%h(db_column_text(&q,4))</td>
923 @ <td>%s(db_column_int(&q,5)?"":"unverified")</td>
924 @ </tr>
925 }
926 @ </table>
927 db_finalize(&q);
928 style_footer();
929 }
930
--- src/email.c
+++ src/email.c
@@ -93,10 +93,29 @@
93 if( !db_table_exists("repository", "subscriber") ){
94 db_multi_exec(zEmailInit/*works-like:""*/);
95 }
96 }
97
98 /*
99 ** Return true if email alerts are active.
100 */
101 int email_enabled(void){
102 if( !db_table_exists("repository", "subscriber") ) return 0;
103 if( fossil_strcmp(db_get("email-send-method","off"),"off")==0 ) return 0;
104 return 1;
105 }
106
107 /*
108 ** Insert a "Subscriber List" submenu link if the current user
109 ** is an administrator.
110 */
111 void email_subscriber_list_link(void){
112 if( g.perm.Admin ){
113 style_submenu_element("Subscriber List","%R/subscribers");
114 }
115 }
116
117
118 /*
119 ** WEBPAGE: setup_email
120 **
121 ** Administrative page for configuring and controlling email notification
@@ -113,52 +132,52 @@
132 login_needed(0);
133 return;
134 }
135 db_begin_transaction();
136
137 email_subscriber_list_link();
138 style_header("Email Notification Setup");
139 @ <form action="%R/setup_email" method="post"><div>
140 @ <input type="submit" name="submit" value="Apply Changes" /><hr>
141 login_insert_csrf_secret();
142 multiple_choice_attribute("Email Send Method", "email-send-method", "esm",
143 "off", count(azSendMethods)/2, azSendMethods);
144 @ <p>How to send email. The "Pipe to a command"
145 @ method is the usual choice in production.
146 @ (Property: "email-send-method")</p>
147 @ <hr>
148 entry_attribute("Command To Pipe Email To", 80, "email-send-command",
149 "ecmd", "sendmail -t", 0);
150 @ <p>When the send method is "pipe to a command", this is the command
151 @ that is run. Email messages are piped into the standard input of this
152 @ command. The command is expected to extract the sender address,
153 @ recepient addresses, and subject from the header of the piped email
154 @ text. (Property: "email-send-command")</p>
155
156 entry_attribute("Database In Which To Store Email", 60, "email-send-db",
157 "esdb", "", 0);
158 @ <p>When the send method is "store in a databaes", each email message is
159 @ stored in an SQLite database file with the name given here.
160 @ (Property: "email-send-db")</p>
161
162 entry_attribute("Directory In Which To Store Email", 60, "email-send-dir",
163 "esdir", "", 0);
164 @ <p>When the send method is "store in a directory", each email message is
165 @ stored as a separate file in the directory shown here.
166 @ (Property: "email-send-dir")</p>
167 @ <hr>
168
169 entry_attribute("\"From\" email address", 40, "email-self",
170 "eself", "", 0);
171 @ <p>This is the email from which email notifications are sent. The
172 @ system administrator should arrange for emails sent to this address
173 @ to be handed off to the "fossil email incoming" command so that Fossil
174 @ can handle bounces. (Property: "email-self")</p>
175 @ <hr>
176
177 entry_attribute("Administrator email address", 40, "email-admin",
178 "eadmin", "", 0);
179 @ <p>This is the email for the human administrator for the system.
180 @ Abuse and trouble reports are send here.
181 @ (Property: "email-admin")</p>
182 @ <hr>
183 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
@@ -566,13 +585,14 @@
585 && db_exists("SELECT 1 FROM subscriber WHERE suname=%Q",g.zLogin)
586 ){
587 /* This person is already signed up for email alerts. Jump
588 ** to the screen that lets them edit their alert preferences.
589 */
590 cgi_redirectf("%R/alerts");
591 return;
592 }
593 email_subscriber_list_link();
594 needCaptcha = !login_is_individual();
595 if( P("submit")
596 && cgi_csrf_safe(1)
597 && subscribe_error_check(&eErr,&zErr,needCaptcha)
598 ){
@@ -682,11 +702,16 @@
702 }
703 @ </td>
704 @ </tr>
705 @ <tr>
706 @ <td></td>
707 if( needCaptcha && !email_enabled() ){
708 @ <td><input type="submit" name="submit" value="Submit" disabled>
709 @ (Email current disabled)</td>
710 }else{
711 @ <td><input type="submit" name="submit" value="Submit"></td>
712 }
713 @ </tr>
714 @ </table>
715 if( needCaptcha ){
716 @ <div class="captcha"><table class="captcha"><tr><td><pre>
717 @ %h(zCaptcha)
@@ -739,10 +764,11 @@
764 }
765 if( zName==0 || !validate16(zName, -1) ){
766 cgi_redirect("subscribe");
767 return;
768 }
769 email_subscriber_list_link();
770 if( P("submit")!=0 && cgi_csrf_safe(1) ){
771 int sdonotcall = PB("sdonotcall");
772 int sdigest = PB("sdigest");
773 char ssub[10];
774 int nsub = 0;
@@ -907,23 +933,32 @@
933 blob_append_sql(&sql,
934 "SELECT hex(subscriberCode),"
935 " semail,"
936 " ssub,"
937 " suname,"
938 " sverified,"
939 " sdigest"
940 " FROM subscriber"
941 );
942 db_prepare_blob(&q, &sql);
943 @ <table border="1">
944 @ <tr>
945 @ <th>Email
946 @ <th>Events
947 @ <th>Digest-Only?
948 @ <th>User
949 @ <th>Verified?
950 @ </tr>
951 while( db_step(&q)==SQLITE_ROW ){
952 @ <tr>
953 @ <td><a href='%R/alerts/%s(db_column_text(&q,0))'>\
954 @ %h(db_column_text(&q,1))</a></td>
955 @ <td>%h(db_column_text(&q,2))</td>
956 @ <td>%s(db_column_int(&q,5)?"digest":"")</td>
957 @ <td>%h(db_column_text(&q,3))</td>
958 @ <td>%s(db_column_int(&q,4)?"yes":"pending")</td>
 
959 @ </tr>
960 }
961 @ </table>
962 db_finalize(&q);
963 style_footer();
964 }
965
--- src/login.c
+++ src/login.c
@@ -730,10 +730,15 @@
730730
free(zCaptcha);
731731
}
732732
@ </form>
733733
}
734734
if( g.zLogin && g.perm.Password ){
735
+ if( email_enabled() ){
736
+ @ <hr>
737
+ @ <p>Configure <a href="%R/alerts">Email Alerts</a>
738
+ @ for user <b>%h(g.zLogin)</b></p>
739
+ }
735740
@ <hr />
736741
@ <p>Change Password for user <b>%h(g.zLogin)</b>:</p>
737742
form_begin(0, "%R/login");
738743
@ <table>
739744
@ <tr><td class="form_label">Old Password:</td>
740745
--- src/login.c
+++ src/login.c
@@ -730,10 +730,15 @@
730 free(zCaptcha);
731 }
732 @ </form>
733 }
734 if( g.zLogin && g.perm.Password ){
 
 
 
 
 
735 @ <hr />
736 @ <p>Change Password for user <b>%h(g.zLogin)</b>:</p>
737 form_begin(0, "%R/login");
738 @ <table>
739 @ <tr><td class="form_label">Old Password:</td>
740
--- src/login.c
+++ src/login.c
@@ -730,10 +730,15 @@
730 free(zCaptcha);
731 }
732 @ </form>
733 }
734 if( g.zLogin && g.perm.Password ){
735 if( email_enabled() ){
736 @ <hr>
737 @ <p>Configure <a href="%R/alerts">Email Alerts</a>
738 @ for user <b>%h(g.zLogin)</b></p>
739 }
740 @ <hr />
741 @ <p>Change Password for user <b>%h(g.zLogin)</b>:</p>
742 form_begin(0, "%R/login");
743 @ <table>
744 @ <tr><td class="form_label">Old Password:</td>
745
+2 -2
--- src/setup.c
+++ src/setup.c
@@ -1022,13 +1022,13 @@
10221022
admin_log("Set entry_attribute %Q to: %.*s%s",
10231023
zVar, 20, zQ, (nZQ>20 ? "..." : ""));
10241024
zVal = zQ;
10251025
}
10261026
@ <input type="text" id="%s(zQParm)" name="%s(zQParm)" value="%h(zVal)" \
1027
- @ size="%d(width)"
1027
+ @ size="%d(width)" \
10281028
if( disabled ){
1029
- @ disabled="disabled"
1029
+ @ disabled="disabled" \
10301030
}
10311031
@ /> <b>%s(zLabel)</b>
10321032
}
10331033
10341034
/*
10351035
--- src/setup.c
+++ src/setup.c
@@ -1022,13 +1022,13 @@
1022 admin_log("Set entry_attribute %Q to: %.*s%s",
1023 zVar, 20, zQ, (nZQ>20 ? "..." : ""));
1024 zVal = zQ;
1025 }
1026 @ <input type="text" id="%s(zQParm)" name="%s(zQParm)" value="%h(zVal)" \
1027 @ size="%d(width)"
1028 if( disabled ){
1029 @ disabled="disabled"
1030 }
1031 @ /> <b>%s(zLabel)</b>
1032 }
1033
1034 /*
1035
--- src/setup.c
+++ src/setup.c
@@ -1022,13 +1022,13 @@
1022 admin_log("Set entry_attribute %Q to: %.*s%s",
1023 zVar, 20, zQ, (nZQ>20 ? "..." : ""));
1024 zVal = zQ;
1025 }
1026 @ <input type="text" id="%s(zQParm)" name="%s(zQParm)" value="%h(zVal)" \
1027 @ size="%d(width)" \
1028 if( disabled ){
1029 @ disabled="disabled" \
1030 }
1031 @ /> <b>%s(zLabel)</b>
1032 }
1033
1034 /*
1035

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button