summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-02 16:05:32 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-02 16:05:32 +0800
commit2b6bc05af8cee0ee3db2bda82f35282071c76280 (patch)
tree659a664b40a99c8c7cf523ed0435cdf96de03a32
parentbf317a83fd06ffd9a0cf90e15c4f708458d0b496 (diff)
downloadpttbbs-2b6bc05af8cee0ee3db2bda82f35282071c76280.tar
pttbbs-2b6bc05af8cee0ee3db2bda82f35282071c76280.tar.gz
pttbbs-2b6bc05af8cee0ee3db2bda82f35282071c76280.tar.bz2
pttbbs-2b6bc05af8cee0ee3db2bda82f35282071c76280.tar.lz
pttbbs-2b6bc05af8cee0ee3db2bda82f35282071c76280.tar.xz
pttbbs-2b6bc05af8cee0ee3db2bda82f35282071c76280.tar.zst
pttbbs-2b6bc05af8cee0ee3db2bda82f35282071c76280.zip
add chkhbf
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1574 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--sample/crontab3
-rw-r--r--util/Makefile2
-rw-r--r--util/chkhbf.c161
3 files changed, 165 insertions, 1 deletions
diff --git a/sample/crontab b/sample/crontab
index 888dde53..876451c8 100644
--- a/sample/crontab
+++ b/sample/crontab
@@ -105,6 +105,9 @@
# rebuildaloha
25 6 3 * * bin/rebuildaloha.pl > /dev/null
+# 過期板友通知
+#17 7 25 * * bin/chkhbf
+
# utmpfix
0 2-20 * * * bin/shmctl utmpfix -n
0 21 * * * bin/shmctl utmpfix -t 10800
diff --git a/util/Makefile b/util/Makefile
index ba821188..693ee50e 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -22,7 +22,7 @@ CPROG_WITH_UTIL= \
openvice parse_news openticket topusr \
indexuser yearsold toplazyBM toplazyBBM \
reaper buildAnnounce inndBM shmctl \
- outmail
+ outmail chkhbf
# 下面這些程式, 會直接被 compile
CPROG_WITHOUT_UTIL= \
diff --git a/util/chkhbf.c b/util/chkhbf.c
new file mode 100644
index 00000000..e63c13fe
--- /dev/null
+++ b/util/chkhbf.c
@@ -0,0 +1,161 @@
+/* $Id: shmctl.c 1484 2004-01-15 17:37:12Z in2 $ */
+#include "bbs.h"
+
+struct {
+ char userid[IDLEN + 1];
+ time_t lastlogin, expire;
+} explist[MAX_FRIEND];
+time_t now;
+
+void usage(void)
+{
+ fprintf(stderr, "通知隱板板主是否有板友過期/已經過期\n"
+ "usage: chkhbf [-a] [board name [board name]]\n");
+}
+
+int mailalertuid(int tuid)
+{
+ userinfo_t *uentp=NULL;
+ if(tuid>0 && (uentp = (userinfo_t *)search_ulist(tuid)) )
+ uentp->mailalert=1;
+ return 0;
+}
+
+char *CTIMEx(char *buf, time_t t)
+{
+ strcpy(buf, ctime(&t));
+ buf[strlen(buf) - 1] = 0;
+ return buf;
+}
+
+void informBM(char *userid, boardheader_t *bptr, int nEXP)
+{
+ int uid, i;
+ char filename[256], buf[64];
+ fileheader_t mymail;
+ FILE *fp;
+ if( !(uid = getuser(userid)) )
+ return;
+ sprintf(filename, BBSHOME "/home/%c/%s", userid[0], userid);
+ stampfile(filename, &mymail);
+ if( (fp = fopen(filename, "w")) == NULL )
+ return;
+
+ printf("brdname: %s, BM: %s\n", bptr->brdname, userid);
+ fprintf(fp,
+ "作者: 系統通知.\n"
+ "標題: 警告: 貴板板友即將過期/已經過期\n"
+ "時間: %s\n"
+ " %s 的板主您好: \n"
+ " 下列貴板板友即將過期或已經過期:\n"
+ "------------------------------------------------------------\n",
+ CTIMEx(buf, now), bptr->brdname);
+ for( i = 0 ; i < nEXP ; ++i )
+ if( explist[i].expire == -1 )
+ fprintf(fp, "%-15s 已經過期\n", explist[i].userid);
+ else
+ fprintf(fp, "%-15s 即將在 %s 過期\n",
+ explist[i].userid, CTIMEx(buf, explist[i].expire));
+ fprintf(fp,
+ "------------------------------------------------------------\n"
+ "說明:\n"
+ " 為了節省系統資源, 系統將自動清除掉超過四個月未上站\n"
+ "的使用者. 此時若有某位您不認識的使用者恰好註冊了該帳號,\n"
+ "將會視為貴板板友而放行進入.\n"
+ " 建議您暫時將這些使用者自貴板的板友名單中移除.\n"
+ "\n"
+ " 這封信件是由程式自動發出, 請不要直接回覆這封信. 若\n"
+ "您有相關問題請麻煩至看板 SYSOP, 或是直接與看板總管聯繫. :)\n"
+ "\n"
+ BBSNAME "站長群敬上"
+ );
+ fclose(fp);
+
+ strcpy(mymail.title, "警告: 貴板板友即將過期/已經過期");
+ strcpy(mymail.owner, "系統通知.");
+ sprintf(filename, BBSHOME "/home/%c/%s/.DIR", userid[0], userid);
+ mailalertuid(uid);
+ append_record(filename, &mymail, sizeof(mymail));
+}
+
+void chkhbf(boardheader_t *bptr)
+{
+ char fn[256], chkuser[256];
+ int i, nEXP = 0;
+ FILE *fp;
+ sprintf(fn, "boards/%c/%s/visable", bptr->brdname[0], bptr->brdname);
+ if( (fp = fopen(fn, "rt")) == NULL )
+ return;
+ while( fgets(chkuser, sizeof(chkuser), fp) != NULL ){
+ for( i = 0 ; chkuser[i] != 0 && i < sizeof(chkuser) ; ++i )
+ if( !isalnum(chkuser[i]) ){
+ chkuser[i] = 0;
+ break;
+ }
+ if( !getuser(chkuser) || strcmp(chkuser, "guest") == 0 ){
+ strcpy(explist[nEXP].userid, chkuser);
+ explist[nEXP].expire = -1;
+ ++nEXP;
+ }
+ else if( (xuser.lastlogin < now - 86400 * 90) &&
+ !(xuser.userlevel & PERM_XEMPT) ){
+ strcpy(explist[nEXP].userid, chkuser);
+ explist[nEXP].lastlogin = xuser.lastlogin;
+ explist[nEXP].expire = xuser.lastlogin + 86400 * 120;
+ ++nEXP;
+ }
+ }
+ fclose(fp);
+ if( nEXP ){
+ char BM[IDLEN * 3 + 3], *p;
+ strlcpy(BM, bptr->BM, sizeof(BM));
+ for( p = BM ; *p != 0 ; ++p )
+ if( !isalpha(*p) && !isdigit(*p) )
+ *p = ' ';
+ for( i = 0, p = strtok(BM, " ") ; p != NULL ;
+ ++i, p = strtok(NULL, " ") )
+ informBM(p, bptr, nEXP);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ int ch, allboards = 0, i;
+ boardheader_t *bptr;
+ while( (ch = getopt(argc, argv, "ah")) != -1 )
+ switch( ch ){
+ case 'a':
+ allboards = 1;
+ break;
+ case 'h':
+ usage();
+ return 0;
+ }
+
+ chdir(BBSHOME);
+ attach_SHM();
+ argc -= optind;
+ argv += optind;
+ now = time(NULL);
+ if( allboards ){
+ for( i = 0 ; i < MAX_BOARD ; ++i ){
+ bptr = &bcache[i];
+ if( bptr->brdname[0] &&
+ !(bptr->brdattr & (BRD_TOP | BRD_GROUPBOARD)) &&
+ bptr->brdattr & BRD_HIDE )
+ chkhbf(bptr);
+ }
+ }
+ else if( argc > 0 ){
+ int bid;
+ for( i = 0 ; i < argc ; ++i )
+ if( (bid = getbnum(argv[i])) != 0 ) // XXX: bid start 1
+ chkhbf(getbcache(bid));
+ else
+ fprintf(stderr, "%s not found\n", argv[i]);
+ }
+ else
+ usage();
+
+ return 0;
+}