From ae31e19f92e717919ac8e3db9039eb38d2b89aae Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 7 Mar 2002 15:13:44 +0000 Subject: Initial revision git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@1 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- util/birth.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 util/birth.c (limited to 'util/birth.c') diff --git a/util/birth.c b/util/birth.c new file mode 100644 index 00000000..899bf9ee --- /dev/null +++ b/util/birth.c @@ -0,0 +1,99 @@ +/* 壽星程式 96 10/11 */ + +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "common.h" + +#define OUTFILE BBSHOME "/etc/birth.today" + +struct userec_t cuser; + +int bad_user_id() { + register char ch; + int j; + if (strlen(cuser.userid) < 2 || !isalpha(cuser.userid[0])) + return 1; + if (cuser.numlogins == 0 || cuser.numlogins > 15000) + return 1; + if (cuser.numposts > 15000) + return 1; + for (j = 1; (ch = cuser.userid[j]); j++) + { + if (!isalnum(ch)) + return 1; + } + return 0; +} + +int Link(char *src, char *dst) { + char cmd[200]; + + if (link(src, dst) == 0) + return 0; + + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); +} + +int main(argc, argv) + int argc; + char **argv; +{ + FILE *fp1; + fileheader_t mymail; + int i, day = 0; + time_t now; + struct tm *ptime; + int j; + + now = time(NULL); /* back to ancent */ + ptime = localtime(&now); + + if(passwd_mmap()) + exit(1); + + printf("*製表\n"); + fp1 = fopen(OUTFILE, "w"); + + fprintf(fp1, "\n " + "★★★★★★ 壽星大觀 " + "★★★★★★ \n\n"); + fprintf(fp1, "【本日壽星】 \n"); + for(j = 1; j <= MAX_USERS; j++) { + passwd_query(j, &cuser); + if (bad_user_id()) + continue; + if (cuser.month == ptime->tm_mon + 1) + { + if (cuser.day == ptime->tm_mday) + { + char genbuf[200]; + sprintf(genbuf, BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid); + stampfile(genbuf, &mymail); + strcpy(mymail.owner, BBSNAME); + strcpy(mymail.title, "!! 生日快樂 !!"); + mymail.savemode = 0; + unlink(genbuf); + Link(BBSHOME "/etc/Welcome_birth", genbuf); + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", cuser.userid[0], cuser.userid); + append_record(genbuf, &mymail, sizeof(mymail)); + if ((cuser.numlogins + cuser.numposts) < 20) + continue; + + fprintf(fp1, + " [%2d/%-2d] %-14s %-24s login:%-5d post:%-5d\n", + ptime->tm_mon + 1, ptime->tm_mday, cuser.userid, + cuser.username, cuser.numlogins, cuser.numposts); + } + } + } + fclose(fp1); + return 0; +} -- cgit v1.2.3