作者BioStar.bbs@micro.bio.ncue.edu.tw (澎湖小雲雀) 看板: plan
標題Re: [問題] 如何使系統自動寄生日祝賀信給壽星
時間擎天崗 (Wed, 27 Aug 2003 19:10:53 +0800 (CST)) Updated: 2003/08/27
因為敝站的 util/topusr.c 是每小時一次......
(因為某些使用者急於看到自己的「豐功偉業」)
所以將這功能獨立成 util/birth.c ......
: src/util/Makefile
EXE = ..... birth
: crontab -e 加入
1 0 * * * bin/birth > /dev/null 2>&1
: util/birth.c 新增此程式
/*-------------------------------------------------------*/
/* util/birth.c ( NTHU CS MapleBBS Ver 3.00 ) */
/*-------------------------------------------------------*/
/* target : 系統自動送生日祝賀信件 */
/* create : 99/03/29 */
/* update : 01/10/01 */
/* modify : BioStar.bbs@bbs.bio.ncue.edu.tw */
/*-------------------------------------------------------*/
#include "bbs.h"
static UCACHE *ushm;
static inline void
init_ushm()
{
ushm = shm_new(UTMPSHM_KEY, sizeof(UCACHE));
}
static inline void
bbs_biff(userid)
char *userid;
{
UTMP *utmp, *uceil;
usint offset;
offset = ushm->offset;
if (offset > (MAXACTIVE - 1) * sizeof(UTMP))
offset = (MAXACTIVE - 1) * sizeof(UTMP);
utmp = ushm->uslot;
uceil = (void *) utmp + offset;
do
{
if (!str_cmp(utmp->userid, userid))
utmp->status |= STATUS_BIFF;
} while (++utmp <= uceil);
}
int
main()
{
char c;
int year, month, day;
time_t now;
struct tm *ptime;
now = time(NULL);
ptime = localtime(&now);
year = ptime->tm_year;
month = ptime->tm_mon + 1;
day = ptime->tm_mday;
init_ushm();
for (c = 'a'; c <= 'z'; c++)
{
char buf[64];
struct dirent *de;
DIR *dirp;
sprintf(buf, BBSHOME "/usr/%c", c);
chdir(buf);
if (!(dirp = opendir(".")))
continue;
while (de = readdir(dirp))
{
ACCT acct;
int fd;
char *fname;
fname = de->d_name;
if (*fname <= ' ' || *fname == '.')
continue;
sprintf(buf, "%s/.ACCT", fname);
if ((fd = open(buf, O_RDONLY)) < 0)
continue;
read(fd, &acct, sizeof(ACCT));
close(fd);
if (acct.month == month && acct.day == day) /* 本日壽星 */
{
HDR hdr;
char folder[64], lowid[IDLEN + 1];
str_lower(lowid, acct.userid);
sprintf(folder, "%s/.DIR", lowid);
hdr_stamp(folder, HDR_COPY, &hdr, BBSHOME "etc/birth");
strcpy(hdr.owner, STR_SYSOP);
strcpy(hdr.title, "生日快樂");
hdr.xmode = 0;
rec_add(folder, &hdr, sizeof(HDR));
bbs_biff(acct.userid);
}
}
closedir(dirp);
}
}
--
┌┼ Author: 彰化師大生物系˙吟風‧眺月‧擎天崗 micro.bio.ncue.edu.tw
└┘ Origin: BioStar 從 163.23.212.15 發表