summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2010-10-04 00:41:28 +0800
committerwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2010-10-04 00:41:28 +0800
commita817b4f057ef097e8d5928300afb067d52039806 (patch)
treeee0d43c8d4d7c4760e8b1dca7d451b32f91a3f80
parent4aa5a0a32d0ce0fef269f9db04f2abacf2f9134b (diff)
downloadpttbbs-a817b4f057ef097e8d5928300afb067d52039806.tar
pttbbs-a817b4f057ef097e8d5928300afb067d52039806.tar.gz
pttbbs-a817b4f057ef097e8d5928300afb067d52039806.tar.bz2
pttbbs-a817b4f057ef097e8d5928300afb067d52039806.tar.lz
pttbbs-a817b4f057ef097e8d5928300afb067d52039806.tar.xz
pttbbs-a817b4f057ef097e8d5928300afb067d52039806.tar.zst
pttbbs-a817b4f057ef097e8d5928300afb067d52039806.zip
Clean up code, change filenames to MACROS
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5104 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/util/account.c145
1 files changed, 78 insertions, 67 deletions
diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c
index 0b99b8c4..99dbacb5 100644
--- a/pttbbs/util/account.c
+++ b/pttbbs/util/account.c
@@ -28,22 +28,21 @@ reset_garbage(void)
*/
}
-void
-keeplog(char *fpath, char *board, char *title, char *sym)
+static void
+keeplog(const char *fpath, const char *board, const char *title, const char *sym)
{
fileheader_t fhdr;
int bid;
- char genbuf[256], buf[256];
+ char genbuf[PATHLEN], buf[256];
if (!board)
- board = "Record";
+ board = BN_RECORD;
- sprintf(genbuf, BBSHOME "/boards/%c/%s", board[0], board);
+ setbpath(genbuf, board);
stampfile(genbuf, &fhdr);
- sprintf(buf, "mv %s %s", fpath, genbuf);
- system(buf);
+ Rename(fpath, genbuf);
- if( sym ){
+ if (sym) {
sprintf(buf, "log/%s", sym);
unlink(buf);
symlink(genbuf, buf);
@@ -51,9 +50,9 @@ keeplog(char *fpath, char *board, char *title, char *sym)
/*
* printf("keep record:[%s][%s][%s][%s]\n",fpath, board, title,genbuf);
*/
- strcpy(fhdr.title, title);
- strcpy(fhdr.owner, "[歷史老師]");
- sprintf(genbuf, "boards/%c/%s/.DIR", board[0], board);
+ strlcpy(fhdr.title, title, sizeof(fhdr.title));
+ strlcpy(fhdr.owner, "[歷史老師]", sizeof(fhdr.owner));
+ setbfile(genbuf, board, FN_DIR);
append_record(genbuf, &fhdr, sizeof(fhdr));
/* XXX: bid of cache.c's getbnum starts from 1 */
if ((bid = getbnum(board)) > 0)
@@ -74,43 +73,22 @@ my_outs(FILE *fp, char *buf, char mode)
}
}
-/* XXX: 怪怪的, 看不懂在 gzip() 什麼, 而且其中的 stamp 好像都亂傳進來 */
+// moves "source" to "target""suffix", then gzips it
static void
-gzip(char *source, char *target, char *stamp)
+gzip(const char *source, const char *target, const char *suffix)
{
- char buf[128];
- sprintf(buf, "gzip -f9n adm/%s%s", target, stamp);
- rename(source, &buf[14]);
+ char buf[PATHLEN];
+ snprintf(buf, sizeof(buf), "gzip -f9n adm/%s%s", target, suffix);
+ Rename(source, &buf[14]);
system(buf);
}
-int
-main(int argc, char **argv)
+static int
+parse_usies(const char *fn, struct tm *ptime, int act[27])
{
- int i, j;
- int item, mo, da, peak_hour_login = 0,
- max_reg = 0, peak_hour = 0;
- int day_login, max_day_login;
- int max_hour_login;
- int max_online;
- char *act_file = ".act";
- char *log_file = "usies";
- char *wday_str = "UMTWRFS";
- char buf[256], buf1[256], *p;
- FILE *fp, *fp1;
- int act[27]; /* 次數/累計時間/pointer */
- time4_t now;
- struct tm *ptime;
- int per_hour_unit = 100;
-
- attach_SHM();
- nice(10);
- chdir(BBSHOME);
- now = time(NULL) - ADJUST_M * 60; /* back to ancent */
- ptime = localtime4(&now);
-
- memset(act, 0, sizeof(act));
- printf("次數/累計時間\n");
+ const char const act_file[] = ".act";
+ char buf[256], *p;
+ FILE *fp;
// load parsed result
if ((ptime->tm_hour != 0) && (fp = fopen(act_file, "r"))) {
@@ -119,13 +97,15 @@ main(int argc, char **argv)
}
// parse "usies"
- if ((fp = fopen(log_file, "r")) == NULL) {
+ if ((fp = fopen(fn, "r")) == NULL) {
printf("cann't open usies\n");
return 1;
}
+
if (act[26])
fseek(fp, act[26], 0);
- while (fgets(buf, 256, fp)) {
+
+ while (fgets(buf, sizeof(buf), fp)) {
int hour;
buf[11 + 2] = 0;
hour = atoi(buf + 11);
@@ -138,7 +118,7 @@ main(int argc, char **argv)
act[hour]++;
continue;
}
- if ((p = (char *)strstr(buf + 40, "Stay:"))) {
+ if ((p = strstr(buf + 40, "Stay:"))) {
if ((hour = atoi(p + 5))) {
act[24] += hour;
act[25]++;
@@ -155,6 +135,38 @@ main(int argc, char **argv)
fclose(fp);
}
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ int i, j;
+ int item, mo, da, peak_hour_login = 0,
+ max_reg = 0, peak_hour = 0;
+ int day_login, max_day_login;
+ int max_hour_login;
+ int max_online;
+ const char const log_file[] = "usies";
+ const char const wday_str[] = "UMTWRFS";
+ char buf[256], buf1[256];
+ FILE *fp, *fp1;
+ int act[27]; /* 次數/累計時間/pointer */
+ time4_t now;
+ struct tm *ptime;
+ int per_hour_unit = 100;
+
+ attach_SHM();
+ nice(10);
+ chdir(BBSHOME);
+ now = time(NULL) - ADJUST_M * 60; /* back to ancent */
+ ptime = localtime4(&now);
+
+ memset(act, 0, sizeof(act));
+
+ printf("次數/累計時間\n");
+ parse_usies(log_file, ptime, act);
+
peak_hour_login = 0;
day_login = 0;
for (i = 0; i < 24; i++) {
@@ -167,11 +179,11 @@ main(int argc, char **argv)
item = peak_hour_login / ACCOUNT_MAX_LINE + 1;
if (!ptime->tm_hour) {
- keeplog("etc/today", "Record", "上站人次統計", NULL);
- keeplog(FN_MONEY, "Security", "本日金錢往來記錄", NULL);
- keeplog("etc/illegal_money", "Security", "本日違法賺錢記錄", NULL);
- keeplog("etc/osong.log", "Security", "本日點歌記錄", NULL);
- keeplog("etc/chicken", "Record", "雞場報告", NULL);
+ keeplog("etc/today", BN_RECORD, "上站人次統計", NULL);
+ keeplog(FN_MONEY, BN_SECURITY, "本日金錢往來記錄", NULL);
+ keeplog("etc/illegal_money", BN_SECURITY, "本日違法賺錢記錄", NULL);
+ keeplog("etc/osong.log", BN_SECURITY, "本日點歌記錄", NULL);
+ keeplog("etc/chicken", BN_RECORD, "雞場報告", NULL);
}
/* -------------------------------------------------------------- */
@@ -205,12 +217,6 @@ main(int argc, char **argv)
fclose(fp);
/* -------------------------------------------------------------- */
-
- sprintf(buf, "-%02d%02d%02d",
- ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday);
-
-
-
printf("歷史事件處理\n");
/* Ptt 歷史事件處理 */
if ((fp = fopen("etc/history.data", "r"))) { /* 最多同時上線 */
@@ -260,23 +266,27 @@ main(int argc, char **argv)
fclose(fp1);
}
}
+
if (ptime->tm_hour == 0) {
system("/bin/cp etc/today etc/yesterday");
/* system("rm -f note.dat"); */
+
/* Ptt */
- sprintf(buf1, "[公安報告] 使用者上線監控 [%02d/%02d:%02d]",
+ snprintf(buf, sizeof(buf), "[公安報告] 使用者上線監控 [%02d/%02d:%02d]",
ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_hour);
- keeplog("usies", "Security", buf1, "usies");
+ keeplog("usies", "Security", buf, "usies");
printf("[公安報告] 使用者上線監控\n");
- gzip(log_file, "usies", buf);
- printf("壓縮使用者上線監控\n");
+
/* Ptt 歷史事件處理 */
- now = time(NULL) - ADJUST_M * 60; /* back to ancent */
+ now -= ADJUST_M * 60; /* back to ancent */
ptime = localtime4(&now);
- attach_SHM();
- if ((fp = fopen("etc/history.data", "r"))) { /* 單日最多次人次,同時上線
- * ,註冊 */
+ sprintf(buf, "-%02d%02d%02d",
+ ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday);
+ gzip(log_file, "usies", buf);
+ printf("壓縮使用者上線監控\n");
+
+ if ((fp = fopen("etc/history.data", "r"))) { /* 單日最多次人次,同時上線,註冊 */
if (fscanf(fp, "%d %d %d %d", &max_day_login, &max_hour_login, &max_reg, &max_online) == 4) {
fp1 = fopen("etc/history", "a");
if (peak_hour_login > max_hour_login) {
@@ -352,6 +362,7 @@ main(int argc, char **argv)
}
fclose(fp1);
}
+
/* Ptt 歡迎畫面處理 */
printf("歡迎畫面處理\n");
@@ -369,17 +380,17 @@ main(int argc, char **argv)
}
printf("歡迎畫面處理\n");
if (ptime->tm_wday == 0) {
- keeplog("etc/week", "Record", "本週熱門話題", NULL);
+ keeplog("etc/week", BN_RECORD, "本週熱門話題", NULL);
gzip("bbslog", "bntplink", buf);
gzip("innd/bbslog", "innbbsd", buf);
gzip("etc/mailog", "mailog", buf);
}
if (ptime->tm_mday == 1)
- keeplog("etc/month", "Record", "本月熱門話題", NULL);
+ keeplog("etc/month", BN_RECORD, "本月熱門話題", NULL);
if (ptime->tm_yday == 1)
- keeplog("etc/year", "Record", "年度熱門話題", NULL);
+ keeplog("etc/year", BN_RECORD, "年度熱門話題", NULL);
} else if (ptime->tm_hour == 3 && ptime->tm_wday == 6) {
char *fn1 = "tmp";
char *fn2 = "suicide";