Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Change the schema of the subscriber table to make it compatible with the "fossil config sync" mechanism. Upgrading through this check-in requires running "fossil email reset" to rebuild the email notification schema, and losing subscriber information. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
9040de46ec2605442c10390d27c9a32b |
User & Date: | drh 2018-06-25 18:13:06.590 |
Context
2018-06-25
| ||
18:17 | Fix a syntax error in the SQL of the "config pull" mechanism. ... (check-in: 4e699c29 user: drh tags: trunk) | |
18:13 | Change the schema of the subscriber table to make it compatible with the "fossil config sync" mechanism. Upgrading through this check-in requires running "fossil email reset" to rebuild the email notification schema, and losing subscriber information. ... (check-in: 9040de46 user: drh tags: trunk) | |
16:19 | Fix harmless compiler warnings. Also remove the "ago" text from the "Last Change" column in the subscriber list webpage. ... (check-in: 69d332ff user: drh tags: trunk) | |
Changes
Changes to src/configure.c.
︙ | ︙ | |||
351 352 353 354 355 356 357 | */ void configure_receive(const char *zName, Blob *pContent, int groupMask){ int checkMask; /* Masks for which we must first check existance of tables */ checkMask = CONFIGSET_ALERT; if( zName[0]=='/' ){ /* The new format */ | | < | < < | | | | | | | < < > > > | < | | < < < | | < < < | | | | | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | */ void configure_receive(const char *zName, Blob *pContent, int groupMask){ int checkMask; /* Masks for which we must first check existance of tables */ checkMask = CONFIGSET_ALERT; if( zName[0]=='/' ){ /* The new format */ char *azToken[24]; int nToken = 0; int ii, jj; int thisMask; Blob name, value, sql; static const struct receiveType { const char *zName; /* Configuration key for this table */ const char *zPrimKey; /* Primary key column */ int nField; /* Number of data fields */ const char *azField[6]; /* Names of the data fields */ } aType[] = { { "/config", "name", 1, { "value", 0,0,0,0,0 } }, { "@user", "login", 4, { "pw","cap","info","photo",0,0} }, { "@shun", "uuid", 1, { "scom", 0,0,0,0,0} }, { "@reportfmt", "title", 3, { "owner","cols","sqlcode",0,0,0}}, { "@concealed", "hash", 1, { "content", 0,0,0,0,0 } }, { "@subscriber","semail",6, { "suname","sdigest","sdonotcall","ssub","sctime","smip"} }, }; /* Locate the receiveType in aType[ii] */ for(ii=0; ii<count(aType); ii++){ if( fossil_strcmp(&aType[ii].zName[1],&zName[1])==0 ) break; } if( ii>=count(aType) ) return; while( blob_token(pContent, &name) && blob_sqltoken(pContent, &value) ){ char *z = blob_terminate(&name); if( !safeSql(z) ) return; if( nToken>0 ){ for(jj=0; jj<aType[ii].nField; jj++){ if( fossil_strcmp(aType[ii].azField[jj], z)==0 ) break; } if( jj>=aType[ii].nField ) continue; }else{ if( !safeInt(z) ) return; } azToken[nToken++] = z; azToken[nToken++] = z = blob_terminate(&value); if( !safeSql(z) ) return; if( nToken>=count(azToken)-1 ) break; } if( nToken<2 ) return; if( aType[ii].zName[0]=='/' ){ thisMask = configure_is_exportable(azToken[1]); }else{ thisMask = configure_is_exportable(aType[ii].zName); } if( (thisMask & groupMask)==0 ) return; if( (thisMask & checkMask)!=0 ){ if( (thisMask & CONFIGSET_ALERT)!=0 ){ email_schema(1); } checkMask &= ~thisMask; } blob_zero(&sql); if( groupMask & CONFIGSET_OVERWRITE ){ if( (thisMask & configHasBeenReset)==0 && aType[ii].zName[0]!='/' ){ db_multi_exec("DELETE FROM \"%w\"", &aType[ii].zName[1]); configHasBeenReset |= thisMask; } blob_append_sql(&sql, "REPLACE INTO "); }else{ blob_append_sql(&sql, "INSERT OR IGNORE INTO "); } blob_append_sql(&sql, "\"%w\"(\"%w\",mtime", &zName[1], aType[ii].zPrimKey); for(jj=2; jj<nToken; jj+=2){ blob_append_sql(&sql, ",\"%w\"", azToken[jj]); } blob_append_sql(&sql,") VALUES(%s", azToken[1] /*safe-for-%s*/); for(jj=2; jj<nToken; jj+=2){ blob_append_sql(&sql, ",%s", azToken[jj+1] /*safe-for-%s*/); } db_multi_exec("%s)", blob_sql_text(&sql)); if( db_changes()==0 ){ blob_reset(&sql); blob_append_sql(&sql, "UPDATE \"%w\" SET mtime=%s", &zName[1], azToken[0]/*safe-for-%s*/); for(jj=2; jj<nToken; jj+=2){ blob_append_sql(&sql, ", \"%w\"=%s", azToken[jj], azToken[jj+1]/*safe-for-%s*/); } blob_append_sql(&sql, " WHERE \"%w\"=%s AND mtime<%s", aType[ii].zPrimKey, azToken[1]/*safe-for-%s*/, azToken[0]/*safe-for-%s*/); db_multi_exec("%s", blob_sql_text(&sql)); } blob_reset(&sql); rebuildMask |= thisMask; } } |
︙ | ︙ | |||
595 596 597 598 599 600 601 | blob_reset(&rec); } db_finalize(&q); } if( (groupMask & CONFIGSET_ALERT)!=0 && db_table_exists("repository","subscriber") ){ | | | | > | | > | | > | 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 | blob_reset(&rec); } db_finalize(&q); } if( (groupMask & CONFIGSET_ALERT)!=0 && db_table_exists("repository","subscriber") ){ db_prepare(&q, "SELECT mtime, quote(semail)," " quote(suname), quote(sdigest)," " quote(sdonotcall), quote(ssub)," " quote(sctime), quote(smip)," " FROM subscriber WHERE sverified" " AND mtime>=%lld", iStart); while( db_step(&q)==SQLITE_ROW ){ blob_appendf(&rec, "%lld %s suname %s sdigest %s sdonotcall %s ssub %s" " sctime %s smip %s", db_column_int64(&q, 0), /* mtime */ db_column_text(&q, 1), /* semail (PK) */ db_column_text(&q, 2), /* suname */ db_column_text(&q, 3), /* sdigest */ db_column_text(&q, 4), /* sdonotcall */ db_column_text(&q, 5), /* ssub */ db_column_text(&q, 6), /* sctime */ db_column_text(&q, 7) /* smip */ ); blob_appendf(pOut, "config /subscriber %d\n%s\n", blob_size(&rec), blob_str(&rec)); nCard++; blob_reset(&rec); } db_finalize(&q); |
︙ | ︙ | |||
836 837 838 839 840 841 842 | }else if( fossil_strcmp(zName,"@user")==0 ){ db_multi_exec("DELETE FROM user"); db_create_default_users(0, 0); }else if( fossil_strcmp(zName,"@concealed")==0 ){ db_multi_exec("DELETE FROM concealed"); }else if( fossil_strcmp(zName,"@shun")==0 ){ db_multi_exec("DELETE FROM shun"); | | | 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 | }else if( fossil_strcmp(zName,"@user")==0 ){ db_multi_exec("DELETE FROM user"); db_create_default_users(0, 0); }else if( fossil_strcmp(zName,"@concealed")==0 ){ db_multi_exec("DELETE FROM concealed"); }else if( fossil_strcmp(zName,"@shun")==0 ){ db_multi_exec("DELETE FROM shun"); }else if( fossil_strcmp(zName,"@subscriber")==0 ){ if( db_table_exists("repository","subscriber") ){ db_multi_exec("DELETE FROM subscriber"); } }else if( fossil_strcmp(zName,"@forum")==0 ){ if( db_table_exists("repository","forumpost") ){ db_multi_exec("DELETE FROM forumpost"); db_multi_exec("DELETE FROM forumthread"); |
︙ | ︙ |
Changes to src/email.c.
︙ | ︙ | |||
46 47 48 49 50 51 52 | @ -- w - Wiki changes @ -- Probably different codes will be added in the future. In the future @ -- we might also add a separate table that allows subscribing to email @ -- notifications for specific branches or tags or tickets. @ -- @ CREATE TABLE repository.subscriber( @ subscriberId INTEGER PRIMARY KEY, -- numeric subscriber ID. Internal use | | | | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | @ -- w - Wiki changes @ -- Probably different codes will be added in the future. In the future @ -- we might also add a separate table that allows subscribing to email @ -- notifications for specific branches or tags or tickets. @ -- @ CREATE TABLE repository.subscriber( @ subscriberId INTEGER PRIMARY KEY, -- numeric subscriber ID. Internal use @ subscriberCode BLOB DEFAULT (randomblob(32)) UNIQUE, -- UUID for subscriber @ semail TEXT UNIQUE COLLATE nocase,-- email address @ suname TEXT, -- corresponding USER entry @ sverified BOOLEAN DEFAULT true, -- email address verified @ sdonotcall BOOLEAN, -- true for Do Not Call @ sdigest BOOLEAN, -- true for daily digests only @ ssub TEXT, -- baseline subscriptions @ sctime INTDATE, -- When this entry was created. unixtime @ mtime INTDATE, -- Last change. unixtime @ smip TEXT -- IP address of last change @ ); @ CREATE INDEX repository.subscriberUname @ ON subscriber(suname) WHERE suname IS NOT NULL; @ @ DROP TABLE IF EXISTS repository.pending_alert; @ -- Email notifications that need to be sent. |
︙ | ︙ | |||
918 919 920 921 922 923 924 | if( suname && suname[0]==0 ) suname = 0; if( PB("sa") ) ssub[nsub++] = 'a'; if( PB("sc") ) ssub[nsub++] = 'c'; if( PB("st") ) ssub[nsub++] = 't'; if( PB("sw") ) ssub[nsub++] = 'w'; ssub[nsub] = 0; db_multi_exec( | | | | < | 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 | if( suname && suname[0]==0 ) suname = 0; if( PB("sa") ) ssub[nsub++] = 'a'; if( PB("sc") ) ssub[nsub++] = 'c'; if( PB("st") ) ssub[nsub++] = 't'; if( PB("sw") ) ssub[nsub++] = 'w'; ssub[nsub] = 0; db_multi_exec( "INSERT INTO subscriber(semail,suname," " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)" "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)", /* semail */ zEAddr, /* suname */ suname, /* sverified */ needCaptcha==0, /* sdigest */ PB("di"), /* ssub */ ssub, /* smip */ g.zIpAddr ); |
︙ | ︙ | |||
1093 1094 1095 1096 1097 1098 1099 | Stmt q; int sa, sc, st, sw; int sdigest, sdonotcall, sverified; const char *ssub; const char *semail; const char *smip; const char *suname; | | | 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 | Stmt q; int sa, sc, st, sw; int sdigest, sdonotcall, sverified; const char *ssub; const char *semail; const char *smip; const char *suname; const char *mtime; const char *sctime; int eErr = 0; char *zErr = 0; if( email_webpages_disabled() ) return; login_check_credentials(); if( zName==0 && login_is_individual() ){ |
︙ | ︙ | |||
1128 1129 1130 1131 1132 1133 1134 | if( suname && suname[0]==0 ) suname = 0; int sverified = PB("sverified"); db_multi_exec( "UPDATE subscriber SET" " sdonotcall=%d," " sdigest=%d," " ssub=%Q," | | | | 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | if( suname && suname[0]==0 ) suname = 0; int sverified = PB("sverified"); db_multi_exec( "UPDATE subscriber SET" " sdonotcall=%d," " sdigest=%d," " ssub=%Q," " mtime=strftime('%%s','now')," " smip=%Q," " suname=%Q," " sverified=%d" " WHERE subscriberCode=hextoblob(%Q)", sdonotcall, sdigest, ssub, g.zIpAddr, suname, sverified, zName ); }else{ db_multi_exec( "UPDATE subscriber SET" " sdonotcall=%d," " sdigest=%d," " ssub=%Q," " mtime=strftime('%%s','now')," " smip=%Q" " WHERE subscriberCode=hextoblob(%Q)", sdonotcall, sdigest, ssub, g.zIpAddr, zName |
︙ | ︙ | |||
1170 1171 1172 1173 1174 1175 1176 | }else{ email_unsubscribe(zName); return; } } db_prepare(&q, "SELECT" | | | | | | | | | | | | 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 | }else{ email_unsubscribe(zName); return; } } db_prepare(&q, "SELECT" " semail," /* 0 */ " sverified," /* 1 */ " sdonotcall," /* 2 */ " sdigest," /* 3 */ " ssub," /* 4 */ " smip," /* 5 */ " suname," /* 6 */ " datetime(mtime,'unixepoch')," /* 7 */ " datetime(sctime,'unixepoch')" /* 8 */ " FROM subscriber WHERE subscriberCode=hextoblob(%Q)", zName); if( db_step(&q)!=SQLITE_ROW ){ db_finalize(&q); cgi_redirect("subscribe"); return; } style_header("Update Subscription"); semail = db_column_text(&q, 0); sverified = db_column_int(&q, 1); sdonotcall = db_column_int(&q, 2); sdigest = db_column_int(&q, 3); ssub = db_column_text(&q, 4); sa = strchr(ssub,'a')!=0; sc = strchr(ssub,'c')!=0; st = strchr(ssub,'t')!=0; sw = strchr(ssub,'w')!=0; smip = db_column_text(&q, 5); suname = db_column_text(&q, 6); mtime = db_column_text(&q, 7); sctime = db_column_text(&q, 8); if( !g.perm.Admin && !sverified ){ db_multi_exec( "UPDATE subscriber SET sverified=1 WHERE subscriberCode=hextoblob(%Q)", zName); @ <h1>Your email alert subscription has been verified!</h1> @ <p>Use the form below to update your subscription information.</p> |
︙ | ︙ | |||
1225 1226 1227 1228 1229 1230 1231 | if( g.perm.Admin ){ @ <tr> @ <td class='form_label'>Created:</td> @ <td>%h(sctime)</td> @ </tr> @ <tr> @ <td class='form_label'>Last Modified:</td> | | | 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 | if( g.perm.Admin ){ @ <tr> @ <td class='form_label'>Created:</td> @ <td>%h(sctime)</td> @ </tr> @ <tr> @ <td class='form_label'>Last Modified:</td> @ <td>%h(mtime)</td> @ </tr> @ <tr> @ <td class='form_label'>IP Address:</td> @ <td>%h(smip)</td> @ </tr> @ <tr> @ <td class="form_label">User:</td> |
︙ | ︙ | |||
1451 1452 1453 1454 1455 1456 1457 | fossil_redirect_home(); return; } email_submenu_common(); style_header("Subscriber List"); blob_init(&sql, 0, 0); blob_append_sql(&sql, | | | | | | | | | | 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 | fossil_redirect_home(); return; } email_submenu_common(); style_header("Subscriber List"); blob_init(&sql, 0, 0); blob_append_sql(&sql, "SELECT hex(subscriberCode)," /* 0 */ " semail," /* 1 */ " ssub," /* 2 */ " suname," /* 3 */ " sverified," /* 4 */ " sdigest," /* 5 */ " date(sctime,'unixepoch')," /* 6 */ " julianday(mtime,'unixepoch')" /* 7 */ " FROM subscriber" ); db_prepare_blob(&q, &sql); rNow = db_double(0.0,"SELECT julianday('now')"); @ <table border="1"> @ <tr> @ <th>Email |
︙ | ︙ |