home *** CD-ROM | disk | FTP | other *** search
- #include "rausm.h"
- #include "ra20.h"
- #include <ctype.h>
- #include <dos.h>
- #include <process.h>
- #include <share.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
-
- FILE *logfp;
- char UserBbsPath[_MAX_PATH];
- char ListName[_MAX_PATH];
- int ReportOnly;
- long int UploadCredit;
- long int UploadKCredit;
- long int DownloadCredit;
- long int DownloadKCredit;
- long int MessageCredit;
- long int CallOnCredit;
- long int SysOpCredit;
- long int LoginDayCredit;
- long int BaseCredit;
- char UserFlag[4];
- unsigned int MaxSecurity;
- unsigned int MinSecurity;
- int SecCount;
- SecData Security[200];
- Hidden *HiddenHead;
- SortList *SortHead;
-
- char *strp2c(char *p)
- {
- static char str[100];
-
- memcpy(str, p+1, *p);
- str[*p] = '\0';
-
- return &str[0];
- }
-
- unsigned int change_security(long int count)
- {
- int i;
- unsigned sec;
-
- sec = MinSecurity;
- for (i = 0; i < SecCount; i++)
- if (count > Security[i].Credit)
- sec = Security[i].Security > sec ? Security[i].Security : sec;
- return sec;
- }
-
- int CheckFlag(char *s)
- {
- int i;
-
- for (i = 0; i < 4; i++)
- if (UserFlag[i] & s[i]) return 0;
- return 1;
- }
-
- long int CountDay(char *last)
- {
- static struct dosdate_t tm;
- static int x = 0;
- char str[3];
- int mon, day, year;
- long int count1, count2;
-
- str[0] = last[1];
- str[1] = last[2];
- str[2] = '\0';
- mon = atoi(str);
- str[0] = last[4];
- str[1] = last[5];
- str[2] = '\0';
- day = atoi(str);
- str[0] = last[7];
- str[1] = last[8];
- str[2] = '\0';
- year = atoi(str);
- if (x == 0) _dos_getdate(&tm);
- count1 = (long)(day-1) + 30L * (mon-1) + 365L * (year-90);
- count2 = (long)(tm.day-1) + 30L * (tm.month-1) + 365L * (tm.year-1990);
-
- return count2-count1;
- }
-
- int isHidden(char *p)
- {
- Hidden *temp;
-
- temp = HiddenHead;
- while (temp != NULL) {
- if (stricmp(temp->name, p) == 0) return 1;
- temp = temp->next;
- }
- return 0;
- }
-
- int usort_func(const void *a, const void *b)
- {
- USort *pa, *pb;
-
- pa = (USort *)a;
- pb = (USort *)b;
- return (pb->no - pa->no);
- }
-
- int lsort_func(const void *a, const void *b)
- {
- LSort *pa, *pb;
-
- pa = (LSort *)a;
- pb = (LSort *)b;
- return (int)(pb->no - pa->no);
- }
-
-
- int main(int argc, char *argv[])
- {
- int len, i, userno, intable;
- char *name;
- FILE *fp, *listfp;
- RA2T_users userdata;
- fpos_t pos, prepos;
- long int count;
- USort *USortData[1];
- LSort *LSortData[6];
- SortList *temp;
- struct tm *time_now;
- time_t secs_now;
-
- printf("RAUSM %s, RemoteAccess User Security Manager\n"
- " Copyright (c) 1992 by Tommy Wu. All rights reserved.\n", Version);
-
- ReadCTL(argv[0]);
- len = strlen(UserBbsPath);
- if (UserBbsPath[len-1] != '\\') {
- UserBbsPath[len] = '\\';
- UserBbsPath[len+1] = '\0';
- }
- strcat(UserBbsPath, "USERS.BBS");
- printf(" ■ Open RemoteAccess database file [%s].\n", UserBbsPath);
- if (logfp != NULL) fprintf(logfp, " ■ Open RemoteAccess database file [%s].\n", UserBbsPath);
- if ((fp = _fsopen(UserBbsPath, "r+b", SH_DENYNO)) == NULL) {
- fprintf(stderr, "Failed to open %s.\n", UserBbsPath);
- if (logfp != NULL) fprintf(logfp, "Failed to open %s.\n", UserBbsPath);
- ERR_EXIT(1);
- }
- USortData[0] = (USort *)calloc(sizeof(USort), 101);
- if (USortData[0] == NULL) {
- fprintf(stderr, "Memory not enough.\n");
- if (logfp != NULL) fprintf(logfp, "Memory not enough.\n");
- ERR_EXIT(2);
- }
- for (i = 0; i < 6; i++) {
- LSortData[i] = (LSort *)calloc(sizeof(LSort), 101);
- if (LSortData[i] == NULL) {
- fprintf(stderr, "Memory not enough.\n");
- if (logfp != NULL) fprintf(logfp, "Memory not enough.\n");
- ERR_EXIT(2);
- }
- }
-
- listfp = NULL;
- if (ListName[0] != '\0') {
- char str[100];
- struct tm *time_now;
- time_t secs_now;
-
- if ((listfp = fopen(ListName, "wb")) == NULL) {
- fprintf(stderr, "Failed to open %s.\n", ListName);
- if (logfp != NULL) fprintf(logfp, "Failed to open %s.\n", ListName);
- ERR_EXIT(1);
- }
- tzset();
- time(&secs_now);
- time_now = localtime(&secs_now);
- strftime(str, 80, "%b %d %Y %H:%M:%S", time_now);
- // 0 1 2 3 4 5 6 7
- // 1234567890123456789012345678901234567890123456789012345678901234567890123456789
- fprintf(listfp, " ówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówów\r\n");
- fprintf(listfp, " RemoteAccess User Security Manager ▓╬¡p╕Ω«╞¬φ\r\n");
- fprintf(listfp, " ╗s¬φñΘ┤┴ : %s\r\n", str);
- fprintf(listfp, " │╠░¬╡Ñ»┼ : %5u │╠ºC╡Ñ»┼ : %5u\r\n", MaxSecurity, MinSecurity);
- fprintf(listfp, " Generated by RAUSM %s, written by Tommy Wu.\r\n", Version);
- fprintf(listfp, " ówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówów\r\n");
- }
-
- printf(" ■ Processing....\n");
- if (logfp != NULL) fprintf(logfp, " ■ Processing....\n");
-
- userno = 0;
- intable = 0;
- while (1) {
- fgetpos(fp, &pos);
- fread(&userdata, sizeof(RA2T_users), 1, fp);
- if (feof(fp)) break;
- name = strp2c(userdata.Name);
- count = 0UL;
- count += MessageCredit * userdata.MsgsPosted;
- count += CallOnCredit * userdata.NoCalls;
- count += UploadCredit * userdata.Uploads;
- count += DownloadCredit * userdata.Downloads;
- count += UploadKCredit * userdata.UploadsK;
- count += DownloadKCredit * userdata.DownloadsK;
- count += LoginDayCredit * CountDay(userdata.LastDate);
- count += SysOpCredit * (userdata.Credit-BaseCredit);
-
- if (isHidden(name) == 0) {
- if (intable < 100) {
- USortData[0][intable].userno = userno;
- USortData[0][intable].no = userdata.MsgsPosted;
- for (i = 0; i < 6; i++) LSortData[i][intable].userno = userno;
- LSortData[0][intable].no = userdata.NoCalls;
- LSortData[1][intable].no = userdata.Uploads;
- LSortData[2][intable].no = userdata.Downloads;
- LSortData[3][intable].no = userdata.UploadsK;
- LSortData[4][intable].no = userdata.DownloadsK;
- LSortData[5][intable].no = userdata.Credit;
- intable++;
- }
- else {
- USortData[0][100].userno = userno;
- USortData[0][100].no = userdata.MsgsPosted;
- for (i = 0; i < 6; i++) LSortData[i][100].userno = userno;
- LSortData[0][100].no = userdata.NoCalls;
- LSortData[1][100].no = userdata.Uploads;
- LSortData[2][100].no = userdata.Downloads;
- LSortData[3][100].no = userdata.UploadsK;
- LSortData[4][100].no = userdata.DownloadsK;
- LSortData[5][100].no = userdata.Credit;
- qsort((void *)USortData[0], 101, sizeof(USort), usort_func);
- for (i = 0; i < 6; i++)
- qsort((void *)LSortData[i], 101, sizeof(LSort), lsort_func);
- }
- }
-
- userno++;
-
- if (userdata.Security <= MaxSecurity && userdata.Security >= MinSecurity
- && CheckFlag(userdata.Flags)) {
- unsigned int sec;
-
- sec = change_security(count);
- if (sec != userdata.Security) {
- if (logfp != NULL)
- fprintf(logfp, " User : %-35s security %u %sto %u.\n", name, userdata.Security,
- (sec > userdata.Security) ? "up" : "down", sec);
- printf(" User : %-35s security %u %sto %u.\n", name, userdata.Security,
- (sec > userdata.Security) ? "up" : "down", sec);
- userdata.Security = sec;
- }
- }
- if (!ReportOnly) {
- fgetpos(fp, &prepos);
- fsetpos(fp, &pos);
- fwrite(&userdata, sizeof(RA2T_users), 1, fp);
- fsetpos(fp, &prepos);
- }
- if (listfp != NULL) {
- fprintf(listfp, " ¿╧Ñ╬¬╠⌐mªW : %-40s ╡Ñ»┼ : %5u\r\n", name, userdata.Security);
- fprintf(listfp, " ╝g½Hª╕╝╞ : %10u ñW╜uª╕╝╞ : %10ld ñW╢╟ª╕╝╞ : %10ld\r\n",
- userdata.MsgsPosted, userdata.NoCalls, userdata.Uploads);
- fprintf(listfp, " ñU╢╟ª╕╝╞ : %10ld ñW╢╟ó┘╝╞ : %10ld ñU╢╟ó┘╝╞ : %10ld\r\n",
- userdata.Downloads, userdata.UploadsK, userdata.DownloadsK);
- fprintf(listfp, " »╕¬°Ñ[┼v : %10ld ┴`Ñ[┼v╝╞ : %10ld\r\n",
- userdata.Credit-BaseCredit, count);
- fprintf(listfp, " ówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówówów\r\n");
- }
- }
- if (listfp != NULL) fclose(listfp);
-
- if (intable < 100) {
- qsort((void *)USortData[0], intable, sizeof(USort), usort_func);
- for (i = 0; i < 6; i++)
- qsort((void *)LSortData[i], intable, sizeof(LSort), lsort_func);
- }
- temp = SortHead;
- while (temp != NULL) {
- FILE *in, *out;
- char ch;
- char tagno, itemno;
- char str[80];
- int no;
-
- if ((in = _fsopen(temp->SourceName, "rb", SH_DENYNO)) == NULL) {
- fprintf(stderr, "Failed to open %s.\n", temp->SourceName);
- if (logfp != NULL) fprintf(logfp, "Failed to open %s.\n", temp->SourceName);
- ERR_EXIT(1);
- }
-
- if ((out = _fsopen(temp->TargetName, "wb", SH_DENYNO)) == NULL) {
- fprintf(stderr, "Failed to open %s.\n", temp->TargetName);
- if (logfp != NULL) fprintf(logfp, "Failed to open %s.\n", temp->TargetName);
- ERR_EXIT(1);
- }
-
- printf(" ■ Generate %s from %s.\n", temp->TargetName, temp->SourceName);
- if (logfp != NULL)
- fprintf(logfp, " ■ Generate %s from %s.\n", temp->TargetName, temp->SourceName);
-
- temp = temp->Next;
-
- ch = fgetc(in);
- while (!feof(in)) {
- if (ch != '%') {
- fputc(ch, out);
- ch = fgetc(in);
- continue;
- }
-
- ch = fgetc(in);
- if (ch == '\0' || strchr("ABCDEFG012", toupper(ch)) == NULL) {
- fputc('%', out);
- fputc(ch, out);
- ch = fgetc(in);
- continue;
- }
-
- if (ch == '0') {
- tzset();
- time(&secs_now);
- time_now = localtime(&secs_now);
- strftime(str, 80, "%b %d %Y", time_now);
- len = strlen(str);
- fprintf(out, "%s", str);
- len -= 2;
- for (i = 0; i < len; i++) ch = fgetc(in);
- ch = fgetc(in);
- continue;
- }
-
- if (ch == '1') {
- tzset();
- time(&secs_now);
- time_now = localtime(&secs_now);
- strftime(str, 80, "%H:%M:%S", time_now);
- len = strlen(str);
- fprintf(out, "%s", str);
- len -= 2;
- for (i = 0; i < len; i++) ch = fgetc(in);
- ch = fgetc(in);
- continue;
- }
-
- if (ch == '2') {
- sprintf(str, "■ Generated by RAUSM %s, written by Tommy Wu.", Version);
- len = strlen(str);
- fprintf(out, "%s", str);
- len -= 2;
- for (i = 0; i < len; i++) ch = fgetc(in);
- ch = fgetc(in);
- continue;
- }
-
- tagno = ch;
- ch = fgetc(in);
- if (!isdigit(ch)) {
- fputc('%', out);
- fputc(tagno, out);
- fputc(ch, out);
- ch = fgetc(in);
- continue;
- }
-
- str[0] = ch;
- ch = fgetc(in);
- if (!isdigit(ch)) {
- fputc('%', out);
- fputc(tagno, out);
- fputc(str[0], out);
- fputc(ch, out);
- ch = fgetc(in);
- continue;
- }
-
- str[1] = ch;
- str[2] = '\0';
- no = atoi(str)-1;
- ch = fgetc(in);
- if (ch == '\0' || strchr("NSABCDEFG", toupper(ch)) == NULL) {
- fputc('%', out);
- fputc(tagno, out);
- fputc(str[0], out);
- fputc(str[1], out);
- fputc(ch, out);
- ch = fgetc(in);
- continue;
- }
-
- itemno = ch;
- if (toupper(tagno) == 'A')
- fseek(fp, (long)sizeof(RA2T_users) * USortData[0][no].userno, SEEK_SET);
- else
- fseek(fp, (long)sizeof(RA2T_users) * LSortData[toupper(tagno)-'B'][no].userno, SEEK_SET);
- fread(&userdata, sizeof(RA2T_users), 1, fp);
- switch (toupper(itemno)) {
- case 'N': // Name
- strcpy(str, strp2c(userdata.Name));
- str[24] = '\0';
- fprintf(out, "%-24s", str);
- for (i = 0; i < 19; i++) fgetc(in);
- break;
- case 'S':
- sprintf(str, "%5u", userdata.Security);
- fprintf(out, "%s", str);
- break;
- case 'A':
- sprintf(str, "%5u", userdata.MsgsPosted);
- fprintf(out, "%s", str);
- break;
- case 'B':
- sprintf(str, "%10ld", userdata.NoCalls);
- fprintf(out, "%s", str);
- for (i = 0; i < 5; i++) fgetc(in);
- break;
- case 'C':
- sprintf(str, "%10ld", userdata.Uploads);
- fprintf(out, "%s", str);
- for (i = 0; i < 5; i++) fgetc(in);
- break;
- case 'D':
- sprintf(str, "%10ld", userdata.Downloads);
- fprintf(out, "%s", str);
- for (i = 0; i < 5; i++) fgetc(in);
- break;
- case 'E':
- sprintf(str, "%10ld", userdata.UploadsK);
- fprintf(out, "%s", str);
- for (i = 0; i < 5; i++) fgetc(in);
- break;
- case 'F':
- sprintf(str, "%10ld", userdata.DownloadsK);
- fprintf(out, "%s", str);
- for (i = 0; i < 5; i++) fgetc(in);
- break;
- case 'G':
- sprintf(str, "%10ld", userdata.Credit);
- fprintf(out, "%s", str);
- for (i = 0; i < 5; i++) fgetc(in);
- break;
- }
- ch = fgetc(in);
- }
- fclose(in);
- fclose(out);
- }
-
- fclose(fp);
- if (logfp != NULL) {
- fprintf(logfp, " ■ RAUSM %s shutdown.\n\n", Version);
- fclose(logfp);
- }
- return 0;
- }
-