diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-06 17:02:50 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-06 17:02:50 +0800 |
commit | 243b8fa1bcadfb312cc334fdd83322a043d97a41 (patch) | |
tree | 695ef854c84e0e7abfc1c2b1b34881bd52e48fc8 /util | |
parent | 1f6dede4cd2f7f35a2a768ec4c1f75aba51b71dd (diff) | |
download | pttbbs-243b8fa1bcadfb312cc334fdd83322a043d97a41.tar pttbbs-243b8fa1bcadfb312cc334fdd83322a043d97a41.tar.gz pttbbs-243b8fa1bcadfb312cc334fdd83322a043d97a41.tar.bz2 pttbbs-243b8fa1bcadfb312cc334fdd83322a043d97a41.tar.lz pttbbs-243b8fa1bcadfb312cc334fdd83322a043d97a41.tar.xz pttbbs-243b8fa1bcadfb312cc334fdd83322a043d97a41.tar.zst pttbbs-243b8fa1bcadfb312cc334fdd83322a043d97a41.zip |
Revision 3000
- sync with ptt1 local modified source
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3000 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util')
-rw-r--r-- | util/Makefile | 10 | ||||
-rw-r--r-- | util/boardlist.c | 15 | ||||
-rw-r--r-- | util/mailangel.c | 143 | ||||
-rw-r--r-- | util/userlist.c | 23 |
4 files changed, 187 insertions, 4 deletions
diff --git a/util/Makefile b/util/Makefile index 7ff2f3b6..4f7e19a4 100644 --- a/util/Makefile +++ b/util/Makefile @@ -23,7 +23,7 @@ CPROG_WITH_UTIL= \ expire mandex rmuid horoscope \ openvice parse_news openticket topusr \ yearsold toplazyBM toplazyBBM writemoney \ - reaper buildAnnounce inndBM shmctl \ + reaper buildAnnounce inndBM mailangel \ outmail chkhbf checkmoney merge_dir \ transman angel gamblegive checkdir \ chesscountry tunepasswd buildir xchatd @@ -37,6 +37,7 @@ CPROG_WITHOUT_UTIL= \ # 下面這些程式會被 install PROGS= ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} \ + shmctl \ BM_money.sh backpasswd.sh mailog.sh opendice.sh \ openticket.sh stock.sh topsong.sh weather.sh \ stock.perl weather.perl toplazyBM.sh toplazyBBM.sh \ @@ -58,6 +59,13 @@ util_${fn}.o: ${BBSBASE} ../mbbsd/${fn}.c $(CCACHE) ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o $@ ../mbbsd/${fn}.c .endfor +shmctl: ${BBSBASE} shmctl.c ${UTIL_OBJS} + $(CCACHE) ${CC} ${CFLAGS} ${LDFLAGS} -o shmctl ${UTIL_OBJS} shmctl.c +#shmctl: ${BBSBASE} shmctl.c ${UTIL_OBJS} +# $(CCACHE) gcc -g -DBBSHOME='"/home/bbs"' -I../include -D__OS_MAJOR_VERSION__="2" -D__OS_MINOR_VERSION__="6" -DPTTBBS_UTIL -O1 -o shmctl ${UTIL_OBJS} shmctl.c +#shmctl: ${BBSBASE} shmctl.cc ${UTIL_OBJS} +# $(CCACHE) g++ -g -DBBSHOME='"/home/bbs"' -I../include -D__OS_MAJOR_VERSION__="2" -D__OS_MINOR_VERSION__="6" -DPTTBBS_UTIL -O1 -o shmctl ${UTIL_OBJS} shmctl.cc + bbsmail: ${BBSBASE} bbsmail.c ../innbbsd/str_decode.c $(UTIL_OBJS) $(CCACHE) $(CC) $(CFLAGS) $(LDFLAGS) -o bbsmail -DUSE_ICONV \ bbsmail.c ../innbbsd/str_decode.c $(UTIL_OBJS) diff --git a/util/boardlist.c b/util/boardlist.c index e530ecfb..a6758f46 100644 --- a/util/boardlist.c +++ b/util/boardlist.c @@ -1,6 +1,19 @@ /* $Id$ */ /* 這是用來將樹狀分類輸出成 perl module (可以給像是 man/ 使用) */ #include "bbs.h" +/* 產生 hash 的內容如下: + + $db{'tobid.BRDNAME'} 把 BRDNAME(大小寫需正確) 查 bid + $db{'parent.BID'} 從 BID 查 parent 的 bid + $db{'tobrdname.BID'} 從 BID 查英文看板名稱 + $db{'look.SBRDNAME'} 從全部都是小寫的 SBRDNAME 查正確的看板大小寫 + $db{'BID.isboard'} 看 BID 是看板(1)或群組(0) + $db{'BID.brdname'} 從 BID 查 brdname + $db{'BID.title'} 查 BID 的中文板名 + $db{'BID.BM.0'} .. $db{'BID.BM.4'} + 該板板主 ID + */ +int parent[MAX_BOARD]; static void load_uidofgid(const int gid, const int type) @@ -68,6 +81,7 @@ void dumpdetail(void) bid = bptr - bcache + 1; printf("$db{'tobid.%s'} = %d;\n", bptr->brdname, bid); + printf("$db{'parent.%d'} = %d;\n", bid, parent[bid]); printf("$db{'tobrdname.%d'} = '%s';\n", bid, bptr->brdname); printf("$db{'look.%s'} = '%s';\n", smallbrdname, bptr->brdname); printf("$db{'%d.isboard'} = %d;\n", bid, @@ -100,6 +114,7 @@ void dumpclass(int gid) continue; printf("%5d,\t", bid); + parent[bid] = gid; } printf("]);\n"); diff --git a/util/mailangel.c b/util/mailangel.c new file mode 100644 index 00000000..f873188c --- /dev/null +++ b/util/mailangel.c @@ -0,0 +1,143 @@ +/* $Id$ */ +#include "bbs.h" + +#ifndef PLAY_ANGEL +int main(){ return 0; } +#else + +int total[MAX_USERS + 1]; +int *list; +int count; +char *mailto = NULL; +char *mailfile = NULL; + +int ListCmp(const void * a, const void * b){ + return *(int*)b - *(int*)a; +} + +int RejCmp(const void * a, const void * b){ + return strcasecmp(SHM->userid[*(int*)a - 1], SHM->userid[*(int*)b - 1]); +} + +void readData(); +void sendResult(); +void mailUser(char *userid); + +int main(int argc, char* argv[]){ + if (argc < 2) { + fprintf(stderr, "Usage: %s file [userid]\n", argv[0]); + exit(1); + } + mailfile = argv[1]; + + if (argc > 2) + mailto = argv[2]; + + readData(); + if (mailto) + mailUser(mailto); + else + sendResult(); + + return 0; +} + +int mailalertuser(char* userid) +{ + userinfo_t *uentp=NULL; + if (userid[0] && (uentp = search_ulist_userid(userid))) + uentp->mailalert=1; + return 0; +} + +void readData(){ + int i, j; + userec_t user; + FILE* fp; + + attach_SHM(); + + fp = fopen(BBSHOME "/.PASSWDS", "rb"); + j = count = 0; + while (fread(&user, sizeof(userec_t), 1, fp) == 1) { + ++j; /* j == uid */ + if (user.userlevel & PERM_ANGEL) { + ++count; + ++total[j]; /* make all angel have total > 0 */ + } else { /* don't have PERM_ANGEL */ + total[j] = INT_MIN; + } + } + fclose(fp); + + list = (int *) malloc(count * sizeof(int)); + j = 0; + for (i = 1; i <= MAX_USERS; ++i) + if (total[i] > 0) { + list[j] = i; + ++j; + } +} + +void sendResult(){ + int i; + for (i = 0; i < count; ++i) { + mailUser(SHM->userid[list[i] - 1]); +// printf("%s\n", SHM->userid[list[i] - 1]); + } +} + +void mailUser(char *userid) +{ + int count; + FILE *fp, *fp2; + time4_t t; + fileheader_t header; + struct stat st; + char filename[512]; + + fp2 = fopen(mailfile, "r"); + if (fp2 == NULL) { + fprintf(stderr, "Cannot open file %s\n", mailfile); + return; + } + + sprintf(filename, BBSHOME "/home/%c/%s", userid[0], userid); + if (stat(filename, &st) == -1) { + if (mkdir(filename, 0755) == -1) { + fprintf(stderr, "mail box create error %s \n", filename); + return; + } + } + else if (!(st.st_mode & S_IFDIR)) { + fprintf(stderr, "mail box error\n"); + return; + } + + stampfile(filename, &header); + fp = fopen(filename, "w"); + if (fp == NULL) { + fprintf(stderr, "Cannot open file %s\n", filename); + return; + } + + t = time(NULL); + fprintf(fp, "作者: 小天使系統\n" + "標題: 給小天使的一封信\n" + "時間: %s\n", + ctime4(&t)); + + while ((count = fread(filename, 1, sizeof(filename), fp2))) { + fwrite(filename, 1, count, fp); + } + fclose(fp); + fclose(fp2); + + strcpy(header.title, "給小天使的一封信"); + strcpy(header.owner, "小天使系統"); + sprintf(filename, BBSHOME "/home/%c/%s/.DIR", userid[0], userid); + append_record(filename, &header, sizeof(header)); + mailalertuser(userid); + printf("%s\n", userid); +} +#endif /* defined PLAY_ANGEL */ diff --git a/util/userlist.c b/util/userlist.c index 3faf5364..12f6b3d9 100644 --- a/util/userlist.c +++ b/util/userlist.c @@ -20,11 +20,28 @@ int main(int argc, char **argv) { perror("shmat"); exit(0); } - - if(argc > 1) { + + if(argc == 2) { + /* list specific id */ + for (i = 0; i < USHM_SIZE; i++) + { + userinfo_t *f = &SHM->uinfo[i]; + if(!f->pid) + continue; + if(strcmp(f->userid, argv[1]) != 0) + continue; + printf( + "id=%s money=%d\n", + f->userid, SHM->money[f->uid - 1]); + } + } + else if(argc > 1) + { for(i = 1; i < argc; i++) SHM->uinfo[atoi(argv[i])].pid = 0; - } else { + } + else + { for(i = counter = 0; i < USHM_SIZE; i++) if(SHM->uinfo[i].pid) { userinfo_t *f; |