dstsedit.c 5.66 KB
Newer Older
Rob Swindell's avatar
Rob Swindell committed
1
/* $Id: dstsedit.c,v 1.9 2020/08/17 00:48:28 rswindell Exp $ */
2

3 4 5 6
/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/
33 34 35 36 37 38 39

#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>

40
#include "str_util.h"
deuce's avatar
deuce committed
41
#include "dirwrap.h"
42
#include "nopen.h"
43
#include "scfgdefs.h"
44
#include "conwrap.h"
45
#include "date_str.h"
46 47 48 49

int 
main(int argc, char **argv)
{
50
	char		ch, str[MAX_PATH+1], path[MAX_PATH + 1]
51
	               ,*lst = "%c) %-25s: %13lu\n"
52
	               ,*nv = "\nNew value: ";
53 54 55 56 57
	int		file;
	stats_t		stats;
	time32_t		t;
	scfg_t		cfg;

58
	memset(&cfg, 0, sizeof(cfg));
59

60 61 62
	if (argc > 1) {
		SAFECOPY(path, argv[1]);
	} else {
63
		SAFECOPY(path, get_ctrl_dir(/* warn: */TRUE));
64 65 66
	}
	backslash(path);

67
	SAFEPRINTF(str, "%sdsts.dab", path);
68 69 70 71 72 73 74
	if ((file = nopen(str, O_RDONLY)) == -1) {
		printf("Can't open %s\r\n", str);
		exit(1);
	}
	read(file, &t, 4L);
	if (read(file, &stats, sizeof(stats_t)) != sizeof(stats_t)) {
		close(file);
deuce's avatar
deuce committed
75
		printf("Error reading %" XP_PRIsize_t "u bytes from %s\r\n", sizeof(stats_t), str);
76 77 78 79
		exit(1);
	}
	close(file);
	while (1) {
80
		printf("Synchronet Daily Statistics Editor v1.02\r\n\r\n");
81
		printf("S) %-25s: %13s\n", "Date Stamp (MM/DD/YY)", unixtodstr(&cfg, t, str));
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
		printf(lst, 'L', "Total Logons", stats.logons);
		printf(lst, 'O', "Logons Today", stats.ltoday);
		printf(lst, 'T', "Total Time on", stats.timeon);
		printf(lst, 'I', "Time on Today", stats.ttoday);
		printf(lst, 'U', "Uploaded Files Today", stats.uls);
		printf(lst, 'B', "Uploaded Bytes Today", stats.ulb);
		printf(lst, 'D', "Downloaded Files Today", stats.dls);
		printf(lst, 'W', "Downloaded Bytes Today", stats.dlb);
		printf(lst, 'P', "Posts Today", stats.ptoday);
		printf(lst, 'E', "E-Mails Today", stats.etoday);
		printf(lst, 'F', "Feedback Today", stats.ftoday);
		printf("%c) %-25s: %13u\r\n", 'N', "New Users Today", stats.nusers);

		printf("Q) Quit and save changes\r\n");
		printf("X) Quit and don't save changes\r\n");

		printf("\r\nWhich: ");

		ch = toupper(getch());
		printf("%c\r\n", ch);

		switch (ch) {
		case 'S':
			printf("Date stamp (MM/DD/YY): ");
106
			fgets(str, sizeof(str), stdin);
107
			if (isdigit(str[0]))
108 109 110
				t = dstrtounix(&cfg, str);
			break;
		case 'L':
deuce's avatar
deuce committed
111
			fputs(nv,stdout);
112
			fgets(str, sizeof(str), stdin);
113
			if (isdigit(str[0]))
114 115 116
				stats.logons = atol(str);
			break;
		case 'O':
deuce's avatar
deuce committed
117
			fputs(nv,stdout);
118
			fgets(str, sizeof(str), stdin);
119
			if (isdigit(str[0]))
120 121 122
				stats.ltoday = atol(str);
			break;
		case 'T':
deuce's avatar
deuce committed
123
			fputs(nv,stdout);
124
			fgets(str, sizeof(str), stdin);
125
			if (isdigit(str[0]))
126 127 128
				stats.timeon = atol(str);
			break;
		case 'I':
deuce's avatar
deuce committed
129
			fputs(nv,stdout);
130
			fgets(str, sizeof(str), stdin);
131
			if (isdigit(str[0]))
132 133 134
				stats.ttoday = atol(str);
			break;
		case 'U':
deuce's avatar
deuce committed
135
			fputs(nv,stdout);
136
			fgets(str, sizeof(str), stdin);
137
			if (isdigit(str[0]))
138 139 140
				stats.uls = atol(str);
			break;
		case 'B':
deuce's avatar
deuce committed
141
			fputs(nv,stdout);
142
			fgets(str, sizeof(str), stdin);
143
			if (isdigit(str[0]))
144 145 146
				stats.ulb = atol(str);
			break;
		case 'D':
deuce's avatar
deuce committed
147
			fputs(nv,stdout);
148
			fgets(str, sizeof(str), stdin);
149
			if (isdigit(str[0]))
150 151 152
				stats.dls = atol(str);
			break;
		case 'W':
deuce's avatar
deuce committed
153
			fputs(nv,stdout);
154
			fgets(str, sizeof(str), stdin);
155
			if (isdigit(str[0]))
156 157 158
				stats.dlb = atol(str);
			break;
		case 'P':
deuce's avatar
deuce committed
159
			fputs(nv,stdout);
160
			fgets(str, sizeof(str), stdin);
161
			if (isdigit(str[0]))
162 163 164
				stats.ptoday = atol(str);
			break;
		case 'E':
deuce's avatar
deuce committed
165
			fputs(nv,stdout);
166
			fgets(str, sizeof(str), stdin);
167
			if (isdigit(str[0]))
168 169 170
				stats.etoday = atol(str);
			break;
		case 'F':
deuce's avatar
deuce committed
171
			fputs(nv,stdout);
172
			fgets(str, sizeof(str), stdin);
173
			if (isdigit(str[0]))
174 175 176
				stats.ftoday = atol(str);
			break;
		case 'N':
deuce's avatar
deuce committed
177
			fputs(nv,stdout);
178
			fgets(str, sizeof(str), stdin);
179
			if (isdigit(str[0]))
180 181 182
				stats.nusers = atoi(str);
			break;
		case 'Q':
183
			SAFEPRINTF(str, "%sdsts.dab", path);
184 185 186 187 188 189 190
			if ((file = nopen(str, O_WRONLY)) == -1) {
				printf("Error opening %s\r\n", str);
				exit(1);
			}
			write(file, &t, 4L);
			write(file, &stats, sizeof(stats_t));
			close(file);
191
			// fall-through
192 193 194 195 196 197 198 199
		case 'X':
			exit(0);
		default:
			putchar(7);
			break;
		}
	}
}