-
Notifications
You must be signed in to change notification settings - Fork 0
/
baddest.c
249 lines (199 loc) · 4.53 KB
/
baddest.c
1
2
3
4
5
6
7
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
Baddest Batches datafile maker for DayDream
(c) PMC 1998 - 2015.
*/
#include <dd.h>
#include <ddlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../include/pmc.h"
#include "baddest.h"
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
FILE *datafile;
FILE *logfile;
Baddest BB;
struct dif *d;
struct tm *tm;
char buf[300];
char temp_username[25];
char temp[80];
char temp_date[10];
char bbsname[80] = "MyBBS";
int newuser = 0, record = 0;
/* crap */
unsigned long temp_megs;
unsigned long temp_cps;
unsigned long temp_files;
unsigned long temp_time;
/* crap */
int grab_date() /* date grabbing routine */
{
char tmp_time[80];
time_t t;
t = time(0);
tm = localtime(&t);
/* grabbing current date */
strcpy(tmp_time, ctime(&t));
bzero(temp_date, sizeof(temp_date));
sprintf(temp_date, "%2.2d/%2.2d/%2.2d", tm->tm_mon + 1, tm->tm_mday, tm->tm_year % 100);
/* above makes xx/xx/xx date fixation */
fputs("******* log entry at: ", logfile);
fputs(tmp_time, logfile);
fputs("-- user: ", logfile);
fputs(temp_username, logfile);
sprintf(tmp_time, " -- %lu megs -- %lu files -- %lu time\n", temp_megs, temp_files, temp_time);
fputs(tmp_time, logfile);
return 0;
}
int Search_User()
{
fread(&BB, sizeof(Baddest), 1, datafile);
while (strstr(temp_username, BB.User_Name) == NULL)
{
fread(&BB, sizeof(Baddest), 1, datafile);
if (feof(datafile))
{
newuser = 1;
return 0;
}
}
fseek(datafile, -sizeof(Baddest), SEEK_CUR);
newuser = 0;
return 0;
}
int Add_User()
{
strcpy(BB.User_Name, "");
BB.Megs = 0;
BB.Cps = 0;
BB.Files = 0;
BB.Time = 0;
strcpy(BB.Date, "");
/* ^ clean the bitch up */
strcpy(BB.User_Name, temp_username);
BB.Megs = temp_megs;
BB.Cps = temp_cps;
BB.Files = temp_files;
BB.Time = temp_time;
strcpy(BB.Date, temp_date);
fwrite(&BB, sizeof(Baddest), 1, datafile);
return 0;
}
int My_Bytes()
{
if (BB.Megs < temp_megs)
{
strcpy(BB.User_Name, "");
BB.Megs = 0;
BB.Cps = 0;
BB.Files = 0;
BB.Time = 0;
strcpy(BB.Date, "");
strcpy(BB.User_Name, temp_username);
BB.Megs = temp_megs;
BB.Cps = temp_cps;
BB.Files = temp_files;
BB.Time = temp_time;
strcpy(BB.Date, temp_date);
fwrite(&BB, sizeof(Baddest), 1, datafile);
record = 1;
}
return 0;
}
int main(int argv, char *argc[])
{
if (argv == 1)
{
printf("need to run from DayDream\n");
}
d = dd_initdoor(argc[1]);
/* sprintf(buf,"%s/pmc/baddest.dat",getenv("DAYDREAM"));*/
strcpy(buf, "/home/bbs/pmc/baddest.dat");
datafile = fopen(buf, "r+b");
if (!datafile)
{
printf("error at %s!\n", buf);
return 1;
}
logfile = fopen("/home/bbs/pmc/baddest.log", "at");
if (!logfile)
{
printf("error at /home/bbs/pmc/baddest.log!\n");
return 1;
}
dd_sendstring(d, "\n[ Baddest Batches (c) PMC 1996-2015 ]\n");
dd_getstrval(d, buf, USER_HANDLE);
strcpy(temp_username, buf);
dd_getstrval(d, buf, DOOR_PARAMS);
sscanf(buf, "%lu %lu %lu", &temp_files, &temp_megs, &temp_time);
grab_date();
Search_User();
if (newuser == 1)
Add_User();
if (newuser == 0)
My_Bytes();
if (temp_files > 1)
{
Create_Announce();
/* RehashBot();*/
}
fclose(datafile);
fclose(logfile);
dd_close(d);
return 0;
}
int Create_Announce()
{
FILE *announce;
char ann_string[200];
announce = fopen("/eggdrop/pmc-announce.txt", "wt");
if (!announce)
{
dd_sendstring(d, "error at /eggdrop/pmc-announce.txt! inform sysop.\n");
return 0;
}
if (record == 0)
{
sprintf(ann_string, "%s daydream bbs ul batch complete!\ntrader [ %s ] uploaded - %lu files %lu megs in %lu mins (ps fuck ftp)\n",
bbsname, temp_username, temp_files, (temp_megs / (1024 * 1024)), (temp_time / 60));
}
else
{
sprintf(ann_string, ".%s daydream bbs ul .batch. complete!\ntrader [ .%s. ] uploaded - .%lu. files .%lu. megs in .%lu. mins (ps fuck ftp)\n --- this is %s's new baddest batches record\n",
bbsname, temp_username, temp_files, (temp_megs / (1024 * 1024)), (temp_time / 60), temp_username);
}
fputs(ann_string, announce);
fclose(announce);
return 0;
}
/* rehash the eggdrop bot */
int RehashBot()
{
FILE *botpidfile;
char iptemp[80];
int olduid = getuid();
int botpid;
botpidfile = fopen("/eggdrop/pid.PMCbitch", "rt");
if (!botpidfile)
{
printf("error at eggdrop pid file...\n");
return 0;
}
/* if cannot find bot pid, PMC bitches ass, just return and sux */
fgets(iptemp, 80, botpidfile);
botpid = atoi(iptemp);
if (!setuid(0))
{
kill(botpid, SIGHUP);
setuid(olduid);
}
else
{
printf("setuid failed\n");
}
fclose(botpidfile);
return 0;
}